[Lldb-commits] [lldb] [lldb-dap] Don't emit memory reference for constants (PR #197645)

via lldb-commits lldb-commits at lists.llvm.org
Thu May 14 03:08:02 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Sergei Druzhkov (DrSergei)

<details>
<summary>Changes</summary>

Some time ago I noticed that constants in Watch Window have meaningless memory references (their values were interpreted as load addresses). I am not an expert in LLDB internals, but hope it is correct fix.

---
Full diff: https://github.com/llvm/llvm-project/pull/197645.diff


2 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py (+1) 
- (modified) lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp (+7-3) 


``````````diff
diff --git a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
index 556168e5adfa8..328938b42b39f 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -155,6 +155,7 @@ def run_test_evaluate_expressions(
         self.assertEvaluate("non_static_int", "43", want_type="int")
         self.assertEvaluate("struct1.foo", "15", want_type="int")
         self.assertEvaluate("struct2->foo", "16", want_type="int")
+        self.assertEvaluate("10", "10", want_type="int", want_memref=False)
 
         if self.isResultExpandedDescription():
             self.assertEvaluate(
diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
index 7537eca72ec25..0917da637d8f7 100644
--- a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
@@ -118,6 +118,13 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
   if (value.GetError().Fail())
     return ToError(value.GetError(), /*show_user=*/false);
 
+  // Check original value type before calling `Persist`, because it change value
+  // type to const result
+  if (lldb::addr_t addr = value.GetLoadAddress();
+      value.GetValueType() != lldb::eValueTypeConstResult &&
+      addr != LLDB_INVALID_ADDRESS)
+    body.memoryReference = EncodeMemoryReference(addr);
+
   if (is_repl_context) {
     // save the new variable expression
     dap.last_valid_variable_expression = std::move(expression);
@@ -137,9 +144,6 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
     body.variablesReference = dap.reference_storage.Insert(
         value, /*is_permanent=*/is_repl_context, /*is_internal=*/false);
 
-  if (lldb::addr_t addr = value.GetLoadAddress(); addr != LLDB_INVALID_ADDRESS)
-    body.memoryReference = EncodeMemoryReference(addr);
-
   if (ValuePointsToCode(value) &&
       body.variablesReference.Kind() != eReferenceKindInvalid)
     body.valueLocationReference =

``````````

</details>


https://github.com/llvm/llvm-project/pull/197645


More information about the lldb-commits mailing list