2011-01-05 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-var.c
index 55ccdbd40f5c42c0df83a688f1f354927c1d9e45..8e0f410a08405b050864bd140f7cb7e67b852597 100644 (file)
@@ -1,6 +1,6 @@
 /* MI Command Set - varobj commands.
 
 /* MI Command Set - varobj commands.
 
-   Copyright (C) 2000, 2002, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2000, 2002, 2004, 2005, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions (a Red Hat company).
    Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions (a Red Hat company).
@@ -41,7 +41,8 @@ static void varobj_update_one (struct varobj *var,
                              enum print_values print_values,
                              int explicit);
 
                              enum print_values print_values,
                              int explicit);
 
-static int mi_print_value_p (struct type *type, enum print_values print_values);
+static int mi_print_value_p (struct varobj *var,
+                            enum print_values print_values);
 
 /* Print variable object VAR.  The PRINT_VALUES parameter controls
    if the value should be printed.  The PRINT_EXPRESSION parameter
 
 /* Print variable object VAR.  The PRINT_VALUES parameter controls
    if the value should be printed.  The PRINT_EXPRESSION parameter
@@ -50,17 +51,22 @@ static void
 print_varobj (struct varobj *var, enum print_values print_values,
              int print_expression)
 {
 print_varobj (struct varobj *var, enum print_values print_values,
              int print_expression)
 {
-  struct type *gdb_type;
   char *type;
   int thread_id;
   char *type;
   int thread_id;
+  char *display_hint;
 
   ui_out_field_string (uiout, "name", varobj_get_objname (var));
   if (print_expression)
     ui_out_field_string (uiout, "exp", varobj_get_expression (var));
   ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
   
 
   ui_out_field_string (uiout, "name", varobj_get_objname (var));
   if (print_expression)
     ui_out_field_string (uiout, "exp", varobj_get_expression (var));
   ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
   
-  if (mi_print_value_p (varobj_get_gdb_type (var), print_values))
-    ui_out_field_string (uiout, "value", varobj_get_value (var));
+  if (mi_print_value_p (var, print_values))
+    {
+      char *val = varobj_get_value (var);
+
+      ui_out_field_string (uiout, "value", val);
+      xfree (val);
+    }
 
   type = varobj_get_type (var);
   if (type != NULL)
 
   type = varobj_get_type (var);
   if (type != NULL)
@@ -75,6 +81,16 @@ print_varobj (struct varobj *var, enum print_values print_values,
 
   if (varobj_get_frozen (var))
     ui_out_field_int (uiout, "frozen", 1);
 
   if (varobj_get_frozen (var))
     ui_out_field_int (uiout, "frozen", 1);
+
+  display_hint = varobj_get_display_hint (var);
+  if (display_hint)
+    {
+      ui_out_field_string (uiout, "displayhint", display_hint);
+      xfree (display_hint);
+    }
+
+  if (varobj_pretty_printed_p (var))
+    ui_out_field_int (uiout, "dynamic", 1);
 }
 
 /* VAROBJ operations */
 }
 
 /* VAROBJ operations */
@@ -138,6 +154,8 @@ mi_cmd_var_create (char *command, char **argv, int argc)
 
   print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */);
 
 
   print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */);
 
+  ui_out_field_int (uiout, "has_more", varobj_has_more (var, 0));
+
   do_cleanups (old_cleanups);
 }
 
   do_cleanups (old_cleanups);
 }
 
@@ -163,7 +181,8 @@ mi_cmd_var_delete (char *command, char **argv, int argc)
   if (argc == 1)
     {
       if (strcmp (name, "-c") == 0)
   if (argc == 1)
     {
       if (strcmp (name, "-c") == 0)
-       error (_("mi_cmd_var_delete: Missing required argument after '-c': variable object name"));
+       error (_("mi_cmd_var_delete: Missing required "
+                "argument after '-c': variable object name"));
       if (*name == '-')
        error (_("mi_cmd_var_delete: Illegal variable object name"));
     }
       if (*name == '-')
        error (_("mi_cmd_var_delete: Illegal variable object name"));
     }
@@ -215,7 +234,8 @@ mi_parse_format (const char *arg)
        return FORMAT_OCTAL;
     }
 
        return FORMAT_OCTAL;
     }
 
