From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22352 invoked by alias); 24 Nov 2013 02:12:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 22324 invoked by uid 89); 24 Nov 2013 02:12:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_50,RDNS_NONE,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Nov 2013 02:12:02 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VkPB2-0006qd-G2 from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Sat, 23 Nov 2013 18:12:00 -0800 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sat, 23 Nov 2013 18:12:00 -0800 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Sat, 23 Nov 2013 18:11:59 -0800 From: Yao Qi To: Subject: [PATCH 08/11] Iterator varobj_items by their availability Date: Sun, 24 Nov 2013 02:12:00 -0000 Message-ID: <1385258996-26047-9-git-send-email-yao@codesourcery.com> In-Reply-To: <1385258996-26047-1-git-send-email-yao@codesourcery.com> References: <1385258996-26047-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00735.txt.bz2 This patch adds a new implementation of varobj iterator, which is based on the availability of children. gdb: 2013-10-24 Pedro Alves Yao Qi * 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 (dynamic_varobj_has_child_method): (varobj_get_iterator): Add one more argument 'lang_ops' and Caller update. Return iterator for available children. --- gdb/Makefile.in | 4 +- gdb/varobj-iter-avail.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++ gdb/varobj-iter.h | 4 + gdb/varobj.c | 8 ++- 4 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 gdb/varobj-iter-avail.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 7d8a365..6d84def 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -772,7 +772,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 \ @@ -933,7 +933,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..0cd2e23 --- /dev/null +++ b/gdb/varobj-iter-avail.c @@ -0,0 +1,160 @@ +/* Copyright (C) 2013 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 . */ + +#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; + + 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 = xmalloc (sizeof (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/dealocation of the iterator if + there are no raw children to iterator 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 b4bda82..c466225 100644 --- a/gdb/varobj-iter.h +++ b/gdb/varobj-iter.h @@ -68,3 +68,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 1fd9fd2..ba93eb5 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -768,8 +768,11 @@ dynamic_varobj_has_child_method (struct varobj *var) 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