1 # Copyright 2012-2021 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/>.
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
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 "can only run on local host"
29 # Find length of addresses in bytes.
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
42 # $srcdir may be relative.
43 if {[file pathtype $srcabsdir] != "absolute"} {
44 untested "objdir pathtype is not absolute"
48 set f [open $asmsrcfile "w"]
49 puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */"
51 proc out_cu { name cu_dir cu_name line_dir line_name } {
57 .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */
59 .2byte 2 /* DWARF Version */
60 .4byte .Labbrev1_begin /* Offset into abbrev section */
61 .byte ${addr_len} /* Pointer size */
63 if { $cu_dir != "" } {
64 puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */"
66 puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */"
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 */
72 .${addr_len}byte ${name}_start /* DW_AT_low_pc */
73 .${addr_len}byte ${name}_end /* DW_AT_high_pc */
75 if { $cu_dir != "" } {
76 puts $f " .ascii $cu_dir /* DW_AT_comp_dir */"
79 .ascii $cu_name /* DW_AT_name */
81 .uleb128 3 /* Abbrev: DW_TAG_subprogram */
82 .asciz \"${name}\" /* DW_AT_name */
83 .${addr_len}byte ${name}_start /* DW_AT_low_pc */
84 .${addr_len}byte ${name}_end /* DW_AT_high_pc */
86 .byte 0 /* End of children of CU */
91 proc out_line { name cu_dir cu_name line_dir line_name } {
97 .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */
99 .2byte 2 /* Version */
100 .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */
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 */
108 /* Standard lengths */
113 /* Include directories */
115 if { $line_dir != "" } {
116 puts $f " .ascii $line_dir"
118 puts -nonewline $f "\
124 if { $line_dir != "" } {
125 puts $f " .uleb128 1"
127 puts $f " .uleb128 0"
129 puts -nonewline $f "\
135 .Lline_${name}_lines:
136 .byte 3 /* DW_LNS_advance_line */
137 .sleb128 998 /* ... to 999 */
138 .byte 0 /* DW_LNE_set_address */
139 .uleb128 ${addr_len}+1
141 .${addr_len}byte ${name}_start
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 */
146 .uleb128 ${addr_len}+1
148 .${addr_len}byte ${name}_end
149 .byte 1 /* DW_LNS_copy */
150 .byte 0 /* DW_LNE_end_of_sequence */
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
161 proc out_unit { func compdir ldir file ifsame } {
162 set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}"
164 if { $compdir == "missing_" } {
166 } elseif { $compdir == "relative" } {
167 set cu_dir {COMPDIR "\0"}
168 } elseif { $compdir == "absolute" } {
169 set cu_dir {BDIR "/" COMPDIR "\0"}
171 error "compdir $compdir"
174 if { $ldir == "missing_" } {
176 } elseif { $ldir == "relative" } {
177 set line_dir {LDIR "\0"}
178 } elseif { $ldir == "absolute" } {
179 set line_dir {BDIR "/" LDIR "\0"}
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"}
193 set line_name $cu_name
195 if { "$ifsame" == "_different" } {
196 if { $file == "absolute" } {
197 if { $ldir == "absolute" } {
198 set line_dir {XDIR "\0"}
200 if { $compdir == "absolute" } {
201 set cu_dir {XDIR "\0"}
203 } elseif { $ldir == "absolute" } {
204 if { $compdir == "absolute" } {
205 set cu_dir {XDIR "\0"}
208 error "not enough absolutes"
212 $func $name $cu_dir $cu_name $line_dir $line_name
215 proc out_diff { func compdir ldir file } {
217 if { $compdir == "absolute" } {
220 if { $ldir == "absolute" } {
223 if { $file == "absolute" } {
226 if { $abscount <= 1 } {
227 out_unit $func $compdir $ldir $file ""
229 out_unit $func $compdir $ldir $file "_same"
230 out_unit $func $compdir $ldir $file "_different"
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"
240 proc out_ldir { func compdir } {
241 out_file $func $compdir "missing_"
242 out_file $func $compdir "relative"
243 out_file $func $compdir "absolute"
246 proc out_compdir { func } {
247 out_ldir $func "missing_"
248 out_ldir $func "relative"
249 out_ldir $func "absolute"
252 puts -nonewline $f "\
253 #define ABBREV_NAME 1
254 #define ABBREV_COMP_DIR_NAME 2
259 puts $f " .section .debug_line"
262 puts -nonewline $f "\
263 .section .debug_abbrev
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 */
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 */
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 */
316 .byte 0x0 /* Terminator */
317 .byte 0x0 /* Terminator */
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}\""
336 # Clang's integrated assembler doesn't support .ascii directives
337 # with multiple string literals.
338 if { [test_compiler_info clang*] } {
339 lappend opts "additional_flags=-fno-integrated-as"
342 if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } {
343 untested "failed to compile"
348 foreach r {"" /rdir} {
349 foreach x {"" /xdir} {
350 foreach comp {"" /compdir} {
351 foreach l {"" /ldir} {
352 foreach f {"" /fdir} {
353 lappend dirs $r$x$comp$l$f
360 proc pathexpand {prefix dirlst suffix} {
362 foreach dir $dirlst {
363 lappend retlst "$prefix$dir$suffix"
368 set filelist [pathexpand $srcabsdir $dirs "/$srctmpfile"]
369 set dircreatelist [pathexpand $srcabsdir $dirs ""]
370 set dirremovelist [pathexpand $srcabsdir [lreverse $dirs] ""]
372 remote_exec host "sh -c \"rm -f $filelist\""
373 remote_exec host "sh -c \"rmdir $dirremovelist\""
374 remote_exec host "sh -c \"mkdir $dircreatelist\""
375 remote_exec host "sh -c \"for d in $dircreatelist; do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\""
377 clean_restart ${testfile}
383 gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir"
385 proc test { func compdir filename } {
386 with_test_prefix "$func" {
387 # Clear the GDB cache.
388 gdb_test_no_output "set directories" ""
390 if {$compdir == ""} {
391 set absolute "$filename"
393 set absolute "$compdir/$filename"
395 if {[string index $absolute 0] != "/"} {
400 gdb_continue_to_breakpoint $func "$func \\(\\) at .*"
402 gdb_test_no_output "set filename-display absolute"
403 verbose -log "expect: ${absolute}"
404 gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute"
406 gdb_test_no_output "set filename-display basename"
407 verbose -log "expect: [file tail $filename]"
408 gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename"
410 gdb_test_no_output "set filename-display relative"
411 verbose -log "expect: $filename"
412 gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative"
416 set bdir "${srcabsdir}"
417 set file "${srctmpfile}"
418 test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file"
419 test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file"
420 test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file"
421 test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file"
422 test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file"
423 test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file"
424 test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file"
425 test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
426 test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file"
427 test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file"
428 test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file"
429 test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file"
430 test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file"
431 test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file"
432 test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file"
433 test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file"
434 test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file"
435 test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
436 test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file"
437 test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file"
438 test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file"
439 test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file"
440 test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file"
441 test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file"
442 test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file"
443 test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file"
444 test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file"
445 test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file"
446 test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file"
447 test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file"
448 test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file"
449 test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file"