Skip to content

Commit 3694798

Browse files
authored
[lldb-dap] Add format support for evaluate request (llvm#169132)
This patch adds support for format option in the `evaluate` request according to [DAP](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Evaluate) specification. Also, fixed typo in `LLDB_DAP_INVALID_VARRERF` constant.
1 parent af0fcf8 commit 3694798

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,14 @@ def request_writeMemory(self, memoryReference, data, offset=0, allowPartial=Fals
987987
}
988988
return self._send_recv(command_dict)
989989

990-
def request_evaluate(self, expression, frameIndex=0, threadId=None, context=None):
990+
def request_evaluate(
991+
self,
992+
expression,
993+
frameIndex=0,
994+
threadId=None,
995+
context=None,
996+
is_hex: Optional[bool] = None,
997+
):
991998
stackFrame = self.get_stackFrame(frameIndex=frameIndex, threadId=threadId)
992999
if stackFrame is None:
9931000
return []
@@ -997,6 +1004,8 @@ def request_evaluate(self, expression, frameIndex=0, threadId=None, context=None
9971004
}
9981005
if context:
9991006
args_dict["context"] = context
1007+
if is_hex is not None:
1008+
args_dict["format"] = {"hex": is_hex}
10001009
command_dict = {
10011010
"command": "evaluate",
10021011
"type": "request",

lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def assertEvaluate(
2727
want_varref=False,
2828
want_memref=True,
2929
want_locref=False,
30+
is_hex=None,
3031
):
31-
resp = self.dap_server.request_evaluate(expression, context=self.context)
32+
resp = self.dap_server.request_evaluate(
33+
expression, context=self.context, is_hex=is_hex
34+
)
3235
self.assertTrue(
3336
resp["success"], f"Failed to evaluate expression {expression!r}"
3437
)
@@ -132,6 +135,12 @@ def run_test_evaluate_expressions(
132135
if context == "repl":
133136
self.assertEvaluate("", "21", want_type="int")
134137
self.assertEvaluate("", "21", want_type="int")
138+
self.assertEvaluate("static_int", "0x0000002a", want_type="int", is_hex=True)
139+
self.assertEvaluate(
140+
"non_static_int", "0x0000002b", want_type="int", is_hex=True
141+
)
142+
self.assertEvaluate("struct1.foo", "0x0000000f", want_type="int", is_hex=True)
143+
self.assertEvaluate("struct2->foo", "0x00000010", want_type="int", is_hex=True)
135144
self.assertEvaluate("static_int", "42", want_type="int")
136145
self.assertEvaluate("non_static_int", "43", want_type="int")
137146
self.assertEvaluate("struct1.foo", "15", want_type="int")

lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
8484
if (value.GetError().Fail())
8585
return ToError(value.GetError(), /*show_user=*/false);
8686

87-
VariableDescription desc(value,
88-
dap.configuration.enableAutoVariableSummaries);
87+
const bool hex = arguments.format ? arguments.format->hex : false;
88+
89+
VariableDescription desc(value, dap.configuration.enableAutoVariableSummaries,
90+
hex);
8991

9092
body.result = desc.GetResult(arguments.context);
9193
body.type = desc.display_type_name;
@@ -98,7 +100,7 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
98100
body.memoryReference = EncodeMemoryReference(addr);
99101

100102
if (ValuePointsToCode(value) &&
101-
body.variablesReference != LLDB_DAP_INVALID_VARRERF)
103+
body.variablesReference != LLDB_DAP_INVALID_VAR_REF)
102104
body.valueLocationReference = PackLocation(body.variablesReference, true);
103105

104106
return body;

lldb/tools/lldb-dap/Protocol/ProtocolTypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <optional>
2929
#include <string>
3030

31-
#define LLDB_DAP_INVALID_VARRERF INT64_MAX
31+
#define LLDB_DAP_INVALID_VAR_REF INT64_MAX
3232
#define LLDB_DAP_INVALID_SRC_REF 0
3333
#define LLDB_DAP_INVALID_VALUE_LOC 0
3434

@@ -462,7 +462,7 @@ struct Scope {
462462
/// remains suspended. See 'Lifetime of Object References' in the Overview
463463
/// section for details.
464464
////
465-
uint64_t variablesReference = LLDB_DAP_INVALID_VARRERF;
465+
uint64_t variablesReference = LLDB_DAP_INVALID_VAR_REF;
466466

467467
/// The number of named variables in this scope.
468468
/// The client can use this information to present the variables in a paged UI

0 commit comments

Comments
 (0)