1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2011-2014 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\]"
29 } elseif [istarget "arm*-*-linux*"] {
30 set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
35 proc disp_step_cross_syscall { syscall } {
36 with_test_prefix "$syscall" {
40 set testfile "disp-step-$syscall"
42 if [prepare_for_testing ${testfile}.exp ${testfile} ${testfile}.c {debug}] {
43 untested ${testfile}.exp
47 if { ![runto main] } then {
48 fail "run to main ($syscall)"
52 # Delete the breakpoint on main.
53 gdb_test_no_output "delete break 1"
55 gdb_test "break marker" "Breakpoint.*at.* file .*${testfile}.c, line.*"
56 gdb_test_no_output "set displaced-stepping off"
59 gdb_test_multiple "break $syscall" "break $syscall" {
60 -re "Breakpoint (\[0-9\]*) at .*$gdb_prompt $" {
61 set syscall_bp $expect_out(1,string)
66 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
67 "continue to $syscall (1st time)"
68 # Hit the breakpoint on $syscall for the first time. In this time, we will let PLT
69 # resolution done, and the number single steps we will do later will be
72 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
73 "continue to $syscall (2nd time)"
74 # Hit the breakpoint on $syscall for the second time. In this time, the address
75 # of syscall insn and next insn of syscall are recorded.
77 gdb_test "display/i \$pc" ".*"
80 # Single step until we see sysall insn or we reach the upper bound of loop
82 set see_syscall_insn 0
84 for {set i 0} {$i < 1000 && $see_syscall_insn == 0} {incr i} {
87 -re ".*$syscall_insn.*$gdb_prompt $" {
88 set see_syscall_insn 1
90 -re ".*$gdb_prompt $" {}
94 if {$see_syscall_insn == 0} then {
95 fail "find syscall insn in $syscall"
99 set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
100 gdb_test "stepi" ".*" "stepi $syscall insn"
101 set syscall_insn_next_addr [get_hexadecimal_valueof "\$pc" "0"]
103 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
104 "continue to $syscall (3rd time)"
106 # Hit the breakpoint on $syscall for the third time. In this time, we'll set
107 # breakpoint on the syscall insn we recorded previously, and single step over it.
109 set syscall_insn_bp 0
110 gdb_test_multiple "break \*$syscall_insn_addr" "break on syscall insn" {
111 -re "Breakpoint (\[0-9\]*) at .*$gdb_prompt $" {
112 set syscall_insn_bp $expect_out(1,string)
113 pass "break on syscall insns"
116 gdb_test_no_output "delete $syscall_bp" "delete break $syscall"
118 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, .*" \
119 "continue to syscall insn $syscall"
121 gdb_test_no_output "set displaced-stepping on"
123 # Check the address of next instruction of syscall.
124 if {$syscall == "vfork" && [is_remote target]} {
125 setup_kfail server/13796 "*-*-*"
127 set test "single step over $syscall"
128 gdb_test_multiple "stepi" $test {
129 -re "Program terminated with signal SIGILL,.*\r\n$gdb_prompt $" {
133 -re "\\\[Inferior .* exited normally\\\].*\r\n$gdb_prompt $" {
137 -re "\r\n$gdb_prompt $" {
142 set syscall_insn_next_addr_found [get_hexadecimal_valueof "\$pc" "0"]
144 set test "single step over $syscall final pc"
145 if {$syscall_insn_next_addr != 0
146 && $syscall_insn_next_addr == $syscall_insn_next_addr_found} {
152 # Delete breakpoint syscall insns to avoid interference to other syscalls.
153 gdb_test_no_output "delete $syscall_insn_bp" "delete break $syscall insn"
155 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker \\(\\) at.*" \
156 "continue to marker ($syscall)"
160 disp_step_cross_syscall "fork"
161 disp_step_cross_syscall "vfork"