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