[Lldb-commits] [lldb] r367820 - Remove SymbolVendor::GetSymtab

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 5 02:21:47 PDT 2019


Author: labath
Date: Mon Aug  5 02:21:47 2019
New Revision: 367820

URL: http://llvm.org/viewvc/llvm-project?rev=367820&view=rev
Log:
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

Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Symbol/SymbolVendor.h
    lldb/trunk/source/API/SBModule.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Address.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
    lldb/trunk/source/Symbol/SymbolFile.cpp
    lldb/trunk/source/Symbol/SymbolVendor.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Mon Aug  5 02:21:47 2019
@@ -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

Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Mon Aug  5 02:21:47 2019
@@ -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();

Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Mon Aug  5 02:21:47 2019
@@ -290,11 +290,8 @@ SBSymbolContextList SBModule::FindCompil
 }
 
 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;
 }
 

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Mon Aug  5 02:21:47 2019
@@ -1447,15 +1447,11 @@ static size_t DumpModuleObjfileHeaders(S
 
 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(Com
                                      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);
-        }
-
-        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;
-        }
+  Symtab *symtab = module->GetSymtab();
+  if (!symtab)
+    return 0;
+
+  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,

Modified: lldb/trunk/source/Core/Address.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/Core/Address.cpp (original)
+++ lldb/trunk/source/Core/Address.cpp Mon Aug  5 02:21:47 2019
@@ -493,23 +493,19 @@ bool Address::Dump(Stream *s, ExecutionC
         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()
   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());
     }
   }

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon Aug  5 02:21:47 2019
@@ -1061,6 +1061,12 @@ SymbolFile *Module::GetSymbolFile(bool c
   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::FindFirstSymbolWit
   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(Const
   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::FindSymbolsWithNameAndTyp
       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::FindSymbolsMatchingRegExA
       "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;
 }

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp Mon Aug  5 02:21:47 2019
@@ -370,22 +370,18 @@ bool DynamicLoaderMacOS::SetNotification
 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);
       }
     }
   }

Modified: lldb/trunk/source/Symbol/SymbolFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolFile.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolFile.cpp Mon Aug  5 02:21:47 2019
@@ -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;

Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=367820&r1=367819&r2=367820&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Mon Aug  5 02:21:47 2019
@@ -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()
   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();




More information about the lldb-commits mailing list