-  error (_("Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
+  error (_("Must specify the format as: \"natural\", "
+          "\"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
 }
 
 void
 }
 
 void
@@ -223,6 +243,7 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
 {
   enum varobj_display_formats format;
   struct varobj *var;
 {
   enum varobj_display_formats format;
   struct varobj *var;
+  char *val;
 
   if (argc != 2)
     error (_("mi_cmd_var_set_format: Usage: NAME FORMAT."));
 
   if (argc != 2)
     error (_("mi_cmd_var_set_format: Usage: NAME FORMAT."));
@@ -239,7 +260,9 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
   ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
  
   /* Report the value in the new format */
   ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
  
   /* Report the value in the new format */
-  ui_out_field_string (uiout, "value", varobj_get_value (var));
+  val = varobj_get_value (var);
+  ui_out_field_string (uiout, "value", val);
+  xfree (val);
 }
 
 void
 }
 
 void
@@ -337,11 +360,12 @@ Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
 }
 
 /* Return 1 if given the argument PRINT_VALUES we should display
 }
 
 /* Return 1 if given the argument PRINT_VALUES we should display
-   a value of type TYPE.  */
+   the varobj VAR.  */
 
 static int
 
 static int
-mi_print_value_p (struct type *type, enum print_values print_values)
+mi_print_value_p (struct varobj *var, enum print_values print_values)
 {
 {
+  struct type *type;
 
   if (print_values == PRINT_NO_VALUES)
     return 0;
 
   if (print_values == PRINT_NO_VALUES)
     return 0;
@@ -349,6 +373,10 @@ mi_print_value_p (struct type *type, enum print_values print_values)
   if (print_values == PRINT_ALL_VALUES)
     return 1;
 
   if (print_values == PRINT_ALL_VALUES)
     return 1;
 
+  if (varobj_pretty_printed_p (var))
+    return 1;
+
+  type = varobj_get_gdb_type (var);
   if (type == NULL)
     return 1;
   else
   if (type == NULL)
     return 1;
   else
@@ -369,24 +397,35 @@ mi_cmd_var_list_children (char *command, char **argv, int argc)
   struct varobj *var;  
   VEC(varobj_p) *children;
   struct varobj *child;
   struct varobj *var;  
   VEC(varobj_p) *children;
   struct varobj *child;
-  struct cleanup *cleanup_children;
-  int numchild;
   enum print_values print_values;
   int ix;
   enum print_values print_values;
   int ix;
+  int from, to;
   char *display_hint;
 
   char *display_hint;
 
-  if (argc != 1 && argc != 2)
-    error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME"));
+  if (argc < 1 || argc > 4)
+    error (_("mi_cmd_var_list_children: Usage: "
+            "[PRINT_VALUES] NAME [FROM TO]"));
 
   /* Get varobj handle, if a valid var obj name was specified */
 
   /* Get varobj handle, if a valid var obj name was specified */
-  if (argc == 1)
+  if (argc == 1 || argc == 3)
     var = varobj_get_handle (argv[0]);
   else
     var = varobj_get_handle (argv[1]);
 
     var = varobj_get_handle (argv[0]);
   else
     var = varobj_get_handle (argv[1]);
 
-  children = varobj_list_children (var);
-  ui_out_field_int (uiout, "numchild", VEC_length (varobj_p, children));
-  if (argc == 2)
+  if (argc > 2)
+    {
+      from = atoi (argv[argc - 2]);
+      to = atoi (argv[argc - 1]);
+    }
+  else
+    {
+      from = -1;
+      to = -1;
+    }
+
+  children = varobj_list_children (var, &from, &to);
+  ui_out_field_int (uiout, "numchild", to - from);
+  if (argc == 2 || argc == 4)
     print_values = mi_parse_values_option (argv[0]);
   else
     print_values = PRINT_NO_VALUES;
     print_values = mi_parse_values_option (argv[0]);
   else
     print_values = PRINT_NO_VALUES;
@@ -398,21 +437,30 @@ mi_cmd_var_list_children (char *command, char **argv, int argc)
       xfree (display_hint);
     }
 
       xfree (display_hint);
     }
 
-  if (VEC_length (varobj_p, children) == 0)
-    return;
-
-  if (mi_version (uiout) == 1)
-    cleanup_children = make_cleanup_ui_out_tuple_begin_end (uiout, "children");
-  else
-    cleanup_children = make_cleanup_ui_out_list_begin_end (uiout, "children");
-  for (ix = 0; VEC_iterate (varobj_p, children, ix, child); ++ix)
+  if (from < to)
     {
     {
-      struct cleanup *cleanup_child;
-      cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
-      print_varobj (child, print_values, 1 /* print expression */);
-      do_cleanups (cleanup_child);
+      struct cleanup *cleanup_children;
+
+      if (mi_version (uiout) == 1)
+       cleanup_children
+         = make_cleanup_ui_out_tuple_begin_end (uiout, "children");
+      else
+       cleanup_children
+         = make_cleanup_ui_out_list_begin_end (uiout, "children");
+      for (ix = from;
+          ix < to && VEC_iterate (varobj_p, children, ix, child);
+          ++ix)
+       {
+         struct cleanup *cleanup_child;
+
+         cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
+         print_varobj (child, print_values, 1 /* print expression */);
+         do_cleanups (cleanup_child);
+       }
+      do_cleanups (cleanup_children);
     }
     }
-  do_cleanups (cleanup_children);
+
+  ui_out_field_int (uiout, "has_more", varobj_has_more (var, to));
 }
 
 void
 }
 
 void
