]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/disp-step-syscall.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / disp-step-syscall.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2011-2015 Free Software Foundation, Inc.
4
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.
9 #
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.
14 #
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/>.
17
18 if { ![support_displaced_stepping] } {
19 unsupported "displaced stepping"
20 return -1
21 }
22
23 set syscall_insn ""
24
25 # Define the syscall instruction for each target.
26
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\]"
31 } else {
32 return -1
33 }
34
35 proc disp_step_cross_syscall { syscall } {
36 with_test_prefix "$syscall" {
37 global syscall_insn
38 global gdb_prompt
39
40 set testfile "disp-step-$syscall"
41
42 if [prepare_for_testing ${testfile}.exp ${testfile} ${testfile}.c {debug}] {
43 untested ${testfile}.exp
44 return -1
45 }
46
47 if { ![runto main] } then {
48 fail "run to main ($syscall)"
49 return
50 }
51
52 # Delete the breakpoint on main.
53 gdb_test_no_output "delete break 1"
54
55 gdb_test "break marker" "Breakpoint.*at.* file .*${testfile}.c, line.*"
56 gdb_test_no_output "set displaced-stepping off"
57
58 set syscall_bp 0
59 gdb_test_multiple "break $syscall" "break $syscall" {
60 -re "Breakpoint (\[0-9\]*) at .*$gdb_prompt $" {
61 set syscall_bp $expect_out(1,string)
62 pass "break $syscall"
63 }
64 }
65
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
70 # reduced.
71
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.
76
77 gdb_test "display/i \$pc" ".*"
78
79
80 # Single step until we see sysall insn or we reach the upper bound of loop
81 # iterations.
82 set see_syscall_insn 0
83
84 for {set i 0} {$i < 1000 && $see_syscall_insn == 0} {incr i} {
85 send_gdb "stepi\n"
86 gdb_expect {
87 -re ".*$syscall_insn.*$gdb_prompt $" {
88 set see_syscall_insn 1
89 }
90 -re ".*$gdb_prompt $" {}
91 }
92 }
93
94 if {$see_syscall_insn == 0} then {
95 fail "find syscall insn in $syscall"
96 return -1
97 }
98
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"]
102
103 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
104 "continue to $syscall (3rd time)"
105
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.
108
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"
114 }
115 }
116 gdb_test_no_output "delete $syscall_bp" "delete break $syscall"
117
118 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, .*" \
119 "continue to syscall insn $syscall"
120
121 gdb_test_no_output "set displaced-stepping on"
122
123 # Check the address of next instruction of syscall.
124 if {$syscall == "vfork" && [is_remote target]} {
125 setup_kfail server/13796 "*-*-*"
126 }
127 set test "single step over $syscall"
128 gdb_test_multiple "stepi" $test {
129 -re "Program terminated with signal SIGILL,.*\r\n$gdb_prompt $" {
130 fail $test
131 return
132 }
133 -re "\\\[Inferior .* exited normally\\\].*\r\n$gdb_prompt $" {
134 fail $test
135 return
136 }
137 -re "\r\n$gdb_prompt $" {
138 pass $test
139 }
140 }
141
142 set syscall_insn_next_addr_found [get_hexadecimal_valueof "\$pc" "0"]
143
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} {
147 pass $test
148 } else {
149 fail $test
150 }
151
152 # Delete breakpoint syscall insns to avoid interference to other syscalls.
153 gdb_test_no_output "delete $syscall_insn_bp" "delete break $syscall insn"
154
155 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker \\(\\) at.*" \
156 "continue to marker ($syscall)"
157 }
158 }
159
160 disp_step_cross_syscall "fork"
161 disp_step_cross_syscall "vfork"