1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2022-2023 Free Software Foundation, Inc.
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.
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.
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/>.
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.
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 if { [is_remote host] } {
30 # Copy the source file at these locations in the output directory ($out):
32 # $out/cwd/macro-source-path.c
33 # $out/other/macro-source-path.c
35 # Set the current working directory to $out/cwd, so that we can test compiling
36 # using relative paths.
38 set out_dir [standard_output_file ""]
39 file mkdir $out_dir/cwd
40 file mkdir $out_dir/other
41 file copy -force $srcdir/$subdir/$srcfile $out_dir/cwd
42 file copy -force $srcdir/$subdir/$srcfile $out_dir/other
46 # SRC is the path to the source file, to be passed to the compiler as-is.
47 # NAME is the name of the test.
49 proc test { src name } {
50 with_test_prefix $name {
51 set binfile $::out_dir/$name
53 if { [gdb_compile $src $binfile executable {debug macros additional_flags=-DONE=1}] != "" } {
54 fail "could not compile"
58 clean_restart $binfile
60 if { ![runto_main] } {
64 # Print the macro that is defined on the command-line.
65 gdb_test "print ONE" " = 1"
67 # Print the macro that is defined in the main file.
68 gdb_test "print TWO" " = 2"
72 # When adding a test here, please consider adding an equivalent case to the test
73 # of the same name in gdb.dwarf2.
75 with_cwd "$out_dir/cwd" {
76 test $testfile.c filename
77 test ./$testfile.c dot-filename
78 test ../cwd/$testfile.c dot-dot-filename
79 test [file normalize $testfile.c] absolute-cwd
80 test ../other/$testfile.c dot-dot-other
81 test [file normalize ../other/$testfile.c] absolute-other