This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 07/11] MI option --available-children-only


On 11/23/2013 06:09 PM, Yao Qi wrote:
This patch adds option --available-children-only to three MI commands,
parse it, and set corresponding field of 'struct varobj_dynamic'.

I've already mentioned my preference for allowing --available-children-only for -var-create and adding a new command to flip it on/off, so unless another maintainer agrees, we'll agree to leave this alone.

Two minor nits below.

Keith

gdb:

2013-11-24  Pedro Alves  <pedro@codesourcery.com>
	    Yao Qi  <yao@codesourcery.com>

	* mi/mi-cmd-var.c (mi_cmd_var_create): Use mi_getopt to parse
	options.  Handle "--available-children-only".
	(mi_cmd_var_info_num_children): Likewise.
	(mi_cmd_var_list_children): Likewise.
	* varobj.c (struct varobj_dynamic) <available_children_only>:
	New.
	(new_variable, new_root_variable): Update declaration.
	(varobj_is_dynamic_p): Return true if available-children-only
	is true.
	(varobj_create): Add new argument "available_children_only".
	Callers update.
	(varobj_get_num_children): Handle "available_children_only"
	(varobj_set_available_children_only): New function.
	(varobj_list_children): Handle "available_children_only".
	(install_new_value): Likewise.
	(varobj_update): Likewise.
	(new_variable): Add new argument "available_children_only".
	(new_root_variable): Likewise.
	(varobj_invalidate_iter): Likewise.
	* varobj.h (varobj_create): Update declaration.
	(varobj_set_available_children_only): Declare.
---
  gdb/mi/mi-cmd-var.c |  128 ++++++++++++++++++++++++++++++++++++++++++++-------
  gdb/varobj.c        |   51 +++++++++++++++-----
  gdb/varobj.h        |   11 ++++-
  3 files changed, 160 insertions(+), 30 deletions(-)

diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 2201630..552a527 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -105,19 +105,50 @@ mi_cmd_var_create (char *command, char **argv, int argc)
    char *expr;
    struct cleanup *old_cleanups;
    enum varobj_type var_type;
+  int available_children_only = 0;
+  int oind = 0;
+  enum opt
+    {
+      AVAILABLE_CHILDREN_ONLY,
+    };
+  static const struct mi_opt opts[] =
+    {
+      {"-available-children-only", AVAILABLE_CHILDREN_ONLY, 0},
+      { 0, 0, 0 }
+    };

-  if (argc != 3)
-    error (_("-var-create: Usage: NAME FRAME EXPRESSION."));
+  /* Parse arguments.  In this instance we are just looking for
+     --available_children_only.  */
+  while (1)
+    {
+      char *oarg;
+      int opt = mi_getopt ("-var-create", argc, argv,
+			   opts, &oind, &oarg);
+      if (opt < 0)
+	break;
+      switch ((enum opt) opt)
+	{
+	case AVAILABLE_CHILDREN_ONLY:
+	  available_children_only = 1;
+	  break;
+	}
+    }

-  name = xstrdup (argv[0]);
+
+  if (argc - oind != 3)
+    error (_("Usage: -var-create [--available-children-only] "
+	     "NAME FRAME EXPRESSION"));
+
+
+  name = xstrdup (argv[oind]);
    /* Add cleanup for name. Must be free_current_contents as name can
       be reallocated.  */
    old_cleanups = make_cleanup (free_current_contents, &name);

-  frame = xstrdup (argv[1]);
+  frame = xstrdup (argv[oind + 1]);
    make_cleanup (xfree, frame);

-  expr = xstrdup (argv[2]);
+  expr = xstrdup (argv[oind + 2]);
    make_cleanup (xfree, expr);

    if (strcmp (name, "-") == 0)
@@ -143,7 +174,8 @@ mi_cmd_var_create (char *command, char **argv, int argc)
  		    "Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
  			name, frame, hex_string (frameaddr), expr);

-  var = varobj_create (name, expr, frameaddr, var_type);
+  var = varobj_create (name, expr, frameaddr, var_type,
+		       available_children_only);

    if (var == NULL)
      error (_("-var-create: unable to create variable object"));
