1 # Copyright (C) 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Please email any bugs, comments, and/or additions to this file to:
19 # This file is part of the gdb testsuite.
25 # Test i386 prologue analyzer.
30 if ![istarget "i?86-*-*"] then {
31 verbose "Skipping i386 prologue tests."
35 set testfile "i386-prologue"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 # some targets have leading underscores on assembly symbols.
40 # TODO: detect this automatically
41 set additional_flags ""
42 if [istarget "i?86-*-cygwin*"] then {
43 set additional_flags "additional_flags=-DSYMBOL_PREFIX=\"_\""
46 # Don't use "debug", so that we don't have line information for the assembly
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
49 untested i386-prologue.exp
54 # The code used by the tests here encodes some breakpoints by using
55 # inline assembler. This will generate a SIGTRAP which will be caught
56 # by GDB. At that point the instruction pointer will point at the
57 # next instruction, and execution can continue without any problems.
58 # Some systems however (QNX Neutrino, Solaris) will adjust the
59 # instruction pointer to point at the breakpoint instruction instead.
60 # On these systems we cannot continue unless we skip it. This
61 # procedure takes care of that.
63 proc skip_breakpoint { msg } {
64 gdb_test "if (*(unsigned char *)\$pc == 0xcc)\nset \$pc = \$pc + 1\nend" \
65 "" "skip breakpoint in ${msg}"
71 gdb_reinitialize_dir $srcdir/$subdir
75 # Run to `main' where we begin our tests.
78 if ![runto_main] then {
82 # Testcase for standard prologue.
84 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to standard"
86 skip_breakpoint standard
88 gdb_test "backtrace 10" \
89 "#0\[ \t\]*$hex in standard.*\r\n#1\[ \t\]*$hex in main.*" \
90 "backtrace in standard"
92 gdb_test "info frame" \
93 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
94 "saved registers in standard"
97 # Testcase from breakpoints/2080 (when %ecx is used)
99 gdb_test "break *(stack_align_ecx + 7)" \
100 "Breakpoint \[0-9\]* at $hex"
102 gdb_test "continue" \
103 "Breakpoint \[0-9\]*.*stack_align_ecx.*" \
104 "continue to stack_align_ecx + 7"
106 gdb_test "backtrace 10" \
107 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
108 "first backtrace in stack_align_ecx"
110 gdb_test "continue" \
111 "Program received signal SIGTRAP.*" \
112 "continue in stack_align_ecx"
114 skip_breakpoint stack_align_ecx
116 gdb_test "backtrace 10" \
117 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
118 "second backtrace in stack_align_ecx"
120 gdb_test "info frame" \
121 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
122 "saved registers in stack_align_ecx"
125 # Testcase from breakpoints/2080 (when %edx is used)
127 gdb_test "break *(stack_align_edx + 7)" \
128 "Breakpoint \[0-9\]* at $hex"
130 gdb_test "continue" \
131 "Breakpoint \[0-9\]*.*stack_align_edx.*" \
132 "continue to stack_align_edx + 7"
134 gdb_test "backtrace 10" \
135 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
136 "first backtrace in stack_align_edx"
138 gdb_test "continue" \
139 "Program received signal SIGTRAP.*" \
140 "continue in stack_align_edx"
142 skip_breakpoint stack_align_edx
144 gdb_test "backtrace 10" \
145 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
146 "second backtrace in stack_align_edx"
148 gdb_test "info frame" \
149 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
150 "saved registers in stack_align_edx"
153 # Testcase from breakpoints/2080 (when %eax is used)
155 gdb_test "break *(stack_align_eax + 7)" \
156 "Breakpoint \[0-9\]* at $hex"
158 gdb_test "continue" \
159 "Breakpoint \[0-9\]*.*stack_align_eax.*" \
160 "continue to stack_align_eax + 7"
162 gdb_test "backtrace 10" \
163 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
164 "first backtrace in stack_align_eax"
166 gdb_test "continue" \
167 "Program received signal SIGTRAP.*" \
168 "continue in stack_align_eax"
170 skip_breakpoint stack_align_eax
172 gdb_test "backtrace 10" \
173 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
174 "second backtrace in stack_align_eax"
176 gdb_test "info frame" \
177 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
178 "saved registers in stack_align_eax"
181 # Testcase from symtab/1253.
183 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1253"
185 skip_breakpoint gdb1253
187 gdb_test "backtrace 10" \
188 "#0\[ \t\]*$hex in gdb1253.*\r\n#1\[ \t\]*$hex in main.*" \
189 "backtrace in gdb1253"
191 gdb_test "info frame" \
192 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
193 "saved registers in gdb1253"
196 # Testcase from backtrace/1718.
198 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1718"
200 skip_breakpoint gdb1718
202 gdb_test "backtrace 10" \
203 "#0\[ \t\]*$hex in gdb1718.*\r\n#1\[ \t\]*$hex in main.*" \
204 "backtrace in gdb1718"
206 setup_kfail *-*-* gdb/1718
207 gdb_test "info frame" \
208 ".*Saved registers:.*esi at.*ebx at.*eip at.*" \
209 "saved registers in gdb1718"
212 # Testcase from backtrace/1338.
214 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1338"
216 skip_breakpoint gdb1338
218 gdb_test "backtrace 10" \
219 "#0\[ \t\]*$hex in gdb1338.*\r\n#1\[ \t\]*$hex in main.*" \
220 "backtrace in gdb1338"
222 gdb_test "info frame" \
223 ".*Saved registers:.*ebx at.*esi at.*edi at.*eip at.*" \
224 "saved registers in gdb1338"
226 # Testcase jump_at_beginning.
227 gdb_test_multiple "break jump_at_beginning" \
228 "set breakpoint in jump_at_beginning" {
229 -re "Breakpoint \[0-9\]* at ($hex).*$gdb_prompt $" {
230 gdb_test "x/i $expect_out(1,string)" \
231 ".*<jump_at_beginning.*>:.*jmp.*" \
232 "check jump_at_beginning prologue end"
235 fail "set breakpoint in jump_at_beginning"