Add support to GDB for the Renesas rl78 architecture.
[external/binutils.git] / gdb / testsuite / gdb.arch / i386-prologue.exp
1 # Copyright (C) 2003-2004, 2006-2012 Free Software Foundation, Inc.
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
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@gnu.org
18
19 # This file is part of the gdb testsuite.
20
21 # Test i386 prologue analyzer.
22
23
24 if {(![istarget "x86_64-*-*"] && ![istarget "i?86-*-*"]) || ![is_ilp32_target] } then {
25     verbose "Skipping i386 prologue tests."
26     return
27 }
28
29 set testfile "i386-prologue"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32
33 # some targets have leading underscores on assembly symbols.
34 set additional_flags [gdb_target_symbol_prefix_flags]
35
36 # Don't use "debug", so that we don't have line information for the assembly
37 # fragments.
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
39     untested i386-prologue.exp
40     return -1
41 }
42
43
44 # The code used by the tests here encodes some breakpoints by using
45 # inline assembler.  This will generate a SIGTRAP which will be caught
46 # by GDB.  At that point the instruction pointer will point at the
47 # next instruction, and execution can continue without any problems.
48 # Some systems however (QNX Neutrino, Solaris) will adjust the
49 # instruction pointer to point at the breakpoint instruction instead.
50 # On these systems we cannot continue unless we skip it.  This
51 # procedure takes care of that.
52
53 proc skip_breakpoint { msg } {
54     gdb_test "if (*(unsigned char *)\$pc == 0xcc)\nset \$pc = \$pc + 1\nend" \
55             "" "skip breakpoint in ${msg}"
56 }
57
58
59 gdb_exit
60 gdb_start
61 gdb_reinitialize_dir $srcdir/$subdir
62 gdb_load ${binfile}
63
64 #
65 # Run to `main' where we begin our tests.
66 #
67
68 if ![runto_main] then {
69     gdb_suppress_tests
70 }
71
72 # Testcase for standard prologue.
73
74 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to standard"
75
76 skip_breakpoint standard
77
78 gdb_test "backtrace 10" \
79         "#0\[ \t\]*$hex in standard.*\r\n#1\[ \t\]*$hex in main.*" \
80         "backtrace in standard"
81
82 gdb_test "info frame" \
83         ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
84         "saved registers in standard"
85
86
87 # Testcase from breakpoints/2080 (when %ecx is used)
88
89 gdb_test "break *(stack_align_ecx + 7)" \
90         "Breakpoint \[0-9\]* at $hex"
91
92 gdb_test "continue" \
93         "Breakpoint \[0-9\]*.*stack_align_ecx.*" \
94         "continue to stack_align_ecx + 7"
95
96 gdb_test "backtrace 10" \
97         "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
98         "first backtrace in stack_align_ecx"
99
100 gdb_test "continue" \
101         "Program received signal SIGTRAP.*" \
102         "continue in stack_align_ecx"
103
104 skip_breakpoint stack_align_ecx
105
106 gdb_test "backtrace 10" \
107         "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
108         "second backtrace in stack_align_ecx"
109
110 gdb_test "info frame" \
111         ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
112         "saved registers in stack_align_ecx"
113
114
115 # Testcase from breakpoints/2080 (when %edx is used)
116
117 gdb_test "break *(stack_align_edx + 7)" \
118         "Breakpoint \[0-9\]* at $hex"
119
120 gdb_test "continue" \
121         "Breakpoint \[0-9\]*.*stack_align_edx.*" \
122         "continue to stack_align_edx + 7"
123
124 gdb_test "backtrace 10" \
125         "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
126         "first backtrace in stack_align_edx"
127
128 gdb_test "continue" \
129         "Program received signal SIGTRAP.*" \
130         "continue in stack_align_edx"
131
132 skip_breakpoint stack_align_edx
133
134 gdb_test "backtrace 10" \
135         "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
136         "second backtrace in stack_align_edx"
137
138 gdb_test "info frame" \
139         ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
140         "saved registers in stack_align_edx"
141
142
143 # Testcase from breakpoints/2080 (when %eax is used)
144
145 gdb_test "break *(stack_align_eax + 7)" \
146         "Breakpoint \[0-9\]* at $hex"
147
148 gdb_test "continue" \
149         "Breakpoint \[0-9\]*.*stack_align_eax.*" \
150         "continue to stack_align_eax + 7"
151
152 gdb_test "backtrace 10" \
153         "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
154         "first backtrace in stack_align_eax"
155
156 gdb_test "continue" \
157         "Program received signal SIGTRAP.*" \
158         "continue in stack_align_eax"
159
160 skip_breakpoint stack_align_eax
161
162 gdb_test "backtrace 10" \
163         "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
164         "second backtrace in stack_align_eax"
165
166 gdb_test "info frame" \
167         ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
168         "saved registers in stack_align_eax"
169
170
171 # Testcase from symtab/1253.
172
173 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1253"
174
175 skip_breakpoint gdb1253
176
177 gdb_test "backtrace 10" \
178         "#0\[ \t\]*$hex in gdb1253.*\r\n#1\[ \t\]*$hex in main.*" \
179         "backtrace in gdb1253"
180
181 gdb_test "info frame" \
182         ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
183         "saved registers in gdb1253"
184
185
186 # Testcase from backtrace/1718.
187
188 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1718"
189
190 skip_breakpoint gdb1718
191
192 gdb_test "backtrace 10" \
193         "#0\[ \t\]*$hex in gdb1718.*\r\n#1\[ \t\]*$hex in main.*" \
194         "backtrace in gdb1718"
195
196 setup_kfail gdb/1718 *-*-*
197 gdb_test "info frame" \
198         ".*Saved registers:.*esi at.*ebx at.*eip at.*" \
199         "saved registers in gdb1718"
200
201
202 # Testcase from backtrace/1338.
203
204 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1338"
205
206 skip_breakpoint gdb1338
207
208 gdb_test "backtrace 10" \
209         "#0\[ \t\]*$hex in gdb1338.*\r\n#1\[ \t\]*$hex in main.*" \
210         "backtrace in gdb1338"
211
212 gdb_test "info frame" \
213         ".*Saved registers:.*ebx at.*esi at.*edi at.*eip at.*" \
214         "saved registers in gdb1338"
215
216 # Testcase jump_at_beginning.
217 gdb_test_multiple "break jump_at_beginning" \
218         "set breakpoint in jump_at_beginning" {
219     -re "Breakpoint \[0-9\]* at ($hex).*$gdb_prompt $" {
220         gdb_test "x/i $expect_out(1,string)" \
221                 ".*<jump_at_beginning.*>:.*jmp.*" \
222                 "check jump_at_beginning prologue end"
223     }
224     default {
225         fail "set breakpoint in jump_at_beginning"
226     }
227 }