1 # Copyright 2012-2013 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]} {
23 set asmsrcfile [standard_output_file ${testfile}asm.S]
24 set asmobjfile [standard_output_file ${testfile}asm.o]
25 set srcabsdir [standard_output_file ${testfile}.d]
26 set srctmpfile tmp-${testfile}.c
28 # $srcdir may be relative.
29 if {[file pathtype $srcabsdir] != "absolute"} {
30 untested "objdir pathtype is not absolute"
34 set f [open $asmsrcfile "w"]
35 puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */"
37 proc out_cu { name cu_dir cu_name line_dir line_name } {
42 .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */
44 .2byte 2 /* DWARF Version */
45 .4byte .Labbrev1_begin /* Offset into abbrev section */
46 .byte 4 /* Pointer size */
48 if { $cu_dir != "" } {
49 puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */"
51 puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */"
54 .ascii \"GNU C\\0\" /* DW_AT_producer */
55 .byte 2 /* DW_AT_language (DW_LANG_C) */
56 .4byte .Lline_${name}_begin /* DW_AT_stmt_list */
57 .4byte ${name}_start /* DW_AT_low_pc */
58 .4byte ${name}_end /* DW_AT_high_pc */
60 if { $cu_dir != "" } {
61 puts $f " .ascii $cu_dir /* DW_AT_comp_dir */"
64 .ascii $cu_name /* DW_AT_name */
66 .uleb128 3 /* Abbrev: DW_TAG_subprogram */
67 .asciz \"${name}\" /* DW_AT_name */
68 .4byte ${name}_start /* DW_AT_low_pc */
69 .4byte ${name}_end /* DW_AT_high_pc */
71 .byte 0 /* End of children of CU */
76 proc out_line { name cu_dir cu_name line_dir line_name } {
81 .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */
83 .2byte 2 /* Version */
84 .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */
86 .byte 1 /* Minimum insn length */
87 .byte 1 /* default_is_stmt */
88 .byte 1 /* line_base */
89 .byte 1 /* line_range */
90 .byte 4 /* opcode_base */
92 /* Standard lengths */
97 /* Include directories */
99 if { $line_dir != "" } {
100 puts $f " .ascii $line_dir"
102 puts -nonewline $f "\
108 if { $line_dir != "" } {
109 puts $f " .uleb128 1"
111 puts $f " .uleb128 0"
113 puts -nonewline $f "\
119 .Lline_${name}_lines:
120 .byte 3 /* DW_LNS_advance_line */
121 .sleb128 998 /* ... to 999 */
122 .byte 0 /* DW_LNE_set_address */
126 .byte 1 /* DW_LNS_copy */
127 .byte 3 /* DW_LNS_advance_line */
128 .sleb128 1 /* ... to 1000 */
129 .byte 0 /* DW_LNE_set_address */
133 .byte 1 /* DW_LNS_copy */
134 .byte 0 /* DW_LNE_end_of_sequence */
141 # IFSOME can be optionally _same or _different if >= 2 absolute directories are
142 # provided. Then in the _different case the overriden directories have invalid
145 proc out_unit { func compdir ldir file ifsame } {
146 set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}"
148 if { $compdir == "missing_" } {
150 } elseif { $compdir == "relative" } {
151 set cu_dir {COMPDIR "\0"}
152 } elseif { $compdir == "absolute" } {
153 set cu_dir {BDIR "/" COMPDIR "\0"}
155 error "compdir $compdir"
158 if { $ldir == "missing_" } {
160 } elseif { $ldir == "relative" } {
161 set line_dir {LDIR "\0"}
162 } elseif { $ldir == "absolute" } {
163 set line_dir {BDIR "/" LDIR "\0"}
168 if { $file == "basename" } {
169 set cu_name {FILE "\0"}
170 } elseif { $file == "relative" } {
171 set cu_name {FDIR "/" FILE "\0"}
172 } elseif { $file == "absolute" } {
173 set cu_name {BDIR "/" FILE "\0"}
177 set line_name $cu_name
179 if { "$ifsame" == "_different" } {
180 if { $file == "absolute" } {
181 if { $ldir == "absolute" } {
182 set line_dir {XDIR "\0"}
184 if { $compdir == "absolute" } {
185 set cu_dir {XDIR "\0"}
187 } elseif { $ldir == "absolute" } {
188 if { $compdir == "absolute" } {
189 set cu_dir {XDIR "\0"}
192 error "not enough absolutes"
196 $func $name $cu_dir $cu_name $line_dir $line_name
199 proc out_diff { func compdir ldir file } {
201 if { $compdir == "absolute" } {
204 if { $ldir == "absolute" } {
207 if { $file == "absolute" } {
210 if { $abscount <= 1 } {
211 out_unit $func $compdir $ldir $file ""
213 out_unit $func $compdir $ldir $file "_same"
214 out_unit $func $compdir $ldir $file "_different"
218 proc out_file { func compdir ldir } {
219 out_diff $func $compdir $ldir "basename"
220 out_diff $func $compdir $ldir "relative"
221 out_diff $func $compdir $ldir "absolute"
224 proc out_ldir { func compdir } {
225 out_file $func $compdir "missing_"
226 out_file $func $compdir "relative"
227 out_file $func $compdir "absolute"
230 proc out_compdir { func } {
231 out_ldir $func "missing_"
232 out_ldir $func "relative"
233 out_ldir $func "absolute"
236 puts -nonewline $f "\
237 #define ABBREV_NAME 1
238 #define ABBREV_COMP_DIR_NAME 2
243 puts $f " .section .debug_line"
246 puts -nonewline $f "\
247 .section .debug_abbrev
250 .uleb128 ABBREV_NAME /* Abbrev code */
251 .uleb128 0x11 /* DW_TAG_compile_unit */
252 .byte 1 /* has_children */
253 .uleb128 0x25 /* DW_AT_producer */
254 .uleb128 0x8 /* DW_FORM_string */
255 .uleb128 0x13 /* DW_AT_language */
256 .uleb128 0xb /* DW_FORM_data1 */
257 .uleb128 0x10 /* DW_AT_stmt_list */
258 .uleb128 0x6 /* DW_FORM_data4 */
259 .uleb128 0x11 /* DW_AT_low_pc */
260 .uleb128 0x1 /* DW_FORM_addr */
261 .uleb128 0x12 /* DW_AT_high_pc */
262 .uleb128 0x1 /* DW_FORM_addr */
263 .uleb128 0x3 /* DW_AT_name */
264 .uleb128 0x8 /* DW_FORM_string */
265 .byte 0x0 /* Terminator */
266 .byte 0x0 /* Terminator */
268 .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev code */
269 .uleb128 0x11 /* DW_TAG_compile_unit */
270 .byte 1 /* has_children */
271 .uleb128 0x25 /* DW_AT_producer */
272 .uleb128 0x8 /* DW_FORM_string */
273 .uleb128 0x13 /* DW_AT_language */
274 .uleb128 0xb /* DW_FORM_data1 */
275 .uleb128 0x10 /* DW_AT_stmt_list */
276 .uleb128 0x6 /* DW_FORM_data4 */
277 .uleb128 0x11 /* DW_AT_low_pc */
278 .uleb128 0x1 /* DW_FORM_addr */
279 .uleb128 0x12 /* DW_AT_high_pc */
280 .uleb128 0x1 /* DW_FORM_addr */
281 .uleb128 0x1b /* DW_AT_comp_dir */
282 .uleb128 0x8 /* DW_FORM_string */
283 .uleb128 0x3 /* DW_AT_name */
284 .uleb128 0x8 /* DW_FORM_string */
285 .byte 0x0 /* Terminator */
286 .byte 0x0 /* Terminator */
288 .uleb128 3 /* Abbrev code */
289 .uleb128 0x2e /* DW_TAG_subprogram */
290 .byte 0 /* has_children */
291 .uleb128 0x3 /* DW_AT_name */
292 .uleb128 0x8 /* DW_FORM_string */
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 .byte 0x0 /* Terminator */
298 .byte 0x0 /* Terminator */
300 .byte 0x0 /* Terminator */
301 .byte 0x0 /* Terminator */
308 lappend opts "additional_flags=-DBDIR=\"${srcabsdir}\""
309 # Incorrect directory which should never be visible from GDB.
310 lappend opts "additional_flags=-DXDIR=\"${srcabsdir}/xdir\""
311 # CU's DW_AT_comp_dir.
312 lappend opts "additional_flags=-DCOMPDIR=\"compdir\""
313 # .debug_line's directory.
314 lappend opts "additional_flags=-DLDIR=\"ldir\""
315 # CU's DW_AT_name and .debug_line's filename relative directory, if needed.
316 lappend opts "additional_flags=-DFDIR=\"fdir\""
317 # CU's DW_AT_name and .debug_line's filename.
318 lappend opts "additional_flags=-DFILE=\"${srctmpfile}\""
320 if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } {
321 untested "Cannot compile ${asmsrcfile} or $srcfile"
326 foreach r {"" /rdir} {
327 foreach x {"" /xdir} {
328 foreach comp {"" /compdir} {
329 foreach l {"" /ldir} {
330 foreach f {"" /fdir} {
331 lappend dirs $r$x$comp$l$f
338 proc pathexpand {prefix dirlst suffix} {
340 foreach dir $dirlst {
341 lappend retlst "$prefix$dir$suffix"
346 set filelist [pathexpand $srcabsdir $dirs "/$srctmpfile"]
347 set dircreatelist [pathexpand $srcabsdir $dirs ""]
348 set dirremovelist [pathexpand $srcabsdir [lreverse $dirs] ""]
350 remote_exec host "sh -c \"rm -f $filelist\""
351 remote_exec host "sh -c \"rmdir $dirremovelist\""
352 remote_exec host "sh -c \"mkdir $dircreatelist\""
353 remote_exec host "sh -c \"for d in $dircreatelist; do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\""
355 clean_restart ${testfile}
361 gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir"
363 proc test { func compdir filename } {
364 with_test_prefix "$func" {
365 # Clear the GDB cache.
366 gdb_test_no_output "set directories" ""
368 if {$compdir == ""} {
369 set absolute "$filename"
371 set absolute "$compdir/$filename"
373 if {[string index $absolute 0] != "/"} {
378 gdb_continue_to_breakpoint $func "$func \\(\\) at .*"
380 gdb_test_no_output "set filename-display absolute"
381 verbose -log "expect: ${absolute}"
382 gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute"
384 gdb_test_no_output "set filename-display basename"
385 verbose -log "expect: [file tail $filename]"
386 gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename"
388 gdb_test_no_output "set filename-display relative"
389 verbose -log "expect: $filename"
390 gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative"
394 set bdir "${srcabsdir}"
395 set file "${srctmpfile}"
396 test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file"
397 test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file"
398 test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file"
399 test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file"
400 test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file"
401 test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file"
402 test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file"
403 test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
404 test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file"
405 test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file"
406 test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file"
407 test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file"
408 test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file"
409 test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file"
410 test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file"
411 test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file"
412 test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file"
413 test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
414 test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file"
415 test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file"
416 test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file"
417 test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file"
418 test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file"
419 test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file"
420 test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file"
421 test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file"
422 test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file"
423 test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file"
424 test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file"
425 test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file"
426 test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file"
427 test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file"