1 # Copyright (C) 2003-2024 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.
21 # Test i386 prologue analyzer.
24 require is_x86_like_target
26 set testfile "i386-prologue"
27 set srcfile ${testfile}.c
28 set binfile [standard_output_file ${testfile}]
30 # some targets have leading underscores on assembly symbols.
31 set additional_flags [gdb_target_symbol_prefix_flags]
33 # Don't use "debug", so that we don't have line information for the assembly
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
36 untested "failed to compile"
41 # The code used by the tests here encodes some breakpoints by using
42 # inline assembler. This will generate a SIGTRAP which will be caught
43 # by GDB. At that point the instruction pointer will point at the
44 # next instruction, and execution can continue without any problems.
45 # Some systems however (QNX Neutrino, Solaris) will adjust the
46 # instruction pointer to point at the breakpoint instruction instead.
47 # On these systems we cannot continue unless we skip it. This
48 # procedure takes care of that.
50 proc skip_breakpoint { msg } {
51 gdb_test "if (*(unsigned char *)\$pc == 0xcc)\nset \$pc = \$pc + 1\nend" \
52 "" "skip breakpoint in ${msg}"
56 clean_restart $binfile
59 # Run to `main' where we begin our tests.
66 # Testcase for standard prologue.
68 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to standard"
70 skip_breakpoint standard
72 gdb_test "backtrace 10" \
73 "#0\[ \t\]*$hex in standard.*\r\n#1\[ \t\]*$hex in main.*" \
74 "backtrace in standard"
76 gdb_test "info frame" \
77 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
78 "saved registers in standard"
81 # Testcase from breakpoints/2080 (when %ecx is used)
83 gdb_test "break *(stack_align_ecx + 7)" \
84 "Breakpoint \[0-9\]* at $hex"
87 "Breakpoint \[0-9\]*.*stack_align_ecx.*" \
88 "continue to stack_align_ecx + 7"
90 gdb_test "backtrace 10" \
91 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
92 "first backtrace in stack_align_ecx"
95 "Program received signal SIGTRAP.*" \
96 "continue in stack_align_ecx"
98 skip_breakpoint stack_align_ecx
100 gdb_test "backtrace 10" \
101 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
102 "second backtrace in stack_align_ecx"
104 gdb_test "info frame" \
105 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
106 "saved registers in stack_align_ecx"
109 # Testcase from breakpoints/2080 (when %edx is used)
111 gdb_test "break *(stack_align_edx + 7)" \
112 "Breakpoint \[0-9\]* at $hex"
114 gdb_test "continue" \
115 "Breakpoint \[0-9\]*.*stack_align_edx.*" \
116 "continue to stack_align_edx + 7"
118 gdb_test "backtrace 10" \
119 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
120 "first backtrace in stack_align_edx"
122 gdb_test "continue" \
123 "Program received signal SIGTRAP.*" \
124 "continue in stack_align_edx"
126 skip_breakpoint stack_align_edx
128 gdb_test "backtrace 10" \
129 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
130 "second backtrace in stack_align_edx"
132 gdb_test "info frame" \
133 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
134 "saved registers in stack_align_edx"
137 # Testcase from breakpoints/2080 (when %eax is used)
139 gdb_test "break *(stack_align_eax + 7)" \
140 "Breakpoint \[0-9\]* at $hex"
142 gdb_test "continue" \
143 "Breakpoint \[0-9\]*.*stack_align_eax.*" \
144 "continue to stack_align_eax + 7"
146 gdb_test "backtrace 10" \
147 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
148 "first backtrace in stack_align_eax"
150 gdb_test "continue" \
151 "Program received signal SIGTRAP.*" \
152 "continue in stack_align_eax"
154 skip_breakpoint stack_align_eax
156 gdb_test "backtrace 10" \
157 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
158 "second backtrace in stack_align_eax"
160 gdb_test "info frame" \
161 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
162 "saved registers in stack_align_eax"
165 # Testcase from symtab/1253.
167 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1253"
169 skip_breakpoint gdb1253
171 gdb_test "backtrace 10" \
172 "#0\[ \t\]*$hex in gdb1253.*\r\n#1\[ \t\]*$hex in main.*" \
173 "backtrace in gdb1253"
175 gdb_test "info frame" \
176 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
177 "saved registers in gdb1253"
180 # Testcase from backtrace/1718.
182 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1718"
184 skip_breakpoint gdb1718
186 gdb_test "backtrace 10" \
187 "#0\[ \t\]*$hex in gdb1718.*\r\n#1\[ \t\]*$hex in main.*" \
188 "backtrace in gdb1718"
190 setup_kfail gdb/1718 *-*-*
191 gdb_test "info frame" \
192 ".*Saved registers:.*esi at.*ebx at.*eip at.*" \
193 "saved registers in gdb1718"
196 # Testcase from backtrace/1338.
198 gdb_test "continue" "Program received signal SIGTRAP.*" "continue to gdb1338"
200 skip_breakpoint gdb1338
202 gdb_test "backtrace 10" \
203 "#0\[ \t\]*$hex in gdb1338.*\r\n#1\[ \t\]*$hex in main.*" \
204 "backtrace in gdb1338"
206 gdb_test "info frame" \
207 ".*Saved registers:.*ebx at.*esi at.*edi at.*eip at.*" \
208 "saved registers in gdb1338"
210 # Testcase jump_at_beginning.
211 gdb_test_multiple "break jump_at_beginning" \
212 "set breakpoint in jump_at_beginning" {
213 -re "Breakpoint \[0-9\]* at ($hex).*$gdb_prompt $" {
214 gdb_test "x/i $expect_out(1,string)" \
215 ".*<jump_at_beginning.*>:.*jmp.*" \
216 "check jump_at_beginning prologue end"
219 fail "set breakpoint in jump_at_beginning"