1 # Copyright 2009-2018 Free Software Foundation, Inc.
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.
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.
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/>.
18 if { [build_executable ${testfile}.exp "${testfile}" $srcfile {debug nowarnings}] } {
22 # Define the hook-stop that runs COMMANDS.
24 proc 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"
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.
37 proc setup {commands} {
38 global srcfile binfile
40 clean_restart $binfile
42 if ![runto_main] then {
43 fail "can't run to main"
47 gdb_test "break func" \
48 "Breakpoint.*at.* file .*$srcfile.*\\." \
49 "breakpoint line number"
51 define_hook_stop $commands
54 # Check that the hook-stop runs before the frame is printed.
56 proc hook_stop_before_frame {} {
57 with_test_prefix "hook-stop runs before frame print" {
60 setup "echo \"Hello.\""
62 set test "run hook-stop"
63 gdb_test_multiple "continue" "$test" {
64 -re "\"Hello\\.\"\r\nBreakpo.*func.*set breakpoint here.*${gdb_prompt} $" {
68 -re "Breakpo.*func.*set breakpoint here.*\"Hello\\.\".*${gdb_prompt} $" {
75 # Check that GDB gracefully handles the case of the inferior dying
76 # while running the hook-stop.
78 proc hook_stop_kill {} {
79 with_test_prefix "hook-stop kills inferior" {
85 gdb_test_no_output "set confirm off"
87 set test "run hook-stop"
88 gdb_test_multiple "continue" "$test" {
89 -re "Continuing.\r\n\\\[Inferior $decimal \\(.*\\) has been killed\\\]\r\n${gdb_prompt} $" {
94 gdb_test "info threads" "No threads.*"
98 # Check that GDB gracefully handles the case of the hook-stop
99 # continuing the inferior in the foreground.
101 proc hook_stop_continue_fg {} {
102 with_test_prefix "hook-stop runs continue" {
105 setup "if \$do_continue\nset \$do_continue = 0\ncontinue\nend"
107 gdb_test "print \$do_continue = 1" " = 1"
109 gdb_test "next" "Breakpoint.*func \\(\\) at .*set breakpoint here \\*/" \
110 "next triggering hook-stop"
112 gdb_test "next" "a = 2;" "next no hook-stop"
116 # Check that GDB gracefully handles the case of the hook-stop
117 # continuing the inferior in the background.
119 proc hook_stop_continue_bg {} {
120 with_test_prefix "hook-stop runs continue&" {
123 setup "if \$do_continue\nset \$do_continue = 0\ncontinue&\nend"
125 gdb_test "print \$do_continue = 1" " = 1"
127 set test "run hook-stop"
128 gdb_test_multiple "continue" "$test" {
129 -re "Continuing.\r\n.*${gdb_prompt} " {
134 set test "inferior exits normally"
135 gdb_test_multiple "" "$test" {
136 -re "exited normally" {
140 gdb_test "info threads" "No threads.*"
144 # Check that GDB gracefully handles the case of the hook-stop running
145 # "next". GDB used to print the stop event twice.
147 proc hook_stop_next {} {
148 with_test_prefix "hook-stop runs next" {
153 set test "run hook-stop"
154 gdb_test_multiple "continue" "$test" {
155 -re "a = 2.*a = 2${gdb_prompt} $" {
158 -re "a = 2.*${gdb_prompt} $" {
165 hook_stop_before_frame
167 hook_stop_continue_fg
168 hook_stop_continue_bg