1 # Copyright
(C
) 2003-2019 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 if { ![is_x86_like_target
] } then {
25 verbose
"Skipping i386 prologue tests."
29 set testfile
"i386-prologue"
30 set srcfile $
{testfile
}.c
31 set binfile
[standard_output_file $
{testfile
}]
33 # some targets have leading underscores
on assembly symbols.
34 set additional_flags
[gdb_target_symbol_prefix_flags
]
36 # Don
't use "debug", so that we don't have line information
for the assembly
38 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
39 untested
"failed to compile"
44 # The code used by the tests here encodes some breakpoints by using
45 # inline assembler. This will generate a SIGTRAP which will be caught
46 # by GDB. At that point the instruction pointer will point at the
47 # next instruction
, and execution can
continue without
any problems.
48 # Some systems however
(QNX Neutrino
, Solaris
) will adjust the
49 # instruction pointer to point at the breakpoint instruction instead.
50 #
On these systems we cannot
continue unless we skip it. This
51 # procedure takes care of that.
53 proc skip_breakpoint
{ msg
} {
54 gdb_test
"if (*(unsigned char *)\$pc == 0xcc)\nset \$pc = \$pc + 1\nend" \
55 "" "skip breakpoint in ${msg}"
61 gdb_reinitialize_dir $srcdir
/$subdir
65 # Run to `main
' where we begin our tests.
68 if ![runto_main] then {
69 fail "can't run to main
"
73 # Testcase
for standard prologue.
75 gdb_test
"continue" "Program received signal SIGTRAP.*" "continue to standard"
77 skip_breakpoint standard
79 gdb_test
"backtrace 10" \
80 "#0\[ \t\]*$hex in standard.*\r\n#1\[ \t\]*$hex in main.*" \
81 "backtrace in standard"
83 gdb_test
"info frame" \
84 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
85 "saved registers in standard"
88 # Testcase from breakpoints
/2080 (when
%ecx is used
)
90 gdb_test
"break *(stack_align_ecx + 7)" \
91 "Breakpoint \[0-9\]* at $hex"
94 "Breakpoint \[0-9\]*.*stack_align_ecx.*" \
95 "continue to stack_align_ecx + 7"
97 gdb_test
"backtrace 10" \
98 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
99 "first backtrace in stack_align_ecx"
101 gdb_test
"continue" \
102 "Program received signal SIGTRAP.*" \
103 "continue in stack_align_ecx"
105 skip_breakpoint stack_align_ecx
107 gdb_test
"backtrace 10" \
108 "#0\[ \t\]*$hex in stack_align_ecx.*\r\n#1\[ \t\]*$hex in main.*" \
109 "second backtrace in stack_align_ecx"
111 gdb_test
"info frame" \
112 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
113 "saved registers in stack_align_ecx"
116 # Testcase from breakpoints
/2080 (when
%edx is used
)
118 gdb_test
"break *(stack_align_edx + 7)" \
119 "Breakpoint \[0-9\]* at $hex"
121 gdb_test
"continue" \
122 "Breakpoint \[0-9\]*.*stack_align_edx.*" \
123 "continue to stack_align_edx + 7"
125 gdb_test
"backtrace 10" \
126 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
127 "first backtrace in stack_align_edx"
129 gdb_test
"continue" \
130 "Program received signal SIGTRAP.*" \
131 "continue in stack_align_edx"
133 skip_breakpoint stack_align_edx
135 gdb_test
"backtrace 10" \
136 "#0\[ \t\]*$hex in stack_align_edx.*\r\n#1\[ \t\]*$hex in main.*" \
137 "second backtrace in stack_align_edx"
139 gdb_test
"info frame" \
140 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
141 "saved registers in stack_align_edx"
144 # Testcase from breakpoints
/2080 (when
%eax is used
)
146 gdb_test
"break *(stack_align_eax + 7)" \
147 "Breakpoint \[0-9\]* at $hex"
149 gdb_test
"continue" \
150 "Breakpoint \[0-9\]*.*stack_align_eax.*" \
151 "continue to stack_align_eax + 7"
153 gdb_test
"backtrace 10" \
154 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
155 "first backtrace in stack_align_eax"
157 gdb_test
"continue" \
158 "Program received signal SIGTRAP.*" \
159 "continue in stack_align_eax"
161 skip_breakpoint stack_align_eax
163 gdb_test
"backtrace 10" \
164 "#0\[ \t\]*$hex in stack_align_eax.*\r\n#1\[ \t\]*$hex in main.*" \
165 "second backtrace in stack_align_eax"
167 gdb_test
"info frame" \
168 ".*Saved registers:.*ecx at.*ebp at.*edi at.*eip at.*" \
169 "saved registers in stack_align_eax"
172 # Testcase from symtab
/1253.
174 gdb_test
"continue" "Program received signal SIGTRAP.*" "continue to gdb1253"
176 skip_breakpoint gdb1253
178 gdb_test
"backtrace 10" \
179 "#0\[ \t\]*$hex in gdb1253.*\r\n#1\[ \t\]*$hex in main.*" \
180 "backtrace in gdb1253"
182 gdb_test
"info frame" \
183 ".*Saved registers:.*ebp at.*edi at.*eip at.*" \
184 "saved registers in gdb1253"
187 # Testcase from backtrace
/1718.
189 gdb_test
"continue" "Program received signal SIGTRAP.*" "continue to gdb1718"
191 skip_breakpoint gdb1718
193 gdb_test
"backtrace 10" \
194 "#0\[ \t\]*$hex in gdb1718.*\r\n#1\[ \t\]*$hex in main.*" \
195 "backtrace in gdb1718"
197 setup_kfail gdb
/1718 *-*-*
198 gdb_test
"info frame" \
199 ".*Saved registers:.*esi at.*ebx at.*eip at.*" \
200 "saved registers in gdb1718"
203 # Testcase from backtrace
/1338.
205 gdb_test
"continue" "Program received signal SIGTRAP.*" "continue to gdb1338"
207 skip_breakpoint gdb1338
209 gdb_test
"backtrace 10" \
210 "#0\[ \t\]*$hex in gdb1338.*\r\n#1\[ \t\]*$hex in main.*" \
211 "backtrace in gdb1338"
213 gdb_test
"info frame" \
214 ".*Saved registers:.*ebx at.*esi at.*edi at.*eip at.*" \
215 "saved registers in gdb1338"
217 # Testcase jump_at_beginning.
218 gdb_test_multiple
"break jump_at_beginning" \
219 "set breakpoint in jump_at_beginning" {
220 -re
"Breakpoint \[0-9\]* at ($hex).*$gdb_prompt $" {
221 gdb_test
"x/i $expect_out(1,string)" \
222 ".*<jump_at_beginning.*>:.*jmp.*" \
223 "check jump_at_beginning prologue end"
226 fail
"set breakpoint in jump_at_beginning"