From: Tom de Vries Date: Wed, 27 Aug 2025 08:37:45 +0000 (+0200) Subject: [gdb/testsuite] Add have_startup_shell X-Git-Tag: gdb-17-branchpoint~164 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=793534c26924c986069b03ab1bd6659aead5065b;p=thirdparty%2Fbinutils-gdb.git [gdb/testsuite] Add have_startup_shell Say we disable startup-with-shell, we get: ... (gdb) run `echo 8`^M Starting program: a2-run `echo 8`^M [Thread debugging using libthread_db enabled]^M Using host libthread_db library "/lib64/libthread_db.so.1".^M usage: factorial ^M [Inferior 1 (process 10787) exited with code 01]^M (gdb) FAIL: gdb.base/a2-run.exp: run "a2-run" with shell (timeout) ... Fix this by only doing this test if startup-with-shell is supported. This fixes the test-case on msys2-ucrt64, where startup-with-shell is not supported. Likewise in other test-cases. Tested on x86_64-linux. --- diff --git a/gdb/testsuite/gdb.base/a2-run.exp b/gdb/testsuite/gdb.base/a2-run.exp index 4e95e56ed89..966e12a6f05 100644 --- a/gdb/testsuite/gdb.base/a2-run.exp +++ b/gdb/testsuite/gdb.base/a2-run.exp @@ -18,6 +18,8 @@ # Can't do this test without stdio support. require {!gdb_skip_stdio_test "a2run.exp"} +set have_startup_shell [have_startup_shell] + # # test running programs # @@ -166,9 +168,8 @@ gdb_run_cmd setup_xfail "arm-*-coff" gdb_test_stdio "" "720" "" "run \"$testfile\" again after setting args" -# GOAL: Test that shell is being used with "run". For remote debugging -# targets, there is no guarantee that a "shell" (whatever that is) is used. -if {![is_remote target]} { +# GOAL: Test that shell is being used with "run". +if { $have_startup_shell == 1 } { gdb_test_stdio "run `echo 8`" \ "40320" "" "run \"$testfile\" with shell" } diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 33952e4bd76..7b62a750bf4 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -21,6 +21,7 @@ require {!target_info exists noargs} # This test requires starting new inferior processes, skip it if the target # board is a stub. require !use_gdb_stub +require {expr [have_startup_shell] != -1} standard_testfile diff --git a/gdb/testsuite/gdb.base/inferior-args.exp b/gdb/testsuite/gdb.base/inferior-args.exp index 9406c7882f0..dfa1215c504 100644 --- a/gdb/testsuite/gdb.base/inferior-args.exp +++ b/gdb/testsuite/gdb.base/inferior-args.exp @@ -17,6 +17,7 @@ # This does not work on boards that don't support inferior arguments. require {!target_info exists noargs} +require {expr [have_startup_shell] != -1} standard_testfile .c diff --git a/gdb/testsuite/gdb.base/startup-with-shell.exp b/gdb/testsuite/gdb.base/startup-with-shell.exp index 80dfdf3db83..9c016b47c1f 100644 --- a/gdb/testsuite/gdb.base/startup-with-shell.exp +++ b/gdb/testsuite/gdb.base/startup-with-shell.exp @@ -22,6 +22,8 @@ require !use_gdb_stub # (via dejagnu) yet. require {!is_remote target} +require {expr [have_startup_shell] != -1} + standard_testfile if { [build_executable "failed to prepare" $testfile $srcfile debug] } { diff --git a/gdb/testsuite/gdb.mi/mi-exec-run.exp b/gdb/testsuite/gdb.mi/mi-exec-run.exp index a7a61b80fd2..43406cf6ab4 100644 --- a/gdb/testsuite/gdb.mi/mi-exec-run.exp +++ b/gdb/testsuite/gdb.mi/mi-exec-run.exp @@ -30,6 +30,8 @@ set MIFLAGS "-i=mi" # cannot use it, then there is no point in running this testcase. require !use_gdb_stub +set have_startup_shell [have_startup_shell] + standard_testfile mi-start.c if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { @@ -172,6 +174,9 @@ remote_exec target "chmod \"a-x\" $binfile.nox" foreach_with_prefix inferior-tty {"main" "separate"} { foreach_with_prefix mi {"main" "separate"} { foreach_with_prefix force-fail {0 1} { + if { ${force-fail} && $have_startup_shell == -1 } { + continue + } test ${inferior-tty} ${mi} ${force-fail} } } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 041650ac33a..d3e2a454902 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -11490,5 +11490,46 @@ gdb_caching_proc have_builtin_trap {} { } executable] } +# Return 1 if there is a startup shell. Return -1 if there's no startup shell. +# Return -1 otherwise. + +gdb_caching_proc have_startup_shell {} { + if { [is_remote target] } { + # For remote debugging targets, there is no guarantee that a "shell" + # is used. + return -1 + } + + + gdb_exit + gdb_start + + set re_on \ + [string_to_regexp "Use of shell to start subprocesses is on."] + set re_off \ + [string_to_regexp "Use of shell to start subprocesses is off."] + set re_cmd_unsupported \ + [string_to_regexp \ + {Undefined show command: "startup-with-shell". Try "help show".}] + + set supported -1 + gdb_test_multiple "show startup-with-shell" "" { + -re -wrap $re_on { + set supported 1 + } + -re -wrap $re_off { + set supported 0 + } + -re -wrap $re_cmd_unsupported { + } + -re -wrap "" { + } + } + + gdb_exit + + return $supported +} + # Always load compatibility stuff. load_lib future.exp