From: Pedro Alves Date: Wed, 20 Aug 2025 09:30:25 +0000 (+0100) Subject: Fix gdb.base/gcorebg.exp and --program-prefix X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b655a89ff523f459f8effaf17694a7248517a99b;p=thirdparty%2Fbinutils-gdb.git Fix gdb.base/gcorebg.exp and --program-prefix 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@" Change-Id: I6c60fba8768618eeba8d8d03b131dc756b57ee78 --- diff --git a/gdb/NEWS b/gdb/NEWS index 01bd1524c7a..2f3a26048d8 100644 --- 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 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 676143be416..6b0cfec26eb 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -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. 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 # `