PR ld/12982
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-dir-file-name.exp
CommitLineData
6c01dd94 1# Copyright 2012-2013 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.
18if {![dwarf2_support]} {
19 return 0
20}
21
22standard_testfile
23set asmsrcfile [standard_output_file ${testfile}asm.S]
24set asmobjfile [standard_output_file ${testfile}asm.o]
25set srcabsdir [standard_output_file ${testfile}.d]
26set srctmpfile tmp-${testfile}.c
27
28# $srcdir may be relative.
29if {[file pathtype $srcabsdir] != "absolute"} {
30 untested "objdir pathtype is not absolute"
31 return -1
32}
33
34set f [open $asmsrcfile "w"]
35puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */"
36
37proc out_cu { name cu_dir cu_name line_dir line_name } {
38 global f
39
40 puts -nonewline $f "\
41.L${name}_begin:
42 .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */
43.L${name}_start:
44 .2byte 2 /* DWARF Version */
45 .4byte .Labbrev1_begin /* Offset into abbrev section */
46 .byte 4 /* Pointer size */
47"
48 if { $cu_dir != "" } {
49 puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */"
50 } else {
51 puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */"
52 }
53 puts -nonewline $f "\
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 */
59"
60 if { $cu_dir != "" } {
61 puts $f " .ascii $cu_dir /* DW_AT_comp_dir */"
62 }
63 puts -nonewline $f "\
64 .ascii $cu_name /* DW_AT_name */
65
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 */
70
71 .byte 0 /* End of children of CU */
72.L${name}_end:
73"
74}
75
76proc out_line { name cu_dir cu_name line_dir line_name } {
77 global f
78
79 puts -nonewline $f "\
80.Lline_${name}_begin:
81 .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */
82.Lline_${name}_start:
83 .2byte 2 /* Version */
84 .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */
85.Lline_${name}_hdr:
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 */
91
92 /* Standard lengths */
93 .byte 0
94 .byte 1
95 .byte 1
96
97 /* Include directories */
98"
99 if { $line_dir != "" } {
100 puts $f " .ascii $line_dir"
101 }
102 puts -nonewline $f "\
103 .byte 0
104
105 /* File names */
106 .ascii $line_name
107"
108 if { $line_dir != "" } {
109 puts $f " .uleb128 1"
110 } else {
111 puts $f " .uleb128 0"
112 }
113 puts -nonewline $f "\
114 .uleb128 0
115 .uleb128 0
116
117 .byte 0
118
119.Lline_${name}_lines:
120 .byte 3 /* DW_LNS_advance_line */
121 .sleb128 998 /* ... to 999 */
122 .byte 0 /* DW_LNE_set_address */
123 .uleb128 5
124 .byte 2
125 .4byte ${name}_start
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 */
130 .uleb128 5
131 .byte 2
132 .4byte ${name}_end
133 .byte 1 /* DW_LNS_copy */
134 .byte 0 /* DW_LNE_end_of_sequence */
135 .uleb128 1
136 .byte 1
137.Lline_${name}_end:
138"
139}
140
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
143# XDIR value.
144
145proc out_unit { func compdir ldir file ifsame } {
146 set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}"
147
148 if { $compdir == "missing_" } {
149 set cu_dir {}
150 } elseif { $compdir == "relative" } {
151 set cu_dir {COMPDIR "\0"}
152 } elseif { $compdir == "absolute" } {
153 set cu_dir {BDIR "/" COMPDIR "\0"}
154 } else {
155 error "compdir $compdir"
156 }
157
158 if { $ldir == "missing_" } {
159 set line_dir {}
160 } elseif { $ldir == "relative" } {
161 set line_dir {LDIR "\0"}
162 } elseif { $ldir == "absolute" } {
163 set line_dir {BDIR "/" LDIR "\0"}
164 } else {
165 error "ldir $ldir"
166 }
167
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"}
174 } else {
175 error "file $file"
176 }
177 set line_name $cu_name
178
179 if { "$ifsame" == "_different" } {
180 if { $file == "absolute" } {
181 if { $ldir == "absolute" } {
182 set line_dir {XDIR "\0"}
183 }
184 if { $compdir == "absolute" } {
185 set cu_dir {XDIR "\0"}
186 }
187 } elseif { $ldir == "absolute" } {
188 if { $compdir == "absolute" } {
189 set cu_dir {XDIR "\0"}
190 }
191 } else {
192 error "not enough absolutes"
193 }
194 }
195
196 $func $name $cu_dir $cu_name $line_dir $line_name
197}
198
199proc out_diff { func compdir ldir file } {
200 set abscount 0
201 if { $compdir == "absolute" } {
202 incr abscount
203 }
204 if { $ldir == "absolute" } {
205 incr abscount
206 }
207 if { $file == "absolute" } {
208 incr abscount
209 }
210 if { $abscount <= 1 } {
211 out_unit $func $compdir $ldir $file ""
212 } else {
213 out_unit $func $compdir $ldir $file "_same"
214 out_unit $func $compdir $ldir $file "_different"
215 }
216}
217
218proc 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"
222}
223
224proc out_ldir { func compdir } {
225 out_file $func $compdir "missing_"
226 out_file $func $compdir "relative"
227 out_file $func $compdir "absolute"
228}
229
230proc out_compdir { func } {
231 out_ldir $func "missing_"
232 out_ldir $func "relative"
233 out_ldir $func "absolute"
234}
235
236puts -nonewline $f "\
237#define ABBREV_NAME 1
238#define ABBREV_COMP_DIR_NAME 2
239 .section .debug_info
240"
241out_compdir out_cu
242
243puts $f " .section .debug_line"
244out_compdir out_line
245
246puts -nonewline $f "\
247 .section .debug_abbrev
248.Labbrev1_begin:
249
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 */
267
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 */
287
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 */
299
300 .byte 0x0 /* Terminator */
301 .byte 0x0 /* Terminator */
302"
303
304close $f
305
306set opts {}
307# Base directory.
308lappend opts "additional_flags=-DBDIR=\"${srcabsdir}\""
309# Incorrect directory which should never be visible from GDB.
310lappend opts "additional_flags=-DXDIR=\"${srcabsdir}/xdir\""
311# CU's DW_AT_comp_dir.
312lappend opts "additional_flags=-DCOMPDIR=\"compdir\""
313# .debug_line's directory.
314lappend opts "additional_flags=-DLDIR=\"ldir\""
315# CU's DW_AT_name and .debug_line's filename relative directory, if needed.
316lappend opts "additional_flags=-DFDIR=\"fdir\""
317# CU's DW_AT_name and .debug_line's filename.
318lappend opts "additional_flags=-DFILE=\"${srctmpfile}\""
319
320if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } {
321 untested "Cannot compile ${asmsrcfile} or $srcfile"
322 return -1
323}
324
325remote_exec host "sh -c \"rm -f ${srcabsdir}{/rdir,}{/xdir,}{/compdir,}{/ldir,}{/fdir,}/${srctmpfile}\""
326remote_exec host "sh -c \"rmdir ${srcabsdir}{/rdir,}{/xdir,}{/compdir,}{/ldir,}{/fdir,}\""
327remote_exec host "sh -c \"mkdir ${srcabsdir}{,/rdir}{,/xdir}{,/compdir}{,/ldir}{,/fdir}\""
328remote_exec host "sh -c \"for d in ${srcabsdir}{,/rdir}{,/xdir}{,/compdir}{,/ldir}{,/fdir};do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\""
329
330clean_restart ${testfile}
331
332if ![runto_main] {
333 return -1
334}
335
5a2dc60a 336gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir"
1b56eb55 337
0a251e08
YQ
338proc test { func compdir filename } {
339 with_test_prefix "$func" {
340 # Clear the GDB cache.
341 gdb_test_no_output "set directories" ""
1b56eb55 342
0a251e08
YQ
343 if {$compdir == ""} {
344 set absolute "$filename"
345 } else {
346 set absolute "$compdir/$filename"
347 }
348 if {[string index $absolute 0] != "/"} {
349 error "not absolute"
350 }
1b56eb55 351
0a251e08
YQ
352 gdb_breakpoint $func
353 gdb_continue_to_breakpoint $func "$func \\(\\) at .*"
1b56eb55 354
0a251e08
YQ
355 gdb_test_no_output "set filename-display absolute"
356 verbose -log "expect: ${absolute}"
357 gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute"
1b56eb55 358
0a251e08
YQ
359 gdb_test_no_output "set filename-display basename"
360 verbose -log "expect: [file tail $filename]"
361 gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename"
1b56eb55 362
0a251e08
YQ
363 gdb_test_no_output "set filename-display relative"
364 verbose -log "expect: $filename"
365 gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative"
366 }
367}
1b56eb55
JK
368
369set bdir "${srcabsdir}"
370set file "${srctmpfile}"
371test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file"
372test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file"
373test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file"
374test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file"
375test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file"
376test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file"
377test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file"
378test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
379test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file"
380test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file"
381test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file"
382test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file"
383test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file"
384test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file"
385test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file"
386test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file"
387test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file"
388test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file"
389test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file"
390test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file"
391test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file"
392test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file"
393test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file"
394test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file"
395test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file"
396test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file"
397test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file"
398test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file"
399test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file"
400test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file"
401test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file"
402test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file"
This page took 0.081199 seconds and 4 git commands to generate.