From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 4EBE5385841D for ; Wed, 14 Feb 2024 16:22:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EBE5385841D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4EBE5385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707927739; cv=none; b=XisW/Aa91IGdIAoQZ2KKuW3rsXWmGcL1i20t6SbL05SNm5aVHqdc8LDC9mNeC5pInxVc2rqIttPHGBWCxoEPiZ8gz7MkWrL/ilMCn9ubv2w8ZMoRX6RwfLH4Rxhy39G0ay23+2pxVaTApuUGHJlLzDWMYEUAPCsaYkM9z9yYAjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707927739; c=relaxed/simple; bh=5gIWOWfVzdt0+hEJEabxQ3jFj0xvFjdj1cs0YQ9mzkM=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=E71X1mlQp5gQuVXstaFQbzTeYIr3B02xzcn/mC2WE06n7c9W/BYyon0cENEx9+PXXBHTF21zdF/HkabQnn1QwiVdXnL4TGhDQO6MuNEQRBjLxfo+liRQooHnXjD1Rtg8X1siHiOlrDmfnxvhRU07ou4pFZsa94rgQL4WKt3/0Ko= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 400A721FE3 for ; Wed, 14 Feb 2024 16:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707927736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/5I32BYUJepP1eZ0e/FmYjKyv9bDbIRW9P5baHdYZBg=; b=bNvUptPpPI3sAvFGUpAKSnophXStKMtF6GaXp8mDYHkjEHZlo///ar4KRU6lL2HLPRW9F8 EAQNbGmIsvMEEp5tcoeAd3XJNatFztL2kgIrued+1wlnsHhW0cECs2HnZpbc8cWOSKF6f9 KZuUvFculwAmPYfbA4u5q9KmyFhuT2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707927736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/5I32BYUJepP1eZ0e/FmYjKyv9bDbIRW9P5baHdYZBg=; b=CywSuAjLBkMxs3fd7D1FGYgZJF+7c3c2pTX8W1ChZp5Z9hVVU2B0Daw4j+CwiL4VZxMQzv JFv5q5rgcnx2wNAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707927736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/5I32BYUJepP1eZ0e/FmYjKyv9bDbIRW9P5baHdYZBg=; b=bNvUptPpPI3sAvFGUpAKSnophXStKMtF6GaXp8mDYHkjEHZlo///ar4KRU6lL2HLPRW9F8 EAQNbGmIsvMEEp5tcoeAd3XJNatFztL2kgIrued+1wlnsHhW0cECs2HnZpbc8cWOSKF6f9 KZuUvFculwAmPYfbA4u5q9KmyFhuT2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707927736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/5I32BYUJepP1eZ0e/FmYjKyv9bDbIRW9P5baHdYZBg=; b=CywSuAjLBkMxs3fd7D1FGYgZJF+7c3c2pTX8W1ChZp5Z9hVVU2B0Daw4j+CwiL4VZxMQzv JFv5q5rgcnx2wNAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 291C513A72 for ; Wed, 14 Feb 2024 16:22:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qHCcCLjozGXnNQAAD6G6ig (envelope-from ) for ; Wed, 14 Feb 2024 16:22:16 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/testsuite] Fix error handling in _dap_read_json Date: Wed, 14 Feb 2024 17:22:31 +0100 Message-Id: <20240214162231.26969-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=bNvUptPp; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CywSuAjL X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 0.49 X-Rspamd-Queue-Id: 400A721FE3 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: In _dap_read_json we have a gdb_expect with clauses that generate errors: ... timeout { error "timeout reading json header" } eof { error "eof reading json header" } ... 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. ..... When a timeout triggers, it generates a timeout error, which is reported by gdb_expect, after which it runs the timeout/eof/default clauses, which generates an eof error, which is reported by runtest. I think the intention here is to generate just a one error, a timeout error. Fix this by postponing generating the error until after gdb_expect. 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, and observing only a timeout error. PR testsuite/31382 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31382 --- 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-support.exp index 979dfa2cd73..42c1491e507 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -137,6 +137,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) @@ -150,13 +152,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 } } + if {$seen_timeout} { + error "timeout reading json header" + } + if {$seen_eof} { + error "eof reading json header" + } + if {$length == ""} { error "didn't find content-length" } @@ -166,17 +175,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" + } + if {$seen_eof} { + error "eof reading json header" + } + incr length -$this_len } base-commit: b235e90e740aa486e6bbe8243eedf109fed41a5c -- 2.35.3