1 # Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Please email any bugs, comments, and/or additions to this file to:
20 # This file is part of the gdb testsuite.
26 # Test i386 prologue analyzer.
29 if {(![istarget "x86_64-*-*"] && ![istarget "i?86-*-*"]) || ![is_ilp32_target] } then {
30 verbose "Skipping i386 prologue tests."
34 set testfile "i386-prologue"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 # some targets have leading underscores on assembly symbols.
39 # TODO: detect this automatically
40 set additional_flags ""
41 if { [istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"] } then {
42 set additional_flags "additional_flags=-DSYMBOL_PREFIX=\"_\""
45 # Don't use "debug", so that we don't have line information for the assembly
47 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
48 untested i386-prologue.exp
53 # The code used by the tests here encodes some breakpoints by using
54 # inline assembler. This will generate a SIGTRAP which will be caught
55 # by GDB. At that point the instruction pointer will point at the
56 # next instruction, and execution can continue without any problems.
57 # Some systems however (QNX Neutrino, Solaris) will adjust the
58 # instruction pointer to point at the breakpoint instruction instead.
59 # On these systems we cannot continue unless we skip it. This
60 # procedure takes care of that.
62 proc skip_breakpoint { msg } {
63 gdb_test "if (*(unsigned char *)\$pc == 0xcc)\nset \$pc = \$pc + 1\nend" \
64 "" "skip breakpoint in ${msg}"
70 gdb_reinitialize_dir $srcdir/$subdir
74 # Run to `main' where we begin our tests.
77 if ![runto_main] then {
81 # Testcase for standard prologue.
83 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to standard"
85 skip_breakpoint standard
87 gdb_test "backtrace 10" \
88 "#0\[ \t\]*$hex in standard.*\r\n#1\[ \t\]*$hex in main.*" \
89 "backtrace in standard"
91 gdb_test "info frame" \
92 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
93 "saved registers in standard"
96 # Testcase from breakpoints/2080 (when %ecx is used)
98 gdb_test "break *(stack_align_ecx + 7)" \
99 "Breakpoint \[0-9\]* at $hex"
101 gdb_test "continue" \
102 "Breakpoint \[0-9\]*.*stack_align_ecx.*" \
103 "continue to stack_align_ecx + 7"
105 gdb_test "backtrace 10" \
106 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
107 "first backtrace in stack_align_ecx"
109 gdb_test "continue" \
110 "Program received signal SIGTRAP.*" \
111 "continue in stack_align_ecx"
113 skip_breakpoint stack_align_ecx
115 gdb_test "backtrace 10" \
116 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
117 "second backtrace in stack_align_ecx"
119 gdb_test "info frame" \
120 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
121 "saved registers in stack_align_ecx"
124 # Testcase from breakpoints/2080 (when %edx is used)
126 gdb_test "break *(stack_align_edx + 7)" \
127 "Breakpoint \[0-9\]* at $hex"
129 gdb_test "continue" \
130 "Breakpoint \[0-9\]*.*stack_align_edx.*" \
131 "continue to stack_align_edx + 7"
133 gdb_test "backtrace 10" \
134 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
135 "first backtrace in stack_align_edx"
137 gdb_test "continue" \
138 "Program received signal SIGTRAP.*" \
139 "continue in stack_align_edx"
141 skip_breakpoint stack_align_edx
143 gdb_test "backtrace 10" \
144 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
145 "second backtrace in stack_align_edx"
147 gdb_test "info frame" \
148 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
149 "saved registers in stack_align_edx"
152 # Testcase from breakpoints/2080 (when %eax is used)
154 gdb_test "break *(stack_align_eax + 7)" \
155 "Breakpoint \[0-9\]* at $hex"
157 gdb_test "continue" \
158 "Breakpoint \[0-9\]*.*stack_align_eax.*" \
159 "continue to stack_align_eax + 7"
161 gdb_test "backtrace 10" \
162 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
163 "first backtrace in stack_align_eax"
165 gdb_test "continue" \
166 "Program received signal SIGTRAP.*" \
167 "continue in stack_align_eax"
169 skip_breakpoint stack_align_eax
171 gdb_test "backtrace 10" \
172 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
173 "second backtrace in stack_align_eax"
175 gdb_test "info frame" \
176 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
177 "saved registers in stack_align_eax"
180 # Testcase from symtab/1253.
182 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1253"
184 skip_breakpoint gdb1253
186 gdb_test "backtrace 10" \
187 "#0\[ \t\]*$hex in gdb1253.*\r\n#1\[ \t\]*$hex in main.*" \
188 "backtrace in gdb1253"
190 gdb_test "info frame" \
191 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
192 "saved registers in gdb1253"
195 # Testcase from backtrace/1718.
197 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1718"
199 skip_breakpoint gdb1718
201 gdb_test "backtrace 10" \
202 "#0\[ \t\]*$hex in gdb1718.*\r\n#1\[ \t\]*$hex in main.*" \
203 "backtrace in gdb1718"
205 setup_kfail gdb/1718 *-*-*
206 gdb_test "info frame" \
207 ".*Saved registers:.*esi at.*ebx at.*eip at.*" \
208 "saved registers in gdb1718"
211 # Testcase from backtrace/1338.
213 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1338"
215 skip_breakpoint gdb1338
217 gdb_test "backtrace 10" \
218 "#0\[ \t\]*$hex in gdb1338.*\r\n#1\[ \t\]*$hex in main.*" \
219 "backtrace in gdb1338"
221 gdb_test "info frame" \
222 ".*Saved registers:.*ebx at.*esi at.*edi at.*eip at.*" \
223 "saved registers in gdb1338"
225 # Testcase jump_at_beginning.
226 gdb_test_multiple "break jump_at_beginning" \
227 "set breakpoint in jump_at_beginning" {
228 -re "Breakpoint \[0-9\]* at ($hex).*$gdb_prompt $" {
229 gdb_test "x/i $expect_out(1,string)" \
230 ".*<jump_at_beginning.*>:.*jmp.*" \
231 "check jump_at_beginning prologue end"
234 fail "set breakpoint in jump_at_beginning"