diff options
author | Tom Tromey <tromey@adacore.com> | 2023-02-16 07:49:33 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-03-24 10:05:51 -0600 |
commit | 84bc96de16b64ae67460bf4896379a7543cecfd3 (patch) | |
tree | 35ac2c933b06f7cfaad63cbca3ef3913fbef7c56 /gdb/python | |
parent | 9ed6d7410c800c331d1f24051c85e4e52d7dfced (diff) | |
download | binutils-84bc96de16b64ae67460bf4896379a7543cecfd3.zip binutils-84bc96de16b64ae67460bf4896379a7543cecfd3.tar.gz binutils-84bc96de16b64ae67460bf4896379a7543cecfd3.tar.bz2 |
Implement repl evaluation for DAP
The evaluate command supports a "context" parameter which tells the
adapter the context in which an evaluation occurs. One of the
supported values is "repl", which we took to mean evaluation of a gdb
command. That is what this patch implements.
Note that some gdb commands probably will not work correctly with the
rest of the protocol. For example if the user types "continue",
confusion may result.
This patch requires the earlier patch to fix up scopes in DAP.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/dap/evaluate.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index d04ac16..55d41b0 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -38,12 +38,30 @@ def _evaluate(expr, frame_id): return ref.to_object() +# Helper function to evaluate a gdb command in a certain frame. +@in_gdb_thread +def _repl(command, frame_id): + if frame_id is not None: + frame = frame_for_id(frame_id) + frame.select() + val = gdb.execute(command, from_tty=True, to_string=True) + return { + "result": val, + "variablesReference": 0, + } + + # FIXME 'format' & hex # FIXME supportsVariableType handling -# FIXME "repl" @request("evaluate") -def eval_request(*, expression, frameId=None, **args): - return send_gdb_with_response(lambda: _evaluate(expression, frameId)) +def eval_request(*, expression, frameId=None, context="variables", **args): + if context in ("watch", "variables"): + # These seem to be expression-like. + return send_gdb_with_response(lambda: _evaluate(expression, frameId)) + elif context == "repl": + return send_gdb_with_response(lambda: _repl(expression, frameId)) + else: + raise Exception(f'unknown evaluate context "{context}"') @in_gdb_thread |