public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 07/11] MI option --available-children-only
Date: Sun, 24 Nov 2013 02:12:00 -0000	[thread overview]
Message-ID: <1385258996-26047-8-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1385258996-26047-1-git-send-email-yao@codesourcery.com>

This patch adds option --available-children-only to three MI commands,
parse it, and set corresponding field of 'struct varobj_dynamic'.

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."));
 
   /* 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;
 }
 
+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);
 
-- 
1.7.7.6

  parent reply	other threads:[~2013-11-24  2:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-24  5:04 [RCF 00/11] Visit varobj available children only in MI Yao Qi
2013-11-24  2:12 ` [PATCH 04/11] Remove #if HAVE_PYTHON Yao Qi
2014-01-21 20:44   ` Keith Seitz
2013-11-24  2:12 ` [PATCH 03/11] Iterate over 'struct varobj_item' instead of PyObject Yao Qi
2014-01-21 20:44   ` Keith Seitz
2013-11-24  2:12 ` Yao Qi [this message]
2014-01-21 20:45   ` [PATCH 07/11] MI option --available-children-only Keith Seitz
2013-11-24  2:12 ` [PATCH 10/11] Match dynamic="1" in the output of -var-list-children Yao Qi
2014-01-21 20:47   ` Keith Seitz
2013-11-24  2:12 ` [PATCH 09/11] Delete varobj's children on traceframe is changed Yao Qi
2014-01-21 20:47   ` Keith Seitz
2013-11-24  2:12 ` [PATCH 11/11] Test case Yao Qi
2014-01-21 20:49   ` Keith Seitz
2013-11-24  2:12 ` [PATCH 05/11] Rename varobj_pretty_printed_p to varobj_is_dynamic_p Yao Qi
2014-01-21 20:44   ` Keith Seitz
2013-11-24  2:12 ` [PATCH 08/11] Iterator varobj_items by their availability Yao Qi
2014-01-21 20:46   ` Keith Seitz
2013-11-24  2:12 ` [PATCH 01/11] Use 'struct varobj_item' to represent name and value pair Yao Qi
2014-01-21 20:43   ` Keith Seitz
2014-01-22  1:00     ` Doug Evans
2014-01-23  4:08       ` Yao Qi
2014-01-23 16:08         ` Doug Evans
2013-11-24  2:12 ` [PATCH 02/11] Generalize varobj iterator Yao Qi
2014-01-21 20:44   ` Keith Seitz
2014-01-22  1:07     ` Doug Evans
2013-11-24  2:12 ` [PATCH 06/11] Use varobj_is_dynamic_p more widely Yao Qi
2014-01-21 20:44   ` Keith Seitz
2013-12-02  9:09 ` [RCF 00/11] Visit varobj available children only in MI Yao Qi
2013-12-17 12:54 ` Yao Qi
2014-01-07 18:22 ` Keith Seitz
2014-01-08 11:41   ` Joel Brobecker
2014-01-08 14:27   ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385258996-26047-8-git-send-email-yao@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).