5094f5fa303541121d3f63230205d4c6ac245f38
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
1 # Copyright (C) 1988, 1990, 1991, 1992 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 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 #
25 # test special commands (if, while, etc)
26 #
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "run"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 perror "Couldn't compile ${srcfile}"
35 return -1
36 }
37
38 gdb_exit
39 gdb_start
40 delete_breakpoints
41 gdb_reinitialize_dir $srcdir/$subdir
42 gdb_load ${binfile}
43
44 proc gdbvar_simple_if_test {} {
45 global gdb_prompt
46
47 gdb_test "set \$foo = 0" "" "set foo in gdbvar_simple_if_test"
48 # All this test should do is print 0xdeadbeef once.
49 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
50 # All this test should do is print 0xfeedface once.
51 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
52 }
53
54 proc gdbvar_simple_while_test {} {
55 global gdb_prompt
56
57 gdb_test "set \$foo = 5" "" "set foo in gdbvar_simple_while_test"
58 # This test should print 0xfeedface five times.
59 gdb_test "while \$foo > 0\np/x 0xfeedface\nset \$foo -= 1\nend" "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_while_test #1"
60 }
61
62 proc gdbvar_complex_if_while_test {} {
63 global gdb_prompt
64
65 gdb_test "set \$foo = 4" "" "set foo in gdbvar complex_if_while_test"
66 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
67 gdb_test "while \$foo > 0\nset \$foo -= 1\nif \(\$foo % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "gdbvar_complex_if_while_test #1"
68 }
69
70 proc progvar_simple_if_test {} {
71 global gdb_prompt
72
73 if [target_info exists gdb,noargs] {
74 verbose "Skipping progvar_simple_if_test because of noargs."
75 return
76 }
77
78 gdb_test "set args 5" "" "set args in progvar_simple_if_test"
79 if { ![runto factorial] } then { return }
80 # All this test should do is print 0xdeadbeef once.
81 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "progvar_simple_if_test #1"
82 # All this test should do is print 0xfeedface once.
83 gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "progvar_simple_if_test #2"
84 }
85
86 proc progvar_simple_while_test {} {
87 global gdb_prompt
88
89 if [target_info exists gdb,noargs] {
90 verbose "Skipping progvar_simple_while_test because of noargs."
91 return
92 }
93
94 gdb_test "set args 5" "" "set args in progvar_simple_while_test"
95 if { ![runto factorial] } then { return }
96 # This test should print 0xfeedface five times.
97 gdb_test "while value > 0\np/x 0xfeedface\nset value -= 1\nend" "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "progvar_simple_while_test #1"
98 }
99
100 proc progvar_complex_if_while_test {} {
101 global gdb_prompt
102
103 if [target_info exists gdb,noargs] {
104 verbose "Skipping progvar_simple_if_while_test because of noargs."
105 return
106 }
107
108 gdb_test "set args 4" "" "set args in progvar_complex_if_while_test"
109 if { ![runto factorial] } then { return }
110 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
111 gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "progvar_complex_if_while_test #1"
112 }
113
114 proc if_while_breakpoint_command_test {} {
115 if [target_info exists gdb,noargs] {
116 verbose "Skipping if_while_breakpoint_command_test because of noargs."
117 return
118 }
119
120 gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test"
121 if { ![runto factorial] } then { return }
122 delete_breakpoints
123 gdb_test "break factorial" "Breakpoint.*at.*"
124
125 send_gdb "commands\n"
126 gdb_expect {
127 -re "End with" {
128 pass "commands in if_while_breakpoint_command_test"
129 }
130 default {
131 fail "(timeout or eof) commands in if_while_breakpoint_command_test"
132 }
133 }
134 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
135 gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" "" "commands part 2 in if_while_breakpoint_command_test"
136 gdb_test "continue" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "if_while_breakpoint_command_test #1"
137 gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*" "info break in if_while_breakpoint_command_test"
138 }
139
140 # Test that we can run the inferior from breakpoint commands.
141 proc infrun_breakpoint_command_test {} {
142 if [target_info exists gdb,noargs] {
143 verbose "Skipping infrun_breakpoint_command_test because of noargs."
144 return
145 }
146
147 gdb_test "set args 6" "" "set args in progvar_simple_while_test"
148 if { ![runto factorial] } then { return }
149 delete_breakpoints
150 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
151 gdb_test "commands\nstep\nstep\nstep\nstep\nbt\nend" \
152 "End with.*" "commands in infrun_breakpoint_command_test"
153 gdb_test "continue" "Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*
154 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
155 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
156 factorial \\(value=4\\) at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*
157 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
158 factorial \\(value=3\\) at .*
159 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
160 #0 factorial \\(value=3\\).*
161 #1 \[0-9a-fx\]* in factorial \\(value=4\\).*
162 #2 \[0-9a-fx\]* in factorial \\(value=5\\).*
163 #3 \[0-9a-fx\]* in factorial \\(value=6\\).*
164 #4 \[0-9a-fx\]* in main \\(.*\\).*" \
165 "continue in infrun_breakpoint_command_test"
166 }
167
168 proc breakpoint_command_test {} {
169 if [target_info exists gdb,noargs] {
170 verbose "Skipping breakpoint_command_test because of noargs."
171 return
172 }
173
174 gdb_test "set args 6" "" "set args in progvar_simple_while_test"
175 if { ![runto factorial] } then { return }
176 delete_breakpoints
177 gdb_test "break factorial" "Breakpoint.*at.*"
178 gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \
179 "End with.*" "commands in breakpoint_command_test"
180 gdb_test "continue" "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
181 "continue in breakpoint_command_test"
182 gdb_test "print value" " = 5" "print value in breakpoint_command_test"
183 }
184
185 # Test a simple user defined command (with arguments)
186 proc user_defined_command_test {} {
187 global gdb_prompt
188
189 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
190
191 send_gdb "define mycommand\n"
192 gdb_expect {
193 -re "End with" {
194 pass "define mycommand in user_defined_command_test"
195 }
196 default {
197 fail "(timeout or eof) define mycommand in user_defined_command_test"
198 }
199 }
200 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
201 gdb_test "while \$arg0 > 0\nset \$arg0 -= 1\nif \(\$arg0 % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" "" "enter commands in user_defined_command_test"
202
203 gdb_test "mycommand \$foo" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "execute user defined command in user_defined_command_test"
204 gdb_test "show user mycommand" "while.*set.*if.*p/x.*else.*p/x.*end.*" "display user command in user_defined_command_test"
205 }
206
207 gdbvar_simple_if_test
208 gdbvar_simple_while_test
209 gdbvar_complex_if_while_test
210 progvar_simple_if_test
211 progvar_simple_while_test
212 progvar_complex_if_while_test
213 if_while_breakpoint_command_test
214 infrun_breakpoint_command_test
215 breakpoint_command_test
216 user_defined_command_test
This page took 0.050689 seconds and 4 git commands to generate.