Beispiel #1
0
bool DysectAPI::CodeLocation::findSymbol(SymtabAPI::Symtab* symtab, string name, string libName, vector<DysectAPI::CodeLocation*>& symbols, bool isRegex) {
  assert(symtab != 0);

  bool exit = false;
  vector<SymtabAPI::Symbol *> symtabSymbols;
  vector<SymtabAPI::Symbol *> foundSymtabSymbols;
  set<pair<Dyninst::Address, string> > lOffsets;

  foundSymtabSymbols.clear();
  symtabSymbols.clear();

  // XXX: Include class specialization!
  if (name[0] == '~') {
    name.erase(0, 1);
    exit = true;
  }
  string symbolExpr = string(name);
  symbolExpr.append("<*>");
  //boost::regex expression(symbolExpr);

  if(!symtab->findSymbol(foundSymtabSymbols, name, SymtabAPI::Symbol::ST_FUNCTION, anyName, isRegex) && !isRegex) {

    // Try to search for template specialization
    symtab->findSymbol(foundSymtabSymbols, symbolExpr, SymtabAPI::Symbol::ST_FUNCTION, anyName, true);
  }

  if(foundSymtabSymbols.empty()) {
    //return Err::verbose(false, "No symbols found for '%s'", name.c_str());
    return false;
  }


  for(int i = 0; i < foundSymtabSymbols.size(); i++) {
    DysectAPI::CodeLocation* dsym = new DysectAPI::CodeLocation();
    dsym->libName = libName;

    SymtabAPI::Symbol* ssym = foundSymtabSymbols[i];

    string* str = new string(ssym->getPrettyName());
    Dyninst::Address offset = ssym->getOffset();
    if (exit == true) //TODO: This may not work if code optimized (i.e. MPI functions)
      offset = offset + ssym->getSize() - 1; // this is computing the exit!

    if(lOffsets.find(pair<Dyninst::Address, string> (offset, *str)) != lOffsets.end()) {
      continue;
    }
    lOffsets.insert(pair<Dyninst::Address, string> (offset, *str));

    dsym->offsets.insert(pair<Dyninst::Address, string*>(offset, str));

    symbols.push_back(dsym);
  }

  return true;
}
Beispiel #2
0
bool DysectAPI::CodeLocation::findSymbol(SymtabAPI::Symtab* symtab, string name, string libName, vector<DysectAPI::CodeLocation*>& symbols, bool isRegex) {
  assert(symtab != 0);

  vector<SymtabAPI::Symbol *> symtabSymbols;
  vector<SymtabAPI::Symbol *> foundSymtabSymbols;
  vector<Dyninst::Address> lOffsets;

  foundSymtabSymbols.clear();
  symtabSymbols.clear();

  // XXX: Include class specialization!
  string symbolExpr = string(name);
  symbolExpr.append("<*>");
  //boost::regex expression(symbolExpr);
  
  if(!symtab->findSymbol(foundSymtabSymbols, name, SymtabAPI::Symbol::ST_FUNCTION, anyName, isRegex) && !isRegex) {

    // Try to search for template specialization
    symtab->findSymbol(foundSymtabSymbols, symbolExpr, SymtabAPI::Symbol::ST_FUNCTION, anyName, true);
  }

  if(foundSymtabSymbols.empty()) {
    //return Err::verbose(false, "No symbols found for '%s'", name.c_str());
    return false;
  }


  for(int i = 0; i < foundSymtabSymbols.size(); i++) {
    DysectAPI::CodeLocation* dsym = new DysectAPI::CodeLocation();
    dsym->libName = libName;

    SymtabAPI::Symbol* ssym = foundSymtabSymbols[i];

    string* str = new string(ssym->getPrettyName());
    Dyninst::Address offset = ssym->getOffset();

    // XXX: Search for pair instead of plain offset
    if(dsym->offsets.find(offset) != dsym->offsets.end()) {
      continue;
    }

    dsym->offsets.insert(pair<Dyninst::Address, string*>(offset, str));

    symbols.push_back(dsym);
  }
  
  return true;
}