1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2011-2013 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 if { ![support_displaced_stepping] } {
19 unsupported "displaced stepping"
25 # Define the syscall instruction for each target.
27 if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
28 set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
33 proc disp_step_cross_syscall { syscall } { with_test_prefix "$syscall" {
37 set testfile "disp-step-$syscall"
39 if [prepare_for_testing ${testfile}.exp ${testfile} ${testfile}.c {debug}] {
40 untested ${testfile}.exp
44 if { ![runto main] } then {
45 fail "run to main ($syscall)"
49 # Delete the breakpoint on main.
50 gdb_test_no_output "delete break 1"
52 gdb_test "break marker" "Breakpoint.*at.* file .*${testfile}.c, line.*"
53 gdb_test_no_output "set displaced-stepping off"
56 gdb_test_multiple "break $syscall" "break $syscall" {
57 -re "Breakpoint (\[0-9\]*) at .*$gdb_prompt $" {
58 set syscall_bp $expect_out(1,string)
63 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
64 "continue to $syscall (1st time)"
65 # Hit the breakpoint on $syscall for the first time. In this time, we will let PLT
66 # resolution done, and the number single steps we will do later will be
69 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
70 "continue to $syscall (2nd time)"
71 # Hit the breakpoint on $syscall for the second time. In this time, the address
72 # of syscall insn and next insn of syscall are recorded.
74 gdb_test "display/i \$pc" ".*"
77 # Single step until we see sysall insn or we reach the upper bound of loop
79 set see_syscall_insn 0
81 for {set i 0} {$i < 1000 && $see_syscall_insn == 0} {incr i} {
84 -re ".*$syscall_insn.*$gdb_prompt $" {
85 set see_syscall_insn 1
87 -re ".*$gdb_prompt $" {}
91 if {$see_syscall_insn == 0} then {
92 fail "find syscall insn in $syscall"
96 set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
97 gdb_test "stepi" ".*" "stepi $syscall insn"
98 set syscall_insn_next_addr [get_hexadecimal_valueof "\$pc" "0"]
100 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
101 "continue to $syscall (3rd time)"
103 # Hit the breakpoint on $syscall for the third time. In this time, we'll set
104 # breakpoint on the syscall insn we recorded previously, and single step over it.
106 set syscall_insn_bp 0
107 gdb_test_multiple "break \*$syscall_insn_addr" "break on syscall insn" {
108 -re "Breakpoint (\[0-9\]*) at .*$gdb_prompt $" {
109 set syscall_insn_bp $expect_out(1,string)
110 pass "break on syscall insns"
113 gdb_test_no_output "delete $syscall_bp" "delete break $syscall"
115 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, .*" \
116 "continue to syscall insn $syscall"
118 gdb_test_no_output "set displaced-stepping on"
120 # Check the address of next instruction of syscall.
121 if {$syscall == "vfork" && [is_remote target]} {
122 setup_kfail server/13796 "*-*-*"
124 set test "single step over $syscall"
125 gdb_test_multiple "stepi" $test {
126 -re "Program terminated with signal SIGILL,.*\r\n$gdb_prompt $" {
130 -re "\\\[Inferior .* exited normally\\\].*\r\n$gdb_prompt $" {
134 -re "\r\n$gdb_prompt $" {
139 set syscall_insn_next_addr_found [get_hexadecimal_valueof "\$pc" "0"]
141 set test "single step over $syscall final pc"
142 if {$syscall_insn_next_addr != 0
143 && $syscall_insn_next_addr == $syscall_insn_next_addr_found} {
149 # Delete breakpoint syscall insns to avoid interference to other syscalls.
150 gdb_test_no_output "delete $syscall_insn_bp" "delete break $syscall insn"
152 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker \\(\\) at.*" \
153 "continue to marker ($syscall)"
156 disp_step_cross_syscall "fork"
157 disp_step_cross_syscall "vfork"