Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix gdb.base/gcorebg.exp and --program-prefix
@ 2025-08-22 20:23 Pedro Alves
  2025-08-23 19:24 ` Kevin Buettner
  0 siblings, 1 reply; 2+ messages in thread
From: Pedro Alves @ 2025-08-22 20:23 UTC (permalink / raw)
  To: gdb-patches

When GDB is configured with --program-prefix, we see:

 Running /home/pedro/gdb/src/gdb/testsuite/gdb.base/gcorebg.exp ...
 FAIL: gdb.base/gcorebg.exp: detached=detached: Spawned gcore finished
 FAIL: gdb.base/gcorebg.exp: detached=detached: Core file generated by gcore
 FAIL: gdb.base/gcorebg.exp: detached=standard: Spawned gcore finished
 FAIL: gdb.base/gcorebg.exp: detached=standard: Core file generated by gcore

The problem is here (with --program-prefix=prefix-), from gdb.log:
 gcore: GDB binary (/home/pedro/gdb/build-program-prefix/gdb/testsuite/../../gdb/prefix-gdb) not found
 FAIL: gdb.base/gcorebg.exp: detached=detached: Spawned gcore finished

That is gcore (the script, not the GDB command) trying to run the
installed GDB:

if [ ! -f "$binary_path/@GDB_TRANSFORM_NAME@" ]; then
  echo "gcore: GDB binary (${binary_path}/@GDB_TRANSFORM_NAME@) not found"
  exit 1
fi
...
	"$binary_path/@GDB_TRANSFORM_NAME@" </dev/null \
...

When running the testsuite with the just-built GDB, the GDB binary is
'gdb', not @GDB_TRANSFORM_NAME@.

Fix this by adding a new '-g gdb" option to the 'gcore' script, that
lets you override the GDB binary gcore runs, and then making
gdb.base/gcorebg.exp pass it to gcore.  The GDB binary we're testing
is always in the $GDB global.  This is similar to how it is already
possible to specify GDB's data directory with an option to gcore, and
then gdb.base/gcorebg.exp uses it.

NEWS and documentation changes included.

Change-Id: I6c60fba8768618eeba8d8d03b131dc756b57ee78
---
 gdb/NEWS                           |  3 +++
 gdb/doc/gdb.texinfo                |  6 ++++++
 gdb/gcore-1.in                     | 26 ++++++++++++++++++++------
 gdb/testsuite/gdb.base/gcorebg.exp |  4 ++--
 4 files changed, 31 insertions(+), 8 deletions(-)
 mode change 100644 => 100755 gdb/gcore-1.in

diff --git a/gdb/NEWS b/gdb/NEWS
index db0e74a2623..f8e817299c9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -35,6 +35,9 @@
   a -h or --help option, which prints each options and a brief
   description.
 
+* The gcore script now has a -g option that lets you specify the GDB
+  binary invoked by gcore.
+
 * On systems that support linker namespaces, the output of the command
   "info sharedlibraries" may add one more column, NS, which identifies the
   namespace into which the library was loaded, if more than one namespace
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7718a9c4d83..418a9e33c18 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -51530,6 +51530,12 @@ composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
 process ID of the running program being analyzed by @command{gcore}.
 If not specified, @var{prefix} defaults to @var{core}.
 
+@item -g @var{gdb}
+Use @var{gdb} as the executable binary to invoke @value{GDBN} for
+running the gcore command.  This argument is optional, and defaults to
+invoking the @value{GDBN} binary that is installed alongside
+@command{gcore}.
+
 @item -d @var{directory}
 Use @var{directory} as the data directory when invoking @value{GDBN} for running
 the gcore command. This argument is optional.
diff --git a/gdb/gcore-1.in b/gdb/gcore-1.in
old mode 100644
new mode 100755
index 2f6eb02557a..d733682704d
--- a/gdb/gcore-1.in
+++ b/gdb/gcore-1.in
@@ -32,12 +32,15 @@ dump_all_cmds=()
 
 data_directory_opt=()
 
+# The GDB binary to run.
+gdb_binary=
+
 function print_usage() {
     prefix="Usage: $0"
     padding=$(printf '%*s' ${#prefix})
 
     echo "$prefix [-h|--help] [-v|--version]"
-    echo "$padding [-a] [-o prefix] [-d data-directory]"
+    echo "$padding [-a] [-o prefix] [-g gdb] [-d data-directory]"
     echo "$padding pid1 [pid2...pidN]"
 }
 
@@ -55,6 +58,8 @@ function print_help() {
     echo "  -a                 Dump all memory mappings."
     echo "  -o prefix          Use 'prefix.pid' as the core file name."
     echo "                       The default prefix is 'core'."
+    echo "  -g gdb             The GDB binary to run."
+    echo "                       Defaults to GDB installed alongside gcore."
     echo "  -d dir             Pass '--data-directory dir' as an argument"
     echo "                       to GDB."
 }
@@ -63,7 +68,7 @@ function print_version() {
     echo "GNU gcore (${PKGVERSION}) ${VERSION}"
 }
 
-while getopts vhao:d:-: OPT; do
+while getopts vhao:g:d:-: OPT; do
     if [ "$OPT" = "-" ]; then
 	OPT="${OPTARG%%=*}"
 	OPTARG="${OPTARG#'$OPT'}"
@@ -82,6 +87,9 @@ while getopts vhao:d:-: OPT; do
         o)
             prefix=$OPTARG
             ;;
+        g)
+            gdb_binary="$OPTARG"
+            ;;
         d)
             data_directory_opt=("--data-directory" "$OPTARG")
             ;;
@@ -144,10 +152,16 @@ if test "x$binary_path" = x. ; then
   fi
 fi
 
+if [ -z "$gdb_binary" ]; then
+   gdb_binary="$binary_path/@GDB_TRANSFORM_NAME@"
+fi
+
+gdb_binary_basename=`basename "$gdb_binary"`
+
 # Check if the GDB binary is in the expected path.  If not, just
 # quit with a message.
-if [ ! -f "$binary_path/@GDB_TRANSFORM_NAME@" ]; then
-  echo "gcore: GDB binary (${binary_path}/@GDB_TRANSFORM_NAME@) not found"
+if [ ! -f "$gdb_binary" ]; then
+  echo "gcore: GDB binary ($gdb_binary) not found"
   exit 1
 fi
 
@@ -159,7 +173,7 @@ for pid in "$@"
 do
 	# `</dev/null' to avoid touching interactive terminal if it is
 	# available but not accessible as GDB would get stopped on SIGTTIN.
