From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 140823858C54; Fri, 12 May 2023 18:29:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 140823858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683916165; bh=3RL52aL4IaIO+gLV6SvS0V7ylGSyafXQSe/vOuqwL2g=; h=From:To:Subject:Date:From; b=LqH2h+OlS/GwAhZoDfbMYA+rk4AY5+CSj+xWcOsjPhamXV3gnZYTHqWcXUKrYyEfk eg2gMNAo3LUCjJyER5rwWd0DnHe1FuI/xKPw0hyAU15pKQVE0ABrYiA1jzlcPsrtyw Cap6eTHVhddEYEPgB2XzEHRmMXF5S4dGBucqe6iY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Implement DAP register scope X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 61f9fb1ea4aab3cd42bfcaaee2a05ac0dbe18a22 X-Git-Newrev: 14e8fded85efa824e6652ed876229e5c24758b72 Message-Id: <20230512182925.140823858C54@sourceware.org> Date: Fri, 12 May 2023 18:29:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D14e8fded85ef= a824e6652ed876229e5c24758b72 commit 14e8fded85efa824e6652ed876229e5c24758b72 Author: Tom Tromey Date: Thu Apr 13 11:24:02 2023 -0600 Implement DAP register scope =20 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. Diff: --- 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/scop= es.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): =20 =20 class ScopeReference(BaseReference): - def __init__(self, name, frame, var_list): + def __init__(self, name, hint, frame, var_list): super().__init__(name) + self.hint =3D hint self.frame =3D frame self.func =3D frame.function() self.var_list =3D var_list =20 def to_object(self): result =3D super().to_object() + result["presentationHint"] =3D self.hint # How would we know? result["expensive"] =3D False result["namedVariables"] =3D len(self.var_list) @@ -79,6 +81,17 @@ class ScopeReference(BaseReference): return (sym.print_name, val) =20 =20 +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) =3D _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] =20 =20 diff --git a/gdb/testsuite/gdb.dap/scopes.exp b/gdb/testsuite/gdb.dap/scope= s.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] =20 -gdb_assert {[llength $scopes] =3D=3D 1} "single scope" +gdb_assert {[llength $scopes] =3D=3D 2} "two scopes" =20 -set scope [lindex $scopes 0] +lassign $scopes scope reg_scope gdb_assert {[dict get $scope name] =3D=3D "Locals"} "scope is locals" +gdb_assert {[dict get $scope presentationHint] =3D=3D "locals"} \ + "locals presentation hint" gdb_assert {[dict get $scope namedVariables] =3D=3D 3} "three vars in scop= e" =20 +gdb_assert {[dict get $reg_scope name] =3D=3D "Registers"} \ + "second scope is registers" +gdb_assert {[dict get $reg_scope presentationHint] =3D=3D "registers"} \ + "registers presentation hint" +gdb_assert {[dict get $reg_scope namedVariables] > 0} "at least one regist= er" + 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] =3D=3D 2} "dei has two members" =20 +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