Пример #1
0
bool DepositLightCore::prepare() {
  DYSECTVERBOSE(true, "Preparing deposit light core action");
#ifdef CALLPATH_ENABLED
  prepared = true;
  findAggregates();

  string libraryPath;
  char *envValue;
  Domain *domain = owner->getDomain();
  bool boolRet;
  vector<Process::ptr>::iterator procIter;
  ProcessSet::ptr procs;
  WalkerSet *allWalkers;
  Process::ptr *proc;
  ProcDebug *pDebug;

  if(domain == NULL)
    return DYSECTWARN(false, "Domain not found when preparing DepositLightCore action");

  allWalkers = domain->getAllWalkers();
  DYSECTVERBOSE(true, "Preparing deposit light core action %d", allWalkers->size());

  envValue = getenv("STAT_PREFIX");
  if (envValue != NULL)
    libraryPath = envValue;
  else
    libraryPath = STAT_PREFIX;
  libraryPath += "/lib/libcallpathwrap.so";
  for (WalkerSet::iterator i = allWalkers->begin(); i != allWalkers->end(); i++) {
    pDebug = dynamic_cast<ProcDebug *>((*i)->getProcessState());
    proc = &(pDebug->getProc());
    DYSECTVERBOSE(true, "loading library %s", libraryPath.c_str());
    // This will fail in launch mode since process hasn't been started yet. We will also try loading the library on finishBE
    // This will also be called multiple times if multiple probes use this action, but this won't result in any errors
    if (Backend::loadLibrary(*proc, libraryPath) != OK) {
      return DYSECTWARN(false, "Failed to load library %s: %s", libraryPath.c_str(), Stackwalker::getLastErrorMsg());
    }
  }

  DYSECTVERBOSE(true, "Prepared deposit light core action");
#endif //ifdef CALLPATH_ENABLED
  return true;
}
Пример #2
0
bool Location::resolveExpression() {
  // Location expression parsed:
  //
  // loc_expr   ::= image '#' file '#' line
  //             |  image '#' symbol
  //             |  file '#' line
  //             |  symbol
  
  vector<string> tokens = Parser::tokenize(locationExpr, '#');
  int numTokens = tokens.size();
  Walker* proc = 0;

  if(numTokens > 0) {
    // XXX: Make this local to domain
    WalkerSet* walkerSet = Backend::getWalkerset();

    if(!walkerSet) {
      return Err::warn(false, "Walkerset not present");
    }

    WalkerSet::iterator procIter = walkerSet->begin();
    proc = *procIter;
  }

  if(numTokens == 1) {        // symbol
    string &symbol = tokens[0];

    if(!proc) {
      return Err::warn(false, "Walker could not be retrieved from walkerSet");
    }

    if(!DysectAPI::CodeLocation::findSymbol(proc, symbol, codeLocations)) {
      return Err::warn(false, "No symbols found for symbol %s", symbol.c_str());
    }

  } else if(numTokens == 2) { // file '#' line 
    
    int line = atoi(tokens[1].c_str());

    if(line > 0) {  // File '#' line
      string& file = tokens[0];

      if(!DysectAPI::CodeLocation::findFileLine(proc, file, line, codeLocations)) {
        return Err::warn(false, "Location for '%s#%d' not found", file.c_str(), line);
      }
    } else { // Image '#' symbol
      Symtab* symtab;
      string libName;
      string& image = tokens[0];
      string& symbol = tokens[1];

      // XXX: Move this to CodeLocation
      bool isRegex = false;
      int pos = symbol.find_first_of("*?");
      if(pos != string::npos) {
        isRegex = true;
      }

      if(SymbolTable::findSymtabByName(image, proc, symtab, libName) != OK) {
        return Err::warn(false, "Could not find image '%s'", image.c_str());
      }

      if(!CodeLocation::findSymbol(symtab, symbol, libName, codeLocations, isRegex)) {
        return Err::warn(false, "Location for symbol '%s' in image '%s' not found", symbol.c_str(), image.c_str());
      }
    }
  } else if(numTokens == 3) { // image '#' file '#' line
    Symtab* symtab;
    string libName;
    string& image = tokens[0];
    string& file = tokens[1];
    int line = atoi(tokens[2].c_str());

    if(line <= 0) {
      return Err::warn(false, "Line number for format image#file#line must be an integer");
    }

    if(SymbolTable::findSymtabByName(image, proc, symtab, libName) != OK) {
      return Err::warn(false, "Could not find image '%s'", image.c_str());
    }

    if(!CodeLocation::findFileLine(symtab, file, line, libName, codeLocations)) {
      return Err::warn(false, "Location for '%s:%d' in image '%s' not found", file.c_str(), line, image.c_str());
    }

  } else {
    return Err::warn(false, "Cannot resolve location '%s' - unknown format", locationExpr.c_str());
  }

  return true;
}