hook-stop.exp revision 1.1.1.4
1171095Ssam# Copyright 2009-2020 Free Software Foundation, Inc. 2171095Ssam 3171095Ssam# This program is free software; you can redistribute it and/or modify 4242731Skevlo# it under the terms of the GNU General Public License as published by 5171095Ssam# the Free Software Foundation; either version 3 of the License, or 6171095Ssam# (at your option) any later version. 7171095Ssam# 8171095Ssam# This program is distributed in the hope that it will be useful, 9171095Ssam# but WITHOUT ANY WARRANTY; without even the implied warranty of 10171095Ssam# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11171095Ssam# GNU General Public License for more details. 12171095Ssam# 13171095Ssam# You should have received a copy of the GNU General Public License 14171095Ssam# along with this program. If not, see <http://www.gnu.org/licenses/>. 15171095Ssam 16171095Ssamstandard_testfile 17171095Ssam 18171095Ssamif { [build_executable ${testfile}.exp "${testfile}" $srcfile {debug nowarnings}] } { 19171095Ssam return -1 20171095Ssam} 21171095Ssam 22171095Ssam# Define the hook-stop that runs COMMANDS. 23171095Ssam 24171095Ssamproc define_hook_stop {commands} { 25173139Srwatson set test "define hook-stop command" 26173139Srwatson gdb_test_multiple "define hook-stop" "$test" { 27173139Srwatson -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$" { 28171095Ssam gdb_test "$commands\nend" "" "$test" 29173139Srwatson } 30171095Ssam } 31171095Ssam} 32171095Ssam 33171095Ssam# Restart GDB, run to main, set a breakpoint, and define a hook-stop 34171095Ssam# that runs COMMANDS. If running to main fails, this returns to the 35171095Ssam# caller's caller directly. 36171095Ssam 37171095Ssamproc setup {commands} { 38171095Ssam global srcfile binfile 39171095Ssam 40171095Ssam clean_restart $binfile 41171095Ssam 42228994Sdim if ![runto_main] then { 43228994Sdim fail "can't run to main" 44228994Sdim return -code return 45228994Sdim } 46228994Sdim 47228994Sdim gdb_test "break func" \ 48228994Sdim "Breakpoint.*at.* file .*$srcfile.*\\." \ 49228994Sdim "breakpoint line number" 50228994Sdim 51228994Sdim define_hook_stop $commands 52} 53 54# Check that the hook-stop runs before the frame is printed. 55 56proc hook_stop_before_frame {} { 57 with_test_prefix "hook-stop runs before frame print" { 58 global gdb_prompt 59 60 setup "echo \"Hello.\"" 61 62 set test "run hook-stop" 63 gdb_test_multiple "continue" "$test" { 64 -re "\"Hello\\.\"\r\nBreakpo.*func.*set breakpoint here.*${gdb_prompt} $" { 65 pass $test 66 } 67 68 -re "Breakpo.*func.*set breakpoint here.*\"Hello\\.\".*${gdb_prompt} $" { 69 fail $test 70 } 71 } 72 } 73} 74 75# Check that GDB gracefully handles the case of the inferior dying 76# while running the hook-stop. 77 78proc hook_stop_kill {} { 79 with_test_prefix "hook-stop kills inferior" { 80 global gdb_prompt 81 global decimal 82 83 setup "kill" 84 85 gdb_test_no_output "set confirm off" 86 87 set test "run hook-stop" 88 gdb_test_multiple "continue" "$test" { 89 -re "Continuing.\r\n\\\[Inferior $decimal \\(.*\\) killed\\\]\r\n${gdb_prompt} $" { 90 pass $test 91 } 92 } 93 94 gdb_test "info threads" "No threads.*" 95 } 96} 97 98# Check that GDB gracefully handles the case of the hook-stop 99# continuing the inferior in the foreground. 100 101proc hook_stop_continue_fg {} { 102 with_test_prefix "hook-stop runs continue" { 103 global gdb_prompt 104 105 setup "if \$do_continue\nset \$do_continue = 0\ncontinue\nend" 106 107 gdb_test "print \$do_continue = 1" " = 1" 108 109 gdb_test "next" "Breakpoint.*func \\(\\) at .*set breakpoint here \\*/" \ 110 "next triggering hook-stop" 111 112 gdb_test "next" "a = 2;" "next no hook-stop" 113 } 114} 115 116# Check that GDB gracefully handles the case of the hook-stop 117# continuing the inferior in the background. 118 119proc hook_stop_continue_bg {} { 120 with_test_prefix "hook-stop runs continue&" { 121 global gdb_prompt 122 123 setup "if \$do_continue\nset \$do_continue = 0\ncontinue&\nend" 124 125 gdb_test "print \$do_continue = 1" " = 1" 126 127 set test "run hook-stop" 128 gdb_test_multiple "continue" "$test" { 129 -re "Continuing.\r\n.*${gdb_prompt} " { 130 pass $test 131 } 132 } 133 134 set test "inferior exits normally" 135 gdb_test_multiple "" "$test" { 136 -re "exited normally" { 137 pass $test 138 } 139 } 140 gdb_test "info threads" "No threads.*" 141 } 142} 143 144# Check that GDB gracefully handles the case of the hook-stop running 145# "next". GDB used to print the stop event twice. 146 147proc hook_stop_next {} { 148 with_test_prefix "hook-stop runs next" { 149 global gdb_prompt 150 151 setup "next" 152 153 set test "run hook-stop" 154 gdb_test_multiple "continue" "$test" { 155 -re "a = 2.*a = 2${gdb_prompt} $" { 156 fail $test 157 } 158 -re "a = 2.*${gdb_prompt} $" { 159 pass $test 160 } 161 } 162 } 163} 164 165hook_stop_before_frame 166hook_stop_kill 167hook_stop_continue_fg 168hook_stop_continue_bg 169hook_stop_next 170