]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/ifelse.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ifelse.exp
CommitLineData
6aba47ca 1# Copyright 2006, 2007 Free Software Foundation, Inc.
40d2e0e3
AS
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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# This test checks that the if .. else .. end construct works and may
18# contain empty bodies without crashing.
19
20if $tracelevel then {
21 strace $tracelevel
22}
23
24gdb_exit
25gdb_start
26
27# First test that the if command works with an empty body
28# Test with different conditions because the body is ignored
29# if it is not executed.
30
31# with true condition
32set message "if 1 with empty body"
6d7fd486
AS
33gdb_test_multiple "if 1\nend" $message {
34 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
35 eof {
36 fail "$message (crashed)"
37 gdb_exit
38 gdb_start
39 }
40}
41
42# with false condition
43set message "if 0 with empty body"
6d7fd486
AS
44gdb_test_multiple "if 0\nend" $message {
45 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
46 eof {
47 fail "$message (crashed)"
48 gdb_exit
49 gdb_start
50 }
51}
52
53# Second, do the same tests with an empty else body.
54# This fails in GDB <=6.5
55
56# Unfortunately it was an uninitialised memory problem so
57# sometimes it just works. Preceed it with an if else end with
58# bodies and hopefully the memory with be dirty and the problem
59# will show itself (this works at time of writing).
60
61gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
62
63# with true condition
64set message "if 1 .. else with empty body"
6d7fd486
AS
65gdb_test_multiple "if 1\nelse\nend" $message {
66 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
67 eof {
68 fail "$message (crashed)"
69 gdb_exit
70 gdb_start
71 }
72}
73
74# dirty memory
75gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
76
77# with false condition
78set message "if 0 .. else with empty body"
6d7fd486
AS
79gdb_test_multiple "if 0\nelse\nend" $message {
80 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
81 eof {
82 fail "$message (crashed)"
83 gdb_exit
84 gdb_start
85 }
86}
87
88gdb_test "set confirm off" "" ""
89
90# Test that a define with an empty else can be replaced.
91# If there is memory corruption then free will fail.
92# dirty memory
93gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
94# create
95gdb_test "define abc\nif 1\nelse\nend\nend" "" "create define with empty else"
96# call (note that condition is 1 so should pass)
97gdb_test "abc" "" "call original define"
98# replace
99set message "replace define with if .. else with empty body"
100gdb_test_multiple "define abc\necho got here\\n\nend" $message {
101 -re "$gdb_prompt $" {pass $message}
102 eof {fail "$message (crashed)"}
103}
104# call
105gdb_test "abc" "got here" "call replacement define"