]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.asm/asm-source.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.asm / asm-source.exp
1 # Copyright 1998, 2000, 2001, 2002, 2003, 2004, 2007
2 # Free Software Foundation, Inc.
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
35 set asm-arch ""
36 set asm-note "empty"
37 set asm-flags ""
38 set link-flags "-e _start"
39 set debug-flags ""
40
41 switch -glob -- [istarget] {
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.
46 set asm-flags "-no-mdebug -I${srcdir}/${subdir} -I${objdir}/${subdir}"
47 set debug-flags "-gdwarf-2"
48 }
49 "*arm-*-*" {
50 set asm-arch arm
51 }
52 "xscale-*-*" {
53 set asm-arch arm
54 }
55 "d10v-*-*" {
56 set asm-arch d10v
57 }
58 "frv-*-*" {
59 set asm-arch frv
60 }
61 "s390-*-*" {
62 set asm-arch s390
63 }
64 "s390x-*-*" {
65 set asm-arch s390x
66 }
67 "x86_64-*-*" {
68 set asm-arch x86_64
69 set debug-flags "-gdwarf-2"
70 }
71 "i\[3456\]86-*-*" {
72 set asm-arch i386
73 }
74 "m32r*-linux*" {
75 set asm-arch m32r-linux
76 }
77 "m32c-*-*" {
78 set asm-arch m32c
79 }
80 "m32r*-*" {
81 set asm-arch m32r
82 append link-flags "--whole-archive -lgloss --no-whole-archive"
83 }
84 "m6811-*-*" {
85 set asm-arch m68hc11
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"
94 }
95 "m6812-*-*" {
96 set asm-arch m68hc11
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 ""
105 }
106 "mips*-*" {
107 set asm-arch mips
108 }
109 "powerpc*-*" {
110 set asm-arch powerpc
111 }
112 "sh*-*-*" {
113 set asm-arch sh
114 set debug-flags "-gdwarf-2"
115 }
116 "sparc-*-*" {
117 set asm-arch sparc
118 }
119 "sparc64-*-*" {
120 set asm-arch sparc64
121 set asm-flags "-xarch=v9 -I${srcdir}/${subdir} -I${objdir}/${subdir}"
122 set debug-flags "-gdwarf-2"
123 }
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 }
129 "xstormy16-*-*" {
130 set asm-arch xstormy16
131 set debug-flags "-gdwarf-2"
132 }
133 "v850-*-*" {
134 set asm-arch v850
135 set gdb_wrapper_initialized 1
136 }
137 "m68k-*-*" {
138 set asm-arch m68k
139 }
140 "ia64-*-*" {
141 set asm-arch ia64
142 set debug-flags "-gdwarf-2"
143 }
144 "iq2000-*-*" {
145 set asm-arch iq2000
146 }
147 "hppa*-linux-*" {
148 set asm-arch pa
149 set debug-flags "-gdwarf-2"
150 }
151 "hppa-*-openbsd*" {
152 set asm-arch pa
153 set debug-flags "-gdwarf-2"
154 }
155 "hppa64-*-hpux*" {
156 set asm-arch pa64
157 set debug-flags "-gdwarf-2"
158 }
159 "h83*-*" {
160 set asm-arch h8300
161 set debug-flags "-gdwarf-2"
162 }
163 }
164
165 if { "${asm-arch}" == "" } {
166 untested asm-source.exp
167 return -1
168 }
169
170 # On NetBSD/ELF we need a special NetBSD-identifying note section.
171 if { [istarget "*-*-netbsdelf*"]
172 || [istarget "alpha-*-netbsd*"]
173 || [istarget "mips*-*-netbsd*"]
174 || [istarget "powerpc-*-netbsd*"]
175 || [istarget "x86_64-*-netbsd*"] } then {
176 set asm-note "netbsd"
177 }
178
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
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}" != "" } {
196 untested asm-source.exp
197 return -1
198 return;
199 }
200 }
201
202 set testfile "asm-source"
203 set binfile ${objdir}/${subdir}/${testfile}
204 set srcfile1 asmsrc1.s
205 set srcfile2 asmsrc2.s
206
207 remote_exec build "rm -f ${subdir}/arch.inc"
208 remote_download host ${srcdir}/${subdir}/${asm-arch}.inc ${subdir}/arch.inc
209 remote_exec build "rm -f ${subdir}/note.inc"
210 remote_download host ${srcdir}/${subdir}/${asm-note}.inc ${subdir}/note.inc
211
212 if { [string equal ${asm-flags} ""] } {
213 set asm-flags "-I${srcdir}/${subdir} -I${objdir}/${subdir}"
214 }
215
216 if { [string equal ${debug-flags} ""] } {
217 set debug-flags "-gstabs"
218 }
219
220 # Allow the target board to override the debug flags.
221 if { [board_info $dest exists debug_flags] } then {
222 set debug-flags "[board_info $dest debug_flags]"
223 }
224
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
244
245 if {[target_assemble ${srcdir}/${subdir}/${srcfile1} asmsrc1.o "${asm-flags} ${debug-flags}"] != ""} then {
246 untested asm-source.exp
247 return -1
248 }
249 if {[target_assemble ${srcdir}/${subdir}/${srcfile2} asmsrc2.o "${asm-flags} ${debug-flags}"] != ""} then {
250 untested asm-source.exp
251 return -1
252 }
253
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 {
261 untested asm-source.exp
262 return -1
263 }
264
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
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.
286 gdb_test "f" "asmsrc1\[.\]s:29.*several_nops" "f at main"
287
288 # See if we properly `next' over a macro with several insns.
289 gdb_test "n" "33\[ \]*.*foo2" "next over macro"
290
291 # See if we can properly `step' into a subroutine call.
292 gdb_test "s" "8\[ \]*.*" "step into foo2"
293
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 {
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. :(
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
337 # Now try a 'list' from the other source file.
338 gdb_test "list $entry_symbol" ".*gdbasm_startup.*" "list"
339
340 # Now try a source file search
341 gdb_test "search A routine for foo2 to call" \
342 "40\[ \t\]+comment \"A routine for foo2 to call.\"" "search"
343
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
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" \
354 "\#0.*foo2.*asmsrc2\[.\]s:12.*\#1.*main.*asmsrc1\[.\]s:33" \
355 "bt ALL in foo2"
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"
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
366 # Now see if a capped `bt' is correct.
367 gdb_test "bt 3" "\#0.*foo3.*asmsrc1\[.\]s:45.*\#1.*foo2.*asmsrc2\[.\]s:12.*\#2.*main.*asmsrc1\[.\]s:33.*" "bt 3 in foo3"
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
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
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" \
425 "Make (foo2|selected stack frame) return now\?.*" "y"
426
427 # Disassemble something, check the output
428 proc test_dis { command var } {
429 global gdb_prompt
430 send_gdb "${command}\n"
431 gdb_expect {
432 -re "${var}.*:.*(Cannot access|Bad address)" {
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
448 gdb_test "print globalvar" ".* = 11" "look at global variable"
449 test_dis "x/i &globalvar" "globalvar"
450 test_dis "disassem &globalvar &globalvar+1" "globalvar"
451
452 # See if we can look at a static variable, three ways
453 gdb_test "print staticvar" ".* = 5" "look at static variable"
454 test_dis "x/i &staticvar" "staticvar"
455 test_dis "disassem &staticvar &staticvar+1" "staticvar"
456
457 # See if we can look at a static function
458 gdb_test "disassem foostatic" ".*<foostatic\\+0>:.*End of assembler dump." \
459 "look at static function"
460
461 remote_exec build "rm -f ${subdir}/arch.inc"
462 remote_exec build "rm -f ${subdir}/note.inc"