diff options
author | Tom Tromey <tromey@adacore.com> | 2023-06-01 11:54:17 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-06-22 09:46:24 -0600 |
commit | d8a001f57016eff05977e9699c7aabdf4302c71b (patch) | |
tree | 8f52cf811c7b40b9168be6bd7f51e9dfa9e418fc /gdb/python/lib | |
parent | 0aafd5d038581b1eaf7f37b185f9d2c9be47386d (diff) | |
download | gdb-d8a001f57016eff05977e9699c7aabdf4302c71b.zip gdb-d8a001f57016eff05977e9699c7aabdf4302c71b.tar.gz gdb-d8a001f57016eff05977e9699c7aabdf4302c71b.tar.bz2 |
Implement DAP "hover" context
A DAP client can request that an expression be evaluated in "hover"
context, meaning that it should not cause side effects. In gdb, this
can be implemented by temporarily setting a few "may-" parameters to
"off".
In order to make this work, I had to also change "may-write-registers"
so that it can be changed while the program is running. I don't think
there was any reason for this prohibition in the first place.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30476
Diffstat (limited to 'gdb/python/lib')
-rw-r--r-- | gdb/python/lib/gdb/dap/evaluate.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index a0b199a..651a404 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -43,6 +43,16 @@ def _evaluate(expr, frame_id): return ref.to_object() +# Like _evaluate but ensure that the expression cannot cause side +# effects. +@in_gdb_thread +def _eval_for_hover(expr, frame_id): + with gdb.with_parameter("may-write-registers", "off"): + with gdb.with_parameter("may-write-memory", "off"): + with gdb.with_parameter("may-call-functions", "off"): + return _evaluate(expr, frame_id) + + # Helper function to perform an assignment. @in_gdb_thread def _set_expression(expression, value, frame_id): @@ -71,6 +81,7 @@ def _repl(command, frame_id): @request("evaluate") +@capability("supportsEvaluateForHovers") def eval_request( *, expression: str, @@ -81,6 +92,8 @@ def eval_request( if context in ("watch", "variables"): # These seem to be expression-like. return send_gdb_with_response(lambda: _evaluate(expression, frameId)) + elif context == "hover": + return send_gdb_with_response(lambda: _eval_for_hover(expression, frameId)) elif context == "repl": return send_gdb_with_response(lambda: _repl(expression, frameId)) else: |