1 # Copyright 1999-2015 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" \
44 "break-insert operation" \
45 -number 1 -func do_children_tests -file ".*var-cmd.c" \
49 mi_expect_stop "breakpoint-hit" "do_children_tests" "" ".*var-cmd.c" \
50 $line_dct_end { "" "disp=\"keep\"" } "run to main"
52 # Prevent symbol on the address being printed.
53 mi_gdb_test "-gdb-set print symbol off"
61 # Test: c_variable-6.1
62 # Desc: create variable bar
63 mi_create_varobj bar bar "create local variable bar"
65 # Test: c_variable-6.2
66 # Desc: type of variable bar
67 mi_gdb_test "-var-info-type bar" \
68 "\\^done,type=\"int\"" \
69 "info type variable bar"
71 # Test: c_variable-6.3
72 # Desc: format of variable bar
73 mi_gdb_test "-var-show-format bar" \
74 "\\^done,format=\"natural\"" \
75 "show format variable bar"
77 # Test: c_variable-6.4
78 # Desc: value of variable bar
79 mi_gdb_test "-var-evaluate-expression bar" \
80 "\\^done,value=\"2121\"" \
83 # Test: c_variable-6.5
84 # Desc: change format of bar to hex
85 mi_gdb_test "-var-set-format bar hexadecimal" \
86 "\\^done,format=\"hexadecimal\",value=\"0x849\"" \
87 "set format variable bar in hex"
89 # Test: c_variable-6.6
90 # Desc: value of bar with new format
91 mi_gdb_test "-var-evaluate-expression bar" \
92 "\\^done,value=\"0x849\"" \
93 "eval variable bar with new format"
95 # Test: c_variable-6.7
96 # Desc: change value of bar
97 mi_gdb_test "-var-assign bar 3" \
98 "\\^done,value=\"0x3\"" \
99 "assing to variable bar"
101 mi_gdb_test "-var-set-format bar decimal" \
102 "\\^done,format=\"decimal\",value=\"3\"" \
103 "set format variable bar in decimal"
105 mi_gdb_test "-var-evaluate-expression bar" \
106 "\\^done,value=\"3\"" \
107 "eval variable bar with new value"
109 mi_gdb_test "-var-delete bar" \
110 "\\^done,ndeleted=\"1\"" \
113 # Test: c_variable-6.11
114 # Desc: create variable foo
115 mi_create_varobj foo foo "create local variable foo"
117 # Test: c_variable-6.12
118 # Desc: type of variable foo
119 mi_gdb_test "-var-info-type foo" \
120 "\\^done,type=\"int \\*\"" \
121 "info type variable foo"
123 # Test: c_variable-6.13
124 # Desc: format of variable foo
125 mi_gdb_test "-var-show-format foo" \
126 "\\^done,format=\"natural\"" \
127 "show format variable foo in natural"
129 # Test: c_variable-6.14
130 # Desc: value of variable foo
131 mi_gdb_test "-var-evaluate-expression foo" \
132 "\\^done,value=\"$hex\"" \
133 "eval variable foo in natural"
135 # Test: c_variable-6.15
136 # Desc: change format of var to octal
137 mi_gdb_test "-var-set-format foo octal" \
138 "\\^done,format=\"octal\",value=\"$octal\"" \
139 "set format variable foo in octal"
141 mi_gdb_test "-var-show-format foo" \
142 "\\^done,format=\"octal\"" \
143 "show format variable foo in octal"
145 # Test: c_variable-6.16
146 # Desc: value of foo with new format
147 mi_gdb_test "-var-evaluate-expression foo" \
148 "\\^done,value=\"\[0-7\]+\"" \
149 "eval variable foo in octal"
151 # Test: c_variable-6.17
152 # Desc: change value of foo
153 mi_gdb_test "-var-assign foo 3" \
154 "\\^done,value=\"03\"" \
155 "assing to variable foo"
157 mi_gdb_test "-var-set-format foo decimal" \
158 "\\^done,format=\"decimal\",value=\"3\"" \
159 "set format variable foo decimal"
161 # Test: c_variable-6.18
162 # Desc: check new value of foo
163 mi_gdb_test "-var-evaluate-expression foo" \
164 "\\^done,value=\"3\"" \
165 "eval variable foo in decimal"
168 # Test: c_variable-6.19
169 # Desc: check optional format parameter of var-evaluate-expression
170 # and check that current format is not changed
171 mi_gdb_test "-var-evaluate-expression -f hex foo" \
172 "\\^done,value=\"0x3\"" \
173 "eval variable foo in hex"
175 mi_gdb_test "-var-show-format foo" \
176 "\\^done,format=\"decimal\"" \
177 "show format variable foo after eval in hex"
179 mi_gdb_test "-var-evaluate-expression -f octal foo" \
180 "\\^done,value=\"03\"" \
181 "eval variable -f octal foo"
183 mi_gdb_test "-var-show-format foo" \
184 "\\^done,format=\"decimal\"" \
185 "show format variable foo after eval in octal"
187 mi_gdb_test "-var-evaluate-expression -f decimal foo" \
188 "\\^done,value=\"3\"" \
189 "eval variable -f decimal foo"
191 mi_gdb_test "-var-show-format foo" \
192 "\\^done,format=\"decimal\"" \
193 "show format variable foo after eval in decimal"
195 mi_gdb_test "-var-evaluate-expression -f nat foo" \
196 "\\^done,value=\"0x3\"" \
197 "eval variable -f nat foo"
199 mi_gdb_test "-var-show-format foo" \
200 "\\^done,format=\"decimal\"" \
201 "show format variable foo after eval in natural"
203 mi_gdb_test "-var-evaluate-expression -f bin foo" \
204 "\\^done,value=\"11\"" \
205 "eval variable foo in binary"
207 mi_gdb_test "-var-show-format foo" \
208 "\\^done,format=\"decimal\"" \
209 "show format variable foo after eval in binary"
211 mi_gdb_test "-var-delete foo" \
212 "\\^done,ndeleted=\"1\"" \
215 # Test: c_variable-6.21
216 # Desc: create variable weird and children
217 mi_create_varobj weird weird "create local variable weird"
219 mi_list_varobj_children weird {
220 {weird.integer integer 0 int}
221 {weird.character character 0 char}
222 {weird.char_ptr char_ptr 1 "char \\*"}
223 {weird.long_int long_int 0 "long"}
224 {weird.int_ptr_ptr int_ptr_ptr 1 "int \\*\\*"}
225 {weird.long_array long_array 10 "long \\[10\\]"}
226 {weird.func_ptr func_ptr 0 "void \\(\\*\\)\\((void)?\\)"}
227 {weird.func_ptr_struct func_ptr_struct 0 \
228 "struct _struct_decl \\(\\*\\)(\\(int, char \\*, long\\))?"}
229 {weird.func_ptr_ptr func_ptr_ptr 0 \
230 "struct _struct_decl \\*\\(\\*\\)\\((int, char \\*, long)?\\)"}
231 {weird.u1 u1 4 "union \\{\\.\\.\\.\\}"}
232 {weird.s2 s2 4 "struct \\{\\.\\.\\.\\}"}
233 } "get children local variable weird"
236 # Test: c_variable-6.23
237 # Desc: change format of weird.func_ptr and weird.func_ptr_ptr
238 mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \
239 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
240 "set format variable weird.func_ptr in hex (1)"
242 mi_gdb_test "-var-show-format weird.func_ptr" \
243 "\\^done,format=\"hexadecimal\"" \
244 "show format variable weird.func_ptr"
246 mi_gdb_test "-var-set-format weird.func_ptr_ptr hexadecimal" \
247 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
248 "set format variable weird.func_ptr_ptr in hex"
250 mi_gdb_test "-var-show-format weird.func_ptr_ptr" \
251 "\\^done,format=\"hexadecimal\"" \
252 "show format variable weird.func_ptr_ptr"
254 # Test: c_variable-6.24
255 # Desc: format of weird and children
256 mi_gdb_test "-var-set-format weird natural" \
257 "\\^done,format=\"natural\",value=\"$hex\"" \
258 "set format variable weird"
260 mi_gdb_test "-var-set-format weird.integer natural" \
261 "\\^done,format=\"natural\",value=\"123\"" \
262 "set format variable weird.integer"
264 mi_gdb_test "-var-set-format weird.character natural" \
265 "\\^done,format=\"natural\",value=\"0 '\\\\\\\\000'\"" \
266 "set format variable weird.character"
268 mi_gdb_test "-var-set-format weird.char_ptr natural" \
269 "\\^done,format=\"natural\",value=\"$hex \\\\\"hello\\\\\"\"" \
270 "set format variable weird.char_ptr"
272 mi_gdb_test "-var-set-format weird.long_int natural" \
273 "\\^done,format=\"natural\",value=\"0\"" \
274 "set format variable weird.long_int"
276 mi_gdb_test "-var-set-format weird.int_ptr_ptr natural" \
277 "\\^done,format=\"natural\",value=\"$hex\"" \
278 "set format variable weird.int_ptr_ptr"
280 mi_gdb_test "-var-set-format weird.long_array natural" \
281 "\\^done,format=\"natural\",value=\"\\\[10\\\]\"" \
282 "set format variable weird.long_array"
284 mi_gdb_test "-var-set-format weird.func_ptr hexadecimal" \
285 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
286 "set format variable weird.func_ptr in hex (2)"
288 mi_gdb_test "-var-set-format weird.func_ptr_struct hexadecimal" \
289 "\\^done,format=\"hexadecimal\",value=\"$hex\"" \
290 "set format variable weird.func_ptr_struct"
292 mi_gdb_test "-var-set-format weird.func_ptr_ptr natural" \
293 "\\^done,format=\"natural\",value=\"$hex <nothing2>\"" \
294 "set format variable weird.func_ptr_ptr in natural"
296 mi_gdb_test "-var-set-format weird.u1 natural" \
297 "\\^done,format=\"natural\",value=\"\{...\}\"" \
298 "set format variable weird.u1"
300 mi_gdb_test "-var-set-format weird.s2 natural" \
301 "\\^done,format=\"natural\",value=\"\{...\}\"" \
302 "set format variable weird.s2"
304 # Test: c_variable-6.25
305 # Desc: value of weird and children
306 #gdbtk_test c_variable-6.25 {value of weird and children} {
308 # foreach v [lsort [array names var]] f [list x "" "" x x x x d d d d d] {
309 # lappend values [value $v $f]
313 #} {ok ok ok ok ok ok ok ok weird.long_array ok weird.s2 weird.u1}
315 # Test: c_variable-6.26
316 # Desc: change format of weird and children to octal
317 #gdbtk_test c_variable-6.26 {change format of weird and children to octal} {
319 # foreach v [lsort [array names var]] {
320 # $var($v) format octal
321 # lappend formats [$var($v) format]
325 #} {octal octal octal octal octal octal octal octal octal octal octal octal}
327 # Test: c_variable-6.27
328 # Desc: value of weird and children with new format
329 #gdbtk_test c_variable-6.27 {value of foo with new format} {
331 # foreach v [lsort [array names var]] {
332 # lappend values [value $v o]
336 #} {ok ok ok ok ok ok ok ok weird.long_array ok weird.s2 weird.u1}
338 # Test: c_variable-6.30
339 # Desc: create more children of weird
340 #gdbtk_test c_variable-6.30 {create more children of weird} {
341 # foreach v [array names var] {
345 # # Do it twice to get more children
346 # foreach v [array names var] {
350 # lsort [array names var]
351 #} {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}
353 # Test: c_variable-6.31
354 # Desc: check that all children of weird change
355 # Ok, obviously things like weird.s2 and weird.u1 will not change!
356 #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)} {
357 # $var(weird) value 0x2121
359 #} {{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} {}}
361 mi_gdb_test "-var-delete weird" \
362 "\\^done,ndeleted=\"12\"" \
368 # Special Display Tests #
372 # Stop at the end of "do_special_tests"
374 set line_dst_incr_a_2 [gdb_get_line_number "incr_a(2);"]
376 mi_create_breakpoint "$line_dst_incr_a_2" \
377 "break-insert operation 2" \
378 -number 2 -func do_special_tests -file ".*var-cmd.c" \
379 -line $line_dst_incr_a_2
381 mi_execute_to "exec-continue" "breakpoint-hit" "do_special_tests" "" \
382 ".*var-cmd.c" $line_dst_incr_a_2 { "" "disp=\"keep\"" } \
383 "continue to do_special_tests"
385 # Test: c_variable-7.10
386 # Desc: create union u
387 mi_create_varobj u u "create local variable u"
389 # Test: c_variable-7.11
391 mi_gdb_test "-var-evaluate-expression u" \
392 "\\^done,value=\"\{\\.\\.\\.\}\"" \
395 # Test: c_variable-7.12
397 mi_gdb_test "-var-info-type u" \
398 "\\^done,type=\"union named_union\"" \
399 "info type variable u"
401 # Test: c_variable-7.13
402 # Desc: is u editable
403 mi_gdb_test "-var-show-attributes u" \
404 "\\^done,attr=\"noneditable\"" \
407 # Test: c_variable-7.14
408 # Desc: number of children of u
409 mi_gdb_test "-var-info-num-children u" \
410 "\\^done,numchild=\"2\"" \
411 "get number of children of u"
413 # Test: c_variable-7.15
414 # Desc: children of u
415 mi_list_varobj_children u {
416 {u.integer integer 0 int}
417 {u.char_ptr char_ptr 1 {char \*}}
418 } "get children of u"
420 # Test: c_variable-7.20
422 mi_create_varobj anonu anonu "create local variable anonu"
424 # Test: c_variable-7.21
425 # Desc: value of anonu
426 mi_gdb_test "-var-evaluate-expression anonu" \
427 "\\^done,value=\"\{\\.\\.\\.\}\"" \
428 "eval variable anonu"
430 # Test: c_variable-7.22
431 # Desc: type of anonu
432 mi_gdb_test "-var-info-type anonu" \
433 "\\^done,type=\"union \{\\.\\.\\.\}\"" \
434 "info type variable anonu"
436 # Test: c_variable-7.23
437 # Desc: is anonu editable
438 mi_gdb_test "-var-show-attributes anonu" \
439 "\\^done,attr=\"noneditable\"" \
442 # Test: c_variable-7.24
443 # Desc: number of children of anonu
444 mi_gdb_test "-var-info-num-children anonu" \
445 "\\^done,numchild=\"3\"" \
446 "get number of children of anonu"
448 # Test: c_variable-7.25
449 # Desc: children of anonu
450 mi_list_varobj_children "anonu" {
454 } "get children of anonu"
456 # Test: c_variable-7.30
457 # Desc: create struct s
458 mi_create_varobj s s "create local variable s"
461 # Test: c_variable-7.31
463 mi_gdb_test "-var-evaluate-expression s" \
464 "\\^done,value=\"\{\\.\\.\\.\}\"" \
467 # Test: c_variable-7.32
469 mi_gdb_test "-var-info-type s" \
470 "\\^done,type=\"struct _simple_struct\"" \
471 "info type variable s"
473 # Test: c_variable-7.33
474 # Desc: is s editable
475 mi_gdb_test "-var-show-attributes s" \
476 "\\^done,attr=\"noneditable\"" \
479 # Test: c_variable-7.34
480 # Desc: number of children of s
481 mi_gdb_test "-var-info-num-children s" \
482 "\\^done,numchild=\"6\"" \
483 "get number of children of s"
485 # Test: c_variable-7.35
486 # Desc: children of s
487 mi_list_varobj_children s {
488 {s.integer integer 0 int}
489 {s.unsigned_integer unsigned_integer 0 "unsigned int"}
490 {s.character character 0 char}
491 {s.signed_character signed_character 0 "signed char"}
492 {s.char_ptr char_ptr 1 {char \*}}
493 {s.array_of_10 array_of_10 10 {int \[10\]}}
494 } "get children of s"
495 #} {integer unsigned_integer character signed_character char_ptr array_of_10}
497 # Test: c_variable-7.40
499 mi_create_varobj anons anons "create local variable anons"
501 # Test: c_variable-7.41
502 # Desc: value of anons
503 mi_gdb_test "-var-evaluate-expression anons" \
504 "\\^done,value=\"\{\\.\\.\\.\}\"" \
505 "eval variable anons"
507 # Test: c_variable-7.42
508 # Desc: type of anons
509 mi_gdb_test "-var-info-type anons" \
510 "\\^done,type=\"struct \{\\.\\.\\.\}\"" \
511 "info type variable anons"
513 # Test: c_variable-7.43
514 # Desc: is anons editable
515 mi_gdb_test "-var-show-attributes anons" \
516 "\\^done,attr=\"noneditable\"" \
519 # Test: c_variable-7.44
520 # Desc: number of children of anons
521 mi_gdb_test "-var-info-num-children anons" \
522 "\\^done,numchild=\"3\"" \
523 "get number of children of anons"
525 # Test: c_variable-7.45
526 # Desc: children of anons
527 mi_list_varobj_children anons {
531 } "get children of anons"
533 # Test: c_variable-7.50
534 # Desc: create enum e
535 mi_create_varobj e e "create local variable e"
537 # Test: c_variable-7.51
539 mi_gdb_test "-var-evaluate-expression e" \
540 "\\^done,value=\"bar\"" \
543 # Test: c_variable-7.52
545 mi_gdb_test "-var-info-type e" \
546 "\\^done,type=\"enum foo\"" \
547 "info type variable e"
549 # Test: c_variable-7.53
550 # Desc: is e editable
551 mi_gdb_test "-var-show-attributes e" \
552 "\\^done,attr=\"editable\"" \
555 # Test: c_variable-7.54
556 # Desc: number of children of e
557 mi_gdb_test "-var-info-num-children e" \
558 "\\^done,numchild=\"0\"" \
559 "get number of children of e"
561 # Test: c_variable-7.55
562 # Desc: children of e
563 mi_gdb_test "-var-list-children e" \
564 "\\^done,numchild=\"0\",has_more=\"0\"" \
567 # Test: c_variable-7.60
569 mi_create_varobj anone anone "create local variable anone"
571 # Test: c_variable-7.61
572 # Desc: value of anone
573 mi_gdb_test "-var-evaluate-expression anone" \
574 "\\^done,value=\"A\"" \
575 "eval variable anone"
577 # Test: c_variable-7.70
579 mi_gdb_test "-var-create anone * anone" \
580 "\\^error,msg=\"Duplicate variable object name\"" \
581 "create duplicate local variable anone"
584 # Test: c_variable-7.72
585 # Desc: type of anone
586 mi_gdb_test "-var-info-type anone" \
587 "\\^done,type=\"enum \{\\.\\.\\.\}\"" \
588 "info type variable anone"
591 # Test: c_variable-7.73
592 # Desc: is anone editable
593 mi_gdb_test "-var-show-attributes anone" \
594 "\\^done,attr=\"editable\"" \
597 # Test: c_variable-7.74
598 # Desc: number of children of anone
599 mi_gdb_test "-var-info-num-children anone" \
600 "\\^done,numchild=\"0\"" \
601 "get number of children of anone"
603 # Test: c_variable-7.75
604 # Desc: children of anone
605 mi_gdb_test "-var-list-children anone" \
606 "\\^done,numchild=\"0\",has_more=\"0\"" \
607 "get children of anone"
611 if ![mi_gdb_test "p/x \$fp" ".*($hex).*\\^done" "print FP register"] {
612 set fp $expect_out(3,string)
615 mi_continue_to "incr_a"
617 # Test: c_variable-7.81
618 # Desc: Create variables in different scopes
619 mi_gdb_test "-var-create a1 * a" \
620 "\\^done,name=\"a1\",numchild=\"0\",value=\".*\",type=\"char\".*" \
621 "create local variable a1"
623 if { [info exists fp] } {
624 mi_gdb_test "-var-create a2 $fp a" \
625 "\\^done,name=\"a2\",numchild=\"0\",value=\".*\",type=\"int\".*" \
626 "create variable a2 in different scope"
628 untested "create variable a2 in different scope"
631 #gdbtk_test c_variable-7.81 {create variables in different scopes} {
632 # set a1 [gdb_variable create -expr a]
633 # set a2 [gdb_variable create -expr a -frame $fp]
636 # lappend vals [$a1 value]
637 # lappend vals [$a2 value]