[Lldb-commits] [lldb] 0cfcd38 - [lldb][NativePDB] Parse global variables. (#114303)

via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 1 11:15:57 PDT 2024


Author: Zequan Wu
Date: 2024-11-01T14:15:54-04:00
New Revision: 0cfcd387f968f2c9de0648673b5db9e221e5c84e

URL: https://github.com/llvm/llvm-project/commit/0cfcd387f968f2c9de0648673b5db9e221e5c84e
DIFF: https://github.com/llvm/llvm-project/commit/0cfcd387f968f2c9de0648673b5db9e221e5c84e.diff

LOG: [lldb][NativePDB] Parse global variables. (#114303)

This doesn't parse S_CONSTANT case yet, because I found that the global
variable `std::strong_ordering::equal` is a S_CONSTANT and has type of
LF_STRUCTURE which is not currently handled when creating dwarf
expression for the variable. Left a TODO for it to finish later.

This makes `lldb/test/Shell/SymbolFile/PDB/ast-restore.test` and
`lldb/test/Shell/SymbolFile/PDB/calling-conventions-x86.test` pass on
windows with native pdb plugin only.

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
    lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
    lldb/test/Shell/SymbolFile/PDB/ast-restore.test

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 7fded6a31a3af5..c784c2e28f6452 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -888,9 +888,9 @@ VariableSP SymbolFileNativePDB::CreateGlobalVariable(PdbGlobalSymId var_id) {
 
   CompUnitSP comp_unit;
   std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(addr);
-  if (!modi) {
+  // Some globals has modi points to the linker module, ignore them.
+  if (!modi || modi >= GetNumCompileUnits())
     return nullptr;
-  }
 
   CompilandIndexItem &cci = m_index->compilands().GetOrCreateCompiland(*modi);
   comp_unit = GetOrCreateCompileUnit(cci);
@@ -1810,7 +1810,27 @@ SymbolFileNativePDB::ParseVariablesForCompileUnit(CompileUnit &comp_unit,
                                                   VariableList &variables) {
   PdbSymUid sym_uid(comp_unit.GetID());
   lldbassert(sym_uid.kind() == PdbSymUidKind::Compiland);
-  return 0;
+  for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
+    PdbGlobalSymId global{gid, false};
+    CVSymbol sym = m_index->ReadSymbolRecord(global);
+    // TODO: S_CONSTANT is not handled here to prevent a possible crash in
+    // lldb_private::npdb::MakeConstantLocationExpression when it's a record
+    // type (e.g. std::strong_ordering::equal). That function needs to be
+    // updated to handle this case when we add S_CONSTANT case here.
+    switch (sym.kind()) {
+    case SymbolKind::S_GDATA32:
+    case SymbolKind::S_LDATA32:
+    case SymbolKind::S_GTHREAD32:
+    case SymbolKind::S_LTHREAD32: {
+      if (VariableSP var = GetOrCreateGlobalVariable(global))
+        variables.AddVariable(var);
+      break;
+    }
+    default:
+      break;
+    }
+  }
+  return variables.GetSize();
 }
 
 VariableSP SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,

diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp b/lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
index 91bd5bb810c8e3..c90eaefe298035 100644
--- a/lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
+++ b/lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
@@ -44,8 +44,7 @@ int main(int argc, char **argv) {
 // AST: |   |-ParmVarDecl {{.*}} 'char'
 // AST: |   `-ParmVarDecl {{.*}} 'int'
 
-// SYMBOL:      int main(int argc, char **argv);
-// SYMBOL-NEXT: struct Struct {
+// SYMBOL:      struct Struct {
 // SYMBOL-NEXT:     void simple_method();
 // SYMBOL-NEXT:     static void static_method();
 // SYMBOL-NEXT:     virtual void virtual_method();
@@ -53,3 +52,5 @@ int main(int argc, char **argv) {
 // SYMBOL-NEXT:     int overloaded_method(char);
 // SYMBOL-NEXT:     int overloaded_method(char, int, ...);
 // SYMBOL-NEXT: };
+// SYMBOL-NEXT: Struct s;
+// SYMBOL-NEXT: int main(int argc, char **argv);

diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp b/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
index 5f6c68d69023ef..e34e6eb7bf54a1 100644
--- a/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
+++ b/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
@@ -18,13 +18,14 @@ int main() {
   return 0;
 }
 
-// CHECK:      static void B::`dynamic initializer for 'glob'();
+// CHECK:      struct A {
+// CHECK-NEXT:     ~A();
+// CHECK-NEXT: };
+// CHECK-NEXT: A B::glob;
+// CHECK-NEXT: static void B::`dynamic initializer for 'glob'();
 // CHECK-NEXT: static void B::`dynamic atexit destructor for 'glob'();
 // CHECK-NEXT: int main();
 // CHECK-NEXT: static void _GLOBAL__sub_I_global_ctor_dtor.cpp();
-// CHECK-NEXT: struct A {
-// CHECK-NEXT:     ~A();
-// CHECK-NEXT: };
 // CHECK-NEXT: struct B {
 // CHECK-NEXT:     static A glob;
 // CHECK-NEXT: };

diff  --git a/lldb/test/Shell/SymbolFile/PDB/ast-restore.test b/lldb/test/Shell/SymbolFile/PDB/ast-restore.test
index a2597c46ba31b2..a91364bbbee632 100644
--- a/lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ b/lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -25,12 +25,7 @@ ENUM:         }
 ENUM:     }
 ENUM: }
 
-GLOBAL: Module: {{.*}}
-GLOBAL: namespace N0 {
-GLOBAL:     namespace N1 {
-GLOBAL:         N0::N1::(anonymous namespace)::Enum Global;
-GLOBAL:     }
-GLOBAL: }
+GLOBAL: N0::N1::(anonymous namespace)::Enum {{.*}}Global;
 
 BASE: Module: {{.*}}
 BASE: namespace N0 {
@@ -77,7 +72,7 @@ INNER: }
 
 TEMPLATE: Module: {{.*}}
 TEMPLATE: struct Template<N0::N1::Class> {
-TEMPLATE:     inline void TemplateFunc<1>();
+TEMPLATE:     void TemplateFunc<1>();
 TEMPLATE: };
 
 FOO: Module: {{.*}}


        


More information about the lldb-commits mailing list