* [PATCH] Implement DAP register scope
@ 2023-04-18 15:19 Tom Tromey
2023-05-12 18:28 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2023-04-18 15:19 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed that gdb's DAP code did not provide a way to see register
values. DAP defines a "register" scope, which this patch implements.
This patch also adds the missing (and optional) "presentationHint" to
scopes.
---
gdb/python/lib/gdb/dap/scopes.py | 20 +++++++++++++++++---
gdb/testsuite/gdb.dap/scopes.exp | 18 ++++++++++++++++--
2 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py
index 9ab454aa57b..5982934d9fb 100644
--- a/gdb/python/lib/gdb/dap/scopes.py
+++ b/gdb/python/lib/gdb/dap/scopes.py
@@ -50,14 +50,16 @@ def _block_vars(block):
class ScopeReference(BaseReference):
- def __init__(self, name, frame, var_list):
+ def __init__(self, name, hint, frame, var_list):
super().__init__(name)
+ self.hint = hint
self.frame = frame
self.func = frame.function()
self.var_list = var_list
def to_object(self):
result = super().to_object()
+ result["presentationHint"] = self.hint
# How would we know?
result["expensive"] = False
result["namedVariables"] = len(self.var_list)
@@ -79,6 +81,17 @@ class ScopeReference(BaseReference):
return (sym.print_name, val)
+class RegisterReference(ScopeReference):
+ def __init__(self, name, frame):
+ super().__init__(
+ name, "registers", frame, list(frame.architecture().registers())
+ )
+
+ @in_gdb_thread
+ def fetch_one_child(self, idx):
+ return (self.var_list[idx].name, self.frame.read_register(self.var_list[idx]))
+
+
# Helper function to create a DAP scopes for a given frame ID.
@in_gdb_thread
def _get_scope(id):
@@ -88,9 +101,10 @@ def _get_scope(id):
if block is not None:
(args, locs) = _block_vars(block)
if args:
- scopes.append(ScopeReference("Arguments", frame, args))
+ scopes.append(ScopeReference("Arguments", "arguments", frame, args))
if locs:
- scopes.append(ScopeReference("Locals", frame, locs))
+ scopes.append(ScopeReference("Locals", "locals", frame, locs))
+ scopes.append(RegisterReference("Registers", frame))
return [x.to_object() for x in scopes]
diff --git a/gdb/testsuite/gdb.dap/scopes.exp b/gdb/testsuite/gdb.dap/scopes.exp
index 2c4b9ed81a5..cf9174f06a2 100644
--- a/gdb/testsuite/gdb.dap/scopes.exp
+++ b/gdb/testsuite/gdb.dap/scopes.exp
@@ -52,12 +52,20 @@ set scopes [dap_check_request_and_response "get scopes" scopes \
[format {o frameId [i %d]} $frame_id]]
set scopes [dict get [lindex $scopes 0] body scopes]
-gdb_assert {[llength $scopes] == 1} "single scope"
+gdb_assert {[llength $scopes] == 2} "two scopes"
-set scope [lindex $scopes 0]
+lassign $scopes scope reg_scope
gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
+gdb_assert {[dict get $scope presentationHint] == "locals"} \
+ "locals presentation hint"
gdb_assert {[dict get $scope namedVariables] == 3} "three vars in scope"
+gdb_assert {[dict get $reg_scope name] == "Registers"} \
+ "second scope is registers"
+gdb_assert {[dict get $reg_scope presentationHint] == "registers"} \
+ "registers presentation hint"
+gdb_assert {[dict get $reg_scope namedVariables] > 0} "at least one register"
+
set num [dict get $scope variablesReference]
set refs [lindex [dap_check_request_and_response "fetch variables" \
"variables" \
@@ -98,4 +106,10 @@ set refs [lindex [dap_check_request_and_response "fetch contents of dei" \
set deivals [dict get $refs body variables]
gdb_assert {[llength $deivals] == 2} "dei has two members"
+set num [dict get $reg_scope variablesReference]
+# The request succeeding is sufficient.
+dap_check_request_and_response "fetch first register" \
+ "variables" \
+ [format {o variablesReference [i %d] count [i 1]} $num]
+
dap_shutdown
--
2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Implement DAP register scope
2023-04-18 15:19 [PATCH] Implement DAP register scope Tom Tromey
@ 2023-05-12 18:28 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-05-12 18:28 UTC (permalink / raw)
To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey
>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:
Tom> I noticed that gdb's DAP code did not provide a way to see register
Tom> values. DAP defines a "register" scope, which this patch implements.
Tom> This patch also adds the missing (and optional) "presentationHint" to
Tom> scopes.
I'm checking this in now.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-12 18:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 15:19 [PATCH] Implement DAP register scope Tom Tromey
2023-05-12 18:28 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).