]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/hook-stop.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / hook-stop.exp
CommitLineData
1d506c26 1# Copyright 2009-2024 Free Software Foundation, Inc.
4c2f2a79
PA
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
18if { [build_executable ${testfile}.exp "${testfile}" $srcfile {debug nowarnings}] } {
19 return -1
20}
21
22# Define the hook-stop that runs COMMANDS.
23
24proc define_hook_stop {commands} {
25 set test "define hook-stop command"
26 gdb_test_multiple "define hook-stop" "$test" {
27 -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$" {
28 gdb_test "$commands\nend" "" "$test"
29 }
30 }
31}
32
33# Restart GDB, run to main, set a breakpoint, and define a hook-stop
34# that runs COMMANDS. If running to main fails, this returns to the
35# caller's caller directly.
36
37proc setup {commands} {
38 global srcfile binfile
39
40 clean_restart $binfile
41
65a33d75 42 if {![runto_main]} {
4c2f2a79
PA
43 return -code return
44 }
45
46 gdb_test "break func" \
47 "Breakpoint.*at.* file .*$srcfile.*\\." \
48 "breakpoint line number"
49
50 define_hook_stop $commands
51}
52
53# Check that the hook-stop runs before the frame is printed.
54
55proc hook_stop_before_frame {} {
56 with_test_prefix "hook-stop runs before frame print" {
57 global gdb_prompt
58
59 setup "echo \"Hello.\""
60
61 set test "run hook-stop"
62 gdb_test_multiple "continue" "$test" {
63 -re "\"Hello\\.\"\r\nBreakpo.*func.*set breakpoint here.*${gdb_prompt} $" {
64 pass $test
65 }
66
67 -re "Breakpo.*func.*set breakpoint here.*\"Hello\\.\".*${gdb_prompt} $" {
68 fail $test
69 }
70 }
71 }
72}
73
74# Check that GDB gracefully handles the case of the inferior dying
75# while running the hook-stop.
76
77proc hook_stop_kill {} {
78 with_test_prefix "hook-stop kills inferior" {
79 global gdb_prompt
f67c0c91 80 global decimal
4c2f2a79
PA
81
82 setup "kill"
83
84 gdb_test_no_output "set confirm off"
85
86 set test "run hook-stop"
87 gdb_test_multiple "continue" "$test" {
a006bc9c 88 -re "Continuing.*\r\n\\\[Inferior $decimal \\(.*\\) killed\\\]\r\n${gdb_prompt} $" {
4c2f2a79
PA
89 pass $test
90 }
91 }
92
93 gdb_test "info threads" "No threads.*"
94 }
95}
96
97# Check that GDB gracefully handles the case of the hook-stop
98# continuing the inferior in the foreground.
99
100proc hook_stop_continue_fg {} {
101 with_test_prefix "hook-stop runs continue" {
102 global gdb_prompt
103
104 setup "if \$do_continue\nset \$do_continue = 0\ncontinue\nend"
105
106 gdb_test "print \$do_continue = 1" " = 1"
107
108 gdb_test "next" "Breakpoint.*func \\(\\) at .*set breakpoint here \\*/" \
109 "next triggering hook-stop"
110
111 gdb_test "next" "a = 2;" "next no hook-stop"
112 }
113}
114
115# Check that GDB gracefully handles the case of the hook-stop
116# continuing the inferior in the background.
117
118proc hook_stop_continue_bg {} {
119 with_test_prefix "hook-stop runs continue&" {
120 global gdb_prompt
121
122 setup "if \$do_continue\nset \$do_continue = 0\ncontinue&\nend"
123
124 gdb_test "print \$do_continue = 1" " = 1"
125
126 set test "run hook-stop"
127 gdb_test_multiple "continue" "$test" {
128 -re "Continuing.\r\n.*${gdb_prompt} " {
129 pass $test
130 }
131 }
132
133 set test "inferior exits normally"
134 gdb_test_multiple "" "$test" {
135 -re "exited normally" {
136 pass $test
137 }
138 }
139 gdb_test "info threads" "No threads.*"
140 }
141}
142
143# Check that GDB gracefully handles the case of the hook-stop running
144# "next". GDB used to print the stop event twice.
145
146proc hook_stop_next {} {
147 with_test_prefix "hook-stop runs next" {
148 global gdb_prompt
149
150 setup "next"
151
152 set test "run hook-stop"
153 gdb_test_multiple "continue" "$test" {
154 -re "a = 2.*a = 2${gdb_prompt} $" {
155 fail $test
156 }
157 -re "a = 2.*${gdb_prompt} $" {
158 pass $test
159 }
160 }
161 }
162}
163
164hook_stop_before_frame
165hook_stop_kill
166hook_stop_continue_fg
167hook_stop_continue_bg
168hook_stop_next