]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/macro-source-path.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / macro-source-path.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2022-2023 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 if { [is_remote host] } {
27 return
28 }
29
30 # Copy the source file at these locations in the output directory ($out):
31 #
32 # $out/cwd/macro-source-path.c
33 # $out/other/macro-source-path.c
34 #
35 # Set the current working directory to $out/cwd, so that we can test compiling
36 # using relative paths.
37
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
43
44 # Run one test.
45 #
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.
48
49 proc test { src name } {
50 with_test_prefix $name {
51 set binfile $::out_dir/$name
52
53 if { [gdb_compile $src $binfile executable {debug macros additional_flags=-DONE=1}] != "" } {
54 fail "could not compile"
55 return
56 }
57
58 clean_restart $binfile
59
60 if { ![runto_main] } {
61 return
62 }
63
64 # Print the macro that is defined on the command-line.
65 gdb_test "print ONE" " = 1"
66
67 # Print the macro that is defined in the main file.
68 gdb_test "print TWO" " = 2"
69 }
70 }
71
72 # When adding a test here, please consider adding an equivalent case to the test
73 # of the same name in gdb.dwarf2.
74
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
82 }