1 # Copyright (C) 1999, 2000, 2002 Cygnus Solutions
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # Test essential Machine interface (MI) operations
22 # Verify that, using the MI, we can create, update, delete variables.
26 load_lib mi-support.exp
34 set testfile "var-cmd"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42 mi_gdb_reinitialize_dir $srcdir/$subdir
43 mi_gdb_load ${binfile}
48 # Variable Creation tests #
52 # Test: c_variable-1.1
53 # Desc: Create global variable
55 mi_gdb_test "111-var-create global_simple * global_simple" \
56 "111\\^done,name=\"global_simple\",numchild=\"6\",type=\"simpleton\"" \
57 "create global variable"
59 # Test: c_variable-1.2
60 # Desc: Create non-existent variable
62 mi_gdb_test "112-var-create bogus_unknown_variable * bogus_unknown_variable" \
63 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*112\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
64 "create non-existent variable"
66 # Test: c_variable-1.3
67 # Desc: Create out of scope variable
69 mi_gdb_test "113-var-create argc * argc" \
70 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*113\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
71 "create out of scope variable"
73 mi_gdb_test "200-break-insert do_locals_tests" \
74 "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"do_locals_tests\",file=\".*var-cmd.c\",line=\"106\",times=\"0\"\}" \
75 "break-insert operation"
78 # The running part has been checked already by mi_run_cmd
80 -re "\[\r\n\]*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\\\[\\\],file=\".*var-cmd.c\",line=\"106\"\}\r\n$mi_gdb_prompt$" {
81 pass "run to do_locals_tests"
83 -re ".*$mi_gdb_prompt$" {fail "run to do_locals_tests (2)"}
84 timeout {fail "run to do_locals_tests (timeout 2)"}
87 # Test: c_variable-1.4
88 # Desc: create local variables
90 mi_gdb_test "-var-create linteger * linteger" \
91 "\\^done,name=\"linteger\",numchild=\"0\",type=\"int\"" \
92 "create local variable linteger"
94 mi_gdb_test "-var-create lpinteger * lpinteger" \
95 "\\^done,name=\"lpinteger\",numchild=\"1\",type=\"int \\*\"" \
96 "create local variable lpinteger"
98 mi_gdb_test "-var-create lcharacter * lcharacter" \
99 "\\^done,name=\"lcharacter\",numchild=\"0\",type=\"char\"" \
100 "create local variablelcharacter "
102 mi_gdb_test "-var-create lpcharacter * lpcharacter" \
103 "\\^done,name=\"lpcharacter\",numchild=\"1\",type=\"char \\*\"" \
104 "create local variable lpcharacter"
106 mi_gdb_test "-var-create llong * llong" \
107 "\\^done,name=\"llong\",numchild=\"0\",type=\"long int\"" \
108 "create local variable llong"
110 mi_gdb_test "-var-create lplong * lplong" \
111 "\\^done,name=\"lplong\",numchild=\"1\",type=\"long int \\*\"" \
112 "create local variable lplong"
114 mi_gdb_test "-var-create lfloat * lfloat" \
115 "\\^done,name=\"lfloat\",numchild=\"0\",type=\"float\"" \
116 "create local variable lfloat"
118 mi_gdb_test "-var-create lpfloat * lpfloat" \
119 "\\^done,name=\"lpfloat\",numchild=\"1\",type=\"float \\*\"" \
120 "create local variable lpfloat"
122 mi_gdb_test "-var-create ldouble * ldouble" \
123 "\\^done,name=\"ldouble\",numchild=\"0\",type=\"double\"" \
124 "create local variable ldouble"
126 mi_gdb_test "-var-create lpdouble * lpdouble" \
127 "\\^done,name=\"lpdouble\",numchild=\"1\",type=\"double \\*\"" \
128 "create local variable lpdouble"
130 mi_gdb_test "-var-create lsimple * lsimple" \
131 "\\^done,name=\"lsimple\",numchild=\"6\",type=\"struct _simple_struct\"" \
132 "create local variable lsimple"
134 mi_gdb_test "-var-create lpsimple * lpsimple" \
135 "\\^done,name=\"lpsimple\",numchild=\"6\",type=\"struct _simple_struct \\*\"" \
136 "create local variable lpsimple"
138 mi_gdb_test "-var-create func * func" \
139 "\\^done,name=\"func\",numchild=\"0\",type=\"void \\(\\*\\)\\((void|)\\)\"" \
140 "create local variable func"
142 # Test: c_variable-1.5
143 # Desc: create lsimple.character
144 mi_gdb_test "-var-create lsimple.character * lsimple.character" \
145 "\\^done,name=\"lsimple.character\",numchild=\"0\",type=\"char\"" \
146 "create lsimple.character"
148 # Test: c_variable-1.6
149 # Desc: create lpsimple->integer
150 mi_gdb_test "-var-create lsimple->integer * lsimple->integer" \
151 "\\^done,name=\"lsimple->integer\",numchild=\"0\",type=\"int\"" \
152 "create lsimple->integer"
154 # Test: c_variable-1.7
155 # Desc: ceate lsimple.integer
156 mi_gdb_test "-var-create lsimple.integer * lsimple.integer" \
157 "\\^done,name=\"lsimple.integer\",numchild=\"0\",type=\"int\"" \
158 "create lsimple->integer"
161 # Test: c_variable-1.9
162 # Desc: create type name
163 # Type names (like int, long, etc..) are all proper expressions to gdb.
164 # make sure variable code does not allow users to create variables, though.
165 mi_gdb_test "-var-create int * int" \
166 "&\"Attempt to use a type name as an expression.mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
172 # Value changed tests #
176 # Test: c_variable-2.1
177 # Desc: check whether values changed at do_block_tests
178 mi_gdb_test "-var-update *" \
179 "\\^done,changelist=\{\}" \
182 # Step over "linteger = 1234;"
183 mi_step_to "do_locals_tests" "" "var-cmd.c" "107" "step at do_locals_test"
185 # Test: c_variable-2.2
186 # Desc: check whether only linteger changed values
187 mi_gdb_test "-var-update *" \
188 "\\^done,changelist=\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}" \
189 "update all vars: linteger changed"
191 # Step over "lpinteger = &linteger;"
192 mi_step_to "do_locals_tests" "" "var-cmd.c" 108 "step at do_locals_tests (2)"
194 # Test: c_variable-2.3
195 # Desc: check whether only lpinteger changed
196 mi_gdb_test "-var-update *" \
197 "\\^done,changelist=\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\"\}" \
198 "update all vars: lpinteger changed"
200 # Step over "lcharacter = 'a';"
201 mi_step_to "do_locals_tests" "" "var-cmd.c" "109" "step at do_locals_tests (3)"
203 # Test: c_variable-2.4
204 # Desc: check whether only lcharacter changed
205 mi_gdb_test "-var-update *" \
206 "\\^done,changelist=\{name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\"\}" \
207 "update all vars: lcharacter changed"
209 # Step over "lpcharacter = &lcharacter;"
210 mi_step_to "do_locals_tests" "" "var-cmd.c" "110" "step at do_locals_tests (4)"
212 # Test: c_variable-2.5
213 # Desc: check whether only lpcharacter changed
214 mi_gdb_test "-var-update *" \
215 "\\^done,changelist=\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\"\}" \
216 "update all vars: lpcharacter changed"
224 # ldouble = 2.718281828459045;
225 # lpdouble = &ldouble;
226 # lsimple.integer = 1234;
227 # lsimple.unsigned_integer = 255;
228 # lsimple.character = 'a';
230 mi_execute_to "exec-step 9" "end-stepping-range" "do_locals_tests" "" \
231 "var-cmd.c" "119" "" "step at do_locals_tests (5)"
233 # Test: c_variable-2.6
234 # Desc: check whether llong, lplong, lfloat, lpfloat, ldouble, lpdouble, lsimple.integer,
235 # lsimple.unsigned_character lsimple.integer lsimple.character changed
236 mi_gdb_test "-var-update *" \
237 "\\^done,changelist=\{name=\"lsimple.integer\",in_scope=\"true\",type_changed=\"false\",name=\"lsimple->integer\",in_scope=\"true\",type_changed=\"false\",name=\"lsimple.character\",in_scope=\"true\",type_changed=\"false\",name=\"lpdouble\",in_scope=\"true\",type_changed=\"false\",name=\"ldouble\",in_scope=\"true\",type_changed=\"false\",name=\"lpfloat\",in_scope=\"true\",type_changed=\"false\",name=\"lfloat\",in_scope=\"true\",type_changed=\"false\",name=\"lplong\",in_scope=\"true\",type_changed=\"false\",name=\"llong\",in_scope=\"true\",type_changed=\"false\"\}" \
238 "update all vars: many changed"
241 # lsimple.signed_character = 21;
242 # lsimple.char_ptr = &lcharacter;
243 # lpsimple = &lsimple;
246 mi_execute_to "exec-step 4" "end-stepping-range" "do_locals_tests" "" \
247 "var-cmd.c" "125" "" "step at do_locals_tests (6)"
249 # Test: c_variable-2.7
250 # Desc: check whether (lsimple.signed_character, lsimple.char_ptr) lpsimple, func changed
251 mi_gdb_test "-var-update *" \
252 "\\^done,changelist=\{name=\"func\",in_scope=\"true\",type_changed=\"false\",name=\"lpsimple\",in_scope=\"true\",type_changed=\"false\"\}" \
253 "update all vars: func and lpsimple changed"
260 # ldouble = 5.498548281828172;
261 # lsimple.integer = 255;
262 # lsimple.unsigned_integer = 4321;
263 # lsimple.character = 'b';
265 mi_execute_to "exec-step 8" "end-stepping-range" "do_locals_tests" "" \
266 "var-cmd.c" "133" "" "step at do_locals_tests (7)"
268 # Test: c_variable-2.8
269 # Desc: check whether linteger, lcharacter, llong, lfoat, ldouble, lsimple.integer,
270 # lpsimple.integer lsimple.character changed
271 # Note: this test also checks that lpsimple->integer and lsimple.integer have
272 # changed (they are the same)
273 mi_gdb_test "-var-update *" \
274 "\\^done,changelist=\{name=\"lsimple.integer\",in_scope=\"true\",type_changed=\"false\",name=\"lsimple->integer\",in_scope=\"true\",type_changed=\"false\",name=\"lsimple.character\",in_scope=\"true\",type_changed=\"false\",name=\"ldouble\",in_scope=\"true\",type_changed=\"false\",name=\"lfloat\",in_scope=\"true\",type_changed=\"false\",name=\"llong\",in_scope=\"true\",type_changed=\"false\",name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\",name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}" \
275 "update all vars: func and lpsimple changed"
280 # Test assignment to variables. More tests on assignment are in other files.
283 mi_gdb_test "-var-assign global_simple 0" \
284 "&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msg=\"mi_cmd_var_assign: Variable object is not editable\"" \
285 "assign to global_simple"
287 mi_gdb_test "-var-assign linteger 3333" \
288 "\\^done,value=\"3333\"" \
291 mi_gdb_test "-var-evaluate-expression linteger" \
292 "\\^done,value=\"3333\"" \
295 mi_gdb_test "-var-assign lpinteger \"&linteger + 3\"" \
296 "\\^done,value=\"$hex\"" \
297 "assign to lpinteger"
299 mi_gdb_test "-var-evaluate-expression lpinteger" \
300 "\\^done,value=\"$hex\"" \
303 # reset the values to the original ones so that the rest of the file doesn't suffer.
305 mi_gdb_test "-var-assign linteger 4321" \
306 "\\^done,value=\"4321\"" \
309 mi_gdb_test "-var-assign lpinteger &linteger" \
310 "\\^done,value=\"$hex\"" \
311 "assign to lpinteger"
313 mi_gdb_test "-var-assign lcharacter 'z'" \
314 "\\^done,value=\"122 'z'\"" \
315 "assign to lcharacter"
317 mi_gdb_test "-var-evaluate-expression lcharacter" \
318 "\\^done,value=\"122 'z'\"" \
321 mi_gdb_test "-var-assign llong 1313L" \
322 "\\^done,value=\"1313\"" \
324 mi_gdb_test "-var-evaluate-expression llong" \
325 "\\^done,value=\"1313\"" \
327 mi_gdb_test "-var-assign llong 1212L" \
328 "\\^done,value=\"1212\"" \
331 mi_gdb_test "-var-assign lplong &llong+4" \
332 "\\^done,value=\"$hex\"" \
334 mi_gdb_test "-var-evaluate-expression lplong" \
335 "\\^done,value=\"$hex\"" \
337 mi_gdb_test "-var-assign lplong &llong" \
338 "\\^done,value=\"$hex\"" \
341 mi_gdb_test "-var-assign lfloat 3.4567" \
342 "\\^done,value=\"3.45.*\"" \
344 mi_gdb_test "-var-evaluate-expression lfloat" \
345 "\\^done,value=\"3.45.*\"" \
347 mi_gdb_test "-var-assign lfloat 1.2345" \
348 "\\^done,value=\"1.23.*\"" \
351 mi_gdb_test "-var-assign lpfloat &lfloat+4" \
352 "\\^done,value=\"$hex\"" \
355 mi_gdb_test "-var-assign ldouble 5.333318284590435" \
356 "\\^done,value=\"5.333318284590435\"" \
359 mi_gdb_test "-var-assign func do_block_tests" \
360 "\\^done,value=\"$hex <do_block_tests>\"" \
363 mi_gdb_test "-var-assign lsimple.character 'd'" \
364 "\\^done,value=\"100 'd'\"" \
365 "assign to lsimple.character"
367 mi_gdb_test "-var-assign lsimple->integer 222" \
368 "\\^done,value=\"222\"" \
369 "assign to lsimple->integer"
371 mi_gdb_test "-var-assign lsimple.integer 333" \
372 "\\^done,value=\"333\"" \
373 "assign to lsimple.integer"
376 # End of assign tests
379 mi_gdb_test "-break-insert subroutine1" \
380 "\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"subroutine1\",file=\".*var-cmd.c\",line=\"146\",times=\"0\"\}" \
381 "break-insert subroutine1"
382 mi_continue_to "2" "subroutine1" \
383 "\{name=\"i\",value=\"4321\"\},\{name=\"l\",value=\"$hex\"\}" \
384 "var-cmd.c" "146" "continue to subroutine1"
386 # Test: c_variable-2.10
387 # Desc: create variable for locals i,l in subroutine1
388 mi_gdb_test "-var-create i * i" \
389 "\\^done,name=\"i\",numchild=\"0\",type=\"int\"" \
392 mi_gdb_test "-var-create l * l" \
393 "\\^done,name=\"l\",numchild=\"1\",type=\"long int \\*\"" \
396 # Test: c_variable-2.11
397 # Desc: create do_locals_tests local in subroutine1
398 mi_gdb_test "-var-create linteger * linteger" \
399 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
402 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
403 "var-cmd.c" "147" "step at subroutine1"
405 # Test: c_variable-2.12
406 # Desc: change global_simple.integer
407 # Note: This also tests whether we are reporting changes in structs properly.
408 # gdb normally would say that global_simple has changed, but we
409 # special case that, since it is not what a human expects to
413 mi_gdb_test "-var-update *" \
414 "\\^done,changelist=\{FIXME: WHAT IS CORRECT HERE\}" \
415 "update all vars: changed FIXME"
418 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
419 "var-cmd.c" "148" "step at subroutine1 (2)"
421 # Test: c_variable-2.13
422 # Desc: change subroutine1 local i
423 mi_gdb_test "-var-update *" \
424 "\\^done,changelist=\{name=\"i\",in_scope=\"true\",type_changed=\"false\"\}" \
425 "update all vars: i changed"
427 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
428 "var-cmd.c" "149" "step at subroutine1 (3)"
430 # Test: c_variable-2.14
431 # Desc: change do_locals_tests local llong
432 mi_gdb_test "-var-update *" \
433 "\\^done,changelist=\{name=\"llong\",in_scope=\"true\",type_changed=\"false\"\}" \
434 "update all vars: llong changed"
436 mi_next_to "do_locals_tests" "" "var-cmd.c" "136" "next out of subroutine1"
438 # Test: c_variable-2.15
439 # Desc: check for out of scope subroutine1 locals
440 mi_gdb_test "-var-update *" \
441 "\\^done,changelist=\{name=\"l\",in_scope=\"false\",name=\"i\",in_scope=\"false\"\}" \
442 "update all vars: all now out of scope"
444 # Done with locals/globals tests. Erase all variables
445 #delete_all_variables
446 mi_gdb_test "-var-delete global_simple" \
447 "\\^done,ndeleted=\"1\"" \
450 mi_gdb_test "-var-delete linteger" \
451 "\\^done,ndeleted=\"1\"" \
452 "delete var linteger"
454 mi_gdb_test "-var-delete lpinteger" \
455 "\\^done,ndeleted=\"1\"" \
456 "delete var lpinteger"
458 mi_gdb_test "-var-delete lcharacter" \
459 "\\^done,ndeleted=\"1\"" \
460 "delete var lcharacter"
462 mi_gdb_test "-var-delete lpcharacter" \
463 "\\^done,ndeleted=\"1\"" \
464 "delete var lpcharacter"
466 mi_gdb_test "-var-delete llong" \
467 "\\^done,ndeleted=\"1\"" \
470 mi_gdb_test "-var-delete lplong" \
471 "\\^done,ndeleted=\"1\"" \
474 mi_gdb_test "-var-delete lfloat" \
475 "\\^done,ndeleted=\"1\"" \
478 mi_gdb_test "-var-delete lpfloat" \
479 "\\^done,ndeleted=\"1\"" \
482 mi_gdb_test "-var-delete ldouble" \
483 "\\^done,ndeleted=\"1\"" \
486 mi_gdb_test "-var-delete lpdouble" \
487 "\\^done,ndeleted=\"1\"" \
488 "delete var lpdouble"
490 mi_gdb_test "-var-delete lsimple" \
491 "\\^done,ndeleted=\"1\"" \
494 mi_gdb_test "-var-delete lpsimple" \
495 "\\^done,ndeleted=\"1\"" \
496 "delete var lpsimple"
498 mi_gdb_test "-var-delete func" \
499 "\\^done,ndeleted=\"1\"" \
502 mi_gdb_test "-var-delete lsimple.character" \
503 "\\^done,ndeleted=\"1\"" \
504 "delete var lsimple.character"
506 mi_gdb_test "-var-delete lsimple->integer" \
507 "\\^done,ndeleted=\"1\"" \
508 "delete var lsimple->integer"
510 mi_gdb_test "-var-delete lsimple.integer" \
511 "\\^done,ndeleted=\"1\"" \
512 "delete var lsimple.integer"
514 mi_gdb_test "-var-delete i" \
515 "\\^done,ndeleted=\"1\"" \
518 mi_gdb_test "-var-delete l" \
519 "\\^done,ndeleted=\"1\"" \