From patchwork Mon Aug 18 17:38:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 2421 Received: (qmail 17560 invoked by alias); 18 Aug 2014 17:38:50 -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 17451 invoked by uid 89); 18 Aug 2014 17:38:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 18 Aug 2014 17:38:46 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 975CF1162C5 for ; Mon, 18 Aug 2014 13:38:44 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IgYI+zYyQyHN for ; Mon, 18 Aug 2014 13:38:44 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 697FB1162A9 for ; Mon, 18 Aug 2014 13:38:44 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 5D463410E6; Mon, 18 Aug 2014 19:38:43 +0200 (CEST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed 2/4] Add support for DW_AT_data_location. Date: Mon, 18 Aug 2014 19:38:35 +0200 Message-Id: <1408383517-29205-3-git-send-email-brobecker@adacore.com> In-Reply-To: <1408383517-29205-1-git-send-email-brobecker@adacore.com> References: <1408383517-29205-1-git-send-email-brobecker@adacore.com> gdb/ChangeLog: * gdbtypes.h (struct main_type): Add field "data_location". (TYPE_DATA_LOCATION, TYPE_DATA_LOCATION_BATON) (TYPE_DATA_LOCATION_ADDR, TYPE_DATA_LOCATION_KIND): New macros. * gdbtypes.c (is_dynamic_type): Return 1 if the type has a dynamic data location. (resolve_dynamic_type): Add DW_AT_data_location handling. (copy_recursive, copy_type): Copy the data_location information when present. * dwarf2read.c (set_die_type): Add DW_AT_data_location handling. * value.c (value_from_contents_and_address): Add DW_AT_data_location handling. --- gdb/ChangeLog | 15 +++++++++++++++ gdb/dwarf2read.c | 11 +++++++++++ gdb/gdbtypes.c | 39 +++++++++++++++++++++++++++++++++++++++ gdb/gdbtypes.h | 15 +++++++++++++++ gdb/value.c | 3 +++ 5 files changed, 83 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 607a5c3..1d35ac3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,6 +1,21 @@ 2014-08-18 Keven Boell Joel Brobecker + * gdbtypes.h (struct main_type): Add field "data_location". + (TYPE_DATA_LOCATION, TYPE_DATA_LOCATION_BATON) + (TYPE_DATA_LOCATION_ADDR, TYPE_DATA_LOCATION_KIND): New macros. + * gdbtypes.c (is_dynamic_type): Return 1 if the type has + a dynamic data location. + (resolve_dynamic_type): Add DW_AT_data_location handling. + (copy_recursive, copy_type): Copy the data_location information + when present. + * dwarf2read.c (set_die_type): Add DW_AT_data_location handling. + * value.c (value_from_contents_and_address): Add + DW_AT_data_location handling. + +2014-08-18 Keven Boell + Joel Brobecker + * dwarf2expr.h (struct dwarf_expr_context_funcs): Uncomment field "get_object_address". * dwarf2expr.c (execute_stack_op): Add handling for diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 801f05d..11580cc 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -21669,6 +21669,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) { struct dwarf2_per_cu_offset_and_type **slot, ofs; struct objfile *objfile = cu->objfile; + struct attribute *attr; + struct dynamic_prop prop; /* For Ada types, make sure that the gnat-specific data is always initialized (if not already set). There are a few types where @@ -21683,6 +21685,15 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) && !HAVE_GNAT_AUX_INFO (type)) INIT_GNAT_SPECIFIC (type); + /* Read DW_AT_data_location and set in type. */ + 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; + } + if (dwarf2_per_objfile->die_type_hash == NULL) { dwarf2_per_objfile->die_type_hash = diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 0e18304..1326f85 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1620,6 +1620,17 @@ is_dynamic_type_internal (struct type *type, int top_level) if (top_level && TYPE_CODE (type) == TYPE_CODE_REF) type = check_typedef (TYPE_TARGET_TYPE (type)); + /* Types that have a dynamic TYPE_DATA_LOCATION are considered + dynamic, even if the type itself is statically defined. + From a user's point of view, this may appear counter-intuitive; + but it makes sense in this context, because the point is to determine + whether any part of the type needs to be resolved before it can + be exploited. */ + if (TYPE_DATA_LOCATION (type) != NULL + && (TYPE_DATA_LOCATION_KIND (type) == PROP_LOCEXPR + || TYPE_DATA_LOCATION_KIND (type) == PROP_LOCLIST)) + return 1; + switch (TYPE_CODE (type)) { case TYPE_CODE_RANGE: @@ -1852,6 +1863,8 @@ resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr, { struct type *real_type = check_typedef (type); struct type *resolved_type = type; + const struct dynamic_prop *prop; + CORE_ADDR value; if (!is_dynamic_type_internal (real_type, top_level)) return type; @@ -1893,6 +1906,16 @@ resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr, break; } + /* Resolve data_location attribute. */ + prop = TYPE_DATA_LOCATION (resolved_type); + if (dwarf2_evaluate_property (prop, addr, &value)) + { + TYPE_DATA_LOCATION_ADDR (resolved_type) = value; + TYPE_DATA_LOCATION_KIND (resolved_type) = PROP_CONST; + } + else + TYPE_DATA_LOCATION (resolved_type) = NULL; + return resolved_type; } @@ -4110,6 +4133,15 @@ 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) + { + 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)); + } + /* Copy pointers to other types. */ if (TYPE_TARGET_TYPE (type)) TYPE_TARGET_TYPE (new_type) = @@ -4155,6 +4187,13 @@ 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) + { + 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)); + } return new_type; } diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 5008ef4..bd1a0ab 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -724,6 +724,11 @@ struct main_type struct func_type *func_stuff; } 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; }; /* * A ``struct type'' describes a particular instance of a type, with @@ -1203,6 +1208,16 @@ extern void allocate_gnat_aux_type (struct type *); #define TYPE_LOW_BOUND_KIND(range_type) \ TYPE_RANGE_DATA(range_type)->low.kind +/* Attribute accessors for the type data location. */ +#define TYPE_DATA_LOCATION(thistype) \ + TYPE_MAIN_TYPE(thistype)->data_location +#define TYPE_DATA_LOCATION_BATON(thistype) \ + TYPE_DATA_LOCATION (thistype)->data.baton +#define TYPE_DATA_LOCATION_ADDR(thistype) \ + TYPE_DATA_LOCATION (thistype)->data.const_val +#define TYPE_DATA_LOCATION_KIND(thistype) \ + TYPE_DATA_LOCATION (thistype)->kind + /* Moto-specific stuff for FORTRAN arrays. */ #define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \ diff --git a/gdb/value.c b/gdb/value.c index 355194e..3d460bd 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -3398,6 +3398,9 @@ value_from_contents_and_address (struct type *type, v = allocate_value_lazy (resolved_type); else v = value_from_contents (resolved_type, valaddr); + if (TYPE_DATA_LOCATION (resolved_type) != NULL + && TYPE_DATA_LOCATION_KIND (resolved_type) == PROP_CONST) + address = TYPE_DATA_LOCATION_ADDR (resolved_type); set_value_address (v, address); VALUE_LVAL (v) = lval_memory; return v;