@@ -328,12 +360,43 @@ mi_cmd_var_info_num_children (char *command, char **argv, int argc)
  {
    struct ui_out *uiout = current_uiout;
    struct varobj *var;
+  int available_children_only = 0;
+  int oind = 0;
+  enum opt
+    {
+      AVAILABLE_CHILDREN_ONLY,
+    };
+  static const struct mi_opt opts[] =
+    {
+      {"-available-children-only", AVAILABLE_CHILDREN_ONLY, 0},
+      { 0, 0, 0 }
+    };

-  if (argc != 1)
-    error (_("-var-info-num-children: Usage: NAME."));
+  /* Parse arguments.  In this instance we are just looking for
+     --available_children_only.  */
+  while (1)
+    {
+      char *oarg;
+      int opt = mi_getopt ("-var-info-num-children", argc, argv,
+			   opts, &oind, &oarg);
+      if (opt < 0)
+	break;
+      switch ((enum opt) opt)
+	{
+	case AVAILABLE_CHILDREN_ONLY:
+	  available_children_only = 1;
+	  break;
+	}
+    }
+
+  if (argc - oind != 1)
+    error (_("-var-info-num-children: Usage: "
+	     "[--available-children-only] NAME."));

This statement spans multiple lines and should be enclosed in braces ("{}").


    /* Get varobj handle, if a valid var obj name was specified.  */
-  var = varobj_get_handle (argv[0]);
+  var = varobj_get_handle (argv[oind]);
+
+  varobj_set_available_children_only (var, available_children_only);

    ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
  }
@@ -381,18 +444,47 @@ mi_cmd_var_list_children (char *command, char **argv, int argc)
    int ix;
    int from, to;
    char *display_hint;
+  int available_children_only = 0;
+  int oind = 0;
+  enum opt
+    {
+      AVAILABLE_CHILDREN_ONLY,
+    };
+  static const struct mi_opt opts[] =
+    {
+      {"-available-children-only", AVAILABLE_CHILDREN_ONLY, 0},
+      { 0, 0, 0 }
+    };
+
+  /* Parse arguments.  In this instance we are just looking for
+     --available_children_only.  */
+  while (1)
+    {
+      char *oarg;
+      int opt = mi_getopt_allow_unknown ("-var-list-children", argc, argv,
+					 opts, &oind, &oarg);
+
+      if (opt < 0)
+	break;
+      switch ((enum opt) opt)
+	{
+	case AVAILABLE_CHILDREN_ONLY:
+	  available_children_only = 1;
+	  break;
+	}
+    }

