standard_testfile
set srcfileabs [standard_output_file $srcfile]
-# "//$srcfile" It is used for the test of compare_filenames_for_search.
+# Double the final slash separator in $srcfileabs, such that
+# "/path/to/$srcfile" becomes "/path/to//$srcfile". This is
+# passed as the "source" argument of gdb_compile, which, when
+# using GCC (as of 10.2) will result in the doubled slash
+# being incorporated into the built executable's debug info.
+# This is then used to check compare_filenames_for_search does
+# not falsely use an absolute filename as a relative one.
+# Note that Clang (as of 12.0.0) normalizes the path before
+# storing it in the executable's debug info, removing the double
+# slash. This nullifies the "compare_filenames_for_search does
+# not match" test when using Clang (it can never fail).
if { [regsub {/[^/]+$} $srcfileabs {/\0} srcfileabs] != 1 } {
xfail "cannot double the last slash separator"
return -1
return -1
}
+# Generate a regular expression which to match $srcfileabs with
+# or without the doubled slash. This is used by the substituted
+# fullname test.
+set srcfileabssubst_regexp [string_to_regexp $srcfileabssubst]
+regsub {//} $srcfileabssubst_regexp {\0?} srcfileabssubst_regexp
+
set f [open $srcfileabs "w"]
puts $f "int main (void) { return 0; }"
close $f
mi_gdb_test "-file-list-exec-source-file" ".*\",fullname=\".*\".*" "fullname present"
-mi_gdb_test "-file-list-exec-source-file" ".*\",fullname=\"[string_to_regexp $srcfileabssubst]\".*" "substituted fullname"
+mi_gdb_test "-file-list-exec-source-file" ".*\",fullname=\"$srcfileabssubst_regexp\".*" "substituted fullname"
-# Test compare_filenames_for_search does not falsely use absolute filename as
-# a relative one.
+# Test compare_filenames_for_search does not falsely use absolute
+# filename as a relative one. Note that this test can falsely pass
+# with Clang, and possibly other compilers too; see the comment
+# above for more.
mi_gdb_test "-break-insert -t /$srcfile:main" \
"\\^error,msg=\"No source file named /[string_to_regexp $srcfile]\\.\"" \
"compare_filenames_for_search does not match"