1 # Copyright
2023-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 # Test amd64 displaced stepping over a
call instruction that calls to
17 # itself. This is pretty unlikely to be seen in the wild
, but does
18 # test a corner case of our displaced step handling.
20 require is_x86_64_m64_target
22 set newline
"\[\r\n\]*"
24 set opts
{debug nopie
}
25 standard_testfile .S
-alarm.c
27 if { [prepare_for_testing
"failed to prepare" $testfile "$srcfile $srcfile2" $opts] } {
31 gdb_test
"set displaced-stepping on" ""
32 gdb_test
"show displaced-stepping" ".* displaced stepping .* is on.*"
38 # Proceed to the test function.
39 gdb_breakpoint
"test_call"
40 gdb_continue_to_breakpoint
"test_call"
42 #
Get the current stack pointer value.
43 set sp
[get_hexadecimal_valueof
"\$sp" "*UNKNOWN*"]
45 #
Get the address of the next instruction.
47 gdb_test_multiple
"x/2i \$pc" "get address of next insn" {
48 -re
"\r\n=> $hex \[^\r\n\]+\r\n" {
51 -re
"^ ($hex) \[^\r\n\]+\r\n" {
52 set next_insn_addr $expect_out
(1,string
)
55 -re
"^$::gdb_prompt $" {
56 gdb_assert
{![string equal $next_insn_addr
""]} \
61 # Clear the slot
on the stack and confirm it was
set to zero.
62 set sp
[expr $sp
- 0x8]
63 gdb_test_no_output
"set {unsigned long long} $sp = 0" \
65 set zero_val
0x
[format
%016x
0]
66 gdb_test
"x/1gx 0x[format %x $sp]" "$hex:\\s+${zero_val}" \
67 "check return address slot was set to zero"
71 "Breakpoint $decimal, test_call \\(\\) at .*"
73 # Check stack pointer was updated to the expected value.
74 set new_sp
[get_hexadecimal_valueof
"\$sp" "*UNKNOWN*" \
75 "get stack pointer after step"]
76 gdb_assert
{[expr $sp
== $new_sp
]} \
77 "check stack pointer was updated as expected"
79 # Check the contents of the stack were updated to the expected value.
80 set next_insn_addr
0x
[format
%016x $next_insn_addr
]
81 gdb_test
"x/1gx 0x[format %x $sp]" "$hex:\\s+$next_insn_addr" \
82 "check return address was updated correctly"