[PATCH 22/27] gdb.base/maint-info-sections.exp: Match exec file name with optional .exe

Pedro Alves <[email protected]> Thu, 23 Jul 2026 14:01:13 +0100
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Two tests of gdb.base/maint-info-sections.exp match a header line
against the expected binary name:

 1. The "maint info sections" test matches the "Exec file:" header
    with:

      Exec file: .*${binfile}., file type...

    where the trailing "." is meant to match the closing quote after
    the file name.

 2. The "maint info sections -all-objects" test matches the "Object
    file:" header, expecting the closing quote immediately after
    $binfile.  Both assume the printed name is exactly $binfile.

But on a host where the executable has a ".exe" suffix that is not
part of $binfile, the printed name is "$binfile.exe", so neither
header matches: the single "." matches the dot instead of the quote,
and the "Object file:" quote does not line up at all.  The tests then
fail, e.g., on x86_64-w64-mingw32:

  FAIL: gdb.base/maint-info-sections.exp: maint info sections
  FAIL: gdb.base/maint-info-sections.exp: maint info sections -all-objects

Fix this by allowing for an optional ".exe" between the file name and
the closing quote in both, matching the closing quote explicitly.

Tested on:

 x86_64-pc-linux-gnu
 x86_64-pc-cygwin
 x86_64-w64-mingw32
 x86_64-pc-windows-msvc

Change-Id: Icce62d69d8e23a8e859639a2e4a72c6f5c24ec0e
---
 gdb/testsuite/gdb.base/maint-info-sections.exp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/gdb.base/maint-info-sections.exp b/gdb/testsuite/gdb.base/maint-info-sections.exp
index ac712137cc6..3cc128c0ad3 100644
--- a/gdb/testsuite/gdb.base/maint-info-sections.exp
+++ b/gdb/testsuite/gdb.base/maint-info-sections.exp
@@ -123,19 +123,23 @@ gdb_test_multiple "maint info sections" "general output check" {
 set text_section ".text"
 set data_section ".data"
 
+# On some hosts the executable has a ".exe" suffix that is not part of
+# $binfile (e.g. a native Windows build), so allow for it between the
+# file name and the closing quote.
+set exec_re "Exec file: .*${binfile}(\\.exe)?', file type"
 gdb_test_multiple "maint info sections" "" {
-    -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" {
+    -re -wrap "${exec_re}.*ER_RO.*" {
 	# Looks like RealView which uses different section names.
 	set text_section ER_RO
 	set data_section ER_RW
 	pass "maint info sections"
     }
-    -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" {
+    -re -wrap "${exec_re}.*neardata.*" {
 	# c6x doesn't have .data section.  It has .neardata and .fardata section.
 	set data_section ".neardata"
 	pass "maint info sections"
     }
-    -re -wrap "Exec file: .*${binfile}., file type.*" {
+    -re -wrap "${exec_re}.*" {
 	pass "maint info sections"
     }
 }
@@ -207,7 +211,7 @@ gdb_test_no_output "maint info sections" \
 set seen_header false
 set seen_a_section false
 gdb_test_multiple "maint info sections -all-objects" "" {
-    -re "Object file: `${binfile}', file type \[^.\]+\.\r\n" {
+    -re "Object file: `${binfile}(\\.exe)?', file type \[^.\]+\.\r\n" {
 	set seen_header true
 	exp_continue
     }
-- 
2.54.0