[PATCH] D44253: [SymbolFilePDB] Rewrite ParseTypes method

Aaron Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 8 08:34:36 PST 2018


asmith created this revision.
asmith added reviewers: zturner, rnk, lldb-commits.
Herald added a subscriber: llvm-commits.

The types for the compiland's children are parsed when parsing types for a PDB compiland. Global types also need to be parsed but unfortunately PDBs do not have compiland information about each global type. So we parse them all on the first call to ParseTypes.

If a sc.function is provided then parse the types for that function. Otherwise parse the types for the overall sc.comp_unit.

The ParseTypes method can be very slow if a program has a long list of compile units containing needed modules. Debugging clang-cl with lldb will show the problem.


Repository:
  rL LLVM

https://reviews.llvm.org/D44253

Files:
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp


Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -438,30 +438,59 @@
 
 size_t SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) {
   lldbassert(sc.module_sp.get());
+  if (!sc.comp_unit)
+    return 0;
+
   size_t num_added = 0;
-  auto results_up = m_session_up->getGlobalScope()->findAllChildren();
-  if (!results_up)
+  auto compiland = GetPDBCompilandByUID(sc.comp_unit->GetID());
+  if (!compiland)
     return 0;
-  while (auto symbol_up = results_up->getNext()) {
-    switch (symbol_up->getSymTag()) {
-    case PDB_SymType::Enum:
-    case PDB_SymType::UDT:
-    case PDB_SymType::Typedef:
-      break;
-    default:
-      continue;
-    }
 
-    auto type_uid = symbol_up->getSymIndexId();
-    if (m_types.find(type_uid) != m_types.end())
-      continue;
+  auto ParseTypesByTagFn = [&num_added, this](const PDBSymbol &raw_sym) {
+    std::unique_ptr<IPDBEnumSymbols> results;
+    PDB_SymType tags_to_search[] = { PDB_SymType::Enum, PDB_SymType::Typedef,
+        PDB_SymType::UDT };
+    for (auto tag : tags_to_search) {
+      results = raw_sym.findAllChildren(tag);
+      if (!results || results->getChildCount() == 0)
+        continue;
+      while (auto symbol = results->getNext()) {
+        switch (symbol->getSymTag()) {
+        case PDB_SymType::Enum:
+        case PDB_SymType::UDT:
+        case PDB_SymType::Typedef:
+          break;
+        default:
+          continue;
+        }
 
-    // This should cause the type to get cached and stored in the `m_types`
-    // lookup.
-    if (!ResolveTypeUID(symbol_up->getSymIndexId()))
-      continue;
+        // This should cause the type to get cached and stored in the `m_types`
+        // lookup.
+        if (!ResolveTypeUID(symbol->getSymIndexId()))
+          continue;
 
-    ++num_added;
+        ++num_added;
+      }
+    }
+  };
+
+  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;
+    }
   }
   return num_added;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44253.137579.patch
Type: text/x-patch
Size: 2695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180308/98e26336/attachment.bin>


More information about the llvm-commits mailing list