[Lldb-commits] [lldb] d962cab - [lldb][NativePDB] Look up global variables by qualified name (#230134)

via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 9 07:57:32 PDT 2026


Author: Charles Zablit
Date: 2026-10-09T15:57:26+01:00
New Revision: d962cab045bea431119c08adcce9c88f30625697

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

LOG: [lldb][NativePDB] Look up global variables by qualified name (#230134)

`SymbolFileNativePDB::FindGlobalVariables` looks the name up in an index
keyed by basename, so a qualified name such as `A::g_points` never
matches (`target variable A::g_points` fails with `"can't find global
variable"`).

This patch splits the name with
`CPlusPlusLanguage::ExtractContextAndIdentifier`, looks up the basename,
and when the name was qualified only keeps variables whose qualified
name contains it, as `SymbolFileDWARF::FindGlobalVariables` does.

Fixes `TestStaticVariables` with PDB debug info.

rdar://189618458

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    lldb/test/API/lang/cpp/class_static/TestStaticVariables.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index ad77a321dad2b1..6a1d368b40b492 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -9,6 +9,7 @@
 #include "SymbolFileNativePDB.h"
 
 #include "Plugins/ExpressionParser/Clang/ClangUtil.h"
+#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
 #include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h"
 #include "Plugins/ObjectFile/PDB/ObjectFilePDB.h"
 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
@@ -2223,8 +2224,14 @@ void SymbolFileNativePDB::FindGlobalVariables(
 
   CacheGlobalBaseNames();
 
+  llvm::StringRef context;
+  llvm::StringRef basename;
+  if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name.GetStringRef(),
+                                                      context, basename))
+    basename = name.GetStringRef();
+
   std::vector<uint32_t> results;
-  m_global_variable_base_names.GetValues(name, results);
+  m_global_variable_base_names.GetValues(ConstString(basename), results);
 
   size_t n_matches = 0;
   for (uint32_t gid : results) {
@@ -2237,6 +2244,9 @@ void SymbolFileNativePDB::FindGlobalVariables(
     VariableSP var = GetOrCreateGlobalVariable(global);
     if (!var)
       continue;
+    if (!context.empty() &&
+        !var->GetName().GetStringRef().contains(name.GetStringRef()))
+      continue;
     variables.AddVariable(var);
 
     if (++n_matches >= max_matches)

diff  --git a/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py b/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
index 145d1b70d706a3..efd0a9159ea32d 100644
--- a/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
+++ b/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
@@ -9,6 +9,8 @@
 
 
 class StaticVariableTestCase(TestBase):
+    TEST_WITH_PDB_DEBUG_INFO = True
+
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)


        


More information about the lldb-commits mailing list