[PATCH 05/27] gdb/testsuite: Recognize windows-msvc across lib/gdb.exp procedures

Pedro Alves <[email protected]> Thu, 23 Jul 2026 14:00:56 +0100
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
The testsuite has many istarget checks like e.g.:

  [istarget *-*-mingw*] || [istarget *-*-cygwin*]

and

  [istarget *-*-mingw*] || [istarget *-*-cygwin*] || [istarget *-*-pe*]

to decide Windows- or PE/COFF-specific behavior.  These do not match a
windows-msvc target, whose triplets are
{x86_64,aarch64,i686}-pc-windows-msvc, so on such a configuration the
testsuite would take the non-Windows paths and misbehave in many
places.

Rather than adding windows-msvc to each site by hand, introduce two
predicates and replace the existing checks in lib/gdb.exp with them:

 - is_windows_native_target -- mingw* or windows* triplets, as opposed
   to Cygwin.

 - is_pecoff_target -- any Windows-based target or a bare PE target.

is_windows_based_target is extended to build on
is_windows_native_target so it too picks up windows-msvc.

Following patches will go over the testcases throughout using these
predicates.

Change-Id: I786285c009565ec2d3ddc06c0ba57d466d42e4d0
---
 gdb/testsuite/lib/gdb.exp | 62 +++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index fb9f29ee03d..db22d2bc320 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2528,7 +2528,7 @@ proc default_gdb_exit {} {
     }
 
     if { ([is_remote host] && [board_info host exists fileid])
-	 || [istarget *-*-mingw*] } {
+	 || [is_windows_native_target] } {
 	send_gdb "quit\n"
 	gdb_expect 10 {
 	    -re "y or n" {
@@ -3102,9 +3102,7 @@ proc allow_shlib_tests {} {
     if {([istarget *-*-linux*]
 	 || [istarget *-*-*bsd*]
 	 || [istarget *-*-solaris2*]
-	 || [istarget *-*-mingw*]
-	 || [istarget *-*-cygwin*]
-	 || [istarget *-*-pe*])} {
+	 || [is_pecoff_target])} {
 	return 1
     }
 
@@ -3210,7 +3208,7 @@ gdb_caching_proc allow_dlmopen_tests {} {
 # Return 1 if we should allow TUI-related tests.
 
 gdb_caching_proc allow_tui_tests {} {
-    if { [istarget *-*-mingw*] } {
+    if { [is_windows_native_target] } {
 	# Avoid "Cannot enable the TUI when output is not a terminal".
 	return 0
     }
@@ -4217,10 +4215,25 @@ proc is_aarch64_target {} {
     return [expr {![is_aarch32_target]}]
 }
 
+# Return true if the target is Windows native (as opposed to Cygwin).
+
+proc is_windows_native_target {} {
+    return [expr {[istarget *-*-mingw*]
+		  || [istarget *-*-windows*]}]
+}
+
 # Return true if the target is Windows-based.
 
 proc is_windows_based_target {} {
-    return [expr {[istarget *-*-cygwin*] || [istarget *-*-mingw*]}]
+    return [expr {[istarget *-*-cygwin*]
+		  || [is_windows_native_target]}]
+}
+
+# Return true if the target is PE/COFF-based.
+
+proc is_pecoff_target {} {
+    return [expr {[is_windows_based_target]
+		  || [istarget *-*-pe*]}]
 }
 
 # Return true if this is a native configuration in GDB's sense.  This
@@ -5736,7 +5749,7 @@ proc skip_inline_var_tests {} {
 # time out sequences.
 
 proc allow_fork_tests {} {
-    if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+    if {[is_windows_based_target]} {
 	return 0
     }
 
@@ -5750,7 +5763,7 @@ proc allow_fork_tests {} {
 # false.
 
 proc allow_multi_inferior_tests {} {
-    if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+    if {[is_windows_based_target]} {
 	return 0
     }
 
@@ -6792,17 +6805,14 @@ proc gdb_compile {source dest type options} {
 		# IBM xlc compiler doesn't accept shared library named other
 		# than .so: use "-Wl," to bypass this
 		lappend source "-Wl,$shlib_name"
-	    } elseif { ([istarget "*-*-mingw*"]
-			|| [istarget *-*-cygwin*]
-			|| [istarget *-*-pe*])} {
+	    } elseif { [is_pecoff_target] } {
 		lappend source "${shlib_name}.a"
 	    } else {
 	       lappend source $shlib_name
 	    }
 	    if { $shlib_found == 0 } {
 		set shlib_found 1
-		if { ([istarget "*-*-mingw*"]
-		      || [istarget *-*-cygwin*]) } {
+		if { [is_pecoff_target] } {
 		    lappend new_options "ldflags=-Wl,--enable-auto-import"
 		}
 		if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
@@ -6924,9 +6934,7 @@ proc gdb_compile {source dest type options} {
     # (depending on the platform) to set a special rpath value, to allow
     # the executable to find the libraries it depends on.
     if { $shlib_load || $shlib_found } {
-	if { ([istarget "*-*-mingw*"]
-	      || [istarget *-*-cygwin*]
-	      || [istarget *-*-pe*]) } {
+	if { [is_pecoff_target] } {
 	    # Do not need anything.
 	} elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
 	    lappend new_options "ldflags=-Wl,-rpath,${outdir}"
@@ -7022,9 +7030,7 @@ proc gdb_compile {source dest type options} {
   }
 
     if { $type == "executable" } {
-	if { ([istarget "*-*-mingw*"]
-	      || [istarget "*-*-*djgpp"]
-	      || [istarget "*-*-cygwin*"])} {
+	if { [is_windows_based_target] || [istarget "*-*-*djgpp"] } {
 	    # Force output to unbuffered mode, by linking in an object file
 	    # with a global constructor that calls setvbuf.
 	    #
@@ -7299,9 +7305,7 @@ proc gdb_compile_shlib_1 {sources dest options} {
     } else {
 	lappend link_options "additional_flags=-shared"
 
-	if { ([istarget "*-*-mingw*"]
-	      || [istarget *-*-cygwin*]
-	      || [istarget *-*-pe*]) } {
+	if { [is_pecoff_target] } {
 	    if { [is_remote host] } {
 		set name [file tail ${dest}]
 	    } else {
@@ -7325,10 +7329,7 @@ proc gdb_compile_shlib_1 {sources dest options} {
     if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
 	return -1
     }
-    if { [is_remote host]
-	 && ([istarget "*-*-mingw*"]
-	     || [istarget *-*-cygwin*]
-	     || [istarget *-*-pe*]) } {
+    if { [is_remote host] && [is_pecoff_target] } {
 	set dest_tail_name [file tail ${dest}]
 	remote_upload host $dest_tail_name.a ${dest}.a
 	remote_file host delete $dest_tail_name.a
@@ -7841,7 +7842,7 @@ proc kill_wait_spawned_process { proc_spawn_id } {
 proc spawn_id_get_pid { spawn_id } {
     set testpid [exp_pid -i $spawn_id]
 
-    if { [istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"] } {
+    if { [is_windows_based_target] } {
 	# testpid is the Cygwin PID, GDB uses the Windows PID, which
 	# might be different due to the way fork/exec works.
 	set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
@@ -9102,7 +9103,7 @@ proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
 
   if {$allow_extra} {
       set extra ".*"
-  } elseif {[istarget *-*-cygwin*] || [istarget *-*-mingw*]} {
+  } elseif {[is_windows_based_target]} {
       # On Windows, even on supposedly single-threaded programs, we
       # may see thread exit output when running to end, for threads
       # spawned by the runtime.  E.g.:
@@ -9479,7 +9480,7 @@ gdb_caching_proc gdb_has_argv0 {} {
 	  || [istarget *-*-solaris*]
 	  || [istarget *-*-aix*]
 	  || [istarget *-*-gnu*]
-	  || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
+	  || [is_windows_based_target]
 	  || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
 	  || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
 	  || [istarget *-*-osf*]
@@ -9512,8 +9513,7 @@ gdb_caching_proc gdb_has_argv0 {} {
 # Returns "" if there is none.
 
 proc get_build_id { filename } {
-    if { ([istarget "*-*-mingw*"]
-	  || [istarget *-*-cygwin*]) } {
+    if { ([is_windows_based_target]) } {
 	set objdump_program [gdb_find_objdump]
 	set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
 	verbose "result is $result"
-- 
2.54.0