summaryrefslogtreecommitdiff
path: root/gdb/python/lib/gdb/dap/scopes.py
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-04-13 11:24:02 -0600
committerTom Tromey <tromey@adacore.com>2023-05-12 12:22:31 -0600
commit14e8fded85efa824e6652ed876229e5c24758b72 (patch)
treeed9462405edac4865e0e9fee4a994c04a260b0e3 /gdb/python/lib/gdb/dap/scopes.py
parent61f9fb1ea4aab3cd42bfcaaee2a05ac0dbe18a22 (diff)
downloadbinutils-gdb-14e8fded85efa824e6652ed876229e5c24758b72.tar.gz
Implement DAP register scope
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.
Diffstat (limited to 'gdb/python/lib/gdb/dap/scopes.py')
-rw-r--r--gdb/python/lib/gdb/dap/scopes.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py
index be4f8fc28a0..8e9af5064c2 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]