From: Jan Vrany Date: Mon, 19 Jan 2026 08:58:41 +0000 (+0000) Subject: gdb/testsuite: fix FAILs in fileio.exp X-Git-Tag: binutils-2_46~203 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d2cc16cd7fc96367132332cf26348be18435a851;p=thirdparty%2Fbinutils-gdb.git gdb/testsuite: fix FAILs in fileio.exp 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 --- diff --git a/gdb/testsuite/gdb.base/fileio.c b/gdb/testsuite/gdb.base/fileio.c index 0ef85a26bee..7007e6879ef 100644 --- a/gdb/testsuite/gdb.base/fileio.c +++ b/gdb/testsuite/gdb.base/fileio.c @@ -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 diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp index 2ecf50c3b7e..d33c8224a10 100644 --- a/gdb/testsuite/gdb.base/fileio.exp +++ b/gdb/testsuite/gdb.base/fileio.exp @@ -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 } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 68fd2b55ee7..7ac26f417ba 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -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 }