From ad8677bc8995af992f39d5cce39a818354d26ef7 Mon Sep 17 00:00:00 2001 From: Lancelot SIX Date: Wed, 29 Jan 2025 11:07:18 +0000 Subject: [PATCH] gdb/testsuite: gdb.base/gcorebg.exp against installed binaries It is possible to run GDB's testsuite against installed binaries rather than the one from the build tree. For example, one could do: $ make check-gdb RUNTESTFLAGS=GDB=/usr/bin/gdb Running the testsuite this way causes error for gdb.base/gcorebg.exp: Running [...]/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 This is due to 2 problems. First, when running this way, the $GDB_DATA_DIRECTORY is not set (on purpose) as the installed GDB does not need to be specified where to find it. See this section in gdb/testsuite/lib/gdb.exp: if ![info exists GDB] { [....] } else { # If the user specifies GDB on the command line, and doesn't # specify GDB_DATA_DIRECTORY, then assume we're testing an # installed GDB, and let it use its own configured data directory. if ![info exists GDB_DATA_DIRECTORY] { set GDB_DATA_DIRECTORY "" } } The testbg.exp file always assumes a non-empty GDB_DATA_DIRECTORY. As a consequence, when calling the gcorebg binary with an empty argument (i.e. missing argument), the program fails: gcorebg: [...]/gdb/testsuite/gdb.base/gcorebg.c:42: main: Assertion `argc == 5' failed. FAIL: gdb.base/gcorebg.exp: detached=standard: Spawned gcore finished This patch does adjust the gcorebg.c and gcorebg.exp files to allow not specifying the data-directory. The other issue is that the testsuite assumes that the `gcore` to test is always the one from the build tree. However, if someone is testing an installed binary by setting GDB, I think that person would expect to test the `gcore` script next to the binary that was specified (unless GCORE is specified to explicitly specified). This patch does that adjustment as well. To that end, it needs to move the block setting GCORE after the block setting GDB. Change-Id: I070e039903c0b5afeac357d8fac7d710ff6697b9 Approved-By: Tom Tromey --- gdb/testsuite/gdb.base/gcorebg.c | 14 ++++++------ gdb/testsuite/gdb.base/gcorebg.exp | 6 +++++- gdb/testsuite/lib/gdb.exp | 34 +++++++++++++++--------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/gdb/testsuite/gdb.base/gcorebg.c b/gdb/testsuite/gdb.base/gcorebg.c index 9b585b500db..f0554541b1f 100644 --- a/gdb/testsuite/gdb.base/gcorebg.c +++ b/gdb/testsuite/gdb.base/gcorebg.c @@ -21,15 +21,15 @@ #include #include -/* Expects 4 arguments: +/* Expects 3 arguments: 1. Either 'standard' or 'detached', where 'standard' tests a general gcore script spawn with its controlling terminal available and 'detached' tests gcore script spawn without its controlling terminal available. - 2. Path to the gcore script. - 3. Path to the data-directory to pass to the gcore script. - 4. The core file output name. */ + 2. The command to invoke gcore (path to the gcore script and any necessary + flags). + 3. The core file output name. */ int main (int argc, char **argv) @@ -39,7 +39,7 @@ main (int argc, char **argv) char buf[1024*2 + 500]; int gotint, res; - assert (argc == 5); + assert (argc == 4); pid = fork (); @@ -49,8 +49,8 @@ main (int argc, char **argv) if (strcmp (argv[1], "detached") == 0) setpgrp (); ppid = getppid (); - gotint = snprintf (buf, sizeof (buf), "%s -d %s -o %s %d", - argv[2], argv[3], argv[4], (int) ppid); + gotint = snprintf (buf, sizeof (buf), "%s -o %s %d", + argv[2], argv[3], (int) ppid); assert (gotint < sizeof (buf)); res = system (buf); assert (res != -1); diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp index c271251b7df..3761f221b52 100644 --- a/gdb/testsuite/gdb.base/gcorebg.exp +++ b/gdb/testsuite/gdb.base/gcorebg.exp @@ -49,7 +49,11 @@ proc test_body { detached } { global GDB_DATA_DIRECTORY # We can't use gdb_test_multiple here because GDB is not started. - set res [remote_spawn target "$binfile $detached $GCORE $GDB_DATA_DIRECTORY $corefile"] + set gcore_cmd $GCORE + if {$GDB_DATA_DIRECTORY ne ""} { + set gcore_cmd "$gcore_cmd -d '$GDB_DATA_DIRECTORY'" + } + set res [remote_spawn target "$binfile $detached \"$gcore_cmd\" $corefile"] if { ![gdb_assert { ![expr {$res < 0 || $res == ""}] } \ "spawned gcore"] } { return diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 19e2ec42ddd..56dc8351e03 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -158,23 +158,6 @@ load_lib gdb-utils.exp load_lib memory.exp load_lib check-test-names.exp -# The path to the GCORE script to test. -global GCORE -if {![info exists GCORE]} { - set GCORE [findfile $base_dir/../../gdb/gcore] -} -verbose "using GCORE = $GCORE" 2 - -# Return 0 if the gcore scipt is missing. -proc has_gcore_script {} { - global GCORE - if {$GCORE == ""} { - return 0 - } else { - return 1 - } -} - # The path to the GDB binary to test. global GDB @@ -217,6 +200,23 @@ if ![info exists GDB_DATA_DIRECTORY] { } verbose "using GDB_DATA_DIRECTORY = $GDB_DATA_DIRECTORY" 2 +# The path to the GCORE script to test. +global GCORE +if {![info exists GCORE]} { + set GCORE [file join [file dirname $GDB] [transform gcore]] +} +verbose "using GCORE = $GCORE" 2 + +# Return 0 if the gcore scipt is missing. +proc has_gcore_script {} { + global GCORE + if {$GCORE == ""} { + return 0 + } else { + return 1 + } +} + # GDBFLAGS is available for the user to set on the command line. # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble # Testcases may use it to add additional flags, but they must: -- 2.39.5