From patchwork Mon Mar 2 07:37:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keven Boell X-Patchwork-Id: 5385 Received: (qmail 16180 invoked by alias); 2 Mar 2015 07:37:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 16162 invoked by uid 89); 2 Mar 2015 07:37:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Mar 2015 07:37:48 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 01 Mar 2015 23:37:46 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 01 Mar 2015 23:37:51 -0800 Received: from ullecvh004g04.iul.intel.com (ullecvh004g04.iul.intel.com [172.28.50.14]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t227bijO019716; Mon, 2 Mar 2015 07:37:44 GMT Received: from ullecvh004g04.iul.intel.com (ullecvh004g04.iul.intel.com [127.0.0.1]) by ullecvh004g04.iul.intel.com (8.13.8/8.13.8) with ESMTP id t227buGb020334; Mon, 2 Mar 2015 08:37:56 +0100 Received: (from kboell@localhost) by ullecvh004g04.iul.intel.com (8.13.8/8.13.8/Submit) id t227buVK020333; Mon, 2 Mar 2015 08:37:56 +0100 From: Keven Boell To: gdb-patches@sourceware.org Cc: Keven Boell Subject: [PATCH] Introduce linked list for dynamic attributes Date: Mon, 2 Mar 2015 08:37:56 +0100 Message-Id: <1425281876-20302-1-git-send-email-keven.boell@intel.com> This patch introduces a linked list for dynamic attributes of a type. This is a pre-work for the Fortran dynamic array support. The Fortran dynamic array support will add more dynamic attributes to a type. As only a few types will have such dynamic attributes set, a linked list is more efficient in terms of memory consumption than adding multiple attributes to main_type. Transformed the data_location dynamic attribute to use the linked list. 2015-02-23 Keven Boell * gdbtypes.c (resolve_dynamic_type_internal): Adapted data_location usage to linked list. (resolve_dynamic_type_internal): Adapted data_location usage to linked list. (get_dyn_attr): New function. (add_dyn_attr): New function. (copy_type_recursive): Add copy of linked list. (copy_type): Add copy of linked list. * gdbtypes.h (enum dynamic_prop_kind): Kind of the dynamic attribute in linked list. (struct dynamic_prop_list): Dynamic list node. * dwarf2read.c (set_die_type): Add data_location data to linked list using helper functions. --- gdb/dwarf2read.c | 4 +- gdb/gdbtypes.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++------- gdb/gdbtypes.h | 47 ++++++++++++++++++--- 3 files changed, 148 insertions(+), 23 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ac78165..9923758 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -22077,9 +22077,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_data_location, cu); if (attr_to_dynamic_prop (attr, die, cu, &prop)) { - TYPE_DATA_LOCATION (type) - = obstack_alloc (&objfile->objfile_obstack, sizeof (prop)); - *TYPE_DATA_LOCATION (type) = prop; + add_dyn_attr (type, objfile, prop, DYN_ATTR_DATA_LOCATION); } if (dwarf2_per_objfile->die_type_hash == NULL) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index a80151c..65a6897 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2021,7 +2021,7 @@ resolve_dynamic_type_internal (struct type *type, { struct type *real_type = check_typedef (type); struct type *resolved_type = type; - const struct dynamic_prop *prop; + struct dynamic_prop *prop; CORE_ADDR value; if (!is_dynamic_type_internal (real_type, top_level)) @@ -2078,11 +2078,11 @@ resolve_dynamic_type_internal (struct type *type, prop = TYPE_DATA_LOCATION (resolved_type); if (dwarf2_evaluate_property (prop, addr_stack, &value)) { - TYPE_DATA_LOCATION_ADDR (resolved_type) = value; - TYPE_DATA_LOCATION_KIND (resolved_type) = PROP_CONST; + TYPE_DYN_ATTR_ADDR (prop) = value; + TYPE_DYN_ATTR_KIND (prop) = PROP_CONST; } else - TYPE_DATA_LOCATION (resolved_type) = NULL; + prop = NULL; return resolved_type; } @@ -2097,6 +2097,48 @@ resolve_dynamic_type (struct type *type, CORE_ADDR addr) return resolve_dynamic_type_internal (type, &pinfo, 1); } +/* See gdbtypes.h */ + +struct dynamic_prop * get_dyn_attr (const struct type * type, + enum dynamic_prop_kind kind) +{ + struct dynamic_prop_list * head = + (TYPE_MAIN_TYPE (type))->dyn_attribs; + + while (head != NULL) + { + if (head->kind == kind) + return head->prop; + head = head->next; + } + return NULL; +} + +/* See gdbtypes.h */ + +void add_dyn_attr (struct type * type, struct objfile *objfile, + struct dynamic_prop prop, enum dynamic_prop_kind kind) +{ + struct dynamic_prop_list * temp + = obstack_alloc (&objfile->objfile_obstack, + sizeof (struct dynamic_prop_list)); + temp->prop = obstack_alloc (&objfile->objfile_obstack, sizeof (prop)); + *temp->prop = prop; + temp->kind = kind; + + if (TYPE_MAIN_TYPE (type)->dyn_attribs == NULL) + { + TYPE_MAIN_TYPE (type)->dyn_attribs = temp; + temp->next = NULL; + } + else + { + temp->next = TYPE_MAIN_TYPE (type)->dyn_attribs; + TYPE_MAIN_TYPE (type)->dyn_attribs = temp; + } +} + + /* Find the real type of TYPE. This function returns the real type, after removing all layers of typedefs, and completing opaque or stub types. Completion changes the TYPE argument, but stripping of @@ -4321,15 +4363,39 @@ copy_type_recursive (struct objfile *objfile, *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type); } - /* Copy the data location information. */ - if (TYPE_DATA_LOCATION (type) != NULL) + if (TYPE_DYN_ATTRIBS (type) != NULL) { - TYPE_DATA_LOCATION (new_type) - = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop)); - memcpy (TYPE_DATA_LOCATION (new_type), TYPE_DATA_LOCATION (type), - sizeof (struct dynamic_prop)); + struct dynamic_prop_list * p; + struct dynamic_prop_list * trav = TYPE_DYN_ATTRIBS (type); + + /* Copy head. */ + struct dynamic_prop_list * new_head = + TYPE_ALLOC (new_type, sizeof (struct dynamic_prop_list)); + memcpy (new_head, TYPE_DYN_ATTRIBS (type), + sizeof (struct dynamic_prop_list)); + new_head->prop = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop)); + memcpy (new_head->prop, TYPE_DYN_ATTRIBS (type)->prop, + sizeof (struct dynamic_prop)); + + /* Rest of list. */ + p = new_head; + trav = trav->next; + while (trav != NULL) + { + p->next = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop_list)); + memcpy (p->next, trav, + sizeof (struct dynamic_prop_list)); + p = p->next; + p->prop = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop)); + memcpy (p->prop, trav->prop, sizeof (struct dynamic_prop)); + trav = trav->next; + } + p->next = NULL; + + TYPE_DYN_ATTRIBS (new_type) = new_head; } + /* Copy pointers to other types. */ if (TYPE_TARGET_TYPE (type)) TYPE_TARGET_TYPE (new_type) = @@ -4392,12 +4458,36 @@ copy_type (const struct type *type) TYPE_LENGTH (new_type) = TYPE_LENGTH (type); memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type), sizeof (struct main_type)); - if (TYPE_DATA_LOCATION (type) != NULL) + if (TYPE_DYN_ATTRIBS (type) != NULL) { - TYPE_DATA_LOCATION (new_type) - = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop)); - memcpy (TYPE_DATA_LOCATION (new_type), TYPE_DATA_LOCATION (type), - sizeof (struct dynamic_prop)); + struct dynamic_prop_list * p; + struct dynamic_prop_list * trav = TYPE_DYN_ATTRIBS (type); + + /* Copy head. */ + struct dynamic_prop_list * new_head = + TYPE_ALLOC (new_type, sizeof (struct dynamic_prop_list)); + memcpy (new_head, TYPE_DYN_ATTRIBS (type), + sizeof (struct dynamic_prop_list)); + new_head->prop = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop)); + memcpy (new_head->prop, TYPE_DYN_ATTRIBS (type)->prop, + sizeof (struct dynamic_prop)); + + /* Rest of list. */ + p = new_head; + trav = trav->next; + while (trav != NULL) + { + p->next = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop_list)); + memcpy (p->next, trav, + sizeof (struct dynamic_prop_list)); + p = p->next; + p->prop = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop)); + memcpy (p->prop, trav->prop, sizeof (struct dynamic_prop)); + trav = trav->next; + } + p->next = NULL; + + TYPE_DYN_ATTRIBS (new_type) = new_head; } return new_type; diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index ef6d92c..ab3e2cc 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -430,6 +430,25 @@ struct dynamic_prop } data; }; +/* * Defines the kind of a dynamic attribute of a type. The dynamic attributes + can be the following: + + * DYN_ATTR_DATA_LOCATION: + Contains a location description value for the current type. + Evaluating this field yields to the location of the data for an object. +*/ +enum dynamic_prop_kind +{ + DYN_ATTR_DATA_LOCATION +}; + +/* * List for dynamic type attributes. */ +struct dynamic_prop_list +{ + enum dynamic_prop_kind kind; + struct dynamic_prop *prop; + struct dynamic_prop_list *next; +}; /* * Determine which field of the union main_type.fields[x].loc is used. */ @@ -704,10 +723,8 @@ struct main_type struct type *self_type; } type_specific; - /* * Contains a location description value for the current type. Evaluating - this field yields to the location of the data for an object. */ - - struct dynamic_prop *data_location; + /* * Contains all dynamic type attributes. */ + struct dynamic_prop_list *dyn_attribs; }; /* * A ``struct type'' describes a particular instance of a type, with @@ -1221,7 +1238,7 @@ extern void allocate_gnat_aux_type (struct type *); /* Attribute accessors for the type data location. */ #define TYPE_DATA_LOCATION(thistype) \ - TYPE_MAIN_TYPE(thistype)->data_location + get_dyn_attr (thistype, DYN_ATTR_DATA_LOCATION) #define TYPE_DATA_LOCATION_BATON(thistype) \ TYPE_DATA_LOCATION (thistype)->data.baton #define TYPE_DATA_LOCATION_ADDR(thistype) \ @@ -1229,6 +1246,17 @@ extern void allocate_gnat_aux_type (struct type *); #define TYPE_DATA_LOCATION_KIND(thistype) \ TYPE_DATA_LOCATION (thistype)->kind + /* Attribute accessors for dynamic attributes. */ +#define TYPE_DYN_ATTRIBS(thistype) \ + TYPE_MAIN_TYPE(thistype)->dyn_attribs +#define TYPE_DYN_ATTR_BATON(dynprop) \ + dynprop->data.baton +#define TYPE_DYN_ATTR_ADDR(dynprop) \ + dynprop->data.const_val +#define TYPE_DYN_ATTR_KIND(dynprop) \ + dynprop->kind + + /* Moto-specific stuff for FORTRAN arrays. */ #define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \ @@ -1748,6 +1776,15 @@ extern struct type *resolve_dynamic_type (struct type *type, CORE_ADDR addr); /* * Predicate if the type has dynamic values, which are not resolved yet. */ extern int is_dynamic_type (struct type *type); +/* * Fetches a dynamic attribute of a type out of the dynamic attribute + list. */ +extern struct dynamic_prop * get_dyn_attr + (const struct type * type, enum dynamic_prop_kind kind); + +/* * Adds a dynamic attribute to a type. */ +extern void add_dyn_attr (struct type * type, struct objfile *objfile, + struct dynamic_prop prop, enum dynamic_prop_kind kind); + extern struct type *check_typedef (struct type *); #define CHECK_TYPEDEF(TYPE) \