From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cts3O9D6NmhIxjcAWB0awg (envelope-from ) for ; Wed, 28 May 2025 08:00:16 -0400 Received: by simark.ca (Postfix, from userid 112) id E26DA1E11C; Wed, 28 May 2025 08:00:16 -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 E26B31E102 for ; Wed, 28 May 2025 08:00:15 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FF3D385115B for ; Wed, 28 May 2025 12:00:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FF3D385115B Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id 00A423858D32 for ; Wed, 28 May 2025 11:59:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00A423858D32 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 00A423858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748433580; cv=none; b=hmGCC3va2fz4C1oVh0oBiKAZEzDifWIwmMdfDUpr0VVVZGsga+9reM9XQNHf3ehmx8GXScY81kvXlpO/TdLnCckmdupmANQVVUoOXu5m+cIjbk3BSAdmhjB9+dwCZaq9utgGPKj/UcCjrDQ6gQ50EX3REfJZmMhI5QKzi0PStsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748433580; c=relaxed/simple; bh=7bvl6KukDVIkxXsCmNRks86PuCLeMlwKCJ3+EZ0XRBE=; h=Message-ID:Date:MIME-Version:Subject:From:To; b=LHvuH0Q2xva1rcnVyoADPZGobs6zPFyFg/RKgrhCBMwwGE4LhE1BtsRD98DwMD/9wjivoNofU9xZnnRT6YwXdbHHaMfqAwPb26y2YJJGroVkqpoxKYvOeKzGLMGbIA4oYkfPgyrG85w544ZOO5KQHJSRONE/AEWPJ8SjddDJS9c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00A423858D32 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43cfe574976so34967955e9.1 for ; Wed, 28 May 2025 04:59:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748433579; x=1749038379; 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=X4uD+4sJIsd55B0dLtu08BvTKtI6LjNRYoX/gHi02Zc=; b=EFAW6boUEZ51/eF7y3Ml8eiEbEaHcNn9v2+COsuvu0MImALNVxhfLGvekcDIwgPhd5 e/+LX4cw+X+9Rj3FkhjDbgCFet7Hy16v6Y+hcUui0NuLpcSYpXkF4LnlFKFDkWTGAtdX DKbH5s5nB52373LX99MhS5yjqrE/MAMaiNi3mhGEq6ea2u6ECRb3IB0gS0girC23jQNS x6z67SXBzvoqXhCL9G0vFS9Xc4Lo9vTha6fAe+R/GPAywSVzEexE1dIFIJOTYSWpXIuG p6X71F3k8Bhznryskz9vhYEoLOrsluc+DUNjcMglE92An3nEnN+z+VPUqc/9AnkYMjD4 ding== X-Forwarded-Encrypted: i=1; AJvYcCWMi4bqLrJE0KZTAkIwmR83f4ZO9qIaIXrMgMJYO7m7aK+Asczc/8odjiwSc4/h71irplPE4orDsR0QcA==@sourceware.org X-Gm-Message-State: AOJu0YwbPXYoxdrWKZT57VuCWL37hu3wqj4coTuYntCGvainN1eBm2Uq TkwCOjAfjUH8GNM+pd2+shLOBmtCdyqABEwI66gaoS+u4QZvoDK2FkdzR2livX8X X-Gm-Gg: ASbGncs3A3T1m02pMfrxovx/ZEmxsnaUxD0UUFFuwKGU9SPw0af/jL9cc2GwYap7Tx7 4PYwoGtvFaEXlV7tbmrIAPhtM2PV67eCE/CMryecgTkHmYBys/2iWV3zD2R9hWVRXObn1nZekY8 jPyVwJL6klOXKMBuryUPre6wGwbgE0s72sN59ntk0m/YZRbqrIVgAuV3Wyfs4RnY5frChO0+zNZ /l77aUfukVTIFzN5UFJ2J7Y+GTJMyjdXTXykJNvwlYwkuQaWzXv3iHWhrg06rpgGPbHEgC/cQwc Nx4FWRwEH2MoYveeGtZUAZTtpFaZyeCX+FWKKS1+02rUD2tZMhbr2Z/27u1C+DuDiGWUBW0/0sb ilIBJdNitnBjX/Brugvs= X-Google-Smtp-Source: AGHT+IEzBDBp8IZpTFTHk9F2AgUOM3p3hg37hEyuCw1L3B2Zgbl2gefWJfdJuqJHvOr91z8bmOlAuQ== X-Received: by 2002:a05:6000:2586:b0:3a4:d8b6:ca3f with SMTP id ffacd0b85a97d-3a4e9449b23mr1645259f8f.30.1748433578568; Wed, 28 May 2025 04:59:38 -0700 (PDT) Received: from ?IPV6:2001:8a0:facf:2b00:92c3:77a6:8c07:8a4c? ([2001:8a0:facf:2b00:92c3:77a6:8c07:8a4c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4eac8af1dsm1298932f8f.57.2025.05.28.04.59.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 May 2025 04:59:37 -0700 (PDT) Message-ID: Date: Wed, 28 May 2025 12:59:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2] 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> Content-Language: en-US In-Reply-To: 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 Hi! On 2025-05-28 00:20, Pedro Alves wrote: > On 2025-05-27 23:41, Pedro Alves wrote: > > Somehow I didn't recall that we can define commands in the CLI with "define foo". :-) > > I think the best & simplest in this case is to do just that. Like, put this in a gdb script (*): > > define command > echo prefix \n > echo prefix foo\n > echo prefix bar\n > echo prefix \n > end > > then run the testcase with GDB as normal, load the script, and use gdb_test_multiple, all as usual. > > I can take care of that. I went ahead and did this. Here's the new patch, now with a testcase, and a new commit log, with a better explanation. Let me know what you think of this one. --- 8< --- >From d3a75f89b701d32958cc3f54642204054984c17c Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 28 May 2025 10:40:46 +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 exp_continue } -re "^\r\nprefix bar(?=\r\n)" { # some other action exp_continue } -re "^\r\nprefix (?=\r\n)" { # yet another action 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 \r\nprefix foo\r\n" ... then the "prefix foo" pattern match inadvertently consumes the first "prefix " 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..1ed352ddad7 --- /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 \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 \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)" { + 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..710c5e057ba --- /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 \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 \n + echo prefix \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