1 # Copyright 2012-2014 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 # Find length of addresses in bytes.
30 set asmsrcfile [standard_output_file ${testfile}asm.S]
31 set asmobjfile [standard_output_file ${testfile}asm.o]
32 set srcabsdir [standard_output_file ${testfile}.d]
33 set srctmpfile tmp-${testfile}.c
35 # $srcdir may be relative.
36 if {[file pathtype $srcabsdir] != "absolute"} {
37 untested "objdir pathtype is not absolute"
41 set f [open $asmsrcfile "w"]
42 puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */"
44 proc out_cu { name cu_dir cu_name line_dir line_name } {
50 .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */
52 .2byte 2 /* DWARF Version */
53 .4byte .Labbrev1_begin /* Offset into abbrev section */
54 .byte ${addr_len} /* Pointer size */
56 if { $cu_dir != "" } {
57 puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */"
59 puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */"
62 .ascii \"GNU C\\0\" /* DW_AT_producer */
63 .byte 2 /* DW_AT_language (DW_LANG_C) */
64 .4byte .Lline_${name}_begin /* DW_AT_stmt_list */
65 .${addr_len}byte ${name}_start /* DW_AT_low_pc */
66 .${addr_len}byte ${name}_end /* DW_AT_high_pc */
68 if { $cu_dir != "" } {
69 puts $f " .ascii $cu_dir /* DW_AT_comp_dir */"
72 .ascii $cu_name /* DW_AT_name */
74 .uleb128 3 /* Abbrev: DW_TAG_subprogram */
75 .asciz \"${name}\" /* DW_AT_name */
76 .${addr_len}byte ${name}_start /* DW_AT_low_pc */
77 .${addr_len}byte ${name}_end /* DW_AT_high_pc */
79 .byte 0 /* End of children of CU */
84 proc out_line { name cu_dir cu_name line_dir line_name } {
90 .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */
92 .2byte 2 /* Version */
93 .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */
95 .byte 1 /* Minimum insn length */
96 .byte 1 /* default_is_stmt */
97 .byte 1 /* line_base */
98 .byte 1 /* line_range */
99 .byte 4 /* opcode_base */
101 /* Standard lengths */
106 /* Include directories */
108 if { $line_dir != "" } {
109 puts $f " .ascii $line_dir"
111 puts -nonewline $f "\
117 if { $line_dir != "" } {
118 puts $f " .uleb128 1"
120 puts $f " .uleb128 0"
122 puts -nonewline $f "\
128 .Lline_${name}_lines:
129 .byte 3 /* DW_LNS_advance_line */
130 .sleb128 998 /* ... to 999 */
131 .byte 0 /* DW_LNE_set_address */
132 .uleb128 ${addr_len}+1
134 .${addr_len}byte ${name}_start
135 .byte 1 /* DW_LNS_copy */
136 .byte 3 /* DW_LNS_advance_line */
137 .sleb128 1 /* ... to 1000 */
138 .byte 0 /* DW_LNE_set_address */
139 .uleb128 ${addr_len}+1
141 .${addr_len}byte ${name}_end
142 .byte 1 /* DW_LNS_copy */
143 .byte 0 /* DW_LNE_end_of_sequence */
150 # IFSOME can be optionally _same or _different if >= 2 absolute directories are
151 # provided. Then in the _different case the overriden directories have invalid
154 proc out_unit { func compdir ldir file ifsame } {
155 set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}"
157 if { $compdir == "missing_" } {
159 } elseif { $compdir == "relative" } {
160 set cu_dir {COMPDIR "\0"}
161 } elseif { $compdir == "absolute" } {
162 set cu_dir {BDIR "/" COMPDIR "\0"}
164 error "compdir $compdir"
167 if { $ldir == "missing_" } {
169 } elseif { $ldir == "relative" } {
170 set line_dir {LDIR "\0"}
171 } elseif { $ldir == "absolute" } {
172 set line_dir {BDIR "/" LDIR "\0"}
177 if { $file == "basename" } {
178 set cu_name {FILE "\0"}
179 } elseif { $file == "relative" } {
180 set cu_name {FDIR "/" FILE "\0"}
181 } elseif { $file == "absolute" } {
182 set cu_name {BDIR "/" FILE "\0"}
186 set line_name $cu_name
188 if { "$ifsame" == "_different" } {
189 if { $file == "absolute" } {
190 if { $ldir == "absolute" } {
191 set line_dir {XDIR "\0"}
193 if { $compdir == "absolute" } {
194 set cu_dir {XDIR "\0"}
196 } elseif { $ldir == "absolute" } {
197 if { $compdir == "absolute" } {
198 set cu_dir {XDIR "\0"}
201 error "not enough absolutes"
205 $func $name $cu_dir $cu_name $line_dir $line_name
208 proc out_diff { func compdir ldir file } {
210 if { $compdir == "absolute" } {
213 if { $ldir == "absolute" } {
216 if { $file == "absolute" } {
219 if { $abscount <= 1 } {
220 out_unit $func $compdir $ldir $file ""
222 out_unit $func $compdir $ldir $file "_same"
223 out_unit $func $compdir $ldir $file "_different"
227 proc out_file { func compdir ldir } {
228 out_diff $func $compdir $ldir "basename"
229 out_diff $func $compdir $ldir "relative"
230 out_diff $func $compdir $ldir "absolute"
233 proc out_ldir { func compdir } {
234 out_file $func $compdir "missing_"
235 out_file $func $compdir "relative"
236 out_file $func $compdir "absolute"
239 proc out_compdir { func } {
240 out_ldir $func "missing_"
241 out_ldir $func "relative"
242 out_ldir $func "absolute"
245 puts -nonewline $f "\
246 #define ABBREV_NAME 1
247 #define ABBREV_COMP_DIR_NAME 2
252 puts $f " .section .debug_line"
255 puts -nonewline $f "\
256 .section .debug_abbrev
259 .uleb128 ABBREV_NAME /* Abbrev code */
260 .uleb128 0x11 /* DW_TAG_compile_unit */
261 .byte 1 /* has_children */
262 .uleb128 0x25 /* DW_AT_producer */
263 .uleb128 0x8 /* DW_FORM_string */
264 .uleb128 0x13 /* DW_AT_language */
265 .uleb128 0xb /* DW_FORM_data1 */
266 .uleb128 0x10 /* DW_AT_stmt_list */
267 .uleb128 0x6 /* DW_FORM_data4 */
268 .uleb128 0x11 /* DW_AT_low_pc */
269 .uleb128 0x1 /* DW_FORM_addr */
270 .uleb128 0x12 /* DW_AT_high_pc */
271 .uleb128 0x1 /* DW_FORM_addr */
272 .uleb128 0x3 /* DW_AT_name */
273 .uleb128 0x8 /* DW_FORM_string */
274 .byte 0x0 /* Terminator */
275 .byte 0x0 /* Terminator */
277 .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev code */
278 .uleb128 0x11 /* DW_TAG_compile_unit */
279 .byte 1 /* has_children */
280 .uleb128 0x25 /* DW_AT_producer */
281 .uleb128 0x8 /* DW_FORM_string */
282 .uleb128 0x13 /* DW_AT_language */
283 .uleb128 0xb /* DW_FORM_data1 */
284 .uleb128 0x10 /* DW_AT_stmt_list */
285 .uleb128 0x6 /* DW_FORM_data4 */
286 .uleb128 0x11 /* DW_AT_low_pc */
287 .uleb128 0x1 /* DW_FORM_addr */
288 .uleb128 0x12 /* DW_AT_high_pc */
289 .uleb128 0x1 /* DW_FORM_addr */
290 .uleb128 0x1b /* DW_AT_comp_dir */
291 .uleb128 0x8 /* DW_FORM_string */
292 .uleb128 0x3 /* DW_AT_name */
293 .uleb128 0x8 /* DW_FORM_string */
294 .byte 0x0 /* Terminator */
295 .byte 0x0 /* Terminator */
297 .uleb128 3 /* Abbrev code */
298 .uleb128 0x2e /* DW_TAG_subprogram */
299 .byte 0 /* has_children */
300 .uleb128 0x3 /* DW_AT_name */
301 .uleb128 0x8 /* DW_FORM_string */
302 .uleb128 0x11 /* DW_AT_low_pc */
303 .uleb128 0x1 /* DW_FORM_addr */
304 .uleb128 0x12 /* DW_AT_high_pc */
305 .uleb128 0x1 /* DW_FORM_addr */
306 .byte 0x0 /* Terminator */
307 .byte 0x0 /* Terminator */
309 .byte 0x0 /* Terminator */
310 .byte 0x0 /* Terminator */
317 lappend opts "additional_flags=-DBDIR=\"${srcabsdir}\""
318 # Incorrect directory which should never be visible from GDB.
319 lappend opts "additional_flags=-DXDIR=\"${srcabsdir}/xdir\""
320 # CU's DW_AT_comp_dir.
321 lappend opts "additional_flags=-DCOMPDIR=\"compdir\""
322 # .debug_line's directory.
323 lappend opts "additional_flags=-DLDIR=\"ldir\""
324 # CU's DW_AT_name and .debug_line's filename relative directory, if needed.
325 lappend opts "additional_flags=-DFDIR=\"fdir\""
326 # CU's DW_AT_name and .debug_line's filename.
327 lappend opts "additional_flags=-DFILE=\"${srctmpfile}\""
329 if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } {
330 untested "Cannot compile ${asmsrcfile} or $srcfile"
335 foreach r {"" /rdir} {
336 foreach x {"" /xdir} {
337 foreach comp {"" /compdir} {
338 foreach l {"" /ldir} {
339 foreach f {"" /fdir} {
340 lappend dirs $r$x$comp$l$f
347 proc pathexpand {prefix dirlst suffix} {
349 foreach dir $dirlst {
350 lappend retlst "$prefix$dir$suffix"
355 set filelist [pathexpand $srcabsdir $dirs "/$srctmpfile"]
356 set dircreatelist [pathexpand $srcabsdir $dirs ""]
357 set dirremovelist [pathexpand $srcabsdir [lreverse $dirs] ""]
359 remote_exec host "sh -c \"rm -f $filelist\""
360 remote_exec host "sh -c \"rmdir $dirremovelist\""
361 remote_exec host "sh -c \"mkdir $dircreatelist\""
362 remote_exec host "sh -c \"for d in $dircreatelist; do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\""
364 clean_restart ${testfile}
370 gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir"
372 proc test { func compdir filename } {
373 with_test_prefix "$func" {
374 # Clear the GDB cache.
375 gdb_test_no_output "set directories" ""
377 if {$compdir == ""} {
378 set absolute "$filename"
380 set absolute "$compdir/$filename"
382 if {[string index $absolute 0] != "/"} {
387 gdb_continue_to_breakpoint $func "$func \\(\\) at .*"
389 gdb_test_no_output "set filename-display absolute"
390 verbose -log "expect: ${absolute}"
391 gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute"
393 gdb_test_no_output "set filename-display basename"
394 verbose -log "expect: [file tail $filename]"
395 gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename"
397 gdb_test_no_output "set filename-display relative"
398 verbose -log "expect: $filename"
399 gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative"
403 set bdir "${srcabsdir}"
404 set file "${srctmpfile}"
405 test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file"
406 test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file"
407 test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file"
408 test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file"
409 test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file"
410 test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file"
411 test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file"
412 test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
413 test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file"
414 test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file"
415 test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file"
416 test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file"
417 test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file"
418 test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file"
419 test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file"
420 test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file"
421 test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file"
422 test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
423 test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file"
424 test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file"
425 test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file"
426 test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file"
427 test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file"
428 test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file"
429 test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file"
430 test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file"
431 test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file"
432 test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file"
433 test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file"
434 test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file"
435 test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file"
436 test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file"