-  if (argc < 1 || argc > 4)
-    error (_("-var-list-children: Usage: "
+  if (argc - oind < 1 || argc - oind > 4)
+    error (_("-var-list-children: Usage: [--available-children-only] "
  	     "[PRINT_VALUES] NAME [FROM TO]"));

    /* Get varobj handle, if a valid var obj name was specified.  */
-  if (argc == 1 || argc == 3)
-    var = varobj_get_handle (argv[0]);
+  if (argc - oind == 1 || argc - oind == 3)
+    var = varobj_get_handle (argv[oind]);
    else
-    var = varobj_get_handle (argv[1]);
+    var = varobj_get_handle (argv[oind + 1]);

-  if (argc > 2)
+  if (argc - oind > 2)
      {
        from = atoi (argv[argc - 2]);
        to = atoi (argv[argc - 1]);
@@ -403,10 +495,12 @@ mi_cmd_var_list_children (char *command, char **argv, int argc)
        to = -1;
      }

+  varobj_set_available_children_only (var, available_children_only);
+
    children = varobj_list_children (var, &from, &to);
    ui_out_field_int (uiout, "numchild", to - from);
-  if (argc == 2 || argc == 4)
-    print_values = mi_parse_print_values (argv[0]);
+  if (argc - oind == 2 || argc - oind == 4)
+    print_values = mi_parse_print_values (argv[oind]);
    else
      print_values = PRINT_NO_VALUES;

diff --git a/gdb/varobj.c b/gdb/varobj.c
index 0e0be6c..1fd9fd2 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -119,6 +119,10 @@ struct varobj_dynamic
       can avoid that.  */
    int children_requested;

+  /* True if this varobj only includes available/collected objects in
+     its list of children.  */
+  int available_children_only;
+
    /* The pretty-printer constructor.  If NULL, then the default
       pretty-printer will be looked up.  If None, then no
       pretty-printer will be installed.  */
@@ -175,9 +179,9 @@ create_child_with_value (struct varobj *parent, int index,

  /* Utility routines */

-static struct varobj *new_variable (void);
+static struct varobj *new_variable (int available_children_only);

-static struct varobj *new_root_variable (void);
+static struct varobj *new_root_variable (int available_children_only);

  static void free_variable (struct varobj *var);

@@ -285,14 +289,14 @@ find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
  }

  struct varobj *
-varobj_create (char *objname,
-	       char *expression, CORE_ADDR frame, enum varobj_type type)
+varobj_create (char *objname, char *expression, CORE_ADDR frame,
+	       enum varobj_type type, int available_children_only)
  {
    struct varobj *var;
    struct cleanup *old_chain;

    /* Fill out a varobj structure for the (root) variable being constructed.  */
-  var = new_root_variable ();
+  var = new_root_variable (available_children_only);
    old_chain = make_cleanup_free_variable (var);

    if (expression != NULL)
@@ -911,6 +915,23 @@ varobj_get_num_children (struct varobj *var)
    return var->num_children >= 0 ? var->num_children : 0;
  }


Missing comment to describe below function. ["See description in varobj.h."]

+void
+varobj_set_available_children_only (struct varobj *var, int available_only)
+{
+  if (var->dynamic->available_children_only != available_only)
+    {
+      /* If there are any children now, wipe them.  */
+      varobj_delete (var, NULL, /* children only */ 1);
+      var->num_children = -1;
+      var->dynamic->available_children_only = available_only;
+
+      /* We're starting over, so get rid of any iterator.  */
+      varobj_iter_delete (var->dynamic->child_iter);
+      var->dynamic->child_iter = NULL;
+      varobj_clear_saved_item (var->dynamic);
+    }
+}
+
  /* Creates a list of the immediate children of a variable object;
     the return code is the number of such children or -1 on error.  */

@@ -1071,7 +1092,8 @@ varobj_get_attributes (struct varobj *var)
  int
  varobj_is_dynamic_p (struct varobj *var)
  {
-  return var->dynamic->pretty_printer != NULL;
+  return (var->dynamic->pretty_printer != NULL
+	  || var->dynamic->available_children_only);
  }

  char *
@@ -2049,7 +2071,7 @@ create_child_with_value (struct varobj *parent, int index,
    struct varobj *child;
    char *childs_name;

-  child = new_variable ();
+  child = new_variable (parent->dynamic->available_children_only);

    /* NAME is allocated by caller.  */
    child->name = item->name;
@@ -2086,8 +2108,9 @@ create_child_with_value (struct varobj *parent, int index,
   */

  /* Allocate memory and initialize a new variable.  */
+
  static struct varobj *
-new_variable (void)
+new_variable (int available_children_only)
  {
    struct varobj *var;

@@ -2116,15 +2139,17 @@ new_variable (void)
    var->dynamic->pretty_printer = 0;
    var->dynamic->child_iter = 0;
    var->dynamic->saved_item = 0;
+  var->dynamic->available_children_only = available_children_only;

    return var;
  }

  /* Allocate memory and initialize a new root variable.  */
+
  static struct varobj *
-new_root_variable (void)
+new_root_variable (int available_children_only)
  {
-  struct varobj *var = new_variable ();
+  struct varobj *var = new_variable (available_children_only);

    var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));
    var->root->lang_ops = NULL;
@@ -2396,7 +2421,8 @@ value_of_root (struct varobj **var_handle, int *type_changed)
        char *old_type, *new_type;

        tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
-			       USE_SELECTED_FRAME);
+			       USE_SELECTED_FRAME,
+			       var->dynamic->available_children_only);
        if (tmp_var == NULL)
  	{
  	  return NULL;
@@ -2756,7 +2782,8 @@ varobj_invalidate_iter (struct varobj *var, void *unused)
        /* Try to create a varobj with same expression.  If we succeed
  	 replace the old varobj, otherwise invalidate it.  */
        tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
-			       USE_CURRENT_FRAME);
+			       USE_CURRENT_FRAME,
+			       var->dynamic->available_children_only);
        if (tmp_var != NULL)
  	{
  	  tmp_var->obj_name = xstrdup (var->obj_name);
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 60ace6f..9beec79 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -225,7 +225,8 @@ const struct lang_varobj_ops ada_varobj_ops;

  extern struct varobj *varobj_create (char *objname,
  				     char *expression, CORE_ADDR frame,
-				     enum varobj_type type);
+				     enum varobj_type type,
+				     int available_children_only);

  extern char *varobj_gen_name (void);

@@ -310,6 +311,14 @@ extern int varobj_is_dynamic_p (struct varobj *var);

  extern  struct cleanup *varobj_ensure_python_env (struct varobj *var);

+/* Marks the varobj VAR as listing available children only or not,
+   depending on the boolean AVAILABLE_ONLY.  If the
+   available-only-ness of the varobj changes compared to its present
+   state with this call, the varobj's current list of children is
+   deleted.  */
+extern void varobj_set_available_children_only (struct varobj *var,
+						int available_only);
+
  extern int varobj_default_value_is_changeable_p (struct varobj *var);
  extern int varobj_value_is_changeable_p (struct varobj *var);




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]