]>
Commit | Line | Data |
---|---|---|
6aba47ca DJ |
1 | # Copyright 1998, 2000, 2001, 2002, 2003, 2004, 2007 |
2 | # Free Software Foundation, Inc. | |
c906108c SS |
3 | # |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | # Please email any bugs, comments, and/or additions to this file to: | |
19 | # bug-gdb@prep.ai.mit.edu | |
20 | # | |
21 | # This file was written by Kendra. | |
22 | ||
23 | if $tracelevel then { | |
24 | strace $tracelevel | |
25 | } | |
26 | ||
27 | # | |
28 | # Test debugging assembly level programs. | |
29 | # This file uses asmsrc[12].s for input. | |
30 | # | |
31 | ||
32 | set prms_id 0 | |
33 | set bug_id 0 | |
34 | ||
78492fde | 35 | set asm-arch "" |
71507b56 | 36 | set asm-note "empty" |
78492fde | 37 | set asm-flags "" |
31d3fb18 | 38 | set link-flags "-e _start" |
575eebb1 | 39 | set debug-flags "" |
78492fde | 40 | |
be375bae | 41 | switch -glob -- [istarget] { |
acf4b816 RH |
42 | "alpha*-*-*" { |
43 | set asm-arch alpha | |
44 | # ??? Won't work with ecoff systems like Tru64, but then we also | |
45 | # don't have any other -g flag that creates mdebug output. | |
575eebb1 NC |
46 | set asm-flags "-no-mdebug -I${srcdir}/${subdir} -I${objdir}/${subdir}" |
47 | set debug-flags "-gdwarf-2" | |
acf4b816 | 48 | } |
be375bae JB |
49 | "*arm-*-*" { |
50 | set asm-arch arm | |
51 | } | |
52 | "xscale-*-*" { | |
53 | set asm-arch arm | |
54 | } | |
55 | "d10v-*-*" { | |
56 | set asm-arch d10v | |
57 | } | |
3a4c9371 KB |
58 | "frv-*-*" { |
59 | set asm-arch frv | |
60 | } | |
be375bae JB |
61 | "s390-*-*" { |
62 | set asm-arch s390 | |
63 | } | |
09bf6082 JB |
64 | "s390x-*-*" { |
65 | set asm-arch s390x | |
66 | } | |
be375bae JB |
67 | "x86_64-*-*" { |
68 | set asm-arch x86_64 | |
575eebb1 | 69 | set debug-flags "-gdwarf-2" |
be375bae JB |
70 | } |
71 | "i\[3456\]86-*-*" { | |
72 | set asm-arch i386 | |
be375bae | 73 | } |
73cb587d KI |
74 | "m32r*-linux*" { |
75 | set asm-arch m32r-linux | |
76 | } | |
c702009a MS |
77 | "m32c-*-*" { |
78 | set asm-arch m32c | |
79 | } | |
be375bae JB |
80 | "m32r*-*" { |
81 | set asm-arch m32r | |
3a4b3aac | 82 | append link-flags "--whole-archive -lgloss --no-whole-archive" |
be375bae JB |
83 | } |
84 | "m6811-*-*" { | |
85 | set asm-arch m68hc11 | |
c3d0b56e SC |
86 | set asm-flags "-mshort-double -m68hc11 --no-warn -I${srcdir}/${subdir} -I${objdir}/${subdir}" |
87 | set debug-flags "-gdwarf-2" | |
88 | # This asm test is specific and uses the linker directly. | |
89 | # We must not use the target board linker script defined for other | |
90 | # tests. Remove it and restore it later on. | |
91 | set board [target_info name] | |
92 | set old_ldscript [board_info $board ldscript] | |
93 | unset_board_info "ldscript" | |
be375bae JB |
94 | } |
95 | "m6812-*-*" { | |
96 | set asm-arch m68hc11 | |
c3d0b56e SC |
97 | set asm-flags "-mshort-double -m68hc12 --no-warn -I${srcdir}/${subdir} -I${objdir}/${subdir}" |
98 | set debug-flags "-gdwarf-2" | |
99 | # This asm test is specific and uses the linker directly. | |
100 | # We must not use the target board linker script defined for other | |
101 | # tests. Remove it and restore it later on. | |
102 | set board [target_info name] | |
103 | set old_ldscript [board_info $board ldscript] | |
104 | set_board_info ldscript "" | |
be375bae JB |
105 | } |
106 | "mips*-*" { | |
107 | set asm-arch mips | |
108 | } | |
109 | "powerpc*-*" { | |
110 | set asm-arch powerpc | |
111 | } | |
71e06f80 CV |
112 | "sh*-*-*" { |
113 | set asm-arch sh | |
575eebb1 | 114 | set debug-flags "-gdwarf-2" |
71e06f80 | 115 | } |
be375bae JB |
116 | "sparc-*-*" { |
117 | set asm-arch sparc | |
118 | } | |
119 | "sparc64-*-*" { | |
120 | set asm-arch sparc64 | |
575eebb1 NC |
121 | set asm-flags "-xarch=v9 -I${srcdir}/${subdir} -I${objdir}/${subdir}" |
122 | set debug-flags "-gdwarf-2" | |
be375bae | 123 | } |
c1d88655 UW |
124 | "spu*-*-*" { |
125 | set asm-arch spu | |
126 | set asm-flags "-I${srcdir}/${subdir} -I${objdir}/${subdir} --no-warn" | |
127 | set debug-flags "-gdwarf-2" | |
128 | } | |
be375bae JB |
129 | "xstormy16-*-*" { |
130 | set asm-arch xstormy16 | |
575eebb1 | 131 | set debug-flags "-gdwarf-2" |
be375bae JB |
132 | } |
133 | "v850-*-*" { | |
134 | set asm-arch v850 | |
135 | set gdb_wrapper_initialized 1 | |
a955b5bb | 136 | } |
2705e972 AS |
137 | "m68k-*-*" { |
138 | set asm-arch m68k | |
139 | } | |
4630e498 JJ |
140 | "ia64-*-*" { |
141 | set asm-arch ia64 | |
575eebb1 | 142 | set debug-flags "-gdwarf-2" |
4630e498 | 143 | } |
be46087e CV |
144 | "iq2000-*-*" { |
145 | set asm-arch iq2000 | |
146 | } | |
81bb3443 RC |
147 | "hppa*-linux-*" { |
148 | set asm-arch pa | |
575eebb1 | 149 | set debug-flags "-gdwarf-2" |
81bb3443 | 150 | } |
a1b06f35 MK |
151 | "hppa-*-openbsd*" { |
152 | set asm-arch pa | |
a1b06f35 MK |
153 | set debug-flags "-gdwarf-2" |
154 | } | |
9fdb1f50 RC |
155 | "hppa64-*-hpux*" { |
156 | set asm-arch pa64 | |
9fdb1f50 RC |
157 | set debug-flags "-gdwarf-2" |
158 | } | |
547b869a CV |
159 | "h83*-*" { |
160 | set asm-arch h8300 | |
761ae4d6 | 161 | set debug-flags "-gdwarf-2" |
547b869a | 162 | } |
017ac23d | 163 | } |
be375bae | 164 | |
78492fde | 165 | if { "${asm-arch}" == "" } { |
b60f0898 JB |
166 | untested asm-source.exp |
167 | return -1 | |
c906108c SS |
168 | } |
169 | ||
71507b56 MK |
170 | # On NetBSD/ELF we need a special NetBSD-identifying note section. |
171 | if { [istarget "*-*-netbsdelf*"] | |
8dd4540b | 172 | || [istarget "alpha-*-netbsd*"] |
b7cbf173 | 173 | || [istarget "mips*-*-netbsd*"] |
27ce9a6d | 174 | || [istarget "powerpc-*-netbsd*"] |
71507b56 MK |
175 | || [istarget "x86_64-*-netbsd*"] } then { |
176 | set asm-note "netbsd" | |
177 | } | |
178 | ||
53904d1e MK |
179 | # On OpenBSD/ELF we need a similar note section. We make no attempt |
180 | # of handing a.out here since most OpenBSD/a.out systems use a rather | |
181 | # outdated assembler that doesn't assemble this test's code anyway. | |
182 | if { [istarget "*-*-openbsd*"] } then { | |
183 | set asm-note "openbsd" | |
184 | } | |
185 | ||
0fcddd82 EZ |
186 | # Watch out, we are invoking the assembler, but the testsuite sets multilib |
187 | # switches according to compiler syntax. If we pass these options straight | |
188 | # to the assembler, they won't always make sense. If we don't pass them to | |
189 | # the assembler, the final link will complain that the object files were | |
190 | # built with different defaults. So no matter what we do, we lose. We may as | |
191 | # well get out of this test sooner rather than later. | |
192 | set dest [target_info name] | |
193 | if [board_info $dest exists multilib_flags] { | |
194 | set multilib_flags [board_info $dest multilib_flags] | |
195 | if { "${multilib_flags}" != "" } { | |
b60f0898 JB |
196 | untested asm-source.exp |
197 | return -1 | |
0fcddd82 EZ |
198 | return; |
199 | } | |
200 | } | |
201 | ||
c906108c SS |
202 | set testfile "asm-source" |
203 | set binfile ${objdir}/${subdir}/${testfile} | |
f2dd3617 EZ |
204 | set srcfile1 asmsrc1.s |
205 | set srcfile2 asmsrc2.s | |
c906108c | 206 | |
a73a20a2 EZ |
207 | remote_exec build "rm -f ${subdir}/arch.inc" |
208 | remote_download host ${srcdir}/${subdir}/${asm-arch}.inc ${subdir}/arch.inc | |
71507b56 MK |
209 | remote_exec build "rm -f ${subdir}/note.inc" |
210 | remote_download host ${srcdir}/${subdir}/${asm-note}.inc ${subdir}/note.inc | |
16a8534a | 211 | |
761ae4d6 | 212 | if { [string equal ${asm-flags} ""] } { |
575eebb1 | 213 | set asm-flags "-I${srcdir}/${subdir} -I${objdir}/${subdir}" |
761ae4d6 JB |
214 | } |
215 | ||
216 | if { [string equal ${debug-flags} ""] } { | |
575eebb1 | 217 | set debug-flags "-gstabs" |
78492fde | 218 | } |
c906108c | 219 | |
c724d49b | 220 | # Allow the target board to override the debug flags. |
575eebb1 NC |
221 | if { [board_info $dest exists debug_flags] } then { |
222 | set debug-flags "[board_info $dest debug_flags]" | |
223 | } | |
224 | ||
c724d49b MC |
225 | # The debug flags are in the format that gcc expects: |
226 | # "-gdwarf-2", "-gstabs+", or "-gstabs". To be compatible with the | |
227 | # other languages in the test suite, we accept this input format. | |
228 | # So the user can run the test suite with: | |
229 | # | |
230 | # runtest --target_board unix/gdb:debug_flags=-gdwarf-2 | |
231 | # make check RUNTESTFLAGS="--target_board unix/gdb:debug_flags=-gdwarf-2" | |
232 | # | |
233 | # However, the GNU assembler has different spellings than gcc. | |
234 | # So I adjust the debug flags here. | |
235 | ||
236 | # The GNU assembler spells "dwarf-2" as "dwarf2". | |
237 | regsub "--" "-gdwarf-2" "${debug-flags}" "-gdwarf2" debug-flags | |
238 | ||
239 | # The GNU assembler before 2.15 did not support "stabs+". | |
240 | regsub "--" "-gstabs\[+\]" "${debug-flags}" "-gstabs" debug-flags | |
241 | ||
242 | # The GNU assembler does not support level options like "-g2" or "-g3". | |
243 | regsub "--" "-g\[0-9\]" "${debug-flags}" "" debug-flags | |
575eebb1 NC |
244 | |
245 | if {[target_assemble ${srcdir}/${subdir}/${srcfile1} asmsrc1.o "${asm-flags} ${debug-flags}"] != ""} then { | |
b60f0898 JB |
246 | untested asm-source.exp |
247 | return -1 | |
c906108c | 248 | } |
575eebb1 | 249 | if {[target_assemble ${srcdir}/${subdir}/${srcfile2} asmsrc2.o "${asm-flags} ${debug-flags}"] != ""} then { |
b60f0898 JB |
250 | untested asm-source.exp |
251 | return -1 | |
c906108c SS |
252 | } |
253 | ||
3a4b3aac MK |
254 | # We deliberately don't use gdb_compile here to link together the |
255 | # assembled object files. Using gdb_compile, and therefore the C | |
256 | # compiler, is conceptually wrong, since we're testing raw assembler | |
257 | # code here that provides its own startup code. Using target_link | |
258 | # also avoids a lot of problems on many systems, most notably on | |
259 | # *-*-*bsd* and *-*-solaris2*. | |
260 | if {[target_link "asmsrc1.o asmsrc2.o" "${binfile}" ${link-flags}] != "" } then { | |
b60f0898 JB |
261 | untested asm-source.exp |
262 | return -1 | |
c906108c SS |
263 | } |
264 | ||
c3d0b56e SC |
265 | # Restore the target board linker script for HC11/HC12. |
266 | if { [istarget "m6811-*-*"] || [istarget "m6812-*-*"] } { | |
267 | set_board_info ldscript $old_ldscript | |
268 | } | |
269 | ||
c906108c SS |
270 | remote_exec build "mv asmsrc1.o asmsrc2.o ${objdir}/${subdir}" |
271 | ||
272 | ||
273 | gdb_start | |
274 | gdb_reinitialize_dir $srcdir/$subdir | |
275 | gdb_load ${binfile} | |
276 | ||
277 | # | |
278 | # Run to `main' where we begin our tests. | |
279 | # | |
280 | ||
281 | if ![runto_main] then { | |
282 | gdb_suppress_tests | |
283 | } | |
284 | ||
285 | # Execute the `f' command and see if the result includes source info. | |
78492fde | 286 | gdb_test "f" "asmsrc1\[.\]s:29.*several_nops" "f at main" |
c906108c SS |
287 | |
288 | # See if we properly `next' over a macro with several insns. | |
78492fde | 289 | gdb_test "n" "33\[ \]*.*foo2" "next over macro" |
c906108c SS |
290 | |
291 | # See if we can properly `step' into a subroutine call. | |
292 | gdb_test "s" "8\[ \]*.*" "step into foo2" | |
293 | ||
edb6ede1 MS |
294 | # Test 'info target', and incidentally capture the entry point address. |
295 | set entry_point 0 | |
296 | send_gdb "info target\n" | |
297 | gdb_expect { | |
298 | -re "Symbols from .*asm-source.*Entry point: 0x(\[01232456789abcdefABCDEF\]+).*$gdb_prompt $" { | |
299 | set entry_point $expect_out(1,string) | |
300 | pass "info target" | |
301 | } | |
302 | -re ".*$gdb_prompt $" { | |
303 | fail "info target" | |
304 | } | |
305 | timeout { | |
306 | fail "info target (timeout)" | |
307 | } | |
308 | } | |
309 | ||
310 | # Capture the start symbol (may be '_start' or 'start') | |
311 | set entry_symbol "" | |
312 | send_gdb "info symbol 0x$entry_point\n" | |
313 | gdb_expect { | |
ecace851 JB |
314 | -re "info symbol 0x$entry_point\[\r\n\]+(\[^\r\n\]*) in section .*$gdb_prompt $" { |
315 | # We match the echoed `info symbol' command here, to help us | |
316 | # reliably identify the beginning of the start symbol in the | |
317 | # command's output. You might think we could just use '^' to | |
318 | # start matching at the beginning of the line, but | |
319 | # unfortunately, in Expect, '^' matches the beginning of the | |
320 | # input that hasn't been matched by any expect clause yet. If | |
321 | # every expect clause consumes a complete line, along with its | |
322 | # terminating CR/LF, this is equivalent to the beginning of a | |
323 | # line. But expect clauses that end with `.*' will consume as | |
324 | # much as happened to arrive from the TTY --- exactly where | |
325 | # they leave you depends on inter-process timing. :( | |
edb6ede1 MS |
326 | set entry_symbol $expect_out(1,string) |
327 | pass "info symbol" | |
328 | } | |
329 | -re ".*$gdb_prompt $" { | |
330 | fail "info symbol" | |
331 | } | |
332 | timeout { | |
333 | fail "info symbol (timeout)" | |
334 | } | |
335 | } | |
336 | ||
ca9efc90 | 337 | # Now try a 'list' from the other source file. |
edb6ede1 | 338 | gdb_test "list $entry_symbol" ".*gdbasm_startup.*" "list" |
ca9efc90 MS |
339 | |
340 | # Now try a source file search | |
341 | gdb_test "search A routine for foo2 to call" \ | |
8b1d7e37 | 342 | "40\[ \t\]+comment \"A routine for foo2 to call.\"" "search" |
ca9efc90 | 343 | |
c906108c SS |
344 | # See if `f' prints the right source file. |
345 | gdb_test "f" ".*asmsrc2\[.\]s:8.*" "f in foo2" | |
346 | ||
347 | # `next' one insn (or macro) to set up our stackframe (for the following bt). | |
348 | gdb_test "n" "12\[ \]*.*foo3" "n in foo2" | |
349 | ||
b5703437 MS |
350 | # See if a simple `bt' prints the right source files and |
351 | # doesn't fall off the stack. | |
352 | ||
353 | gdb_test "bt 10" \ | |
0714963c | 354 | "\#0.*foo2.*asmsrc2\[.\]s:12.*\#1.*main.*asmsrc1\[.\]s:33" \ |
b5703437 | 355 | "bt ALL in foo2" |
78492fde AC |
356 | |
357 | # See if a capped `bt' prints the right source files. | |
358 | gdb_test "bt 2" "\#0.*foo2.*asmsrc2\[.\]s:12.*\#1.*main.*asmsrc1\[.\]s:33.*" "bt 2 in foo2" | |
c906108c SS |
359 | |
360 | # Step into another subroutine which lives back in the first source file. | |
361 | gdb_test "s" "" "s 2" | |
362 | ||
363 | # Next over insns to set up the stack frame. | |
364 | gdb_test "n" "" "n 2" | |
365 | ||
78492fde | 366 | # Now see if a capped `bt' is correct. |
8b1d7e37 | 367 | gdb_test "bt 3" "\#0.*foo3.*asmsrc1\[.\]s:45.*\#1.*foo2.*asmsrc2\[.\]s:12.*\#2.*main.*asmsrc1\[.\]s:33.*" "bt 3 in foo3" |
ca9efc90 MS |
368 | |
369 | # Try 'info source' from asmsrc1.s | |
370 | gdb_test "info source" \ | |
371 | "Current source file is .*asmsrc1.s.*Source language is asm.*" \ | |
372 | "info source asmsrc1.s" | |
373 | ||
374 | # Try 'finishing' from foo3 | |
375 | gdb_test "finish" "Run till exit from.*\[\r\n\]13\[ \t\]+gdbasm_call foo3" \ | |
376 | "finish from foo3" | |
377 | ||
378 | # Try 'info source' from asmsrc2.s | |
379 | gdb_test "info source" \ | |
380 | "Current source file is .*asmsrc2.s.*Source language is asm.*" \ | |
381 | "info source asmsrc2.s" | |
382 | ||
27924826 JB |
383 | # Try 'info sources'. This can produce a lot of output on systems |
384 | # with dynamic linking, where the system's shared libc was compiled | |
385 | # with debugging info; for example, on Linux, this produces 47kb of | |
386 | # output. So we consume it as we go. | |
387 | send_gdb "info sources\n" | |
388 | set seen_asmsrc_1 0 | |
389 | set seen_asmsrc_2 0 | |
390 | gdb_expect { | |
391 | -re "^\[^,\]*asmsrc1.s(, |\[\r\n\]+)" { | |
392 | set seen_asmsrc_1 1 | |
393 | exp_continue | |
394 | } | |
395 | -re "^\[^,\]*asmsrc2.s(, |\[\r\n\]+)" { | |
396 | set seen_asmsrc_2 1 | |
397 | exp_continue | |
398 | } | |
399 | -re ", " { | |
400 | exp_continue | |
401 | } | |
402 | -re "$gdb_prompt $" { | |
403 | if {$seen_asmsrc_1 && $seen_asmsrc_2} { | |
404 | pass "info sources" | |
405 | } else { | |
406 | fail "info sources" | |
407 | } | |
408 | } | |
409 | timeout { | |
410 | fail "info sources (timeout)" | |
411 | } | |
412 | } | |
413 | ||
ca9efc90 MS |
414 | |
415 | # Try 'info line' | |
416 | gdb_test "info line" \ | |
417 | "Line 13 of.*asmsrc2.s.*starts at.*<foo2+.*> and ends at.*<foo2+.*>." \ | |
418 | "info line" | |
419 | ||
420 | # Try 'nexting' over next call to foo3 | |
421 | gdb_test "next" "17\[ \t\]+gdbasm_leave" "next over foo3" | |
422 | ||
423 | # Try 'return' from foo2 | |
424 | gdb_test "return" "\#0 main .*37\[ \t\]+gdbasm_exit0" "return from foo2" \ | |
8b1d7e37 | 425 | "Make (foo2|selected stack frame) return now\?.*" "y" |
ca9efc90 | 426 | |
2b6fd0d8 AC |
427 | # Disassemble something, check the output |
428 | proc test_dis { command var } { | |
429 | global gdb_prompt | |
430 | send_gdb "${command}\n" | |
431 | gdb_expect { | |
572eb746 | 432 | -re "${var}.*:.*(Cannot access|Bad address)" { |
2b6fd0d8 AC |
433 | # The "disassembler" was only accessing the local |
434 | # executable and that would cause attempts to disassemble | |
435 | # variables to fail (memory not valid). | |
436 | fail "${command} (memory read error)" | |
437 | } | |
438 | -re "${var}.*:.*${gdb_prompt}" { | |
439 | pass "${command}" | |
440 | } | |
441 | timeout { | |
442 | fail "${command} (timeout)" | |
443 | } | |
444 | } | |
445 | } | |
446 | ||
447 | # See if we can look at a global variable, three ways | |
ca9efc90 | 448 | gdb_test "print globalvar" ".* = 11" "look at global variable" |
2c161407 | 449 | test_dis "x/i &globalvar" "globalvar" |
2b6fd0d8 | 450 | test_dis "disassem &globalvar &globalvar+1" "globalvar" |
ca9efc90 | 451 | |
2b6fd0d8 | 452 | # See if we can look at a static variable, three ways |
ca9efc90 | 453 | gdb_test "print staticvar" ".* = 5" "look at static variable" |
2b6fd0d8 AC |
454 | test_dis "x/i &staticvar" "staticvar" |
455 | test_dis "disassem &staticvar &staticvar+1" "staticvar" | |
ca9efc90 MS |
456 | |
457 | # See if we can look at a static function | |
83c31e7d | 458 | gdb_test "disassem foostatic" ".*<foostatic\\+0>:.*End of assembler dump." \ |
ca9efc90 MS |
459 | "look at static function" |
460 | ||
a73a20a2 | 461 | remote_exec build "rm -f ${subdir}/arch.inc" |
71507b56 | 462 | remote_exec build "rm -f ${subdir}/note.inc" |