gdb/mi/mi-cmd-var.c - gdb

Data types defined

Functions defined

Source code

  1. /* MI Command Set - varobj commands.
  2.    Copyright (C) 2000-2015 Free Software Foundation, Inc.

  3.    Contributed by Cygnus Solutions (a Red Hat company).

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "mi-cmds.h"
  17. #include "mi-main.h"
  18. #include "ui-out.h"
  19. #include "mi-out.h"
  20. #include "varobj.h"
  21. #include "language.h"
  22. #include "value.h"
  23. #include <ctype.h>
  24. #include "mi-getopt.h"
  25. #include "gdbthread.h"
  26. #include "mi-parse.h"

  27. extern unsigned int varobjdebug;                /* defined in varobj.c.  */

  28. static void varobj_update_one (struct varobj *var,
  29.                                enum print_values print_values,
  30.                                int explicit);

  31. static int mi_print_value_p (struct varobj *var,
  32.                              enum print_values print_values);

  33. /* Print variable object VAR.  The PRINT_VALUES parameter controls
  34.    if the value should be printed.  The PRINT_EXPRESSION parameter
  35.    controls if the expression should be printed.  */

  36. static void
  37. print_varobj (struct varobj *var, enum print_values print_values,
  38.               int print_expression)
  39. {
  40.   struct ui_out *uiout = current_uiout;
  41.   char *type;
  42.   int thread_id;
  43.   char *display_hint;

  44.   ui_out_field_string (uiout, "name", varobj_get_objname (var));
  45.   if (print_expression)
  46.     ui_out_field_string (uiout, "exp", varobj_get_expression (var));
  47.   ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));

  48.   if (mi_print_value_p (var, print_values))
  49.     {
  50.       char *val = varobj_get_value (var);

  51.       ui_out_field_string (uiout, "value", val);
  52.       xfree (val);
  53.     }

  54.   type = varobj_get_type (var);
  55.   if (type != NULL)
  56.     {
  57.       ui_out_field_string (uiout, "type", type);
  58.       xfree (type);
  59.     }

  60.   thread_id = varobj_get_thread_id (var);
  61.   if (thread_id > 0)
  62.     ui_out_field_int (uiout, "thread-id", thread_id);

  63.   if (varobj_get_frozen (var))
  64.     ui_out_field_int (uiout, "frozen", 1);

  65.   display_hint = varobj_get_display_hint (var);
  66.   if (display_hint)
  67.     {
  68.       ui_out_field_string (uiout, "displayhint", display_hint);
  69.       xfree (display_hint);
  70.     }

  71.   if (varobj_is_dynamic_p (var))
  72.     ui_out_field_int (uiout, "dynamic", 1);
  73. }

  74. /* VAROBJ operations */

  75. void
  76. mi_cmd_var_create (char *command, char **argv, int argc)
  77. {
  78.   struct ui_out *uiout = current_uiout;
  79.   CORE_ADDR frameaddr = 0;
  80.   struct varobj *var;
  81.   char *name;
  82.   char *frame;
  83.   char *expr;
  84.   struct cleanup *old_cleanups;
  85.   enum varobj_type var_type;

  86.   if (argc != 3)
  87.     error (_("-var-create: Usage: NAME FRAME EXPRESSION."));

  88.   name = xstrdup (argv[0]);
  89.   /* Add cleanup for name. Must be free_current_contents as name can
  90.      be reallocated.  */
  91.   old_cleanups = make_cleanup (free_current_contents, &name);

  92.   frame = xstrdup (argv[1]);
  93.   make_cleanup (xfree, frame);

  94.   expr = xstrdup (argv[2]);
  95.   make_cleanup (xfree, expr);

  96.   if (strcmp (name, "-") == 0)
  97.     {
  98.       xfree (name);
  99.       name = varobj_gen_name ();
  100.     }
  101.   else if (!isalpha (*name))
  102.     error (_("-var-create: name of object must begin with a letter"));

  103.   if (strcmp (frame, "*") == 0)
  104.     var_type = USE_CURRENT_FRAME;
  105.   else if (strcmp (frame, "@") == 0)
  106.     var_type = USE_SELECTED_FRAME;
  107.   else
  108.     {
  109.       var_type = USE_SPECIFIED_FRAME;
  110.       frameaddr = string_to_core_addr (frame);
  111.     }

  112.   if (varobjdebug)
  113.     fprintf_unfiltered (gdb_stdlog,
  114.                     "Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
  115.                         name, frame, hex_string (frameaddr), expr);

  116.   var = varobj_create (name, expr, frameaddr, var_type);

  117.   if (var == NULL)
  118.     error (_("-var-create: unable to create variable object"));

  119.   print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */);

  120.   ui_out_field_int (uiout, "has_more", varobj_has_more (var, 0));

  121.   do_cleanups (old_cleanups);
  122. }

  123. void
  124. mi_cmd_var_delete (char *command, char **argv, int argc)
  125. {
  126.   char *name;
  127.   struct varobj *var;
  128.   int numdel;
  129.   int children_only_p = 0;
  130.   struct cleanup *old_cleanups;
  131.   struct ui_out *uiout = current_uiout;

  132.   if (argc < 1 || argc > 2)
  133.     error (_("-var-delete: Usage: [-c] EXPRESSION."));

  134.   name = xstrdup (argv[0]);
  135.   /* Add cleanup for name. Must be free_current_contents as name can
  136.      be reallocated.  */
  137.   old_cleanups = make_cleanup (free_current_contents, &name);

  138.   /* If we have one single argument it cannot be '-c' or any string
  139.      starting with '-'.  */
  140.   if (argc == 1)
  141.     {
  142.       if (strcmp (name, "-c") == 0)
  143.         error (_("-var-delete: Missing required "
  144.                  "argument after '-c': variable object name"));
  145.       if (*name == '-')
  146.         error (_("-var-delete: Illegal variable object name"));
  147.     }

  148.   /* If we have 2 arguments they must be '-c' followed by a string
  149.      which would be the variable name.  */
  150.   if (argc == 2)
  151.     {
  152.       if (strcmp (name, "-c") != 0)
  153.         error (_("-var-delete: Invalid option."));
  154.       children_only_p = 1;
  155.       do_cleanups (old_cleanups);
  156.       name = xstrdup (argv[1]);
  157.       old_cleanups = make_cleanup (free_current_contents, &name);
  158.     }

  159.   /* If we didn't error out, now NAME contains the name of the
  160.      variable.  */

  161.   var = varobj_get_handle (name);

  162.   numdel = varobj_delete (var, NULL, children_only_p);

  163.   ui_out_field_int (uiout, "ndeleted", numdel);

  164.   do_cleanups (old_cleanups);
  165. }

  166. /* Parse a string argument into a format value.  */

  167. static enum varobj_display_formats
  168. mi_parse_format (const char *arg)
  169. {
  170.   if (arg != NULL)
  171.     {
  172.       int len;

  173.       len = strlen (arg);

  174.       if (strncmp (arg, "natural", len) == 0)
  175.         return FORMAT_NATURAL;
  176.       else if (strncmp (arg, "binary", len) == 0)
  177.         return FORMAT_BINARY;
  178.       else if (strncmp (arg, "decimal", len) == 0)
  179.         return FORMAT_DECIMAL;
  180.       else if (strncmp (arg, "hexadecimal", len) == 0)
  181.         return FORMAT_HEXADECIMAL;
  182.       else if (strncmp (arg, "octal", len) == 0)
  183.         return FORMAT_OCTAL;
  184.     }

  185.   error (_("Must specify the format as: \"natural\", "
  186.            "\"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
  187. }

  188. void
  189. mi_cmd_var_set_format (char *command, char **argv, int argc)
  190. {
  191.   enum varobj_display_formats format;
  192.   struct varobj *var;
  193.   char *val;
  194.   struct ui_out *uiout = current_uiout;

  195.   if (argc != 2)
  196.     error (_("-var-set-format: Usage: NAME FORMAT."));

  197.   /* Get varobj handle, if a valid var obj name was specified.  */
  198.   var = varobj_get_handle (argv[0]);

  199.   format = mi_parse_format (argv[1]);

  200.   /* Set the format of VAR to the given format.  */
  201.   varobj_set_display_format (var, format);

  202.   /* Report the new current format.  */
  203.   ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);

  204.   /* Report the value in the new format.  */
  205.   val = varobj_get_value (var);
  206.   ui_out_field_string (uiout, "value", val);
  207.   xfree (val);
  208. }

  209. void
  210. mi_cmd_var_set_visualizer (char *command, char **argv, int argc)
  211. {
  212.   struct varobj *var;

  213.   if (argc != 2)
  214.     error (_("Usage: NAME VISUALIZER_FUNCTION."));

  215.   var = varobj_get_handle (argv[0]);

  216.   if (var == NULL)
  217.     error (_("Variable object not found"));

  218.   varobj_set_visualizer (var, argv[1]);
  219. }

  220. void
  221. mi_cmd_var_set_frozen (char *command, char **argv, int argc)
  222. {
  223.   struct varobj *var;
  224.   int frozen;

  225.   if (argc != 2)
  226.     error (_("-var-set-format: Usage: NAME FROZEN_FLAG."));

  227.   var = varobj_get_handle (argv[0]);

  228.   if (strcmp (argv[1], "0") == 0)
  229.     frozen = 0;
  230.   else if (strcmp (argv[1], "1") == 0)
  231.     frozen = 1;
  232.   else
  233.     error (_("Invalid flag value"));

  234.   varobj_set_frozen (var, frozen);

  235.   /* We don't automatically return the new value, or what varobjs got
  236.      new values during unfreezing.  If this information is required,
  237.      client should call -var-update explicitly.  */
  238. }

  239. void
  240. mi_cmd_var_show_format (char *command, char **argv, int argc)
  241. {
  242.   struct ui_out *uiout = current_uiout;
  243.   enum varobj_display_formats format;
  244.   struct varobj *var;

  245.   if (argc != 1)
  246.     error (_("-var-show-format: Usage: NAME."));

  247.   /* Get varobj handle, if a valid var obj name was specified.  */
  248.   var = varobj_get_handle (argv[0]);

  249.   format = varobj_get_display_format (var);

  250.   /* Report the current format.  */
  251.   ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
  252. }

  253. void
  254. mi_cmd_var_info_num_children (char *command, char **argv, int argc)
  255. {
  256.   struct ui_out *uiout = current_uiout;
  257.   struct varobj *var;

  258.   if (argc != 1)
  259.     error (_("-var-info-num-children: Usage: NAME."));

  260.   /* Get varobj handle, if a valid var obj name was specified.  */
  261.   var = varobj_get_handle (argv[0]);

  262.   ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
  263. }

  264. /* Return 1 if given the argument PRINT_VALUES we should display
  265.    the varobj VAR.  */

  266. static int
  267. mi_print_value_p (struct varobj *var, enum print_values print_values)
  268. {
  269.   struct type *type;

  270.   if (print_values == PRINT_NO_VALUES)
  271.     return 0;

  272.   if (print_values == PRINT_ALL_VALUES)
  273.     return 1;

  274.   if (varobj_is_dynamic_p (var))
  275.     return 1;

  276.   type = varobj_get_gdb_type (var);
  277.   if (type == NULL)
  278.     return 1;
  279.   else
  280.     {
  281.       type = check_typedef (type);

  282.       /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
  283.          and that type is not a compound type.  */
  284.       return (TYPE_CODE (type) != TYPE_CODE_ARRAY
  285.               && TYPE_CODE (type) != TYPE_CODE_STRUCT
  286.               && TYPE_CODE (type) != TYPE_CODE_UNION);
  287.     }
  288. }

  289. void
  290. mi_cmd_var_list_children (char *command, char **argv, int argc)
  291. {
  292.   struct ui_out *uiout = current_uiout;
  293.   struct varobj *var;
  294.   VEC(varobj_p) *children;
  295.   struct varobj *child;
  296.   enum print_values print_values;
  297.   int ix;
  298.   int from, to;
  299.   char *display_hint;

  300.   if (argc < 1 || argc > 4)
  301.     error (_("-var-list-children: Usage: "
  302.              "[PRINT_VALUES] NAME [FROM TO]"));

  303.   /* Get varobj handle, if a valid var obj name was specified.  */
  304.   if (argc == 1 || argc == 3)
  305.     var = varobj_get_handle (argv[0]);
  306.   else
  307.     var = varobj_get_handle (argv[1]);

  308.   if (argc > 2)
  309.     {
  310.       from = atoi (argv[argc - 2]);
  311.       to = atoi (argv[argc - 1]);
  312.     }
  313.   else
  314.     {
  315.       from = -1;
  316.       to = -1;
  317.     }

  318.   children = varobj_list_children (var, &from, &to);
  319.   ui_out_field_int (uiout, "numchild", to - from);
  320.   if (argc == 2 || argc == 4)
  321.     print_values = mi_parse_print_values (argv[0]);
  322.   else
  323.     print_values = PRINT_NO_VALUES;

  324.   display_hint = varobj_get_display_hint (var);
  325.   if (display_hint)
  326.     {
  327.       ui_out_field_string (uiout, "displayhint", display_hint);
  328.       xfree (display_hint);
  329.     }

  330.   if (from < to)
  331.     {
  332.       struct cleanup *cleanup_children;

  333.       if (mi_version (uiout) == 1)
  334.         cleanup_children
  335.           = make_cleanup_ui_out_tuple_begin_end (uiout, "children");
  336.       else
  337.         cleanup_children
  338.           = make_cleanup_ui_out_list_begin_end (uiout, "children");
  339.       for (ix = from;
  340.            ix < to && VEC_iterate (varobj_p, children, ix, child);
  341.            ++ix)
  342.         {
  343.           struct cleanup *cleanup_child;

  344.           cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
  345.           print_varobj (child, print_values, 1 /* print expression */);
  346.           do_cleanups (cleanup_child);
  347.         }
  348.       do_cleanups (cleanup_children);
  349.     }

  350.   ui_out_field_int (uiout, "has_more", varobj_has_more (var, to));
  351. }

  352. void
  353. mi_cmd_var_info_type (char *command, char **argv, int argc)
  354. {
  355.   struct ui_out *uiout = current_uiout;
  356.   struct varobj *var;

  357.   if (argc != 1)
  358.     error (_("-var-info-type: Usage: NAME."));

  359.   /* Get varobj handle, if a valid var obj name was specified.  */
  360.   var = varobj_get_handle (argv[0]);

  361.   ui_out_field_string (uiout, "type", varobj_get_type (var));
  362. }

  363. void
  364. mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
  365. {
  366.   struct ui_out *uiout = current_uiout;
  367.   struct varobj *var;
  368.   char *path_expr;

  369.   if (argc != 1)
  370.     error (_("Usage: NAME."));

  371.   /* Get varobj handle, if a valid var obj name was specified.  */
  372.   var = varobj_get_handle (argv[0]);

  373.   path_expr = varobj_get_path_expr (var);

  374.   ui_out_field_string (uiout, "path_expr", path_expr);
  375. }

  376. void
  377. mi_cmd_var_info_expression (char *command, char **argv, int argc)
  378. {
  379.   struct ui_out *uiout = current_uiout;
  380.   const struct language_defn *lang;
  381.   struct varobj *var;

  382.   if (argc != 1)
  383.     error (_("-var-info-expression: Usage: NAME."));

  384.   /* Get varobj handle, if a valid var obj name was specified.  */
  385.   var = varobj_get_handle (argv[0]);

  386.   lang = varobj_get_language (var);

  387.   ui_out_field_string (uiout, "lang", lang->la_natural_name);
  388.   ui_out_field_string (uiout, "exp", varobj_get_expression (var));
  389. }

  390. void
  391. mi_cmd_var_show_attributes (char *command, char **argv, int argc)
  392. {
  393.   struct ui_out *uiout = current_uiout;
  394.   int attr;
  395.   char *attstr;
  396.   struct varobj *var;

  397.   if (argc != 1)
  398.     error (_("-var-show-attributes: Usage: NAME."));

  399.   /* Get varobj handle, if a valid var obj name was specified */
  400.   var = varobj_get_handle (argv[0]);

  401.   attr = varobj_get_attributes (var);
  402.   /* FIXME: define masks for attributes */
  403.   if (attr & 0x00000001)
  404.     attstr = "editable";
  405.   else
  406.     attstr = "noneditable";

  407.   ui_out_field_string (uiout, "attr", attstr);
  408. }

  409. void
  410. mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
  411. {
  412.   struct ui_out *uiout = current_uiout;
  413.   struct varobj *var;

  414.   enum varobj_display_formats format;
  415.   int formatFound;
  416.   int oind;
  417.   char *oarg;

  418.   enum opt
  419.   {
  420.     OP_FORMAT
  421.   };
  422.   static const struct mi_opt opts[] =
  423.     {
  424.       {"f", OP_FORMAT, 1},
  425.       { 0, 0, 0 }
  426.     };

  427.   /* Parse arguments.  */
  428.   format = FORMAT_NATURAL;
  429.   formatFound = 0;
  430.   oind = 0;
  431.   while (1)
  432.     {
  433.       int opt = mi_getopt ("-var-evaluate-expression", argc, argv,
  434.                            opts, &oind, &oarg);

  435.       if (opt < 0)
  436.         break;
  437.       switch ((enum opt) opt)
  438.         {
  439.         case OP_FORMAT:
  440.           if (formatFound)
  441.             error (_("Cannot specify format more than once"));

  442.           format = mi_parse_format (oarg);
  443.           formatFound = 1;
  444.           break;
  445.         }
  446.     }

  447.   if (oind >= argc)
  448.     error (_("Usage: [-f FORMAT] NAME"));

  449.   if (oind < argc - 1)
  450.     error (_("Garbage at end of command"));

  451.   /* Get varobj handle, if a valid var obj name was specified.  */
  452.   var = varobj_get_handle (argv[oind]);

  453.   if (formatFound)
  454.     {
  455.       char *val = varobj_get_formatted_value (var, format);

  456.       ui_out_field_string (uiout, "value", val);
  457.       xfree (val);
  458.     }
  459.   else
  460.     {
  461.       char *val = varobj_get_value (var);

  462.       ui_out_field_string (uiout, "value", val);
  463.       xfree (val);
  464.     }
  465. }

  466. void
  467. mi_cmd_var_assign (char *command, char **argv, int argc)
  468. {
  469.   struct ui_out *uiout = current_uiout;
  470.   struct varobj *var;
  471.   char *expression, *val;
  472.   struct cleanup *cleanup;

  473.   if (argc != 2)
  474.     error (_("-var-assign: Usage: NAME EXPRESSION."));

  475.   /* Get varobj handle, if a valid var obj name was specified.  */
  476.   var = varobj_get_handle (argv[0]);

  477.   if (!varobj_editable_p (var))
  478.     error (_("-var-assign: Variable object is not editable"));

  479.   expression = xstrdup (argv[1]);

  480.   /* MI command '-var-assign' may write memory, so suppress memory
  481.      changed notification if it does.  */
  482.   cleanup
  483.     = make_cleanup_restore_integer (&mi_suppress_notification.memory);
  484.   mi_suppress_notification.memory = 1;

  485.   if (!varobj_set_value (var, expression))
  486.     error (_("-var-assign: Could not assign "
  487.              "expression to variable object"));

  488.   val = varobj_get_value (var);
  489.   ui_out_field_string (uiout, "value", val);
  490.   xfree (val);

  491.   do_cleanups (cleanup);
  492. }

  493. /* Type used for parameters passing to mi_cmd_var_update_iter.  */

  494. struct mi_cmd_var_update
  495.   {
  496.     int only_floating;
  497.     enum print_values print_values;
  498.   };

  499. /* Helper for mi_cmd_var_update - update each VAR.  */

  500. static void
  501. mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
  502. {
  503.   struct mi_cmd_var_update *data = data_pointer;
  504.   int thread_id, thread_stopped;

  505.   thread_id = varobj_get_thread_id (var);

  506.   if (thread_id == -1
  507.       && (ptid_equal (inferior_ptid, null_ptid)
  508.           || is_stopped (inferior_ptid)))
  509.     thread_stopped = 1;
  510.   else
  511.     {
  512.       struct thread_info *tp = find_thread_id (thread_id);

  513.       if (tp)
  514.         thread_stopped = is_stopped (tp->ptid);
  515.       else
  516.         thread_stopped = 1;
  517.     }

  518.   if (thread_stopped
  519.       && (!data->only_floating || varobj_floating_p (var)))
  520.     varobj_update_one (var, data->print_values, 0 /* implicit */);
  521. }

  522. void
  523. mi_cmd_var_update (char *command, char **argv, int argc)
  524. {
  525.   struct ui_out *uiout = current_uiout;
  526.   struct cleanup *cleanup;
  527.   char *name;
  528.   enum print_values print_values;

  529.   if (argc != 1 && argc != 2)
  530.     error (_("-var-update: Usage: [PRINT_VALUES] NAME."));

  531.   if (argc == 1)
  532.     name = argv[0];
  533.   else
  534.     name = argv[1];

  535.   if (argc == 2)
  536.     print_values = mi_parse_print_values (argv[0]);
  537.   else
  538.     print_values = PRINT_NO_VALUES;

  539.   if (mi_version (uiout) <= 1)
  540.     cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
  541.   else
  542.     cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");

  543.   /* Check if the parameter is a "*", which means that we want to
  544.      update all variables.  */

  545.   if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
  546.     {
  547.       struct mi_cmd_var_update data;

  548.       data.only_floating = (*name == '@');
  549.       data.print_values = print_values;

  550.       /* varobj_update_one automatically updates all the children of
  551.          VAROBJ.  Therefore update each VAROBJ only once by iterating
  552.          only the root VAROBJs.  */

  553.       all_root_varobjs (mi_cmd_var_update_iter, &data);
  554.     }
  555.   else
  556.     {
  557.       /* Get varobj handle, if a valid var obj name was specified.  */
  558.       struct varobj *var = varobj_get_handle (name);

  559.       varobj_update_one (var, print_values, 1 /* explicit */);
  560.     }

  561.   do_cleanups (cleanup);
  562. }

  563. /* Helper for mi_cmd_var_update().  */

  564. static void
  565. varobj_update_one (struct varobj *var, enum print_values print_values,
  566.                    int explicit)
  567. {
  568.   struct ui_out *uiout = current_uiout;
  569.   VEC (varobj_update_result) *changes;
  570.   varobj_update_result *r;
  571.   int i;

  572.   changes = varobj_update (&var, explicit);

  573.   for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
  574.     {
  575.       char *display_hint;
  576.       int from, to;
  577.       struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);

  578.       if (mi_version (uiout) > 1)
  579.         make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
  580.       ui_out_field_string (uiout, "name", varobj_get_objname (r->varobj));

  581.       switch (r->status)
  582.         {
  583.         case VAROBJ_IN_SCOPE:
  584.           if (mi_print_value_p (r->varobj, print_values))
  585.             {
  586.               char *val = varobj_get_value (r->varobj);

  587.               ui_out_field_string (uiout, "value", val);
  588.               xfree (val);
  589.             }
  590.           ui_out_field_string (uiout, "in_scope", "true");
  591.           break;
  592.         case VAROBJ_NOT_IN_SCOPE:
  593.           ui_out_field_string (uiout, "in_scope", "false");
  594.           break;
  595.         case VAROBJ_INVALID:
  596.           ui_out_field_string (uiout, "in_scope", "invalid");
  597.            break;
  598.         }

  599.       if (r->status != VAROBJ_INVALID)
  600.         {
  601.           if (r->type_changed)
  602.             ui_out_field_string (uiout, "type_changed", "true");
  603.           else
  604.             ui_out_field_string (uiout, "type_changed", "false");
  605.         }

  606.       if (r->type_changed)
  607.         ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj));

  608.       if (r->type_changed || r->children_changed)
  609.         ui_out_field_int (uiout, "new_num_children",
  610.                           varobj_get_num_children (r->varobj));

  611.       display_hint = varobj_get_display_hint (r->varobj);
  612.       if (display_hint)
  613.         {
  614.           ui_out_field_string (uiout, "displayhint", display_hint);
  615.           xfree (display_hint);
  616.         }

  617.       if (varobj_is_dynamic_p (r->varobj))
  618.         ui_out_field_int (uiout, "dynamic", 1);

  619.       varobj_get_child_range (r->varobj, &from, &to);
  620.       ui_out_field_int (uiout, "has_more",
  621.                         varobj_has_more (r->varobj, to));

  622.       if (r->new)
  623.         {
  624.           int j;
  625.           varobj_p child;
  626.           struct cleanup *cleanup;

  627.           cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children");
  628.           for (j = 0; VEC_iterate (varobj_p, r->new, j, child); ++j)
  629.             {
  630.               struct cleanup *cleanup_child;

  631.               cleanup_child
  632.                 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
  633.               print_varobj (child, print_values, 1 /* print_expression */);
  634.               do_cleanups (cleanup_child);
  635.             }

  636.           do_cleanups (cleanup);
  637.           VEC_free (varobj_p, r->new);
  638.           r->new = NULL;        /* Paranoia.  */
  639.         }

  640.       do_cleanups (cleanup);
  641.     }
  642.   VEC_free (varobj_update_result, changes);
  643. }

  644. void
  645. mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
  646. {
  647.   if (argc != 0)
  648.     error (_("-enable-pretty-printing: no arguments allowed"));

  649.   varobj_enable_pretty_printing ();
  650. }

  651. void
  652. mi_cmd_var_set_update_range (char *command, char **argv, int argc)
  653. {
  654.   struct varobj *var;
  655.   int from, to;

  656.   if (argc != 3)
  657.     error (_("-var-set-update-range: Usage: VAROBJ FROM TO"));

  658.   var = varobj_get_handle (argv[0]);
  659.   from = atoi (argv[1]);
  660.   to = atoi (argv[2]);

  661.   varobj_set_child_range (var, from, to);
  662. }