Commit | Line | Data |
---|---|---|
42a4f53d | 1 | # Copyright 2014-2019 Free Software Foundation, Inc. |
5e3f4fab EBM |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
16 | standard_testfile | |
17 | ||
f1b620e9 MG |
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 | |
21 | # the results. | |
22 | proc search_dir_list { dirs } { | |
23 | set output "\r\nSource directories searched: " | |
24 | append output [join $dirs "\[:;\]"] | |
5e3f4fab | 25 | |
f1b620e9 MG |
26 | return ${output} |
27 | } | |
5e3f4fab | 28 | |
f1b620e9 MG |
29 | # Check that adding directories to the search path changes the order |
30 | # in which directories are searched. | |
31 | proc test_changing_search_directory {} { | |
32 | gdb_start | |
33 | ||
34 | set foo "/nOtExStInG" | |
35 | ||
36 | gdb_test "directory $foo/a $foo/b $foo/c" \ | |
37 | [search_dir_list [list \ | |
38 | "$foo/a" \ | |
39 | "$foo/b" \ | |
40 | "$foo/c" \ | |
41 | "\\\$cdir" \ | |
42 | "\\\$cwd"]] | |
43 | gdb_test "directory $foo/b $foo/d $foo/c" \ | |
44 | [search_dir_list [list \ | |
45 | "$foo/b" \ | |
46 | "$foo/d" \ | |
47 | "$foo/c" \ | |
48 | "$foo/a" \ | |
49 | "\\\$cdir" \ | |
50 | "\\\$cwd"]] | |
51 | gdb_exit | |
52 | } | |
53 | ||
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 | |
58 | global decimal | |
59 | ||
60 | # When we run this test the current directory will be something | |
61 | # like this: | |
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/ | |
66 | # | |
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/ | |
71 | # | |
72 | # As a result the debug information will look like this: | |
73 | # | |
74 | # DW_AT_name : source-dir.c | |
75 | # DW_AT_comp_dir : /gdb.base/source-dir | |
76 | # | |
77 | # Finally we switch back to this directory: | |
78 | # /some/path/to/gdb/build/testsuite/ | |
79 | # | |
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. | |
83 | ||
84 | set original_dir [pwd] | |
85 | set working_dir [standard_output_file ""] | |
86 | cd ${working_dir} | |
87 | ||
88 | set strip_dir [file normalize "${working_dir}/../.."] | |
89 | ||
90 | set new_srcfile [standard_output_file ${srcfile}] | |
91 | set fd [open "$new_srcfile" w] | |
92 | puts $fd "int | |
93 | main () | |
94 | { | |
95 | return 0; | |
96 | }" | |
97 | close $fd | |
98 | ||
99 | set options \ | |
100 | "debug additional_flags=-fdebug-prefix-map=${strip_dir}=" | |
101 | if { [gdb_compile "${srcfile}" "${binfile}" \ | |
102 | executable ${options}] != "" } { | |
103 | untested "failed to compile" | |
104 | return -1 | |
105 | } | |
106 | ||
107 | cd ${original_dir} | |
108 | ||
109 | clean_restart ${binfile} | |
110 | ||
111 | gdb_test_no_output "set directories \$cdir:\$cwd" | |
112 | gdb_test "show directories" \ | |
113 | "\r\nSource directories searched: \\\$cdir\[:;\]\\\$cwd" | |
114 | ||
115 | if ![runto_main] then { | |
116 | fail "can't run to main" | |
117 | return 0 | |
118 | } | |
119 | ||
120 | gdb_test "info source" \ | |
121 | [multi_line \ | |
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" | |
129 | ||
130 | gdb_test "dir $strip_dir" \ | |
131 | [search_dir_list [list \ | |
132 | "$strip_dir" \ | |
133 | "\\\$cdir" \ | |
134 | "\\\$cwd"]] | |
135 | gdb_test "list" [multi_line \ | |
136 | "1\[ \t\]+int" \ | |
137 | "2\[ \t\]+main \\(\\)" \ | |
138 | "3\[ \t\]+\\{" \ | |
139 | "4\[ \t\]+return 0;" \ | |
140 | "5\[ \t\]+\\}" ] | |
141 | ||
142 | gdb_test "info source" \ | |
143 | [multi_line \ | |
144 | "Current source file is ${srcfile}" \ | |
145 | "Compilation directory is \[^\n\r\]+" \ | |
146 | "Located in ${new_srcfile}" \ | |
147 | "Contains 5 lines." \ | |
148 | "Source language is c." \ | |
149 | "Producer is \[^\n\r\]+" \ | |
150 | "\[^\n\r\]+" \ | |
151 | "\[^\n\r\]+" ] \ | |
152 | "info source after setting directory search list" | |
153 | } | |
154 | ||
155 | test_changing_search_directory | |
156 | test_truncated_comp_dir |