1 # This testcase is part of GDB, the GNU debugger. 2 3 # Copyright 2022-2024 Free Software Foundation, Inc. 4 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 # Compile a source file using different ways of passing the path to the 19 # compiler. Then, verify that we can print a macro defined in that file. 20 21 standard_testfile 22 23 # If the host is remote, source files are uploaded to the host and compiled 24 # there, but without the directory structure we expect, making the test 25 # pointless. Skip the test in that case. 26 require {!is_remote host} 27 28 # Copy the source file at these locations in the output directory ($out): 29 # 30 # $out/cwd/macro-source-path.c 31 # $out/other/macro-source-path.c 32 # 33 # Set the current working directory to $out/cwd, so that we can test compiling 34 # using relative paths. 35 36 set out_dir [standard_output_file ""] 37 file mkdir $out_dir/cwd 38 file mkdir $out_dir/other 39 file copy -force $srcdir/$subdir/$srcfile $out_dir/cwd 40 file copy -force $srcdir/$subdir/$srcfile $out_dir/other 41 42 # Run one test. 43 # 44 # SRC is the path to the source file, to be passed to the compiler as-is. 45 # NAME is the name of the test. 46 47 proc test { src name } { 48 with_test_prefix $name { 49 set binfile $::out_dir/$name 50 51 if { [gdb_compile $src $binfile executable {debug macros additional_flags=-DONE=1}] != "" } { 52 fail "could not compile" 53 return 54 } 55 56 clean_restart $binfile 57 58 if { ![runto_main] } { 59 return 60 } 61 62 # Print the macro that is defined on the command-line. 63 gdb_test "print ONE" " = 1" 64 65 # Print the macro that is defined in the main file. 66 gdb_test "print TWO" " = 2" 67 } 68 } 69 70 # When adding a test here, please consider adding an equivalent case to the test 71 # of the same name in gdb.dwarf2. 72 73 with_cwd "$out_dir/cwd" { 74 test $testfile.c filename 75 test ./$testfile.c dot-filename 76 test ../cwd/$testfile.c dot-dot-filename 77 test [file normalize $testfile.c] absolute-cwd 78 test ../other/$testfile.c dot-dot-other 79 test [file normalize ../other/$testfile.c] absolute-other 80 } 81