llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Sergei Druzhkov (DrSergei) <details> <summary>Changes</summary> Added hex format support in `setVariable` request according to DAP specification. --- Full diff: https://github.com/llvm/llvm-project/pull/181968.diff 5 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py (+3-1) - (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py (+8-6) - (modified) lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py (+10) - (modified) lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp (+2-1) - (modified) lldb/tools/lldb-dap/Protocol/ProtocolRequests.h (+1-1) ``````````diff 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); `````````` </details> https://github.com/llvm/llvm-project/pull/181968 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
