]>
Commit | Line | Data |
---|---|---|
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/>. | |
15 | load_lib dwarf.exp | |
16 | ||
17 | # This test can only be run on targets which support DWARF-2 and use gas. | |
18 | if {![dwarf2_support]} { | |
19 | return 0 | |
20 | } | |
21 | ||
22 | standard_testfile | |
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 | |
27 | ||
28 | # $srcdir may be relative. | |
29 | if {[file pathtype $srcabsdir] != "absolute"} { | |
30 | untested "objdir pathtype is not absolute" | |
31 | return -1 | |
32 | } | |
33 | ||
34 | set f [open $asmsrcfile "w"] | |
35 | puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */" | |
36 | ||
37 | proc 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 | ||
76 | proc 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 | ||
145 | proc 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 | ||
199 | proc 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 | ||
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" | |
222 | } | |
223 | ||
224 | proc out_ldir { func compdir } { | |
225 | out_file $func $compdir "missing_" | |
226 | out_file $func $compdir "relative" | |
227 | out_file $func $compdir "absolute" | |
228 | } | |
229 | ||
230 | proc out_compdir { func } { | |
231 | out_ldir $func "missing_" | |
232 | out_ldir $func "relative" | |
233 | out_ldir $func "absolute" | |
234 | } | |
235 | ||
236 | puts -nonewline $f "\ | |
237 | #define ABBREV_NAME 1 | |
238 | #define ABBREV_COMP_DIR_NAME 2 | |
239 | .section .debug_info | |
240 | " | |
241 | out_compdir out_cu | |
242 | ||
243 | puts $f " .section .debug_line" | |
244 | out_compdir out_line | |
245 | ||
246 | puts -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 | ||
304 | close $f | |
305 | ||
306 | set opts {} | |
307 | # Base directory. | |
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}\"" | |
319 | ||
320 | if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } { | |
321 | untested "Cannot compile ${asmsrcfile} or $srcfile" | |
322 | return -1 | |
323 | } | |
324 | ||
325 | remote_exec host "sh -c \"rm -f ${srcabsdir}{/rdir,}{/xdir,}{/compdir,}{/ldir,}{/fdir,}/${srctmpfile}\"" | |
326 | remote_exec host "sh -c \"rmdir ${srcabsdir}{/rdir,}{/xdir,}{/compdir,}{/ldir,}{/fdir,}\"" | |
327 | remote_exec host "sh -c \"mkdir ${srcabsdir}{,/rdir}{,/xdir}{,/compdir}{,/ldir}{,/fdir}\"" | |
328 | remote_exec host "sh -c \"for d in ${srcabsdir}{,/rdir}{,/xdir}{,/compdir}{,/ldir}{,/fdir};do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\"" | |
329 | ||
330 | clean_restart ${testfile} | |
331 | ||
332 | if ![runto_main] { | |
333 | return -1 | |
334 | } | |
335 | ||
5a2dc60a | 336 | gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir" |
1b56eb55 JK |
337 | |
338 | proc test { func compdir filename } { with_test_prefix "$func" { | |
339 | # Clear the GDB cache. | |
340 | gdb_test_no_output "set directories" "" | |
341 | ||
342 | if {$compdir == ""} { | |
343 | set absolute "$filename" | |
344 | } else { | |
345 | set absolute "$compdir/$filename" | |
346 | } | |
347 | if {[string index $absolute 0] != "/"} { | |
348 | error "not absolute" | |
349 | } | |
350 | ||
351 | gdb_breakpoint $func | |
352 | gdb_continue_to_breakpoint $func "$func \\(\\) at .*" | |
353 | ||
354 | gdb_test_no_output "set filename-display absolute" | |
355 | verbose -log "expect: ${absolute}" | |
356 | gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute" | |
357 | ||
358 | gdb_test_no_output "set filename-display basename" | |
359 | verbose -log "expect: [file tail $filename]" | |
360 | gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename" | |
361 | ||
362 | gdb_test_no_output "set filename-display relative" | |
363 | verbose -log "expect: $filename" | |
364 | gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative" | |
365 | }} | |
366 | ||
367 | set bdir "${srcabsdir}" | |
368 | set file "${srctmpfile}" | |
369 | test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file" | |
370 | test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file" | |
371 | test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file" | |
372 | test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file" | |
373 | test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file" | |
374 | test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file" | |
375 | test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file" | |
376 | test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file" | |
377 | test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file" | |
378 | test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file" | |
379 | test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file" | |
380 | test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file" | |
381 | test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file" | |
382 | test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file" | |
383 | test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file" | |
384 | test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file" | |
385 | test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file" | |
386 | test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file" | |
387 | test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file" | |
388 | test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file" | |
389 | test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file" | |
390 | test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file" | |
391 | test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file" | |
392 | test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file" | |
393 | test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file" | |
394 | test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file" | |
395 | test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file" | |
396 | test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file" | |
397 | test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file" | |
398 | test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file" | |
399 | test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file" | |
400 | test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file" |