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