[Lldb-commits] [lldb] r350889 - Change SymbolFile::ParseTypes to ParseTypesForCompileUnit.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 10 12:57:50 PST 2019


Author: zturner
Date: Thu Jan 10 12:57:50 2019
New Revision: 350889

URL: http://llvm.org/viewvc/llvm-project?rev=350889&view=rev
Log:
Change SymbolFile::ParseTypes to ParseTypesForCompileUnit.

The function SymbolFile::ParseTypes previously accepted a SymbolContext.
This makes it extremely difficult to implement faithfully, because you
have to account for all possible combinations of members being set in
the SymbolContext. On the other hand, no clients of this function
actually care about implementing this function to this strict of a
standard. AFAICT, there is actually only 1 client in the entire
codebase, and it is the function ParseAllDebugSymbols, which is itself
only called for testing purposes when dumping information. At this
call-site, the only field it sets is the CompileUnit, meaning that an
implementer of a SymbolFile need not worry about any examining or
handling any other fields which might be set.

By restricting this API to accept exactly a CompileUnit& and nothing
more, we can simplify the life of new SymbolFile plugin implementers by
making it clear exactly what the necessary and sufficient set of
functionality they need to implement is, while at the same time removing
some dead code that tried to handle other types of SymbolContext fields
that were never going to be set anyway.

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

Modified:
    lldb/trunk/include/lldb/Symbol/SymbolFile.h
    lldb/trunk/include/lldb/Symbol/SymbolVendor.h
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
    lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
    lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
    lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
    lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
    lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
    lldb/trunk/source/Symbol/SymbolVendor.cpp

Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Thu Jan 10 12:57:50 2019
@@ -140,7 +140,7 @@ public:
   ParseImportedModules(const SymbolContext &sc,
                        std::vector<ConstString> &imported_modules) = 0;
   virtual size_t ParseFunctionBlocks(const SymbolContext &sc) = 0;
-  virtual size_t ParseTypes(const SymbolContext &sc) = 0;
+  virtual size_t ParseTypesForCompileUnit(CompileUnit &comp_unit) = 0;
   virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0;
   virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0;
 

Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Thu Jan 10 12:57:50 2019
@@ -64,7 +64,7 @@ public:
 
   virtual size_t ParseFunctionBlocks(const SymbolContext &sc);
 
-  virtual size_t ParseTypes(const SymbolContext &sc);
+  virtual size_t ParseTypesForCompileUnit(CompileUnit &comp_unit);
 
   virtual size_t ParseVariablesForContext(const SymbolContext &sc);
 

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Thu Jan 10 12:57:50 2019
@@ -380,8 +380,7 @@ void Module::ParseAllDebugSymbols() {
       });
 
       // Parse all types for this compile unit
-      sc.function = nullptr;
-      symbols->ParseTypes(sc);
+      symbols->ParseTypesForCompileUnit(*sc.comp_unit);
     }
   }
 }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Jan 10 12:57:50 2019
@@ -3149,24 +3149,16 @@ size_t SymbolFileDWARF::ParseFunctionBlo
   return functions_added;
 }
 
-size_t SymbolFileDWARF::ParseTypes(const SymbolContext &sc) {
+size_t SymbolFileDWARF::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
   ASSERT_MODULE_LOCK(this);
-  // At least a compile unit must be valid
-  assert(sc.comp_unit);
   size_t types_added = 0;
-  DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
+  DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
   if (dwarf_cu) {
-    if (sc.function) {
-      dw_offset_t function_die_offset = sc.function->GetID();
-      DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset);
-      if (func_die && func_die.HasChildren()) {
-        types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true);
-      }
-    } else {
-      DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
-      if (dwarf_cu_die && dwarf_cu_die.HasChildren()) {
-        types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
-      }
+    DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
+    if (dwarf_cu_die && dwarf_cu_die.HasChildren()) {
+      SymbolContext sc;
+      sc.comp_unit = &comp_unit;
+      types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
     }
   }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Thu Jan 10 12:57:50 2019
@@ -131,7 +131,8 @@ public:
 
   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
 
-  size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
+  size_t
+  ParseTypesForCompileUnit(lldb_private::CompileUnit &comp_unit) override;
 
   size_t
   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Thu Jan 10 12:57:50 2019
@@ -678,10 +678,13 @@ size_t SymbolFileDWARFDebugMap::ParseFun
   return 0;
 }
 
-size_t SymbolFileDWARFDebugMap::ParseTypes(const SymbolContext &sc) {
+size_t
+SymbolFileDWARFDebugMap::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
+  SymbolContext sc;
+  sc.comp_unit = &comp_unit;
   SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
   if (oso_dwarf)
-    return oso_dwarf->ParseTypes(sc);
+    return oso_dwarf->ParseTypesForCompileUnit(comp_unit);
   return 0;
 }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Thu Jan 10 12:57:50 2019
