Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>,
	Tom de Vries <tdevries@suse.de>,
	Guinevere Larsen <guinevere@redhat.com>
Subject: [PATCH] gdb/testsuite: work around empty substring bug in expect
Date: Tue, 26 Aug 2025 15:35:14 +0100	[thread overview]
Message-ID: <be288fecba0f90f1f874e1c6e236afbd01802900.1756218901.git.aburgess@redhat.com> (raw)
In-Reply-To: <7af123b1-ded2-40bb-b6af-7c5d4bb6f17a@suse.de>

There is a bug in expect, see:

  https://sourceforge.net/p/expect/patches/26/

which causes empty substring matches from a regexp to instead return
the complete input buffer.  To reproduce this bug, try this command:

  expect -c 'spawn sh -c "echo -n -e \"abc\""; \
            expect -re "(a?)(a)(bc)"; \
	    puts "\n"; \
	    for { set i 1 } { $i < 4 } { incr i } { \
	      puts -nonewline "($i): \""; \
	      puts -nonewline $expect_out($i,string); \
	      puts "\"" \
	    }'

For a working expect the output looks like:

  spawn sh -c echo -n -e "abc"
  abc

  (1): ""
  (2): "a"
  (3): "bc"

But for a broken expect the output looks like:

  spawn sh -c echo -n -e "abc"
  abc

  (1): "abc"
  (2): "a"
  (3): "bc"

Notice that (1) is now returning the complete input buffer rather than
the empty string, this is wrong.

This is not the first time this bug has impacted GDB's testsuite,
this commit seems to be working around the same problem:

  commit e579b537353cd91cb8fac1eaeb69901d4936766f
  Date:   Sat Aug 16 20:32:37 2025 +0200

      [gdb/testsuite] Fix TUI tests on freebsd

I recently pushed this commit:

  commit 3825c972a636852600b47c242826313f4b9963b8
  Date:   Wed Jun 18 15:02:29 2025 +0100

      gdb: allow gdb.Color to work correctly with pagination

Which added gdb.python/py-color-pagination.exp.  Bug PR gdb/33321 was
then created as the test was failing on some hosts.  Turns out, this
is same expect bug.

The fix presented here is the same as for e579b537353cd91cb8, avoid
using optional regexp substrings at the start of a regexp, and instead
use two separate regexp patterns.  With this change in place, the test
now passes on all hosts.

There's no change in what is being tested after this commit.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33321
---
 .../gdb.python/py-color-pagination.exp        | 36 +++++++++++++------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-color-pagination.exp b/gdb/testsuite/gdb.python/py-color-pagination.exp
index 3235fffe5cc..e1ca1f1ce75 100644
--- a/gdb/testsuite/gdb.python/py-color-pagination.exp
+++ b/gdb/testsuite/gdb.python/py-color-pagination.exp
@@ -66,18 +66,25 @@ proc test_pagination { type mode } {
 	    exp_continue
 	}
 
