1# Copyright 2004-2020 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# Author: Paul N. Hilfinger (Hilfinger@gnat.com)
17
18# Test that GDB cleans up properly after errors that result when a
19# breakpoint is reset.
20
21standard_testfile .c
22
23if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DVARIABLE=var1}] != "" } {
24    untested "failed to compile"
25    return -1
26}
27
28set oldtimeout $timeout
29set timeout 10
30verbose "Timeout is now 10 seconds" 2
31
32proc expect_to_stop_here { ident } {
33    # the "at foo.c:36" output we get with -g.
34    # the "in func" output we get without -g.
35
36    gdb_test "" "Breakpoint \[0-9\]*, stop_here .*" "running to stop_here $ident"
37}
38
39clean_restart ${binfile}
40
41gdb_test "break stop_here if (var1 == 42)" \
42    "Breakpoint.*at.* file .*$srcfile, line.*" \
43    "setting conditional breakpoint on function"
44gdb_run_cmd
45
46expect_to_stop_here "first time"
47
48gdb_continue_to_end "breakpoint first time through"
49
50# Now we recompile the executable, but without a variable named "var1", first
51# waiting to insure that even on fast machines, the file modification times
52# are distinct. This will force GDB to reload the file on the
53# next "run" command, causing an error when GDB tries to tries to reset
54# the breakpoint.
55
56sleep 2
57if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DVARIABLE=var2}] != "" } {
58
59# Complication: Since GDB generally holds an open file descriptor on the
60# executable at this point, there are some systems in which the
61# re-compilation will fail. In such cases, we'll consider the test
62# (vacuously) passed providing that re-running it succeeds as before.
63
64    gdb_run_cmd
65    expect_to_stop_here "after re-compile fails"
66    gdb_continue_to_end "after re-compile fails"
67
68} else {
69
70    gdb_run_cmd
71
72    set test "running with invalidated bpt condition after executable changes"
73    gdb_test_multiple "" $test {
74	-re ".*$inferior_exited_re normally.*$gdb_prompt $" {
75	    pass $test
76	}
77	-re ".*Breakpoint .*,( 0x.* in)? (\[^ \]*)exit .*$gdb_prompt $" {
78	    pass $test
79	}
80    }
81
82}
83
84set timeout $oldtimeout
85verbose "Timeout is now $timeout seconds" 2
86return 0
87