[Lldb-commits] [PATCH] D51967: [PDB] Use the raw PDB symbol interface more accurately

Aleksandr Urakov via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 12 01:34:54 PDT 2018


aleksandr.urakov created this revision.
aleksandr.urakov added a reviewer: zturner.
aleksandr.urakov added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch adds some symbol tag checks before using the `IPDBRawSymbol` interface to improve safety and readability.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D51967

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


Index: source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -269,23 +269,43 @@
 GetClassOrFunctionParent(const llvm::pdb::PDBSymbol &symbol) {
   const IPDBSession &session = symbol.getSession();
   const IPDBRawSymbol &raw = symbol.getRawSymbol();
+  auto tag = symbol.getSymTag();
 
-  auto class_parent_id = raw.getClassParentId();
-  if (auto class_parent = session.getSymbolById(class_parent_id))
-    return class_parent;
+  switch (tag) {
+  case PDB_SymType::Function:
+  case PDB_SymType::Data:
+  case PDB_SymType::UDT:
+  case PDB_SymType::Enum:
+  case PDB_SymType::FunctionSig:
+  case PDB_SymType::Typedef:
+  case PDB_SymType::BaseClass: {
+    auto class_parent_id = raw.getClassParentId();
+    if (auto class_parent = session.getSymbolById(class_parent_id))
+      return class_parent;
+  }
+  default:
+    break;
+  }
 
-  auto lexical_parent_id = raw.getLexicalParentId();
-  auto lexical_parent = session.getSymbolById(lexical_parent_id);
-  if (!lexical_parent)
-    return nullptr;
+  switch (tag) {
+  case PDB_SymType::Block:
+  case PDB_SymType::Data: {
+    auto lexical_parent_id = raw.getLexicalParentId();
+    auto lexical_parent = session.getSymbolById(lexical_parent_id);
+    if (!lexical_parent)
+      return nullptr;
 
-  auto lexical_parent_tag = lexical_parent->getSymTag();
-  if (lexical_parent_tag == PDB_SymType::Function)
-    return lexical_parent;
-  if (lexical_parent_tag == PDB_SymType::Exe)
-    return nullptr;
+    auto lexical_parent_tag = lexical_parent->getSymTag();
+    if (lexical_parent_tag == PDB_SymType::Function)
+      return lexical_parent;
+    if (lexical_parent_tag == PDB_SymType::Exe)
+      return nullptr;
 
-  return GetClassOrFunctionParent(*lexical_parent);
+    return GetClassOrFunctionParent(*lexical_parent);
+  }
+  default:
+    return nullptr;
+  }
 }
 
 clang::NamedDecl *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51967.165029.patch
Type: text/x-patch
Size: 2024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180912/f4b4a98f/attachment-0001.bin>


More information about the lldb-commits mailing list