Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2012-2016 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 | ||
bd286a29 KCY |
22 | # Find length of addresses in bytes. |
23 | if {[is_64_target]} { | |
24 | set addr_len 8 | |
25 | } else { | |
26 | set addr_len 4 | |
27 | } | |
28 | ||
1b56eb55 JK |
29 | standard_testfile |
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 | |
34 | ||
35 | # $srcdir may be relative. | |
36 | if {[file pathtype $srcabsdir] != "absolute"} { | |
37 | untested "objdir pathtype is not absolute" | |
38 | return -1 | |
39 | } | |
40 | ||
41 | set f [open $asmsrcfile "w"] | |
42 | puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */" | |
43 | ||
44 | proc out_cu { name cu_dir cu_name line_dir line_name } { | |
45 | global f | |
bd286a29 | 46 | global addr_len |
1b56eb55 JK |
47 | |
48 | puts -nonewline $f "\ | |
49 | .L${name}_begin: | |
50 | .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */ | |
51 | .L${name}_start: | |
52 | .2byte 2 /* DWARF Version */ | |
53 | .4byte .Labbrev1_begin /* Offset into abbrev section */ | |
bd286a29 | 54 | .byte ${addr_len} /* Pointer size */ |
1b56eb55 JK |
55 | " |
56 | if { $cu_dir != "" } { | |
57 | puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */" | |
58 | } else { | |
59 | puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */" | |
60 | } | |
61 | puts -nonewline $f "\ | |
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 */ | |
bd286a29 KCY |
65 | .${addr_len}byte ${name}_start /* DW_AT_low_pc */ |
66 | .${addr_len}byte ${name}_end /* DW_AT_high_pc */ | |
1b56eb55 JK |
67 | " |
68 | if { $cu_dir != "" } { | |
69 | puts $f " .ascii $cu_dir /* DW_AT_comp_dir */" | |
70 | } | |
71 | puts -nonewline $f "\ | |
72 | .ascii $cu_name /* DW_AT_name */ | |
73 | ||
74 | .uleb128 3 /* Abbrev: DW_TAG_subprogram */ | |
75 | .asciz \"${name}\" /* DW_AT_name */ | |
bd286a29 KCY |
76 | .${addr_len}byte ${name}_start /* DW_AT_low_pc */ |
77 | .${addr_len}byte ${name}_end /* DW_AT_high_pc */ | |
1b56eb55 JK |
78 | |
79 | .byte 0 /* End of children of CU */ | |
80 | .L${name}_end: | |
81 | " | |
82 | } | |
83 | ||
84 | proc out_line { name cu_dir cu_name line_dir line_name } { | |
85 | global f | |
bd286a29 | 86 | global addr_len |
1b56eb55 JK |
87 | |
88 | puts -nonewline $f "\ | |
89 | .Lline_${name}_begin: | |
90 | .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */ | |
91 | .Lline_${name}_start: | |
92 | .2byte 2 /* Version */ | |
93 | .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */ | |
94 | .Lline_${name}_hdr: | |
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 */ | |
100 | ||
101 | /* Standard lengths */ | |
102 | .byte 0 | |
103 | .byte 1 | |
104 | .byte 1 | |
105 | ||
106 | /* Include directories */ | |
107 | " | |
108 | if { $line_dir != "" } { | |
109 | puts $f " .ascii $line_dir" | |
110 | } | |
111 | puts -nonewline $f "\ | |
112 | .byte 0 | |
113 | ||
114 | /* File names */ | |
115 | .ascii $line_name | |
116 | " | |
117 | if { $line_dir != "" } { | |
118 | puts $f " .uleb128 1" | |
119 | } else { | |
120 | puts $f " .uleb128 0" | |
121 | } | |
122 | puts -nonewline $f "\ | |
123 | .uleb128 0 | |
124 | .uleb128 0 | |
125 | ||
126 | .byte 0 | |
127 | ||
128 | .Lline_${name}_lines: | |
129 | .byte 3 /* DW_LNS_advance_line */ | |
130 | .sleb128 998 /* ... to 999 */ | |
131 | .byte 0 /* DW_LNE_set_address */ | |
bd286a29 | 132 | .uleb128 ${addr_len}+1 |
1b56eb55 | 133 | .byte 2 |
bd286a29 | 134 | .${addr_len}byte ${name}_start |
1b56eb55 JK |
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 */ | |
bd286a29 | 139 | .uleb128 ${addr_len}+1 |
1b56eb55 | 140 | .byte 2 |
bd286a29 | 141 | .${addr_len}byte ${name}_end |
1b56eb55 JK |
142 | .byte 1 /* DW_LNS_copy */ |
143 | .byte 0 /* DW_LNE_end_of_sequence */ | |
144 | .uleb128 1 | |
145 | .byte 1 | |
146 | .Lline_${name}_end: | |
147 | " | |
148 | } | |
149 | ||
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 | |
152 | # XDIR value. | |
153 | ||
154 | proc out_unit { func compdir ldir file ifsame } { | |
155 | set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}" | |
156 | ||
157 | if { $compdir == "missing_" } { | |
158 | set cu_dir {} | |
159 | } elseif { $compdir == "relative" } { | |
160 | set cu_dir {COMPDIR "\0"} | |
161 | } elseif { $compdir == "absolute" } { | |
162 | set cu_dir {BDIR "/" COMPDIR "\0"} | |
163 | } else { | |
164 | error "compdir $compdir" | |
165 | } | |
166 | ||
167 | if { $ldir == "missing_" } { | |
168 | set line_dir {} | |
169 | } elseif { $ldir == "relative" } { | |
170 | set line_dir {LDIR "\0"} | |
171 | } elseif { $ldir == "absolute" } { | |
172 | set line_dir {BDIR "/" LDIR "\0"} | |
173 | } else { | |
174 | error "ldir $ldir" | |
175 | } | |
176 | ||
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"} | |
183 | } else { | |
184 | error "file $file" | |
185 | } | |
186 | set line_name $cu_name | |
187 | ||
188 | if { "$ifsame" == "_different" } { | |
189 | if { $file == "absolute" } { | |
190 | if { $ldir == "absolute" } { | |
191 | set line_dir {XDIR "\0"} | |
192 | } | |
193 | if { $compdir == "absolute" } { | |
194 | set cu_dir {XDIR "\0"} | |
195 | } | |
196 | } elseif { $ldir == "absolute" } { | |
197 | if { $compdir == "absolute" } { | |
198 | set cu_dir {XDIR "\0"} | |
199 | } | |
200 | } else { | |
201 | error "not enough absolutes" | |
202 | } | |
203 | } | |
204 | ||
205 | $func $name $cu_dir $cu_name $line_dir $line_name | |
206 | } | |
207 | ||
208 | proc out_diff { func compdir ldir file } { | |
209 | set abscount 0 | |
210 | if { $compdir == "absolute" } { | |
211 | incr abscount | |
212 | } | |
213 | if { $ldir == "absolute" } { | |
214 | incr abscount | |
215 | } | |
216 | if { $file == "absolute" } { | |
217 | incr abscount | |
218 | } | |
219 | if { $abscount <= 1 } { | |
220 | out_unit $func $compdir $ldir $file "" | |
221 | } else { | |
222 | out_unit $func $compdir $ldir $file "_same" | |
223 | out_unit $func $compdir $ldir $file "_different" | |
224 | } | |
225 | } | |
226 | ||
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" | |
231 | } | |
232 | ||
233 | proc out_ldir { func compdir } { | |
234 | out_file $func $compdir "missing_" | |
235 | out_file $func $compdir "relative" | |
236 | out_file $func $compdir "absolute" | |
237 | } | |
238 | ||
239 | proc out_compdir { func } { | |
240 | out_ldir $func "missing_" | |
241 | out_ldir $func "relative" | |
242 | out_ldir $func "absolute" | |
243 | } | |
244 | ||
245 | puts -nonewline $f "\ | |
246 | #define ABBREV_NAME 1 | |
247 | #define ABBREV_COMP_DIR_NAME 2 | |
248 | .section .debug_info | |
249 | " | |
250 | out_compdir out_cu | |
251 | ||
252 | puts $f " .section .debug_line" | |
253 | out_compdir out_line | |
254 | ||
255 | puts -nonewline $f "\ | |
256 | .section .debug_abbrev | |
257 | .Labbrev1_begin: | |
258 | ||
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 */ | |
276 | ||
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 */ | |
296 | ||
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 */ | |
308 | ||
309 | .byte 0x0 /* Terminator */ | |
310 | .byte 0x0 /* Terminator */ | |
311 | " | |
312 | ||
313 | close $f | |
314 | ||
315 | set opts {} | |
316 | # Base directory. | |
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}\"" | |
328 | ||
329 | if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } { | |
330 | untested "Cannot compile ${asmsrcfile} or $srcfile" | |
331 | return -1 | |
332 | } | |
333 | ||
02392865 CG |
334 | set dirs {} |
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 | |
341 | } | |
342 | } | |
343 | } | |
344 | } | |
345 | } | |
346 | ||
347 | proc pathexpand {prefix dirlst suffix} { | |
348 | set retlst {} | |
349 | foreach dir $dirlst { | |
350 | lappend retlst "$prefix$dir$suffix" | |
351 | } | |
352 | return $retlst | |
353 | } | |
354 | ||
355 | set filelist [pathexpand $srcabsdir $dirs "/$srctmpfile"] | |
356 | set dircreatelist [pathexpand $srcabsdir $dirs ""] | |
357 | set dirremovelist [pathexpand $srcabsdir [lreverse $dirs] ""] | |
358 | ||
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\"" | |
1b56eb55 JK |
363 | |
364 | clean_restart ${testfile} | |
365 | ||
366 | if ![runto_main] { | |
367 | return -1 | |
368 | } | |
369 | ||
5a2dc60a | 370 | gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir" |
1b56eb55 | 371 | |
0a251e08 YQ |
372 | proc test { func compdir filename } { |
373 | with_test_prefix "$func" { | |
374 | # Clear the GDB cache. | |
375 | gdb_test_no_output "set directories" "" | |
1b56eb55 | 376 | |
0a251e08 YQ |
377 | if {$compdir == ""} { |
378 | set absolute "$filename" | |
379 | } else { | |
380 | set absolute "$compdir/$filename" | |
381 | } | |
382 | if {[string index $absolute 0] != "/"} { | |
383 | error "not absolute" | |
384 | } | |
1b56eb55 | 385 | |
0a251e08 YQ |
386 | gdb_breakpoint $func |
387 | gdb_continue_to_breakpoint $func "$func \\(\\) at .*" | |
1b56eb55 | 388 | |
0a251e08 YQ |
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" | |
1b56eb55 | 392 | |
0a251e08 YQ |
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" | |
1b56eb55 | 396 | |
0a251e08 YQ |
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" | |
400 | } | |
401 | } | |
1b56eb55 JK |
402 | |
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" |