1 # Copyright 1999-2005, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>.
16 # Test essential Machine interface (MI) operations
18 # Verify that, using the MI, we can create, update, delete variables.
22 load_lib mi-support.exp
30 set testfile "var-cmd"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/mi-var-display
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
34 untested mi-var-display.exp
39 mi_gdb_reinitialize_dir $srcdir/$subdir
40 mi_gdb_load ${binfile}
42 set line_dct_end [gdb_get_line_number "{int a = 0;}"]
44 mi_create_breakpoint "$srcfile:$line_dct_end" 1 keep do_children_tests ".*var-cmd.c" $line_dct_end $hex \
45 "break-insert operation"
48 mi_expect_stop "breakpoint-hit" "do_children_tests" "" ".*var-cmd.c" \
49 $line_dct_end { "" "disp=\"keep\"" } "run to main"
57 # Test: c_variable-6.1
58 # Desc: create variable bar
59 mi_create_varobj bar bar "create local variable bar"
61 # Test: c_variable-6.2
62 # Desc: type of variable bar
63 mi_gdb_test "-var-info-type bar" \
64 "\\^done,type=\"int\"" \
65 "info type variable bar"
67 # Test: c_variable-6.3
68 # Desc: format of variable bar
69 mi_gdb_test "-var-show-format bar" \
70 "\\^done,format=\"natural\"" \
71 "show format variable bar"
73 # Test: c_variable-6.4
74 # Desc: value of variable bar
75 mi_gdb_test "-var-evaluate-expression bar" \
76 "\\^done,value=\"2121\"" \
79 # Test: c_variable-6.5
80 # Desc: change format of bar to hex
81 mi_gdb_test "-var-set-format bar hexadecimal" \
82 "\\^done,format=\"hexadecimal\",value=\"0x849\"" \
83 "set format variable bar"
85 # Test: c_variable-6.6
86 # Desc: value of bar with new format
87 mi_gdb_test "-var-evaluate-expression bar" \
88 "\\^done,value=\"0x849\"" \
89 "eval variable bar with new format"
91 # Test: c_variable-6.7
92 # Desc: change value of bar
93 mi_gdb_test "-var-assign bar 3" \
94 "\\^done,value=\"0x3\"" \
95 "assing to variable bar"
97 mi_gdb_test "-var-set-format bar decimal" \
98 "\\^done,format=\"decimal\",value=\"3\"" \
99 "set format variable bar"
101 mi_gdb_test "-var-evaluate-expression bar" \
102 "\\^done,value=\"3\"" \
103 "eval variable bar with new value"
105 mi_gdb_test "-var-delete bar" \
106 "\\^done,ndeleted=\"1\"" \
109 # Test: c_variable-6.11
110 # Desc: create variable foo
111 mi_create_varobj foo foo "create local variable foo"
113 # Test: c_variable-6.12
114 # Desc: type of variable foo
115 mi_gdb_test "-var-info-type foo" \
116 "\\^done,type=\"int \\*\"" \
117 "info type variable foo"
119 # Test: c_variable-6.13
120 # Desc: format of variable foo
121 mi_gdb_test "-var-show-format foo" \
122 "\\^done,format=\"natural\"" \
123 "show format variable foo"
125 # Test: c_variable-6.14
126 # Desc: value of variable foo
127 mi_gdb_test "-var-evaluate-expression foo" \
128 "\\^done,value=\"$hex\"" \
131 # Test: c_variable-6.15
132 # Desc: change format of var to octal
133 mi_gdb_test "-var-set-format foo octal" \
134 "\\^done,format=\"octal\",value=\"$octal\"" \
135 "set format variable foo"
137 mi_gdb_test "-var-show-format foo" \
138 "\\^done,format=\"octal\"" \
139 "show format variable foo"
141 # Test: c_variable-6.16
142 # Desc: value of foo with new format
143 mi_gdb_test "-var-evaluate-expression foo" \
144 "\\^done,value=\"\[0-7\]+\"" \
147 # Test: c_variable-6.17
148 # Desc: change value of foo
149 mi_gdb_test "-var-assign foo 3" \
150 "\\^done,value=\"03\"" \
151 "assing to variable foo"
153 mi_gdb_test "-var-set-format foo decimal" \
154 "\\^done,format=\"decimal\",value=\"3\"" \
155 "set format variable foo"
157 # Test: c_variable-6.18
158 # Desc: check new value of foo
159 mi_gdb_test "-var-evaluate-expression foo" \
160 "\\^done,value=\"3\"" \
164 # Test: c_variable-6.19
165 # Desc: check optional format parameter of var-evaluate-expression
166 # and check that current format is not changed
167 mi_gdb_test "-var-evaluate-expression -f hex foo" \
168 "\\^done,value=\"0x3\"" \
169 "eval variable foo in hex"
171 mi_gdb_test "-var-show-format foo" \
172 "\\^done,format=\"decimal\"" \
173 "show format variable foo after eval in hex"
175 mi_gdb_test "-var-evaluate-expression -f octal foo" \
176 "\\^done,value=\"03\"" \
177 "eval variable foo in octal"
179 mi_gdb_test "-var-show-format foo" \
180 "\\^done,format=\"decimal\"" \
181 "show format variable foo after eval in octal"
183 mi_gdb_test "-var-evaluate-expression -f decimal foo" \
184 "\\^done,value=\"3\"" \
185 "eval variable foo in decimal"
187 mi_gdb_test "-var-show-format foo" \
188 "\\^done,format=\"decimal\"" \
189 "show format variable foo after eval in decimal"
191 mi_gdb_test "-var-evaluate-expression -f nat foo" \
192 "\\^done,value=\"0x3\"" \
193 "eval variable foo in natural"
195 mi_gdb_test "-var-show-format foo" \
196 "\\^done,format=\"decimal\"" \
197 "show format variable foo after eval in natural"
199 mi_gdb_test "-var-evaluate-expression -f bin foo" \
200 "\\^done,value=\"11\"" \
201 "eval variable foo in binary"
203 mi_gdb_test "-var-show-format foo" \
204 "\\^done,format=\"decimal\"" \
205 "show format variable foo after eval in binary"
207 mi_gdb_test "-var-delete foo" \
208 "\\^done,ndeleted=\"1\"" \
211 # Test: c_variable-6.21
212 # Desc: create variable weird and children
213 mi_create_varobj weird weird "create local variable weird"
215 mi_list_varobj_children weird {
216 {weird.integer integer 0 int}
217 {weird.character character 0 char}
218 {weird.char_ptr char_ptr 1 "char \\*"}
219 {weird.long_int long_int 0 "long int"}
220 {weird.int_ptr_ptr int_ptr_ptr 1 "int \\*\\*"}
221 {weird.long_array long_array 10 "long int \\[10\\]"}
222 {weird.func_ptr func_ptr 0 "void \\(\\*\\)\\((void)?\\)"}
223 {weird.func_ptr_struct func_ptr_struct 0 \
224 "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long int\\))?"}
225 {weird.func_ptr_ptr func_ptr_ptr 0 \
226 "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long int)?\\)"}
227 {weird.u1 u1 4 "union \\{\\.\\.\\.\\}"}
228 {weird.s2 s2 4 "struct \\{\\.\\.\\.\\}"}
229 } "get children local variable weird"
232 # Test: c_variable-6.23
233 # Desc: change format of weird.func_ptr and weird.func_ptr_ptr
234 mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \
235 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
236 "set format variable weird.func_ptr"
238 mi_gdb_test "-var-show-format weird.func_ptr" \
239 "\\^done,format=\"hexadecimal\"" \
240 "show format variable weird.func_ptr"
242 mi_gdb_test "-var-set-format weird.func_ptr_ptr hexadecimal" \
243 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
244 "set format variable weird.func_ptr_ptr"
246 mi_gdb_test "-var-show-format weird.func_ptr_ptr" \
247 "\\^done,format=\"hexadecimal\"" \
248 "show format variable weird.func_ptr_ptr"
250 # Test: c_variable-6.24
251 # Desc: format of weird and children
252 mi_gdb_test "-var-set-format weird natural" \
253 "\\^done,format=\"natural\",value=\"$hex\"" \
254 "set format variable weird"
256 mi_gdb_test "-var-set-format weird.integer natural" \
257 "\\^done,format=\"natural\",value=\"123\"" \
258 "set format variable weird.integer"
260 mi_gdb_test "-var-set-format weird.character natural" \
261 "\\^done,format=\"natural\",value=\"0 '\\\\\\\\000'\"" \
262 "set format variable weird.character"
264 mi_gdb_test "-var-set-format weird.char_ptr natural" \
265 "\\^done,format=\"natural\",value=\"$hex \\\\\"hello\\\\\"\"" \
266 "set format variable weird.char_ptr"
268 mi_gdb_test "-var-set-format weird.long_int natural" \
269 "\\^done,format=\"natural\",value=\"0\"" \
270 "set format variable weird.long_int"
272 mi_gdb_test "-var-set-format weird.int_ptr_ptr natural" \
273 "\\^done,format=\"natural\",value=\"$hex\"" \
274 "set format variable weird.int_ptr_ptr"
276 mi_gdb_test "-var-set-format weird.long_array natural" \
277 "\\^done,format=\"natural\",value=\"\\\[10\\\]\"" \
278 "set format variable weird.long_array"
280 mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \
281 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
282 "set format variable weird.func_ptr"
284 mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
285 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
286 "set format variable weird.func_ptr_struct"
288 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
289 "\\^done,format=\"natural\",value=\"0x0\"" \
290 "set format variable weird.func_ptr_ptr"
292 mi_gdb_test "-var-set-format weird.u1 natural" \
293 "\\^done,format=\"natural\",value=\"\{...\}\"" \
294 "set format variable weird.u1"
296 mi_gdb_test "-var-set-format weird.s2 natural" \
297 "\\^done,format=\"natural\",value=\"\{...\}\"" \
298 "set format variable weird.s2"
300 # Test: c_variable-6.25
301 # Desc: value of weird and children
302 #gdbtk_test c_variable-6.25 {value of weird and children} {
304 # foreach v [lsort [array names var]] f [list x "" "" x x x x d d d d d] {
305 # lappend values [value $v $f]
309 #} {ok ok ok ok ok ok ok ok weird.long_array ok weird.s2 weird.u1}
311 # Test: c_variable-6.26
312 # Desc: change format of weird and children to octal
313 #gdbtk_test c_variable-6.26 {change format of weird and children to octal} {
315 # foreach v [lsort [array names var]] {
316 # $var($v) format octal
317 # lappend formats [$var($v) format]
321 #} {octal octal octal octal octal octal octal octal octal octal octal octal}
323 # Test: c_variable-6.27
324 # Desc: value of weird and children with new format
325 #gdbtk_test c_variable-6.27 {value of foo with new format} {
327 # foreach v [lsort [array names var]] {
328 # lappend values [value $v o]
332 #} {ok ok ok ok ok ok ok ok weird.long_array ok weird.s2 weird.u1}
334 # Test: c_variable-6.30
335 # Desc: create more children of weird
336 #gdbtk_test c_variable-6.30 {create more children of weird} {
337 # foreach v [array names var] {
341 # # Do it twice to get more children
342 # foreach v [array names var] {
346 # lsort [array names var]
347 #} {weird weird.char_ptr weird.character weird.func_ptr weird.func_ptr_ptr weird.func_ptr_struct weird.int_ptr_ptr weird.int_ptr_ptr.*int_ptr_ptr weird.int_ptr_ptr.*int_ptr_ptr.**int_ptr_ptr weird.integer weird.long_array weird.long_array.0 weird.long_array.1 weird.long_array.2 weird.long_array.3 weird.long_array.4 weird.long_array.5 weird.long_array.6 weird.long_array.7 weird.long_array.8 weird.long_array.9 weird.long_int weird.s2 weird.s2.g weird.s2.h weird.s2.i weird.s2.i.0 weird.s2.i.1 weird.s2.i.2 weird.s2.i.3 weird.s2.i.4 weird.s2.i.5 weird.s2.i.6 weird.s2.i.7 weird.s2.i.8 weird.s2.i.9 weird.s2.u2 weird.s2.u2.f weird.s2.u2.u1s1 weird.s2.u2.u1s2 weird.u1 weird.u1.a weird.u1.b weird.u1.c weird.u1.d}
349 # Test: c_variable-6.31
350 # Desc: check that all children of weird change
351 # Ok, obviously things like weird.s2 and weird.u1 will not change!
352 #gdbtk_test *c_variable-6.31 {check that all children of weird change (ops, we are now reporting array names as changed in this case - seems harmless though)} {
353 # $var(weird) value 0x2121
355 #} {{weird.integer weird.character weird.char_ptr weird.long_int weird.int_ptr_ptr weird.int_ptr_ptr.*int_ptr_ptr weird.int_ptr_ptr.*int_ptr_ptr.**int_ptr_ptr weird.long_array.0 weird.long_array.1 weird.long_array.2 weird.long_array.3 weird.long_array.4 weird.long_array.5 weird.long_array.6 weird.long_array.7 weird.long_array.8 weird.long_array.9 weird.func_ptr weird.func_ptr_struct weird.func_ptr_ptr weird.u1.a weird.u1.b weird.u1.c weird.u1.d weird.s2.u2.f weird.s2.g weird.s2.h weird.s2.i.0 weird.s2.i.1 weird.s2.i.2 weird.s2.i.3 weird.s2.i.4 weird.s2.i.5 weird.s2.i.6 weird.s2.i.7 weird.s2.i.8 weird.s2.i.9} {weird.s2.i weird.s2.u2 weird weird.s2.u2.u1s1 weird.s2.u2.u1s2 weird.s2 weird.long_array weird.u1} {}}
357 mi_gdb_test "-var-delete weird" \
358 "\\^done,ndeleted=\"12\"" \
364 # Special Display Tests #
368 # Stop at the end of "do_special_tests"
370 set line_dst_incr_a_2 [gdb_get_line_number "incr_a(2);"]
372 mi_create_breakpoint "$line_dst_incr_a_2" 2 keep do_special_tests ".*var-cmd.c" $line_dst_incr_a_2 $hex \
373 "break-insert operation 2"
375 mi_execute_to "exec-continue" "breakpoint-hit" "do_special_tests" "" \
376 ".*var-cmd.c" $line_dst_incr_a_2 { "" "disp=\"keep\"" } \
377 "continue to do_special_tests"
379 # Test: c_variable-7.10
380 # Desc: create union u
381 mi_create_varobj u u "create local variable u"
383 # Test: c_variable-7.11
385 mi_gdb_test "-var-evaluate-expression u" \
386 "\\^done,value=\"\{\\.\\.\\.\}\"" \
389 # Test: c_variable-7.12
391 mi_gdb_test "-var-info-type u" \
392 "\\^done,type=\"union named_union\"" \
393 "info type variable u"
395 # Test: c_variable-7.13
396 # Desc: is u editable
397 mi_gdb_test "-var-show-attributes u" \
398 "\\^done,attr=\"noneditable\"" \
401 # Test: c_variable-7.14
402 # Desc: number of children of u
403 mi_gdb_test "-var-info-num-children u" \
404 "\\^done,numchild=\"2\"" \
405 "get number of children of u"
407 # Test: c_variable-7.15
408 # Desc: children of u
409 mi_list_varobj_children u {
410 {u.integer integer 0 int}
411 {u.char_ptr char_ptr 1 {char \*}}
412 } "get children of u"
414 # Test: c_variable-7.20
416 mi_create_varobj anonu anonu "create local variable anonu"
418 # Test: c_variable-7.21
419 # Desc: value of anonu
420 mi_gdb_test "-var-evaluate-expression anonu" \
421 "\\^done,value=\"\{\\.\\.\\.\}\"" \
422 "eval variable anonu"
424 # Test: c_variable-7.22
425 # Desc: type of anonu
426 mi_gdb_test "-var-info-type anonu" \
427 "\\^done,type=\"union \{\\.\\.\\.\}\"" \
428 "info type variable anonu"
430 # Test: c_variable-7.23
431 # Desc: is anonu editable
432 mi_gdb_test "-var-show-attributes anonu" \
433 "\\^done,attr=\"noneditable\"" \
436 # Test: c_variable-7.24
437 # Desc: number of children of anonu
438 mi_gdb_test "-var-info-num-children anonu" \
439 "\\^done,numchild=\"3\"" \
440 "get number of children of anonu"
442 # Test: c_variable-7.25
443 # Desc: children of anonu
444 mi_list_varobj_children "anonu" {
447 {anonu.c c 0 "long int"}
448 } "get children of anonu"
450 # Test: c_variable-7.30
451 # Desc: create struct s
452 mi_create_varobj s s "create local variable s"
455 # Test: c_variable-7.31
457 mi_gdb_test "-var-evaluate-expression s" \
458 "\\^done,value=\"\{\\.\\.\\.\}\"" \
461 # Test: c_variable-7.32
463 mi_gdb_test "-var-info-type s" \
464 "\\^done,type=\"struct _simple_struct\"" \
465 "info type variable s"
467 # Test: c_variable-7.33
468 # Desc: is s editable
469 mi_gdb_test "-var-show-attributes s" \
470 "\\^done,attr=\"noneditable\"" \
473 # Test: c_variable-7.34
474 # Desc: number of children of s
475 mi_gdb_test "-var-info-num-children s" \
476 "\\^done,numchild=\"6\"" \
477 "get number of children of s"
479 # Test: c_variable-7.35
480 # Desc: children of s
481 mi_list_varobj_children s {
482 {s.integer integer 0 int}
483 {s.unsigned_integer unsigned_integer 0 "unsigned int"}
484 {s.character character 0 char}
485 {s.signed_character signed_character 0 "signed char"}
486 {s.char_ptr char_ptr 1 {char \*}}
487 {s.array_of_10 array_of_10 10 {int \[10\]}}
488 } "get children of s"
489 #} {integer unsigned_integer character signed_character char_ptr array_of_10}
491 # Test: c_variable-7.40
493 mi_create_varobj anons anons "create local variable anons"
495 # Test: c_variable-7.41
496 # Desc: value of anons
497 mi_gdb_test "-var-evaluate-expression anons" \
498 "\\^done,value=\"\{\\.\\.\\.\}\"" \
499 "eval variable anons"
501 # Test: c_variable-7.42
502 # Desc: type of anons
503 mi_gdb_test "-var-info-type anons" \
504 "\\^done,type=\"struct \{\\.\\.\\.\}\"" \
505 "info type variable anons"
507 # Test: c_variable-7.43
508 # Desc: is anons editable
509 mi_gdb_test "-var-show-attributes anons" \
510 "\\^done,attr=\"noneditable\"" \
513 # Test: c_variable-7.44
514 # Desc: number of children of anons
515 mi_gdb_test "-var-info-num-children anons" \
516 "\\^done,numchild=\"3\"" \
517 "get number of children of anons"
519 # Test: c_variable-7.45
520 # Desc: children of anons
521 mi_list_varobj_children anons {
524 {anons.c c 0 "long int"}
525 } "get children of anons"
527 # Test: c_variable-7.50
528 # Desc: create enum e
529 mi_create_varobj e e "create local variable e"
531 # Test: c_variable-7.51
533 mi_gdb_test "-var-evaluate-expression e" \
534 "\\^done,value=\"bar\"" \
537 # Test: c_variable-7.52
539 mi_gdb_test "-var-info-type e" \
540 "\\^done,type=\"enum foo\"" \
541 "info type variable e"
543 # Test: c_variable-7.53
544 # Desc: is e editable
545 mi_gdb_test "-var-show-attributes e" \
546 "\\^done,attr=\"editable\"" \
549 # Test: c_variable-7.54
550 # Desc: number of children of e
551 mi_gdb_test "-var-info-num-children e" \
552 "\\^done,numchild=\"0\"" \
553 "get number of children of e"
555 # Test: c_variable-7.55
556 # Desc: children of e
557 mi_gdb_test "-var-list-children e" \
558 "\\^done,numchild=\"0\",has_more=\"0\"" \
561 # Test: c_variable-7.60
563 mi_create_varobj anone anone "create local variable anone"
565 # Test: c_variable-7.61
566 # Desc: value of anone
567 mi_gdb_test "-var-evaluate-expression anone" \
568 "\\^done,value=\"A\"" \
569 "eval variable anone"
571 # Test: c_variable-7.70
573 mi_gdb_test "-var-create anone * anone" \
574 "\\^error,msg=\"Duplicate variable object name\"" \
575 "create duplicate local variable anone"
578 # Test: c_variable-7.72
579 # Desc: type of anone
580 mi_gdb_test "-var-info-type anone" \
581 "\\^done,type=\"enum \{\\.\\.\\.\}\"" \
582 "info type variable anone"
585 # Test: c_variable-7.73
586 # Desc: is anone editable
587 mi_gdb_test "-var-show-attributes anone" \
588 "\\^done,attr=\"editable\"" \
591 # Test: c_variable-7.74
592 # Desc: number of children of anone
593 mi_gdb_test "-var-info-num-children anone" \
594 "\\^done,numchild=\"0\"" \
595 "get number of children of anone"
597 # Test: c_variable-7.75
598 # Desc: children of anone
599 mi_gdb_test "-var-list-children anone" \
600 "\\^done,numchild=\"0\",has_more=\"0\"" \
601 "get children of anone"
605 if ![mi_gdb_test "p/x \$fp" ".*($hex).*\\^done" "print FP register"] {
606 set fp $expect_out(3,string)
609 mi_continue_to "incr_a"
611 # Test: c_variable-7.81
612 # Desc: Create variables in different scopes
613 mi_gdb_test "-var-create a1 * a" \
614 "\\^done,name=\"a1\",numchild=\"0\",value=\".*\",type=\"char\".*" \
615 "create local variable a1"
617 if { [info exists fp] } {
618 mi_gdb_test "-var-create a2 $fp a" \
619 "\\^done,name=\"a2\",numchild=\"0\",value=\".*\",type=\"int\".*" \
620 "create variable a2 in different scope"
622 untested "create variable a2 in different scope"
625 #gdbtk_test c_variable-7.81 {create variables in different scopes} {
626 # set a1 [gdb_variable create -expr a]
627 # set a2 [gdb_variable create -expr a -frame $fp]
630 # lappend vals [$a1 value]
631 # lappend vals [$a2 value]