1 # Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
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_runto do_locals_tests
75 # Test: c_variable-1.4
76 # Desc: create local variables
78 mi_gdb_test "-var-create linteger * linteger" \
79 "\\^done,name=\"linteger\",numchild=\"0\",type=\"int\"" \
80 "create local variable linteger"
82 mi_gdb_test "-var-create lpinteger * lpinteger" \
83 "\\^done,name=\"lpinteger\",numchild=\"1\",type=\"int \\*\"" \
84 "create local variable lpinteger"
86 mi_gdb_test "-var-create lcharacter * lcharacter" \
87 "\\^done,name=\"lcharacter\",numchild=\"0\",type=\"char\"" \
88 "create local variablelcharacter "
90 mi_gdb_test "-var-create lpcharacter * lpcharacter" \
91 "\\^done,name=\"lpcharacter\",numchild=\"1\",type=\"char \\*\"" \
92 "create local variable lpcharacter"
94 mi_gdb_test "-var-create llong * llong" \
95 "\\^done,name=\"llong\",numchild=\"0\",type=\"long int\"" \
96 "create local variable llong"
98 mi_gdb_test "-var-create lplong * lplong" \
99 "\\^done,name=\"lplong\",numchild=\"1\",type=\"long int \\*\"" \
100 "create local variable lplong"
102 mi_gdb_test "-var-create lfloat * lfloat" \
103 "\\^done,name=\"lfloat\",numchild=\"0\",type=\"float\"" \
104 "create local variable lfloat"
106 mi_gdb_test "-var-create lpfloat * lpfloat" \
107 "\\^done,name=\"lpfloat\",numchild=\"1\",type=\"float \\*\"" \
108 "create local variable lpfloat"
110 mi_gdb_test "-var-create ldouble * ldouble" \
111 "\\^done,name=\"ldouble\",numchild=\"0\",type=\"double\"" \
112 "create local variable ldouble"
114 mi_gdb_test "-var-create lpdouble * lpdouble" \
115 "\\^done,name=\"lpdouble\",numchild=\"1\",type=\"double \\*\"" \
116 "create local variable lpdouble"
118 mi_gdb_test "-var-create lsimple * lsimple" \
119 "\\^done,name=\"lsimple\",numchild=\"6\",type=\"struct _simple_struct\"" \
120 "create local variable lsimple"
122 mi_gdb_test "-var-create lpsimple * lpsimple" \
123 "\\^done,name=\"lpsimple\",numchild=\"6\",type=\"struct _simple_struct \\*\"" \
124 "create local variable lpsimple"
126 mi_gdb_test "-var-create func * func" \
127 "\\^done,name=\"func\",numchild=\"0\",type=\"void \\(\\*\\)\\((void|)\\)\"" \
128 "create local variable func"
130 # Test: c_variable-1.5
131 # Desc: create lsimple.character
132 mi_gdb_test "-var-create lsimple.character * lsimple.character" \
133 "\\^done,name=\"lsimple.character\",numchild=\"0\",type=\"char\"" \
134 "create lsimple.character"
136 # Test: c_variable-1.6
137 # Desc: create lpsimple->integer
138 mi_gdb_test "-var-create lsimple->integer * lsimple->integer" \
139 "\\^done,name=\"lsimple->integer\",numchild=\"0\",type=\"int\"" \
140 "create lsimple->integer"
142 # Test: c_variable-1.7
143 # Desc: ceate lsimple.integer
144 mi_gdb_test "-var-create lsimple.integer * lsimple.integer" \
145 "\\^done,name=\"lsimple.integer\",numchild=\"0\",type=\"int\"" \
146 "create lsimple->integer"
149 # Test: c_variable-1.9
150 # Desc: create type name
151 # Type names (like int, long, etc..) are all proper expressions to gdb.
152 # make sure variable code does not allow users to create variables, though.
153 mi_gdb_test "-var-create int * int" \
154 "&\"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\"" \
160 # Value changed tests #
164 # Test: c_variable-2.1
165 # Desc: check whether values changed at do_block_tests
166 mi_gdb_test "-var-update *" \
167 "\\^done,changelist=\\\[\\\]" \
170 # Step over "linteger = 1234;"
171 mi_step_to "do_locals_tests" "" "var-cmd.c" "107" "step at do_locals_test"
173 # Test: c_variable-2.2
174 # Desc: check whether only linteger changed values
175 mi_gdb_test "-var-update *" \
176 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
177 "update all vars: linteger changed"
179 # Step over "lpinteger = &linteger;"
180 mi_step_to "do_locals_tests" "" "var-cmd.c" 108 "step at do_locals_tests (2)"
182 # Test: c_variable-2.3
183 # Desc: check whether only lpinteger changed
184 mi_gdb_test "-var-update *" \
185 "\\^done,changelist=\\\[\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
186 "update all vars: lpinteger changed"
188 # Step over "lcharacter = 'a';"
189 mi_step_to "do_locals_tests" "" "var-cmd.c" "109" "step at do_locals_tests (3)"
191 # Test: c_variable-2.4
192 # Desc: check whether only lcharacter changed
193 mi_gdb_test "-var-update *" \
194 "\\^done,changelist=\\\[\{name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
195 "update all vars: lcharacter changed"
197 # Step over "lpcharacter = &lcharacter;"
198 mi_step_to "do_locals_tests" "" "var-cmd.c" "110" "step at do_locals_tests (4)"
200 # Test: c_variable-2.5
201 # Desc: check whether only lpcharacter changed
202 mi_gdb_test "-var-update *" \
203 "\\^done,changelist=\\\[\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
204 "update all vars: lpcharacter changed"
212 # ldouble = 2.718281828459045;
213 # lpdouble = &ldouble;
214 # lsimple.integer = 1234;
215 # lsimple.unsigned_integer = 255;
216 # lsimple.character = 'a';
218 mi_execute_to "exec-step 9" "end-stepping-range" "do_locals_tests" "" \
219 "var-cmd.c" "119" "" "step at do_locals_tests (5)"
221 # Test: c_variable-2.6
222 # Desc: check whether llong, lplong, lfloat, lpfloat, ldouble, lpdouble, lsimple.integer,
223 # lsimple.unsigned_character lsimple.integer lsimple.character changed
224 mi_gdb_test "-var-update *" \
225 "\\^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\"\}\\\]" \
226 "update all vars: many changed"
229 # lsimple.signed_character = 21;
230 # lsimple.char_ptr = &lcharacter;
231 # lpsimple = &lsimple;
234 mi_execute_to "exec-step 4" "end-stepping-range" "do_locals_tests" "" \
235 "var-cmd.c" "125" "" "step at do_locals_tests (6)"
237 # Test: c_variable-2.7
238 # Desc: check whether (lsimple.signed_character, lsimple.char_ptr) lpsimple, func changed
239 mi_gdb_test "-var-update *" \
240 "\\^done,changelist=\\\[\{name=\"func\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"lpsimple\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
241 "update all vars: func and lpsimple changed"
248 # ldouble = 5.498548281828172;
249 # lsimple.integer = 255;
250 # lsimple.unsigned_integer = 4321;
251 # lsimple.character = 'b';
253 mi_execute_to "exec-step 8" "end-stepping-range" "do_locals_tests" "" \
254 "var-cmd.c" "133" "" "step at do_locals_tests (7)"
256 # Test: c_variable-2.8
257 # Desc: check whether linteger, lcharacter, llong, lfoat, ldouble, lsimple.integer,
258 # lpsimple.integer lsimple.character changed
259 # Note: this test also checks that lpsimple->integer and lsimple.integer have
260 # changed (they are the same)
261 mi_gdb_test "-var-update *" \
262 "\\^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\"\}\\\]" \
263 "update all vars: func and lpsimple changed"
268 # Test assignment to variables. More tests on assignment are in other files.
271 mi_gdb_test "-var-assign global_simple 0" \
272 "&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msg=\"mi_cmd_var_assign: Variable object is not editable\"" \
273 "assign to global_simple"
275 mi_gdb_test "-var-assign linteger 3333" \
276 "\\^done,value=\"3333\"" \
279 mi_gdb_test "-var-update *" \
280 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
281 "update all vars: linteger changed after assign"
283 mi_gdb_test "-var-assign linteger 3333" \
284 "\\^done,value=\"3333\"" \
285 "assign to linteger again, same value"
287 mi_gdb_test "-var-update *" \
288 "\\^done,changelist=\\\[\\\]" \
289 "update all vars: linteger not changed after same assign"
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-update *" \
300 "\\^done,changelist=\\\[\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
301 "update all vars: lpinteger changed after assign"
303 mi_gdb_test "-var-update *" \
304 "\\^done,changelist=\\\[\\\]" \
305 "update all vars: no changes on second update"
307 mi_gdb_test "-var-evaluate-expression lpinteger" \
308 "\\^done,value=\"$hex\"" \
311 # reset the values to the original ones so that the rest of the file doesn't suffer.
313 mi_gdb_test "-var-assign linteger 4321" \
314 "\\^done,value=\"4321\"" \
317 mi_gdb_test "-var-assign lpinteger &linteger" \
318 "\\^done,value=\"$hex\"" \
319 "assign to lpinteger"
321 mi_gdb_test "-var-assign lcharacter 'z'" \
322 "\\^done,value=\"122 'z'\"" \
323 "assign to lcharacter"
325 mi_gdb_test "-var-evaluate-expression lcharacter" \
326 "\\^done,value=\"122 'z'\"" \
329 mi_gdb_test "-var-assign llong 1313L" \
330 "\\^done,value=\"1313\"" \
332 mi_gdb_test "-var-evaluate-expression llong" \
333 "\\^done,value=\"1313\"" \
335 mi_gdb_test "-var-assign llong 1212L" \
336 "\\^done,value=\"1212\"" \
339 mi_gdb_test "-var-assign lplong &llong+4" \
340 "\\^done,value=\"$hex\"" \
342 mi_gdb_test "-var-evaluate-expression lplong" \
343 "\\^done,value=\"$hex\"" \
345 mi_gdb_test "-var-assign lplong &llong" \
346 "\\^done,value=\"$hex\"" \
349 mi_gdb_test "-var-assign lfloat 3.4567" \
350 "\\^done,value=\"3.45.*\"" \
352 mi_gdb_test "-var-evaluate-expression lfloat" \
353 "\\^done,value=\"3.45.*\"" \
355 mi_gdb_test "-var-assign lfloat 1.2345" \
356 "\\^done,value=\"1.23.*\"" \
359 mi_gdb_test "-var-assign lpfloat &lfloat+4" \
360 "\\^done,value=\"$hex\"" \
363 mi_gdb_test "-var-assign ldouble 5.333318284590435" \
364 "\\^done,value=\"5.333318284590435\"" \
367 mi_gdb_test "-var-assign func do_block_tests" \
368 "\\^done,value=\"$hex <do_block_tests>\"" \
371 mi_gdb_test "-var-assign lsimple.character 'd'" \
372 "\\^done,value=\"100 'd'\"" \
373 "assign to lsimple.character"
375 mi_gdb_test "-var-assign lsimple->integer 222" \
376 "\\^done,value=\"222\"" \
377 "assign to lsimple->integer"
379 mi_gdb_test "-var-assign lsimple.integer 333" \
380 "\\^done,value=\"333\"" \
381 "assign to lsimple.integer"
384 # End of assign tests
387 mi_gdb_test "-break-insert subroutine1" \
388 "\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"subroutine1\",file=\".*var-cmd.c\",line=\"146\",times=\"0\"\}" \
389 "break-insert subroutine1"
390 mi_continue_to "2" "subroutine1" \
391 "\{name=\"i\",value=\"4321\"\},\{name=\"l\",value=\"$hex\"\}" \
392 "var-cmd.c" "146" "continue to subroutine1"
394 # Test: c_variable-2.10
395 # Desc: create variable for locals i,l in subroutine1
396 mi_gdb_test "-var-create i * i" \
397 "\\^done,name=\"i\",numchild=\"0\",type=\"int\"" \
400 mi_gdb_test "-var-create l * l" \
401 "\\^done,name=\"l\",numchild=\"1\",type=\"long int \\*\"" \
404 # Test: c_variable-2.11
405 # Desc: create do_locals_tests local in subroutine1
406 mi_gdb_test "-var-create linteger * linteger" \
407 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
410 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
411 "var-cmd.c" "147" "step at subroutine1"
413 # Test: c_variable-2.12
414 # Desc: change global_simple.integer
415 # Note: This also tests whether we are reporting changes in structs properly.
416 # gdb normally would say that global_simple has changed, but we
417 # special case that, since it is not what a human expects to
421 mi_gdb_test "-var-update *" \
422 "\\^done,changelist=\{FIXME: WHAT IS CORRECT HERE\}" \
423 "update all vars: changed FIXME"
426 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
427 "var-cmd.c" "148" "step at subroutine1 (2)"
429 # Test: c_variable-2.13
430 # Desc: change subroutine1 local i
431 mi_gdb_test "-var-update *" \
432 "\\^done,changelist=\\\[\{name=\"i\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
433 "update all vars: i changed"
435 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
436 "var-cmd.c" "149" "step at subroutine1 (3)"
438 # Test: c_variable-2.14
439 # Desc: change do_locals_tests local llong
440 mi_gdb_test "-var-update *" \
441 "\\^done,changelist=\\\[\{name=\"llong\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
442 "update all vars: llong changed"
444 mi_next_to "do_locals_tests" "" "var-cmd.c" "136" "next out of subroutine1"
446 # Test: c_variable-2.15
447 # Desc: check for out of scope subroutine1 locals
448 mi_gdb_test "-var-update *" \
449 "\\^done,changelist=\\\[\{name=\"l\",in_scope=\"false\"\},\{name=\"i\",in_scope=\"false\"\}\\\]" \
450 "update all vars: all now out of scope"
452 # Done with locals/globals tests. Erase all variables
453 #delete_all_variables
454 mi_gdb_test "-var-delete global_simple" \
455 "\\^done,ndeleted=\"1\"" \
458 mi_gdb_test "-var-delete linteger" \
459 "\\^done,ndeleted=\"1\"" \
460 "delete var linteger"
462 mi_gdb_test "-var-delete lpinteger" \
463 "\\^done,ndeleted=\"1\"" \
464 "delete var lpinteger"
466 mi_gdb_test "-var-delete lcharacter" \
467 "\\^done,ndeleted=\"1\"" \
468 "delete var lcharacter"
470 mi_gdb_test "-var-delete lpcharacter" \
471 "\\^done,ndeleted=\"1\"" \
472 "delete var lpcharacter"
474 mi_gdb_test "-var-delete llong" \
475 "\\^done,ndeleted=\"1\"" \
478 mi_gdb_test "-var-delete lplong" \
479 "\\^done,ndeleted=\"1\"" \
482 mi_gdb_test "-var-delete lfloat" \
483 "\\^done,ndeleted=\"1\"" \
486 mi_gdb_test "-var-delete lpfloat" \
487 "\\^done,ndeleted=\"1\"" \
490 mi_gdb_test "-var-delete ldouble" \
491 "\\^done,ndeleted=\"1\"" \
494 mi_gdb_test "-var-delete lpdouble" \
495 "\\^done,ndeleted=\"1\"" \
496 "delete var lpdouble"
498 mi_gdb_test "-var-delete lsimple" \
499 "\\^done,ndeleted=\"1\"" \
502 mi_gdb_test "-var-delete lpsimple" \
503 "\\^done,ndeleted=\"1\"" \
504 "delete var lpsimple"
506 mi_gdb_test "-var-delete func" \
507 "\\^done,ndeleted=\"1\"" \
510 mi_gdb_test "-var-delete lsimple.character" \
511 "\\^done,ndeleted=\"1\"" \
512 "delete var lsimple.character"
514 mi_gdb_test "-var-delete lsimple->integer" \
515 "\\^done,ndeleted=\"1\"" \
516 "delete var lsimple->integer"
518 mi_gdb_test "-var-delete lsimple.integer" \
519 "\\^done,ndeleted=\"1\"" \
520 "delete var lsimple.integer"
522 mi_gdb_test "-var-delete i" \
523 "\\^done,ndeleted=\"1\"" \
526 mi_gdb_test "-var-delete l" \
527 "\\^done,ndeleted=\"1\"" \
530 # Test whether we can follow the name of a variable through multiple
532 mi_gdb_test "-break-insert do_special_tests" \
534 "set breakpoint at do_special_tests"
536 mi_continue_to {.*} do_special_tests {.*} {.*var-cmd.c} {.*} {stop in do_special_tests}
538 mi_gdb_test "-var-create selected_a @ a" \
539 {\^done,name="selected_a",numchild="0",type="int"} \
542 mi_gdb_test "-break-insert incr_a" \
544 "set breakpoint at incr_a"
546 mi_continue_to {.*} incr_a {.*} {.*var-cmd.c} {.*} {stop in incr_a}
548 mi_gdb_test "-var-update selected_a" \
549 "\\^done,changelist=\\\[\{name=\"selected_a\",in_scope=\"true\",new_type=\"char\",new_num_children=\"0\"\}\\\]" \
550 "update selected_a in incr_a"
552 mi_next "step a line in incr_a"
553 mi_next "return from incr_a to do_special_tests"
555 mi_gdb_test "-var-update selected_a" \
556 "\\^done,changelist=\\\[\{name=\"selected_a\",in_scope=\"true\",new_type=\"int\",new_num_children=\"0\"\}\\\]" \
557 "update selected_a in do_special_tests"