Remove path name from test case
[binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-condbreak-fail.exp
1 # Copyright (C) 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
16 # Check that when GDB fails to evaluate the condition of a conditional
17 # breakpoint we only get one *stopped notification. In this test case
18 # the breakpoint condition fails due to receiving a signal (SIGSEGV).
19
20 load_lib mi-support.exp
21 set MIFLAGS "-i=mi"
22
23 standard_testfile
24
25 if [build_executable ${testfile}.exp ${binfile} ${srcfile}] {
26 return -1
27 }
28
29 # Create a breakpoint with a condition that invokes an inferior
30 # function call, that will segfault. Run until GDB hits the
31 # breakpoint and check how GDB reports the failed condition check.
32 #
33 # UNWIND_ON_SIGNAL is either 'on' or 'off'. This is used to configure
34 # GDB's 'set unwindonsignal' setting.
35
36 proc run_test { unwind_on_signal } {
37
38 if {[mi_clean_restart $::binfile]} {
39 return
40 }
41
42 if {[mi_runto_main] == -1} {
43 return
44 }
45
46 mi_gdb_test "-gdb-set unwindonsignal ${unwind_on_signal}" {\^done} \
47 "set unwind-on-signal"
48
49 # Create the conditional breakpoint.
50 set bp_location [gdb_get_line_number "Set breakpoint here"]
51 mi_create_breakpoint "-c \"cond_fail ()\" $::srcfile:$bp_location" \
52 "insert conditional breakpoint" \
53 -func foo -file ".*$::srcfile" -line "$bp_location" \
54 -cond "cond_fail \\(\\)"
55
56 # Number of the previous breakpoint.
57 set bpnum [mi_get_valueof "/d" "\$bpnum" "INVALID" \
58 "get number for breakpoint"]
59
60 # The line where we expect the inferior to crash.
61 set crash_linenum [gdb_get_line_number "Crash here"]
62
63 # Run the inferior and wait for it to stop.
64 mi_send_resuming_command "exec-continue" "continue the inferior"
65
66 if {$unwind_on_signal} {
67 mi_gdb_test "" \
68 [multi_line \
69 "&\"Error in testing condition for breakpoint $bpnum:\\\\n\"" \
70 "&\"The program being debugged received signal SIGSEGV, Segmentation fault\\\\n\"" \
71 "&\"while in a function called from GDB\\. GDB has restored the context\\\\n\"" \
72 "&\"to what it was before the call\\. To change this behavior use\\\\n\"" \
73 "&\"\\\\\"set unwindonsignal off\\\\\"\\. Evaluation of the expression containing\\\\n\"" \
74 "&\"the function \\(cond_fail\\) will be abandoned\\.\\\\n\"" \
75 "=breakpoint-modified,bkpt={number=\"$bpnum\",type=\"breakpoint\",\[^\r\n\]+times=\"1\",\[^\r\n\]+}" \
76 "~\"\\\\n\"" \
77 "~\"Breakpoint $bpnum, foo \\(\\) at \[^\r\n\]+/${::srcfile}:${bp_location}\\\\n\"" \
78 "~\"${bp_location}\\\\t\[^\r\n\]+Set breakpoint here\\.\[^\r\n\]+\\\\n\"" \
79 "\\*stopped,reason=\"breakpoint-hit\",disp=\"keep\",bkptno=\"$bpnum\",frame=\\{addr=\"$::hex\",func=\"foo\"\\,args=\\\[\\\],file=\"\[^\r\n\]+\",fullname=\"\[^\r\n\]+\",line=\"$bp_location\",\[^\r\n\]+}\[^\r\n\]+"] \
80 "wait for stop"
81
82 mi_info_frame "check the current frame" \
83 -level 0 -func foo -line $bp_location
84 } else {
85 mi_gdb_test "" \
86 [multi_line \
87 "~\"\\\\nProgram\"" \
88 "~\" received signal SIGSEGV, Segmentation fault\\.\\\\n\"" \
89 "~\"$::hex in cond_fail \\(\\) at \[^\r\n\]+\"" \
90 "~\"${crash_linenum}\\\\t\\s+return \\*p;\[^\r\n\]+\\\\n\"" \
91 "\\*stopped,reason=\"signal-received\",signal-name=\"SIGSEGV\"\[^\r\n\]+frame=\\{addr=\"$::hex\",func=\"cond_fail\",args=\\\[\\\],file=\"\[^\r\n\]+\",fullname=\"\[^\r\n\]+\",line=\"$crash_linenum\",\[^\r\n\]+\\}\[^\r\n\]+" \
92 "&\"Error in testing condition for breakpoint $bpnum:\\\\n\"" \
93 "&\"The program being debugged was signaled while in a function called from GDB\\.\\\\n\"" \
94 "&\"GDB remains in the frame where the signal was received\\.\\\\n\"" \
95 "&\"To change this behavior use \\\\\"set unwindonsignal on\\\\\"\\.\\\\n\"" \
96 "&\"Evaluation of the expression containing the function\\\\n\"" \
97 "&\"\\(cond_fail\\) will be abandoned\\.\\\\n\"" \
98 "&\"When the function is done executing, GDB will silently stop\\.\\\\n\"" \
99 "=breakpoint-modified,bkpt={number=\"$bpnum\",type=\"breakpoint\",\[^\r\n\]+times=\"1\",\[^\r\n\]+}"] \
100 "wait for stop"
101
102 mi_info_frame "check the current frame" \
103 -level 0 -func cond_fail -line $crash_linenum
104 }
105 }
106
107 foreach_with_prefix unwind_on_signal { off on } {
108 run_test $unwind_on_signal
109 }