@@ -513,7 +561,9 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
   optind = 0;
   while (1)
     {
   optind = 0;
   while (1)
     {
-      int opt = mi_getopt ("-var-evaluate-expression", argc, argv, opts, &optind, &optarg);
+      int opt = mi_getopt ("-var-evaluate-expression", argc, argv,
+                          opts, &optind, &optarg);
+
       if (opt < 0)
        break;
       switch ((enum opt) opt)
       if (opt < 0)
        break;
       switch ((enum opt) opt)
@@ -538,16 +588,26 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
   var = varobj_get_handle (argv[optind]);
    
   if (formatFound)
   var = varobj_get_handle (argv[optind]);
    
   if (formatFound)
-    ui_out_field_string (uiout, "value", varobj_get_formatted_value (var, format));
+    {
+      char *val = varobj_get_formatted_value (var, format);
+
+      ui_out_field_string (uiout, "value", val);
+      xfree (val);
+    }
   else
   else
-    ui_out_field_string (uiout, "value", varobj_get_value (var));
+    {
+      char *val = varobj_get_value (var);
+
+      ui_out_field_string (uiout, "value", val);
+      xfree (val);
+    }
 }
 
 void
 mi_cmd_var_assign (char *command, char **argv, int argc)
 {
   struct varobj *var;
 }
 
 void
 mi_cmd_var_assign (char *command, char **argv, int argc)
 {
   struct varobj *var;
-  char *expression;
+  char *expression, *val;
 
   if (argc != 2)
     error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION."));
 
   if (argc != 2)
     error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION."));
@@ -561,9 +621,47 @@ mi_cmd_var_assign (char *command, char **argv, int argc)
   expression = xstrdup (argv[1]);
 
   if (!varobj_set_value (var, expression))
   expression = xstrdup (argv[1]);
 
   if (!varobj_set_value (var, expression))
-    error (_("mi_cmd_var_assign: Could not assign expression to variable object"));
+    error (_("mi_cmd_var_assign: Could not assign "
+            "expression to variable object"));
+
+  val = varobj_get_value (var);
+  ui_out_field_string (uiout, "value", val);
+  xfree (val);
+}
+
+/* Type used for parameters passing to mi_cmd_var_update_iter.  */
+
+struct mi_cmd_var_update
+  {
+    int only_floating;
+    enum print_values print_values;
+  };
 
 
-  ui_out_field_string (uiout, "value", varobj_get_value (var));
+/* Helper for mi_cmd_var_update - update each VAR.  */
+
+static void
+mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
+{
+  struct mi_cmd_var_update *data = data_pointer;
+  int thread_id, thread_stopped;
+
+  thread_id = varobj_get_thread_id (var);
+
+  if (thread_id == -1 && is_stopped (inferior_ptid))
+    thread_stopped = 1;
+  else
+    {
+      struct thread_info *tp = find_thread_id (thread_id);
+
+      if (tp)
+       thread_stopped = is_stopped (tp->ptid);
+      else
+       thread_stopped = 1;
+    }
+
+  if (thread_stopped)
+    if (!data->only_floating || varobj_floating_p (var))
+      varobj_update_one (var, data->print_values, 0 /* implicit */);
 }
 
 void
 }
 
 void
