1 # Copyright (C) 1999 2000 Cygnus Solutions
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
33 set testfile "var-cmd"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
37 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 mi_gdb_reinitialize_dir $srcdir/$subdir
42 mi_gdb_load ${binfile}
47 # Variable Creation tests #
51 # Test: c_variable-1.1
52 # Desc: Create global variable
54 mi_gdb_test "111-var-create global_simple * global_simple" \
55 "111\\^done,name=\"global_simple\",numchild=\"6\",type=\"simpleton\"" \
56 "create global variable"
58 # Test: c_variable-1.2
59 # Desc: Create non-existent variable
61 mi_gdb_test "112-var-create bogus_unknown_variable * bogus_unknown_variable" \
62 "&\"No symbol \\\\\"bogus_unknown_variable\\\\\" in current context.\\\\n\".*112\\^error,msg=\"No symbol \\\\\"bogus_unknown_variable\\\\\" in current context.\"" \
63 "create non-existent variable"
65 # Test: c_variable-1.3
66 # Desc: Create out of scope variable
68 mi_gdb_test "113-var-create argc * argc" \
69 "&\"No symbol \\\\\"argc\\\\\" in current context.\\\\n\".*113\\^error,msg=\"No symbol \\\\\"argc\\\\\" in current context.\"" \
70 "create out of scope variable"
72 mi_gdb_test "200-break-insert do_locals_tests" \
73 "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"do_locals_tests\",file=\".*var-cmd.c\",line=\"106\",times=\"0\"\}" \
74 "break-insert operation"
77 # The running part has been checked already by mi_run_cmd
79 -re "\[\r\n\]*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"106\"\}\r\n$mi_gdb_prompt$" {
80 pass "run to do_locals_tests"
82 -re ".*$mi_gdb_prompt$" {fail "run todo_locals_tests (2)"}
83 timeout {fail "run to do_locals_tests (timeout 2)"}
86 # Test: c_variable-1.4
87 # Desc: create local variables
89 mi_gdb_test "-var-create linteger * linteger" \
90 "\\^done,name=\"linteger\",numchild=\"0\",type=\"int\"" \
91 "create local variable linteger"
93 mi_gdb_test "-var-create lpinteger * lpinteger" \
94 "\\^done,name=\"lpinteger\",numchild=\"1\",type=\"int \\*\"" \
95 "create local variable lpinteger"
97 mi_gdb_test "-var-create lcharacter * lcharacter" \
98 "\\^done,name=\"lcharacter\",numchild=\"0\",type=\"char\"" \
99 "create local variablelcharacter "
101 mi_gdb_test "-var-create lpcharacter * lpcharacter" \
102 "\\^done,name=\"lpcharacter\",numchild=\"0\",type=\"char \\*\"" \
103 "create local variable lpcharacter"
105 mi_gdb_test "-var-create llong * llong" \
106 "\\^done,name=\"llong\",numchild=\"0\",type=\"long int\"" \
107 "create local variable llong"
109 mi_gdb_test "-var-create lplong * lplong" \
110 "\\^done,name=\"lplong\",numchild=\"1\",type=\"long int \\*\"" \
111 "create local variable lplong"
113 mi_gdb_test "-var-create lfloat * lfloat" \
114 "\\^done,name=\"lfloat\",numchild=\"0\",type=\"float\"" \
115 "create local variable lfloat"
117 mi_gdb_test "-var-create lpfloat * lpfloat" \
118 "\\^done,name=\"lpfloat\",numchild=\"1\",type=\"float \\*\"" \
119 "create local variable lpfloat"
121 mi_gdb_test "-var-create ldouble * ldouble" \
122 "\\^done,name=\"ldouble\",numchild=\"0\",type=\"double\"" \
123 "create local variable ldouble"
125 mi_gdb_test "-var-create lpdouble * lpdouble" \
126 "\\^done,name=\"lpdouble\",numchild=\"1\",type=\"double \\*\"" \
127 "create local variable lpdouble"
129 mi_gdb_test "-var-create lsimple * lsimple" \
130 "\\^done,name=\"lsimple\",numchild=\"6\",type=\"struct _simple_struct\"" \
131 "create local variable lsimple"
133 mi_gdb_test "-var-create lpsimple * lpsimple" \
134 "\\^done,name=\"lpsimple\",numchild=\"6\",type=\"struct _simple_struct \\*\"" \
135 "create local variable lpsimple"
137 mi_gdb_test "-var-create func * func" \
138 "\\^done,name=\"func\",numchild=\"0\",type=\"void \\(\\*\\)\\(\\)\"" \
139 "create local variable func"
141 # Test: c_variable-1.5
142 # Desc: create lsimple.character
143 mi_gdb_test "-var-create lsimple.character * lsimple.character" \
144 "\\^done,name=\"lsimple.character\",numchild=\"0\",type=\"char\"" \
145 "create lsimple.character"
147 # Test: c_variable-1.6
148 # Desc: create lpsimple->integer
149 mi_gdb_test "-var-create lsimple->integer * lsimple->integer" \
150 "\\^done,name=\"lsimple->integer\",numchild=\"0\",type=\"int\"" \
151 "create lsimple->integer"
153 # Test: c_variable-1.7
154 # Desc: ceate lsimple.integer
155 mi_gdb_test "-var-create lsimple.integer * lsimple.integer" \
156 "\\^done,name=\"lsimple.integer\",numchild=\"0\",type=\"int\"" \
157 "create lsimple->integer"
160 # Test: c_variable-1.9
161 # Desc: create type name
162 # Type names (like int, long, etc..) are all proper expressions to gdb.
163 # make sure variable code does not allow users to create variables, though.
164 mi_gdb_test "-var-create int * int" \
165 "&\"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\"" \
171 # Value changed tests #
175 # Test: c_variable-2.1
176 # Desc: check whether values changed at do_block_tests
177 mi_gdb_test "-var-update *" \
178 "\\^done,changelist=\{\}" \
181 # Step over "linteger = 1234;"
182 send_gdb "-exec-step\n"
184 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"107\"\}\r\n$mi_gdb_prompt$" {
185 pass "step at do_locals_tests"
188 fail "step at do_locals_tests (timeout)"
192 # Test: c_variable-2.2
193 # Desc: check whether only linteger changed values
194 mi_gdb_test "-var-update *" \
195 "\\^done,changelist=\{name=\"linteger\"\}" \
196 "update all vars: linteger changed"
198 # Step over "lpinteger = &linteger;"
199 send_gdb "-exec-step\n"
201 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"108\"\}\r\n$mi_gdb_prompt$" {
202 pass "step at do_locals_tests"
205 fail "step at do_locals_tests (timeout)"
209 # Test: c_variable-2.3
210 # Desc: check whether only lpinteger changed
211 mi_gdb_test "-var-update *" \
212 "\\^done,changelist=\{name=\"lpinteger\"\}" \
213 "update all vars: lpinteger changed"
215 # Step over "lcharacter = 'a';"
216 send_gdb "-exec-step\n"
218 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"109\"\}\r\n$mi_gdb_prompt$" {
219 pass "step at do_locals_tests"
222 fail "step at do_locals_tests (timeout)"
226 # Test: c_variable-2.4
227 # Desc: check whether only lcharacter changed
228 mi_gdb_test "-var-update *" \
229 "\\^done,changelist=\{name=\"lcharacter\"\}" \
230 "update all vars: lcharacter changed"
232 # Step over "lpcharacter = &lcharacter;"
233 send_gdb "-exec-step\n"
235 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"110\"\}\r\n$mi_gdb_prompt$" {
236 pass "step at do_locals_tests"
239 fail "step at do_locals_tests (timeout)"
243 # Test: c_variable-2.5
244 # Desc: check whether only lpcharacter changed
245 mi_gdb_test "-var-update *" \
246 "\\^done,changelist=\{name=\"lpcharacter\"\}" \
247 "update all vars: lpcharacter changed"
255 # ldouble = 2.718281828459045;
256 # lpdouble = &ldouble;
257 # lsimple.integer = 1234;
258 # lsimple.unsigned_integer = 255;
259 # lsimple.character = 'a';
261 send_gdb "-exec-step 9\n"
263 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"119\"\}\r\n$mi_gdb_prompt$" {
264 pass "step at do_locals_tests"
267 fail "step at do_locals_tests (timeout)"
271 # Test: c_variable-2.6
272 # Desc: check whether llong, lplong, lfloat, lpfloat, ldouble, lpdouble, lsimple.integer,
273 # lsimple.unsigned_character lsimple.integer lsimple.character changed
274 mi_gdb_test "-var-update *" \
275 "\\^done,changelist=\{name=\"lsimple.integer\",name=\"lsimple->integer\",name=\"lsimple.character\",name=\"lpdouble\",name=\"ldouble\",name=\"lpfloat\",name=\"lfloat\",name=\"lplong\",name=\"llong\"\}" \
276 "update all vars: many changed"
279 # lsimple.signed_character = 21;
280 # lsimple.char_ptr = &lcharacter;
281 # lpsimple = &lsimple;
284 send_gdb "-exec-step 4\n"
286 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"125\"\}\r\n$mi_gdb_prompt$" {
287 pass "step at do_locals_tests"
290 fail "step at do_locals_tests (timeout)"
294 # Test: c_variable-2.7
295 # Desc: check whether (lsimple.signed_character, lsimple.char_ptr) lpsimple, func changed
296 mi_gdb_test "-var-update *" \
297 "\\^done,changelist=\{name=\"func\",name=\"lpsimple\"\}" \
298 "update all vars: func and lpsimple changed"
305 # ldouble = 5.498548281828172;
306 # lsimple.integer = 255;
307 # lsimple.unsigned_integer = 4321;
308 # lsimple.character = 'b';
310 send_gdb "-exec-step 8\n"
312 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"133\"\}\r\n$mi_gdb_prompt$" {
313 pass "step at do_locals_tests"
316 fail "step at do_locals_tests (timeout)"
320 # Test: c_variable-2.8
321 # Desc: check whether linteger, lcharacter, llong, lfoat, ldouble, lsimple.integer,
322 # lpsimple.integer lsimple.character changed
323 # Note: this test also checks that lpsimple->integer and lsimple.integer have
324 # changed (they are the same)
325 mi_gdb_test "-var-update *" \
326 "\\^done,changelist=\{name=\"lsimple.integer\",name=\"lsimple->integer\",name=\"lsimple.character\",name=\"ldouble\",name=\"lfloat\",name=\"llong\",name=\"lcharacter\",name=\"linteger\"\}" \
327 "update all vars: func and lpsimple changed"
332 # Test assignment to variables. More tests on assignment are in other files.
335 mi_gdb_test "-var-assign global_simple 0" \
336 "&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msg=\"mi_cmd_var_assign: Variable object is not editable\"" \
337 "assign to global_simple"
339 mi_gdb_test "-var-assign linteger 3333" \
340 "\\^done,value=\"3333\"" \
343 mi_gdb_test "-var-evaluate-expression linteger" \
344 "\\^done,value=\"3333\"" \
347 mi_gdb_test "-var-assign lpinteger \"&linteger + 3\"" \
348 "\\^done,value=\"$hex\"" \
349 "assign to lpinteger"
351 mi_gdb_test "-var-evaluate-expression lpinteger" \
352 "\\^done,value=\"$hex\"" \
355 # reset the values to the original ones so that the rest of the file doesn't suffer.
357 mi_gdb_test "-var-assign linteger 4321" \
358 "\\^done,value=\"4321\"" \
361 mi_gdb_test "-var-assign lpinteger &linteger" \
362 "\\^done,value=\"$hex\"" \
363 "assign to lpinteger"
365 mi_gdb_test "-var-assign lcharacter 'z'" \
366 "\\^done,value=\"122 'z'\"" \
367 "assign to lcharacter"
369 mi_gdb_test "-var-evaluate-expression lcharacter" \
370 "\\^done,value=\"122 'z'\"" \
373 mi_gdb_test "-var-assign llong 1313L" \
374 "\\^done,value=\"1313\"" \
376 mi_gdb_test "-var-evaluate-expression llong" \
377 "\\^done,value=\"1313\"" \
379 mi_gdb_test "-var-assign llong 1212L" \
380 "\\^done,value=\"1212\"" \
383 mi_gdb_test "-var-assign lplong &llong+4" \
384 "\\^done,value=\"$hex\"" \
386 mi_gdb_test "-var-evaluate-expression lplong" \
387 "\\^done,value=\"$hex\"" \
389 mi_gdb_test "-var-assign lplong &llong" \
390 "\\^done,value=\"$hex\"" \
393 mi_gdb_test "-var-assign lfloat 3.4" \
394 "\\^done,value=\"3.4.*\"" \
396 mi_gdb_test "-var-evaluate-expression lfloat" \
397 "\\^done,value=\"3.4.*\"" \
399 mi_gdb_test "-var-assign lfloat 1.2" \
400 "\\^done,value=\"1.2.*\"" \
403 mi_gdb_test "-var-assign lpfloat &lfloat+4" \
404 "\\^done,value=\"$hex\"" \
407 mi_gdb_test "-var-assign ldouble 5.333318284590435" \
408 "\\^done,value=\"5.333318284590435\"" \
411 mi_gdb_test "-var-assign func do_block_tests" \
412 "\\^done,value=\"$hex <do_block_tests>\"" \
415 mi_gdb_test "-var-assign lsimple.character 'd'" \
416 "\\^done,value=\"100 'd'\"" \
417 "assign to lsimple.character"
419 mi_gdb_test "-var-assign lsimple->integer 222" \
420 "\\^done,value=\"222\"" \
421 "assign to lsimple->integer"
423 mi_gdb_test "-var-assign lsimple.integer 333" \
424 "\\^done,value=\"333\"" \
425 "assign to lsimple.integer"
428 # End of assign tests
431 mi_gdb_test "-break-insert subroutine1" \
432 "\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"subroutine1\",file=\".*var-cmd.c\",line=\"146\",times=\"0\"\}" \
433 "break-insert subroutine1"
434 send_gdb "-exec-continue\n"
436 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"breakpoint-hit\",bkptno=\"2\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"subroutine1\",args=\{\{name=\"i\",value=\"4321\"\},\{name=\"l\",value=\"$hex\"\}\},file=\".*var-cmd.c\",line=\"146\"\}\r\n$mi_gdb_prompt$" {
437 pass "continue to subroutine1"
440 fail "continue to subroutine1 (timeout)"
444 # Test: c_variable-2.10
445 # Desc: create variable for locals i,l in subroutine1
446 mi_gdb_test "-var-create i * i" \
447 "\\^done,name=\"i\",numchild=\"0\",type=\"int\"" \
450 mi_gdb_test "-var-create l * l" \
451 "\\^done,name=\"l\",numchild=\"1\",type=\"long int \\*\"" \
454 # Test: c_variable-2.11
455 # Desc: create do_locals_tests local in subroutine1
456 mi_gdb_test "-var-create linteger * linteger" \
457 "&\"No symbol \\\\\"linteger\\\\\" in current context.\\\\n\".*\\^error,msg=\"No symbol \\\\\"linteger\\\\\" in current context.\"" \
460 send_gdb "-exec-step\n"
462 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"subroutine1\",args=\{\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}\},file=\".*var-cmd.c\",line=\"147\"\}\r\n$mi_gdb_prompt$" {
463 pass "step at subroutine1"
466 fail "step at subroutine1 (timeout)"
470 # Test: c_variable-2.12
471 # Desc: change global_simple.integer
472 # Note: This also tests whether we are reporting changes in structs properly.
473 # gdb normally would say that global_simple has changed, but we
474 # special case that, since it is not what a human expects to see.
475 mi_gdb_test "-var-update *" \
476 "\\^done,changelist=\{FIXME: WHAT IS CORRECT HERE\}" \
477 "update all vars: changed FIXME"
479 send_gdb "-exec-step\n"
481 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"subroutine1\",args=\{\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}\},file=\".*var-cmd.c\",line=\"148\"\}\r\n$mi_gdb_prompt$" {
482 pass "step at subroutine1"
484 timeout { fail "step at subroutine1 (timeout)" }
487 # Test: c_variable-2.13
488 # Desc: change subroutine1 local i
489 mi_gdb_test "-var-update *" \
490 "\\^done,changelist=\{name=\"i\"\}" \
491 "update all vars: i changed"
493 send_gdb "-exec-step\n"
495 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"subroutine1\",args=\{\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}\},file=\".*var-cmd.c\",line=\"149\"\}\r\n$mi_gdb_prompt$" {
496 pass "step at subroutine1"
498 timeout { fail "step at subroutine1 (timeout)" }
501 # Test: c_variable-2.14
502 # Desc: change do_locals_tests local llong
503 mi_gdb_test "-var-update *" \
504 "\\^done,changelist=\{name=\"llong\"\}" \
505 "update all vars: llong changed"
507 send_gdb "-exec-next\n"
509 -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\{\},file=\".*var-cmd.c\",line=\"136\"\}\r\n$mi_gdb_prompt$" {
510 pass "next out of subroutine1"
512 timeout { fail "next out of subroutine1 (timeout)" }
515 # Test: c_variable-2.15
516 # Desc: check for out of scope subroutine1 locals
517 mi_gdb_test "-var-update *" \
518 "\\^done,changelist=\{\}" \
519 "update all vars: none changed"
521 # Done with locals/globals tests. Erase all variables
522 #delete_all_variables
523 mi_gdb_test "-var-delete global_simple" \
524 "\\^done,ndeleted=\"1\"" \
527 mi_gdb_test "-var-delete linteger" \
528 "\\^done,ndeleted=\"1\"" \
529 "delete var linteger"
531 mi_gdb_test "-var-delete lpinteger" \
532 "\\^done,ndeleted=\"1\"" \
533 "delete var lpinteger"
535 mi_gdb_test "-var-delete lcharacter" \
536 "\\^done,ndeleted=\"1\"" \
537 "delete var lcharacter"
539 mi_gdb_test "-var-delete lpcharacter" \
540 "\\^done,ndeleted=\"1\"" \
541 "delete var lpcharacter"
543 mi_gdb_test "-var-delete llong" \
544 "\\^done,ndeleted=\"1\"" \
547 mi_gdb_test "-var-delete lplong" \
548 "\\^done,ndeleted=\"1\"" \
551 mi_gdb_test "-var-delete lfloat" \
552 "\\^done,ndeleted=\"1\"" \
555 mi_gdb_test "-var-delete lpfloat" \
556 "\\^done,ndeleted=\"1\"" \
559 mi_gdb_test "-var-delete ldouble" \
560 "\\^done,ndeleted=\"1\"" \
563 mi_gdb_test "-var-delete lpdouble" \
564 "\\^done,ndeleted=\"1\"" \
565 "delete var lpdouble"
567 mi_gdb_test "-var-delete lsimple" \
568 "\\^done,ndeleted=\"1\"" \
571 mi_gdb_test "-var-delete lpsimple" \
572 "\\^done,ndeleted=\"1\"" \
573 "delete var lpsimple"
575 mi_gdb_test "-var-delete func" \
576 "\\^done,ndeleted=\"1\"" \
579 mi_gdb_test "-var-delete lsimple.character" \
580 "\\^done,ndeleted=\"1\"" \
581 "delete var lsimple.character"
583 mi_gdb_test "-var-delete lsimple->integer" \
584 "\\^done,ndeleted=\"1\"" \
585 "delete var lsimple->integer"
587 mi_gdb_test "-var-delete lsimple.integer" \
588 "\\^done,ndeleted=\"1\"" \
589 "delete var lsimple.integer"
591 mi_gdb_test "-var-delete i" \
592 "\\^done,ndeleted=\"1\"" \
595 mi_gdb_test "-var-delete l" \
596 "\\^done,ndeleted=\"1\"" \
603 # change-log-default-name: "ChangeLog-mi"