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 standard_testfile var-cmd.c
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 untested mi-var-display.exp
38 mi_gdb_reinitialize_dir $srcdir/$subdir
39 mi_gdb_load ${binfile}
41 set line_dct_end [gdb_get_line_number "{int a = 0;}"]
43 mi_create_breakpoint "$srcfile:$line_dct_end" 1 keep do_children_tests ".*var-cmd.c" $line_dct_end $hex \
44 "break-insert operation"
47 mi_expect_stop "breakpoint-hit" "do_children_tests" "" ".*var-cmd.c" \
48 $line_dct_end { "" "disp=\"keep\"" } "run to main"
56 # Test: c_variable-6.1
57 # Desc: create variable bar
58 mi_create_varobj bar bar "create local variable bar"
60 # Test: c_variable-6.2
61 # Desc: type of variable bar
62 mi_gdb_test "-var-info-type bar" \
63 "\\^done,type=\"int\"" \
64 "info type variable bar"
66 # Test: c_variable-6.3
67 # Desc: format of variable bar
68 mi_gdb_test "-var-show-format bar" \
69 "\\^done,format=\"natural\"" \
70 "show format variable bar"
72 # Test: c_variable-6.4
73 # Desc: value of variable bar
74 mi_gdb_test "-var-evaluate-expression bar" \
75 "\\^done,value=\"2121\"" \
78 # Test: c_variable-6.5
79 # Desc: change format of bar to hex
80 mi_gdb_test "-var-set-format bar hexadecimal" \
81 "\\^done,format=\"hexadecimal\",value=\"0x849\"" \
82 "set format variable bar"
84 # Test: c_variable-6.6
85 # Desc: value of bar with new format
86 mi_gdb_test "-var-evaluate-expression bar" \
87 "\\^done,value=\"0x849\"" \
88 "eval variable bar with new format"
90 # Test: c_variable-6.7
91 # Desc: change value of bar
92 mi_gdb_test "-var-assign bar 3" \
93 "\\^done,value=\"0x3\"" \
94 "assing to variable bar"
96 mi_gdb_test "-var-set-format bar decimal" \
97 "\\^done,format=\"decimal\",value=\"3\"" \
98 "set format variable bar"
100 mi_gdb_test "-var-evaluate-expression bar" \
101 "\\^done,value=\"3\"" \
102 "eval variable bar with new value"
104 mi_gdb_test "-var-delete bar" \
105 "\\^done,ndeleted=\"1\"" \
108 # Test: c_variable-6.11
109 # Desc: create variable foo
110 mi_create_varobj foo foo "create local variable foo"
112 # Test: c_variable-6.12
113 # Desc: type of variable foo
114 mi_gdb_test "-var-info-type foo" \
115 "\\^done,type=\"int \\*\"" \
116 "info type variable foo"
118 # Test: c_variable-6.13
119 # Desc: format of variable foo
120 mi_gdb_test "-var-show-format foo" \
121 "\\^done,format=\"natural\"" \
122 "show format variable foo"
124 # Test: c_variable-6.14
125 # Desc: value of variable foo
126 mi_gdb_test "-var-evaluate-expression foo" \
127 "\\^done,value=\"$hex\"" \
130 # Test: c_variable-6.15
131 # Desc: change format of var to octal
132 mi_gdb_test "-var-set-format foo octal" \
133 "\\^done,format=\"octal\",value=\"$octal\"" \
134 "set format variable foo"
136 mi_gdb_test "-var-show-format foo" \
137 "\\^done,format=\"octal\"" \
138 "show format variable foo"
140 # Test: c_variable-6.16
141 # Desc: value of foo with new format
142 mi_gdb_test "-var-evaluate-expression foo" \
143 "\\^done,value=\"\[0-7\]+\"" \
146 # Test: c_variable-6.17
147 # Desc: change value of foo
148 mi_gdb_test "-var-assign foo 3" \
149 "\\^done,value=\"03\"" \
150 "assing to variable foo"
152 mi_gdb_test "-var-set-format foo decimal" \
153 "\\^done,format=\"decimal\",value=\"3\"" \
154 "set format variable foo"
156 # Test: c_variable-6.18
157 # Desc: check new value of foo
158 mi_gdb_test "-var-evaluate-expression foo" \
159 "\\^done,value=\"3\"" \
163 # Test: c_variable-6.19
164 # Desc: check optional format parameter of var-evaluate-expression
165 # and check that current format is not changed
166 mi_gdb_test "-var-evaluate-expression -f hex foo" \
167 "\\^done,value=\"0x3\"" \
168 "eval variable foo in hex"
170 mi_gdb_test "-var-show-format foo" \
171 "\\^done,format=\"decimal\"" \
172 "show format variable foo after eval in hex"
174 mi_gdb_test "-var-evaluate-expression -f octal foo" \
175 "\\^done,value=\"03\"" \
176 "eval variable foo in octal"
178 mi_gdb_test "-var-show-format foo" \
179 "\\^done,format=\"decimal\"" \
180 "show format variable foo after eval in octal"
182 mi_gdb_test "-var-evaluate-expression -f decimal foo" \
183 "\\^done,value=\"3\"" \
184 "eval variable foo in decimal"
186 mi_gdb_test "-var-show-format foo" \
187 "\\^done,format=\"decimal\"" \
188 "show format variable foo after eval in decimal"
190 mi_gdb_test "-var-evaluate-expression -f nat foo" \
191 "\\^done,value=\"0x3\"" \
192 "eval variable foo in natural"
194 mi_gdb_test "-var-show-format foo" \
195 "\\^done,format=\"decimal\"" \
196 "show format variable foo after eval in natural"
198 mi_gdb_test "-var-evaluate-expression -f bin foo" \
199 "\\^done,value=\"11\"" \
200 "eval variable foo in binary"
202 mi_gdb_test "-var-show-format foo" \
203 "\\^done,format=\"decimal\"" \
204 "show format variable foo after eval in binary"
206 mi_gdb_test "-var-delete foo" \
207 "\\^done,ndeleted=\"1\"" \
210 # Test: c_variable-6.21
211 # Desc: create variable weird and children
212 mi_create_varobj weird weird "create local variable weird"
214 mi_list_varobj_children weird {
215 {weird.integer integer 0 int}
216 {weird.character character 0 char}
217 {weird.char_ptr char_ptr 1 "char \\*"}
218 {weird.long_int long_int 0 "long"}
219 {weird.int_ptr_ptr int_ptr_ptr 1 "int \\*\\*"}
220 {weird.long_array long_array 10 "long \\[10\\]"}
221 {weird.func_ptr func_ptr 0 "void \\(\\*\\)\\((void)?\\)"}
222 {weird.func_ptr_struct func_ptr_struct 0 \
223 "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long\\))?"}
224 {weird.func_ptr_ptr func_ptr_ptr 0 \
225 "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long)?\\)"}
226 {weird.u1 u1 4 "union \\{\\.\\.\\.\\}"}
227 {weird.s2 s2 4 "struct \\{\\.\\.\\.\\}"}
228 } "get children local variable weird"
231 # Test: c_variable-6.23
232 # Desc: change format of weird.func_ptr and weird.func_ptr_ptr
233 mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \
234 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
235 "set format variable weird.func_ptr"
237 mi_gdb_test "-var-show-format weird.func_ptr" \
238 "\\^done,format=\"hexadecimal\"" \
239 "show format variable weird.func_ptr"
241 mi_gdb_test "-var-set-format weird.func_ptr_ptr hexadecimal" \
242 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
243 "set format variable weird.func_ptr_ptr"
245 mi_gdb_test "-var-show-format weird.func_ptr_ptr" \
246 "\\^done,format=\"hexadecimal\"" \
247 "show format variable weird.func_ptr_ptr"
249 # Test: c_variable-6.24
250 # Desc: format of weird and children
251 mi_gdb_test "-var-set-format weird natural" \
252 "\\^done,format=\"natural\",value=\"$hex\"" \
253 "set format variable weird"
255 mi_gdb_test "-var-set-format weird.integer natural" \
256 "\\^done,format=\"natural\",value=\"123\"" \
257 "set format variable weird.integer"
259 mi_gdb_test "-var-set-format weird.character natural" \
260 "\\^done,format=\"natural\",value=\"0 '\\\\\\\\000'\"" \
261 "set format variable weird.character"
263 mi_gdb_test "-var-set-format weird.char_ptr natural" \
264 "\\^done,format=\"natural\",value=\"$hex \\\\\"hello\\\\\"\"" \
265 "set format variable weird.char_ptr"
267 mi_gdb_test "-var-set-format weird.long_int natural" \
268 "\\^done,format=\"natural\",value=\"0\"" \
269 "set format variable weird.long_int"
271 mi_gdb_test "-var-set-format weird.int_ptr_ptr natural" \
272 "\\^done,format=\"natural\",value=\"$hex\"" \
273 "set format variable weird.int_ptr_ptr"
275 mi_gdb_test "-var-set-format weird.long_array natural" \
276 "\\^done,format=\"natural\",value=\"\\\[10\\\]\"" \
277 "set format variable weird.long_array"
279 mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \
280 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
281 "set format variable weird.func_ptr"
283 mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
284 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
285 "set format variable weird.func_ptr_struct"
287 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
288 "\\^done,format=\"natural\",value=\"0x0\"" \
289 "set format variable weird.func_ptr_ptr"
291 mi_gdb_test "-var-set-format weird.u1 natural" \
292 "\\^done,format=\"natural\",value=\"\{...\}\"" \
293 "set format variable weird.u1"
295 mi_gdb_test "-var-set-format weird.s2 natural" \
296 "\\^done,format=\"natural\",value=\"\{...\}\"" \
297 "set format variable weird.s2"
299 # Test: c_variable-6.25
300 # Desc: value of weird and children
301 #gdbtk_test c_variable-6.25 {value of weird and children} {
303 # foreach v [lsort [array names var]] f [list x "" "" x x x x d d d d d] {
304 # lappend values [value $v $f]
308 #} {ok ok ok ok ok ok ok ok weird.long_array ok weird.s2 weird.u1}
310 # Test: c_variable-6.26
311 # Desc: change format of weird and children to octal
312 #gdbtk_test c_variable-6.26 {change format of weird and children to octal} {
314 # foreach v [lsort [array names var]] {
315 # $var($v) format octal
316 # lappend formats [$var($v) format]
320 #} {octal octal octal octal octal octal octal octal octal octal octal octal}
322 # Test: c_variable-6.27
323 # Desc: value of weird and children with new format
324 #gdbtk_test c_variable-6.27 {value of foo with new format} {
326 # foreach v [lsort [array names var]] {
327 # lappend values [value $v o]
331 #} {ok ok ok ok ok ok ok ok weird.long_array ok weird.s2 weird.u1}
333 # Test: c_variable-6.30
334 # Desc: create more children of weird
335 #gdbtk_test c_variable-6.30 {create more children of weird} {
336 # foreach v [array names var] {
340 # # Do it twice to get more children
341 # foreach v [array names var] {
345 # lsort [array names var]
346 #} {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}
348 # Test: c_variable-6.31
349 # Desc: check that all children of weird change
350 # Ok, obviously things like weird.s2 and weird.u1 will not change!
351 #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)} {
352 # $var(weird) value 0x2121
354 #} {{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} {}}
356 mi_gdb_test "-var-delete weird" \
357 "\\^done,ndeleted=\"12\"" \
363 # Special Display Tests #
367 # Stop at the end of "do_special_tests"
369 set line_dst_incr_a_2 [gdb_get_line_number "incr_a(2);"]
371 mi_create_breakpoint "$line_dst_incr_a_2" 2 keep do_special_tests ".*var-cmd.c" $line_dst_incr_a_2 $hex \
372 "break-insert operation 2"
374 mi_execute_to "exec-continue" "breakpoint-hit" "do_special_tests" "" \
375 ".*var-cmd.c" $line_dst_incr_a_2 { "" "disp=\"keep\"" } \
376 "continue to do_special_tests"
378 # Test: c_variable-7.10
379 # Desc: create union u
380 mi_create_varobj u u "create local variable u"
382 # Test: c_variable-7.11
384 mi_gdb_test "-var-evaluate-expression u" \
385 "\\^done,value=\"\{\\.\\.\\.\}\"" \
388 # Test: c_variable-7.12
390 mi_gdb_test "-var-info-type u" \
391 "\\^done,type=\"union named_union\"" \
392 "info type variable u"
394 # Test: c_variable-7.13
395 # Desc: is u editable
396 mi_gdb_test "-var-show-attributes u" \
397 "\\^done,attr=\"noneditable\"" \
400 # Test: c_variable-7.14
401 # Desc: number of children of u
402 mi_gdb_test "-var-info-num-children u" \
403 "\\^done,numchild=\"2\"" \
404 "get number of children of u"
406 # Test: c_variable-7.15
407 # Desc: children of u
408 mi_list_varobj_children u {
409 {u.integer integer 0 int}
410 {u.char_ptr char_ptr 1 {char \*}}
411 } "get children of u"
413 # Test: c_variable-7.20
415 mi_create_varobj anonu anonu "create local variable anonu"
417 # Test: c_variable-7.21
418 # Desc: value of anonu
419 mi_gdb_test "-var-evaluate-expression anonu" \
420 "\\^done,value=\"\{\\.\\.\\.\}\"" \
421 "eval variable anonu"
423 # Test: c_variable-7.22
424 # Desc: type of anonu
425 mi_gdb_test "-var-info-type anonu" \
426 "\\^done,type=\"union \{\\.\\.\\.\}\"" \
427 "info type variable anonu"
429 # Test: c_variable-7.23
430 # Desc: is anonu editable
431 mi_gdb_test "-var-show-attributes anonu" \
432 "\\^done,attr=\"noneditable\"" \
435 # Test: c_variable-7.24
436 # Desc: number of children of anonu
437 mi_gdb_test "-var-info-num-children anonu" \
438 "\\^done,numchild=\"3\"" \
439 "get number of children of anonu"
441 # Test: c_variable-7.25
442 # Desc: children of anonu
443 mi_list_varobj_children "anonu" {
447 } "get children of anonu"
449 # Test: c_variable-7.30
450 # Desc: create struct s
451 mi_create_varobj s s "create local variable s"
454 # Test: c_variable-7.31
456 mi_gdb_test "-var-evaluate-expression s" \
457 "\\^done,value=\"\{\\.\\.\\.\}\"" \
460 # Test: c_variable-7.32
462 mi_gdb_test "-var-info-type s" \
463 "\\^done,type=\"struct _simple_struct\"" \
464 "info type variable s"
466 # Test: c_variable-7.33
467 # Desc: is s editable
468 mi_gdb_test "-var-show-attributes s" \
469 "\\^done,attr=\"noneditable\"" \
472 # Test: c_variable-7.34
473 # Desc: number of children of s
474 mi_gdb_test "-var-info-num-children s" \
475 "\\^done,numchild=\"6\"" \
476 "get number of children of s"
478 # Test: c_variable-7.35
479 # Desc: children of s
480 mi_list_varobj_children s {
481 {s.integer integer 0 int}
482 {s.unsigned_integer unsigned_integer 0 "unsigned int"}
483 {s.character character 0 char}
484 {s.signed_character signed_character 0 "signed char"}
485 {s.char_ptr char_ptr 1 {char \*}}
486 {s.array_of_10 array_of_10 10 {int \[10\]}}
487 } "get children of s"
488 #} {integer unsigned_integer character signed_character char_ptr array_of_10}
490 # Test: c_variable-7.40
492 mi_create_varobj anons anons "create local variable anons"
494 # Test: c_variable-7.41
495 # Desc: value of anons
496 mi_gdb_test "-var-evaluate-expression anons" \
497 "\\^done,value=\"\{\\.\\.\\.\}\"" \
498 "eval variable anons"
500 # Test: c_variable-7.42
501 # Desc: type of anons
502 mi_gdb_test "-var-info-type anons" \
503 "\\^done,type=\"struct \{\\.\\.\\.\}\"" \
504 "info type variable anons"
506 # Test: c_variable-7.43
507 # Desc: is anons editable
508 mi_gdb_test "-var-show-attributes anons" \
509 "\\^done,attr=\"noneditable\"" \
512 # Test: c_variable-7.44
513 # Desc: number of children of anons
514 mi_gdb_test "-var-info-num-children anons" \
515 "\\^done,numchild=\"3\"" \
516 "get number of children of anons"
518 # Test: c_variable-7.45
519 # Desc: children of anons
520 mi_list_varobj_children anons {
524 } "get children of anons"
526 # Test: c_variable-7.50
527 # Desc: create enum e
528 mi_create_varobj e e "create local variable e"
530 # Test: c_variable-7.51
532 mi_gdb_test "-var-evaluate-expression e" \
533 "\\^done,value=\"bar\"" \
536 # Test: c_variable-7.52
538 mi_gdb_test "-var-info-type e" \
539 "\\^done,type=\"enum foo\"" \
540 "info type variable e"
542 # Test: c_variable-7.53
543 # Desc: is e editable
544 mi_gdb_test "-var-show-attributes e" \
545 "\\^done,attr=\"editable\"" \
548 # Test: c_variable-7.54
549 # Desc: number of children of e
550 mi_gdb_test "-var-info-num-children e" \
551 "\\^done,numchild=\"0\"" \
552 "get number of children of e"
554 # Test: c_variable-7.55
555 # Desc: children of e
556 mi_gdb_test "-var-list-children e" \
557 "\\^done,numchild=\"0\",has_more=\"0\"" \
560 # Test: c_variable-7.60
562 mi_create_varobj anone anone "create local variable anone"
564 # Test: c_variable-7.61
565 # Desc: value of anone
566 mi_gdb_test "-var-evaluate-expression anone" \
567 "\\^done,value=\"A\"" \
568 "eval variable anone"
570 # Test: c_variable-7.70
572 mi_gdb_test "-var-create anone * anone" \
573 "\\^error,msg=\"Duplicate variable object name\"" \
574 "create duplicate local variable anone"
577 # Test: c_variable-7.72
578 # Desc: type of anone
579 mi_gdb_test "-var-info-type anone" \
580 "\\^done,type=\"enum \{\\.\\.\\.\}\"" \
581 "info type variable anone"
584 # Test: c_variable-7.73
585 # Desc: is anone editable
586 mi_gdb_test "-var-show-attributes anone" \
587 "\\^done,attr=\"editable\"" \
590 # Test: c_variable-7.74
591 # Desc: number of children of anone
592 mi_gdb_test "-var-info-num-children anone" \
593 "\\^done,numchild=\"0\"" \
594 "get number of children of anone"
596 # Test: c_variable-7.75
597 # Desc: children of anone
598 mi_gdb_test "-var-list-children anone" \
599 "\\^done,numchild=\"0\",has_more=\"0\"" \
600 "get children of anone"
604 if ![mi_gdb_test "p/x \$fp" ".*($hex).*\\^done" "print FP register"] {
605 set fp $expect_out(3,string)
608 mi_continue_to "incr_a"
610 # Test: c_variable-7.81
611 # Desc: Create variables in different scopes
612 mi_gdb_test "-var-create a1 * a" \
613 "\\^done,name=\"a1\",numchild=\"0\",value=\".*\",type=\"char\".*" \
614 "create local variable a1"
616 if { [info exists fp] } {
617 mi_gdb_test "-var-create a2 $fp a" \
618 "\\^done,name=\"a2\",numchild=\"0\",value=\".*\",type=\"int\".*" \
619 "create variable a2 in different scope"
621 untested "create variable a2 in different scope"
624 #gdbtk_test c_variable-7.81 {create variables in different scopes} {
625 # set a1 [gdb_variable create -expr a]
626 # set a2 [gdb_variable create -expr a -frame $fp]
629 # lappend vals [$a1 value]
630 # lappend vals [$a2 value]