xref: /dragonfly/contrib/gdb-7/gdb/mi/mi-cmd-var.c (revision a4da4a90)
1 /* MI Command Set - varobj commands.
2    Copyright (C) 2000-2013 Free Software Foundation, Inc.
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"
23 #include "mi-main.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 unsigned 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   struct cleanup *cleanup;
620 
621   if (argc != 2)
622     error (_("-var-assign: Usage: NAME EXPRESSION."));
623 
624   /* Get varobj handle, if a valid var obj name was specified.  */
625   var = varobj_get_handle (argv[0]);
626 
627   if (!varobj_editable_p (var))
628     error (_("-var-assign: Variable object is not editable"));
629 
630   expression = xstrdup (argv[1]);
631 
632   /* MI command '-var-assign' may write memory, so suppress memory
633      changed notification if it does.  */
634   cleanup
635     = make_cleanup_restore_integer (&mi_suppress_notification.memory);
636   mi_suppress_notification.memory = 1;
637 
638   if (!varobj_set_value (var, expression))
639     error (_("-var-assign: Could not assign "
640 	     "expression to variable object"));
641 
642   val = varobj_get_value (var);
643   ui_out_field_string (uiout, "value", val);
644   xfree (val);
645 
646   do_cleanups (cleanup);
647 }
648 
649 /* Type used for parameters passing to mi_cmd_var_update_iter.  */
650 
651 struct mi_cmd_var_update
652   {
653     int only_floating;
654     enum print_values print_values;
655   };
656 
657 /* Helper for mi_cmd_var_update - update each VAR.  */
658 
659 static void
660 mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
661 {
662   struct mi_cmd_var_update *data = data_pointer;
663   int thread_id, thread_stopped;
664 
665   thread_id = varobj_get_thread_id (var);
666 
667   if (thread_id == -1 && is_stopped (inferior_ptid))
668     thread_stopped = 1;
669   else
670     {
671       struct thread_info *tp = find_thread_id (thread_id);
672 
673       if (tp)
674 	thread_stopped = is_stopped (tp->ptid);
675       else
676 	thread_stopped = 1;
677     }
678 
679   if (thread_stopped
680       && (!data->only_floating || varobj_floating_p (var)))
681     varobj_update_one (var, data->print_values, 0 /* implicit */);
682 }
683 
684 void
685 mi_cmd_var_update (char *command, char **argv, int argc)
686 {
687   struct ui_out *uiout = current_uiout;
688   struct cleanup *cleanup;
689   char *name;
690   enum print_values print_values;
691 
692   if (argc != 1 && argc != 2)
693     error (_("-var-update: Usage: [PRINT_VALUES] NAME."));
694 
695   if (argc == 1)
696     name = argv[0];
697   else
698     name = argv[1];
699 
700   if (argc == 2)
701     print_values = mi_parse_values_option (argv[0]);
702   else
703     print_values = PRINT_NO_VALUES;
704 
705   if (mi_version (uiout) <= 1)
706     cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
707   else
708     cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");
709 
710   /* Check if the parameter is a "*", which means that we want to
711      update all variables.  */
712 
713   if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
714     {
715       struct mi_cmd_var_update data;
716 
717       data.only_floating = (*name == '@');
718       data.print_values = print_values;
719 
720       /* varobj_update_one automatically updates all the children of
721 	 VAROBJ.  Therefore update each VAROBJ only once by iterating
722 	 only the root VAROBJs.  */
723 
724       all_root_varobjs (mi_cmd_var_update_iter, &data);
725     }
726   else
727     {
728       /* Get varobj handle, if a valid var obj name was specified.  */
729       struct varobj *var = varobj_get_handle (name);
730 
731       varobj_update_one (var, print_values, 1 /* explicit */);
732     }
733 
734   do_cleanups (cleanup);
735 }
736 
737 /* Helper for mi_cmd_var_update().  */
738 
739 static void
740 varobj_update_one (struct varobj *var, enum print_values print_values,
741 		   int explicit)
742 {
743   struct ui_out *uiout = current_uiout;
744   struct cleanup *cleanup = NULL;
745   VEC (varobj_update_result) *changes;
746   varobj_update_result *r;
747   int i;
748 
749   changes = varobj_update (&var, explicit);
750 
751   for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
752     {
753       char *display_hint;
754       int from, to;
755 
756       if (mi_version (uiout) > 1)
757         cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
758       ui_out_field_string (uiout, "name", varobj_get_objname (r->varobj));
759 
760       switch (r->status)
761 	{
762 	case VAROBJ_IN_SCOPE:
763 	  if (mi_print_value_p (r->varobj, print_values))
764 	    {
765 	      char *val = varobj_get_value (r->varobj);
766 
767 	      ui_out_field_string (uiout, "value", val);
768 	      xfree (val);
769 	    }
770 	  ui_out_field_string (uiout, "in_scope", "true");
771 	  break;
772         case VAROBJ_NOT_IN_SCOPE:
773           ui_out_field_string (uiout, "in_scope", "false");
774 	  break;
775         case VAROBJ_INVALID:
776           ui_out_field_string (uiout, "in_scope", "invalid");
777  	  break;
778 	}
779 
780       if (r->status != VAROBJ_INVALID)
781 	{
782 	  if (r->type_changed)
783 	    ui_out_field_string (uiout, "type_changed", "true");
784 	  else
785 	    ui_out_field_string (uiout, "type_changed", "false");
786 	}
787 
788       if (r->type_changed)
789 	ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj));
790 
791       if (r->type_changed || r->children_changed)
792 	ui_out_field_int (uiout, "new_num_children",
793 			  varobj_get_num_children (r->varobj));
794 
795       display_hint = varobj_get_display_hint (r->varobj);
796       if (display_hint)
797 	{
798 	  ui_out_field_string (uiout, "displayhint", display_hint);
799 	  xfree (display_hint);
800 	}
801 
802       if (varobj_pretty_printed_p (r->varobj))
803 	ui_out_field_int (uiout, "dynamic", 1);
804 
805       varobj_get_child_range (r->varobj, &from, &to);
806       ui_out_field_int (uiout, "has_more",
807 			varobj_has_more (r->varobj, to));
808 
809       if (r->new)
810 	{
811 	  int j;
812 	  varobj_p child;
813 	  struct cleanup *cleanup;
814 
815 	  cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children");
816 	  for (j = 0; VEC_iterate (varobj_p, r->new, j, child); ++j)
817 	    {
818 	      struct cleanup *cleanup_child;
819 
820 	      cleanup_child
821 		= make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
822 	      print_varobj (child, print_values, 1 /* print_expression */);
823 	      do_cleanups (cleanup_child);
824 	    }
825 
826 	  do_cleanups (cleanup);
827 	  VEC_free (varobj_p, r->new);
828 	  r->new = NULL;	/* Paranoia.  */
829 	}
830 
831       if (mi_version (uiout) > 1)
832 	do_cleanups (cleanup);
833     }
834   VEC_free (varobj_update_result, changes);
835 }
836 
837 void
838 mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
839 {
840   if (argc != 0)
841     error (_("-enable-pretty-printing: no arguments allowed"));
842 
843   varobj_enable_pretty_printing ();
844 }
845 
846 void
847 mi_cmd_var_set_update_range (char *command, char **argv, int argc)
848 {
849   struct varobj *var;
850   int from, to;
851 
852   if (argc != 3)
853     error (_("-var-set-update-range: Usage: VAROBJ FROM TO"));
854 
855   var = varobj_get_handle (argv[0]);
856   from = atoi (argv[1]);
857   to = atoi (argv[2]);
858 
859   varobj_set_child_range (var, from, to);
860 }
861