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