-	-re "^(${::any_color}?)(${::any_color})$::str" {
+	-re "^(${::any_color})(${::any_color})$::str" {
 	    # After a continuation prompt GDB will restore the previous
 	    # color, and then we immediately switch to a new color.
 	    set restored_color $expect_out(1,string)
-	    if { $restored_color ne ""
-		 && $restored_color ne $expected_restore_color } {
+	    if { $restored_color ne $expected_restore_color } {
 		set saw_bad_color_handling true
 	    }
 	    set last_color $expect_out(2,string)
 	    exp_continue
 	}
 
+	-re "^(${::any_color})$::str" {
+	    # This pattern matches printing STR in all cases that are not
+	    # immediately after a pagination prompt.  In this case there is
+	    # a single escape sequence to set the color.
+	    set last_color $expect_out(1,string)
+	    exp_continue
+	}
+
 	-re "^\033\\\[${::decimal}m$::str" {
 	    # This catches the case where the color's escape sequence has
 	    # not been converted back into a full style.  This indicates
@@ -86,18 +93,25 @@ proc test_pagination { type mode } {
 	    exp_continue
 	}
 
-	-re "^((?:\033\\\[m)?)$::pagination_prompt$" {
+	-re "^\033\\\[m$::pagination_prompt$" {
 	    # After a pagination prompt we expect GDB to restore the last
 	    # color.
 	    set expected_restore_color $last_color
 
-	    # If we didn't see a color reset sequence then the pagination
-	    # prompt will have been printed in the wrong color, this is a
-	    # GDB bug.
-	    set color_reset $expect_out(1,string)
-	    if { $color_reset eq "" } {
-		set saw_bad_color_handling true
-	    }
+	    # Send '\n' to view more output.
+	    send_gdb "\n"
+	    exp_continue
+	}
+
+	-re "^$::pagination_prompt$" {
+	    # After a pagination prompt we expect GDB to restore the last
+	    # color.
+	    set expected_restore_color $last_color
+
+	    # If we didn't see a color reset sequence before the pagination
+	    # prompt, then the prompt will have been printed in the wrong
+	    # color, this is a GDB bug.
+	    set saw_bad_color_handling true
 
 	    # Send '\n' to view more output.
 	    send_gdb "\n"

base-commit: 3825c972a636852600b47c242826313f4b9963b8
-- 
2.47.1


  reply	other threads:[~2025-08-26 14:35 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04  9:39 [PATCH 0/2] Python Style API Andrew Burgess
2025-06-04  9:39 ` [PATCH 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-04  9:39 ` [PATCH 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-06 13:38 ` [PATCHv2 0/2] Python Style API Andrew Burgess
2025-06-06 13:38   ` [PATCHv2 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-06 14:21     ` Eli Zaretskii
2025-06-06 13:38   ` [PATCHv2 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-07 10:44   ` [PATCHv3 0/2] Python Style API Andrew Burgess
2025-06-07 10:44     ` [PATCHv3 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-07 10:44     ` [PATCHv3 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-09 15:54     ` [PATCHv3 0/2] Python Style API Andrew Burgess
2025-06-18 19:30     ` [PATCHv4 0/4] " Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 4/4] gdb: extend gdb.write to support styled output Andrew Burgess
2025-06-25 14:42       ` [PATCHv5 0/4] Python Style API Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-07-07 14:43         ` [PATCHv6 0/4] Python Style API Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-08-13 10:25           ` [PATCHv7 0/4] Fix for gdb.Color + pagination AND new gdb.Style API Andrew Burgess
2025-08-13 10:25             ` [PATCHv7 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-08-24 16:13               ` Andrew Burgess
2025-08-25 10:21                 ` Tom de Vries
2025-08-26 14:35                   ` Andrew Burgess [this message]
2025-08-27  6:24                     ` [PATCH] gdb/testsuite: work around empty substring bug in expect Tom de Vries
2025-08-13 10:29             ` [PATCHv7 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-08-13 10:30             ` [PATCHv7 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-08-13 12:37               ` Eli Zaretskii
2025-08-13 10:34             ` [PATCHv7 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-08-13 13:05               ` Eli Zaretskii
2025-08-13 13:05               ` Eli Zaretskii
2025-08-27 11:34             ` [PATCHv8 0/3] new gdb.Style API Andrew Burgess
2025-08-27 11:34               ` [PATCHv8 1/3] gdb/python: add gdb.Style class Andrew Burgess
2025-09-16 16:47                 ` Tom Tromey
2025-09-23 16:59                   ` Andrew Burgess
2025-08-27 11:34               ` [PATCHv8 2/3] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-09-16 16:50                 ` Tom Tromey
2025-08-27 11:34               ` [PATCHv8 3/3] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-09-16 16:56                 ` Tom Tromey
2025-09-23 17:05                   ` Andrew Burgess
2025-09-23 18:38                     ` Tom Tromey
2025-09-23 16:54               ` [PATCHv9 0/3] new gdb.Style API Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 1/3] gdb/python: add gdb.Style class Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 2/3] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 3/3] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-10-03 19:27                 ` [PATCHv9 0/3] new gdb.Style API Tom Tromey
2025-10-05 12:51                   ` Andrew Burgess
2025-10-05 15:16                     ` Tom de Vries
2025-10-05 17:59                       ` Tom Tromey
2025-10-06  9:01                         ` Andrew Burgess
2025-10-05 18:03                       ` Andrew Burgess
2025-10-05 18:41                         ` Tom de Vries
2025-10-06  9:01                           ` Andrew Burgess
2025-10-06 12:29                             ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be288fecba0f90f1f874e1c6e236afbd01802900.1756218901.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guinevere@redhat.com \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox