Skip to content

Conversation

@DrSergei
Copy link
Contributor

This patch adds support for format option in the evaluate request according to DAP specification. Also, fixed typo in LLDB_DAP_INVALID_VARRERF constant.

@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2025

@llvm/pr-subscribers-lldb

Author: Sergei Druzhkov (DrSergei)

Changes

This patch adds support for format option in the evaluate request according to DAP specification. Also, fixed typo in LLDB_DAP_INVALID_VARRERF constant.


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

4 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py (+5-1)
  • (modified) lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py (+10-1)
  • (modified) lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp (+7-3)
  • (modified) lldb/tools/lldb-dap/Protocol/ProtocolTypes.h (+2-2)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index f85ab1910a2eb..306448602b48f 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -987,7 +987,9 @@ def request_writeMemory(self, memoryReference, data, offset=0, allowPartial=Fals
         }
         return self._send_recv(command_dict)
 
-    def request_evaluate(self, expression, frameIndex=0, threadId=None, context=None):
+    def request_evaluate(
+        self, expression, frameIndex=0, threadId=None, context=None, is_hex=None
+    ):
         stackFrame = self.get_stackFrame(frameIndex=frameIndex, threadId=threadId)
         if stackFrame is None:
             return []
@@ -997,6 +999,8 @@ def request_evaluate(self, expression, frameIndex=0, threadId=None, context=None
         }
         if context:
             args_dict["context"] = context
+        if is_hex is not None:
+            args_dict["format"] = {"hex": is_hex}
         command_dict = {
             "command": "evaluate",
             "type": "request",
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 3c233a5b43ebb..95573780e94bd 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -27,8 +27,11 @@ def assertEvaluate(
         want_varref=False,
         want_memref=True,
         want_locref=False,
+        is_hex=None,
     ):
-        resp = self.dap_server.request_evaluate(expression, context=self.context)
+        resp = self.dap_server.request_evaluate(
+            expression, context=self.context, is_hex=is_hex
+        )
         self.assertTrue(
             resp["success"], f"Failed to evaluate expression {expression!r}"
         )
@@ -132,6 +135,12 @@ def run_test_evaluate_expressions(
         if context == "repl":
             self.assertEvaluate("", "21", want_type="int")
             self.assertEvaluate("", "21", want_type="int")
+        self.assertEvaluate("static_int", "0x0000002a", want_type="int", is_hex=True)
+        self.assertEvaluate(
+            "non_static_int", "0x0000002b", want_type="int", is_hex=True
+        )
+        self.assertEvaluate("struct1.foo", "0x0000000f", want_type="int", is_hex=True)
+        self.assertEvaluate("struct2->foo", "0x00000010", want_type="int", is_hex=True)
         self.assertEvaluate("static_int", "42", want_type="int")
         self.assertEvaluate("non_static_int", "43", want_type="int")
         self.assertEvaluate("struct1.foo", "15", want_type="int")
diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
index ea8c3a2a4a296..637fc4be63bac 100644
--- a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
@@ -84,8 +84,12 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
   if (value.GetError().Fail())
     return ToError(value.GetError(), /*show_user=*/false);
 
-  VariableDescription desc(value,
-                           dap.configuration.enableAutoVariableSummaries);
+  bool hex = false;
+  if (arguments.format)
+    hex = arguments.format->hex;
+
+  VariableDescription desc(value, dap.configuration.enableAutoVariableSummaries,
+                           hex);
 
   body.result = desc.GetResult(arguments.context);
   body.type = desc.display_type_name;
@@ -98,7 +102,7 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
     body.memoryReference = EncodeMemoryReference(addr);
 
   if (ValuePointsToCode(value) &&
-      body.variablesReference != LLDB_DAP_INVALID_VARRERF)
+      body.variablesReference != LLDB_DAP_INVALID_VAR_REF)
     body.valueLocationReference = PackLocation(body.variablesReference, true);
 
   return body;
diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
index 690a1d684d0e9..ee103ddf0b7a2 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
@@ -28,7 +28,7 @@
 #include <optional>
 #include <string>
 
-#define LLDB_DAP_INVALID_VARRERF INT64_MAX
+#define LLDB_DAP_INVALID_VAR_REF INT64_MAX
 #define LLDB_DAP_INVALID_SRC_REF 0
 #define LLDB_DAP_INVALID_VALUE_LOC 0
 
@@ -462,7 +462,7 @@ struct Scope {
   /// remains suspended. See 'Lifetime of Object References' in the Overview
   /// section for details.
   ////
-  uint64_t variablesReference = LLDB_DAP_INVALID_VARRERF;
+  uint64_t variablesReference = LLDB_DAP_INVALID_VAR_REF;
 
   /// The number of named variables in this scope.
   /// The client can use this information to present the variables in a paged UI

@github-actions
Copy link

github-actions bot commented Nov 22, 2025

🐧 Linux x64 Test Results

  • 33166 tests passed
  • 491 tests skipped

Copy link
Contributor

@da-viper da-viper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Only nits to address.

@DrSergei DrSergei force-pushed the improve-evaluate-request branch from 02c043e to ebc4cfd Compare November 24, 2025 11:45
Copy link
Contributor

@ashgti ashgti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@DrSergei DrSergei merged commit 3694798 into llvm:main Nov 25, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants