From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sO+VJIvhu19ETgAAWB0awg (envelope-from ) for ; Mon, 23 Nov 2020 11:21:31 -0500 Received: by simark.ca (Postfix, from userid 112) id 8EC0F1F0AB; Mon, 23 Nov 2020 11:21:31 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 12AB31F0A9 for ; Mon, 23 Nov 2020 11:21:29 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D86D238708E5; Mon, 23 Nov 2020 16:21:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D86D238708E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606148487; bh=JM6EOR2O7qFtQudx1/qxcouR32/5c75RwmEXV2P+fUk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=igLjHSo8QuT+rMZfMptKqJ1yDzqbRnCbZDLl4wt2v8jzck6b+IuT4PdARC0KvoU2D Sd4ICHNimKRKI47cj5SoA6oVVZt22l4qTbNvWAmFCoOtWsCeRYhQ2zv9RrH2J/Y4PH zcEvt0aGHzRzKQxbwX++1DapIlwATb4QfwRLSCQo= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 1745138708C4 for ; Mon, 23 Nov 2020 16:21:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1745138708C4 X-ASG-Debug-ID: 1606148481-0c856e6cd61cb1f0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id fMcuvTiuc6sivOjK (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 23 Nov 2020 11:21:21 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id A663D441D66; Mon, 23 Nov 2020 11:21:21 -0500 (EST) X-Barracuda-RBL-IP: 192.222.181.218 X-Barracuda-Effective-Source-IP: 192-222-181-218.qc.cable.ebox.net[192.222.181.218] X-Barracuda-Apparent-Source-IP: 192.222.181.218 To: gdb-patches@sourceware.org Subject: [PATCH 2/4] gdb: make get_discrete_bounds return bool Date: Mon, 23 Nov 2020 11:21:18 -0500 X-ASG-Orig-Subj: [PATCH 2/4] gdb: make get_discrete_bounds return bool Message-Id: <20201123162120.3778679-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123162120.3778679-1-simon.marchi@efficios.com> References: <20201123162120.3778679-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1606148481 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 15219 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.86072 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" get_discrete_bounds currently has three possible return values (see its current doc for details). It appears that for all callers, it would be sufficient to have a boolean "worked" / "didn't work" return value. Change the return type of get_discrete_bounds to bool and adjust all callers. Doing so simplifies the following patch. gdb/ChangeLog: * gdbtypes.h (get_discrete_bounds): Return bool, adjust all callers. * gdbtypes.c (get_discrete_bounds): Return bool. Change-Id: Ie51feee23c75f0cd7939742604282d745db59172 --- gdb/ada-lang.c | 6 ++--- gdb/ada-valprint.c | 2 +- gdb/c-lang.c | 4 ++-- gdb/eval.c | 4 ++-- gdb/f-array-walker.h | 4 ++-- gdb/f-lang.c | 2 +- gdb/gdbtypes.c | 53 ++++++++++++++++++++------------------------ gdb/gdbtypes.h | 8 ++++++- gdb/m2-typeprint.c | 4 ++-- gdb/m2-valprint.c | 6 ++--- gdb/p-valprint.c | 3 ++- gdb/valarith.c | 2 +- gdb/valops.c | 4 ++-- 13 files changed, 52 insertions(+), 50 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 9ff470d97a7..ba8dde0e9af 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2114,7 +2114,7 @@ constrained_packed_array_type (struct type *type, long *elt_bits) if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE && is_dynamic_type (check_typedef (index_type))) - || get_discrete_bounds (index_type, &low_bound, &high_bound) < 0) + || !get_discrete_bounds (index_type, &low_bound, &high_bound)) low_bound = high_bound = 0; if (high_bound < low_bound) *elt_bits = TYPE_LENGTH (new_type) = 0; @@ -2184,7 +2184,7 @@ recursively_update_array_bitsize (struct type *type) gdb_assert (type->code () == TYPE_CODE_ARRAY); LONGEST low, high; - if (get_discrete_bounds (type->index_type (), &low, &high) < 0 + if (!get_discrete_bounds (type->index_type (), &low, &high) || low > high) return 0; LONGEST our_len = high - low + 1; @@ -2301,7 +2301,7 @@ value_subscript_packed (struct value *arr, int arity, struct value **ind) LONGEST lowerbound, upperbound; LONGEST idx; - if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) + if (!get_discrete_bounds (range_type, &lowerbound, &upperbound)) { lim_warning (_("don't know bounds of array")); lowerbound = upperbound = 0; diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 482069a3fb2..09e9458f427 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -136,7 +136,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, { LONGEST high; - if (get_discrete_bounds (index_type, &low, &high) < 0) + if (!get_discrete_bounds (index_type, &low, &high)) len = 1; else if (low > high) { diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 624aea52f77..9d59c1333d4 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -698,8 +698,8 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp, LONGEST low_bound, high_bound; int element_size = TYPE_LENGTH (type); - if (get_discrete_bounds (expect_type->index_type (), - &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (expect_type->index_type (), + &low_bound, &high_bound)) { low_bound = 0; high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1; diff --git a/gdb/eval.c b/gdb/eval.c index 2626ee6d876..6546b7dd5c6 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1423,7 +1423,7 @@ evaluate_subexp_standard (struct type *expect_type, int element_size = TYPE_LENGTH (check_typedef (element_type)); LONGEST low_bound, high_bound, index; - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (range_type, &low_bound, &high_bound)) { low_bound = 0; high_bound = (TYPE_LENGTH (type) / element_size) - 1; @@ -1476,7 +1476,7 @@ evaluate_subexp_standard (struct type *expect_type, || check_type->code () == TYPE_CODE_TYPEDEF) check_type = TYPE_TARGET_TYPE (check_type); - if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (element_type, &low_bound, &high_bound)) error (_("(power)set type with unknown size")); memset (valaddr, '\0', TYPE_LENGTH (type)); for (tem = 0; tem < nargs; tem++) diff --git a/gdb/f-array-walker.h b/gdb/f-array-walker.h index 417f9f07980..c202df6c65f 100644 --- a/gdb/f-array-walker.h +++ b/gdb/f-array-walker.h @@ -42,7 +42,7 @@ class fortran_array_offset_calculator /* Get the range, and extract the bounds. */ struct type *range_type = type->index_type (); - if (get_discrete_bounds (range_type, &m_lowerbound, &m_upperbound) < 0) + if (!get_discrete_bounds (range_type, &m_lowerbound, &m_upperbound)) error ("unable to read array bounds"); /* Figure out the stride for this array. */ @@ -198,7 +198,7 @@ class fortran_array_walker /* Extract the range, and get lower and upper bounds. */ struct type *range_type = check_typedef (type)->index_type (); LONGEST lowerbound, upperbound; - if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) + if (!get_discrete_bounds (range_type, &lowerbound, &upperbound)) error ("failed to get range bounds"); /* CALC is used to calculate the offsets for each element in this diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 4171c96c8a9..99d8b792caf 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -1423,7 +1423,7 @@ fortran_adjust_dynamic_array_base_address_hack (struct type *type, tmp_type = check_typedef (tmp_type); struct type *range_type = tmp_type->index_type (); LONGEST lowerbound, upperbound, stride; - if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) + if (!get_discrete_bounds (range_type, &lowerbound, &upperbound)) error ("failed to get range bounds"); /* Figure out the stride for this dimension. */ diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 09f33c21e28..b47bd28945d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1036,15 +1036,9 @@ has_static_range (const struct range_bounds *bounds) && bounds->stride.kind () == PROP_CONST); } +/* See gdbtypes.h. */ -/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type - 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 +bool get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) { type = check_typedef (type); @@ -1055,7 +1049,7 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) constant bounds. */ if (type->bounds ()->low.kind () != PROP_CONST || type->bounds ()->high.kind () != PROP_CONST) - return -1; + return false; *lowp = type->bounds ()->low.const_val (); *highp = type->bounds ()->high.const_val (); @@ -1065,20 +1059,17 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) gdb::optional low_pos = discrete_position (TYPE_TARGET_TYPE (type), *lowp); - if (!low_pos.has_value ()) - return 0; - - *lowp = *low_pos; + if (low_pos.has_value ()) + *lowp = *low_pos; gdb::optional high_pos = discrete_position (TYPE_TARGET_TYPE (type), *highp); - if (!high_pos.has_value ()) - return 0; - - *highp = *high_pos; + if (high_pos.has_value ()) + *highp = *high_pos; } - return 1; + return true; + case TYPE_CODE_ENUM: if (type->num_fields () > 0) { @@ -1104,19 +1095,22 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) *lowp = 0; *highp = -1; } - return 0; + return true; + case TYPE_CODE_BOOL: *lowp = 0; *highp = 1; - return 0; + return true; + case TYPE_CODE_INT: if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ - return -1; + return false; + if (!type->is_unsigned ()) { *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); *highp = -*lowp - 1; - return 0; + return true; } /* fall through */ case TYPE_CODE_CHAR: @@ -1126,9 +1120,10 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) if TYPE_LENGTH (type) == sizeof (LONGEST). */ *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); *highp = (*highp - 1) | *highp; - return 0; + return true; + default: - return -1; + return false; } } @@ -1140,13 +1135,11 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound) struct type *index = type->index_type (); LONGEST low = 0; LONGEST high = 0; - int res; if (index == NULL) return false; - res = get_discrete_bounds (index, &low, &high); - if (res == -1) + if (!get_discrete_bounds (index, &low, &high)) return false; if (low_bound) @@ -1223,8 +1216,9 @@ update_static_array_size (struct type *type) if (stride == 0) stride = range_type->bit_stride (); - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (range_type, &low_bound, &high_bound)) low_bound = high_bound = 0; + element_type = check_typedef (TYPE_TARGET_TYPE (type)); /* Be careful when setting the array length. Ada arrays can be empty arrays with the high_bound being smaller than the low_bound. @@ -1420,8 +1414,9 @@ create_set_type (struct type *result_type, struct type *domain_type) { LONGEST low_bound, high_bound, bit_length; - if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (domain_type, &low_bound, &high_bound)) low_bound = high_bound = 0; + bit_length = high_bound - low_bound + 1; TYPE_LENGTH (result_type) = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 59ff6fc6ce3..dd63ab8d876 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2434,7 +2434,13 @@ extern struct type *lookup_template_type (const char *, struct type *, extern int get_vptr_fieldno (struct type *, struct type **); -extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *); +/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type + TYPE. + + Return true if the two bounds are available, false otherwise. */ + +extern bool get_discrete_bounds (struct type *type, LONGEST *lowp, + LONGEST *highp); /* Assuming TYPE is a simple, non-empty array type, compute its upper and lower bound. Save the low bound into LOW_BOUND if not NULL. diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c index 8fbcdf4c603..20a3d131476 100644 --- a/gdb/m2-typeprint.c +++ b/gdb/m2-typeprint.c @@ -372,7 +372,7 @@ m2_is_long_set (struct type *type) This should be integrated into gdbtypes.c inside get_discrete_bounds. */ -static int +static bool m2_get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) { type = check_typedef (type); @@ -419,7 +419,7 @@ m2_is_long_set_of_type (struct type *type, struct type **of_type) l1 = type->field (i).type ()->bounds ()->low.const_val (); h1 = type->field (len - 1).type ()->bounds ()->high.const_val (); *of_type = target; - if (m2_get_discrete_bounds (target, &l2, &h2) >= 0) + if (m2_get_discrete_bounds (target, &l2, &h2)) return (l1 == l2 && h1 == h2); error (_("long_set failed to find discrete bounds for its subtype")); return 0; diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c index 96dc18119cf..542fa492d06 100644 --- a/gdb/m2-valprint.c +++ b/gdb/m2-valprint.c @@ -97,7 +97,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr, target = TYPE_TARGET_TYPE (range); - if (get_discrete_bounds (range, &field_low, &field_high) >= 0) + if (get_discrete_bounds (range, &field_low, &field_high)) { for (i = low_bound; i <= high_bound; i++) { @@ -137,7 +137,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr, if (field == len) break; range = type->field (field).type ()->index_type (); - if (get_discrete_bounds (range, &field_low, &field_high) < 0) + if (!get_discrete_bounds (range, &field_low, &field_high)) break; target = TYPE_TARGET_TYPE (range); } @@ -399,7 +399,7 @@ m2_language::value_print_inner (struct value *val, struct ui_file *stream, fputs_filtered ("{", stream); - i = get_discrete_bounds (range, &low_bound, &high_bound); + i = get_discrete_bounds (range, &low_bound, &high_bound) ? 0 : -1; maybe_bad_bstring: if (i < 0) { diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index 428b2efc656..8f785b71ea4 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -343,7 +343,8 @@ pascal_value_print_inner (struct value *val, struct ui_file *stream, fputs_filtered ("[", stream); - int bound_info = get_discrete_bounds (range, &low_bound, &high_bound); + int bound_info = (get_discrete_bounds (range, &low_bound, &high_bound) + ? 0 : -1); if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) { /* If we know the size of the set type, we can figure out the diff --git a/gdb/valarith.c b/gdb/valarith.c index f4497cd223f..a44d198a1de 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -1942,7 +1942,7 @@ value_bit_index (struct type *type, const gdb_byte *valaddr, int index) unsigned rel_index; struct type *range = type->index_type (); - if (get_discrete_bounds (range, &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (range, &low_bound, &high_bound)) return -2; if (index < low_bound || index > high_bound) return -1; diff --git a/gdb/valops.c b/gdb/valops.c index 0f84a70ceb6..4fc65ea20f5 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -451,7 +451,7 @@ value_cast (struct type *type, struct value *arg2) int val_length = TYPE_LENGTH (type2); LONGEST low_bound, high_bound, new_length; - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) + if (!get_discrete_bounds (range_type, &low_bound, &high_bound)) low_bound = 0, high_bound = 0; new_length = val_length / element_length; if (val_length % element_length != 0) @@ -3946,7 +3946,7 @@ value_slice (struct value *array, int lowbound, int length) error (_("array not associated")); range_type = array_type->index_type (); - if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) + if (!get_discrete_bounds (range_type, &lowerbound, &upperbound)) error (_("slice from bad array or bitstring")); if (lowbound < lowerbound || length < 0 -- 2.29.2