From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 58F583858421; Thu, 26 Jan 2023 20:23:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58F583858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674764593; bh=/+rjYgfvwI1I5kGQGrg/n4zFnudacNjHyMmv+AAf00M=; h=From:To:Subject:Date:From; b=f6Y8bTpKU4HkkDgWZIyepDEdQL4jAgIMv6zhVBaF0ofpbSsiTJRh0ht26J3Pk9cak Nr/TVi2IXowggGQITCqjiucswWPBjIoMi2vETxPHolm12e/znA1KTkovDTKa0DQ6w+ BTcur087bqxx+8LODj4fqg//JA261p21PEECqU/0= 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: make dap_wait_for_event_and_check return preceding messages X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 59db4c934f9931d0c77a36cac1f9d6402ab7496d X-Git-Newrev: 8abd06e066be7ad41d608b500187e90736c9e8fa Message-Id: <20230126202313.58F583858421@sourceware.org> Date: Thu, 26 Jan 2023 20:23:13 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8abd06e066be= 7ad41d608b500187e90736c9e8fa commit 8abd06e066be7ad41d608b500187e90736c9e8fa Author: Simon Marchi Date: Fri Jan 6 13:27:14 2023 -0500 gdb/testsuite/dap: make dap_wait_for_event_and_check return preceding m= essages =20 In the following patch, I change gdb.dap/basic-dap.exp such that after waiting for some event, it checks if it received another event meanwhile. To help with this, make dap_wait_for_event_and_check and _dap_dap_wait_for_event return a list with everything received before the event of interest. This is similar to what dap_check_request_and_response returns. =20 Change-Id: I85c8980203a2dec833937e7552c2196bc137935d Diff: --- gdb/testsuite/lib/dap-support.exp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-supp= ort.exp index 179f675b4d8..527e7db5228 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -282,17 +282,27 @@ proc dap_match_values {name d args} { pass $name } =20 -# A helper for dap_read_event that reads events, looking for one +# A helper for dap_wait_for_event_and_check that reads events, looking for= one # matching TYPE. -proc _dap_wait_for_event {type} { +# +# Return a list of two items: +# +# - the matched event +# - a list of any JSON objects (events or others) seen before the matched +# event. +proc _dap_wait_for_event { {type ""} } { + set preceding [list] + while 1 { # We don't do any extra error checking here for the time # being; we'll just get a timeout thrown instead. set d [_dap_read_json] if {[dict get $d type] =3D=3D "event" - && [dict get $d event] =3D=3D $type} { - return $d + && ($type =3D=3D "" || [dict get $d event] =3D=3D $type)} { + return [list $d $preceding] } + + lappend preceding $d } } =20 @@ -302,14 +312,20 @@ proc _dap_wait_for_event {type} { # 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 dict for the chosen event, or empty string on error. +# Return a list of two items: +# +# - the matched event (regardless of whether it passed the field validati= on or +# not) +# - a list of any JSON objects (events or others) seen before the matched +# event. proc dap_wait_for_event_and_check {name type args} { if {$name =3D=3D ""} { set name $type } =20 set result [_dap_wait_for_event $type] - eval dap_match_values [list $name $result] $args + set event [lindex $result 0] + eval dap_match_values [list $name $event] $args =20 return $result }