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