Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / ifelse.exp
CommitLineData
88b9d363 1# Copyright 2006-2022 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
40d2e0e3
AS
19gdb_exit
20gdb_start
21
22# First test that the if command works with an empty body
23# Test with different conditions because the body is ignored
24# if it is not executed.
25
26# with true condition
27set message "if 1 with empty body"
6d7fd486
AS
28gdb_test_multiple "if 1\nend" $message {
29 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
30 eof {
31 fail "$message (crashed)"
32 gdb_exit
33 gdb_start
34 }
35}
36
37# with false condition
38set message "if 0 with empty body"
6d7fd486
AS
39gdb_test_multiple "if 0\nend" $message {
40 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
41 eof {
42 fail "$message (crashed)"
43 gdb_exit
44 gdb_start
45 }
46}
47
48# Second, do the same tests with an empty else body.
49# This fails in GDB <=6.5
50
51# Unfortunately it was an uninitialised memory problem so
177b42fe 52# sometimes it just works. Precede it with an if else end with
40d2e0e3
AS
53# bodies and hopefully the memory with be dirty and the problem
54# will show itself (this works at time of writing).
55
8344e389
JK
56gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" \
57 "if true else false #1"
40d2e0e3
AS
58
59# with true condition
60set message "if 1 .. else with empty body"
6d7fd486
AS
61gdb_test_multiple "if 1\nelse\nend" $message {
62 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
63 eof {
64 fail "$message (crashed)"
65 gdb_exit
66 gdb_start
67 }
68}
69
70# dirty memory
8344e389
JK
71gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" \
72 "if true else false #2"
40d2e0e3
AS
73
74# with false condition
75set message "if 0 .. else with empty body"
6d7fd486
AS
76gdb_test_multiple "if 0\nelse\nend" $message {
77 -re "$gdb_prompt $" {pass $message}
40d2e0e3
AS
78 eof {
79 fail "$message (crashed)"
80 gdb_exit
81 gdb_start
82 }
83}
84
35ec993f 85gdb_test_no_output "set confirm off" ""
40d2e0e3
AS
86
87# Test that a define with an empty else can be replaced.
88# If there is memory corruption then free will fail.
89# dirty memory
8344e389
JK
90gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" \
91 "if true else false #3"
40d2e0e3
AS
92# create
93gdb_test "define abc\nif 1\nelse\nend\nend" "" "create define with empty else"
94# call (note that condition is 1 so should pass)
27d3a1a2 95gdb_test_no_output "abc" "call original define"
40d2e0e3
AS
96# replace
97set message "replace define with if .. else with empty body"
98gdb_test_multiple "define abc\necho got here\\n\nend" $message {
99 -re "$gdb_prompt $" {pass $message}
100 eof {fail "$message (crashed)"}
101}
102# call
103gdb_test "abc" "got here" "call replacement define"
This page took 1.746104 seconds and 4 git commands to generate.