1# Copyright 2016-2023 Free Software Foundation, Inc. 2# 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. 7# 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. 12# 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/>. 15 16standard_testfile 17 18# Test a thread is doing step-over a syscall instruction which is exit, 19# and GDBserver should cleanup its state of step-over properly. 20 21set syscall_insn "" 22 23# Define the syscall instruction for each target. 24 25if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } { 26 set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]*" 27} elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } { 28 set syscall_insn "\[ \t\](swi|svc)\[ \t\]" 29} else { 30 unsupported "unknown syscall instruction" 31 return -1 32} 33 34if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 35 return -1 36} 37 38if ![runto_main] { 39 return -1 40} 41 42gdb_test "set follow-fork-mode child" 43gdb_test "set detach-on-fork off" 44 45# Step 1, find the syscall instruction address. 46 47gdb_test "break _exit" "Breakpoint $decimal at .*" 48 49# Hit the breakpoint on _exit. The address of syscall insn is recorded. 50 51gdb_test "continue" \ 52 "Continuing\\..*Breakpoint $decimal.*_exit \\(.*\\).*" \ 53 "continue to exit" 54 55gdb_test "display/i \$pc" ".*" 56 57# Single step until we see a syscall insn or we reach the 58# upper bound of loop iterations. 59set msg "find syscall insn in exit" 60set steps 0 61set max_steps 1000 62gdb_test_multiple "stepi" $msg { 63 -re ".*$syscall_insn.*$gdb_prompt $" { 64 pass $msg 65 } 66 -re "x/i .*=>.*\r\n$gdb_prompt $" { 67 incr steps 68 if {$steps == $max_steps} { 69 fail $msg 70 } else { 71 send_gdb "stepi\n" 72 exp_continue 73 } 74 } 75} 76 77if {$steps == $max_steps} { 78 return 79} 80 81# Remove the display 82gdb_test_no_output "delete display 1" 83 84set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"] 85 86gdb_test "continue" "exited normally.*" "continue to end, first time" 87gdb_test "inferior 1" ".*Switching to inferior 1.*" \ 88 "switch back to inferior 1, first time" 89 90delete_breakpoints 91 92gdb_test "break marker" 93 94gdb_test "continue" "Continuing\\..*Breakpoint $bkptno_num_re, .*" \ 95 "continue to marker, first time" 96 97# Step 2, create a breakpoint which evaluates false, and force it 98# evaluated on the target side. 99 100set test "set breakpoint condition-evaluation target" 101gdb_test_multiple $test $test { 102 -re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" { 103 # Target doesn't support breakpoint condition evaluation 104 # on its side, but it is no harm to run the test. 105 } 106 -re "^$test\r\n$gdb_prompt $" { 107 } 108} 109 110gdb_test "break \*$syscall_insn_addr if main == 0" \ 111 "Breakpoint \[0-9\]* at .*" \ 112 "set conditional break at syscall address" 113 114# Resume the child process, and the step-over is being done. 115 116gdb_test "continue" "exited normally.*" "continue to end, second time" 117gdb_test "inferior 1" ".*Switching to inferior 1.*" \ 118 "switch back to inferior 1, second time" 119 120# Switch back to the parent process, continue to the marker to 121# test GDBserver's state is still correct. 122 123gdb_test "continue" "Continuing\\..*Breakpoint $bkptno_numopt_re, .*" \ 124 "continue to marker, second time" 125