Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Symtab::getOrCreateModule #1623

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions dyninstAPI/src/binaryEdit.C
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "os.h"
#include "instPoint.h"
#include "function.h"
#include "Object.h"

using namespace Dyninst::SymtabAPI;

Expand Down Expand Up @@ -585,8 +586,12 @@ bool BinaryEdit::writeFile(const std::string &newFileName)
}

std::vector<Symbol *> newSyms;
buildDyninstSymbols(newSyms, newSec, symObj->getOrCreateModule("dyninstInst",
lowWaterMark_));
auto *mod = symObj->getContainingModule(lowWaterMark_);
if(!mod) {
mod = new Module(lang_Unknown, lowWaterMark_, "dyninstInst", symObj);
symObj->getObject()->addModule(mod);
}
buildDyninstSymbols(newSyms, newSec, mod);
for (unsigned i = 0; i < newSyms.size(); i++) {
symObj->addSymbol(newSyms[i]);
}
Expand Down
5 changes: 3 additions & 2 deletions symtabAPI/h/Symtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ class SYMTAB_EXPORT Symtab : public LookupInterface,


bool canBeShared();
Module *getOrCreateModule(const std::string &modName,
const Offset modAddr);
DYNINST_DEPRECATED("Use getContainingModule")
Module *getOrCreateModule(const std::string &modName, const Offset modAddr);
bool parseFunctionRanges();

//Only valid on ELF formats
Expand All @@ -441,6 +441,7 @@ class SYMTAB_EXPORT Symtab : public LookupInterface,

private:
void createDefaultModule();
void addModule(Module *m);

//bool buildFunctionLists(std::vector <Symbol *> &raw_funcs);
//void enterFunctionInTables(Symbol *func, bool wasSymtab);
Expand Down
14 changes: 11 additions & 3 deletions symtabAPI/src/Object-elf.C
Original file line number Diff line number Diff line change
Expand Up @@ -2197,9 +2197,10 @@ bool Object::fix_global_symbol_modules_static_dwarf() {

dwarf_printf("Locating ranges for module '%s' at offset 0x%zx\n", modname.c_str(), modLow);
std::vector<AddressRange> mod_ranges = DwarfWalker::getDieRanges(cu_die);
SymtabAPI::Module *m;
#pragma omp critical
m = associated_symtab->getOrCreateModule(modname, modLow);
auto *m = associated_symtab->getContainingModule(modLow);
if(!m) {
m = new SymtabAPI::Module(lang_Unknown, modLow, modname, associated_symtab);
}
dwarf_printf("Adding %zu ranges to '%s'\n", mod_ranges.size(), m->fileName().c_str());
for (auto r = mod_ranges.begin(); r != mod_ranges.end(); ++r)
{
Expand Down Expand Up @@ -2240,6 +2241,9 @@ bool Object::fix_global_symbol_modules_static_dwarf() {
}
DwarfWalker::buildSrcFiles(dbg, cu_die, m->getStrings());
// dies_seen.insert(cu_die_off);

// 'addModule' finalizes the Module's ranges, so do not add until after they are computed
associated_symtab->addModule(m);
}

return true;
Expand Down Expand Up @@ -3051,6 +3055,10 @@ ObjectType Object::objType() const {
return obj_type_;
}

void Object::addModule(SymtabAPI::Module* m) {
associated_symtab->addModule(m);
}

void Object::getModuleLanguageInfo(dyn_hash_map<string, supportedLanguages> *mod_langs) {
string working_module;
string mod_string;
Expand Down
4 changes: 2 additions & 2 deletions symtabAPI/src/Object-elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "headers.h"
#include "MappedFile.h"
#include "IntervalTree.h"

#include "Module.h"
#include <elf.h>
#include <libelf.h>
#include <string>
Expand Down Expand Up @@ -166,8 +166,8 @@ class Object : public AObject
bool hasDwarfInfo() const { return dwarvenDebugInfo; }
void getModuleLanguageInfo(dyn_hash_map<std::string, supportedLanguages> *mod_langs);
void parseFileLineInfo();

void parseTypeInfo();
void addModule(SymtabAPI::Module* m) override;

bool needs_function_binding() const override { return (plt_addr_ > 0); }
bool get_func_binding_table(std::vector<relocationEntry> &fbt) const override;
Expand Down
2 changes: 2 additions & 0 deletions symtabAPI/src/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

#include "Symbol.h"
#include "Symtab.h"
#include "Module.h"
#include "LineInformation.h"
#include "common/src/headers.h"
#include "common/src/MappedFile.h"
Expand Down Expand Up @@ -140,6 +141,7 @@ class AObject {
// Only implemented for ELF right now
SYMTAB_EXPORT virtual void getSegmentsSymReader(std::vector<SymSegment> &) {}
SYMTAB_EXPORT virtual void rebase(Offset) {}
virtual void addModule(SymtabAPI::Module *) {}
protected:
SYMTAB_EXPORT virtual ~AObject();
// explicitly protected
Expand Down
22 changes: 8 additions & 14 deletions symtabAPI/src/Symtab.C
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,6 @@ bool Symtab::fixSymModules(std::vector<Symbol *> &raw_syms)
createDefaultModule();
}

for (auto *m : impl->modules)
{
for(auto *mr : m->finalizeRanges()) {
impl->mod_lookup_.insert(mr);
}
}

// const std::vector<std::pair<std::string, Offset> > &mods = obj->modules_;
// for (unsigned i=0; i< mods.size(); i++) {
// getOrCreateModule(mods[i].first, mods[i].second);
Expand Down Expand Up @@ -786,13 +779,15 @@ void Symtab::createDefaultModule() {
this);
mod->addRange(imageOffset_, imageLen_ + imageOffset_);
impl->default_module = mod;
impl->modules.insert(mod);
for(auto *m : mod->finalizeRanges()) {
impl->mod_lookup_.insert(m);
}
addModule(mod);
}


void Symtab::addModule(Module *mod) {
impl->modules.insert(mod);
for(auto *m : mod->finalizeRanges()) {
impl->mod_lookup_.insert(m);
}
}

Module *Symtab::getOrCreateModule(const std::string &modName,
const Offset modAddr)
Expand All @@ -805,9 +800,8 @@ Module *Symtab::getOrCreateModule(const std::string &modName,
FILE__, __LINE__, modName.c_str(), modAddr);

Module *mod = new Module(lang_Unknown, modAddr, modName, this);
addModule(mod);

impl->modules.insert(mod);

return mod;
}

Expand Down