From: Tom Tromey Date: Tue, 16 May 2023 13:14:22 +0000 (-0600) Subject: Implement DAP setExpression request X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c2a0d767db1637d1651b80bc885903cacd637107;p=binutils-gdb.git Implement DAP setExpression request This implements the DAP setExpression request. --- diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 4fc0f31486c..1db6962f8e0 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -20,7 +20,7 @@ import gdb.printing from typing import Optional from .frames import frame_for_id -from .server import request +from .server import capability, request from .startup import send_gdb_with_response, in_gdb_thread from .varref import find_variable, VariableReference @@ -43,6 +43,20 @@ def _evaluate(expr, frame_id): return ref.to_object() +# Helper function to perform an assignment. +@in_gdb_thread +def _set_expression(expression, value, frame_id): + global_context = True + if frame_id is not None: + frame = frame_for_id(frame_id) + frame.select() + global_context = False + lhs = gdb.parse_and_eval(expression, global_context=global_context) + rhs = gdb.parse_and_eval(value, global_context=global_context) + lhs.assign(rhs) + return EvaluateResult(lhs).to_object() + + # Helper function to evaluate a gdb command in a certain frame. @in_gdb_thread def _repl(command, frame_id): @@ -89,3 +103,11 @@ def variables(*, variablesReference: int, start: int = 0, count: int = 0, **args lambda: _variables(variablesReference, start, count) ) return {"variables": result} + + +@capability("supportsSetExpression") +@request("setExpression") +def set_expression( + *, expression: str, value: str, frameId: Optional[int] = None, **args +): + return send_gdb_with_response(lambda: _set_expression(expression, value, frameId)) diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index ce739875404..9aaa94051e6 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -159,6 +159,11 @@ set obj [dap_check_request_and_response "evaluate global in main" \ dap_match_values "global value in main" [lindex $obj 0] \ "body result" 25 +set obj [dap_check_request_and_response "set global in main" \ + setExpression {o expression [s global_variable] value [s 23]}] +dap_match_values "global value in main after set" [lindex $obj 0] \ + "body result" 23 + set obj [dap_request_and_response \ evaluate {o expression [s nosuchvariable]}] set response [lindex $obj 0]