* mi-console.exp: Update copyright.
[external/binutils.git] / gdb / testsuite / gdb.mi / mi-var-cmd.exp
1 #   Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
2 #
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.
7 #
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.
12 #
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.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # Test essential Machine interface (MI) operations
21 #
22 # Verify that, using the MI, we can create, update, delete variables.
23 #
24
25
26 load_lib mi-support.exp
27 set MIFLAGS "-i=mi"
28
29 gdb_exit
30 if [mi_gdb_start] {
31     continue
32 }
33
34 set testfile "var-cmd"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
38     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
39 }
40
41 mi_delete_breakpoints
42 mi_gdb_reinitialize_dir $srcdir/$subdir
43 mi_gdb_load ${binfile}
44
45
46 #####                   #####
47 #                           #
48 #  Variable Creation tests  #
49 #                           #
50 #####                   #####
51
52 # Test:  c_variable-1.1
53 # Desc:  Create global variable
54
55 mi_gdb_test "111-var-create global_simple * global_simple" \
56         "111\\^done,name=\"global_simple\",numchild=\"6\",type=\"simpleton\"" \
57         "create global variable"
58
59 # Test: c_variable-1.2
60 # Desc: Create non-existent variable
61
62 mi_gdb_test "112-var-create bogus_unknown_variable * bogus_unknown_variable" \
63         "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*112\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
64         "create non-existent variable"
65
66 # Test: c_variable-1.3
67 # Desc: Create out of scope variable
68
69 mi_gdb_test "113-var-create argc * argc" \
70         "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*113\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
71         "create out of scope variable"
72
73 mi_gdb_test "200-break-insert do_locals_tests" \
74         "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\"\}" \
75         "break-insert operation"
76
77 mi_run_cmd
78 # The running part has been checked already by mi_run_cmd
79 gdb_expect {
80     -re "\[\r\n\]*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"do_locals_tests\",args=\\\[\\\],file=\".*var-cmd.c\",line=\"106\"\}\r\n$mi_gdb_prompt$" {
81         pass "run to do_locals_tests"
82     }
83     -re ".*$mi_gdb_prompt$" {fail "run to do_locals_tests (2)"}
84     timeout {fail "run to do_locals_tests (timeout 2)"}
85 }
86
87 # Test: c_variable-1.4
88 # Desc: create local variables
89
90 mi_gdb_test "-var-create linteger * linteger" \
91         "\\^done,name=\"linteger\",numchild=\"0\",type=\"int\"" \
92         "create local variable linteger"
93
94 mi_gdb_test "-var-create lpinteger * lpinteger" \
95         "\\^done,name=\"lpinteger\",numchild=\"1\",type=\"int \\*\"" \
96         "create local variable lpinteger"
97
98 mi_gdb_test "-var-create lcharacter * lcharacter" \
99         "\\^done,name=\"lcharacter\",numchild=\"0\",type=\"char\"" \
100         "create local variablelcharacter "
101
102 mi_gdb_test "-var-create lpcharacter * lpcharacter" \
103         "\\^done,name=\"lpcharacter\",numchild=\"1\",type=\"char \\*\"" \
104         "create local variable lpcharacter"
105
106 mi_gdb_test "-var-create llong * llong" \
107         "\\^done,name=\"llong\",numchild=\"0\",type=\"long int\"" \
108         "create local variable llong"
109
110 mi_gdb_test "-var-create lplong * lplong" \
111         "\\^done,name=\"lplong\",numchild=\"1\",type=\"long int \\*\"" \
112         "create local variable lplong"
113
114 mi_gdb_test "-var-create lfloat * lfloat" \
115         "\\^done,name=\"lfloat\",numchild=\"0\",type=\"float\"" \
116         "create local variable lfloat"
117
118 mi_gdb_test "-var-create lpfloat * lpfloat" \
119         "\\^done,name=\"lpfloat\",numchild=\"1\",type=\"float \\*\"" \
120         "create local variable lpfloat"
121
122 mi_gdb_test "-var-create ldouble * ldouble" \
123         "\\^done,name=\"ldouble\",numchild=\"0\",type=\"double\"" \
124         "create local variable ldouble"
125
126 mi_gdb_test "-var-create lpdouble * lpdouble" \
127         "\\^done,name=\"lpdouble\",numchild=\"1\",type=\"double \\*\"" \
128         "create local variable lpdouble"
129
130 mi_gdb_test "-var-create lsimple * lsimple" \
131         "\\^done,name=\"lsimple\",numchild=\"6\",type=\"struct _simple_struct\"" \
132         "create local variable lsimple"
133
134 mi_gdb_test "-var-create lpsimple * lpsimple" \
135         "\\^done,name=\"lpsimple\",numchild=\"6\",type=\"struct _simple_struct \\*\"" \
136         "create local variable lpsimple"
137
138 mi_gdb_test "-var-create func * func" \
139         "\\^done,name=\"func\",numchild=\"0\",type=\"void \\(\\*\\)\\((void|)\\)\"" \
140         "create local variable func"
141
142 # Test: c_variable-1.5
143 # Desc: create lsimple.character
144 mi_gdb_test "-var-create lsimple.character * lsimple.character" \
145         "\\^done,name=\"lsimple.character\",numchild=\"0\",type=\"char\"" \
146         "create lsimple.character"
147
148 # Test: c_variable-1.6
149 # Desc: create lpsimple->integer
150 mi_gdb_test "-var-create lsimple->integer * lsimple->integer" \
151         "\\^done,name=\"lsimple->integer\",numchild=\"0\",type=\"int\"" \
152         "create lsimple->integer"
153
154 # Test: c_variable-1.7
155 # Desc: ceate lsimple.integer
156 mi_gdb_test "-var-create lsimple.integer * lsimple.integer" \
157         "\\^done,name=\"lsimple.integer\",numchild=\"0\",type=\"int\"" \
158         "create lsimple->integer"
159
160
161 # Test: c_variable-1.9
162 # Desc: create type name
163 #    Type names (like int, long, etc..) are all proper expressions to gdb.
164 #    make sure variable code does not allow users to create variables, though.
165 mi_gdb_test "-var-create int * int" \
166         "&\"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\"" \
167         "create int"
168
169
170 #####             #####
171 #                     #
172 # Value changed tests #
173 #                     #
174 #####             #####
175
176 # Test: c_variable-2.1
177 # Desc: check whether values changed at do_block_tests
178 mi_gdb_test "-var-update *" \
179         "\\^done,changelist=\{\}" \
180         "update all vars"
181
182 # Step over "linteger = 1234;"
183 mi_step_to "do_locals_tests" "" "var-cmd.c" "107" "step at do_locals_test"
184
185 # Test: c_variable-2.2
186 # Desc: check whether only linteger changed values
187 mi_gdb_test "-var-update *" \
188         "\\^done,changelist=\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\"\}" \
189         "update all vars: linteger changed"
190
191 # Step over "lpinteger = &linteger;"
192 mi_step_to "do_locals_tests" "" "var-cmd.c" 108 "step at do_locals_tests (2)"
193
194 # Test: c_variable-2.3
195 # Desc: check whether only lpinteger changed
196 mi_gdb_test "-var-update *" \
197         "\\^done,changelist=\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\"\}" \
198         "update all vars: lpinteger changed"
199
200 # Step over "lcharacter = 'a';"
201 mi_step_to "do_locals_tests" "" "var-cmd.c" "109" "step at do_locals_tests (3)"
202
203 # Test: c_variable-2.4
204 # Desc: check whether only lcharacter changed
205 mi_gdb_test "-var-update *" \
206         "\\^done,changelist=\{name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\"\}" \
207         "update all vars: lcharacter changed"
208
209 # Step over "lpcharacter = &lcharacter;"
210 mi_step_to "do_locals_tests" "" "var-cmd.c" "110" "step at do_locals_tests (4)"
211
212 # Test: c_variable-2.5
213 # Desc: check whether only lpcharacter changed
214 mi_gdb_test "-var-update *" \
215         "\\^done,changelist=\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\"\}" \
216         "update all vars: lpcharacter changed"
217
218
219 # Step over:
220 #  llong = 2121L;
221 #  lplong = &llong;
222 #  lfloat = 2.1;
223 #  lpfloat = &lfloat;
224 #  ldouble = 2.718281828459045;
225 #  lpdouble = &ldouble;
226 #  lsimple.integer = 1234;
227 #  lsimple.unsigned_integer = 255;
228 #  lsimple.character = 'a';
229
230 mi_execute_to "exec-step 9" "end-stepping-range" "do_locals_tests" "" \
231         "var-cmd.c" "119" "" "step at do_locals_tests (5)"
232
233 # Test: c_variable-2.6
234 # Desc: check whether llong, lplong, lfloat, lpfloat, ldouble, lpdouble, lsimple.integer,
235 #       lsimple.unsigned_character lsimple.integer lsimple.character changed
236 mi_gdb_test "-var-update *" \
237         "\\^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\"\}" \
238         "update all vars: many changed"
239
240 # Step over:
241 #  lsimple.signed_character = 21;
242 #  lsimple.char_ptr = &lcharacter;
243 #  lpsimple = &lsimple;
244 #  func = nothing;
245
246 mi_execute_to "exec-step 4" "end-stepping-range" "do_locals_tests" "" \
247         "var-cmd.c" "125" "" "step at do_locals_tests (6)"
248
249 # Test: c_variable-2.7
250 # Desc: check whether (lsimple.signed_character, lsimple.char_ptr) lpsimple, func changed
251 mi_gdb_test "-var-update *" \
252         "\\^done,changelist=\{name=\"func\",in_scope=\"true\",type_changed=\"false\",name=\"lpsimple\",in_scope=\"true\",type_changed=\"false\"\}" \
253         "update all vars: func and lpsimple changed"
254
255 # Step over
256 #  linteger = 4321;
257 #  lcharacter = 'b';
258 #  llong = 1212L;
259 #  lfloat = 1.2;
260 #  ldouble = 5.498548281828172;
261 #  lsimple.integer = 255;
262 #  lsimple.unsigned_integer = 4321;
263 #  lsimple.character = 'b';
264
265 mi_execute_to "exec-step 8" "end-stepping-range" "do_locals_tests" "" \
266         "var-cmd.c" "133" "" "step at do_locals_tests (7)"
267
268 # Test: c_variable-2.8
269 # Desc: check whether linteger, lcharacter, llong, lfoat, ldouble, lsimple.integer,
270 #       lpsimple.integer lsimple.character changed
271 # Note: this test also checks that lpsimple->integer and lsimple.integer have
272 #       changed (they are the same)
273 mi_gdb_test "-var-update *" \
274         "\\^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\"\}" \
275         "update all vars: func and lpsimple changed"
276
277
278 ### 
279 #
280 # Test assignment to variables. More tests on assignment are in other files.
281 #
282 ###
283 mi_gdb_test "-var-assign global_simple 0" \
284         "&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msg=\"mi_cmd_var_assign: Variable object is not editable\"" \
285         "assign to global_simple"
286
287 mi_gdb_test "-var-assign linteger 3333" \
288         "\\^done,value=\"3333\"" \
289         "assign to linteger"
290
291 mi_gdb_test "-var-evaluate-expression linteger" \
292         "\\^done,value=\"3333\"" \
293         "eval linteger"
294
295 mi_gdb_test "-var-assign lpinteger \"&linteger + 3\"" \
296         "\\^done,value=\"$hex\"" \
297         "assign to lpinteger"
298
299 mi_gdb_test "-var-evaluate-expression lpinteger" \
300         "\\^done,value=\"$hex\"" \
301         "eval lpinteger"
302
303 # reset the values to the original ones so that the rest of the file doesn't suffer.
304
305 mi_gdb_test "-var-assign linteger 4321" \
306         "\\^done,value=\"4321\"" \
307         "assign to linteger"
308
309 mi_gdb_test "-var-assign lpinteger &linteger" \
310         "\\^done,value=\"$hex\"" \
311         "assign to lpinteger"
312
313 mi_gdb_test "-var-assign lcharacter 'z'" \
314         "\\^done,value=\"122 'z'\"" \
315         "assign to lcharacter"
316
317 mi_gdb_test "-var-evaluate-expression lcharacter" \
318         "\\^done,value=\"122 'z'\"" \
319         "eval lcharacter"
320
321 mi_gdb_test "-var-assign llong 1313L" \
322         "\\^done,value=\"1313\"" \
323         "assign to llong"
324 mi_gdb_test "-var-evaluate-expression llong" \
325         "\\^done,value=\"1313\"" \
326         "eval llong"
327 mi_gdb_test "-var-assign llong 1212L" \
328         "\\^done,value=\"1212\"" \
329         "assign to llong"
330
331 mi_gdb_test "-var-assign lplong &llong+4" \
332         "\\^done,value=\"$hex\"" \
333         "assign to lplong"
334 mi_gdb_test "-var-evaluate-expression lplong" \
335         "\\^done,value=\"$hex\"" \
336         "eval lplong"
337 mi_gdb_test "-var-assign lplong &llong" \
338         "\\^done,value=\"$hex\"" \
339         "assign to lplong"
340
341 mi_gdb_test "-var-assign lfloat 3.4567" \
342         "\\^done,value=\"3.45.*\"" \
343         "assign to lfloat"
344 mi_gdb_test "-var-evaluate-expression lfloat" \
345         "\\^done,value=\"3.45.*\"" \
346         "eval lfloat"
347 mi_gdb_test "-var-assign lfloat 1.2345" \
348         "\\^done,value=\"1.23.*\"" \
349         "assign to lfloat"
350
351 mi_gdb_test "-var-assign lpfloat &lfloat+4" \
352         "\\^done,value=\"$hex\"" \
353         "assign to lpfloat"
354
355 mi_gdb_test "-var-assign ldouble 5.333318284590435" \
356         "\\^done,value=\"5.333318284590435\"" \
357         "assign to ldouble"
358
359 mi_gdb_test "-var-assign func do_block_tests" \
360         "\\^done,value=\"$hex <do_block_tests>\"" \
361         "assign to func"
362
363 mi_gdb_test "-var-assign lsimple.character 'd'" \
364         "\\^done,value=\"100 'd'\"" \
365         "assign to lsimple.character"
366
367 mi_gdb_test "-var-assign  lsimple->integer 222" \
368         "\\^done,value=\"222\"" \
369         "assign to lsimple->integer"
370
371 mi_gdb_test "-var-assign lsimple.integer 333" \
372         "\\^done,value=\"333\"" \
373         "assign to lsimple.integer"
374
375 ######
376 # End of assign tests 
377 #####
378
379 mi_gdb_test "-break-insert subroutine1" \
380         "\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"subroutine1\",file=\".*var-cmd.c\",line=\"146\",times=\"0\"\}" \
381         "break-insert subroutine1"
382 mi_continue_to "2" "subroutine1" \
383         "\{name=\"i\",value=\"4321\"\},\{name=\"l\",value=\"$hex\"\}" \
384         "var-cmd.c" "146" "continue to subroutine1"
385
386 # Test: c_variable-2.10
387 # Desc: create variable for locals i,l in subroutine1
388 mi_gdb_test "-var-create i  * i" \
389         "\\^done,name=\"i\",numchild=\"0\",type=\"int\"" \
390         "create i"
391
392 mi_gdb_test "-var-create l * l" \
393         "\\^done,name=\"l\",numchild=\"1\",type=\"long int \\*\"" \
394         "create l"
395
396 # Test: c_variable-2.11
397 # Desc: create do_locals_tests local in subroutine1
398 mi_gdb_test "-var-create linteger * linteger" \
399         "&\"mi_cmd_var_create: unable to create variable object\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
400         "create linteger"
401
402 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
403         "var-cmd.c" "147" "step at subroutine1"
404
405 # Test: c_variable-2.12
406 # Desc: change global_simple.integer
407 # Note: This also tests whether we are reporting changes in structs properly.
408 #       gdb normally would say that global_simple has changed, but we
409 #       special case that, since it is not what a human expects to
410 #       see.
411
412 setup_xfail *-*-*
413 mi_gdb_test "-var-update *" \
414         "\\^done,changelist=\{FIXME: WHAT IS CORRECT HERE\}" \
415         "update all vars: changed FIXME"
416 clear_xfail *-*-*
417
418 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
419         "var-cmd.c" "148" "step at subroutine1 (2)"
420
421 # Test: c_variable-2.13
422 # Desc: change subroutine1 local i
423 mi_gdb_test "-var-update *" \
424         "\\^done,changelist=\{name=\"i\",in_scope=\"true\",type_changed=\"false\"\}" \
425         "update all vars: i changed"
426
427 mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
428         "var-cmd.c" "149" "step at subroutine1 (3)"
429
430 # Test: c_variable-2.14
431 # Desc: change do_locals_tests local llong
432 mi_gdb_test "-var-update *" \
433         "\\^done,changelist=\{name=\"llong\",in_scope=\"true\",type_changed=\"false\"\}" \
434         "update all vars: llong changed"
435
436 mi_next_to "do_locals_tests" "" "var-cmd.c" "136" "next out of subroutine1"
437
438 # Test: c_variable-2.15
439 # Desc: check for out of scope subroutine1 locals
440 mi_gdb_test "-var-update *" \
441         "\\^done,changelist=\{name=\"l\",in_scope=\"false\",name=\"i\",in_scope=\"false\"\}" \
442         "update all vars: all now out of scope"
443
444 # Done with locals/globals tests. Erase all variables
445 #delete_all_variables
446 mi_gdb_test "-var-delete global_simple" \
447         "\\^done,ndeleted=\"1\"" \
448         "delete var"
449
450 mi_gdb_test "-var-delete linteger" \
451         "\\^done,ndeleted=\"1\"" \
452         "delete var linteger"
453
454 mi_gdb_test "-var-delete lpinteger" \
455         "\\^done,ndeleted=\"1\"" \
456         "delete var lpinteger"
457
458 mi_gdb_test "-var-delete lcharacter" \
459         "\\^done,ndeleted=\"1\"" \
460         "delete var lcharacter"
461
462 mi_gdb_test "-var-delete lpcharacter" \
463         "\\^done,ndeleted=\"1\"" \
464         "delete var lpcharacter"
465
466 mi_gdb_test "-var-delete llong" \
467         "\\^done,ndeleted=\"1\"" \
468         "delete var llong"
469
470 mi_gdb_test "-var-delete lplong" \
471         "\\^done,ndeleted=\"1\"" \
472         "delete var lplong"
473
474 mi_gdb_test "-var-delete lfloat" \
475         "\\^done,ndeleted=\"1\"" \
476         "delete var lfloat"
477
478 mi_gdb_test "-var-delete lpfloat" \
479         "\\^done,ndeleted=\"1\"" \
480         "delete var lpfloat"
481
482 mi_gdb_test "-var-delete ldouble" \
483         "\\^done,ndeleted=\"1\"" \
484         "delete var ldouble"
485
486 mi_gdb_test "-var-delete lpdouble" \
487         "\\^done,ndeleted=\"1\"" \
488         "delete var lpdouble"
489
490 mi_gdb_test "-var-delete lsimple" \
491         "\\^done,ndeleted=\"1\"" \
492         "delete var lsimple"
493
494 mi_gdb_test "-var-delete lpsimple" \
495         "\\^done,ndeleted=\"1\"" \
496         "delete var lpsimple"
497
498 mi_gdb_test "-var-delete func" \
499         "\\^done,ndeleted=\"1\"" \
500         "delete var func"
501
502 mi_gdb_test "-var-delete lsimple.character" \
503         "\\^done,ndeleted=\"1\"" \
504         "delete var lsimple.character"
505
506 mi_gdb_test "-var-delete  lsimple->integer" \
507         "\\^done,ndeleted=\"1\"" \
508         "delete var  lsimple->integer"
509
510 mi_gdb_test "-var-delete lsimple.integer" \
511         "\\^done,ndeleted=\"1\"" \
512         "delete var lsimple.integer"
513
514 mi_gdb_test "-var-delete i" \
515         "\\^done,ndeleted=\"1\"" \
516         "delete var i"
517
518 mi_gdb_test "-var-delete l" \
519         "\\^done,ndeleted=\"1\"" \
520         "delete var l"
521
522 mi_gdb_exit
523 return 0