From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uIvvDyvSQWiEMQIAWB0awg (envelope-from ) for ; Thu, 05 Jun 2025 13:21:47 -0400 Received: by simark.ca (Postfix, from userid 112) id 2F0F31E102; Thu, 5 Jun 2025 13:21:47 -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.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 E85F41E0C2 for ; Thu, 5 Jun 2025 13:21:45 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BA72385841C for ; Thu, 5 Jun 2025 17:21:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BA72385841C Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by sourceware.org (Postfix) with ESMTPS id 8168B3858408 for ; Thu, 5 Jun 2025 17:21:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8168B3858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8168B3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749144062; cv=none; b=CA/4363qsKPnXucRhQSJHKKoscELjHZZg+WIMY6c2aCl0zMOum9LT6iwHiq/zdHm0I33EooJ8CeqFLyYgr/VD1aueRiuVX6x9Sdv2LTNRt1rWkZiipgRh8puNlVZ4NCrWjfe672UH9uIfMsKZf2mDM0dLDWMVe8KqHbSclAoWKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749144062; c=relaxed/simple; bh=EOWBZNZzP7hiyJx6KantyBYlgKwXziLMfPN0q6tAVoc=; h=Message-ID:Date:MIME-Version:Subject:From:To; b=ARQ6X5ky1sDE0JrMreIh7txnLdZkCLxjX6bRjgetsSBfCT8GeKB20uqOKyLI7mHDcVbnmuzo24RqiwUDuooV+UtiOElrWI5g3lXxPeespEgan5rpezrHY79wrivqTu5x8GXP5AS/5q4D9fts4g1zEOC6BITc6SvYMjGrAk/QTj4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8168B3858408 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3a522224582so754011f8f.3 for ; Thu, 05 Jun 2025 10:21:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749144051; x=1749748851; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ODcG8d22mM98natAFGjPW6AcE5VW7sjRuMkAEhmMAJk=; b=BgF/ivgSrT4XKRRTHbn0bRM79cIpIcVxvCSfy+3nu+5Emb3DSyKZt/InlFOSc01G8N rO/j2GkPkLnaH/Krgb70PA/BEngh1hVw8avx3PCJAajxvLTnxrgO0Buaf/FfDsnZLMoR M4MbHxy0jBQ84rWqrbvR5C9LD3QJ1bWWk3EEir6Yi6MCow99XpdPNisCGXnTJuMn2obf oQdpV5aFzUtBFF5qPyc+XwOaaoulw6g+zbIKefoWIasOu8sMQs8NzMBawBG4o+ugM2ij PPWfA1aTKyD97MRSU1QV192qxLpz+CcdkiW6hMLgq3ZhKydwQGOFxTEmx3TVZpY+z4Wl mAeg== X-Forwarded-Encrypted: i=1; AJvYcCX5gxepgIE5u+pSvPfWRyK+kqfULlwktoEBaInH8sDjA5aPamcHCUY6O9J/+tLqDYW/83rK4tNl3e0Bxg==@sourceware.org X-Gm-Message-State: AOJu0YzjvDCTdkLS57hXp5tNUtmFCUTO52/A57CedadSL2RtE8HgBJHg kKYiTLSVyCUsbPcZae7OPJ6+y3al3SlRiUNfyjzceY1mPOV4LkSZbPZ8i6Drp4Dh X-Gm-Gg: ASbGncsQtTHEFfWWpwL9IDUXqYF08teE/ns47pRyEvoutoCweFGxGJk5jZmWqg18vZJ vSEsivhv47bHiJqwG6kzAZi9qPJ+CdocSTe6V4+ZoxY5YiEFwvhBRu/EwLdDsE1OHoul4kS/epL qrpk39BUnT2Fh48sLsObiGSTTrgM9iLGC24m3PoKmRBrh9M5DE7XxImu9AhaJBbXjQJ/jNg5Mqo CdrxB2IBe8mud93VibzWtK3QmZZZK3n7XxCK9Mdyn9mHJCi20Xou19Ul6I8JglPom6yLm7XaP3R gSYrWKrsAelrtiBW7TU1n39gMr8vAigA0wLZ3GsqiBxLh2S4wMnRMGOnuNu+anYPVtoOtn4qMhw /Sg6zDLMRFjWp7OaSitM= X-Google-Smtp-Source: AGHT+IFS1wcX6GFXcTJNwLuHBsOsoayEVYW+j5lptZ0wVhiwQ+MI/ZyB3alPYL3C6f+BMS8gQ3dcxA== X-Received: by 2002:a05:6000:2002:b0:3a5:2923:7ffa with SMTP id ffacd0b85a97d-3a5292381aemr3289863f8f.7.1749144051047; Thu, 05 Jun 2025 10:20:51 -0700 (PDT) Received: from ?IPV6:2001:8a0:facf:2b00:451a:975e:a6cb:7552? ([2001:8a0:facf:2b00:451a:975e:a6cb:7552]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-451fb22a31csm25191945e9.36.2025.06.05.10.20.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Jun 2025 10:20:50 -0700 (PDT) Message-ID: <868c00ee-c6cd-44fd-89ea-42916ba931c4@palves.net> Date: Thu, 5 Jun 2025 18:20:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3] of [PATCH v2 42/47] gdb_test_multiple: Anchor prompt match if -lbl From: Pedro Alves To: Tom de Vries , 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> Content-Language: en-US In-Reply-To: <1d374acd-c8e9-48d2-b253-a4584366d953@palves.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 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. --- 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 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. 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. 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 -- 2.49.0