From patchwork Thu Jan 15 09:59:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 4696 Received: (qmail 23042 invoked by alias); 15 Jan 2015 10:00: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 22917 invoked by uid 89); 15 Jan 2015 10:00:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD 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; Thu, 15 Jan 2015 10:00:04 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 210811162BC for ; Thu, 15 Jan 2015 05:00:03 -0500 (EST) 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 7n647XvyQ7Mx for ; Thu, 15 Jan 2015 05:00:03 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id DA99B11663D for ; Thu, 15 Jan 2015 05:00:01 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 42AB548E8C; Thu, 15 Jan 2015 13:59:59 +0400 (RET) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [PATCH 1/3] gdb/DWARF: dynamic subrange type of dynamic subrange type. Date: Thu, 15 Jan 2015 13:59:54 +0400 Message-Id: <1421315996-22616-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1421315996-22616-1-git-send-email-brobecker@adacore.com> References: <1421315996-22616-1-git-send-email-brobecker@adacore.com> Consider the following code: type Record_Type (N : Integer) is record A : Array_Type (1 .. N); end record; [...] R : Record_Type := Get (10); Trying to print the bounds of the array R.A yielded: (gdb) p r.a'last $4 = cannot find reference address for offset property A slightly different example, but from the same cause: (gdb) ptype r type = record n: integer; a: array (cannot find reference address for offset property Looking at the debugging info, "A" is described as... .uleb128 0x11 # (DIE (0x181) DW_TAG_member) .ascii "a\0" # DW_AT_name .long 0x15d # DW_AT_type [...] ... which is an array... .uleb128 0x12 # (DIE (0x15d) DW_TAG_array_type) .long .LASF18 # DW_AT_name: "foo__record_type__T4b" .long 0x194 # DW_AT_type .long 0x174 # DW_AT_sibling ... whose bounds are described as: .uleb128 0x13 # (DIE (0x16a) DW_TAG_subrange_type) .long 0x174 # DW_AT_type .long 0x153 # DW_AT_upper_bound .byte 0 # end of children of DIE 0x15d We can see above that the range has an implict lower value of 1, and an upper value which is a reference 0x153="n". All Good. But looking at the array's subrange subtype, we see... .uleb128 0x14 # (DIE (0x174) DW_TAG_subrange_type) .long 0x153 # DW_AT_upper_bound .long .LASF19 # DW_AT_name: "foo__record_type__T3b" .long 0x18d # DW_AT_type ... another subrange type whose bounds are exactly described the same way. So we have a subrange of a subrange, both with one bound that's dynamic. What happens in the case above is that GDB's resolution of "R.A" yields a array whose index type has static bounds. However, the subtype of the array's index type was left untouched, so, when taking the subtype of the array's subrange type, we were left with the unresolved subrange type, triggering the error above. gdb/ChangeLog: * gdbtypes.c (is_dynamic_type_internal) : Return nonzero if the type's subtype is dynamic. (resolve_dynamic_range): Also resolve the range's subtype. Tested on x86_64-linux, no regression. I'll push in a few days unless there are comments. Thanks, diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 6d3c084..22b6ce4 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1650,7 +1650,15 @@ is_dynamic_type_internal (struct type *type, int top_level) switch (TYPE_CODE (type)) { case TYPE_CODE_RANGE: - return !has_static_range (TYPE_RANGE_DATA (type)); + { + /* A range type is obviously dynamic if it has at least one + dynamic bound. But also consider the range type to be + dynamic when its subtype is dynamic, even if the bounds + of the range type are static. It allows us to assume that + the subtype of a static range type is also static. */ + return (!has_static_range (TYPE_RANGE_DATA (type)) + || is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0)); + } case TYPE_CODE_ARRAY: { @@ -1698,7 +1706,7 @@ static struct type * resolve_dynamic_range (struct type *dyn_range_type, CORE_ADDR addr) { CORE_ADDR value; - struct type *static_range_type; + struct type *static_range_type, *static_target_type; const struct dynamic_prop *prop; const struct dwarf2_locexpr_baton *baton; struct dynamic_prop low_bound, high_bound; @@ -1733,8 +1741,11 @@ resolve_dynamic_range (struct type *dyn_range_type, CORE_ADDR addr) high_bound.data.const_val = 0; } + static_target_type + = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type), + addr, 0); static_range_type = create_range_type (copy_type (dyn_range_type), - TYPE_TARGET_TYPE (dyn_range_type), + static_target_type, &low_bound, &high_bound); TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1; return static_range_type;