Commit | Line | Data |
---|---|---|
f2dd3617 | 1 | # Copyright 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
c906108c SS |
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 2 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, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | # | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | # | |
20 | # This file was written by Kendra. | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | # | |
27 | # Test debugging assembly level programs. | |
28 | # This file uses asmsrc[12].s for input. | |
29 | # | |
30 | ||
31 | set prms_id 0 | |
32 | set bug_id 0 | |
33 | ||
78492fde AC |
34 | set asm-arch "" |
35 | set asm-flags "" | |
25050984 | 36 | set link-flags "" |
78492fde | 37 | |
be375bae JB |
38 | switch -glob -- [istarget] { |
39 | "*arm-*-*" { | |
40 | set asm-arch arm | |
41 | } | |
42 | "xscale-*-*" { | |
43 | set asm-arch arm | |
44 | } | |
45 | "d10v-*-*" { | |
46 | set asm-arch d10v | |
47 | } | |
48 | "s390-*-*" { | |
49 | set asm-arch s390 | |
50 | } | |
09bf6082 JB |
51 | "s390x-*-*" { |
52 | set asm-arch s390x | |
53 | } | |
be375bae JB |
54 | "x86_64-*-*" { |
55 | set asm-arch x86_64 | |
56 | set asm-flags "-gdwarf2 -I${srcdir}/${subdir} -I${objdir}/${subdir}" | |
57 | } | |
58 | "i\[3456\]86-*-*" { | |
59 | set asm-arch i386 | |
60 | if [istarget "*-*-cygwin*"] then { | |
61 | set link-flags "--entry _start" | |
62 | } | |
63 | } | |
64 | "m32r*-*" { | |
65 | set asm-arch m32r | |
66 | } | |
67 | "m6811-*-*" { | |
68 | set asm-arch m68hc11 | |
69 | set asm-flags "-mshort-double -m68hc11 -gdwarf2 --no-warn -I${srcdir}/${subdir} -I${objdir}/${subdir}" | |
70 | } | |
71 | "m6812-*-*" { | |
72 | set asm-arch m68hc11 | |
73 | set asm-flags "-mshort-double -m68hc12 -gdwarf2 --no-warn -I${srcdir}/${subdir} -I${objdir}/${subdir}" | |
74 | } | |
75 | "mips*-*" { | |
76 | set asm-arch mips | |
77 | } | |
78 | "powerpc*-*" { | |
79 | set asm-arch powerpc | |
80 | } | |
81 | "sparc-*-*" { | |
82 | set asm-arch sparc | |
83 | } | |
84 | "sparc64-*-*" { | |
85 | set asm-arch sparc64 | |
86 | set asm-flags "-xarch=v9 -gstabs -I${srcdir}/${subdir} -I${objdir}/${subdir}" | |
87 | } | |
88 | "xstormy16-*-*" { | |
89 | set asm-arch xstormy16 | |
90 | set asm-flags "-gdwarf2 -I${srcdir}/${subdir} -I${objdir}/${subdir}" | |
91 | } | |
92 | "v850-*-*" { | |
93 | set asm-arch v850 | |
94 | set gdb_wrapper_initialized 1 | |
a955b5bb | 95 | } |
017ac23d | 96 | } |
be375bae | 97 | |
78492fde | 98 | if { "${asm-arch}" == "" } { |
9383332c | 99 | gdb_suppress_entire_file "Assembly source test -- not implemented for this target." |
c906108c SS |
100 | } |
101 | ||
0fcddd82 EZ |
102 | # Watch out, we are invoking the assembler, but the testsuite sets multilib |
103 | # switches according to compiler syntax. If we pass these options straight | |
104 | # to the assembler, they won't always make sense. If we don't pass them to | |
105 | # the assembler, the final link will complain that the object files were | |
106 | # built with different defaults. So no matter what we do, we lose. We may as | |
107 | # well get out of this test sooner rather than later. | |
108 | set dest [target_info name] | |
109 | if [board_info $dest exists multilib_flags] { | |
110 | set multilib_flags [board_info $dest multilib_flags] | |
111 | if { "${multilib_flags}" != "" } { | |
112 | gdb_suppress_entire_file "Assembly source test -- multilibs not supported by this test." | |
113 | return; | |
114 | } | |
115 | } | |
116 | ||
c906108c SS |
117 | set testfile "asm-source" |
118 | set binfile ${objdir}/${subdir}/${testfile} | |
f2dd3617 EZ |
119 | set srcfile1 asmsrc1.s |
120 | set srcfile2 asmsrc2.s | |
c906108c | 121 | |
a73a20a2 EZ |
122 | remote_exec build "rm -f ${subdir}/arch.inc" |
123 | remote_download host ${srcdir}/${subdir}/${asm-arch}.inc ${subdir}/arch.inc | |
16a8534a | 124 | |
78492fde AC |
125 | if { "${asm-flags}" == "" } { |
126 | #set asm-flags "-Wa,-gstabs,-I${srcdir}/${subdir},-I${objdir}/${subdir}" | |
127 | set asm-flags "-gstabs -I${srcdir}/${subdir} -I${objdir}/${subdir}" | |
128 | } | |
c906108c | 129 | |
f2dd3617 | 130 | if {[target_assemble ${srcdir}/${subdir}/${srcfile1} asmsrc1.o "${asm-flags}"] != ""} then { |
c906108c SS |
131 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
132 | } | |
f2dd3617 | 133 | if {[target_assemble ${srcdir}/${subdir}/${srcfile2} asmsrc2.o "${asm-flags}"] != ""} then { |
c906108c SS |
134 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
135 | } | |
136 | ||
cf599fa7 CV |
137 | set opts "debug ldflags=-nostartfiles" |
138 | foreach i ${link-flags} { | |
139 | append opts " ldflags=$i" | |
140 | } | |
141 | if { [gdb_compile "asmsrc1.o asmsrc2.o" "${binfile}" executable $opts] != "" } { | |
c906108c SS |
142 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
143 | } | |
144 | ||
145 | remote_exec build "mv asmsrc1.o asmsrc2.o ${objdir}/${subdir}" | |
146 | ||
147 | ||
148 | gdb_start | |
149 | gdb_reinitialize_dir $srcdir/$subdir | |
150 | gdb_load ${binfile} | |
151 | ||
152 | # | |
153 | # Run to `main' where we begin our tests. | |
154 | # | |
155 | ||
156 | if ![runto_main] then { | |
157 | gdb_suppress_tests | |
158 | } | |
159 | ||
160 | # Execute the `f' command and see if the result includes source info. | |
78492fde | 161 | gdb_test "f" "asmsrc1\[.\]s:29.*several_nops" "f at main" |
c906108c SS |
162 | |
163 | # See if we properly `next' over a macro with several insns. | |
78492fde | 164 | gdb_test "n" "33\[ \]*.*foo2" "next over macro" |
c906108c SS |
165 | |
166 | # See if we can properly `step' into a subroutine call. | |
167 | gdb_test "s" "8\[ \]*.*" "step into foo2" | |
168 | ||
edb6ede1 MS |
169 | # Test 'info target', and incidentally capture the entry point address. |
170 | set entry_point 0 | |
171 | send_gdb "info target\n" | |
172 | gdb_expect { | |
173 | -re "Symbols from .*asm-source.*Entry point: 0x(\[01232456789abcdefABCDEF\]+).*$gdb_prompt $" { | |
174 | set entry_point $expect_out(1,string) | |
175 | pass "info target" | |
176 | } | |
177 | -re ".*$gdb_prompt $" { | |
178 | fail "info target" | |
179 | } | |
180 | timeout { | |
181 | fail "info target (timeout)" | |
182 | } | |
183 | } | |
184 | ||
185 | # Capture the start symbol (may be '_start' or 'start') | |
186 | set entry_symbol "" | |
187 | send_gdb "info symbol 0x$entry_point\n" | |
188 | gdb_expect { | |
ecace851 JB |
189 | -re "info symbol 0x$entry_point\[\r\n\]+(\[^\r\n\]*) in section .*$gdb_prompt $" { |
190 | # We match the echoed `info symbol' command here, to help us | |
191 | # reliably identify the beginning of the start symbol in the | |
192 | # command's output. You might think we could just use '^' to | |
193 | # start matching at the beginning of the line, but | |
194 | # unfortunately, in Expect, '^' matches the beginning of the | |
195 | # input that hasn't been matched by any expect clause yet. If | |
196 | # every expect clause consumes a complete line, along with its | |
197 | # terminating CR/LF, this is equivalent to the beginning of a | |
198 | # line. But expect clauses that end with `.*' will consume as | |
199 | # much as happened to arrive from the TTY --- exactly where | |
200 | # they leave you depends on inter-process timing. :( | |
edb6ede1 MS |
201 | set entry_symbol $expect_out(1,string) |
202 | pass "info symbol" | |
203 | } | |
204 | -re ".*$gdb_prompt $" { | |
205 | fail "info symbol" | |
206 | } | |
207 | timeout { | |
208 | fail "info symbol (timeout)" | |
209 | } | |
210 | } | |
211 | ||
ca9efc90 | 212 | # Now try a 'list' from the other source file. |
edb6ede1 | 213 | gdb_test "list $entry_symbol" ".*gdbasm_startup.*" "list" |
ca9efc90 MS |
214 | |
215 | # Now try a source file search | |
216 | gdb_test "search A routine for foo2 to call" \ | |
8b1d7e37 | 217 | "40\[ \t\]+comment \"A routine for foo2 to call.\"" "search" |
ca9efc90 | 218 | |
c906108c SS |
219 | # See if `f' prints the right source file. |
220 | gdb_test "f" ".*asmsrc2\[.\]s:8.*" "f in foo2" | |
221 | ||
222 | # `next' one insn (or macro) to set up our stackframe (for the following bt). | |
223 | gdb_test "n" "12\[ \]*.*foo3" "n in foo2" | |
224 | ||
b5703437 MS |
225 | # See if a simple `bt' prints the right source files and |
226 | # doesn't fall off the stack. | |
227 | ||
228 | gdb_test "bt 10" \ | |
229 | "\#0.*foo2.*asmsrc2\[.\]s:12.*\#1.*main.*asmsrc1\[.\]s:33(.*\#2.*start\[^\r\n\]*)?" \ | |
230 | "bt ALL in foo2" | |
78492fde AC |
231 | |
232 | # See if a capped `bt' prints the right source files. | |
233 | gdb_test "bt 2" "\#0.*foo2.*asmsrc2\[.\]s:12.*\#1.*main.*asmsrc1\[.\]s:33.*" "bt 2 in foo2" | |
c906108c SS |
234 | |
235 | # Step into another subroutine which lives back in the first source file. | |
236 | gdb_test "s" "" "s 2" | |
237 | ||
238 | # Next over insns to set up the stack frame. | |
239 | gdb_test "n" "" "n 2" | |
240 | ||
78492fde | 241 | # Now see if a capped `bt' is correct. |
8b1d7e37 | 242 | 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 |
243 | |
244 | # Try 'info source' from asmsrc1.s | |
245 | gdb_test "info source" \ | |
246 | "Current source file is .*asmsrc1.s.*Source language is asm.*" \ | |
247 | "info source asmsrc1.s" | |
248 | ||
249 | # Try 'finishing' from foo3 | |
250 | gdb_test "finish" "Run till exit from.*\[\r\n\]13\[ \t\]+gdbasm_call foo3" \ | |
251 | "finish from foo3" | |
252 | ||
253 | # Try 'info source' from asmsrc2.s | |
254 | gdb_test "info source" \ | |
255 | "Current source file is .*asmsrc2.s.*Source language is asm.*" \ | |
256 | "info source asmsrc2.s" | |
257 | ||
27924826 JB |
258 | # Try 'info sources'. This can produce a lot of output on systems |
259 | # with dynamic linking, where the system's shared libc was compiled | |
260 | # with debugging info; for example, on Linux, this produces 47kb of | |
261 | # output. So we consume it as we go. | |
262 | send_gdb "info sources\n" | |
263 | set seen_asmsrc_1 0 | |
264 | set seen_asmsrc_2 0 | |
265 | gdb_expect { | |
266 | -re "^\[^,\]*asmsrc1.s(, |\[\r\n\]+)" { | |
267 | set seen_asmsrc_1 1 | |
268 | exp_continue | |
269 | } | |
270 | -re "^\[^,\]*asmsrc2.s(, |\[\r\n\]+)" { | |
271 | set seen_asmsrc_2 1 | |
272 | exp_continue | |
273 | } | |
274 | -re ", " { | |
275 | exp_continue | |
276 | } | |
277 | -re "$gdb_prompt $" { | |
278 | if {$seen_asmsrc_1 && $seen_asmsrc_2} { | |
279 | pass "info sources" | |
280 | } else { | |
281 | fail "info sources" | |
282 | } | |
283 | } | |
284 | timeout { | |
285 | fail "info sources (timeout)" | |
286 | } | |
287 | } | |
288 | ||
ca9efc90 MS |
289 | |
290 | # Try 'info line' | |
291 | gdb_test "info line" \ | |
292 | "Line 13 of.*asmsrc2.s.*starts at.*<foo2+.*> and ends at.*<foo2+.*>." \ | |
293 | "info line" | |
294 | ||
295 | # Try 'nexting' over next call to foo3 | |
296 | gdb_test "next" "17\[ \t\]+gdbasm_leave" "next over foo3" | |
297 | ||
298 | # Try 'return' from foo2 | |
299 | gdb_test "return" "\#0 main .*37\[ \t\]+gdbasm_exit0" "return from foo2" \ | |
8b1d7e37 | 300 | "Make (foo2|selected stack frame) return now\?.*" "y" |
ca9efc90 | 301 | |
2b6fd0d8 AC |
302 | # Disassemble something, check the output |
303 | proc test_dis { command var } { | |
304 | global gdb_prompt | |
305 | send_gdb "${command}\n" | |
306 | gdb_expect { | |
307 | -re "${var}.*:.*Cannot access" { | |
308 | # The "disassembler" was only accessing the local | |
309 | # executable and that would cause attempts to disassemble | |
310 | # variables to fail (memory not valid). | |
311 | fail "${command} (memory read error)" | |
312 | } | |
313 | -re "${var}.*:.*${gdb_prompt}" { | |
314 | pass "${command}" | |
315 | } | |
316 | timeout { | |
317 | fail "${command} (timeout)" | |
318 | } | |
319 | } | |
320 | } | |
321 | ||
322 | # See if we can look at a global variable, three ways | |
ca9efc90 | 323 | gdb_test "print globalvar" ".* = 11" "look at global variable" |
2b6fd0d8 AC |
324 | test_dis "x/i globalvar" "globalvar" |
325 | test_dis "disassem &globalvar &globalvar+1" "globalvar" | |
ca9efc90 | 326 | |
2b6fd0d8 | 327 | # See if we can look at a static variable, three ways |
ca9efc90 | 328 | gdb_test "print staticvar" ".* = 5" "look at static variable" |
2b6fd0d8 AC |
329 | test_dis "x/i &staticvar" "staticvar" |
330 | test_dis "disassem &staticvar &staticvar+1" "staticvar" | |
ca9efc90 MS |
331 | |
332 | # See if we can look at a static function | |
83c31e7d | 333 | gdb_test "disassem foostatic" ".*<foostatic\\+0>:.*End of assembler dump." \ |
ca9efc90 MS |
334 | "look at static function" |
335 | ||
a73a20a2 | 336 | remote_exec build "rm -f ${subdir}/arch.inc" |