* [PATCH 1/1] testsuite: Fix expected corefiles output folder for native-gdbserver boardfile
@ 2026-10-12 13:50 Abdul Basit Ijaz
2026-10-26 9:44 ` [PING][PATCH " Ijaz, Abdul B
0 siblings, 1 reply; 2+ messages in thread
From: Abdul Basit Ijaz @ 2026-10-12 13:50 UTC (permalink / raw)
To: gdb-patches; +Cc: abdul.b.ijaz
Tests that use set_inferior_cwd_to_output_dir and depend on a
gdbserver-launched inferior crashing need this fix. These tests expect the
kernel-generated core file to be created in the output directory. Tests
using core_find are unaffected because core_find runs the program in a
controlled directory. For example, gdb.base/bigcore.exp is affected. On
the native-gdbserver board, core files generated by inferiors launched
through gdbserver are written to gdb/testsuite/ rather than the output
directory, causing them to be reported in gdb.sum as unexpected core files.
set_inferior_cwd_to_output_dir uses "set cwd", which only takes
effect when GDB starts the inferior. With "target remote", gdbserver
has already created the inferior at startup, and the inferior inherits
gdbserver's own working directory, which is gdb/testsuite/.
gdb.base/auxv.exp has the same problem: it uses "set cwd" directly to
make a temporary directory the inferior's working directory. Its core
file ends up in gdb/testsuite/ instead, so the test does not find it
and reports the native core tests as UNSUPPORTED.
Fix this by recording the directory in ::inferior_cwd in
set_inferior_cwd_to_output_dir. When gdbserver is spawned locally
and ::inferior_cwd is set, gdbserver_start adds
"--wrapper env -C <dir> --", so that only the inferior starts in that
directory, and its core files are no longer reported as unexpected
in the gdb.sum file. gdbserver itself still runs from gdb/testsuite/,
so a crash of gdbserver still dumps core there and is reported as an
unexpected core file. ::inferior_cwd is cleared in gdb_exit, so it
does not carry over to later tests.
gdb.base/auxv.exp sets ::inferior_cwd to its temporary directory
itself, since it cannot use the output directory: that also holds
the gcore-created file, which would match the test's "*core*" glob.
The wrapper is not added, and a warning is printed instead, if:
- the target is mingw or cygwin, where gdbserver does not support
--wrapper,
- the caller already passes --wrapper, since gdbserver does not
handle multiple --wrapper options correctly, or
- "env" on the target does not support -C (checked once and
cached).
The wrapper is also not added when gdbserver is started with --multi
(extended-remote), since GDB then starts the inferior with "run" and
passes the "set cwd" value itself.
Tests that do not set ::inferior_cwd are not affected: gdbserver is
started exactly as before. Ideally, the only core files left in
gdb/testsuite/ after a test run come from crashes of GDB or
gdbserver. With this fix, inferior core files that tests expect no
longer end up there, but a few unexpected ones still do because of
known bugs, e.g. gdb.base/foll-vfork.exp leaves 12 of them
(PR gdb/14766, PR gdb/30574).
Tested on x86_64-linux with the native-gdbserver and
native-extended-gdbserver boards: gdb.base/bigcore.exp and
gdb.base/auxv.exp now produce core files in the output directory,
and gdb.server/wrapper.exp still passes.
---
gdb/testsuite/gdb.base/auxv.exp | 5 ++++
gdb/testsuite/lib/gdb.exp | 13 +++++++--
gdb/testsuite/lib/gdbserver-support.exp | 37 +++++++++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.base/auxv.exp b/gdb/testsuite/gdb.base/auxv.exp
index 9d32cee8552..24a57997316 100644
--- a/gdb/testsuite/gdb.base/auxv.exp
+++ b/gdb/testsuite/gdb.base/auxv.exp
@@ -49,6 +49,11 @@ if {$core_works} {
if {[gdb_test_no_output "set cwd $coredir" \
"set cwd to temporary directory for core dumps"]} {
set core_works 0
+ } else {
+ # "set cwd" has no effect on the inferior that gdbserver
+ # creates at startup with "target remote". Have
+ # gdbserver_start pass the directory to it instead.
+ set ::inferior_cwd $coredir
}
}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index a77063b0bf0..d0e3c615209 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -7761,6 +7761,9 @@ proc gdb_start { } {
}
proc gdb_exit { } {
+ # The INFERIOR_CWD set by set_inferior_cwd_to_output_dir should not
+ # outlive the GDB session.
+ unset -nocomplain ::inferior_cwd
catch default_gdb_exit
}
@@ -10261,13 +10264,19 @@ if {[info exists GDB_PARALLEL]} {
proc set_inferior_cwd_to_output_dir {} {
# Note this sets the inferior's cwd ("set cwd"), not GDB's ("cd").
- # If GDB crashes, we want its core dump in gdb/testsuite/, not in
- # the testcase's dir, so we can detect the unexpected core at the
+ # If GDB or GDBSERVER crashes, we want its core dump in gdb/testsuite/,
+ # not in the testcase's dir, so we can detect the unexpected core at the
# end of the test run.
if {![is_remote host]} {
set output_dir [standard_output_file ""]
gdb_test_no_output "set cwd $output_dir" \
"set inferior cwd to test directory"
+
+ # With "target remote", the inferior that gdbserver creates
+ # at startup inherits gdbserver's CWD, and "set cwd" has no
+ # effect on it. Record the requested CWD so that
+ # gdbserver_start can pass it to the inferior.
+ set ::inferior_cwd $output_dir
}
}
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index f7fb9258649..5de065bcea2 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -293,6 +293,13 @@ proc gdbserver_default_get_comm_port { port } {
return "$port"
}
+# Return 1 if "env" on the target supports the -C (--chdir) option.
+
+gdb_caching_proc gdbserver_env_has_chdir {} {
+ set status [lindex [remote_exec target "env -C / true"] 0]
+ return [expr {$status == 0}]
+}
+
# Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS.
# The port will be filled in between them automatically.
#
@@ -346,6 +353,33 @@ proc gdbserver_start { options arguments } {
set gdbserver [find_gdbserver]
+ # An inferior that gdbserver creates at startup inherits the CWD
+ # of gdbserver, so "set cwd" does not apply to it. Start the
+ # inferior in the requested CWD through a wrapper instead. This
+ # way gdbserver itself stays in the testsuite directory, and its
+ # own core dumps are still detected. gdbserver concatenates
+ # multiple --wrapper options incorrectly, so don't add one if the
+ # caller already passes a wrapper. With --multi (extended-remote),
+ # GDB starts the inferior with "run" and sends the "set cwd" value
+ # itself, so no wrapper is needed.
+ set cwd_wrapper ""
+ if { [info exists ::inferior_cwd] && ![is_remote target]
+ && [string first "--multi" $options] == -1 } {
+ if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
+ warning "gdbserver does not support --wrapper on this target\
+ (PR server/15967), core files may not be generated in\
+ $::inferior_cwd"
+ } elseif { [string first "--wrapper" $options] != -1 } {
+ warning "gdbserver already has a --wrapper, core files\
+ may not be generated in $::inferior_cwd"
+ } elseif { ![gdbserver_env_has_chdir] } {
+ warning "env does not support -C, core files may not be\
+ generated in $::inferior_cwd"
+ } else {
+ set cwd_wrapper "--wrapper env -C $::inferior_cwd --"
+ }
+ }
+
# Loop till we find a free port.
while 1 {
# Fire off the debug agent.
@@ -398,6 +432,9 @@ proc gdbserver_start { options arguments } {
}
}
+ if { $cwd_wrapper != "" } {
+ append gdbserver_command " $cwd_wrapper"
+ }
if { $options != "" } {
append gdbserver_command " $options"
}
--
2.34.1
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [PING][PATCH 1/1] testsuite: Fix expected corefiles output folder for native-gdbserver boardfile
2026-10-12 13:50 [PATCH 1/1] testsuite: Fix expected corefiles output folder for native-gdbserver boardfile Abdul Basit Ijaz
@ 2026-10-26 9:44 ` Ijaz, Abdul B
0 siblings, 0 replies; 2+ messages in thread
From: Ijaz, Abdul B @ 2026-10-26 9:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Ijaz, Abdul B
Ping.
Thanks & Best Regards
Abdul Basit
-----Original Message-----
From: Ijaz, Abdul B <abdul.b.ijaz@intel.com>
Sent: Monday, October 12, 2026 3:50 PM
To: gdb-patches@sourceware.org
Cc: Ijaz, Abdul B <abdul.b.ijaz@intel.com>
Subject: [PATCH 1/1] testsuite: Fix expected corefiles output folder for native-gdbserver boardfile
Tests that use set_inferior_cwd_to_output_dir and depend on a gdbserver-launched inferior crashing need this fix. These tests expect the kernel-generated core file to be created in the output directory. Tests using core_find are unaffected because core_find runs the program in a controlled directory. For example, gdb.base/bigcore.exp is affected. On the native-gdbserver board, core files generated by inferiors launched through gdbserver are written to gdb/testsuite/ rather than the output directory, causing them to be reported in gdb.sum as unexpected core files.
set_inferior_cwd_to_output_dir uses "set cwd", which only takes effect when GDB starts the inferior. With "target remote", gdbserver has already created the inferior at startup, and the inferior inherits gdbserver's own working directory, which is gdb/testsuite/.
gdb.base/auxv.exp has the same problem: it uses "set cwd" directly to make a temporary directory the inferior's working directory. Its core file ends up in gdb/testsuite/ instead, so the test does not find it and reports the native core tests as UNSUPPORTED.
Fix this by recording the directory in ::inferior_cwd in set_inferior_cwd_to_output_dir. When gdbserver is spawned locally and ::inferior_cwd is set, gdbserver_start adds "--wrapper env -C <dir> --", so that only the inferior starts in that directory, and its core files are no longer reported as unexpected in the gdb.sum file. gdbserver itself still runs from gdb/testsuite/, so a crash of gdbserver still dumps core there and is reported as an unexpected core file. ::inferior_cwd is cleared in gdb_exit, so it does not carry over to later tests.
gdb.base/auxv.exp sets ::inferior_cwd to its temporary directory itself, since it cannot use the output directory: that also holds the gcore-created file, which would match the test's "*core*" glob.
The wrapper is not added, and a warning is printed instead, if:
- the target is mingw or cygwin, where gdbserver does not support
--wrapper,
- the caller already passes --wrapper, since gdbserver does not
handle multiple --wrapper options correctly, or
- "env" on the target does not support -C (checked once and
cached).
The wrapper is also not added when gdbserver is started with --multi (extended-remote), since GDB then starts the inferior with "run" and passes the "set cwd" value itself.
Tests that do not set ::inferior_cwd are not affected: gdbserver is started exactly as before. Ideally, the only core files left in gdb/testsuite/ after a test run come from crashes of GDB or gdbserver. With this fix, inferior core files that tests expect no longer end up there, but a few unexpected ones still do because of known bugs, e.g. gdb.base/foll-vfork.exp leaves 12 of them (PR gdb/14766, PR gdb/30574).
Tested on x86_64-linux with the native-gdbserver and native-extended-gdbserver boards: gdb.base/bigcore.exp and gdb.base/auxv.exp now produce core files in the output directory, and gdb.server/wrapper.exp still passes.
---
gdb/testsuite/gdb.base/auxv.exp | 5 ++++
gdb/testsuite/lib/gdb.exp | 13 +++++++--
gdb/testsuite/lib/gdbserver-support.exp | 37 +++++++++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.base/auxv.exp b/gdb/testsuite/gdb.base/auxv.exp index 9d32cee8552..24a57997316 100644
--- a/gdb/testsuite/gdb.base/auxv.exp
+++ b/gdb/testsuite/gdb.base/auxv.exp
@@ -49,6 +49,11 @@ if {$core_works} {
if {[gdb_test_no_output "set cwd $coredir" \
"set cwd to temporary directory for core dumps"]} {
set core_works 0
+ } else {
+ # "set cwd" has no effect on the inferior that gdbserver
+ # creates at startup with "target remote". Have
+ # gdbserver_start pass the directory to it instead.
+ set ::inferior_cwd $coredir
}
}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index a77063b0bf0..d0e3c615209 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -7761,6 +7761,9 @@ proc gdb_start { } { }
proc gdb_exit { } {
+ # The INFERIOR_CWD set by set_inferior_cwd_to_output_dir should not
+ # outlive the GDB session.
+ unset -nocomplain ::inferior_cwd
catch default_gdb_exit
}
@@ -10261,13 +10264,19 @@ if {[info exists GDB_PARALLEL]} {
proc set_inferior_cwd_to_output_dir {} {
# Note this sets the inferior's cwd ("set cwd"), not GDB's ("cd").
- # If GDB crashes, we want its core dump in gdb/testsuite/, not in
- # the testcase's dir, so we can detect the unexpected core at the
+ # If GDB or GDBSERVER crashes, we want its core dump in gdb/testsuite/,
+ # not in the testcase's dir, so we can detect the unexpected core
+ at the
# end of the test run.
if {![is_remote host]} {
set output_dir [standard_output_file ""]
gdb_test_no_output "set cwd $output_dir" \
"set inferior cwd to test directory"
+
+ # With "target remote", the inferior that gdbserver creates
+ # at startup inherits gdbserver's CWD, and "set cwd" has no
+ # effect on it. Record the requested CWD so that
+ # gdbserver_start can pass it to the inferior.
+ set ::inferior_cwd $output_dir
}
}
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index f7fb9258649..5de065bcea2 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -293,6 +293,13 @@ proc gdbserver_default_get_comm_port { port } {
return "$port"
}
+# Return 1 if "env" on the target supports the -C (--chdir) option.
+
+gdb_caching_proc gdbserver_env_has_chdir {} {
+ set status [lindex [remote_exec target "env -C / true"] 0]
+ return [expr {$status == 0}]
+}
+
# Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS.
# The port will be filled in between them automatically.
#
@@ -346,6 +353,33 @@ proc gdbserver_start { options arguments } {
set gdbserver [find_gdbserver]
+ # An inferior that gdbserver creates at startup inherits the CWD
+ # of gdbserver, so "set cwd" does not apply to it. Start the
+ # inferior in the requested CWD through a wrapper instead. This
+ # way gdbserver itself stays in the testsuite directory, and its
+ # own core dumps are still detected. gdbserver concatenates
+ # multiple --wrapper options incorrectly, so don't add one if the
+ # caller already passes a wrapper. With --multi (extended-remote),
+ # GDB starts the inferior with "run" and sends the "set cwd" value
+ # itself, so no wrapper is needed.
+ set cwd_wrapper ""
+ if { [info exists ::inferior_cwd] && ![is_remote target]
+ && [string first "--multi" $options] == -1 } {
+ if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
+ warning "gdbserver does not support --wrapper on this target\
+ (PR server/15967), core files may not be generated in\
+ $::inferior_cwd"
+ } elseif { [string first "--wrapper" $options] != -1 } {
+ warning "gdbserver already has a --wrapper, core files\
+ may not be generated in $::inferior_cwd"
+ } elseif { ![gdbserver_env_has_chdir] } {
+ warning "env does not support -C, core files may not be\
+ generated in $::inferior_cwd"
+ } else {
+ set cwd_wrapper "--wrapper env -C $::inferior_cwd --"
+ }
+ }
+
# Loop till we find a free port.
while 1 {
# Fire off the debug agent.
@@ -398,6 +432,9 @@ proc gdbserver_start { options arguments } {
}
}
+ if { $cwd_wrapper != "" } {
+ append gdbserver_command " $cwd_wrapper"
+ }
if { $options != "" } {
append gdbserver_command " $options"
}
--
2.34.1
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-26 9:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12 13:50 [PATCH 1/1] testsuite: Fix expected corefiles output folder for native-gdbserver boardfile Abdul Basit Ijaz
2026-10-26 9:44 ` [PING][PATCH " Ijaz, Abdul B
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox