aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.mi/mi-var-cmd.exp
blob: 1f97200cd6ac012a24f6621f95b3ced78aacd614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
# Copyright 1999-2024 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Test essential Machine interface (MI) operations
#
# Verify that, using the MI, we can create, update, delete variables.
#


load_lib mi-support.exp
set MIFLAGS "-i=mi"

standard_testfile var-cmd.c

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
    untested "failed to compile"
    return -1
}

if {[mi_clean_restart $binfile]} {
    return
}

#####                   #####
#                           #
#  Variable Creation tests  #
#                           #
#####                   #####

# Test:  c_variable-1.1
# Desc:  Create global variable

mi_create_varobj "global_simple" "global_simple" "create global variable"

# PR mi/15863
# Attempt to update the varobj before running the inferior.
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\\\]" \
	"update varobj before running inferior"

# Test: c_variable-1.2
# Desc: Create non-existent variable

mi_gdb_test "112-var-create bogus_unknown_variable * bogus_unknown_variable" \
	"112\\^error,msg=\"-var-create: unable to create variable object\"" \
	"create non-existent variable"

# Test: c_variable-1.3
# Desc: Create out of scope variable

mi_gdb_test "113-var-create argc * argc" \
	"113\\^error,msg=\"-var-create: unable to create variable object\"" \
	"create out of scope variable"

with_test_prefix "first run" {
  mi_runto do_locals_tests
}

set line_dlt_first_real [gdb_get_line_number "linteger = 1234;"]

mi_continue_to_line $line_dlt_first_real "step to real start of do_locals_test"


# Test: c_variable-1.4
# Desc: create local variables

mi_create_varobj_checked linteger linteger int "create local variable linteger"

mi_create_varobj_checked lpinteger lpinteger {int \*} "create local variable lpinteger"

mi_create_varobj_checked lcharacter lcharacter\[0\] char "create local variable lcharacter"

mi_create_varobj_checked lpcharacter lpcharacter {char \*} "create local variable lpcharacter"

mi_create_varobj_checked llong llong "long" "create local variable llong"

mi_create_varobj_checked lplong lplong {long \*} "create local variable lplong"

mi_create_varobj_checked lfloat lfloat float "create local variable lfloat"

mi_create_varobj_checked lpfloat lpfloat {float \*} "create local variable lpfloat"

mi_create_varobj_checked ldouble ldouble double "create local variable ldouble"

mi_create_varobj_checked lpdouble lpdouble {double \*} "create local variable lpdouble"

mi_create_varobj_checked lsimple lsimple "struct _simple_struct" "create local variable lsimple"

mi_create_varobj_checked lpsimple lpsimple {struct _simple_struct \*} "create local variable lpsimple"

mi_create_varobj_checked func func {void \(\*\)\((void|)\)} "create local variable func"

# Test: c_variable-1.5
# Desc: create lsimple.character
mi_create_varobj_checked lsimple.character lsimple.character "char" \
	"create lsimple.character"

# Test: c_variable-1.6
# Desc: create lpsimple->integer
mi_create_varobj_checked lsimple->integer lsimple->integer "int" \
	"create lsimple->integer"

# Test: c_variable-1.7
# Desc: create lsimple.integer
mi_create_varobj_checked lsimple.integer lsimple.integer "int" \
	"create lsimple.integer"


# Test: c_variable-1.9
# Desc: create type name
#    Type names (like int, long, etc..) are all proper expressions to gdb.
#    make sure variable code does not allow users to create variables, though.
mi_gdb_test "-var-create int * int" \
	"&\"Attempt to use a type name as an expression.\\\\n\".*\\^error,msg=\"-var-create: unable to create variable object\"" \
	"create int"


#####             #####
#                     #
# Value changed tests #
#                     #
#####             #####

# Test: c_variable-2.1
# Desc: check whether values changed at do_block_tests
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\\\]" \
	"update all vars"

# Step over "linteger = 1234;"
set line_dlt_linteger [gdb_get_line_number "lpinteger = &linteger;"]
mi_step_to "do_locals_tests" "" "var-cmd.c" $line_dlt_linteger "step at do_locals_test"

# Test: c_variable-2.2
# Desc: check whether only linteger changed values
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: linteger changed"

# Step over "lpinteger = &linteger;"
mi_step_to "do_locals_tests" "" "var-cmd.c" [expr $line_dlt_linteger + 1] "step at do_locals_tests, 2"

# Test: c_variable-2.3
# Desc: check whether only lpinteger changed
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: lpinteger changed"

# Step over "lcharacter = 'a';"
mi_step_to "do_locals_tests" "" "var-cmd.c" [expr $line_dlt_linteger + 2] "step at do_locals_tests, 3"

# Test: c_variable-2.4
# Desc: check whether only lcharacter changed
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: lcharacter changed"

# Step over "lpcharacter = &lcharacter;"
mi_step_to "do_locals_tests" "" "var-cmd.c" [expr $line_dlt_linteger + 3] "step at do_locals_tests, 4"

# Test: c_variable-2.5
# Desc: check whether only lpcharacter changed
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: lpcharacter changed"


# Step over:
#  llong = 2121L;
#  lplong = &llong;
#  lfloat = 2.1;
#  lpfloat = &lfloat;
#  ldouble = 2.718281828459045;
#  lpdouble = &ldouble;
#  lsimple.integer = 1234;
#  lsimple.unsigned_integer = 255;
#  lsimple.character = 'a';

mi_execute_to "exec-step 9" "end-stepping-range" "do_locals_tests" "" \
	"var-cmd.c" [expr $line_dlt_linteger + 12] "" "step at do_locals_tests, 5"

# Test: c_variable-2.6
# Desc: check whether llong, lplong, lfloat, lpfloat, ldouble, lpdouble, lsimple.integer,
#       lsimple.unsigned_character lsimple.integer lsimple.character changed
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"lsimple.integer\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lsimple->integer\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lsimple.character\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lpdouble\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"ldouble\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lpfloat\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lfloat\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lplong\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"llong\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: many changed"

# Step over:
#  lsimple.signed_character = 21;
#  lsimple.char_ptr = &lcharacter;
#  lpsimple = &lsimple;
#  func = nothing;

set line_dlt_4321 [gdb_get_line_number "linteger = 4321;"]

mi_execute_to "exec-step 4" "end-stepping-range" "do_locals_tests" "" \
	"var-cmd.c" $line_dlt_4321 "" "step at do_locals_tests, 6"

# Test: c_variable-2.7
# Desc: check whether (lsimple.signed_character, lsimple.char_ptr) lpsimple, func changed
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"func\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lpsimple\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: func and lpsimple changed"

# Step over
#  linteger = 4321;
#  lcharacter = 'b';
#  llong = 1212L;
#  lfloat = 1.2;
#  ldouble = 5.498548281828172;
#  lsimple.integer = 255;
#  lsimple.unsigned_integer = 4321;
#  lsimple.character = 'b';

mi_execute_to "exec-step 8" "end-stepping-range" "do_locals_tests" "" \
	"var-cmd.c" [expr $line_dlt_4321 + 8] "" "step at do_locals_tests, 7"

# Test: c_variable-2.8
# Desc: check whether linteger, lcharacter, llong, lfoat, ldouble, lsimple.integer,
#       lpsimple.integer lsimple.character changed
# Note: this test also checks that lpsimple->integer and lsimple.integer have
#       changed (they are the same)
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"lsimple.integer\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lsimple->integer\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lsimple.character\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"ldouble\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lfloat\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"llong\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"lcharacter\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: lsimple and others changed"


### 
#
# Test assignment to variables. More tests on assignment are in other files.
#
###
mi_gdb_test "-var-assign global_simple 0" \
	"\\^error,msg=\"-var-assign: Variable object is not editable\"" \
	"assign to global_simple"

mi_gdb_test "-var-assign linteger 3333" \
	"\\^done,value=\"3333\"" \
	"assign to linteger, 1st"

# Allow lpcharacter to update, optionally.  Because it points to a
# char variable instead of a zero-terminated string, if linteger is
# directly after it in memory the printed characters may appear to
# change.
set lpchar_update "\{name=\"lpcharacter\",in_scope=\"true\",type_changed=\"false\"\},"
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[($lpchar_update)?\{name=\"linteger\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: linteger changed after assign"

mi_gdb_test "-var-assign linteger 3333" \
	"\\^done,value=\"3333\"" \
	"assign to linteger again, same value"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\\\]" \
	"update all vars: linteger not changed after same assign"

mi_gdb_test "-var-evaluate-expression linteger" \
	"\\^done,value=\"3333\"" \
	"eval linteger"

mi_gdb_test "-var-assign lpinteger \"&linteger + 3\"" \
	"\\^done,value=\"$hex\"" \
	"assign to lpinteger, 1st"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"lpinteger\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: lpinteger changed after assign"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\\\]" \
	"update all vars: no changes on second update"

mi_gdb_test "-var-evaluate-expression lpinteger" \
	"\\^done,value=\"$hex\"" \
	"eval lpinteger"

# reset the values to the original ones so that the rest of the file doesn't suffer.

mi_gdb_test "-var-assign linteger 4321" \
	"\\^done,value=\"4321\"" \
	"assign to linteger, 2nd"

mi_gdb_test "-var-assign lpinteger &linteger" \
	"\\^done,value=\"$hex\"" \
	"assign to lpinteger, 2nd"

mi_gdb_test "-var-assign lcharacter 'z'" \
	"\\^done,value=\"122 'z'\"" \
	"assign to lcharacter"

mi_gdb_test "-var-evaluate-expression lcharacter" \
	"\\^done,value=\"122 'z'\"" \
	"eval lcharacter"

mi_gdb_test "-var-assign llong 1313L" \
	"\\^done,value=\"1313\"" \
	"assign to llong, 1st"
mi_gdb_test "-var-evaluate-expression llong" \
	"\\^done,value=\"1313\"" \
	"eval llong"
mi_gdb_test "-var-assign llong 1212L" \
	"\\^done,value=\"1212\"" \
	"assign to llong, 2nd"

mi_gdb_test "-var-assign lplong &llong+4" \
	"\\^done,value=\"$hex\"" \
	"assign to lplong, 1st"
mi_gdb_test "-var-evaluate-expression lplong" \
	"\\^done,value=\"$hex\"" \
	"eval lplong"
mi_gdb_test "-var-assign lplong &llong" \
	"\\^done,value=\"$hex\"" \
	"assign to lplong, 2nd"

mi_gdb_test "-var-assign lfloat 3.4567" \
	"\\^done,value=\"3.45.*\"" \
	"assign to lfloat, 1st"
mi_gdb_test "-var-evaluate-expression lfloat" \
	"\\^done,value=\"3.45.*\"" \
	"eval lfloat"
mi_gdb_test "-var-assign lfloat 1.2345" \
	"\\^done,value=\"1.23.*\"" \
	"assign to lfloat, 2nd"

mi_gdb_test "-var-assign lpfloat &lfloat+4" \
	"\\^done,value=\"$hex\"" \
	"assign to lpfloat"

mi_gdb_test "-var-assign ldouble 5.333318284590435" \
	"\\^done,value=\"5.333318284590435\"" \
	"assign to ldouble"

mi_gdb_test "-var-assign func do_block_tests" \
	"\\^done,value=\"$hex <do_block_tests>\"" \
	"assign to func"

mi_gdb_test "-var-assign lsimple.character 'd'" \
	"\\^done,value=\"100 'd'\"" \
	"assign to lsimple.character"

mi_gdb_test "-var-assign  lsimple->integer 222" \
	"\\^done,value=\"222\"" \
	"assign to lsimple->integer"

mi_gdb_test "-var-assign lsimple.integer 333" \
	"\\^done,value=\"333\"" \
	"assign to lsimple.integer"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=.*" \
	"var update"

# Check that assignment of function and array values
# promotes the assigned value to function pointer/data
# pointer before comparing with the existing value, 
# and does not incorrectly make the value as changed.
mi_gdb_test "-var-assign func do_block_tests" \
	"\\^done,value=\"$hex <do_block_tests>\"" \
	"assign same value to func"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\\\]" \
	"assign same value to func, update"

mi_gdb_test "-var-create array_ptr * array_ptr" \
	"\\^done,name=\"array_ptr\",numchild=\"1\",value=\"$hex <array>\",type=\"int \\*\",has_more=\"0\"" \
	"create global variable array_ptr"

mi_gdb_test "-var-assign array_ptr array2" \
	"\\^done,value=\"$hex <array2>\"" \
	"assign array to pointer"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"array_ptr\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"assign array to pointer, update"

mi_gdb_test "-var-assign array_ptr array2" \
	"\\^done,value=\"$hex <array2>\"" \
	"assign same array to pointer"

mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\\\]" \
	"assign same array to pointer, update"


######
# End of assign tests 
#####

set line_subroutine1_body [gdb_get_line_number "global_simple.integer = i + 3;"]

mi_continue_to subroutine1

# Test: c_variable-2.10
# Desc: create variable for locals i,l in subroutine1
mi_create_varobj_checked i i int "create i"

mi_create_varobj_checked l l {long \*} "create l"

# Test: c_variable-2.11
# Desc: create do_locals_tests local in subroutine1
mi_gdb_test "-var-create linteger * linteger" \
	"\\^error,msg=\"-var-create: unable to create variable object\"" \
	"create linteger"

mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
	"var-cmd.c" [expr $line_subroutine1_body + 1] "step at subroutine1"

# Test: c_variable-2.12
# Desc: change global_simple.integer
# Note: This also tests whether we are reporting changes in structs properly.
#       gdb normally would say that global_simple has changed, but we
#       special case that, since it is not what a human expects to
#       see.

setup_xfail *-*-*
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\{FIXME: WHAT IS CORRECT HERE\}" \
	"update all vars: changed FIXME"
clear_xfail *-*-*

mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
	"var-cmd.c" [expr $line_subroutine1_body + 2] "step at subroutine1, 2"

# Test: c_variable-2.13
# Desc: change subroutine1 local i
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"i\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: i changed"

mi_step_to "subroutine1" "\{name=\"i\",value=\".*\"\},\{name=\"l\",value=\".*\"\}" \
	"var-cmd.c" [expr $line_subroutine1_body + 3] "step at subroutine1, 3"

# Test: c_variable-2.14
# Desc: change do_locals_tests local llong
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"llong\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: llong changed"

set line_dlt_call_subroutine1 [gdb_get_line_number "subroutine1 (linteger, &llong);"]
mi_next_to "do_locals_tests" ""	"var-cmd.c" \
  [expr $line_dlt_call_subroutine1 + 1] "next out of subroutine1"

# Test: c_variable-2.15
# Desc: check for out of scope subroutine1 locals
mi_gdb_test "-var-update *" \
	"\\^done,changelist=\\\[\{name=\"l\",in_scope=\"false\"\,type_changed=\"false\",has_more=\"0\"},\{name=\"i\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"\}\\\]" \
	"update all vars: all now out of scope"

# Done with locals/globals tests. Erase all variables
#delete_all_variables
mi_gdb_test "-var-delete global_simple" \
	"\\^done,ndeleted=\"1\"" \
	"delete var"

mi_gdb_test "-var-delete linteger" \
	"\\^done,ndeleted=\"1\"" \
	"delete var linteger"

mi_gdb_test "-var-delete lpinteger" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lpinteger"

mi_gdb_test "-var-delete lcharacter" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lcharacter"

mi_gdb_test "-var-delete lpcharacter" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lpcharacter"

mi_gdb_test "-var-delete llong" \
	"\\^done,ndeleted=\"1\"" \
	"delete var llong"

mi_gdb_test "-var-delete lplong" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lplong"

mi_gdb_test "-var-delete lfloat" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lfloat"

mi_gdb_test "-var-delete lpfloat" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lpfloat"

mi_gdb_test "-var-delete ldouble" \
	"\\^done,ndeleted=\"1\"" \
	"delete var ldouble"

mi_gdb_test "-var-delete lpdouble" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lpdouble"

mi_gdb_test "-var-delete lsimple" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lsimple"

mi_gdb_test "-var-delete lpsimple" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lpsimple"

mi_gdb_test "-var-delete func" \
	"\\^done,ndeleted=\"1\"" \
	"delete var func"

mi_gdb_test "-var-delete lsimple.character" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lsimple.character"

mi_gdb_test "-var-delete  lsimple->integer" \
	"\\^done,ndeleted=\"1\"" \
	"delete var  lsimple->integer"

mi_gdb_test "-var-delete lsimple.integer" \
	"\\^done,ndeleted=\"1\"" \
	"delete var lsimple.integer"

mi_gdb_test "-var-delete i" \
	"\\^done,ndeleted=\"1\"" \
	"delete var i"

mi_gdb_test "-var-delete l" \
	"\\^done,ndeleted=\"1\"" \
	"delete var l"

# Test whether we can follow the name of a variable through multiple
# stack frames.
mi_continue_to do_special_tests

mi_gdb_test "-var-create selected_a @ a" \
  {\^done,name="selected_a",numchild="0",value=\".*\",type="int".*} \
  "create selected_a"

mi_continue_to incr_a

mi_gdb_test "-var-update selected_a" \
	"\\^done,changelist=\\\[\{name=\"selected_a\",in_scope=\"true\",type_changed=\"true\",new_type=\"char\",new_num_children=\"0\",has_more=\"0\"\}\\\]" \
	"update selected_a in incr_a"

mi_next "step a line in incr_a"
mi_next "return from incr_a to do_special_tests"

mi_gdb_test "-var-update selected_a" \
	"\\^done,changelist=\\\[\{name=\"selected_a\",in_scope=\"true\",type_changed=\"true\",new_type=\"int\",new_num_children=\"0\",has_more=\"0\"\}\\\]" \
	"update selected_a in do_special_tests"

if [is_remote host] {
    set filename ${testfile}
} else {
    set filename ${binfile}
}

mi_gdb_test "-file-exec-and-symbols ${filename}" "\\^done" \
    "floating varobj invalidation"

mi_delete_varobj selected_a "delete selected_a"
mi_delete_varobj array_ptr "delete array_ptr"

proc set_frozen {varobjs flag} {
    foreach v $varobjs {
        mi_gdb_test "-var-set-frozen $v $flag" \
            "\\^done" \
            "-var-set-frozen $v $flag"
    }
}

mi_prepare_inline_tests $srcfile

set inline_tests {
    frozen
    bitfield
}

# Needs to be last, following tests rely on this.
lappend inline_tests floating

foreach_with_prefix inline_test $inline_tests {
    if { [mi_run_inline_test $inline_test] < 0 } {
	return -1
    }
}

# Since the inline test framework does not really work with
# function calls, first to inline tests and then do the remainder
# manually.
set do_at_tests_callee_breakpoint [gdb_get_line_number "breakpoint inside callee"]
mi_gdb_test "-break-insert var-cmd.c:$do_at_tests_callee_breakpoint" ".*" \
    "inside breakpoint inside callee"
mi_execute_to "exec-continue" "breakpoint-hit" do_at_tests_callee "" ".*" ".*" \
    { "" "disp=\"keep\"" } \
    "continue to where i is initialized"

mi_varobj_update F {F} "update F inside callee"
mi_check_varobj_value F 7 "check F inside callee"

# Test whether bad varobjs crash GDB.

# A varobj we fail to read during -var-update should be considered
# out of scope.
mi_gdb_test "-var-create null_ptr * **0" \
    {\^done,name="null_ptr",numchild="0",value=".*",type="int",has_more="0"} \
    "create null_ptr"

# Allow this to succeed, if address zero is readable, although it
# will not test what it was meant to.  Most important is that GDB
# does not crash.
mi_gdb_test "-var-update null_ptr" \
    {\^done,changelist=\[.*\]} \
    "update null_ptr"

mi_gdb_test "-var-delete null_ptr" \
    "\\^done,ndeleted=\"1\"" \
    "delete null_ptr"

# When we fail to read a varobj created from a named variable,
# we evaluate its type instead.  Make sure that doesn't blow
# up by trying to read it again.  We can use _end when not running
# the program to simulate an unreadable variable, if this platform
# provides _end, but cope if it's missing.

mi_gdb_test "kill" \
    {&"kill\\n".*\^done} \
    "kill program before endvar"

mi_gdb_test "-var-create endvar * _end" \
    {(\^done,name="endvar",numchild="0",value=".*",type=".*"|\^error,msg=".*")} \
    "create endvar"

# Allow this to succeed whether the value is readable, unreadable, or
# missing.  Most important is that GDB does not crash.
mi_gdb_test "-var-update endvar" \
    {(\^done,changelist=\[.*\]|\^error,msg=".*not found")} \
    "update endvar"

mi_gdb_test "-var-delete endvar" \
    {(\^done,ndeleted="1"|\^error,msg=".*not found")} \
    "delete endvar"

mi_delete_breakpoints

with_test_prefix "second run" {
  mi_runto do_locals_tests
}

mi_create_varobj "L" "lsimple" "in-and-out-of-scope: create varobj"
mi_check_varobj_value "L" "{...}" "in-and-out-of-scope: check initial value"

mi_runto_main

mi_gdb_test "-var-update L" \
    {\^done,changelist=\[{name="L",in_scope="false",type_changed="false",has_more="0"}\]} \
    "in-and-out-of-scope: out of scope now"

mi_gdb_test "-var-update L" \
    {\^done,changelist=\[]} \
    "in-and-out-of-scope: out of scope now, not changed"

mi_continue_to do_locals_tests

mi_gdb_test "-var-update L" \
    {\^done,changelist=\[{name="L",in_scope="true",type_changed="false",has_more="0"}\]} \
    "in-and-out-of-scope: in scope now"

mi_gdb_test "-var-update L" \
    {\^done,changelist=\[\]} \
    "in-and-out-of-scope: in scope now, not changed"

mi_gdb_exit