]>
Commit | Line | Data |
---|---|---|
42a4f53d | 1 | # Copyright 2012-2019 Free Software Foundation, Inc. |
1b56eb55 JK |
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 | load_lib dwarf.exp | |
16 | ||
17 | # This test can only be run on targets which support DWARF-2 and use gas. | |
18 | if {![dwarf2_support]} { | |
19 | return 0 | |
20 | } | |
21 | ||
22a2ab04 SL |
22 | # This test has hard-wired assumptions that host and build filenames are |
23 | # the same, and assumes POSIX pathname syntax. | |
24 | if { [is_remote host] || [ishost *-*-mingw*] } { | |
25 | unsupported "dw2-dir-file-name.exp can only run on local host" | |
26 | return 0 | |
27 | } | |
28 | ||
bd286a29 KCY |
29 | # Find length of addresses in bytes. |
30 | if {[is_64_target]} { | |
31 | set addr_len 8 | |
32 | } else { | |
33 | set addr_len 4 | |
34 | } | |
35 | ||
1b56eb55 JK |
36 | standard_testfile |
37 | set asmsrcfile [standard_output_file ${testfile}asm.S] | |
38 | set asmobjfile [standard_output_file ${testfile}asm.o] | |
39 | set srcabsdir [standard_output_file ${testfile}.d] | |
40 | set srctmpfile tmp-${testfile}.c | |
41 | ||
42 | # $srcdir may be relative. | |
43 | if {[file pathtype $srcabsdir] != "absolute"} { | |
44 | untested "objdir pathtype is not absolute" | |
45 | return -1 | |
46 | } | |
47 | ||
48 | set f [open $asmsrcfile "w"] | |
49 | puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */" | |
50 | ||
51 | proc out_cu { name cu_dir cu_name line_dir line_name } { | |
52 | global f | |
bd286a29 | 53 | global addr_len |
1b56eb55 JK |
54 | |
55 | puts -nonewline $f "\ | |
56 | .L${name}_begin: | |
57 | .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */ | |
58 | .L${name}_start: | |
59 | .2byte 2 /* DWARF Version */ | |
60 | .4byte .Labbrev1_begin /* Offset into abbrev section */ | |
bd286a29 | 61 | .byte ${addr_len} /* Pointer size */ |
1b56eb55 JK |
62 | " |
63 | if { $cu_dir != "" } { | |
64 | puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */" | |
65 | } else { | |
66 | puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */" | |
67 | } | |
68 | puts -nonewline $f "\ | |
69 | .ascii \"GNU C\\0\" /* DW_AT_producer */ | |
70 | .byte 2 /* DW_AT_language (DW_LANG_C) */ | |
71 | .4byte .Lline_${name}_begin /* DW_AT_stmt_list */ | |
bd286a29 KCY |
72 | .${addr_len}byte ${name}_start /* DW_AT_low_pc */ |
73 | .${addr_len}byte ${name}_end /* DW_AT_high_pc */ | |
1b56eb55 JK |
74 | " |
75 | if { $cu_dir != "" } { | |
76 | puts $f " .ascii $cu_dir /* DW_AT_comp_dir */" | |
77 | } | |
78 | puts -nonewline $f "\ | |
79 | .ascii $cu_name /* DW_AT_name */ | |
80 | ||
81 | .uleb128 3 /* Abbrev: DW_TAG_subprogram */ | |
82 | .asciz \"${name}\" /* DW_AT_name */ | |
bd286a29 KCY |
83 | .${addr_len}byte ${name}_start /* DW_AT_low_pc */ |
84 | .${addr_len}byte ${name}_end /* DW_AT_high_pc */ | |
1b56eb55 JK |
85 | |
86 | .byte 0 /* End of children of CU */ | |
87 | .L${name}_end: | |
88 | " | |
89 | } | |
90 | ||
91 | proc out_line { name cu_dir cu_name line_dir line_name } { | |
92 | global f | |
bd286a29 | 93 | global addr_len |
1b56eb55 JK |
94 | |
95 | puts -nonewline $f "\ | |
96 | .Lline_${name}_begin: | |
97 | .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */ | |
98 | .Lline_${name}_start: | |
99 | .2byte 2 /* Version */ | |
100 | .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */ | |
101 | .Lline_${name}_hdr: | |
102 | .byte 1 /* Minimum insn length */ | |
103 | .byte 1 /* default_is_stmt */ | |
104 | .byte 1 /* line_base */ | |
105 | .byte 1 /* line_range */ | |
106 | .byte 4 /* opcode_base */ | |
107 | ||
108 | /* Standard lengths */ | |
109 | .byte 0 | |
110 | .byte 1 | |
111 | .byte 1 | |
112 | ||
113 | /* Include directories */ | |
114 | " | |
115 | if { $line_dir != "" } { | |
116 | puts $f " .ascii $line_dir" | |
117 | } | |
118 | puts -nonewline $f "\ | |
119 | .byte 0 | |
120 | ||
121 | /* File names */ | |
122 | .ascii $line_name | |
123 | " | |
124 | if { $line_dir != "" } { | |
125 | puts $f " .uleb128 1" | |
126 | } else { | |
127 | puts $f " .uleb128 0" | |
128 | } | |
129 | puts -nonewline $f "\ | |
130 | .uleb128 0 | |
131 | .uleb128 0 | |
132 | ||
133 | .byte 0 | |
134 | ||
135 | .Lline_${name}_lines: | |
136 | .byte 3 /* DW_LNS_advance_line */ | |
137 | .sleb128 998 /* ... to 999 */ | |
138 | .byte 0 /* DW_LNE_set_address */ | |
bd286a29 | 139 | .uleb128 ${addr_len}+1 |
1b56eb55 | 140 | .byte 2 |
bd286a29 | 141 | .${addr_len}byte ${name}_start |
1b56eb55 JK |
142 | .byte 1 /* DW_LNS_copy */ |
143 | .byte 3 /* DW_LNS_advance_line */ | |
144 | .sleb128 1 /* ... to 1000 */ | |
145 | .byte 0 /* DW_LNE_set_address */ | |
bd286a29 | 146 | .uleb128 ${addr_len}+1 |
1b56eb55 | 147 | .byte 2 |
bd286a29 | 148 | .${addr_len}byte ${name}_end |
1b56eb55 JK |
149 | .byte 1 /* DW_LNS_copy */ |
150 | .byte 0 /* DW_LNE_end_of_sequence */ | |
151 | .uleb128 1 | |
152 | .byte 1 | |
153 | .Lline_${name}_end: | |
154 | " | |
155 | } | |
156 | ||
157 | # IFSOME can be optionally _same or _different if >= 2 absolute directories are | |
158 | # provided. Then in the _different case the overriden directories have invalid | |
159 | # XDIR value. | |
160 | ||
161 | proc out_unit { func compdir ldir file ifsame } { | |
162 | set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}" | |
163 | ||
164 | if { $compdir == "missing_" } { | |
165 | set cu_dir {} | |
166 | } elseif { $compdir == "relative" } { | |
167 | set cu_dir {COMPDIR "\0"} | |
168 | } elseif { $compdir == "absolute" } { | |
169 | set cu_dir {BDIR "/" COMPDIR "\0"} | |
170 | } else { | |
171 | error "compdir $compdir" | |
172 | } | |
173 | ||
174 | if { $ldir == "missing_" } { | |
175 | set line_dir {} | |
176 | } elseif { $ldir == "relative" } { | |
177 | set line_dir {LDIR "\0"} | |
178 | } elseif { $ldir == "absolute" } { | |
179 | set line_dir {BDIR "/" LDIR "\0"} | |
180 | } else { | |
181 | error "ldir $ldir" | |
182 | } | |
183 | ||
184 | if { $file == "basename" } { | |
185 | set cu_name {FILE "\0"} | |
186 | } elseif { $file == "relative" } { | |
187 | set cu_name {FDIR "/" FILE "\0"} | |
188 | } elseif { $file == "absolute" } { | |
189 | set cu_name {BDIR "/" FILE "\0"} | |
190 | } else { | |
191 | error "file $file" | |
192 | } | |
193 | set line_name $cu_name | |
194 | ||
195 | if { "$ifsame" == "_different" } { | |
196 | if { $file == "absolute" } { | |
197 | if { $ldir == "absolute" } { | |
198 | set line_dir {XDIR "\0"} | |
199 | } | |
200 | if { $compdir == "absolute" } { | |
201 | set cu_dir {XDIR "\0"} | |
202 | } | |
203 | } elseif { $ldir == "absolute" } { | |
204 | if { $compdir == "absolute" } { | |
205 | set cu_dir {XDIR "\0"} | |
206 | } | |
207 | } else { | |
208 | error "not enough absolutes" | |
209 | } | |
210 | } | |
211 | ||
212 | $func $name $cu_dir $cu_name $line_dir $line_name | |
213 | } | |
214 | ||
215 | proc out_diff { func compdir ldir file } { | |
216 | set abscount 0 | |
217 | if { $compdir == "absolute" } { | |
218 | incr abscount | |
219 | } | |
220 | if { $ldir == "absolute" } { | |
221 | incr abscount | |
222 | } | |
223 | if { $file == "absolute" } { | |
224 | incr abscount | |
225 | } | |
226 | if { $abscount <= 1 } { | |
227 | out_unit $func $compdir $ldir $file "" | |
228 | } else { | |
229 | out_unit $func $compdir $ldir $file "_same" | |
230 | out_unit $func $compdir $ldir $file "_different" | |
231 | } | |
232 | } | |
233 | ||
234 | proc out_file { func compdir ldir } { | |
235 | out_diff $func $compdir $ldir "basename" | |
236 | out_diff $func $compdir $ldir "relative" | |
237 | out_diff $func $compdir $ldir "absolute" | |
238 | } | |
239 | ||
240 | proc out_ldir { func compdir } { | |
241 | out_file $func $compdir "missing_" | |
242 | out_file $func $compdir "relative" | |
243 | out_file $func $compdir "absolute" | |
244 | } | |
245 | ||
246 | proc out_compdir { func } { | |
247 | out_ldir $func "missing_" | |
248 | out_ldir $func "relative" | |
249 | out_ldir $func "absolute" | |
250 | } | |
251 | ||
252 | puts -nonewline $f "\ | |
253 | #define ABBREV_NAME 1 | |
254 | #define ABBREV_COMP_DIR_NAME 2 | |
255 | .section .debug_info | |
256 | " | |
257 | out_compdir out_cu | |
258 | ||
259 | puts $f " .section .debug_line" | |
260 | out_compdir out_line | |
261 | ||
262 | puts -nonewline $f "\ | |
263 | .section .debug_abbrev | |
264 | .Labbrev1_begin: | |
265 | ||
266 | .uleb128 ABBREV_NAME /* Abbrev code */ | |
267 | .uleb128 0x11 /* DW_TAG_compile_unit */ | |
268 | .byte 1 /* has_children */ | |
269 | .uleb128 0x25 /* DW_AT_producer */ | |
270 | .uleb128 0x8 /* DW_FORM_string */ | |
271 | .uleb128 0x13 /* DW_AT_language */ | |
272 | .uleb128 0xb /* DW_FORM_data1 */ | |
273 | .uleb128 0x10 /* DW_AT_stmt_list */ | |
274 | .uleb128 0x6 /* DW_FORM_data4 */ | |
275 | .uleb128 0x11 /* DW_AT_low_pc */ | |
276 | .uleb128 0x1 /* DW_FORM_addr */ | |
277 | .uleb128 0x12 /* DW_AT_high_pc */ | |
278 | .uleb128 0x1 /* DW_FORM_addr */ | |
279 | .uleb128 0x3 /* DW_AT_name */ | |
280 | .uleb128 0x8 /* DW_FORM_string */ | |
281 | .byte 0x0 /* Terminator */ | |
282 | .byte 0x0 /* Terminator */ | |
283 | ||
284 | .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev code */ | |
285 | .uleb128 0x11 /* DW_TAG_compile_unit */ | |
286 | .byte 1 /* has_children */ | |
287 | .uleb128 0x25 /* DW_AT_producer */ | |
288 | .uleb128 0x8 /* DW_FORM_string */ | |
289 | .uleb128 0x13 /* DW_AT_language */ | |
290 | .uleb128 0xb /* DW_FORM_data1 */ | |
291 | .uleb128 0x10 /* DW_AT_stmt_list */ | |
292 | .uleb128 0x6 /* DW_FORM_data4 */ | |
293 | .uleb128 0x11 /* DW_AT_low_pc */ | |
294 | .uleb128 0x1 /* DW_FORM_addr */ | |
295 | .uleb128 0x12 /* DW_AT_high_pc */ | |
296 | .uleb128 0x1 /* DW_FORM_addr */ | |
297 | .uleb128 0x1b /* DW_AT_comp_dir */ | |
298 | .uleb128 0x8 /* DW_FORM_string */ | |
299 | .uleb128 0x3 /* DW_AT_name */ | |
300 | .uleb128 0x8 /* DW_FORM_string */ | |
301 | .byte 0x0 /* Terminator */ | |
302 | .byte 0x0 /* Terminator */ | |
303 | ||
304 | .uleb128 3 /* Abbrev code */ | |
305 | .uleb128 0x2e /* DW_TAG_subprogram */ | |
306 | .byte 0 /* has_children */ | |
307 | .uleb128 0x3 /* DW_AT_name */ | |
308 | .uleb128 0x8 /* DW_FORM_string */ | |
309 | .uleb128 0x11 /* DW_AT_low_pc */ | |
310 | .uleb128 0x1 /* DW_FORM_addr */ | |
311 | .uleb128 0x12 /* DW_AT_high_pc */ | |
312 | .uleb128 0x1 /* DW_FORM_addr */ | |
313 | .byte 0x0 /* Terminator */ | |
314 | .byte 0x0 /* Terminator */ | |
315 | ||
316 | .byte 0x0 /* Terminator */ | |
317 | .byte 0x0 /* Terminator */ | |
318 | " | |
319 | ||
320 | close $f | |
321 | ||
322 | set opts {} | |
323 | # Base directory. | |
324 | lappend opts "additional_flags=-DBDIR=\"${srcabsdir}\"" | |
325 | # Incorrect directory which should never be visible from GDB. | |
326 | lappend opts "additional_flags=-DXDIR=\"${srcabsdir}/xdir\"" | |
327 | # CU's DW_AT_comp_dir. | |
328 | lappend opts "additional_flags=-DCOMPDIR=\"compdir\"" | |
329 | # .debug_line's directory. | |
330 | lappend opts "additional_flags=-DLDIR=\"ldir\"" | |
331 | # CU's DW_AT_name and .debug_line's filename relative directory, if needed. | |
332 | lappend opts "additional_flags=-DFDIR=\"fdir\"" | |
333 | # CU's DW_AT_name and .debug_line's filename. | |
334 | lappend opts "additional_flags=-DFILE=\"${srctmpfile}\"" | |
335 | ||
336 | if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } { | |
84c93cd5 | 337 | untested "failed to compile" |
1b56eb55 JK |
338 | return -1 |
339 | } | |
340 | ||
02392865 CG |
341 | set dirs {} |
342 | foreach r {"" /rdir} { | |
343 | foreach x {"" /xdir} { | |
344 | foreach comp {"" /compdir} { | |
345 | foreach l {"" /ldir} { | |
346 | foreach f {"" /fdir} { | |
347 | lappend dirs $r$x$comp$l$f | |
348 | } | |
349 | } | |
350 | } | |
351 | } | |
352 | } | |
353 | ||
354 | proc pathexpand {prefix dirlst suffix} { | |
355 | set retlst {} | |
356 | foreach dir $dirlst { | |
357 | lappend retlst "$prefix$dir$suffix" | |
358 | } | |
359 | return $retlst | |
360 | } | |
361 | ||
362 | set filelist [pathexpand $srcabsdir $dirs "/$srctmpfile"] | |
363 | set dircreatelist [pathexpand $srcabsdir $dirs ""] | |
364 | set dirremovelist [pathexpand $srcabsdir [lreverse $dirs] ""] | |
365 | ||
366 | remote_exec host "sh -c \"rm -f $filelist\"" | |
367 | remote_exec host "sh -c \"rmdir $dirremovelist\"" | |
368 | remote_exec host "sh -c \"mkdir $dircreatelist\"" | |
369 | remote_exec host "sh -c \"for d in $dircreatelist; do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\"" | |
1b56eb55 JK |
370 | |
371 | clean_restart ${testfile} | |
372 | ||
373 | if ![runto_main] { | |
374 | return -1 | |
375 | } | |
376 | ||
5a2dc60a | 377 | gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir" |
1b56eb55 | 378 | |
0a251e08 YQ |
379 | proc test { func compdir filename } { |
380 | with_test_prefix "$func" { | |
381 | # Clear the GDB cache. | |
382 | gdb_test_no_output "set directories" "" | |
1b56eb55 | 383 | |
0a251e08 YQ |
384 | if {$compdir == ""} { |
385 | set absolute "$filename" | |
386 | } else { | |
387 | set absolute "$compdir/$filename" | |
388 | } | |
389 | if {[string index $absolute 0] != "/"} { | |
390 | error "not absolute" | |
391 | } | |
1b56eb55 | 392 | |
0a251e08 YQ |
393 | gdb_breakpoint $func |
394 | gdb_continue_to_breakpoint $func "$func \\(\\) at .*" | |
1b56eb55 | 395 | |
0a251e08 YQ |
396 | gdb_test_no_output "set filename-display absolute" |
397 | verbose -log "expect: ${absolute}" | |
398 | gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute" | |
1b56eb55 | 399 | |
0a251e08 YQ |
400 | gdb_test_no_output "set filename-display basename" |
401 | verbose -log "expect: [file tail $filename]" | |
402 | gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename" | |
1b56eb55 | 403 | |
0a251e08 YQ |
404 | gdb_test_no_output "set filename-display relative" |
405 | verbose -log "expect: $filename" | |
406 | gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative" | |
407 | } | |
408 | } | |
1b56eb55 JK |
409 | |
410 | set bdir "${srcabsdir}" | |
411 | set file "${srctmpfile}" | |
412 | test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file" | |
413 | test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file" | |
414 | test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file" | |
415 | test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file" | |
416 | test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file" | |
417 | test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file" | |
418 | test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file" | |
419 | test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file" | |
420 | test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file" | |
421 | test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file" | |
422 | test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file" | |
423 | test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file" | |
424 | test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file" | |
425 | test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file" | |
426 | test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file" | |
427 | test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file" | |
428 | test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file" | |
429 | test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file" | |
430 | test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file" | |
431 | test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file" | |
432 | test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file" | |
433 | test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file" | |
434 | test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file" | |
435 | test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file" | |
436 | test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file" | |
437 | test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file" | |
438 | test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file" | |
439 | test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file" | |
440 | test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file" | |
441 | test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file" | |
442 | test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file" | |
443 | test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file" |