Remove SymbolVendor::GetSymtab

Summary:
This patch removes the GetSymtab method from the SymbolVendor, which is
a no-op as it's implementation just forwards to the relevant SymbolFile.
Instead it creates a Module::GetSymtab, which calls the SymbolFile
method directly.

All callers have been updated to use the Module method directly instead
of a two phase GetSymbolVendor->GetSymtab search, which leads to reduced
intentation in a lot of deeply nested code.

Reviewers: clayborg, JDevlieghere, jingham

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D65569

llvm-svn: 367820
This commit is contained in:
Pavel Labath 2019-08-05 09:21:47 +00:00
parent 8ed8353fc4
commit d5d47a3574
9 changed files with 97 additions and 140 deletions

View File

@ -656,6 +656,8 @@ public:
SymbolFile *GetSymbolFile(bool can_create = true,
Stream *feedback_strm = nullptr);
Symtab *GetSymtab();
/// Get a reference to the UUID value contained in this object.
///
/// If the executable image file doesn't not have a UUID value built into

View File

@ -118,9 +118,6 @@ public:
FileSpec GetMainFileSpec() const;
// Get module unified section list symbol table.
virtual Symtab *GetSymtab();
/// Notify the SymbolVendor that the file addresses in the Sections
/// for this module have been changed.
virtual void SectionFileAddressesChanged();

View File

@ -290,11 +290,8 @@ SBSymbolContextList SBModule::FindCompileUnits(const SBFileSpec &sb_file_spec) {
}
static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) {
if (module_sp) {
SymbolVendor *symbols = module_sp->GetSymbolVendor();
if (symbols)
return symbols->GetSymtab();
}
if (module_sp)
return module_sp->GetSymtab();
return nullptr;
}
@ -302,11 +299,8 @@ size_t SBModule::GetNumSymbols() {
LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModule, GetNumSymbols);
ModuleSP module_sp(GetSP());
if (module_sp) {
Symtab *symtab = GetUnifiedSymbolTable(module_sp);
if (symtab)
return symtab->GetNumSymbols();
}
if (Symtab *symtab = GetUnifiedSymbolTable(module_sp))
return symtab->GetNumSymbols();
return 0;
}

View File

