Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 08/12] Iterator varobj_items by their availability
Date: Fri, 14 Feb 2014 08:46:00 -0000	[thread overview]
Message-ID: <1392367471-13527-9-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1392367471-13527-1-git-send-email-yao@codesourcery.com>

This patch adds a new implementation of varobj iterator, which is
based on the availability of children.

 V2:
 - Fix changelog entry.
 - Add comments.
 - Use XNEW.
 - Fix typo.
 - Update copyright year for new added file.

gdb:

2014-02-14  Pedro Alves  <pedro@codesourcery.com>
	    Yao Qi  <yao@codesourcery.com>

	* Makefile.in (SFILES): Add varobj-iter-avail.c.
	(COMMON_OBS): Add varobj-iter-avail.o.
	* varobj-iter-avail.c: New file.
	* varobj-iter.h (avail_varobj_get_iterator): Declare.
	* varobj.c (varobj_get_iterator): Add one more argument
	'lang_ops'.  All callers updated.
	Return iterator for available children.
---
 gdb/Makefile.in         |    4 +-
 gdb/varobj-iter-avail.c |  162 +++++++++++++++++++++++++++++++++++++++++++++++
 gdb/varobj-iter.h       |    4 +
 gdb/varobj.c            |    8 ++-
 4 files changed, 174 insertions(+), 4 deletions(-)
 create mode 100644 gdb/varobj-iter-avail.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 1da4055..88c8f68 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -831,7 +831,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	ui-out.c utils.c ui-file.h ui-file.c \
 	user-regs.c \
 	valarith.c valops.c valprint.c value.c varobj.c common/vec.c \
-	xml-tdesc.c xml-support.c \
+	varobj-iter-avail.c xml-tdesc.c xml-support.c \
 	inferior.c gdb_usleep.c \
 	record.c record-full.c gcore.c \
 	jit.c \
@@ -995,7 +995,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \
 	ada-tasks.o ada-varobj.o c-varobj.o \
 	ui-out.o cli-out.o \
-	varobj.o vec.o \
+	varobj.o varobj-iter-avail.o vec.o \
 	go-lang.o go-valprint.o go-typeprint.o \
 	jv-lang.o jv-valprint.o jv-typeprint.o jv-varobj.o \
 	m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o \
