gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / ifelse.exp
CommitLineData
7b6bb8da 1# Copyright 2006, 2007, 2008, 2009, 2010, 2011 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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
40d2e0e3
AS
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
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
40d2e0e3
AS
15
16# This test checks that the if .. else .. end construct works and may
17# contain empty bodies without crashing.
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
23gdb_exit
24gdb_start
25
26# First test that the if command works with an empty body
27# Test with different conditions because the body is ignored
28# if it is not executed.
29
30# with true condition
31set message "if 1 with empty body"
6d7fd486
AS
32gdb_test_multiple "if 1\nend" $message {
33 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
34 eof {
35 fail "$message (crashed)"
36 gdb_exit
37 gdb_start
38 }
39}
40
41# with false condition
42set message "if 0 with empty body"
6d7fd486
AS
43gdb_test_multiple "if 0\nend" $message {
44 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
45 eof {
46 fail "$message (crashed)"
47 gdb_exit
48 gdb_start
49 }
50}
51
52# Second, do the same tests with an empty else body.
53# This fails in GDB <=6.5
54
55# Unfortunately it was an uninitialised memory problem so
177b42fe 56# sometimes it just works. Precede it with an if else end with
40d2e0e3
AS
57# bodies and hopefully the memory with be dirty and the problem
58# will show itself (this works at time of writing).
59
8344e389
JK
60gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" \
61 "if true else false #1"
40d2e0e3
AS
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
8344e389
JK
75gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" \
76 "if true else false #2"
40d2e0e3
AS
77
78# with false condition
79set message "if 0 .. else with empty body"
6d7fd486
AS
80gdb_test_multiple "if 0\nelse\nend" $message {
81 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
82 eof {
83 fail "$message (crashed)"
84 gdb_exit
85 gdb_start
86 }
87}
88
35ec993f 89gdb_test_no_output "set confirm off" ""
40d2e0e3
AS
90
91# Test that a define with an empty else can be replaced.
92# If there is memory corruption then free will fail.
93# dirty memory
8344e389
JK
94gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" \
95 "if true else false #3"
40d2e0e3
AS
96# create
97gdb_test "define abc\nif 1\nelse\nend\nend" "" "create define with empty else"
98# call (note that condition is 1 so should pass)
27d3a1a2 99gdb_test_no_output "abc" "call original define"
40d2e0e3
AS
100# replace
101set message "replace define with if .. else with empty body"
102gdb_test_multiple "define abc\necho got here\\n\nend" $message {
103 -re "$gdb_prompt $" {pass $message}
104 eof {fail "$message (crashed)"}
105}
106# call
107gdb_test "abc" "got here" "call replacement define"
This page took 0.531057 seconds and 4 git commands to generate.