gdb - Local mods (compile)
[dragonfly.git] / contrib / gdb-7 / gdb / mi / mi-cmd-var.c
CommitLineData
5796c8dc 1/* MI Command Set - varobj commands.
25e4902b 2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
5796c8dc
SS
3
4 Contributed by Cygnus Solutions (a Red Hat company).
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21#include "defs.h"
22#include "mi-cmds.h"
ef5ccd6c 23#include "mi-main.h"
5796c8dc
SS
24#include "ui-out.h"
25#include "mi-out.h"
26#include "varobj.h"
25e4902b 27#include "language.h"
5796c8dc
SS
28#include "value.h"
29#include <ctype.h>
5796c8dc
SS
30#include "mi-getopt.h"
31#include "gdbthread.h"
25e4902b 32#include "mi-parse.h"
5796c8dc 33
ef5ccd6c 34extern unsigned int varobjdebug; /* defined in varobj.c. */
5796c8dc
SS
35
36static void varobj_update_one (struct varobj *var,
ef5ccd6c 37 enum print_values print_values,
25e4902b 38 int is_explicit);
5796c8dc 39
c50c785c
JM
40static int mi_print_value_p (struct varobj *var,
41 enum print_values print_values);
5796c8dc
SS
42
43/* Print variable object VAR. The PRINT_VALUES parameter controls
44 if the value should be printed. The PRINT_EXPRESSION parameter
45 controls if the expression should be printed. */
ef5ccd6c 46
5796c8dc
SS
47static void
48print_varobj (struct varobj *var, enum print_values print_values,
49 int print_expression)
50{
a45ae5f8 51 struct ui_out *uiout = current_uiout;
5796c8dc
SS
52 char *type;
53 int thread_id;
54 char *display_hint;
55
56 ui_out_field_string (uiout, "name", varobj_get_objname (var));
57 if (print_expression)
25e4902b
AHJ
58 {
59 char *exp = varobj_get_expression (var);
60
61 ui_out_field_string (uiout, "exp", exp);
62 xfree (exp);
63 }
5796c8dc
SS
64 ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
65
66 if (mi_print_value_p (var, print_values))
67 {
68 char *val = varobj_get_value (var);
cf7f2e2d 69
5796c8dc
SS
70 ui_out_field_string (uiout, "value", val);
71 xfree (val);
72 }
73
74 type = varobj_get_type (var);
75 if (type != NULL)
76 {
77 ui_out_field_string (uiout, "type", type);
78 xfree (type);
79 }
80
81 thread_id = varobj_get_thread_id (var);
82 if (thread_id > 0)
83 ui_out_field_int (uiout, "thread-id", thread_id);
84
85 if (varobj_get_frozen (var))
86 ui_out_field_int (uiout, "frozen", 1);
87
88 display_hint = varobj_get_display_hint (var);
89 if (display_hint)
90 {
91 ui_out_field_string (uiout, "displayhint", display_hint);
92 xfree (display_hint);
93 }
94
25e4902b 95 if (varobj_is_dynamic_p (var))
5796c8dc
SS
96 ui_out_field_int (uiout, "dynamic", 1);
97}
98
99/* VAROBJ operations */
100
101void
102mi_cmd_var_create (char *command, char **argv, int argc)
103{
a45ae5f8 104 struct ui_out *uiout = current_uiout;
5796c8dc
SS
105 CORE_ADDR frameaddr = 0;
106 struct varobj *var;
107 char *name;
108 char *frame;
109 char *expr;
110 struct cleanup *old_cleanups;
111 enum varobj_type var_type;
112
113 if (argc != 3)
ef5ccd6c 114 error (_("-var-create: Usage: NAME FRAME EXPRESSION."));
5796c8dc
SS
115
116 name = xstrdup (argv[0]);
ef5ccd6c
JM
117 /* Add cleanup for name. Must be free_current_contents as name can
118 be reallocated. */
5796c8dc
SS
119 old_cleanups = make_cleanup (free_current_contents, &name);
120
121 frame = xstrdup (argv[1]);
122 make_cleanup (xfree, frame);
123
124 expr = xstrdup (argv[2]);
125 make_cleanup (xfree, expr);
126
127 if (strcmp (name, "-") == 0)
128 {
129 xfree (name);
130 name = varobj_gen_name ();
131 }
132 else if (!isalpha (*name))
c50c785c 133 error (_("-var-create: name of object must begin with a letter"));
5796c8dc
SS
134
135 if (strcmp (frame, "*") == 0)
136 var_type = USE_CURRENT_FRAME;
137 else if (strcmp (frame, "@") == 0)
138 var_type = USE_SELECTED_FRAME;
139 else
140 {
141 var_type = USE_SPECIFIED_FRAME;
142 frameaddr = string_to_core_addr (frame);
143 }
144
145 if (varobjdebug)
146 fprintf_unfiltered (gdb_stdlog,
147 "Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
148 name, frame, hex_string (frameaddr), expr);
149
150 var = varobj_create (name, expr, frameaddr, var_type);
151
152 if (var == NULL)
c50c785c 153 error (_("-var-create: unable to create variable object"));
5796c8dc
SS
154
155 print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */);
156
157 ui_out_field_int (uiout, "has_more", varobj_has_more (var, 0));
158
159 do_cleanups (old_cleanups);
160}
161
162void
163mi_cmd_var_delete (char *command, char **argv, int argc)
164{
165 char *name;
166 struct varobj *var;
167 int numdel;
168 int children_only_p = 0;
169 struct cleanup *old_cleanups;
a45ae5f8 170 struct ui_out *uiout = current_uiout;
5796c8dc
SS
171
172 if (argc < 1 || argc > 2)
c50c785c 173 error (_("-var-delete: Usage: [-c] EXPRESSION."));
5796c8dc
SS
174
175 name = xstrdup (argv[0]);
ef5ccd6c
JM
176 /* Add cleanup for name. Must be free_current_contents as name can
177 be reallocated. */
5796c8dc
SS
178 old_cleanups = make_cleanup (free_current_contents, &name);
179
180 /* If we have one single argument it cannot be '-c' or any string
ef5ccd6c 181 starting with '-'. */
5796c8dc
SS
182 if (argc == 1)
183 {
184 if (strcmp (name, "-c") == 0)
c50c785c
JM
185 error (_("-var-delete: Missing required "
186 "argument after '-c': variable object name"));
5796c8dc 187 if (*name == '-')
c50c785c 188 error (_("-var-delete: Illegal variable object name"));
5796c8dc
SS
189 }
190
191 /* If we have 2 arguments they must be '-c' followed by a string
ef5ccd6c 192 which would be the variable name. */
5796c8dc
SS
193 if (argc == 2)
194 {
195 if (strcmp (name, "-c") != 0)
c50c785c 196 error (_("-var-delete: Invalid option."));
5796c8dc
SS
197 children_only_p = 1;
198 do_cleanups (old_cleanups);
199 name = xstrdup (argv[1]);
a45ae5f8 200 old_cleanups = make_cleanup (free_current_contents, &name);
5796c8dc
SS
201 }
202
203 /* If we didn't error out, now NAME contains the name of the
ef5ccd6c 204 variable. */
5796c8dc
SS
205
206 var = varobj_get_handle (name);
207
208 numdel = varobj_delete (var, NULL, children_only_p);
209
210 ui_out_field_int (uiout, "ndeleted", numdel);
211
212 do_cleanups (old_cleanups);
213}
214
215/* Parse a string argument into a format value. */
216
217static enum varobj_display_formats
218mi_parse_format (const char *arg)
219{
220 if (arg != NULL)
221 {
222 int len;
223
224 len = strlen (arg);
225
226 if (strncmp (arg, "natural", len) == 0)
227 return FORMAT_NATURAL;
228 else if (strncmp (arg, "binary", len) == 0)
229 return FORMAT_BINARY;
230 else if (strncmp (arg, "decimal", len) == 0)
231 return FORMAT_DECIMAL;
232 else if (strncmp (arg, "hexadecimal", len) == 0)
233 return FORMAT_HEXADECIMAL;
234 else if (strncmp (arg, "octal", len) == 0)
235 return FORMAT_OCTAL;
236 }
237
c50c785c
JM
238 error (_("Must specify the format as: \"natural\", "
239 "\"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
5796c8dc
SS
240}
241
242void
243mi_cmd_var_set_format (char *command, char **argv, int argc)
244{
245 enum varobj_display_formats format;
246 struct varobj *var;
247 char *val;
a45ae5f8 248 struct ui_out *uiout = current_uiout;
5796c8dc
SS
249
250 if (argc != 2)
c50c785c 251 error (_("-var-set-format: Usage: NAME FORMAT."));
5796c8dc 252
ef5ccd6c 253 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
254 var = varobj_get_handle (argv[0]);
255
256 format = mi_parse_format (argv[1]);
257
ef5ccd6c 258 /* Set the format of VAR to the given format. */
5796c8dc
SS
259 varobj_set_display_format (var, format);
260
ef5ccd6c 261 /* Report the new current format. */
5796c8dc
SS
262 ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
263
ef5ccd6c 264 /* Report the value in the new format. */
5796c8dc
SS
265 val = varobj_get_value (var);
266 ui_out_field_string (uiout, "value", val);
267 xfree (val);
268}
269
270void
271mi_cmd_var_set_visualizer (char *command, char **argv, int argc)
272{
273 struct varobj *var;
274
275 if (argc != 2)
c50c785c 276 error (_("Usage: NAME VISUALIZER_FUNCTION."));
5796c8dc
SS
277
278 var = varobj_get_handle (argv[0]);
279
280 if (var == NULL)
c50c785c 281 error (_("Variable object not found"));
5796c8dc
SS
282
283 varobj_set_visualizer (var, argv[1]);
284}
285
286void
287mi_cmd_var_set_frozen (char *command, char **argv, int argc)
288{
289 struct varobj *var;
290 int frozen;
291
292 if (argc != 2)
293 error (_("-var-set-format: Usage: NAME FROZEN_FLAG."));
294
295 var = varobj_get_handle (argv[0]);
296
297 if (strcmp (argv[1], "0") == 0)
298 frozen = 0;
299 else if (strcmp (argv[1], "1") == 0)
300 frozen = 1;
301 else
302 error (_("Invalid flag value"));
303
304 varobj_set_frozen (var, frozen);
305
ef5ccd6c
JM
306 /* We don't automatically return the new value, or what varobjs got
307 new values during unfreezing. If this information is required,
308 client should call -var-update explicitly. */
5796c8dc
SS
309}
310
5796c8dc
SS
311void
312mi_cmd_var_show_format (char *command, char **argv, int argc)
313{
a45ae5f8 314 struct ui_out *uiout = current_uiout;
5796c8dc
SS
315 enum varobj_display_formats format;
316 struct varobj *var;
317
318 if (argc != 1)
c50c785c 319 error (_("-var-show-format: Usage: NAME."));
5796c8dc 320
ef5ccd6c 321 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
322 var = varobj_get_handle (argv[0]);
323
324 format = varobj_get_display_format (var);
325
ef5ccd6c 326 /* Report the current format. */
5796c8dc
SS
327 ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
328}
329
330void
331mi_cmd_var_info_num_children (char *command, char **argv, int argc)
332{
a45ae5f8 333 struct ui_out *uiout = current_uiout;
5796c8dc
SS
334 struct varobj *var;
335
336 if (argc != 1)
c50c785c 337 error (_("-var-info-num-children: Usage: NAME."));
5796c8dc 338
ef5ccd6c 339 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
340 var = varobj_get_handle (argv[0]);
341
342 ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
343}
344
5796c8dc
SS
345/* Return 1 if given the argument PRINT_VALUES we should display
346 the varobj VAR. */
347
348static int
349mi_print_value_p (struct varobj *var, enum print_values print_values)
350{
351 struct type *type;
352
353 if (print_values == PRINT_NO_VALUES)
354 return 0;
355
356 if (print_values == PRINT_ALL_VALUES)
357 return 1;
358
25e4902b 359 if (varobj_is_dynamic_p (var))
5796c8dc
SS
360 return 1;
361
362 type = varobj_get_gdb_type (var);
363 if (type == NULL)
364 return 1;
365 else
366 {
367 type = check_typedef (type);
368
369 /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
370 and that type is not a compound type. */
371 return (TYPE_CODE (type) != TYPE_CODE_ARRAY
372 && TYPE_CODE (type) != TYPE_CODE_STRUCT
373 && TYPE_CODE (type) != TYPE_CODE_UNION);
374 }
375}
376
377void
378mi_cmd_var_list_children (char *command, char **argv, int argc)
379{
a45ae5f8 380 struct ui_out *uiout = current_uiout;
5796c8dc
SS
381 struct varobj *var;
382 VEC(varobj_p) *children;
383 struct varobj *child;
5796c8dc
SS
384 enum print_values print_values;
385 int ix;
386 int from, to;
387 char *display_hint;
388
389 if (argc < 1 || argc > 4)
c50c785c
JM
390 error (_("-var-list-children: Usage: "
391 "[PRINT_VALUES] NAME [FROM TO]"));
5796c8dc 392
ef5ccd6c 393 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
394 if (argc == 1 || argc == 3)
395 var = varobj_get_handle (argv[0]);
396 else
397 var = varobj_get_handle (argv[1]);
398
399 if (argc > 2)
400 {
401 from = atoi (argv[argc - 2]);
402 to = atoi (argv[argc - 1]);
403 }
404 else
405 {
406 from = -1;
407 to = -1;
408 }
409
410 children = varobj_list_children (var, &from, &to);
411 ui_out_field_int (uiout, "numchild", to - from);
412 if (argc == 2 || argc == 4)
25e4902b 413 print_values = mi_parse_print_values (argv[0]);
5796c8dc
SS
414 else
415 print_values = PRINT_NO_VALUES;
416
417 display_hint = varobj_get_display_hint (var);
418 if (display_hint)
419 {
420 ui_out_field_string (uiout, "displayhint", display_hint);
421 xfree (display_hint);
422 }
423
424 if (from < to)
425 {
426 struct cleanup *cleanup_children;
cf7f2e2d 427
5796c8dc
SS
428 if (mi_version (uiout) == 1)
429 cleanup_children
430 = make_cleanup_ui_out_tuple_begin_end (uiout, "children");
431 else
432 cleanup_children
433 = make_cleanup_ui_out_list_begin_end (uiout, "children");
434 for (ix = from;
435 ix < to && VEC_iterate (varobj_p, children, ix, child);
436 ++ix)
437 {
438 struct cleanup *cleanup_child;
cf7f2e2d 439
5796c8dc
SS
440 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
441 print_varobj (child, print_values, 1 /* print expression */);
442 do_cleanups (cleanup_child);
443 }
444 do_cleanups (cleanup_children);
445 }
446
447 ui_out_field_int (uiout, "has_more", varobj_has_more (var, to));
448}
449
450void
451mi_cmd_var_info_type (char *command, char **argv, int argc)
452{
a45ae5f8 453 struct ui_out *uiout = current_uiout;
5796c8dc 454 struct varobj *var;
25e4902b 455 char *type_name;
5796c8dc
SS
456
457 if (argc != 1)
c50c785c 458 error (_("-var-info-type: Usage: NAME."));
5796c8dc 459
ef5ccd6c 460 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc 461 var = varobj_get_handle (argv[0]);
25e4902b
AHJ
462 type_name = varobj_get_type (var);
463
464 ui_out_field_string (uiout, "type", type_name);
5796c8dc 465
25e4902b 466 xfree (type_name);
5796c8dc
SS
467}
468
469void
470mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
471{
a45ae5f8 472 struct ui_out *uiout = current_uiout;
5796c8dc
SS
473 struct varobj *var;
474 char *path_expr;
475
476 if (argc != 1)
477 error (_("Usage: NAME."));
478
479 /* Get varobj handle, if a valid var obj name was specified. */
480 var = varobj_get_handle (argv[0]);
481
482 path_expr = varobj_get_path_expr (var);
483
484 ui_out_field_string (uiout, "path_expr", path_expr);
485}
486
487void
488mi_cmd_var_info_expression (char *command, char **argv, int argc)
489{
a45ae5f8 490 struct ui_out *uiout = current_uiout;
25e4902b 491 const struct language_defn *lang;
5796c8dc 492 struct varobj *var;
25e4902b 493 char *exp;
5796c8dc
SS
494
495 if (argc != 1)
c50c785c 496 error (_("-var-info-expression: Usage: NAME."));
5796c8dc 497
ef5ccd6c 498 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
499 var = varobj_get_handle (argv[0]);
500
501 lang = varobj_get_language (var);
502
25e4902b
AHJ
503 ui_out_field_string (uiout, "lang", lang->la_natural_name);
504
505 exp = varobj_get_expression (var);
506 ui_out_field_string (uiout, "exp", exp);
507 xfree (exp);
5796c8dc
SS
508}
509
510void
511mi_cmd_var_show_attributes (char *command, char **argv, int argc)
512{
a45ae5f8 513 struct ui_out *uiout = current_uiout;
5796c8dc
SS
514 int attr;
515 char *attstr;
516 struct varobj *var;
517
518 if (argc != 1)
c50c785c 519 error (_("-var-show-attributes: Usage: NAME."));
5796c8dc
SS
520
521 /* Get varobj handle, if a valid var obj name was specified */
522 var = varobj_get_handle (argv[0]);
523
524 attr = varobj_get_attributes (var);
525 /* FIXME: define masks for attributes */
526 if (attr & 0x00000001)
527 attstr = "editable";
528 else
529 attstr = "noneditable";
530
531 ui_out_field_string (uiout, "attr", attstr);
532}
533
534void
535mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
536{
a45ae5f8 537 struct ui_out *uiout = current_uiout;
5796c8dc
SS
538 struct varobj *var;
539
540 enum varobj_display_formats format;
541 int formatFound;
ef5ccd6c
JM
542 int oind;
543 char *oarg;
5796c8dc
SS
544
545 enum opt
5796c8dc 546 {
ef5ccd6c 547 OP_FORMAT
5796c8dc 548 };
ef5ccd6c
JM
549 static const struct mi_opt opts[] =
550 {
551 {"f", OP_FORMAT, 1},
552 { 0, 0, 0 }
553 };
5796c8dc 554
ef5ccd6c 555 /* Parse arguments. */
5796c8dc
SS
556 format = FORMAT_NATURAL;
557 formatFound = 0;
ef5ccd6c 558 oind = 0;
5796c8dc
SS
559 while (1)
560 {
cf7f2e2d 561 int opt = mi_getopt ("-var-evaluate-expression", argc, argv,
ef5ccd6c 562 opts, &oind, &oarg);
cf7f2e2d 563
5796c8dc
SS
564 if (opt < 0)
565 break;
566 switch ((enum opt) opt)
ef5ccd6c 567 {
5796c8dc
SS
568 case OP_FORMAT:
569 if (formatFound)
570 error (_("Cannot specify format more than once"));
571
ef5ccd6c 572 format = mi_parse_format (oarg);
5796c8dc
SS
573 formatFound = 1;
574 break;
ef5ccd6c 575 }
5796c8dc
SS
576 }
577
ef5ccd6c 578 if (oind >= argc)
5796c8dc
SS
579 error (_("Usage: [-f FORMAT] NAME"));
580
ef5ccd6c 581 if (oind < argc - 1)
5796c8dc
SS
582 error (_("Garbage at end of command"));
583
ef5ccd6c
JM
584 /* Get varobj handle, if a valid var obj name was specified. */
585 var = varobj_get_handle (argv[oind]);
5796c8dc
SS
586
587 if (formatFound)
588 {
589 char *val = varobj_get_formatted_value (var, format);
cf7f2e2d 590
5796c8dc
SS
591 ui_out_field_string (uiout, "value", val);
592 xfree (val);
593 }
594 else
595 {
596 char *val = varobj_get_value (var);
cf7f2e2d 597
5796c8dc
SS
598 ui_out_field_string (uiout, "value", val);
599 xfree (val);
600 }
601}
602
603void
604mi_cmd_var_assign (char *command, char **argv, int argc)
605{
a45ae5f8 606 struct ui_out *uiout = current_uiout;
5796c8dc
SS
607 struct varobj *var;
608 char *expression, *val;
ef5ccd6c 609 struct cleanup *cleanup;
5796c8dc
SS
610
611 if (argc != 2)
c50c785c 612 error (_("-var-assign: Usage: NAME EXPRESSION."));
5796c8dc 613
ef5ccd6c 614 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
615 var = varobj_get_handle (argv[0]);
616
617 if (!varobj_editable_p (var))
c50c785c 618 error (_("-var-assign: Variable object is not editable"));
5796c8dc
SS
619
620 expression = xstrdup (argv[1]);
621
ef5ccd6c
JM
622 /* MI command '-var-assign' may write memory, so suppress memory
623 changed notification if it does. */
624 cleanup
625 = make_cleanup_restore_integer (&mi_suppress_notification.memory);
626 mi_suppress_notification.memory = 1;
627
5796c8dc 628 if (!varobj_set_value (var, expression))
c50c785c
JM
629 error (_("-var-assign: Could not assign "
630 "expression to variable object"));
5796c8dc
SS
631
632 val = varobj_get_value (var);
633 ui_out_field_string (uiout, "value", val);
634 xfree (val);
ef5ccd6c
JM
635
636 do_cleanups (cleanup);
5796c8dc
SS
637}
638
639/* Type used for parameters passing to mi_cmd_var_update_iter. */
640
641struct mi_cmd_var_update
642 {
643 int only_floating;
644 enum print_values print_values;
645 };
646
647/* Helper for mi_cmd_var_update - update each VAR. */
648
649static void
650mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
651{
652 struct mi_cmd_var_update *data = data_pointer;
653 int thread_id, thread_stopped;
654
655 thread_id = varobj_get_thread_id (var);
656
25e4902b
AHJ
657 if (thread_id == -1
658 && (ptid_equal (inferior_ptid, null_ptid)
659 || is_stopped (inferior_ptid)))
5796c8dc
SS
660 thread_stopped = 1;
661 else
662 {
663 struct thread_info *tp = find_thread_id (thread_id);
664
665 if (tp)
666 thread_stopped = is_stopped (tp->ptid);
667 else
668 thread_stopped = 1;
669 }
670
ef5ccd6c
JM
671 if (thread_stopped
672 && (!data->only_floating || varobj_floating_p (var)))
673 varobj_update_one (var, data->print_values, 0 /* implicit */);
5796c8dc
SS
674}
675
676void
677mi_cmd_var_update (char *command, char **argv, int argc)
678{
a45ae5f8 679 struct ui_out *uiout = current_uiout;
5796c8dc
SS
680 struct cleanup *cleanup;
681 char *name;
682 enum print_values print_values;
683
684 if (argc != 1 && argc != 2)
c50c785c 685 error (_("-var-update: Usage: [PRINT_VALUES] NAME."));
5796c8dc
SS
686
687 if (argc == 1)
688 name = argv[0];
689 else
ef5ccd6c 690 name = argv[1];
5796c8dc
SS
691
692 if (argc == 2)
25e4902b 693 print_values = mi_parse_print_values (argv[0]);
5796c8dc
SS
694 else
695 print_values = PRINT_NO_VALUES;
696
697 if (mi_version (uiout) <= 1)
698 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
699 else
700 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");
701
ef5ccd6c
JM
702 /* Check if the parameter is a "*", which means that we want to
703 update all variables. */
5796c8dc
SS
704
705 if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
706 {
707 struct mi_cmd_var_update data;
708
ef5ccd6c 709 data.only_floating = (*name == '@');
5796c8dc
SS
710 data.print_values = print_values;
711
ef5ccd6c
JM
712 /* varobj_update_one automatically updates all the children of
713 VAROBJ. Therefore update each VAROBJ only once by iterating
714 only the root VAROBJs. */
5796c8dc
SS
715
716 all_root_varobjs (mi_cmd_var_update_iter, &data);
717 }
718 else
719 {
ef5ccd6c 720 /* Get varobj handle, if a valid var obj name was specified. */
5796c8dc
SS
721 struct varobj *var = varobj_get_handle (name);
722
723 varobj_update_one (var, print_values, 1 /* explicit */);
724 }
725
726 do_cleanups (cleanup);
727}
728
729/* Helper for mi_cmd_var_update(). */
730
731static void
732varobj_update_one (struct varobj *var, enum print_values print_values,
25e4902b 733 int is_explicit)
5796c8dc 734{
a45ae5f8 735 struct ui_out *uiout = current_uiout;
5796c8dc
SS
736 VEC (varobj_update_result) *changes;
737 varobj_update_result *r;
738 int i;
739
25e4902b 740 changes = varobj_update (&var, is_explicit);
5796c8dc
SS
741
742 for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
743 {
744 char *display_hint;
745 int from, to;
25e4902b 746 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
5796c8dc
SS
747
748 if (mi_version (uiout) > 1)
25e4902b 749 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5796c8dc
SS
750 ui_out_field_string (uiout, "name", varobj_get_objname (r->varobj));
751
752 switch (r->status)
753 {
754 case VAROBJ_IN_SCOPE:
755 if (mi_print_value_p (r->varobj, print_values))
756 {
757 char *val = varobj_get_value (r->varobj);
cf7f2e2d 758
5796c8dc
SS
759 ui_out_field_string (uiout, "value", val);
760 xfree (val);
761 }
762 ui_out_field_string (uiout, "in_scope", "true");
763 break;
764 case VAROBJ_NOT_IN_SCOPE:
765 ui_out_field_string (uiout, "in_scope", "false");
766 break;
767 case VAROBJ_INVALID:
768 ui_out_field_string (uiout, "in_scope", "invalid");
769 break;
770 }
771
772 if (r->status != VAROBJ_INVALID)
773 {
774 if (r->type_changed)
775 ui_out_field_string (uiout, "type_changed", "true");
776 else
777 ui_out_field_string (uiout, "type_changed", "false");
778 }
779
780 if (r->type_changed)
25e4902b
AHJ
781 {
782 char *type_name = varobj_get_type (r->varobj);
783
784 ui_out_field_string (uiout, "new_type", type_name);
785 xfree (type_name);
786 }
5796c8dc
SS
787
788 if (r->type_changed || r->children_changed)
789 ui_out_field_int (uiout, "new_num_children",
790 varobj_get_num_children (r->varobj));
791
ef5ccd6c 792 display_hint = varobj_get_display_hint (r->varobj);
5796c8dc
SS
793 if (display_hint)
794 {
795 ui_out_field_string (uiout, "displayhint", display_hint);
796 xfree (display_hint);
797 }
798
25e4902b 799 if (varobj_is_dynamic_p (r->varobj))
5796c8dc
SS
800 ui_out_field_int (uiout, "dynamic", 1);
801
802 varobj_get_child_range (r->varobj, &from, &to);
803 ui_out_field_int (uiout, "has_more",
804 varobj_has_more (r->varobj, to));
805
25e4902b 806 if (r->newobj)
5796c8dc
SS
807 {
808 int j;
809 varobj_p child;
810 struct cleanup *cleanup;
811
812 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children");
25e4902b 813 for (j = 0; VEC_iterate (varobj_p, r->newobj, j, child); ++j)
5796c8dc
SS
814 {
815 struct cleanup *cleanup_child;
cf7f2e2d 816
c50c785c
JM
817 cleanup_child
818 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5796c8dc
SS
819 print_varobj (child, print_values, 1 /* print_expression */);
820 do_cleanups (cleanup_child);
821 }
822
823 do_cleanups (cleanup);
25e4902b
AHJ
824 VEC_free (varobj_p, r->newobj);
825 r->newobj = NULL; /* Paranoia. */
5796c8dc
SS
826 }
827
25e4902b 828 do_cleanups (cleanup);
5796c8dc
SS
829 }
830 VEC_free (varobj_update_result, changes);
831}
832
833void
834mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
835{
836 if (argc != 0)
c50c785c 837 error (_("-enable-pretty-printing: no arguments allowed"));
ef5ccd6c 838
5796c8dc
SS
839 varobj_enable_pretty_printing ();
840}
841
842void
843mi_cmd_var_set_update_range (char *command, char **argv, int argc)
844{
845 struct varobj *var;
846 int from, to;
847
848 if (argc != 3)
c50c785c 849 error (_("-var-set-update-range: Usage: VAROBJ FROM TO"));
5796c8dc
SS
850
851 var = varobj_get_handle (argv[0]);
852 from = atoi (argv[1]);
853 to = atoi (argv[2]);
854
855 varobj_set_child_range (var, from, to);
856}