1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2011-2016 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/>.
20 # Define the syscall instruction for each target.
22 if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
23 set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
24 } elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } {
25 set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
30 proc check_pc_after_cross_syscall { syscall syscall_insn_next_addr } {
31 set syscall_insn_next_addr_found [get_hexadecimal_valueof "\$pc" "0"]
33 set test "single step over $syscall final pc"
34 if {$syscall_insn_next_addr != 0
35 && $syscall_insn_next_addr == $syscall_insn_next_addr_found} {
42 # Restart GDB and set up the test. Return a list in which the first one
43 # is the address of syscall instruction and the second one is the address
44 # of the next instruction address of syscall instruction. If anything
45 # wrong, the two elements of list are -1.
47 proc setup { syscall } {
48 global gdb_prompt syscall_insn
50 set testfile "disp-step-$syscall"
52 clean_restart $testfile
54 if { ![runto main] } then {
55 fail "run to main ($syscall)"
59 # Delete the breakpoint on main.
60 gdb_test_no_output "delete break 1"
62 gdb_test_no_output "set displaced-stepping off"
64 gdb_test "break $syscall" "Breakpoint \[0-9\]* at .*"
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,
69 # we will let PLT resolution done, and the number single steps we will
70 # do later will be reduced.
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,
75 # the address of syscall insn and next insn of syscall are recorded.
77 gdb_test "display/i \$pc" ".*"
79 # Single step until we see a syscall insn or we reach the
80 # upper bound of loop iterations.
81 set msg "find syscall insn in $syscall"
84 gdb_test_multiple "stepi" $msg {
85 -re ".*$syscall_insn.*$gdb_prompt $" {
88 -re "x/i .*=>.*\r\n$gdb_prompt $" {
90 if {$steps == $max_steps} {
99 if {$steps == $max_steps} {
103 set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
104 if {[gdb_test "stepi" "x/i .*=>.*" "stepi $syscall insn"] != 0} {
107 return [list $syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]]
110 proc disp_step_cross_syscall { syscall } {
111 with_test_prefix "$syscall" {
115 set testfile "disp-step-$syscall"
117 if [build_executable ${testfile}.exp ${testfile} ${testfile}.c {debug}] {
118 untested ${testfile}.exp
122 foreach_with_prefix displaced {"off" "on"} {
123 if {$displaced == "on" && ![support_displaced_stepping]} {
127 set ret [setup $syscall]
129 set syscall_insn_addr [lindex $ret 0]
130 set syscall_insn_next_addr [lindex $ret 1]
131 if { $syscall_insn_addr == -1 } {
135 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
136 "continue to $syscall (3rd time)"
138 # Hit the breakpoint on $syscall for the third time. In this time, we'll set
139 # breakpoint on the syscall insn we recorded previously, and single step over it.
141 set syscall_insn_bp 0
142 gdb_test_multiple "break \*$syscall_insn_addr" "break on syscall insn" {
143 -re "Breakpoint (\[0-9\]*) at .*$gdb_prompt $" {
144 set syscall_insn_bp $expect_out(1,string)
145 pass "break on syscall insns"
149 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, .*" \
150 "continue to syscall insn $syscall"
152 gdb_test_no_output "set displaced-stepping $displaced"
154 # Check the address of next instruction of syscall.
155 if {[gdb_test "stepi" "x/i .*=>.*" "single step over $syscall"] != 0} {
159 check_pc_after_cross_syscall $syscall $syscall_insn_next_addr
161 # Delete breakpoint syscall insns to avoid interference to other syscalls.
164 gdb_test "break marker" "Breakpoint.*at.* file .*${testfile}.c, line.*"
165 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker \\(\\) at.*" \
166 "continue to marker ($syscall)"
171 # Set a breakpoint with a condition that evals false on syscall
172 # instruction. In fact, it tests GDBserver steps over syscall
175 proc break_cond_on_syscall { syscall } {
176 with_test_prefix "break cond on target : $syscall" {
177 set testfile "disp-step-$syscall"
179 set ret [setup $syscall]
181 set syscall_insn_addr [lindex $ret 0]
182 set syscall_insn_next_addr [lindex $ret 1]
183 if { $syscall_insn_addr == -1 } {
187 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \
188 "continue to $syscall"
189 # Delete breakpoint syscall insns to avoid interference with other syscalls.
193 # Create a breakpoint with a condition that evals false.
194 gdb_test "break \*$syscall_insn_addr if main == 0" \
195 "Breakpoint \[0-9\]* at .*"
197 gdb_test "break marker" "Breakpoint.*at.* file .*${testfile}.c, line.*"
198 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker \\(\\) at.*" \
199 "continue to marker ($syscall)"
203 disp_step_cross_syscall "fork"
204 disp_step_cross_syscall "vfork"
206 set testfile "disp-step-fork"
207 clean_restart $testfile
208 if { ![runto main] } then {
215 set test "set breakpoint condition-evaluation target"
216 gdb_test_multiple $test $test {
217 -re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" {
218 # Target doesn't support breakpoint condition
219 # evaluation on its side.
222 -re "^$test\r\n$gdb_prompt $" {
226 if { $cond_bp_target } {
227 break_cond_on_syscall "fork"
228 break_cond_on_syscall "vfork"