]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: gdb.base/gcorebg.exp against installed binaries
authorLancelot SIX <lancelot.six@amd.com>
Wed, 29 Jan 2025 11:07:18 +0000 (11:07 +0000)
committerLancelot SIX <lancelot.six@amd.com>
Thu, 6 Feb 2025 14:16:11 +0000 (14:16 +0000)
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 <tom@tromey.com>
gdb/testsuite/gdb.base/gcorebg.c
gdb/testsuite/gdb.base/gcorebg.exp
gdb/testsuite/lib/gdb.exp

index 9b585b500dbf5e8e12aa8687a3523999704b094b..f0554541b1f89266f05744e85f9b372b2c8c8c01 100644 (file)
 #include <sys/wait.h>
 #include <errno.h>
 
-/* 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);
index c271251b7df37cc2bbdf50d2dbfdcb3908647347..3761f221b522f2c01c72554d902bc22fc8914533 100644 (file)
@@ -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
index 19e2ec42ddd57b99540e805a4c79ed775a352092..56dc8351e030b7be6e0f02c20d219e92c102977f 100644 (file)
@@ -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: