1# Copyright 2004, 2007, 2008, 2009, 2010, 2011 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
21if $tracelevel then {
22	strace $tracelevel
23}
24
25
26# IDT/SIM apparently doesn't have enough file descriptors to allow the
27# problem checked by this test to occur.
28if [istarget "mips-idt-*"] {
29    return 0;
30}
31
32set testfile "chng-syms"
33set srcfile ${testfile}.c
34set binfile ${objdir}/${subdir}/${testfile}
35
36if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DVARIABLE=var1}] != "" } {
37    untested chng-syms.exp
38    return -1
39}
40
41set oldtimeout $timeout
42set timeout 10
43verbose "Timeout is now 10 seconds" 2
44
45proc expect_to_stop_here { ident } {
46    global gdb_prompt
47    global decimal
48
49    # the "at foo.c:36" output we get with -g.
50    # the "in func" output we get without -g.
51    gdb_expect {
52	-re "Breakpoint \[0-9\]*, stop_here .*$gdb_prompt $" {
53	    return 1
54	}
55	-re "$gdb_prompt $" {
56	    fail "running to stop_here $ident"
57	    return 0
58	}
59	timeout {
60	    fail "running to stop_here $ident (timeout)"
61	    return 0
62	}
63    }
64    return 1
65}
66
67gdb_exit
68gdb_start
69gdb_reinitialize_dir $srcdir/$subdir
70gdb_load ${binfile}
71
72gdb_test "break stop_here if (var1 == 42)" \
73    "Breakpoint.*at.* file .*$srcfile, line.*" \
74    "setting conditional breakpoint on function"
75gdb_run_cmd
76
77expect_to_stop_here "first time"
78
79gdb_continue_to_end "breakpoint first time through"
80
81# Now we recompile the executable, but without a variable named "var1", first
82# waiting to insure that even on fast machines, the file modification times
83# are distinct. This will force GDB to reload the file on the
84# next "run" command, causing an error when GDB tries to tries to reset
85# the breakpoint.
86
87sleep 2
88if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DVARIABLE=var2}] != "" } {
89
90# Complication: Since GDB generally holds an open file descriptor on the
91# executable at this point, there are some systems in which the
92# re-compilation will fail. In such cases, we'll consider the test
93# (vacuously) passed providing that re-running it succeeds as before.
94
95    gdb_run_cmd
96    expect_to_stop_here "after re-compile fails"
97    gdb_continue_to_end "after re-compile fails"
98
99} else {
100
101    gdb_run_cmd
102    gdb_expect {
103	-re ".*$inferior_exited_re normally.*$gdb_prompt $" {
104	    pass "running with invalidated bpt condition after executable changes"
105	}
106	-re ".*Breakpoint .*,( 0x.* in)? (\[^ \]*)exit .*$gdb_prompt $" {
107	    pass "running with invalidated bpt condition after executable changes"
108	}
109	-re "$gdb_prompt $" {
110	    fail "running with invalidated bpt condition after executable changes"
111	}
112	timeout {
113	    fail "(timeout) running with invalidated bpt condition after executable changes"
114	}
115    }
116
117}
118
119set timeout $oldtimeout
120verbose "Timeout is now $timeout seconds" 2
121return 0
122