diff --git a/gdb/varobj-iter-avail.c b/gdb/varobj-iter-avail.c
new file mode 100644
index 0000000..59d526a
--- /dev/null
+++ b/gdb/varobj-iter-avail.c
@@ -0,0 +1,162 @@
+/* Copyright (C) 2013-2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "gdb_assert.h"
+#include "value.h"
+#include "valprint.h"
+#include "varobj.h"
+#include "varobj-iter.h"
+
+/* A dynamic varobj iterator "class" for available-children-only
+   varobjs.  This inherits struct varobj_iter.  */
+
+struct avail_varobj_iter
+{
+  /* The 'base class'.  */
+  struct varobj_iter base;
+
+  /* Varobj operations related to language.  */
+  const struct lang_varobj_ops *lang_ops;
+};
+
+/* Returns true if VAL is not interesting for an
+   available-children-only varobj.  */
+
+static int
+varobj_value_unavailable (struct value *val)
+{
+  volatile struct gdb_exception e;
+  int unavail = 0;
+
+  gdb_assert (val != NULL);
+
+  /* value_entirely_unavailable may need to try reading the value,
+     which may throw for example, a memory error, e.g., when not
+     inspecting a traceframe, we try to read the pointee of a dangling
+     or NULL pointer.  */
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      struct type *type = value_type (val);
+
+      unavail = (value_entirely_unavailable (val)
+		 /* A scalar object that does not have all bits available
+		    is also considered unavailable, because all bits
+		    contribute to its representation.  */
+		 || (val_print_scalar_type_p (type)
+		     && !value_bytes_available (val,
+						value_embedded_offset (val),
+						TYPE_LENGTH (type))));
+    }
+  if (e.reason < 0)
+    return 1;
+  else
+    return unavail;
+}
+
+/* Implementation of the `next' method for available-children-only
+   varobj iterators.  */
+
+static varobj_item *
+avail_varobj_iter_next (struct varobj_iter *self)
+{
+  struct avail_varobj_iter *dis = (struct avail_varobj_iter *) self;
+  int num_children = dis->lang_ops->number_of_children (self->var);
+  int raw_index = self->next_raw_index;
+  varobj_item *item = NULL;
+
+  for (; raw_index < num_children; raw_index++)
+    {
+      struct value *child_value
+	= dis->lang_ops->value_of_child (self->var, raw_index);
+
+      /* The "fake" children will have NULL values.  */
+      if (child_value == NULL || !varobj_value_unavailable (child_value))
+	{
+	  item = xmalloc (sizeof *item);
+
+	  item->name
+	    = dis->lang_ops->name_of_child (self->var, raw_index);
+	  item->value = child_value;
+
+	  raw_index++;
+	  self->next_raw_index = raw_index;
+	  break;
+	}
+    }
+  return item;
+}
+
+/* Implementation of the `dtor' method of available-children-only
+   varobj iterators.  */
+
+static void
+avail_varobj_iter_dtor (struct varobj_iter *self)
+{
+  /* nothing to do */
+}
+
+/* The 'vtable' of available-children-only varobj iterators.  */
+
+static const struct varobj_iter_ops avail_varobj_iter_ops =
+{
+  avail_varobj_iter_dtor,
+  avail_varobj_iter_next
+};
+
+/* Constructor of available-children-only varobj iterators.  VAR is
+   the varobj whose children the iterator will be iterating over.  */
+
+static void
+avail_varobj_iter_ctor (struct avail_varobj_iter *self, struct varobj *var,
+			const struct lang_varobj_ops *lang_ops)
+{
+  self->base.var = var;
+  self->base.ops = &avail_varobj_iter_ops;
+  self->base.next_raw_index = 0;
+  self->lang_ops = lang_ops;
+}
+
+/* Allocate and construct an available-children-only varobj iterator.
+   VAR is the varobj whose children the iterator will be iterating
+   over.  */
+
+static struct avail_varobj_iter *
+avail_varobj_iter_new (struct varobj *var, const struct lang_varobj_ops *lang_ops)
+{
+  struct avail_varobj_iter *self;
+
+  self = XNEW (struct avail_varobj_iter);
+  avail_varobj_iter_ctor (self, var, lang_ops);
+  return self;
+}
+
+/* Return a new available-children-only varobj iterator suitable to
+   iterate over VAR's children.  */
+
+struct varobj_iter *
+avail_varobj_get_iterator (struct varobj *var,
+			   const struct lang_varobj_ops *lang_ops)
+{
+  struct avail_varobj_iter *iter;
+
+  /* Avoid the needless allocation/deallocation of the iterator if
+     there are no raw children to iterate over anyway.  */
+  if (lang_ops->number_of_children (var) == 0)
+    return NULL;
+
+  iter = avail_varobj_iter_new (var, lang_ops);
+  return &iter->base;
+}
diff --git a/gdb/varobj-iter.h b/gdb/varobj-iter.h
index 9eb672d..ef95a9b 100644
--- a/gdb/varobj-iter.h
+++ b/gdb/varobj-iter.h
@@ -70,3 +70,7 @@ struct varobj_iter_ops
 	  xfree (ITER);		       \
 	}				       \
     } while (0)
+
+struct varobj_iter *
+  avail_varobj_get_iterator (struct varobj *var,
+			     const struct lang_varobj_ops *lang_ops);
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 61309b2..bfa6b1d 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -768,8 +768,11 @@ dynamic_varobj_has_child_method (struct varobj *var)
    iterator object suitable for iterating over VAR's children.  */
 
 static struct varobj_iter *
