From patchwork Thu Apr 10 12:40:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Agovic, Sanimir" X-Patchwork-Id: 474 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id E071F36008F for ; Thu, 10 Apr 2014 05:43:16 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id 9A00410CD524; Thu, 10 Apr 2014 05:43:11 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 5B1412455977 for ; Thu, 10 Apr 2014 05:43:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=g7xGCHpOoXKdR75VZW37Xaov9P11g2y C9f2R/QlnSc5KoFMpcCfZ+NJUoye3wqlAlBiTVTmf99IhQ/bGLiex/KnadRI96e/ cTtiMjK5f82Rt6spKQtfSkM8JqrCy6bXsgMn55u7GmIYhnDu0IgL0VPIHUWpKXqS NuBTeid2ej3M= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=6JA/52dYVicDngEP5kX6fNZ//dE=; b=GW1Qq DCMURE/IuFh2Yw1YN0hDZqnk7wHf13IhVnHemir4rjtZQr1n+RnVgERpugXRuOlk 4u7/2R0CQv3gum6O2HFzTgqT6UuuwDOsEwRd1dYMKOyJzODhQHFpL1wVgzO2KJ+z Nic+4xGT5SrxsNDiGVgcBDs+0m+0Lk2aeIAs2s= Received: (qmail 25119 invoked by alias); 10 Apr 2014 12:43:09 -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 25103 invoked by uid 89); 10 Apr 2014 12:43:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, 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; Thu, 10 Apr 2014 12:43:07 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 10 Apr 2014 05:43:06 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2014 05:43:04 -0700 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [172.28.50.125]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s3ACgctp009456; Thu, 10 Apr 2014 13:42:43 +0100 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [127.0.0.1]) by ulliclel004.iul.intel.com (8.13.8/8.12.8/MailSET/client) with ESMTP id s3ACfl0O026736; Thu, 10 Apr 2014 14:42:07 +0200 Received: (from sagovic@localhost) by ulliclel004.iul.intel.com (8.13.8/8.13.1/Submit) id s3ACff5Q026735; Thu, 10 Apr 2014 14:41:41 +0200 From: Sanimir Agovic To: brobecker@adacore.com Cc: gdb-patches@sourceware.org, tromey@redhat.com Subject: [PATCH v6 02/15] vla: introduce new bound type abstraction adapt uses Date: Thu, 10 Apr 2014 14:40:04 +0200 Message-Id: <1397133617-26681-3-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1397133617-26681-1-git-send-email-sanimir.agovic@intel.com> References: <1397133617-26681-1-git-send-email-sanimir.agovic@intel.com> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in The rational behind this patch is to get started to implement the feature described in dwarf4 standard (2.19) Static and Dynamic Values of Attributes. It adds new BOUND_PROP to store either a constant, exprloc, or reference to describe an upper-/lower bound of a subrange. Other than that no new features are introduced. 2013-10-18 Sanimir Agovic Keven Boell * dwarf2read.c (read_subrange_type): Use struct bound_prop for declaring high/low bounds and change uses accordingly. Call create_range_type instead of create_static_range_type. * gdbtypes.c (create_range_type): New function. (create_range_type): Convert bounds into struct bound_prop and pass them to create_range_type. * gdbtypes.h (struct bound_prop): New struct. (create_range_type): New function prototype. (struct range_bounds): Use struct bound_prop instead of LONGEST for high/low bounds. Remove low_undefined/high_undefined and adapt all uses. (TYPE_LOW_BOUND,TYPE_HIGH_BOUND): Adapt macros to refer to the static part of the bound. * parse.c (follow_types): Set high bound kind to BOUND_UNDEFINED. Signed-off-by: Sanimir Agovic --- gdb/dwarf2read.c | 43 ++++++++++++++++++++++++------------------ gdb/gdbtypes.c | 50 +++++++++++++++++++++++++++++++++++-------------- gdb/gdbtypes.h | 57 ++++++++++++++++++++++++++++++++++++++++++-------------- gdb/parse.c | 3 ++- 4 files changed, 106 insertions(+), 47 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 4ba25ff..101065b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -14260,7 +14260,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) struct type *base_type, *orig_base_type; struct type *range_type; struct attribute *attr; - LONGEST low, high; + struct dynamic_prop low, high; int low_default_is_valid; const char *name; LONGEST negative_mask; @@ -14277,33 +14277,37 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) if (range_type) return range_type; + low.kind = PROP_CONST; + high.kind = PROP_CONST; + high.data.const_val = 0; + /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow omitting DW_AT_lower_bound. */ switch (cu->language) { case language_c: case language_cplus: - low = 0; + low.data.const_val = 0; low_default_is_valid = 1; break; case language_fortran: - low = 1; + low.data.const_val = 1; low_default_is_valid = 1; break; case language_d: case language_java: case language_objc: - low = 0; + low.data.const_val = 0; low_default_is_valid = (cu->header.version >= 4); break; case language_ada: case language_m2: case language_pascal: - low = 1; + low.data.const_val = 1; low_default_is_valid = (cu->header.version >= 4); break; default: - low = 0; + low.data.const_val = 0; low_default_is_valid = 0; break; } @@ -14313,7 +14317,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) but we don't know how to handle it. */ attr = dwarf2_attr (die, DW_AT_lower_bound, cu); if (attr) - low = dwarf2_get_attr_constant_value (attr, low); + low.data.const_val + = dwarf2_get_attr_constant_value (attr, low.data.const_val); else if (!low_default_is_valid) complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " "- DIE at 0x%x [in module %s]"), @@ -14335,10 +14340,10 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) either; we just represent them as zero-length arrays. Choose an appropriate upper bound given the lower bound we've computed above. */ - high = low - 1; + high.data.const_val = low.data.const_val - 1; } else - high = dwarf2_get_attr_constant_value (attr, 1); + high.data.const_val = dwarf2_get_attr_constant_value (attr, 1); } else { @@ -14346,12 +14351,12 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) if (attr) { int count = dwarf2_get_attr_constant_value (attr, 1); - high = low + count - 1; + high.data.const_val = low.data.const_val + count - 1; } else { /* Unspecified array length. */ - high = low - 1; + high.data.const_val = low.data.const_val - 1; } } @@ -14395,22 +14400,24 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) negative_mask = (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); - if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) - low |= negative_mask; - if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) - high |= negative_mask; + if (low.kind == PROP_CONST + && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask)) + low.data.const_val |= negative_mask; + if (high.kind == PROP_CONST + && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask)) + high.data.const_val |= negative_mask; - range_type = create_static_range_type (NULL, orig_base_type, low, high); + range_type = create_range_type (NULL, orig_base_type, &low, &high); /* Mark arrays with dynamic length at least as an array of unspecified length. GDB could check the boundary but before it gets implemented at least allow accessing the array elements. */ if (attr && attr_form_is_block (attr)) - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; + TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED; /* Ada expects an empty array on no boundary attributes. */ if (attr == NULL && cu->language != language_ada) - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; + TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED; name = dwarf2_name (die, cu); if (name) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 807e18e..7f0269c 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -798,19 +798,13 @@ allocate_stub_method (struct type *type) return mtype; } -/* Create a range type using either a blank type supplied in - RESULT_TYPE, or creating a new type, inheriting the objfile from - INDEX_TYPE. - - Indices will be of type INDEX_TYPE, and will range from LOW_BOUND - to HIGH_BOUND, inclusive. - - FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make - sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ +/* Create a range type with a dynamic range from LOW_BOUND to + HIGH_BOUND, inclusive. See create_range_type for further details. */ struct type * -create_static_range_type (struct type *result_type, struct type *index_type, - LONGEST low_bound, LONGEST high_bound) +create_range_type (struct type *result_type, struct type *index_type, + const struct dynamic_prop *low_bound, + const struct dynamic_prop *high_bound) { if (result_type == NULL) result_type = alloc_type_copy (index_type); @@ -820,17 +814,45 @@ create_static_range_type (struct type *result_type, struct type *index_type, TYPE_TARGET_STUB (result_type) = 1; else TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); + TYPE_RANGE_DATA (result_type) = (struct range_bounds *) TYPE_ZALLOC (result_type, sizeof (struct range_bounds)); - TYPE_LOW_BOUND (result_type) = low_bound; - TYPE_HIGH_BOUND (result_type) = high_bound; + TYPE_RANGE_DATA (result_type)->low = *low_bound; + TYPE_RANGE_DATA (result_type)->high = *high_bound; - if (low_bound >= 0) + if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0) TYPE_UNSIGNED (result_type) = 1; return result_type; } +/* Create a range type using either a blank type supplied in + RESULT_TYPE, or creating a new type, inheriting the objfile from + INDEX_TYPE. + + Indices will be of type INDEX_TYPE, and will range from LOW_BOUND + to HIGH_BOUND, inclusive. + + FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make + sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ + +struct type * +create_static_range_type (struct type *result_type, struct type *index_type, + LONGEST low_bound, LONGEST high_bound) +{ + struct dynamic_prop low, high; + + low.kind = PROP_CONST; + low.data.const_val = low_bound; + + high.kind = PROP_CONST; + high.data.const_val = high_bound; + + result_type = create_range_type (result_type, index_type, &low, &high); + + return result_type; +} + /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. Return 1 if type is a range type, 0 if it is discrete (and bounds will fit in LONGEST), or -1 otherwise. */ diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 0396078..f6e68c5 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -365,6 +365,33 @@ enum type_instance_flag_value #define TYPE_ADDRESS_CLASS_ALL(t) (TYPE_INSTANCE_FLAGS(t) \ & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) +/* Used to store a dynamic property. */ + +struct dynamic_prop +{ + /* Determine which field of the union dynamic_prop.data is used. */ + enum + { + PROP_UNDEFINED, /* Not defined. */ + PROP_CONST, /* Constant. */ + PROP_LOCEXPR, /* Location expression. */ + PROP_LOCLIST /* Location list. */ + } kind; + + /* Storage for dynamic or static value. */ + union data + { + /* Storage for constant property. */ + + LONGEST const_val; + + /* Storage for dynamic property. */ + + void *baton; + } data; +}; + + /* Determine which field of the union main_type.fields[x].loc is used. */ enum field_loc_kind @@ -589,19 +616,11 @@ struct main_type { /* Low bound of range. */ - LONGEST low; + struct dynamic_prop low; /* High bound of range. */ - LONGEST high; - - /* Flags indicating whether the values of low and high are - valid. When true, the respective range value is - undefined. Currently used only for FORTRAN arrays. */ - - char low_undefined; - char high_undefined; - + struct dynamic_prop high; } *bounds; } flds_bnds; @@ -1066,12 +1085,18 @@ extern void allocate_gnat_aux_type (struct type *); #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0) #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds -#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low -#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high +#define TYPE_LOW_BOUND(range_type) \ + TYPE_RANGE_DATA(range_type)->low.data.const_val +#define TYPE_HIGH_BOUND(range_type) \ + TYPE_RANGE_DATA(range_type)->high.data.const_val #define TYPE_LOW_BOUND_UNDEFINED(range_type) \ - TYPE_RANGE_DATA(range_type)->low_undefined + (TYPE_RANGE_DATA(range_type)->low.kind == PROP_UNDEFINED) #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \ - TYPE_RANGE_DATA(range_type)->high_undefined + (TYPE_RANGE_DATA(range_type)->high.kind == PROP_UNDEFINED) +#define TYPE_HIGH_BOUND_KIND(range_type) \ + TYPE_RANGE_DATA(range_type)->high.kind +#define TYPE_LOW_BOUND_KIND(range_type) \ + TYPE_RANGE_DATA(range_type)->low.kind /* Moto-specific stuff for FORTRAN arrays. */ @@ -1529,6 +1554,10 @@ extern struct type *lookup_function_type_with_arguments (struct type *, extern struct type *create_static_range_type (struct type *, struct type *, LONGEST, LONGEST); +extern struct type *create_range_type (struct type *, struct type *, + const struct dynamic_prop *, + const struct dynamic_prop *); + extern struct type *create_array_type (struct type *, struct type *, struct type *); extern struct type *lookup_array_range_type (struct type *, LONGEST, LONGEST); diff --git a/gdb/parse.c b/gdb/parse.c index 4b9ca5d..b1671f3 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -1710,7 +1710,8 @@ follow_types (struct type *follow_type) lookup_array_range_type (follow_type, 0, array_size >= 0 ? array_size - 1 : 0); if (array_size < 0) - TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (follow_type) = 1; + TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (follow_type)) + = PROP_UNDEFINED; break; case tp_function: /* FIXME-type-allocation: need a way to free this type when we are