-	"$binary_path/@GDB_TRANSFORM_NAME@" </dev/null \
+	"$gdb_binary" </dev/null \
             "${data_directory_opt[@]}" \
 	    --nx --batch --readnever -iex 'set debuginfod enabled off' \
 	    -ex "set pagination off" -ex "set height 0" -ex "set width 0" \
@@ -169,7 +183,7 @@ do
 	if [ -r "$prefix.$pid" ] ; then
 	    rc=0
 	else
-	    echo "@GCORE_TRANSFORM_NAME@: failed to create $prefix.$pid"
+	    echo "$gdb_binary_basename: failed to create $prefix.$pid"
 	    rc=1
 	    break
 	fi
diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp
index 3e79702e2f9..fd9f06ed685 100644
--- a/gdb/testsuite/gdb.base/gcorebg.exp
+++ b/gdb/testsuite/gdb.base/gcorebg.exp
@@ -46,10 +46,10 @@ proc test_body { detached } {
     global binfile
     global GCORE
     global corefile
-    global GDB_DATA_DIRECTORY
+    global GDB GDB_DATA_DIRECTORY
 
     # We can't use gdb_test_multiple here because GDB is not started.
-    set gcore_cmd $GCORE
+    set gcore_cmd "$GCORE -g $GDB"
     if {$GDB_DATA_DIRECTORY ne ""} {
 	    set gcore_cmd "$gcore_cmd -d '$GDB_DATA_DIRECTORY'"
     }

base-commit: 8feea8c5d8cc2573da61fee3fd42cf3392ec0f0e
-- 
2.50.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-23 19:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-22 20:23 [PATCH] Fix gdb.base/gcorebg.exp and --program-prefix Pedro Alves
2025-08-23 19:24 ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox