diff options
author | Pavel Labath <pavel@labath.sk> | 2019-08-05 09:21:47 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-08-05 09:21:47 +0000 |
commit | d5d47a3574823635fddef3bba3de37e2a5ea0d76 (patch) | |
tree | 1f0f9b4cde535e98639ac220cb6f45e80aab4dfd /lldb | |
parent | 8ed8353fc45e3906f7fd8dde1072bce7b54aca62 (diff) | |
download | bcm5719-llvm-d5d47a3574823635fddef3bba3de37e2a5ea0d76.tar.gz bcm5719-llvm-d5d47a3574823635fddef3bba3de37e2a5ea0d76.zip |
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
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/include/lldb/Core/Module.h | 2 | ||||
-rw-r--r-- | lldb/include/lldb/Symbol/SymbolVendor.h | 3 | ||||
-rw-r--r-- | lldb/source/API/SBModule.cpp | 14 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 83 | ||||
-rw-r--r-- | lldb/source/Core/Address.cpp | 37 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 57 | ||||
-rw-r--r-- | lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp | 26 | ||||
-rw-r--r-- | lldb/source/Symbol/SymbolFile.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Symbol/SymbolVendor.cpp | 12 |
9 files changed, 97 insertions, 140 deletions
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index 4064d266d0d..999e15dab11 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -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 diff --git a/lldb/include/lldb/Symbol/SymbolVendor.h b/lldb/include/lldb/Symbol/SymbolVendor.h index 1210273dd9c..cfa7c4b92f3 100644 --- a/lldb/include/lldb/Symbol/SymbolVendor.h +++ b/lldb/include/lldb/Symbol/SymbolVendor.h @@ -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(); diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index e3c48cfcecc..6f856de53a1 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -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; } diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 1c75966552a..5535a50f0c8 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -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, diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp index 84ff4ec5b07..a3912bef5a6 100644 --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -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()); } } diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index a926e4ade84..58a09275a9b 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -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 ®ex, "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; } diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp index 057c20f1fb2..aab0e126a0f 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -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); } } } diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp index afc2abbcb4d..d59945962b0 100644 --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -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; diff --git a/lldb/source/Symbol/SymbolVendor.cpp b/lldb/source/Symbol/SymbolVendor.cpp index 8027892006d..929cb3eb648 100644 --- a/lldb/source/Symbol/SymbolVendor.cpp +++ b/lldb/source/Symbol/SymbolVendor.cpp @@ -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(); |