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