https://github.com/DrSergei updated https://github.com/llvm/llvm-project/pull/181968
>From 3c45e904ff797182efcf61c0d033a84d6749c428 Mon Sep 17 00:00:00 2001 From: Sergei Druzhkov <[email protected]> Date: Tue, 17 Feb 2026 21:59:04 +0300 Subject: [PATCH 1/2] [lldb-dap] Add hex format in setVariable request --- .../lldbsuite/test/tools/lldb-dap/dap_server.py | 4 +++- .../test/tools/lldb-dap/lldbdap_testcase.py | 14 ++++++++------ .../tools/lldb-dap/variables/TestDAP_variables.py | 10 ++++++++++ .../lldb-dap/Handler/SetVariableRequestHandler.cpp | 3 ++- lldb/tools/lldb-dap/Protocol/ProtocolRequests.h | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) 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 fdccc9eae9fe4..be1f2693e167e 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 @@ -1639,7 +1639,7 @@ def request_variables( } return self._send_recv(command_dict) - def request_setVariable(self, containingVarRef, name, value, id=None): + def request_setVariable(self, containingVarRef, name, value, id=None, is_hex=None): args_dict = { "variablesReference": containingVarRef, "name": name, @@ -1647,6 +1647,8 @@ def request_setVariable(self, containingVarRef, name, value, id=None): } if id is not None: args_dict["id"] = id + if is_hex is not None: + args_dict["format"] = {"hex": is_hex} command_dict = { "command": "setVariable", "type": "request", diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index f14742365e70e..e2026bc054067 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -376,23 +376,25 @@ def get_local_as_int(self, name, threadId=None): else: return int(value) - def set_variable(self, varRef, name, value, id=None): + def set_variable(self, varRef, name, value, id=None, is_hex=None): """Set a variable.""" - response = self.dap_server.request_setVariable(varRef, name, str(value), id=id) + response = self.dap_server.request_setVariable( + varRef, name, str(value), id=id, is_hex=is_hex + ) if response["success"]: self.verify_invalidated_event(["variables"]) self.verify_memory_event(response["body"].get("memoryReference")) return response - def set_local(self, name, value, id=None): + def set_local(self, name, value, id=None, is_hex=None): """Set a top level local variable only.""" # Get the locals scope reference dynamically locals_ref = self.get_locals_scope_reference() if locals_ref is None: return None - return self.set_variable(locals_ref, name, str(value), id=id) + return self.set_variable(locals_ref, name, str(value), id=id, is_hex=is_hex) - def set_global(self, name, value, id=None): + def set_global(self, name, value, id=None, is_hex=None): """Set a top level global variable only.""" # Get the globals scope reference dynamically stackFrame = self.dap_server.get_stackFrame() @@ -404,7 +406,7 @@ def set_global(self, name, value, id=None): for scope in frame_scopes: if scope["name"] == "Globals": varRef = scope["variablesReference"] - return self.set_variable(varRef, name, str(value), id=id) + return self.set_variable(varRef, name, str(value), id=id, is_hex=is_hex) return None def get_locals_scope_reference(self): diff --git a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py index 1dbb0143e7a55..016736bc8ec86 100644 --- a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py +++ b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py @@ -301,6 +301,16 @@ def do_test_scopes_variables_setVariable_evaluate( argv, 0x1234, "verify argv was set to 0x1234 (0x1234 != %#x)" % (argv) ) + # Test hexadecimal format + response = self.set_local("argc", 42, is_hex=True) + verify_response = { + "type": "int", + "value": "0x0000002a", + } + for key, value in verify_response.items(): + self.assertEqual(value, response["body"][key]) + self.set_local("argc", 123) + # Set a variable value whose name is synthetic, like a variable index # and verify the value by reading it variable_value = 100 diff --git a/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp index b9ae28d6772ac..0ce2aa565a602 100644 --- a/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp @@ -50,8 +50,9 @@ SetVariableRequestHandler::Run(const SetVariableArguments &args) const { if (!success) return llvm::make_error<DAPError>(error.GetCString()); + const bool hex = args.format ? args.format->hex : false; VariableDescription desc(variable, - dap.configuration.enableAutoVariableSummaries); + dap.configuration.enableAutoVariableSummaries, hex); SetVariableResponseBody body; body.value = desc.display_value; diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h index 28c9f48200e0c..e2dde172b5bcd 100644 --- a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h +++ b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h @@ -444,7 +444,7 @@ struct SetVariableArguments { std::string value; /// Specifies details on how to format the response value. - ValueFormat format; + std::optional<ValueFormat> format; }; bool fromJSON(const llvm::json::Value &, SetVariableArguments &, llvm::json::Path); >From baff820e6b258d11f93758c90d367bbd8175b37b Mon Sep 17 00:00:00 2001 From: Sergei Druzhkov <[email protected]> Date: Wed, 18 Feb 2026 17:14:31 +0300 Subject: [PATCH 2/2] Add test --- lldb/unittests/DAP/ProtocolRequestsTest.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lldb/unittests/DAP/ProtocolRequestsTest.cpp b/lldb/unittests/DAP/ProtocolRequestsTest.cpp index cdc012b448c8f..5d635e50fd3b7 100644 --- a/lldb/unittests/DAP/ProtocolRequestsTest.cpp +++ b/lldb/unittests/DAP/ProtocolRequestsTest.cpp @@ -11,6 +11,7 @@ #include "TestingSupport/TestUtilities.h" #include "llvm/Testing/Support/Error.h" #include <gtest/gtest.h> +#include <optional> using namespace llvm; using namespace lldb_dap::protocol; @@ -412,3 +413,22 @@ TEST(ProtocolRequestsTest, StackTraceResponseBody) { ASSERT_THAT_EXPECTED(expected, llvm::Succeeded()); EXPECT_EQ(PrettyPrint(*expected), PrettyPrint(body)); } + +TEST(ProtocolRequestsTest, SetVariableArguments) { + llvm::Expected<SetVariableArguments> expected = + parse<SetVariableArguments>(R"({ + "variablesReference": 42, + "name": "test", + "value": "12345" + })"); + ASSERT_THAT_EXPECTED(expected, llvm::Succeeded()); + EXPECT_EQ(expected->variablesReference, 42U); + EXPECT_EQ(expected->name, "test"); + EXPECT_EQ(expected->value, "12345"); + EXPECT_EQ(expected->format, std::nullopt); + + // Check required keys. + EXPECT_THAT_EXPECTED( + parse<SetVariableArguments>(R"({})"), + FailedWithMessage("missing value at (root).variablesReference")); +} _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
