]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: fix FAILs in fileio.exp
authorJan Vrany <jan.vrany@labware.com>
Mon, 19 Jan 2026 08:58:41 +0000 (08:58 +0000)
committerJan Vrany <jan.vrany@labware.com>
Mon, 19 Jan 2026 08:58:41 +0000 (08:58 +0000)
I'm experiencing intermittent FAILs in fileio.exp when running on (my)
CI:

    FAIL: gdb.base/fileio.exp: Open a file
    FAIL: gdb.base/fileio.exp: Creating already existing file returns EEXIST
    FAIL: gdb.base/fileio.exp: Open for write but no write permission returns EACCES
    FAIL: gdb.base/fileio.exp: Writing to a file
    ...

The problem turned out to be the way the OUTDIR gets defined in fileio.c.
The path is passed down "naked" and turned into string by STRINGIFY macro.

However, if the path happens to contain name of unrelated pre-existing
C macro, this macro gets expanded during the "stringification", resulting
in (likely) different path than used in fileio.exp and therefore causing
failures.

For example, if the GDB is compiled and tested in directory

    /var/lib/jenkins/workspace/binutils-gdb/build/x86_64-linux-gnu

then fileio.c is compiled with

   -DOUTDIR_=/var/lib/jenkins/workspace/binutils-gdb/build/x86_64-linux-gnu/gdb/testsuite/outputs/gdb.base/fileio

But because there's also C macro named "linux" defined to 1, the resulting
OUTDIR is actually:

   /var/lib/jenkins/workspace/binutils-gdb/build/x86_64-1-gnu/gdb/testsuite/outputs/gdb.base/fileio

This commit fixes this by defining the OUTDIR as string literal in first
place (similarly to how it was done prior commit cc91060) and updating
quote_for_host to handle strings that themselves contains quote (").

Tested on x86_64-linux by running all tests using quote_for_host with
both target board unix and host/target board local-remote-host-native.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.base/fileio.c
gdb/testsuite/gdb.base/fileio.exp
gdb/testsuite/lib/gdb.exp

index 0ef85a26bee5bf5f651da62663dd659a22e674be..7007e6879ef383c5055a637954ec74b2cb71dc88 100644 (file)
@@ -73,10 +73,6 @@ static const char *strerrno (int err);
 
 #define STRING      "Hello World"
 
-#define STRINGIFY(s) STRINGIFY_(s)
-#define STRINGIFY_(s) #s
-#define OUTDIR STRINGIFY (OUTDIR_)
-
 static void stop (void) {}
 
 /* A NULL string.  We pass this to stat below instead of a NULL
index 2ecf50c3b7e4e8f9ef4f84135abeca86f09862e3..d33c8224a10f1d4c5633da47496758b885971cb5 100644 (file)
@@ -27,7 +27,7 @@ if {[is_remote host]} {
 
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
           executable \
-          [list debug additional_flags=[quote_for_host -DOUTDIR_=$outdir/]]] != "" } {
+          [list debug additional_flags=[quote_for_host -DOUTDIR=\"$outdir/\"]]] != "" } {
     untested "failed to compile"
     return -1
 }
index 68fd2b55ee73c13d3dafaeec80d5889b2a797157..7ac26f417ba80a5137a3369a16c6f69a261c650d 100644 (file)
@@ -6138,9 +6138,9 @@ proc escape_for_host { str } {
 proc quote_for_host { args } {
     set str [join $args]
     if { [is_remote host] } {
-       set str [join [list {\"} $str {\"}] ""]
+       set str [join [list {\"} [regsub -all {"} $str {\\\"}] {\"}] ""]
     } else {
-       set str [join [list {"} $str {"}] ""]
+       set str [join [list {"} [regsub -all {"} $str {\"}] {"}] ""]
     }
     return $str
 }