https://github.com/speednoisemovement updated 
https://github.com/llvm/llvm-project/pull/180612

>From 71d284289d163859d1bdbd08b878b80d2f399c34 Mon Sep 17 00:00:00 2001
From: Leonard Grey <[email protected]>
Date: Mon, 9 Feb 2026 14:37:45 -0500
Subject: [PATCH 1/3] [LLDB][NativePDB] Add local constant support

---
 .../NativePDB/SymbolFileNativePDB.cpp         | 74 +++++++++++++------
 .../NativePDB/SymbolFileNativePDB.h           |  6 +-
 .../NativePDB/Inputs/local-constant.lldbinit  |  4 +
 .../SymbolFile/NativePDB/local-constant.cpp   | 16 ++++
 4 files changed, 76 insertions(+), 24 deletions(-)
 create mode 100644 
lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit
 create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp

diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 7e39af7d32e2f..67e5cefc59e8c 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -2196,32 +2196,55 @@ 
SymbolFileNativePDB::ParseVariablesForCompileUnit(CompileUnit &comp_unit,
 
 VariableSP SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
                                                     PdbCompilandSymId var_id,
-                                                    bool is_param) {
+                                                    bool is_param,
+                                                    bool is_constant) {
   ModuleSP module = GetObjectFile()->GetModule();
   Block *block = GetOrCreateBlock(scope_id);
   if (!block)
     return nullptr;
 
-  // Get function block.
-  Block *func_block = block;
-  while (func_block->GetParent()) {
-    func_block = func_block->GetParent();
-  }
-
-  Address addr;
-  func_block->GetStartAddress(addr);
-  VariableInfo var_info =
-      GetVariableLocationInfo(*m_index, var_id, *func_block, module);
-  Function *func = func_block->CalculateSymbolContextFunction();
-  if (!func)
-    return nullptr;
-  // Use empty dwarf expr if optimized away so that it won't be filtered out
-  // when lookuping local variables in this scope.
-  if (!var_info.location.IsValid())
-    var_info.location = DWARFExpressionList(module, DWARFExpression(), 
nullptr);
-  var_info.location.SetFuncFileAddress(func->GetAddress().GetFileAddress());
   CompilandIndexItem *cii = m_index->compilands().GetCompiland(var_id.modi);
+  if (!cii)
+    return nullptr;
   CompUnitSP comp_unit_sp = GetOrCreateCompileUnit(*cii);
+
+  VariableInfo var_info;
+  bool location_is_constant_data = is_constant;
+
+  if (is_constant) {
+    CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(var_id.offset);
+    lldbassert(sym.kind() == S_CONSTANT);
+    ConstantSym constant(sym.kind());
+    cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(sym, constant));
+
+    var_info.name = constant.Name;
+    var_info.type = constant.Type;
+    var_info.location = DWARFExpressionList(
+        module,
+        MakeConstantLocationExpression(constant.Type, m_index->tpi(),
+                                       constant.Value, module),
+        nullptr);
+  } else {
+    // Get function block.
+    Block *func_block = block;
+    while (func_block->GetParent()) {
+      func_block = func_block->GetParent();
+    }
+
+    Address addr;
+    func_block->GetStartAddress(addr);
+    var_info = GetVariableLocationInfo(*m_index, var_id, *func_block, module);
+    Function *func = func_block->CalculateSymbolContextFunction();
+    if (!func)
+      return nullptr;
+    // Use empty dwarf expr if optimized away so that it won't be filtered out
+    // when lookuping local variables in this scope.
+    if (!var_info.location.IsValid())
+      var_info.location =
+          DWARFExpressionList(module, DWARFExpression(), nullptr);
+    var_info.location.SetFuncFileAddress(func->GetAddress().GetFileAddress());
+  }
+
   TypeSP type_sp = GetOrCreateType(var_info.type);
   if (!type_sp)
     return nullptr;
@@ -2235,7 +2258,6 @@ VariableSP 
SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
       is_param ? eValueTypeVariableArgument : eValueTypeVariableLocal;
   bool external = false;
   bool artificial = false;
-  bool location_is_constant_data = false;
   bool static_member = false;
   Variable::RangeList scope_ranges;
   VariableSP var_sp = std::make_shared<Variable>(
@@ -2257,12 +2279,13 @@ VariableSP 
SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
 }
 
 VariableSP SymbolFileNativePDB::GetOrCreateLocalVariable(
-    PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param) {
+    PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param,
+    bool is_constant) {
   auto iter = m_local_variables.find(toOpaqueUid(var_id));
   if (iter != m_local_variables.end())
     return iter->second;
 
-  return CreateLocalVariable(scope_id, var_id, is_param);
+  return CreateLocalVariable(scope_id, var_id, is_param, is_constant);
 }
 
 TypeSP SymbolFileNativePDB::CreateTypedef(PdbGlobalSymId id) {
@@ -2390,6 +2413,13 @@ size_t 
SymbolFileNativePDB::ParseVariablesForBlock(PdbCompilandSymId block_id) {
       if (variable)
         variables->AddVariableIfUnique(variable);
       break;
+    case S_CONSTANT:
+      variable = GetOrCreateLocalVariable(block_id, child_sym_id,
+                                          /*is_param=*/false,
+                                          /*is_constant=*/true);
+      if (variable)
+        variables->AddVariableIfUnique(variable);
+      break;
     default:
       break;
     }
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h 
b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
index 11b982e6fc67e..4d5d9fb58bcac 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
@@ -236,14 +236,16 @@ class SymbolFileNativePDB : public SymbolFileCommon {
   Block *GetOrCreateBlock(PdbCompilandSymId block_id);
   lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id,
                                             PdbCompilandSymId var_id,
-                                            bool is_param);
+                                            bool is_param,
+                                            bool is_constant = false);
   lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id);
 
   lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id,
                                   CompileUnit &comp_unit);
   Block *CreateBlock(PdbCompilandSymId block_id);
   lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id,
-                                       PdbCompilandSymId var_id, bool 
is_param);
+                                       PdbCompilandSymId var_id, bool is_param,
+                                       bool is_constant = false);
   lldb::TypeSP CreateTypedef(PdbGlobalSymId id);
   lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci);
   lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct);
diff --git 
a/lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit 
b/lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit
new file mode 100644
index 0000000000000..d06ecdd1f3891
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit
@@ -0,0 +1,4 @@
+break set -n main
+run
+frame variable
+quit
diff --git a/lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp 
b/lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp
new file mode 100644
index 0000000000000..ef76813715eb9
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp
@@ -0,0 +1,16 @@
+// clang-format off
+// REQUIRES: msvc
+
+// Test that we can display local S_CONSTANT records.
+// MSVC emits S_CONSTANT for static const locals; clang-cl does not.
+
+// RUN: %build --compiler=msvc --nodefaultlib -o %t.exe -- %s
+// RUN: %lldb  -o "settings set stop-line-count-after 0" \
+// RUN:   -f %t.exe -s %p/Inputs/local-constant.lldbinit 2>&1 | FileCheck %s
+
+int main() {
+  static const int kConstant = 42;
+  return kConstant;
+}
+
+// CHECK: (const int) {{.*}}kConstant = 42

>From 20881d5aa58e968b49ec5412162240d6b3c5e4e5 Mon Sep 17 00:00:00 2001
From: Leonard Grey <[email protected]>
Date: Mon, 9 Feb 2026 16:04:59 -0500
Subject: [PATCH 2/3] Format

---
 .../Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp   | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 67e5cefc59e8c..edd881fed4370 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -2278,9 +2278,10 @@ VariableSP 
SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
   return var_sp;
 }
 
-VariableSP SymbolFileNativePDB::GetOrCreateLocalVariable(
-    PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param,
-    bool is_constant) {
+VariableSP
+SymbolFileNativePDB::GetOrCreateLocalVariable(PdbCompilandSymId scope_id,
+                                              PdbCompilandSymId var_id,
+                                              bool is_param, bool is_constant) 
{
   auto iter = m_local_variables.find(toOpaqueUid(var_id));
   if (iter != m_local_variables.end())
     return iter->second;

>From 78bce142af7797818773daf39f15689babc22ae7 Mon Sep 17 00:00:00 2001
From: Leonard Grey <[email protected]>
Date: Tue, 10 Feb 2026 10:37:33 -0500
Subject: [PATCH 3/3] Use split-file

---
 .../NativePDB/Inputs/local-constant.lldbinit  |  4 ----
 .../SymbolFile/NativePDB/local-constant.cpp   | 16 -------------
 .../SymbolFile/NativePDB/local-constant.test  | 24 +++++++++++++++++++
 3 files changed, 24 insertions(+), 20 deletions(-)
 delete mode 100644 
lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit
 delete mode 100644 lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp
 create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/local-constant.test

diff --git 
a/lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit 
b/lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit
deleted file mode 100644
index d06ecdd1f3891..0000000000000
--- a/lldb/test/Shell/SymbolFile/NativePDB/Inputs/local-constant.lldbinit
+++ /dev/null
@@ -1,4 +0,0 @@
-break set -n main
-run
-frame variable
-quit
diff --git a/lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp 
b/lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp
deleted file mode 100644
index ef76813715eb9..0000000000000
--- a/lldb/test/Shell/SymbolFile/NativePDB/local-constant.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// clang-format off
-// REQUIRES: msvc
-
-// Test that we can display local S_CONSTANT records.
-// MSVC emits S_CONSTANT for static const locals; clang-cl does not.
-
-// RUN: %build --compiler=msvc --nodefaultlib -o %t.exe -- %s
-// RUN: %lldb  -o "settings set stop-line-count-after 0" \
-// RUN:   -f %t.exe -s %p/Inputs/local-constant.lldbinit 2>&1 | FileCheck %s
-
-int main() {
-  static const int kConstant = 42;
-  return kConstant;
-}
-
-// CHECK: (const int) {{.*}}kConstant = 42
diff --git a/lldb/test/Shell/SymbolFile/NativePDB/local-constant.test 
b/lldb/test/Shell/SymbolFile/NativePDB/local-constant.test
new file mode 100644
index 0000000000000..83d376312a295
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/NativePDB/local-constant.test
@@ -0,0 +1,24 @@
+# REQUIRES: msvc
+
+# Test that we can display local S_CONSTANT records.
+# MSVC emits S_CONSTANT for static const locals; clang-cl does not.
+# RUN: split-file %s %t
+# RUN: %build --compiler=msvc --nodefaultlib -o %t.exe -- %t/main.cpp
+# RUN: %lldb -f %t.exe -s %t/commands.input 2>&1 | FileCheck %s
+
+#--- main.cpp
+
+int main() {
+  static const int kConstant = 42;
+  return kConstant;
+}
+
+#--- commands.input
+
+settings set stop-line-count-after 0
+break set -n main
+run
+frame variable
+quit
+
+# CHECK: (const int) {{.*}}kConstant = 42

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to