From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 8FE913858D20; Wed, 21 Feb 2024 13:25:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FE913858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708521938; bh=Diqe/ZpNbLOKnvSmUyX+DUgXXE2n8R5uqEFOhZ6sqqE=; h=From:To:Subject:Date:From; b=UxHUvSOUi7DsimeWZbhtaxK6+CNoWpUBW1kfkvIGJp0FPpbggPZCeHiSYmKtyOJpr 2fFdY9uUDPRu1/+My8Yys53Qx7Ew6wDsgX/zZywfHGqZwVoQHxyQEAHu0Ilw3HtYz+ 30CEsrjgIJLOl9wJubMuyuuADR4zKsYKfDYYi9Pw= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Fix error handling in _dap_read_json X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 33283d91d94e205ba34306cd1c253b9faceb4dd9 X-Git-Newrev: 99eeecc8d276e5af745e48825d66efff693a7678 Message-Id: <20240221132538.8FE913858D20@sourceware.org> Date: Wed, 21 Feb 2024 13:25:38 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D99eeecc8d276= e5af745e48825d66efff693a7678 commit 99eeecc8d276e5af745e48825d66efff693a7678 Author: Tom de Vries Date: Wed Feb 21 14:25:31 2024 +0100 [gdb/testsuite] Fix error handling in _dap_read_json =20 In _dap_read_json we have a gdb_expect with clauses that generate error= s: ... timeout { error "timeout reading json header" } eof { error "eof reading json header" } ... =20 Proc gdb_expect uses dejagnu's remote_expect, which has some peculiar semantics related to errors: ... # remote_expect works basically the same as standard expect, but it # also takes care of getting the file descriptor from the specified # host and also calling the timeout/eof/default section if there is an # error on the expect call. ..... =20 When a timeout triggers, it generates a timeout error, which is reporte= d by gdb_expect, after which it runs the timeout/eof/default clauses, which generates an eof error, which is reported by runtest. =20 I think the intention here is to generate just a one error, a timeout e= rror. =20 Fix this by postponing generating the error until after gdb_expect. =20 Tested on x86_64-linux, by: - running all the DAP test-cases and observing no regressions, and - modifying the gdb.dap/eof.exp test-case to trigger a timeout error, a= nd observing only a timeout error. =20 PR testsuite/31382 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31382 Diff: --- gdb/testsuite/lib/dap-support.exp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-supp= ort.exp index 31f036eddf2..38b00693790 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -147,6 +147,8 @@ proc dap_send_request {command {obj {}}} { # "last_ton" will be set to the TON form of the result. proc _dap_read_json {} { set length "" + set seen_timeout 0 + set seen_eof 0 gdb_expect { -re "^Content-Length: (\[0-9\]+)\r\n" { set length $expect_out(1,string) @@ -160,13 +162,20 @@ proc _dap_read_json {} { # Done. } timeout { - error "timeout reading json header" + set seen_timeout 1 } eof { - error "eof reading json header" + set seen_eof 1 } } =20 + if {$seen_timeout} { + error "timeout reading json header"=09 + } + if {$seen_eof} { + error "eof reading json header" + } + if {$length =3D=3D ""} { error "didn't find content-length" } @@ -176,17 +185,27 @@ proc _dap_read_json {} { # Tcl only allows up to 255 characters in a {} expression in a # regexp, so we may need to read in chunks. set this_len [expr {min ($length, 255)}] + set seen_timeout 0 + set seen_eof 0 gdb_expect { -re "^.{$this_len}" { append json $expect_out(0,string) } timeout { - error "timeout reading json body" + set seen_timeout 1 } eof { - error "eof reading json body" + set seen_eof 1 } } + + if {$seen_timeout} { + error "timeout reading json header"=09 + } + if {$seen_eof} { + error "eof reading json header" + } + incr length -$this_len }