From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 34F9A3858438; Thu, 26 Jan 2023 20:23:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34F9A3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674764583; bh=o7guOu2ijUaAGVIo2ZOwCOIvmurfniu36HF8TKMoJ9Y=; h=From:To:Subject:Date:From; b=PQ9ddJl8SWfeXReBmGoP3+iJxq7kHPGX5dbP3pEzl703IoV6szrQz5XiUobEvH0GK khuWgRXyeShm3/KcSreGC8PNehWKw3xKNET/ZpLmtj7WEzSqsUwRXaqdHtWR31YwwA IPYsemNKGmyD0l6N2DTDMNReZQOm9V3343MvoleE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite/dap: pass around dicts instead of TON objects X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 4dde3b33e461e40e069c2026861b3e5ba2476604 X-Git-Newrev: faee137249c8494e36d0170c0a57319113f54185 Message-Id: <20230126202303.34F9A3858438@sourceware.org> Date: Thu, 26 Jan 2023 20:23:03 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfaee137249c8= 494e36d0170c0a57319113f54185 commit faee137249c8494e36d0170c0a57319113f54185 Author: Simon Marchi Date: Fri Jan 6 11:15:32 2023 -0500 gdb/testsuite/dap: pass around dicts instead of TON objects =20 The DAP helper functions generally return TON objects. However, callers almost all immediately use ton::2dict to convert them to dicts, to access their contents. This commits makes things a bit simpler for them by having function return dicts directly instead. =20 The downside is that the TON objects contain type information. For instance, a "2" in a TCL dict could have been the integer 2 or the string "2" in JSON. By converting to TCL dicts, we lose that information. If some tests specifically want to check the types of some fields, I think we can add intermediary functions that return TON objects, without having to complicate other callers who don't care. =20 Change-Id: I2ca47bea355bf459090bae8680c6a917350b5c3f Diff: --- gdb/testsuite/gdb.dap/basic-dap.exp | 15 ++++++------ gdb/testsuite/lib/dap-support.exp | 48 ++++++++++++++++++---------------= ---- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/ba= sic-dap.exp index af55d19349f..68d0440f692 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -53,8 +53,7 @@ set line_bpno [dap_get_breakpoint_number $obj] =20 # Check the new breakpoint event. set ok 0 -foreach event [lindex $obj 1] { - set d [namespace eval ton::2dict $event] +foreach d [lindex $obj 1] { if {[dict get $d type] !=3D "event" || [dict get $d event] !=3D "breakpoint"} { continue @@ -84,8 +83,8 @@ set obj [dap_check_request_and_response "set breakpoint b= y address" \ {o breakpoints [a [o instructionReference [s &address_breakpoint_her= e]]]}] set insn_bpno [dap_get_breakpoint_number $obj] =20 -set d [namespace eval ton::2dict [lindex $obj 0]] -set bplist [dict get $d body breakpoints] +set response [lindex $obj 0] +set bplist [dict get $response body breakpoints] set insn_pc [dict get [lindex $bplist 0] instructionReference] =20 dap_check_request_and_response "start inferior" configurationDone @@ -125,14 +124,14 @@ dap_match_values "global value in main" [lindex $obj = 0] \ =20 set obj [dap_request_and_response \ evaluate {o expression [s nosuchvariable]}] -set d [namespace eval ton::2dict [lindex $obj 0]] -gdb_assert { [dict get $d success] =3D=3D "false" } "result of invalid req= uest" +set response [lindex $obj 0] +gdb_assert { [dict get $response success] =3D=3D "false" } "result of inva= lid request" =20 set obj [dap_check_request_and_response "disassemble one instruction" \ disassemble \ [format {o memoryReference [s %s] instructionCount [i 1]} \ $insn_pc]] -set d [namespace eval ton::2dict [lindex $obj 0]] -gdb_assert { [dict exists $d body instructions] } "instructions in disasse= mble output" +set response [lindex $obj 0] +gdb_assert { [dict exists $response body instructions] } "instructions in = disassemble output" =20 dap_shutdown diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-supp= ort.exp index 8c85f90c352..ee55a4acc9c 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -124,7 +124,7 @@ proc _dap_send_request {command {obj {}}} { return $result } =20 -# Read a JSON response from gdb. This will return a TON object on +# Read a JSON response from gdb. This will return a dict on # success, or throw an exception on error. proc _dap_read_json {} { set length "" @@ -171,31 +171,31 @@ proc _dap_read_json {} { incr length -$this_len } =20 - return [ton::json2ton $json] + set ton [ton::json2ton $json] + return [namespace eval ton::2dict $ton] } =20 # Read a sequence of JSON objects from gdb, until a response object is # seen. If the response object has the request sequence number NUM, # and is for command CMD, return a list of two elements: the response # object and a list of any preceding events, in the order they were -# emitted. The objects are in TON format. If a response object is -# seen but has the wrong sequence number or command, throw an -# exception +# emitted. The objects are dicts. If a response object is seen but has +# the wrong sequence number or command, throw an exception + proc _dap_read_response {cmd num} { set result {} while 1 { - set obj [_dap_read_json] - set d [namespace eval ton::2dict $obj] + set d [_dap_read_json] if {[dict get $d type] =3D=3D "response"} { if {[dict get $d request_seq] !=3D $num} { error "saw wrong request_seq in $obj" } elseif {[dict get $d command] !=3D $cmd} { error "saw wrong command in $obj" } else { - return [list $obj $result] + return [list $d $result] } } else { - lappend result $obj + lappend result $d } } } @@ -210,15 +210,15 @@ proc dap_request_and_response {command {obj {}}} { # Like dap_request_and_response, but also checks that the response # indicates success. NAME is used to issue a test result. proc dap_check_request_and_response {name command {obj {}}} { - set result [dap_request_and_response $command $obj] - set d [namespace eval ton::2dict [lindex $result 0]] - if {[dict get $d success] !=3D "true"} { - verbose "request failure: $result" + set response_and_events [dap_request_and_response $command $obj] + set response [lindex $response_and_events 0] + if {[dict get $response success] !=3D "true"} { + verbose "request failure: $response" fail "$name success" return "" } pass "$name success" - return $result + return $response_and_events } =20 # Start gdb, send a DAP initialization request and return the @@ -257,8 +257,7 @@ proc dap_shutdown {{name shutdown}} { # Search the event list EVENTS for an output event matching the regexp # RX. Pass the test NAME if found, fail if not. proc dap_search_output {name rx events} { - foreach event $events { - set d [namespace eval ton::2dict $event] + foreach d $events { if {[dict get $d type] !=3D "event" || [dict get $d event] !=3D "output"} { continue @@ -271,10 +270,9 @@ proc dap_search_output {name rx events} { fail $name } =20 -# Check that OBJ (a single TON object) has values that match the +# Check that D (a dict object) has values that match the # key/value pairs given in ARGS. NAME is used as the test name. -proc dap_match_values {name obj args} { - set d [namespace eval ton::2dict $obj] +proc dap_match_values {name d args} { foreach {key value} $args { if {[eval dict get [list $d] $key] !=3D $value} { fail "$name (checking $key)" @@ -290,21 +288,21 @@ proc _dap_read_event {type} { while 1 { # We don't do any extra error checking here for the time # being; we'll just get a timeout thrown instead. - set obj [_dap_read_json] - set d [namespace eval ton::2dict $obj] + set d [_dap_read_json] if {[dict get $d type] =3D=3D "event" && [dict get $d event] =3D=3D $type} { - return $obj + return $d } } } =20 # Read JSON objects looking for an event whose "event" field is TYPE. +# # NAME is used as the test name; it defaults to TYPE. Extra arguments # are used to check fields of the event; the arguments alternate # between a field name (in "dict get" form) and its expected value. -# Returns the TON object for the chosen event, or empty string on -# error. +# +# Returns the dict for the chosen event, or empty string on error. proc dap_read_event {name type args} { if {$name =3D=3D ""} { set name $type @@ -320,7 +318,7 @@ proc dap_read_event {name type args} { # breakpoint is created. OBJ is an object as returned by # dap_check_request_and_response. proc dap_get_breakpoint_number {obj} { - set d [namespace eval ton::2dict [lindex $obj 0]] + set d [lindex $obj 0] set bplist [dict get $d body breakpoints] return [dict get [lindex $bplist 0] id] }