1 # Copyright 2014-2020 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Take a list of directories DIRS, and return a regular expression
19 # that will match against the output of the 'directory' command
20 # assuming that DIRS are all of the directories that should appear in
22 proc search_dir_list { dirs } {
23 set output "\r\nSource directories searched: "
24 append output [join $dirs "\[:;\]"]
29 # Check that adding directories to the search path changes the order
30 # in which directories are searched.
31 proc test_changing_search_directory {} {
36 gdb_test "directory $foo/a $foo/b $foo/c" \
37 [search_dir_list [list \
43 gdb_test "directory $foo/b $foo/d $foo/c" \
44 [search_dir_list [list \
54 # Test that the compilation directory can also be extended with a
55 # prefix from the directory search path in order to find source files.
56 proc test_truncated_comp_dir {} {
57 global srcfile srcdir subdir binfile
60 # When we run this test the current directory will be something
62 # /some/path/to/gdb/build/testsuite/
63 # We are going to copy the source file out of the source tree into
64 # a location like this:
65 # /some/path/to/gdb/build/testsuite/output/gdb.base/soure-dir/
67 # We will then switch to this directory and compile the source
68 # file, however, we will ask GCC to remove this prefix from the
69 # compilation directory in the debug info:
70 # /some/path/to/gdb/build/testsuite/output/
72 # As a result the debug information will look like this:
74 # DW_AT_name : source-dir.c
75 # DW_AT_comp_dir : /gdb.base/source-dir
77 # Finally we switch back to this directory:
78 # /some/path/to/gdb/build/testsuite/
80 # and start GDB. There was a time when GDB would be unable to
81 # find the source file no matter what we added to the directory
82 # search path, this should now be fixed.
84 set original_dir [pwd]
85 set working_dir [standard_output_file ""]
88 set strip_dir [file normalize "${working_dir}/../.."]
90 set new_srcfile [standard_output_file ${srcfile}]
91 set fd [open "$new_srcfile" w]
100 "debug additional_flags=-fdebug-prefix-map=${strip_dir}="
101 if { [gdb_compile "${srcfile}" "${binfile}" \
102 executable ${options}] != "" } {
103 untested "failed to compile"
109 clean_restart ${binfile}
111 gdb_test_no_output "set directories \$cdir:\$cwd"
112 gdb_test "show directories" \
113 "\r\nSource directories searched: \\\$cdir\[:;\]\\\$cwd"
115 if ![runto_main] then {
116 fail "can't run to main"
120 gdb_test "info source" \
122 "Current source file is ${srcfile}" \
123 "Compilation directory is \[^\n\r\]+" \
124 "Source language is c." \
125 "Producer is \[^\n\r\]+" \
126 "Compiled with DWARF $decimal debugging format." \
127 "Does not include preprocessor macro info." ] \
128 "info source before setting directory search list"
130 gdb_test "dir $strip_dir" \
131 [search_dir_list [list \
135 "setup source path search directory"
136 gdb_test "list" [multi_line \
138 "2\[ \t\]+main \\(\\)" \
140 "4\[ \t\]+return 0;" \
143 gdb_test "info source" \
145 "Current source file is ${srcfile}" \
146 "Compilation directory is \[^\n\r\]+" \
147 "Located in ${new_srcfile}" \
148 "Contains 5 lines." \
149 "Source language is c." \
150 "Producer is \[^\n\r\]+" \
153 "info source after setting directory search list"
156 test_changing_search_directory
157 test_truncated_comp_dir