@@ -72,7 +72,8 @@ public:
       const lldb_private::SymbolContext &sc,
       std::vector<lldb_private::ConstString> &imported_modules) override;
   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
-  size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
+  size_t
+  ParseTypesForCompileUnit(lldb_private::CompileUnit &comp_unit) override;
   size_t
   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
 

Modified: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp Thu Jan 10 12:57:50 2019
@@ -1274,7 +1274,7 @@ size_t SymbolFileNativePDB::FindTypesByN
   return match_count;
 }
 
-size_t SymbolFileNativePDB::ParseTypes(const SymbolContext &sc) {
+size_t SymbolFileNativePDB::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
   // Only do the full type scan the first time.
   if (m_done_full_type_scan)
     return 0;

Modified: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h Thu Jan 10 12:57:50 2019
@@ -104,7 +104,8 @@ public:
                                uint32_t max_matches,
                                VariableList &variables) override;
 
-  size_t ParseTypes(const SymbolContext &sc) override;
+  size_t
+  ParseTypesForCompileUnit(lldb_private::CompileUnit &comp_unit) override;
   size_t ParseVariablesForContext(const SymbolContext &sc) override;
 
   void AddSymbols(Symtab &symtab) override;

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp Thu Jan 10 12:57:50 2019
@@ -464,13 +464,10 @@ SymbolFilePDB::ParseFunctionBlocks(const
   return num_added;
 }
 
-size_t SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) {
-  lldbassert(sc.module_sp.get());
-  if (!sc.comp_unit)
-    return 0;
+size_t SymbolFilePDB::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
 
   size_t num_added = 0;
-  auto compiland = GetPDBCompilandByUID(sc.comp_unit->GetID());
+  auto compiland = GetPDBCompilandByUID(comp_unit.GetID());
   if (!compiland)
     return 0;
 
@@ -505,23 +502,15 @@ size_t SymbolFilePDB::ParseTypes(const l
     }
   };
 
-  if (sc.function) {
-    auto pdb_func = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(
-        sc.function->GetID());
-    if (!pdb_func)
-      return 0;
-    ParseTypesByTagFn(*pdb_func);
-  } else {
-    ParseTypesByTagFn(*compiland);
-
-    // Also parse global types particularly coming from this compiland.
-    // Unfortunately, PDB has no compiland information for each global type. We
-    // have to parse them all. But ensure we only do this once.
-    static bool parse_all_global_types = false;
-    if (!parse_all_global_types) {
-      ParseTypesByTagFn(*m_global_scope_up);
-      parse_all_global_types = true;
-    }
+  ParseTypesByTagFn(*compiland);
+
+  // Also parse global types particularly coming from this compiland.
+  // Unfortunately, PDB has no compiland information for each global type. We
+  // have to parse them all. But ensure we only do this once.
+  static bool parse_all_global_types = false;
+  if (!parse_all_global_types) {
+    ParseTypesByTagFn(*m_global_scope_up);
+    parse_all_global_types = true;
   }
   return num_added;
 }

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h Thu Jan 10 12:57:50 2019
@@ -81,7 +81,8 @@ public:
 
   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
 
-  size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
+  size_t
+  ParseTypesForCompileUnit(lldb_private::CompileUnit &comp_unit) override;
 
   size_t
   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;

Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp Thu Jan 10 12:57:50 2019
@@ -229,7 +229,9 @@ size_t SymbolFileSymtab::ParseFunctionBl
   return 0;
 }
 
-size_t SymbolFileSymtab::ParseTypes(const SymbolContext &sc) { return 0; }
+size_t SymbolFileSymtab::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
+  return 0;
+}
 
 size_t SymbolFileSymtab::ParseVariablesForContext(const SymbolContext &sc) {
   return 0;

Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h Thu Jan 10 12:57:50 2019
@@ -70,7 +70,8 @@ public:
 
   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
 
-  size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
+  size_t
+  ParseTypesForCompileUnit(lldb_private::CompileUnit &comp_unit) override;
 
   size_t
   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;

Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=350889&r1=350888&r2=350889&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Thu Jan 10 12:57:50 2019
@@ -200,12 +200,12 @@ size_t SymbolVendor::ParseFunctionBlocks
   return 0;
 }
 
-size_t SymbolVendor::ParseTypes(const SymbolContext &sc) {
+size_t SymbolVendor::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
   ModuleSP module_sp(GetModule());
   if (module_sp) {
     std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
     if (m_sym_file_ap.get())
-      return m_sym_file_ap->ParseTypes(sc);
+      return m_sym_file_ap->ParseTypesForCompileUnit(comp_unit);
   }
   return 0;
 }




More information about the lldb-commits mailing list