1 # Copyright
1999, 2000, 2001, 2002, 2003, 2004, 2004 Free Software
4 # This
Program Is Free software
; you can redistribute it and
/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation
; either version
2 of the License
, or
7 #
(at your option
) any later version.
9 # This
program is distributed in the hope that it will be useful
,
10 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License
for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this
program; if not
, write to the Free Software
16 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
18 # Test essential Machine interface
(MI
) operations
20 # Verify that
, using the MI
, we can create
, update, delete variables.
24 load_lib mi
-support.exp
32 set testfile
"var-cmd"
33 set srcfile $
{testfile
}.c
34 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
35 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
36 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
40 mi_gdb_reinitialize_dir $srcdir
/$subdir
41 mi_gdb_load $
{binfile
}
46 #
Variable Creation tests #
50 # Test
: c_variable
-1.1
51 # Desc
: Create global
variable
53 mi_gdb_test
"111-var-create global_simple * global_simple" \
54 "111\\^done,name=\"global_simple\",numchild=\"6\",type=\"simpleton\"" \
55 "create global variable"
57 # Test
: c_variable
-1.2
58 # Desc
: Create non
-existent
variable
60 mi_gdb_test
"112-var-create bogus_unknown_variable * bogus_unknown_variable" \
61 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*112\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
62 "create non-existent variable"
64 # Test
: c_variable
-1.3
65 # Desc
: Create out of scope
variable
67 mi_gdb_test
"113-var-create argc * argc" \
68 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*113\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
69 "create out of scope variable"
71 mi_runto do_locals_tests
73 # Test
: c_variable
-1.4
74 # Desc
: create local variables
76 mi_gdb_test
"-var-create linteger * linteger" \
77 "\\^done,name=\"linteger\",numchild=\"0\",type=\"int\"" \
78 "create local variable linteger"
80 mi_gdb_test
"-var-create lpinteger * lpinteger" \
81 "\\^done,name=\"lpinteger\",numchild=\"1\",type=\"int \\*\"" \
82 "create local variable lpinteger"
84 mi_gdb_test
"-var-create lcharacter * lcharacter" \
85 "\\^done,name=\"lcharacter\",numchild=\"0\",type=\"char\"" \
86 "create local variablelcharacter "
88 mi_gdb_test
"-var-create lpcharacter * lpcharacter" \
89 "\\^done,name=\"lpcharacter\",numchild=\"1\",type=\"char \\*\"" \
90 "create local variable lpcharacter"
92 mi_gdb_test
"-var-create llong * llong" \
93 "\\^done,name=\"llong\",numchild=\"0\",type=\"long int\"" \
94 "create local variable llong"
96 mi_gdb_test
"-var-create lplong * lplong" \
97 "\\^done,name=\"lplong\",numchild=\"1\",type=\"long int \\*\"" \
98 "create local variable lplong"
100 mi_gdb_test
"-var-create lfloat * lfloat" \
101 "\\^done,name=\"lfloat\",numchild=\"0\",type=\"float\"" \
102 "create local variable lfloat"
104 mi_gdb_test
"-var-create lpfloat * lpfloat" \
105 "\\^done,name=\"lpfloat\",numchild=\"1\",type=\"float \\*\"" \
106 "create local variable lpfloat"
108 mi_gdb_test
"-var-create ldouble * ldouble" \
109 "\\^done,name=\"ldouble\",numchild=\"0\",type=\"double\"" \
110 "create local variable ldouble"
112 mi_gdb_test
"-var-create lpdouble * lpdouble" \
113 "\\^done,name=\"lpdouble\",numchild=\"1\",type=\"double \\*\"" \
114 "create local variable lpdouble"
116 mi_gdb_test
"-var-create lsimple * lsimple" \
117 "\\^done,name=\"lsimple\",numchild=\"6\",type=\"struct _simple_struct\"" \
118 "create local variable lsimple"
120 mi_gdb_test
"-var-create lpsimple * lpsimple" \
121 "\\^done,name=\"lpsimple\",numchild=\"6\",type=\"struct _simple_struct \\*\"" \
122 "create local variable lpsimple"
124 mi_gdb_test
"-var-create func * func" \
125 "\\^done,name=\"func\",numchild=\"0\",type=\"void \\(\\*\\)\\((void|)\\)\"" \
126 "create local variable func"
128 # Test
: c_variable
-1.5
129 # Desc
: create lsimple.character
130 mi_gdb_test
"-var-create lsimple.character * lsimple.character" \
131 "\\^done,name=\"lsimple.character\",numchild=\"0\",type=\"char\"" \
132 "create lsimple.character"
134 # Test
: c_variable
-1.6
135 # Desc
: create lpsimple
->integer
136 mi_gdb_test
"-var-create lsimple->integer * lsimple->integer" \
137 "\\^done,name=\"lsimple->integer\",numchild=\"0\",type=\"int\"" \
138 "create lsimple->integer"
140 # Test
: c_variable
-1.7
141 # Desc
: ceate lsimple.
integer
142 mi_gdb_test
"-var-create lsimple.integer * lsimple.integer" \
143 "\\^done,name=\"lsimple.integer\",numchild=\"0\",type=\"int\"" \
144 "create lsimple->integer"
147 # Test
: c_variable
-1.9
148 # Desc
: create type
name
149 # Type names
(like
int, long
, etc..
) are all proper expressions to gdb.
150 # make sure
variable code does not allow users to create variables
, though.
151 mi_gdb_test
"-var-create int * int" \
152 "&\"Attempt to use a type name as an expression.\\\\n\".*&\"mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
158 # Value changed tests #
162 # Test
: c_variable
-2.1
163 # Desc
: check whether
values changed at do_block_tests
164 mi_gdb_test
"-var-update *" \
165 "\\^done,changelist=\\\[\\\]" \
168 # Step over
"linteger = 1234;"
169 set line_dlt_linteger
[gdb_get_line_number
"lpinteger = &linteger;"]
170 mi_step_to
"do_locals_tests" "" "var-cmd.c" $line_dlt_linteger "step at do_locals_test"
172 # Test
: c_variable
-2.2
173 # Desc
: check whether only linteger changed
values
174 mi_gdb_test
"-var-update *" \
175 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
176 "update all vars: linteger changed"
178 # Step over
"lpinteger = &linteger;"
179 mi_step_to
"do_locals_tests" "" "var-cmd.c" [expr $line_dlt_linteger + 1] "step at do_locals_tests (2)"
181 # Test
: c_variable
-2.3
182 # Desc
: check whether only lpinteger changed
183 mi_gdb_test
"-var-update *" \
184 "\\^done,changelist=\\\[\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
185 "update all vars: lpinteger changed"
187 # Step over
"lcharacter = 'a';"
188 mi_step_to
"do_locals_tests" "" "var-cmd.c" [expr $line_dlt_linteger + 2] "step at do_locals_tests (3)"
190 # Test
: c_variable
-2.4
191 # Desc
: check whether only lcharacter changed
192 mi_gdb_test
"-var-update *" \
193 "\\^done,changelist=\\\[\{name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
194 "update all vars: lcharacter changed"
196 # Step over
"lpcharacter = &lcharacter;"
197 mi_step_to
"do_locals_tests" "" "var-cmd.c" [expr $line_dlt_linteger + 3] "step at do_locals_tests (4)"
199 # Test
: c_variable
-2.5
200 # Desc
: check whether only lpcharacter changed
201 mi_gdb_test
"-var-update *" \
202 "\\^done,changelist=\\\[\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
203 "update all vars: lpcharacter changed"
211 # ldouble
= 2.718281828459045;
212 # lpdouble
= &ldouble
;
213 # lsimple.
integer = 1234;
214 # lsimple.unsigned_integer
= 255;
215 # lsimple.character
= 'a';
217 mi_execute_to
"exec-step 9" "end-stepping-range" "do_locals_tests" "" \
218 "var-cmd.c" [expr $line_dlt_linteger + 12] "" "step at do_locals_tests (5)"
220 # Test
: c_variable
-2.6
221 # Desc
: check whether llong
, lplong
, lfloat
, lpfloat
, ldouble
, lpdouble
, lsimple.
integer,
222 # lsimple.unsigned_character lsimple.
integer lsimple.character changed
223 mi_gdb_test
"-var-update *" \
224 "\\^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\"\}\\\]" \
225 "update all vars: many changed"
228 # lsimple.signed_character
= 21;
229 # lsimple.char_ptr
= &lcharacter
;
230 # lpsimple
= &lsimple
;
233 set line_dlt_4321
[gdb_get_line_number
"linteger = 4321;"]
235 mi_execute_to
"exec-step 4" "end-stepping-range" "do_locals_tests" "" \
236 "var-cmd.c" $line_dlt_4321 "" "step at do_locals_tests (6)"
238 # Test
: c_variable
-2.7
239 # Desc
: check whether
(lsimple.signed_character
, lsimple.char_ptr
) lpsimple
, func changed
240 mi_gdb_test
"-var-update *" \
241 "\\^done,changelist=\\\[\{name=\"func\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"lpsimple\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
242 "update all vars: func and lpsimple changed"
249 # ldouble
= 5.498548281828172;
250 # lsimple.
integer = 255;
251 # lsimple.unsigned_integer
= 4321;
252 # lsimple.character
= 'b';
254 mi_execute_to
"exec-step 8" "end-stepping-range" "do_locals_tests" "" \
255 "var-cmd.c" [expr $line_dlt_4321 + 8] "" "step at do_locals_tests (7)"
257 # Test
: c_variable
-2.8
258 # Desc
: check whether linteger
, lcharacter
, llong
, lfoat
, ldouble
, lsimple.
integer,
259 # lpsimple.
integer lsimple.character changed
260 # Note
: this test also checks that lpsimple
->integer and lsimple.
integer have
261 # changed
(they are the same
)
262 mi_gdb_test
"-var-update *" \
263 "\\^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\"\}\\\]" \
264 "update all vars: func and lpsimple changed"
269 # Test assignment to variables. More tests
on assignment are in other files.
272 mi_gdb_test
"-var-assign global_simple 0" \
273 "&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msg=\"mi_cmd_var_assign: Variable object is not editable\"" \
274 "assign to global_simple"
276 mi_gdb_test
"-var-assign linteger 3333" \
277 "\\^done,value=\"3333\"" \
280 mi_gdb_test
"-var-update *" \
281 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
282 "update all vars: linteger changed after assign"
284 mi_gdb_test
"-var-assign linteger 3333" \
285 "\\^done,value=\"3333\"" \
286 "assign to linteger again, same value"
288 mi_gdb_test
"-var-update *" \
289 "\\^done,changelist=\\\[\\\]" \
290 "update all vars: linteger not changed after same assign"
292 mi_gdb_test
"-var-evaluate-expression linteger" \
293 "\\^done,value=\"3333\"" \
296 mi_gdb_test
"-var-assign lpinteger \"&linteger + 3\"" \
297 "\\^done,value=\"$hex\"" \
298 "assign to lpinteger"
300 mi_gdb_test
"-var-update *" \
301 "\\^done,changelist=\\\[\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
302 "update all vars: lpinteger changed after assign"
304 mi_gdb_test
"-var-update *" \
305 "\\^done,changelist=\\\[\\\]" \
306 "update all vars: no changes on second update"
308 mi_gdb_test
"-var-evaluate-expression lpinteger" \
309 "\\^done,value=\"$hex\"" \
312 # reset the
values to the original ones so that the rest of the file doesn
't suffer.
314 mi_gdb_test "-var-assign linteger 4321" \
315 "\\^done,value=\"4321\"" \
318 mi_gdb_test "-var-assign lpinteger &linteger" \
319 "\\^done,value=\"$hex\"" \
320 "assign to lpinteger"
322 mi_gdb_test "-var-assign lcharacter 'z
'" \
323 "\\^done,value=\"122 'z
'\"" \
324 "assign to lcharacter"
326 mi_gdb_test "-var-evaluate-expression lcharacter" \
327 "\\^done,value=\"122 'z
'\"" \
330 mi_gdb_test "-var-assign llong 1313L" \
331 "\\^done,value=\"1313\"" \
333 mi_gdb_test "-var-evaluate-expression llong" \
334 "\\^done,value=\"1313\"" \
336 mi_gdb_test "-var-assign llong 1212L" \
337 "\\^done,value=\"1212\"" \
340 mi_gdb_test "-var-assign lplong &llong+4" \
341 "\\^done,value=\"$hex\"" \
343 mi_gdb_test "-var-evaluate-expression lplong" \
344 "\\^done,value=\"$hex\"" \
346 mi_gdb_test "-var-assign lplong &llong" \
347 "\\^done,value=\"$hex\"" \
350 mi_gdb_test "-var-assign lfloat 3.4567" \
351 "\\^done,value=\"3.45.*\"" \
353 mi_gdb_test "-var-evaluate-expression lfloat" \
354 "\\^done,value=\"3.45.*\"" \
356 mi_gdb_test "-var-assign lfloat 1.2345" \
357 "\\^done,value=\"1.23.*\"" \
360 mi_gdb_test "-var-assign lpfloat &lfloat+4" \
361 "\\^done,value=\"$hex\"" \
364 mi_gdb_test "-var-assign ldouble 5.333318284590435" \
365 "\\^done,value=\"5.333318284590435\"" \
368 mi_gdb_test "-var-assign func do_block_tests" \
369 "\\^done,value=\"$hex <do_block_tests>\"" \
372 mi_gdb_test "-var-assign lsimple.character 'd
'" \
373 "\\^done,value=\"100 'd
'\"" \
374 "assign to lsimple.character"
376 mi_gdb_test "-var-assign lsimple->integer 222" \
377 "\\^done,value=\"222\"" \
378 "assign to lsimple->integer"
380 mi_gdb_test "-var-assign lsimple.integer 333" \
381 "\\^done,value=\"333\"" \
382 "assign to lsimple.integer"
385 # End of assign tests
388 set line_subroutine1_body [gdb_get_line_number "global_simple.integer = i + 3;"]
390 mi_gdb_test "-break-insert subroutine1" \
391 "\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"subroutine1\",file=\".*var-cmd.c\",line=\"$line_subroutine1_body\",times=\"0\"\}" \
392 "break-insert subroutine1"
393 mi_continue_to "2" "subroutine1" \
394 "\{name=\"i\",value=\"4321\"\},\{name=\"l\",value=\"$hex\"\}" \
395 "var-cmd.c" $line_subroutine1_body "continue to subroutine1"
397 # Test: c_variable-2.10
398 # Desc: create variable for locals i,l in subroutine1
399 mi_gdb_test "-var-create i * i" \
400 "\\^done,name=\"i\",numchild=\"0\",type=\"int\"" \
403 mi_gdb_test "-var-create l * l" \
404 "\\^done,name=\"l\",numchild=\"1\",type=\"long int \\*\"" \
407 # Test: c_variable-2.11
408 # Desc: create do_locals_tests local in subroutine1
409 mi_gdb_test "-var-create linteger * linteger" \
410 "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
413 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
414 "var-cmd.c" [expr $line_subroutine1_body + 1] "step at subroutine1"
416 # Test: c_variable-2.12
417 # Desc: change global_simple.integer
418 # Note: This also tests whether we are reporting changes in structs properly.
419 # gdb normally would say that global_simple has changed, but we
420 # special case that, since it is not what a human expects to
424 mi_gdb_test "-var-update *" \
425 "\\^done,changelist=\{FIXME: WHAT IS CORRECT HERE\}" \
426 "update all vars: changed FIXME"
429 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
430 "var-cmd.c" [expr $line_subroutine1_body + 2] "step at subroutine1 (2)"
432 # Test: c_variable-2.13
433 # Desc: change subroutine1 local i
434 mi_gdb_test "-var-update *" \
435 "\\^done,changelist=\\\[\{name=\"i\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
436 "update all vars: i changed"
438 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
439 "var-cmd.c" [expr $line_subroutine1_body + 3] "step at subroutine1 (3)"
441 # Test: c_variable-2.14
442 # Desc: change do_locals_tests local llong
443 mi_gdb_test "-var-update *" \
444 "\\^done,changelist=\\\[\{name=\"llong\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
445 "update all vars: llong changed"
447 set line_dlt_call_subroutine1 [gdb_get_line_number "subroutine1 (linteger, &llong);"]
448 mi_next_to "do_locals_tests" "" "var-cmd.c" \
449 [expr $line_dlt_call_subroutine1 + 1] "next out of subroutine1"
451 # Test: c_variable-2.15
452 # Desc: check for out of scope subroutine1 locals
453 mi_gdb_test "-var-update *" \
454 "\\^done,changelist=\\\[\{name=\"l\",in_scope=\"false\"\},\{name=\"i\",in_scope=\"false\"\}\\\]" \
455 "update all vars: all now out of scope"
457 # Done with locals/globals tests. Erase all variables
458 #delete_all_variables
459 mi_gdb_test "-var-delete global_simple" \
460 "\\^done,ndeleted=\"1\"" \
463 mi_gdb_test "-var-delete linteger" \
464 "\\^done,ndeleted=\"1\"" \
465 "delete var linteger"
467 mi_gdb_test "-var-delete lpinteger" \
468 "\\^done,ndeleted=\"1\"" \
469 "delete var lpinteger"
471 mi_gdb_test "-var-delete lcharacter" \
472 "\\^done,ndeleted=\"1\"" \
473 "delete var lcharacter"
475 mi_gdb_test "-var-delete lpcharacter" \
476 "\\^done,ndeleted=\"1\"" \
477 "delete var lpcharacter"
479 mi_gdb_test "-var-delete llong" \
480 "\\^done,ndeleted=\"1\"" \
483 mi_gdb_test "-var-delete lplong" \
484 "\\^done,ndeleted=\"1\"" \
487 mi_gdb_test "-var-delete lfloat" \
488 "\\^done,ndeleted=\"1\"" \
491 mi_gdb_test "-var-delete lpfloat" \
492 "\\^done,ndeleted=\"1\"" \
495 mi_gdb_test "-var-delete ldouble" \
496 "\\^done,ndeleted=\"1\"" \
499 mi_gdb_test "-var-delete lpdouble" \
500 "\\^done,ndeleted=\"1\"" \
501 "delete var lpdouble"
503 mi_gdb_test "-var-delete lsimple" \
504 "\\^done,ndeleted=\"1\"" \
507 mi_gdb_test "-var-delete lpsimple" \
508 "\\^done,ndeleted=\"1\"" \
509 "delete var lpsimple"
511 mi_gdb_test "-var-delete func" \
512 "\\^done,ndeleted=\"1\"" \
515 mi_gdb_test "-var-delete lsimple.character" \
516 "\\^done,ndeleted=\"1\"" \
517 "delete var lsimple.character"
519 mi_gdb_test "-var-delete lsimple->integer" \
520 "\\^done,ndeleted=\"1\"" \
521 "delete var lsimple->integer"
523 mi_gdb_test "-var-delete lsimple.integer" \
524 "\\^done,ndeleted=\"1\"" \
525 "delete var lsimple.integer"
527 mi_gdb_test "-var-delete i" \
528 "\\^done,ndeleted=\"1\"" \
531 mi_gdb_test "-var-delete l" \
532 "\\^done,ndeleted=\"1\"" \
535 # Test whether we can follow the name of a variable through multiple
537 mi_gdb_test "-break-insert do_special_tests" \
539 "set breakpoint at do_special_tests"
541 mi_continue_to {.*} do_special_tests {.*} {.*var-cmd.c} {.*} {stop in do_special_tests}
543 mi_gdb_test "-var-create selected_a @ a" \
544 {\^done,name="selected_a",numchild="0",type="int"} \
547 mi_gdb_test "-break-insert incr_a" \
549 "set breakpoint at incr_a"
551 mi_continue_to {.*} incr_a {.*} {.*var-cmd.c} {.*} {stop in incr_a}
553 mi_gdb_test "-var-update selected_a" \
554 "\\^done,changelist=\\\[\{name=\"selected_a\",in_scope=\"true\",new_type=\"char\",new_num_children=\"0\"\}\\\]" \
555 "update selected_a in incr_a"
557 mi_next "step a line in incr_a"
558 mi_next "return from incr_a to do_special_tests"
560 mi_gdb_test "-var-update selected_a" \
561 "\\^done,changelist=\\\[\{name=\"selected_a\",in_scope=\"true\",new_type=\"int\",new_num_children=\"0\"\}\\\]" \
562 "update selected_a in do_special_tests"