-varobj_get_iterator (struct varobj *var)
+varobj_get_iterator (struct varobj *var, const struct lang_varobj_ops *lang_ops)
 {
+  if (var->dynamic->available_children_only)
+    return avail_varobj_get_iterator (var, lang_ops);
+
 #if HAVE_PYTHON
   if (var->dynamic->pretty_printer)
     return py_varobj_get_iterator (var, var->dynamic->pretty_printer);
@@ -810,7 +813,8 @@ update_dynamic_varobj_children (struct varobj *var,
   if (update_children || var->dynamic->child_iter == NULL)
     {
       varobj_iter_delete (var->dynamic->child_iter);
-      var->dynamic->child_iter = varobj_get_iterator (var);
+      var->dynamic->child_iter = varobj_get_iterator (var,
+						      var->root->lang_ops);
 
       varobj_clear_saved_item (var->dynamic);
 
-- 
1.7.7.6


  parent reply	other threads:[~2014-02-14  8:46 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14  8:46 [RFC 00/12 V2] Visit varobj available children only in MI Yao Qi
2014-02-14  8:46 ` [PATCH 11/12] Test case Yao Qi
2014-04-18 11:45   ` Yao Qi
2014-04-24 20:53     ` Keith Seitz
2014-02-14  8:46 ` Yao Qi [this message]
2014-04-24 20:28   ` [PATCH 08/12] Iterator varobj_items by their availability Keith Seitz
2014-02-14  8:46 ` [PATCH 07/12] MI option --available-children-only Yao Qi
2014-04-24 20:02   ` Keith Seitz
2014-02-14  8:46 ` [PATCH 01/12] Use 'struct varobj_item' to represent name and value pair Yao Qi
2014-04-23 18:16   ` Keith Seitz
2014-05-21 17:53   ` Tom Tromey
2014-02-14  8:46 ` [PATCH 05/12] Rename varobj_pretty_printed_p to varobj_is_dynamic_p Yao Qi
2014-04-24 17:39   ` Keith Seitz
2014-05-21 18:02   ` Tom Tromey
2014-02-14  8:46 ` [PATCH 02/12] Generalize varobj iterator Yao Qi
2014-04-23 19:24   ` Keith Seitz
2014-05-21 17:51   ` Tom Tromey
2014-05-23  1:23     ` Yao Qi
2014-06-04 20:21       ` Tom Tromey
2014-06-05  5:36         ` Yao Qi
2014-06-05 18:21           ` Tom Tromey
2014-02-14  8:46 ` [PATCH 03/12] Iterate over 'struct varobj_item' instead of PyObject Yao Qi
2014-04-23 19:29   ` Keith Seitz
2014-05-21 18:01   ` Tom Tromey
2014-05-23  1:33     ` Yao Qi
2014-06-04 20:22       ` Tom Tromey
2014-02-14  8:46 ` [PATCH 12/12] NEWS and Doc on --available-children-only Yao Qi
2014-02-14  9:40   ` Eli Zaretskii
2014-02-17  9:46     ` Yao Qi
2014-02-17 15:04       ` Eli Zaretskii
2014-02-18  2:01         ` Yao Qi
2014-02-18  5:11           ` Eli Zaretskii
2014-02-18  7:14             ` Yao Qi
2014-02-18 15:07               ` Eli Zaretskii
2014-02-14  8:46 ` [PATCH 09/12] Delete varobj's children on traceframe is changed Yao Qi
2014-04-24 20:45   ` Keith Seitz
2014-02-14  8:46 ` [PATCH 10/12] Match dynamic="1" in the output of -var-list-children Yao Qi
2014-04-24 20:50   ` Keith Seitz
2014-02-14  8:46 ` [PATCH 04/12] Remove #if HAVE_PYTHON Yao Qi
2014-04-23 19:25   ` Keith Seitz
2014-05-21 17:52   ` Tom Tromey
2014-02-14  8:46 ` [PATCH 06/12] Use varobj_is_dynamic_p more widely Yao Qi
2014-04-24 18:17   ` Keith Seitz
2014-05-21 18:04   ` Tom Tromey
     [not found] ` <5327A296.3050605@codesourcery.com>
2014-04-04  2:00   ` [RFC 00/12 V2] Visit varobj available children only in MI Yao Qi
2014-04-17  1:12     ` ping : " Yao Qi
2014-04-21 16:20       ` Joel Brobecker
2014-04-22  2:54         ` Yao Qi
2014-06-12  7:37 ` 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=1392367471-13527-9-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