]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/ifelse.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ifelse.exp
1 # Copyright 2006, 2007 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 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
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 gdb_exit
25 gdb_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
32 set message "if 1 with empty body"
33 gdb_test_multiple "if 1\nend" $message {
34 -re "$gdb_prompt $" {pass $message}
35 eof {
36 fail "$message (crashed)"
37 gdb_exit
38 gdb_start
39 }
40 }
41
42 # with false condition
43 set message "if 0 with empty body"
44 gdb_test_multiple "if 0\nend" $message {
45 -re "$gdb_prompt $" {pass $message}
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
61 gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
62
63 # with true condition
64 set message "if 1 .. else with empty body"
65 gdb_test_multiple "if 1\nelse\nend" $message {
66 -re "$gdb_prompt $" {pass $message}
67 eof {
68 fail "$message (crashed)"
69 gdb_exit
70 gdb_start
71 }
72 }
73
74 # dirty memory
75 gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
76
77 # with false condition
78 set message "if 0 .. else with empty body"
79 gdb_test_multiple "if 0\nelse\nend" $message {
80 -re "$gdb_prompt $" {pass $message}
81 eof {
82 fail "$message (crashed)"
83 gdb_exit
84 gdb_start
85 }
86 }
87
88 gdb_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
93 gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
94 # create
95 gdb_test "define abc\nif 1\nelse\nend\nend" "" "create define with empty else"
96 # call (note that condition is 1 so should pass)
97 gdb_test "abc" "" "call original define"
98 # replace
99 set message "replace define with if .. else with empty body"
100 gdb_test_multiple "define abc\necho got here\\n\nend" $message {
101 -re "$gdb_prompt $" {pass $message}
102 eof {fail "$message (crashed)"}
103 }
104 # call
105 gdb_test "abc" "got here" "call replacement define"