From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 7A51A3857C53 for ; Mon, 6 Jul 2020 13:38:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7A51A3857C53 X-ASG-Debug-ID: 1594042720-0c856e4374aa4a0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id xJMNwzyEtoMECNmD (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 06 Jul 2020 09:38:40 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) by smtp.ebox.ca (Postfix) with ESMTP id A8E58441D64; Mon, 6 Jul 2020 09:38:40 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 173-246-6-90.qc.cable.ebox.net[173.246.6.90] X-Barracuda-Apparent-Source-IP: 173.246.6.90 X-Barracuda-RBL-IP: 173.246.6.90 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 03/12] gdb: make get_discrete_bounds check for non-constant range bounds Date: Mon, 6 Jul 2020 09:38:24 -0400 X-ASG-Orig-Subj: [PATCH 03/12] gdb: make get_discrete_bounds check for non-constant range bounds Message-Id: <20200706133833.145408-4-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200706133833.145408-1-simon.marchi@polymtl.ca> References: <20200706133833.145408-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1594042720 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4883 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.83013 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jul 2020 13:38:42 -0000 From: Simon Marchi The next patch adds getters to the `dynamic_prop` structure. These getters validate that the accessed data matches the property kind (for example, to access the `const_val` field, the property must be of kind `PROP_CONST`). It found one instance where we are accessing the `const_val` data of a property that has the undefined kind. This happens in function `get_discrete_bounds`, and is exposed by test gdb.base/ptype.exp, amongst others. Without this patch, we would get: $ ./gdb -q -nx --data-directory=data-directory testsuite/outputs/gdb.base/ptype/ptype -ex "ptype t_char_array" Reading symbols from testsuite/outputs/gdb.base/ptype/ptype... type = char [ /home/smarchi/src/binutils-gdb/gdb/gdbtypes.h:526: internal-error: LONGEST dynamic_prop::const_val() const: Assertion `m_kind == PROP_CONST' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) The `get_discrete_bounds` function returns the bounds of a type (not only range types). For range types, it naturally uses the bound properties that are intrinsic to the range type. It accesses these properties using TYPE_LOW_BOUND and TYPE_HIGH_BOUND, which assume the properties are defined and have constant values. This is sometimes not the case, and the passed range type (as in the example above) has an undefined high/upper bound. Given its current interface (returning two LONGEST values for low and high), `get_discrete_bounds` can't really work if the range type's bounds are not both defined and both constant values. This patch changes the function to return -1 (failure to get the bounds) if any of the range type's bounds is not a constant value. It is sufficient to fix the issue and it seems to keep the callers happy, at least according to the testsuite. A bit in `get_array_bounds` could be removed, since `get_discrete_bounds` no longer returns 1 if a bound is undefined. gdb/ChangeLog: * gdbtypes.c (get_discrete_bounds): Return failure if the range type's bounds are not both defined and constant values. (get_array_bounds): Update comment. Remove undefined bound check. Change-Id: I047a3beee2c1e275f888cfc4778228339922bde9 --- gdb/gdbtypes.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 957307ec6120..40165563b91a 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1028,8 +1028,11 @@ has_static_range (const struct range_bounds *bounds) /* 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. */ + TYPE. + + Return 1 if type is a range type with two defined, constant bounds. + Else, return 0 if it is discrete (and bounds will fit in LONGEST). + Else, return -1. */ int get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) @@ -1038,8 +1041,15 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) switch (type->code ()) { case TYPE_CODE_RANGE: + /* This function currently only works for ranges with two defined, + constant bounds. */ + if (type->bounds ()->low.kind () != PROP_CONST + || type->bounds ()->high.kind () != PROP_CONST) + return -1; + *lowp = TYPE_LOW_BOUND (type); *highp = TYPE_HIGH_BOUND (type); + if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ENUM) { if (!discrete_position (TYPE_TARGET_TYPE (type), *lowp, lowp) @@ -1107,14 +1117,7 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) Save the high bound into HIGH_BOUND if not NULL. Return 1 if the operation was successful. Return zero otherwise, - in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. - - We now simply use get_discrete_bounds call to get the values - of the low and high bounds. - get_discrete_bounds can return three values: - 1, meaning that index is a range, - 0, meaning that index is a discrete type, - or -1 for failure. */ + in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. */ int get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound) @@ -1131,12 +1134,6 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound) if (res == -1) return 0; - /* Check if the array bounds are undefined. */ - if (res == 1 - && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type)) - || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)))) - return 0; - if (low_bound) *low_bound = low; -- 2.27.0