1 # Copyright (C) 2003-2004, 2006-2012 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.
28 if {(![istarget "x86_64-*-*"] && ![istarget "i?86-*-*"]) || ![is_ilp32_target] } then {
29 verbose "Skipping i386 prologue tests."
33 set testfile "i386-prologue"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 # some targets have leading underscores on assembly symbols.
38 set additional_flags [gdb_target_symbol_prefix_flags]
40 # Don't use "debug", so that we don't have line information for the assembly
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
43 untested i386-prologue.exp
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.
57 proc skip_breakpoint { msg } {
58 gdb_test "if (*(unsigned char *)\$pc == 0xcc)\nset \$pc = \$pc + 1\nend" \
59 "" "skip breakpoint in ${msg}"
65 gdb_reinitialize_dir $srcdir/$subdir
69 # Run to `main' where we begin our tests.
72 if ![runto_main] then {
76 # Testcase for standard prologue.
78 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to standard"
80 skip_breakpoint standard
82 gdb_test "backtrace 10" \
83 "#0\[ \t\]*$hex in standard.*\r\n#1\[ \t\]*$hex in main.*" \
84 "backtrace in standard"
86 gdb_test "info frame" \
87 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
88 "saved registers in standard"
91 # Testcase from breakpoints/2080 (when %ecx is used)
93 gdb_test "break *(stack_align_ecx + 7)" \
94 "Breakpoint \[0-9\]* at $hex"
97 "Breakpoint \[0-9\]*.*stack_align_ecx.*" \
98 "continue to stack_align_ecx + 7"
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"
104 gdb_test "continue" \
105 "Program received signal SIGTRAP.*" \
106 "continue in stack_align_ecx"
108 skip_breakpoint stack_align_ecx
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"
114 gdb_test "info frame" \
115 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
116 "saved registers in stack_align_ecx"
119 # Testcase from breakpoints/2080 (when %edx is used)
121 gdb_test "break *(stack_align_edx + 7)" \
122 "Breakpoint \[0-9\]* at $hex"
124 gdb_test "continue" \
125 "Breakpoint \[0-9\]*.*stack_align_edx.*" \
126 "continue to stack_align_edx + 7"
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"
132 gdb_test "continue" \
133 "Program received signal SIGTRAP.*" \
134 "continue in stack_align_edx"
136 skip_breakpoint stack_align_edx
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"
142 gdb_test "info frame" \
143 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
144 "saved registers in stack_align_edx"
147 # Testcase from breakpoints/2080 (when %eax is used)
149 gdb_test "break *(stack_align_eax + 7)" \
150 "Breakpoint \[0-9\]* at $hex"
152 gdb_test "continue" \
153 "Breakpoint \[0-9\]*.*stack_align_eax.*" \
154 "continue to stack_align_eax + 7"
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"
160 gdb_test "continue" \
161 "Program received signal SIGTRAP.*" \
162 "continue in stack_align_eax"
164 skip_breakpoint stack_align_eax
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"
170 gdb_test "info frame" \
171 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
172 "saved registers in stack_align_eax"
175 # Testcase from symtab/1253.
177 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1253"
179 skip_breakpoint gdb1253
181 gdb_test "backtrace 10" \
182 "#0\[ \t\]*$hex in gdb1253.*\r\n#1\[ \t\]*$hex in main.*" \
183 "backtrace in gdb1253"
185 gdb_test "info frame" \
186 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
187 "saved registers in gdb1253"
190 # Testcase from backtrace/1718.
192 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1718"
194 skip_breakpoint gdb1718
196 gdb_test "backtrace 10" \
197 "#0\[ \t\]*$hex in gdb1718.*\r\n#1\[ \t\]*$hex in main.*" \
198 "backtrace in gdb1718"
200 setup_kfail gdb/1718 *-*-*
201 gdb_test "info frame" \
202 ".*Saved registers:.*esi at.*ebx at.*eip at.*" \
203 "saved registers in gdb1718"
206 # Testcase from backtrace/1338.
208 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1338"
210 skip_breakpoint gdb1338
212 gdb_test "backtrace 10" \
213 "#0\[ \t\]*$hex in gdb1338.*\r\n#1\[ \t\]*$hex in main.*" \
214 "backtrace in gdb1338"
216 gdb_test "info frame" \
217 ".*Saved registers:.*ebx at.*esi at.*edi at.*eip at.*" \
218 "saved registers in gdb1338"
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"
229 fail "set breakpoint in jump_at_beginning"