@@ -596,31 +694,16 @@ mi_cmd_var_update (char *command, char **argv, int argc)
 
   if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
     {
 
   if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
     {
-      struct varobj **rootlist, **cr;
+      struct mi_cmd_var_update data;
 
 
-      varobj_list (&rootlist);
-      make_cleanup (xfree, rootlist);
+      data.only_floating = *name == '@';
+      data.print_values = print_values;
 
 
-      for (cr = rootlist; *cr != NULL; cr++)
-       {
-         int thread_id = varobj_get_thread_id (*cr);
-         int thread_stopped = 0;
-
-         if (thread_id == -1 && is_stopped (inferior_ptid))
-           thread_stopped = 1;
-         else
-           {
-             struct thread_info *tp = find_thread_id (thread_id);
-             if (tp)
-               thread_stopped = is_stopped (tp->ptid);
-             else
-               thread_stopped = 1;
-           }
+      /* varobj_update_one automatically updates all the children of VAROBJ.
+        Therefore update each VAROBJ only once by iterating only the root
+        VAROBJs.  */
 
 
-         if (thread_stopped)
-           if (*name == '*' || varobj_floating_p (*cr))
-             varobj_update_one (*cr, print_values, 0 /* implicit */);
-       }
+      all_root_varobjs (mi_cmd_var_update_iter, &data);
     }
   else
     {
     }
   else
     {
@@ -639,7 +722,6 @@ static void
 varobj_update_one (struct varobj *var, enum print_values print_values,
                   int explicit)
 {
 varobj_update_one (struct varobj *var, enum print_values print_values,
                   int explicit)
 {
-  struct varobj **cc;
   struct cleanup *cleanup = NULL;
   VEC (varobj_update_result) *changes;
   varobj_update_result *r;
   struct cleanup *cleanup = NULL;
   VEC (varobj_update_result) *changes;
   varobj_update_result *r;
@@ -650,6 +732,7 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
   for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
     {
       char *display_hint;
   for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
     {
       char *display_hint;
+      int from, to;
 
       if (mi_version (uiout) > 1)
         cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
 
       if (mi_version (uiout) > 1)
         cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
@@ -658,8 +741,13 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
       switch (r->status)
        {
        case VAROBJ_IN_SCOPE:
       switch (r->status)
        {
        case VAROBJ_IN_SCOPE:
-         if (mi_print_value_p (varobj_get_gdb_type (r->varobj), print_values))
-           ui_out_field_string (uiout, "value", varobj_get_value (r->varobj));
+         if (mi_print_value_p (r->varobj, print_values))
+           {
+             char *val = varobj_get_value (r->varobj);
+
+             ui_out_field_string (uiout, "value", val);
+             xfree (val);
+           }
          ui_out_field_string (uiout, "in_scope", "true");
          break;
         case VAROBJ_NOT_IN_SCOPE:
          ui_out_field_string (uiout, "in_scope", "true");
          break;
         case VAROBJ_NOT_IN_SCOPE:
@@ -679,11 +767,11 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
        }
 
       if (r->type_changed)
        }
 
       if (r->type_changed)
-       {
-          ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj));
-          ui_out_field_int (uiout, "new_num_children", 
-                           varobj_get_num_children (r->varobj));
-       }
+       ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj));
+
+      if (r->type_changed || r->children_changed)
+       ui_out_field_int (uiout, "new_num_children", 
+                         varobj_get_num_children (r->varobj));
 
       display_hint = varobj_get_display_hint (var);
       if (display_hint)
 
       display_hint = varobj_get_display_hint (var);
       if (display_hint)
@@ -692,28 +780,61 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
          xfree (display_hint);
        }
 
          xfree (display_hint);
        }
 
-      if (r->children_changed)
-       {
-         int ix;
-         struct varobj *child;
-         struct cleanup *cleanup =
-           make_cleanup_ui_out_list_begin_end (uiout, "children");
+      if (varobj_pretty_printed_p (var))
+       ui_out_field_int (uiout, "dynamic", 1);
+
+      varobj_get_child_range (r->varobj, &from, &to);
+      ui_out_field_int (uiout, "has_more",
+                       varobj_has_more (r->varobj, to));
 
 
-         VEC (varobj_p)* children = varobj_list_children (r->varobj);
+      if (r->new)
+       {
+         int j;
+         varobj_p child;
+         struct cleanup *cleanup;
 
 
-         for (ix = 0; VEC_iterate (varobj_p, children, ix, child); ++ix)
+         cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children");
+         for (j = 0; VEC_iterate (varobj_p, r->new, j, child); ++j)
            {
              struct cleanup *cleanup_child;
            {
              struct cleanup *cleanup_child;
-             cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-             print_varobj (child, print_values, 1 /* print expression */);
+
+             cleanup_child
+               = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+             print_varobj (child, print_values, 1 /* print_expression */);
              do_cleanups (cleanup_child);
            }
 
          do_cleanups (cleanup);
              do_cleanups (cleanup_child);
            }
 
          do_cleanups (cleanup);
+         VEC_free (varobj_p, r->new);
+         r->new = NULL;        /* Paranoia.  */
        }
        }
-  
+
       if (mi_version (uiout) > 1)
        do_cleanups (cleanup);
     }
   VEC_free (varobj_update_result, changes);
 }
       if (mi_version (uiout) > 1)
        do_cleanups (cleanup);
     }
   VEC_free (varobj_update_result, changes);
 }
+
+void
+mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
+{
+  if (argc != 0)
+    error (_("mi_cmd_enable_pretty_printing: no arguments allowed"));
+  varobj_enable_pretty_printing ();
+}
+
+void
+mi_cmd_var_set_update_range (char *command, char **argv, int argc)
+{
+  struct varobj *var;
+  int from, to;
+
+  if (argc != 3)
+    error (_("mi_cmd_var_set_update_range: Usage: VAROBJ FROM TO"));
+  
+  var = varobj_get_handle (argv[0]);
+  from = atoi (argv[1]);
+  to = atoi (argv[2]);
+
+  varobj_set_child_range (var, from, to);
+}
This page took 0.031613 seconds and 4 git commands to generate.