]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix gdb.base/gcorebg.exp and --program-prefix
authorPedro Alves <pedro@palves.net>
Wed, 20 Aug 2025 09:30:25 +0000 (10:30 +0100)
committerPedro Alves <pedro@palves.net>
Tue, 16 Sep 2025 11:00:38 +0000 (12:00 +0100)
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.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Change-Id: I6c60fba8768618eeba8d8d03b131dc756b57ee78

gdb/NEWS
gdb/doc/gdb.texinfo
gdb/gcore-1.in [changed mode: 0644->0755]
gdb/testsuite/gdb.base/gcorebg.exp

index 01bd1524c7ae38e9a3c75394005a6154313598ea..2f3a26048d88370908e9b35a57156e4628cce01b 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -67,6 +67,9 @@ single-inf-arg in qSupported
   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
index 676143be416684dc8ca076b7bb46be1afc0741f6..6b0cfec26ebad2820bf157cb158823ee39188a44 100644 (file)
@@ -51790,6 +51790,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.
old mode 100644 (file)
new mode 100755 (executable)
index 2f6eb02..d733682
@@ -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
index 3e79702e2f9bd09b5ef72693c23dbd3b5e625227..fd9f06ed685b0e1e71d46daa6e99082b4bfd3a5e 100644 (file)
@@ -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'"
     }