1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# Copyright 2016-2017 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
standard_testfile
# Test a thread is doing step-over a syscall instruction which is exit,
# and GDBserver should cleanup its state of step-over properly.
set syscall_insn ""
# Define the syscall instruction for each target.
if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
} elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } {
set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
} else {
unsupported "unknown syscall instruction"
return -1
}
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] {
fail "can't run to main"
return -1
}
gdb_test "set follow-fork-mode child"
gdb_test "set detach-on-fork off"
# Step 1, find the syscall instruction address.
gdb_test "break _exit" "Breakpoint $decimal at .*"
# Hit the breakpoint on _exit. The address of syscall insn is recorded.
gdb_test "continue" \
"Continuing\\..*Breakpoint $decimal.*_exit \\(.*\\).*" \
"continue to exit"
gdb_test "display/i \$pc" ".*"
# Single step until we see a syscall insn or we reach the
# upper bound of loop iterations.
set msg "find syscall insn in exit"
set steps 0
set max_steps 1000
gdb_test_multiple "stepi" $msg {
-re ".*$syscall_insn.*$gdb_prompt $" {
pass $msg
}
-re "x/i .*=>.*\r\n$gdb_prompt $" {
incr steps
if {$steps == $max_steps} {
fail $msg
} else {
send_gdb "stepi\n"
exp_continue
}
}
}
if {$steps == $max_steps} {
return
}
# Remove the display
gdb_test_no_output "delete display 1"
set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
gdb_test "continue" "exited normally.*" "continue to end, first time"
gdb_test "inferior 1" ".*Switching to inferior 1.*" \
"switch back to inferior 1, first time"
delete_breakpoints
gdb_test "break marker"
gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \
"continue to marker, first time"
# Step 2, create a breakpoint which evaluates false, and force it
# evaluated on the target side.
set test "set breakpoint condition-evaluation target"
gdb_test_multiple $test $test {
-re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" {
# Target doesn't support breakpoint condition evaluation
# on its side, but it is no harm to run the test.
}
-re "^$test\r\n$gdb_prompt $" {
}
}
gdb_test "break \*$syscall_insn_addr if main == 0" \
"Breakpoint \[0-9\]* at .*"
# Resume the child process, and the step-over is being done.
gdb_test "continue" "exited normally.*" "continue to end, second time"
gdb_test "inferior 1" ".*Switching to inferior 1.*" \
"switch back to inferior 1, second time"
# Switch back to the parent process, continue to the marker to
# test GDBserver's state is still correct.
gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \
"continue to marker, second time"
|