From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id DFeoDDO8QmhVEwMAWB0awg (envelope-from ) for ; Fri, 06 Jun 2025 06:00:19 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MqdLjzLL; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=n7rn6tMi; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Uy4ablgy; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KkdMqnsj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1CCBC1E11C; Fri, 6 Jun 2025 06:00:19 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 816521E089 for ; Fri, 6 Jun 2025 06:00:17 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13A2E3858C50 for ; Fri, 6 Jun 2025 10:00:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13A2E3858C50 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MqdLjzLL; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=n7rn6tMi; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Uy4ablgy; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KkdMqnsj Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 48B37385772F for ; Fri, 6 Jun 2025 09:58:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48B37385772F 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 48B37385772F 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=1749203889; cv=none; b=X+VERU+UW5NsPkjCxz9fuMeCLO3BMPtPO0sm4RitDfpMMECv7LpnOd2VLh4XGMyAVCJBFhzmn51OvePl9j3c9/QbF0oGbGQbNDBVa1jXQ4d5+pbXJmxpCx/v9/RAof5nsDdsqGrH4NakoIcmhVHu4yvt6MQxssbfriy1LNT8IrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749203889; c=relaxed/simple; bh=tDs3uYG1DAwLuLtdcpUJ6EnRh2JCAwA4kMWK7BMLsCU=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=AA1Txlx5yrQNYIOlRz9FHvfzywqF3tT5u+hlh9nSPTyqhmqySJ9VQAYly6IawCT2u7u6/vUkgowtA6eaQ0iyjqGpYL960hP4NKvnsTj79VBBYt7iwTUNpPXQi+Tw2mgIyZBHvoR8debeJlpVs61YNeqK3774ypRyxLQRxfW3xWo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48B37385772F 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 EB5613368A; Fri, 6 Jun 2025 09:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1749203888; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s0H3msYXp5xvQuqxb+wcL//9bC+FqrwPvVdUf25ksR0=; b=MqdLjzLLM3llQ+26+K1hO5xQ48AECKHqc6HmG4HwaAwcWjGU4PSz66ocBxr2JzuFrGx5wO meOgY6SgKMC943zfSnGJigV3qQMfbXBRimZ0gQvnDkXZgLow8W7p4G5uv3oTwj4n6d1Pde qWTAC2P5khTvDeDAy6yYv//4bcH/Fww= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1749203888; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s0H3msYXp5xvQuqxb+wcL//9bC+FqrwPvVdUf25ksR0=; b=n7rn6tMiUomHj6E8/c4tbvKrIeBsiuxylkEJVi0fvBHxJZqH6JoEeBmMLv+oomOthzyanw yYX+hqrj+OGj+fAQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Uy4ablgy; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=KkdMqnsj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1749203886; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s0H3msYXp5xvQuqxb+wcL//9bC+FqrwPvVdUf25ksR0=; b=Uy4ablgy/vKqleIrQyyNmJZktcXabLI10z94Cuax1GTQXRGrAbbvnfXusDVrkQV2YIFWSZ 5GPHdfw9lt0I0ufYf4K2ffQKnT/ccXxfss+kqBM1HvzqMsRixjx+nfckEyCjSTgGCgtZim 6Sow4/W18U4QYCIOK6ZZkQ5eSQiFOhk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1749203886; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s0H3msYXp5xvQuqxb+wcL//9bC+FqrwPvVdUf25ksR0=; b=KkdMqnsjM7toq3q545P9HS5E2u+yLdeVhzHKHcFMoPiWhvOLyJhnOiKsN/vczTOiYXO6yH fhZmvYaRmqXfFpBQ== 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 D07021336F; Fri, 6 Jun 2025 09:58:06 +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 VW5iMa67QmgOJQAAD6G6ig (envelope-from ); Fri, 06 Jun 2025 09:58:06 +0000 Message-ID: Date: Fri, 6 Jun 2025 11:58:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] of [PATCH v2 42/47] gdb_test_multiple: Anchor prompt match if -lbl To: Pedro Alves , gdb-patches@sourceware.org References: <20250519132308.3553663-1-pedro@palves.net> <20250519132308.3553663-43-pedro@palves.net> <9c94d111-a9a6-4c89-9e8e-4d5386f1562f@suse.de> <401356fc-d91b-4c70-89e2-9d9971b6b094@palves.net> <1d374acd-c8e9-48d2-b253-a4584366d953@palves.net> <868c00ee-c6cd-44fd-89ea-42916ba931c4@palves.net> Content-Language: en-US From: Tom de Vries In-Reply-To: <868c00ee-c6cd-44fd-89ea-42916ba931c4@palves.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,palves.net:email,gnu.org:url]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Queue-Id: EB5613368A X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 6/5/25 19:20, Pedro Alves wrote: > On 2025-06-05 17:37, Pedro Alves wrote: >> Reading back, I realized that this example looks a bit silly as is, because you could fix it by >> just moving the "prefix " case earlier than the "prefix foo/bar" cases. I should make the command output >> something after "prefix", like "prefix xxx", and then the regexp should match something like: >> >> -re "^\r\nprefix [^\r\n]*(?=\r\n)" { >> >> That's more like what the original testcase that exposed the issue does. >> >> I'll send an updated patch soon. > > Here it is. > Hi Pedro, [ FWIW, the way this patch is posted doesn't work well with patchwork: ... $ git-pw patch apply 113744 Failed to apply patch: Applying: of [PATCH v2 42/47] gdb_test_multiple: Anchor prompt match if -lbl error: No valid patches in input (allow with "--allow-empty") error: could not build fake ancestor hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 of [PATCH v2 42/47] gdb_test_multiple: Anchor prompt match if -lbl When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". $ git am --show-current-patch=diff --- 8< --- $ ... I managed to apply it by saving the email in thunderbird and using git am, though that drops the commit message. ] > --- 8< --- > From 93ce02b9ad0aefefc5f71b6c5d23f565f3f2e87a Mon Sep 17 00:00:00 2001 > From: Pedro Alves > Date: Thu, 5 Jun 2025 18:09:44 +0100 > Subject: [PATCH] gdb_test_multiple: Anchor prompt match if -lbl > > The testcase added by this patch has a gdb_test_multiple call that > wants to match different lines of output that all have a common > prefix, and do different actions on each. Instead of a single regular > expression with alternatives, its clearer code if the different its -> it's > expressions are handled with different "-re", like so: > > gdb_test_multiple "command" "" -lbl { > -re "^command(?=\r\n)" { > exp_continue > } > -re "^\r\nprefix foo(?=\r\n)" { > # Some action for "foo". > exp_continue > } > -re "^\r\nprefix bar(?=\r\n)" { > # Some action for "bar". > exp_continue > } > -re "^\r\nprefix \[^\r\n\]*(?=\r\n)" { > # Some action for all others. > exp_continue > } > -re "^\r\n$::gdb_prompt $" { > gdb_assert {$all_prefixes_were_seen} $gdb_test_name > } > } > > Above, the leading anchors in the "^\r\nprefix..." matches are needed > to avoid too-eager matching due to the common prefix. Without the > anchors, if the expect output buffer happens to contain at least: > > "\r\nprefix xxx\r\nprefix foo\r\n" > > ... then the "prefix foo" pattern match inadvertently consumes the > first "prefix xxx" line. > > Without the anchor in the prompt match, like: > > -re "\r\n$::gdb_prompt $" { > gdb_assert {$all_prefixes_were_seen} $gdb_test_name > } > > Or the equivalent: > > -re -wrap "" { > gdb_assert {$all_prefixes_were_seen} $gdb_test_name > } > > ... then if the expect buffer contains: > > "\r\nmeant-to-be-matched-by-lbl\r\nprefix foo\r\n$gdb_prompt " > > ... then the prompt regexp matches this, consuming the "prefix" line > inadvertently, and we get a FAIL. The built-in regexp matcher for > -lbl doesn't get a chance to match the > "\r\nmeant-to-be-matched-by-lbl\r\n" part, because the built-in prompt > match appears first within gdb_test_multiple. > > By adding the anchor to the prompt regexp, then we avoid that problem. > Should "then" be dropped in this line? > However, the same expect output buffer contents will still match the > built-in prompt match. That is what is fixed by this patch. It makes > it so that if -lbl is specified, the built-in prompt regexp has a > leading anchor. > Thanks for doing this. LGTM. Approved-By: Tom de Vries FWIW, I propose to apply this independently from the patch series, since AFAICT it's unrelated. Thanks, - Tom > Original idea for turning this into a gdb.testsuite/ testcase by Tom > de Vries . > > Change-Id: Ic2571ec793d856a89ee0d533ec363e2ac6036ea2 > --- > .../gdb.testsuite/gdb_test_multiple-lbl.exp | 84 +++++++++++++++++++ > .../gdb.testsuite/gdb_test_multiple-lbl.gdb | 25 ++++++ > gdb/testsuite/lib/gdb.exp | 4 +- > 3 files changed, 112 insertions(+), 1 deletion(-) > create mode 100644 gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp > create mode 100755 gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb > > diff --git a/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp > new file mode 100644 > index 00000000000..a05ce614b1d > --- /dev/null > +++ b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp > @@ -0,0 +1,84 @@ > +# Copyright 2025 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test gdb_test_multiple -lbl, particularly with patterns that share a > +# common prefix. > + > +standard_testfile > + > +clean_restart > + > +gdb_test_no_output "source ${srcdir}/${subdir}/$testfile.gdb" \ > + "source gdb test script" > + > +set saw_prompt 0 > +set saw_prefix 0 > +set saw_command 0 > +set saw_prefix_foo 0 > +set saw_prefix_bar 0 > + > +# #1 - We need anchors so that the "prefix foo" pattern below does not > +# match when the expect output buffer contains: > +# > +# "\r\nprefix xxx\r\n\prefix foo\r\n" > +# > +# #2 - We need an anchor on the prompt match as otherwise the prompt > +# regexp would match: > +# > +# "\r\nmeant-to-be-matched-by-lbl-2\r\nprefix xxx\r\n(gdb) " > +# > +# This test would fail if -lbl did not force the built-in prompt match > +# regexp to have an anchor as well, as without it, the built-in prompt > +# regexp would have the exact same issue as #2 above. > + > +gdb_test_multiple "command" "" -lbl { > + -re "^command(?=\r\n)" { > + verbose -log > + incr saw_command > + exp_continue > + } > + -re "^\r\nprefix foo(?=\r\n)" { > + verbose -log > + incr saw_prefix_foo > + exp_continue > + } > + -re "^\r\nprefix bar(?=\r\n)" { > + verbose -log > + incr saw_prefix_bar > + exp_continue > + } > + -re "^\r\nprefix \[^\r\n\]*(?=\r\n)" { > + verbose -log > + incr saw_prefix > + exp_continue > + } > + -re "^\r\n$gdb_prompt $" { > + verbose -log > + incr saw_prompt > + pass $gdb_test_name > + } > +} > + > +verbose -log "saw_command: $saw_command" > +verbose -log "saw_prefix_foo: $saw_prefix_foo" > +verbose -log "saw_prefix_bar: $saw_prefix_bar" > +verbose -log "saw_prefix: $saw_prefix" > +verbose -log "saw_prompt: $saw_prompt" > + > +gdb_assert {$saw_command == 1} > +gdb_assert {$saw_prefix_foo == 1} > +gdb_assert {$saw_prefix_bar == 1} > +gdb_assert {$saw_prefix == 3} > +gdb_assert {$saw_prompt == 1} > diff --git a/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb > new file mode 100755 > index 00000000000..8c94dfa9211 > --- /dev/null > +++ b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb > @@ -0,0 +1,25 @@ > +# Copyright 2025 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +define command > + echo prefix xxx\n > + echo meant-to-be-matched-by-lbl-1\n > + echo prefix foo\n > + echo prefix bar\n > + echo meant-to-be-matched-by-lbl-2\n > + echo prefix xxx\n > + echo prefix xxx\n > + echo meant-to-be-matched-by-lbl-3\n > +end > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index 0caa9cccd80..eefb6382a27 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -1127,6 +1127,7 @@ proc gdb_test_multiple { command message args } { > global any_spawn_id > > set line_by_line 0 > + set lbl_anchor_re "" > set prompt_regexp "" > set prompt_anchor 1 > for {set i 0} {$i < [llength $args]} {incr i} { > @@ -1136,6 +1137,7 @@ proc gdb_test_multiple { command message args } { > set prompt_regexp [lindex $args $i] > } elseif { $arg == "-lbl" } { > set line_by_line 1 > + set lbl_anchor_re "^" > } elseif { $arg == "-no-prompt-anchor" } { > set prompt_anchor 0 > } else { > @@ -1394,7 +1396,7 @@ proc gdb_test_multiple { command message args } { > fail "$errmsg" > set result -1 > } > - -re "\r\n$prompt_regexp" { > + -re "${lbl_anchor_re}\r\n$prompt_regexp" { > if {![string match "" $message]} { > fail "$message" > } > > base-commit: f601ffb52199a883f16df385b73a14e756b3e19a