@ -1447,15 +1447,11 @@ static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) {
static void DumpModuleSymtab(CommandInterpreter &interpreter, Stream &strm,
Module *module, SortOrder sort_order) {
if (module) {
SymbolVendor *sym_vendor = module->GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab)
symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(),
sort_order);
}
}
if (!module)
return;
if (Symtab *symtab = module->GetSymtab())
symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(),
sort_order);
}
static void DumpModuleSections(CommandInterpreter &interpreter, Stream &strm,
@ -1561,47 +1557,44 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
Stream &strm, Module *module,
const char *name, bool name_is_regex,
bool verbose) {
if (module) {
SymbolContext sc;
if (!module)
return 0;
SymbolVendor *sym_vendor = module->GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab) {
std::vector<uint32_t> match_indexes;
ConstString symbol_name(name);
uint32_t num_matches = 0;
if (name_is_regex) {
RegularExpression name_regexp(symbol_name.GetStringRef());
num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
name_regexp, eSymbolTypeAny, match_indexes);
} else {
num_matches =
symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
}
Symtab *symtab = module->GetSymtab();
if (!symtab)
return 0;
if (num_matches > 0) {
strm.Indent();
strm.Printf("%u symbols match %s'%s' in ", num_matches,
name_is_regex ? "the regular expression " : "", name);
DumpFullpath(strm, &module->GetFileSpec(), 0);
strm.PutCString(":\n");
strm.IndentMore();
for (uint32_t i = 0; i < num_matches; ++i) {
Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
if (symbol && symbol->ValueIsAddress()) {
DumpAddress(interpreter.GetExecutionContext()
.GetBestExecutionContextScope(),
symbol->GetAddressRef(), verbose, strm);
}
}
strm.IndentLess();
return num_matches;
}
SymbolContext sc;
std::vector<uint32_t> match_indexes;
ConstString symbol_name(name);
uint32_t num_matches = 0;
if (name_is_regex) {
RegularExpression name_regexp(symbol_name.GetStringRef());
num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
name_regexp, eSymbolTypeAny, match_indexes);
} else {
num_matches =
symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
}
if (num_matches > 0) {
strm.Indent();
strm.Printf("%u symbols match %s'%s' in ", num_matches,
name_is_regex ? "the regular expression " : "", name);
DumpFullpath(strm, &module->GetFileSpec(), 0);
strm.PutCString(":\n");
strm.IndentMore();
for (uint32_t i = 0; i < num_matches; ++i) {
Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
if (symbol && symbol->ValueIsAddress()) {
DumpAddress(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
symbol->GetAddressRef(), verbose, strm);
}
}
strm.IndentLess();
}
return 0;
return num_matches;
}
static void DumpSymbolContextList(ExecutionContextScope *exe_scope,

View File

@ -493,23 +493,19 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
switch (sect_type) {
case eSectionTypeData:
if (module_sp) {
SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab) {
const addr_t file_Addr = GetFileAddress();
Symbol *symbol =
symtab->FindSymbolContainingFileAddress(file_Addr);
if (symbol) {
const char *symbol_name = symbol->GetName().AsCString();
if (symbol_name) {
s->PutCString(symbol_name);
addr_t delta =
file_Addr - symbol->GetAddressRef().GetFileAddress();
if (delta)
s->Printf(" + %" PRIu64, delta);
showed_info = true;
}
if (Symtab *symtab = module_sp->GetSymtab()) {
const addr_t file_Addr = GetFileAddress();
Symbol *symbol =
symtab->FindSymbolContainingFileAddress(file_Addr);
if (symbol) {
const char *symbol_name = symbol->GetName().AsCString();
if (symbol_name) {
s->PutCString(symbol_name);
addr_t delta =
file_Addr - symbol->GetAddressRef().GetFileAddress();
if (delta)
s->Printf(" + %" PRIu64, delta);
showed_info = true;
}
}
}
@ -1003,10 +999,9 @@ AddressClass Address::GetAddressClass() const {
if (module_sp) {
ObjectFile *obj_file = module_sp->GetObjectFile();
if (obj_file) {
// Give the symbol vendor a chance to add to the unified section list
// and to symtab from symbol file
if (SymbolVendor *vendor = module_sp->GetSymbolVendor())
vendor->GetSymtab();
// Give the symbol file a chance to add to the unified section list
// and to the symtab.
module_sp->GetSymtab();
return obj_file->GetAddressClass(GetFileAddress());
}
}

View File

@ -1061,6 +1061,12 @@ SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
return nullptr;
}
Symtab *Module::GetSymtab() {
if (SymbolFile *symbols = GetSymbolFile())
return symbols->GetSymtab();
return nullptr;
}
void Module::SetFileSpecAndObjectName(const FileSpec &file,
ConstString object_name) {
// Container objects whose paths do not specify a file directly can call this
@ -1231,9 +1237,8 @@ void Module::Dump(Stream *s) {
if (objfile)
objfile->Dump(s);
SymbolVendor *symbols = GetSymbolVendor();
if (symbols)
symbols->Dump(s);
if (SymbolFile *symbols = GetSymbolFile())
symbols->Dump(*s);
s->IndentLess();
}
@ -1309,13 +1314,9 @@ const Symbol *Module::FindFirstSymbolWithNameAndType(ConstString name,
Timer scoped_timer(
func_cat, "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
name.AsCString(), symbol_type);
SymbolVendor *sym_vendor = GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab)
return symtab->FindFirstSymbolWithNameAndType(
name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
}
if (Symtab *symtab = GetSymtab())
return symtab->FindFirstSymbolWithNameAndType(
name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
return nullptr;
}
void Module::SymbolIndicesToSymbolContextList(
@ -1343,12 +1344,8 @@ size_t Module::FindFunctionSymbols(ConstString name,
Timer scoped_timer(func_cat,
"Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
name.AsCString(), name_type_mask);
SymbolVendor *sym_vendor = GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab)
return symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
}
if (Symtab *symtab = GetSymtab())
return symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
return 0;
}
@ -1363,14 +1360,10 @@ size_t Module::FindSymbolsWithNameAndType(ConstString name,
func_cat, "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
name.AsCString(), symbol_type);
const size_t initial_size = sc_list.GetSize();
SymbolVendor *sym_vendor = GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab) {
std::vector<uint32_t> symbol_indexes;
symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
}
if (Symtab *symtab = GetSymtab()) {
std::vector<uint32_t> symbol_indexes;
symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
}
return sc_list.GetSize() - initial_size;
}
@ -1387,16 +1380,12 @@ size_t Module::FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
"Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
regex.GetText().str().c_str(), symbol_type);
const size_t initial_size = sc_list.GetSize();
SymbolVendor *sym_vendor = GetSymbolVendor();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab) {
std::vector<uint32_t> symbol_indexes;
symtab->FindAllSymbolsMatchingRexExAndType(
regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
symbol_indexes);
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
}
if (Symtab *symtab = GetSymtab()) {
std::vector<uint32_t> symbol_indexes;
symtab->FindAllSymbolsMatchingRexExAndType(
regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
symbol_indexes);
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
}
return sc_list.GetSize() - initial_size;
}

View File

@ -370,22 +370,18 @@ bool DynamicLoaderMacOS::SetNotificationBreakpoint() {
addr_t
DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule(Module *module) {
SymbolContext sc;
SymbolVendor *sym_vendor = module->GetSymbolVendor();
Target &target = m_process->GetTarget();
if (sym_vendor) {
Symtab *symtab = sym_vendor->GetSymtab();
if (symtab) {
std::vector<uint32_t> match_indexes;
ConstString g_symbol_name("_dyld_global_lock_held");
uint32_t num_matches = 0;
num_matches =
symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
if (num_matches == 1) {
Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
if (symbol &&
(symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
}
if (Symtab *symtab = module->GetSymtab()) {
std::vector<uint32_t> match_indexes;
ConstString g_symbol_name("_dyld_global_lock_held");
uint32_t num_matches = 0;
num_matches =
symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
if (num_matches == 1) {
Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
if (symbol &&
(symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
}
}
}

View File

@ -244,6 +244,9 @@ void SymbolFile::Dump(Stream &s) {
}
}
s.PutChar('\n');
if (Symtab *symtab = GetSymtab())
symtab->Dump(&s, nullptr, eSortOrderNone);
}
SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;

View File

@ -263,12 +263,6 @@ void SymbolVendor::Dump(Stream *s) {
s->EOL();
if (m_sym_file_up)
m_sym_file_up->Dump(*s);
s->IndentMore();
if (Symtab *symtab = GetSymtab())
symtab->Dump(s, nullptr, eSortOrderNone);
s->IndentLess();
}
}
@ -288,12 +282,6 @@ FileSpec SymbolVendor::GetMainFileSpec() const {
return FileSpec();
}
Symtab *SymbolVendor::GetSymtab() {
if (m_sym_file_up)
return m_sym_file_up->GetSymtab();
return nullptr;
}
void SymbolVendor::SectionFileAddressesChanged() {
if (m_sym_file_up)
m_sym_file_up->SectionFileAddressesChanged();