From patchwork Tue Mar 28 15:49:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67026 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14C5D38708A5 for ; Tue, 28 Mar 2023 15:50:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14C5D38708A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018604; bh=RsYSRw+9fCV4P0R4xSROpAkR79efvHcFBXpMga/TUyA=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=P8DH39pAz/lQYssNjiQdT8Ha5gBjsKiZnsUyWm3kJPBaSmlBsvQtbF47IfvVzRIo0 Ny6aZ5rOHBVuYV+ghhizxDlNFiRu8TAVJJ9CoaQoI3VHw8wlCWPFz42llo4W6wWXkl 1Dd4n08WneBVz+LVBhIOrGbk13QTTCSeIvrJHuFg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id DBBC4385B519 for ; Tue, 28 Mar 2023 15:49:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBBC4385B519 Received: by mail-io1-xd2b.google.com with SMTP id bl9so5538794iob.8 for ; Tue, 28 Mar 2023 08:49:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018580; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RsYSRw+9fCV4P0R4xSROpAkR79efvHcFBXpMga/TUyA=; b=SeUW2WO0Coov+gc4bC8JXkl8fpfGlMbVRb+Eozmmyl06nFED6mQCd6t3PMOKzGyJsP X2DMpVBDtM3F3a0QiLDIOWkBoXXSBpGtieaH8tWMmLX6tGEv8wGC6vuDIIlOl0lnQcHR tlGw/5wEoqfWom2+k8dm+zsZ1+92oHTXLeuSB81ZlLlMO9OA2j78eqe7bGiVyiBMD/jc yNPBqXU71abMZ4hyRasfKVCSeJ5w8vwIp1PeVy8kcH21sLi4IAqrzojaQXG1166FT55q si1Kq9CC9ahrVCGLuRnP/wPpA8DvFKjjPHlPVoSZ6b4BJHhRmEs7cTkJSaA4OPQUuGLq k/8g== X-Gm-Message-State: AO0yUKUu3XefVz4xVXJ3T5NGqKsJc20H6hr+kt4wvHqrd+JvdjnFdIXZ RjXP0yeQ/25u+KnGnpZFMPRvhnXhqRbqDDtHF/ML4g== X-Google-Smtp-Source: AK7set9OfaQmye+aamzMLvYsRifY3AOe2mAERilDeDnZ+/uKRV4oH3msTzk4ioAOpdhvvtuZWJFO7w== X-Received: by 2002:a5e:d601:0:b0:74c:a578:e3a0 with SMTP id w1-20020a5ed601000000b0074ca578e3a0mr10917363iom.5.1680018580169; Tue, 28 Mar 2023 08:49:40 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:39 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:37 -0600 Subject: [PATCH 1/6] Additions to gdb_mpz MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-1-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In preparation for adding more 128-bit support to gdb, a few additions to gdb_mpz are needed. First, this adds a new 'as_integer_truncate' method. This method works like 'as_integer' but does not require the value to fit in the target type -- it just truncates. Second, gdb_mpz::export_bits is changed to handle the somewhat unusual situation of zero-length types. This can happen for a Rust '()' type; but I think other languages have zero-bit integer types as well. Finally, this adds some operator== overloads. --- gdb/gmp-utils.c | 10 ++++++---- gdb/gmp-utils.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/gdb/gmp-utils.c b/gdb/gmp-utils.c index 0afa344781b..13fa61d61e3 100644 --- a/gdb/gmp-utils.c +++ b/gdb/gmp-utils.c @@ -69,19 +69,21 @@ void gdb_mpz::export_bits (gdb::array_view buf, int endian, bool unsigned_p, bool safe) const { - gdb_assert (buf.size () > 0); - int sign = mpz_sgn (m_val); if (sign == 0) { /* Our value is zero, so no need to call mpz_export to do the work, especially since mpz_export's documentation explicitly says that the function is a noop in this case. Just write zero to - BUF ourselves. */ - memset (buf.data (), 0, buf.size ()); + BUF ourselves, if it is non-empty. In some languages, a + zero-bit type can exist and this is also fine. */ + if (buf.size () > 0) + memset (buf.data (), 0, buf.size ()); return; } + gdb_assert (buf.size () > 0); + if (safe) { /* Determine the maximum range of values that our buffer can diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h index f294ab622ee..d05c11ecbe4 100644 --- a/gdb/gmp-utils.h +++ b/gdb/gmp-utils.h @@ -119,11 +119,17 @@ struct gdb_mpz return result; } - /* Convert VAL to an integer of the given type. + /* Convert this value to an integer of the given type. The return type can signed or unsigned, with no size restriction. */ template T as_integer () const; + /* Convert this value to an integer of the given type. If this + value is too large, it is truncated. + + The return type can signed or unsigned, with no size restriction. */ + template T as_integer_truncate () const; + /* Set VAL by importing the number stored in the byte array (BUF), using the given BYTE_ORDER. The size of the data to read is the byte array's size. @@ -312,7 +318,7 @@ struct gdb_mpz return mpz_cmp (m_val, other.m_val) <= 0; } - bool operator< (int other) const + bool operator< (long other) const { return mpz_cmp_si (m_val, other) < 0; } @@ -322,6 +328,28 @@ struct gdb_mpz return mpz_cmp_si (m_val, other) == 0; } + bool operator== (long other) const + { + return mpz_cmp_si (m_val, other) == 0; + } + + bool operator== (unsigned long other) const + { + return mpz_cmp_ui (m_val, other) == 0; + } + + template, + std::integral_constant sizeof (long))>> + > + > + bool operator== (T src) + { + return *this == gdb_mpz (src); + } + bool operator== (const gdb_mpz &other) const { return mpz_cmp (m_val, other.m_val) == 0; @@ -612,4 +640,20 @@ gdb_mpz::as_integer () const return result; } +/* See declaration above. */ + +template +T +gdb_mpz::as_integer_truncate () const +{ + T result; + + this->export_bits ({(gdb_byte *) &result, sizeof (result)}, + 0 /* endian (0 = native) */, + !std::is_signed::value /* unsigned_p */, + false /* safe */); + + return result; +} + #endif From patchwork Tue Mar 28 15:49:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67027 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F37B3850235 for ; Tue, 28 Mar 2023 15:50:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F37B3850235 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018608; bh=bev0VIcRjybmu3It+NCMV9vCPpwP52R4v+nvVdKcDvE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sJYpN/5x0KklDjN0jdakt7hpI+T8MKZV86WBMVI1BR22pjmT+iSUoXCU9VWJnFmqF EcvGL0bDwODFb3oIXsWq4bSJvygprpdKLSH37FijtSiPf2Lfwf5AxYGX8NxjEAHGMk /mPsdQAHD14AhTevnqb2ATd7KkPn1fZpqPaUsOqA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id 6E7E33858413 for ; Tue, 28 Mar 2023 15:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E7E33858413 Received: by mail-io1-xd2b.google.com with SMTP id k17so5557109iob.1 for ; Tue, 28 Mar 2023 08:49:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018580; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bev0VIcRjybmu3It+NCMV9vCPpwP52R4v+nvVdKcDvE=; b=f40ljvCW49Bn+252BuTbv5kI8fDqH2buSjJ1pCywh3LntCBL6qqV72Vc4sGDr3Nuj1 apfRDSvB8CfRXUty7kjW3FzfK2TzYMEzfsJK+2V5VrkTIP2FBwCCotBKAiejFs413vP8 DUfuQ5B3hU8r+9f8Mnhs6J/2weS1h34v7EiEeXyuV7SBl1f+HLlnh+LY1hyUZCcbz5n2 DmtsAZuPRhRN7NcyJ97XPQFxm3ZfyTwZd79H1CQ8htzNyabODTYRZZy8klQ6s+jWD0L/ WJLY3qtIP9IYCBfVnM+g/c5FDOdZaptW4q2q50H7UDcnVJjQ1cwEx5QZa/ln6NnEJvF0 XFSQ== X-Gm-Message-State: AO0yUKWK4YbkMygM69Wj9agdhUmjuxl7DGQP9eAvmNL18h90ME4niXtk 3Ddiwl+jqL7oWvfi2Ely8kSQnbtYTnTspeys3cKYZw== X-Google-Smtp-Source: AK7set9NxuGX6ywQMHNq4aR9VeP9XiWtCAsmppAk+2lTa3YHnna7wgBkPYnN4cozDUytSxTppjVpsw== X-Received: by 2002:a05:6602:228a:b0:758:917b:c313 with SMTP id d10-20020a056602228a00b00758917bc313mr12084713iod.13.1680018580710; Tue, 28 Mar 2023 08:49:40 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:40 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:38 -0600 Subject: [PATCH 2/6] Convert long_const_operation to use gdb_mpz MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-2-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes long_const_operation to use gdb_mpz for its storage. --- gdb/ada-lang.c | 4 ++-- gdb/ax-gdb.c | 4 ++-- gdb/expop.h | 26 +++++++++++++++++++++++--- gdb/expprint.c | 6 ++++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 5301c72d514..e51fd082d73 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10612,10 +10612,10 @@ ada_char_operation::replace (operation_up &&owner, if (context_type != nullptr && context_type->code () == TYPE_CODE_ENUM) { + LONGEST val = as_longest (); gdb_assert (result.get () == this); std::get<0> (m_storage) = context_type; - std::get<1> (m_storage) - = convert_char_literal (context_type, std::get<1> (m_storage)); + std::get<1> (m_storage) = convert_char_literal (context_type, val); } return result; diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 1ed648ce002..9dda7fe524d 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -1630,8 +1630,8 @@ long_const_operation::do_generate_ax (struct expression *exp, struct axs_value *value, struct type *cast_type) { - gen_int_literal (ax, value, std::get<1> (m_storage), - std::get<0> (m_storage)); + LONGEST val = as_longest (); + gen_int_literal (ax, value, val, std::get<0> (m_storage)); } void diff --git a/gdb/expop.h b/gdb/expop.h index d973d2314bb..854945c8688 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -274,6 +274,12 @@ check_objfile (ULONGEST val, struct objfile *objfile) return false; } +static inline bool +check_objfile (const gdb_mpz &val, struct objfile *objfile) +{ + return false; +} + template static inline bool check_objfile (enum_flags val, struct objfile *objfile) @@ -319,6 +325,8 @@ extern void dump_for_expression (struct ui_file *stream, int depth, struct type *type); extern void dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr); +extern void dump_for_expression (struct ui_file *stream, int depth, + const gdb_mpz &addr); extern void dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar); extern void dump_for_expression (struct ui_file *stream, int depth, @@ -468,6 +476,12 @@ check_constant (ULONGEST cst) return true; } +static inline bool +check_constant (const gdb_mpz &cst) +{ + return true; +} + static inline bool check_constant (struct symbol *sym) { @@ -665,18 +679,21 @@ class var_value_operation }; class long_const_operation - : public tuple_holding_operation + : public tuple_holding_operation { public: using tuple_holding_operation::tuple_holding_operation; + long_const_operation (struct type *type, LONGEST val) + : long_const_operation (type, gdb_mpz (val)) + { } + value *evaluate (struct type *expect_type, struct expression *exp, enum noside noside) override { - return value_from_longest (std::get<0> (m_storage), - std::get<1> (m_storage)); + return value_from_mpz (std::get<0> (m_storage), std::get<1> (m_storage)); } enum exp_opcode opcode () const override @@ -687,6 +704,9 @@ class long_const_operation protected: + LONGEST as_longest () const + { return std::get<1> (m_storage).as_integer_truncate (); } + void do_generate_ax (struct expression *exp, struct agent_expr *ax, struct axs_value *value, diff --git a/gdb/expprint.c b/gdb/expprint.c index 0c7cc754179..e0ec25573c2 100644 --- a/gdb/expprint.c +++ b/gdb/expprint.c @@ -108,6 +108,12 @@ dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr) core_addr_to_string (addr)); } +void +dump_for_expression (struct ui_file *stream, int depth, const gdb_mpz &val) +{ + gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", val.str ().c_str ()); +} + void dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar) { From patchwork Tue Mar 28 15:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67030 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BFF83858004 for ; Tue, 28 Mar 2023 15:50:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BFF83858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018634; bh=eZflJ5ajI4rFMlpPyHD3KB/Rwl4AXFd5MJHS52lDXa4=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aE4bGsMtGNSUKv0wHNP1N86qcQwcv3XJ6kdFZsGE7JsPSpv86uFS5QC6cO3ppqObh 18xqLP2jPbIlNAEdC1HyM+VjOl/nunUF1Zek0UaS0ekaxHMxWAttsz4MQCqxbWO9M/ k870P1ARHXAg3ATA3AE14AgnvqXa8N04JokpiYSs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 1F6453857C5A for ; Tue, 28 Mar 2023 15:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F6453857C5A Received: by mail-io1-xd29.google.com with SMTP id n28so1128835ioz.11 for ; Tue, 28 Mar 2023 08:49:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018581; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eZflJ5ajI4rFMlpPyHD3KB/Rwl4AXFd5MJHS52lDXa4=; b=7U9gnjWJ2PniBvfa1xv5zR3dAxSkpgmE1reN4+3TJ0H1FCNKHe6PtPDhFnlKZOpSrl uub2GLD2nY1JC99V03y9VQ70IkaahdDihXvUfzJ/amGphGEUTAbMtOVfH+cNLFyoU886 Qq5rBeIokkKYPyPmJpKOHBnxVrBg20aJBB24CC3MUXcWj7sYNHWtos+zijRnKwOILnGW H9AjVfnD7oGPPwrTsNkkXAFqsWCecFDyxCx7sQWDC4BpjaWTJtjTHMGmV8hM49RPqtMl Ykz8W0vaf5JAGaQgN9/DSipHXx27NjVn7cn8kvZD3BMsyDY6+6f+i0JQ6HpuePkUXfm4 WIAw== X-Gm-Message-State: AO0yUKWVMH3CtyMkjEOBMgdTdy5vOyAS6bLAt2hEmIHje81DC2xcJcTS BIHjzuBHuh7AgPBQOOoxp1voOV3XyGCb05srnsKfmQ== X-Google-Smtp-Source: AK7set/zb6deamkdgsqloz0dgWxZ6hKXEriwXIlC3+g5DzD7ial5lw5e+5Lfh99lRuEeUSmZjMIkTA== X-Received: by 2002:a05:6602:2052:b0:751:d1a9:964f with SMTP id z18-20020a056602205200b00751d1a9964fmr11621327iod.17.1680018581306; Tue, 28 Mar 2023 08:49:41 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:41 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:39 -0600 Subject: [PATCH 3/6] Add 128-bit integer support to the Rust parser MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-3-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds support for 128-bit integers to the Rust parser. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21185 --- gdb/rust-lang.c | 2 ++ gdb/rust-parse.c | 37 ++++++++++++++++++++------------- gdb/testsuite/gdb.base/parse_number.exp | 7 ++++--- gdb/testsuite/gdb.rust/onetwoeight.exp | 4 ++++ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index cb128f13f0e..3ef8fcaa329 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1607,6 +1607,8 @@ rust_language::language_arch_info (struct gdbarch *gdbarch, add (init_integer_type (alloc, 32, 1, "u32")); add (init_integer_type (alloc, 64, 0, "i64")); add (init_integer_type (alloc, 64, 1, "u64")); + add (init_integer_type (alloc, 128, 0, "i128")); + add (init_integer_type (alloc, 128, 1, "u128")); unsigned int length = 8 * builtin->builtin_data_ptr->length (); add (init_integer_type (alloc, length, 0, "isize")); diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index eca98aa286f..6c7922de9c7 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -69,7 +69,7 @@ static const char number_regex_text[] = #define INT_TEXT 5 #define INT_TYPE 6 "(0x[a-fA-F0-9_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*)" - "([iu](size|8|16|32|64))?" + "([iu](size|8|16|32|64|128))?" ")"; /* The number of subexpressions to allocate space for, including the "0th" whole match subexpression. */ @@ -126,7 +126,7 @@ enum token_type : int struct typed_val_int { - ULONGEST val; + gdb_mpz val; struct type *type; }; @@ -1007,7 +1007,6 @@ rust_parser::lex_number () /* Parse the number. */ if (is_integer) { - uint64_t value; int radix = 10; int offset = 0; @@ -1026,14 +1025,22 @@ rust_parser::lex_number () } } - const char *trailer; - value = strtoulst (number.c_str () + offset, &trailer, radix); - if (*trailer != '\0') - error (_("Integer literal is too large")); - if (implicit_i32 && value >= ((uint64_t) 1) << 31) - type = get_type ("i64"); + if (!current_int_val.val.set (number.c_str () + offset, radix)) + { + /* Shouldn't be possible. */ + error (_("Invalid integer")); + } + if (implicit_i32) + { + static gdb_mpz sixty_three_bit = gdb_mpz::pow (2, 63); + static gdb_mpz thirty_one_bit = gdb_mpz::pow (2, 31); + + if (current_int_val.val >= sixty_three_bit) + type = get_type ("i128"); + else if (current_int_val.val >= thirty_one_bit) + type = get_type ("i64"); + } - current_int_val.val = value; current_int_val.type = type; } else @@ -1556,9 +1563,11 @@ rust_parser::parse_field (operation_up &&lhs) break; case DECIMAL_INTEGER: - result = make_operation (current_int_val.val, - std::move (lhs)); - lex (); + { + int idx = current_int_val.val.as_integer (); + result = make_operation (idx, std::move (lhs)); + lex (); + } break; case INTEGER: @@ -1659,7 +1668,7 @@ rust_parser::parse_array_type () if (current_token != INTEGER && current_token != DECIMAL_INTEGER) error (_("integer expected")); - ULONGEST val = current_int_val.val; + ULONGEST val = current_int_val.val.as_integer (); lex (); require (']'); diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp index 07104433a16..5dd4fa705e9 100644 --- a/gdb/testsuite/gdb.base/parse_number.exp +++ b/gdb/testsuite/gdb.base/parse_number.exp @@ -108,9 +108,10 @@ proc parse_number { lang n } { return [list "i32" $n] } elseif { [fits_in_type $n 64 s] } { return [list "i64" $n] - } elseif { [fits_in_type $n 64 u] } { - # Note: Interprets MAX_U64 as -1. - return [list "i64" $n] + } elseif { [fits_in_type $n 128 u] } { + return [list "i128" $n] + } elseif { [fits_in_type $n 128 u] } { + return [list "i128" $n] } else { # Overflow. return [list $re_overflow $re_overflow] diff --git a/gdb/testsuite/gdb.rust/onetwoeight.exp b/gdb/testsuite/gdb.rust/onetwoeight.exp index ef56bcafda2..5ca30712830 100644 --- a/gdb/testsuite/gdb.rust/onetwoeight.exp +++ b/gdb/testsuite/gdb.rust/onetwoeight.exp @@ -64,3 +64,7 @@ gdb_test "print x >> 2" "= 85070591730234615865843651857942052863" gdb_test "print/x x & mask" " = 0xf0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0" gdb_test "print/x x ^ mask" " = 0xf0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f" gdb_test "print/x mask | (mask >> 4)" " = 0xffffffffffffffffffffffffffffffff" + +gdb_test "print 170141183460469231731687303715884105727" \ + " = 170141183460469231731687303715884105727" +gdb_test "ptype 23i128" "type = i128" From patchwork Tue Mar 28 15:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67029 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 69114387090E for ; Tue, 28 Mar 2023 15:50:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69114387090E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018621; bh=EWba4sS6t80FYz/U+pkAv3MrY5lKS6X7HKnukfdMFhk=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=M9sBzG9CXBb8f5G/ZiwQU/T7xIm40Szanm0KQb8dBlNUynG6REckfbAsviKNDeBBS YV1ukCm89S/9UjRsxD53jGV85hrJsfw9GA2JseazUQSL+BelGvIsPF5LOMzB20WF3s hMZ6l/w/+UJPbzFZ7QlBEDEjyrkAHNzu8vkDHHWg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 98C8F385558F for ; Tue, 28 Mar 2023 15:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98C8F385558F Received: by mail-io1-xd34.google.com with SMTP id e13so5566888ioc.0 for ; Tue, 28 Mar 2023 08:49:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018582; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EWba4sS6t80FYz/U+pkAv3MrY5lKS6X7HKnukfdMFhk=; b=prI+crJaOEheTNuFlZRoCDNI5sqJ8aknnldxplVVyezJ0dgSj2yBaRLAEioiNYZAWA 17ccfiU02jIPRaIGMO5iq1z18LC16o9tnePzThETOCw/LKrddbsRqhO0WqC0RW3vmZp6 k1iEEtwJSj2s4R1sfCQ0J1IOdH4+/OKB48cyMxZzn/RQIzhdyR/kzMgx0QOOri8tdEuZ SBvEsqvRFwwTM1tkhHmz10QMF+Ph3FpIXkYhG24oZJVOjPwOUB8I5bEh7hn6uA+GTT1L q8hM+P6wP83xP4jcQ3iGTY3lwnqqqJKH2DVGMYsmXdFBIBcYVXuU2dPqK/Q3dkdYqWsd pI6w== X-Gm-Message-State: AO0yUKV6aTpSFm8/1OuKk7Zk1/FMvLEZWAFA9ah+OsiXtMizKl1b0kG7 lFdem6QIn0g2/oAf7lv+4+avZzPzcrevx82/8saZfg== X-Google-Smtp-Source: AK7set/QjpuCXyhHS3cpaqZ5Ut6f8djG6lgdcxgLmgyx2y7121WuuuiLrJ02EZ/36XAR/Cyz4/uSBA== X-Received: by 2002:a6b:ec11:0:b0:74d:771:6ed5 with SMTP id c17-20020a6bec11000000b0074d07716ed5mr12202785ioh.21.1680018581870; Tue, 28 Mar 2023 08:49:41 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:41 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:40 -0600 Subject: [PATCH 4/6] Add overload of fits_in_type MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-4-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds an overload of fits_in_type that accepts a gdb_mpz. A subsequent patch will use this. --- gdb/parse.c | 26 ++++++++++++++++++++++++++ gdb/parser-defs.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/gdb/parse.c b/gdb/parse.c index 24db3ca57d9..23545e32160 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -648,6 +648,32 @@ fits_in_type (int n_sign, ULONGEST n, int type_bits, bool type_signed_p) else gdb_assert_not_reached (""); } + +/* Return true if the number N_SIGN * N fits in a type with TYPE_BITS and + TYPE_SIGNED_P. N_SIGNED is either 1 or -1. */ + +bool +fits_in_type (int n_sign, const gdb_mpz &n, int type_bits, bool type_signed_p) +{ + /* N must be nonnegative. */ + gdb_assert (n.sgn () >= 0); + + /* Zero always fits. */ + /* Normalize -0. */ + if (n.sgn () == 0) + return true; + + if (n_sign == -1 && !type_signed_p) + /* Can't fit a negative number in an unsigned type. */ + return false; + + gdb_mpz max = gdb_mpz::pow (2, (type_signed_p + ? type_bits - 1 + : type_bits)); + if (n_sign == -1) + return n <= max; + return n < max; +} /* This function avoids direct calls to fprintf in the parser generated debug code. */ diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 1780d856744..62829a86f9a 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -414,6 +414,8 @@ extern bool parse_float (const char *p, int len, const struct type *type, gdb_byte *data); extern bool fits_in_type (int n_sign, ULONGEST n, int type_bits, bool type_signed_p); +extern bool fits_in_type (int n_sign, const gdb_mpz &n, int type_bits, + bool type_signed_p); /* Function used to avoid direct calls to fprintf From patchwork Tue Mar 28 15:49:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67032 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2ECAA3851143 for ; Tue, 28 Mar 2023 15:51:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2ECAA3851143 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018662; bh=t6BB1+wP8aQp5ql4hYTILQqEGZoDw0HHnQ6wM5w/o9M=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=w8TrsqGNGKra7r7P7Hi3TnmA5LQNzN9yPbXTQaJm6jUYnJL7QIzKfgUEh8hV0+6+8 mABg4nsRu/hNv2xzLCSlGPAHbfL141IVp0jiJyuY4CGDBZ0h7nZkgyPgb9UyoLrrm/ AWOxI++7qrWF6YVQqR+0ZZSOxLp4nfIXaE1vEcDg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 1EFFE385483E for ; Tue, 28 Mar 2023 15:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EFFE385483E Received: by mail-io1-xd34.google.com with SMTP id h187so3821849iof.7 for ; Tue, 28 Mar 2023 08:49:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018582; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t6BB1+wP8aQp5ql4hYTILQqEGZoDw0HHnQ6wM5w/o9M=; b=o4D1K4sz/rOurCh04Eawd7fOguwA+nA47gQiepQOb/SWQqO5D71nDf6xwMSnKsto2R 7M0LNQ4xMq6l9nl5YIE/zRhyjZKxXSIYgNgfoWResjMQcdQJ5HI9UXo3A7fuJPqRbtpL JWAXkWcu/t/NLdDX+dfymugkx6CFrbEwZbBvx/CXCv2vFupQVHwmMREVI12Ztw0OnC/2 5Or8Jz2dURgSPzsIuh6nOEba2czhD0ykMfTlSbuRLoP8pckWO0ZclmkPUYWMrpUrP2Ug UYyemuVLg8igcTYofOr8BQKexo1oeSATvClv2GTF/gA78L5/zpZyCjo5AIm21489L5lE TF0w== X-Gm-Message-State: AO0yUKVckiStSWgNCNmOuY6fxfjpC2UiHHCpZNKNl5ZEpkhESZA7W7gj P+eju+4PkKo3++brwAs4qIoOiicpCcMdMrdy2EU49Q== X-Google-Smtp-Source: AK7set+fGIQg4sLZ6FBIjS8z8/O1JLf+vrSFazjclQT00mv0OT/mV25f/fmjkj9g6FSjyOgKdNMYDA== X-Received: by 2002:a05:6602:192:b0:758:b06f:6ab2 with SMTP id m18-20020a056602019200b00758b06f6ab2mr10388937ioo.2.1680018582396; Tue, 28 Mar 2023 08:49:42 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:42 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:41 -0600 Subject: [PATCH 5/6] Remove some Ada parser helper functions MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-5-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" These helper functions in the Ada parser don't seem all that worthwhile to me, so this patch removes them. --- gdb/ada-exp.y | 52 ++++++--------------------------- gdb/ada-lex.l | 8 ++--- gdb/testsuite/gdb.base/parse_number.exp | 2 ++ 3 files changed, 15 insertions(+), 47 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index a9c37bedff0..4095106bb09 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -93,18 +93,8 @@ static const struct block *block_lookup (const struct block *, const char *); static void write_ambiguous_var (struct parser_state *, const struct block *, const char *, int); -static struct type *type_int (struct parser_state *); - -static struct type *type_long (struct parser_state *); - -static struct type *type_long_long (struct parser_state *); - -static struct type *type_long_double (struct parser_state *); - static struct type *type_for_char (struct parser_state *, ULONGEST); -static struct type *type_boolean (struct parser_state *); - static struct type *type_system_address (struct parser_state *); static std::string find_completion_bounds (struct parser_state *); @@ -934,9 +924,15 @@ primary : STRING ; primary : TRUEKEYWORD - { write_int (pstate, 1, type_boolean (pstate)); } + { + write_int (pstate, 1, + parse_type (pstate)->builtin_bool); + } | FALSEKEYWORD - { write_int (pstate, 0, type_boolean (pstate)); } + { + write_int (pstate, 0, + parse_type (pstate)->builtin_bool); + } ; primary : NEW NAME @@ -1268,7 +1264,7 @@ write_object_renaming (struct parser_state *par_state, if (next == renaming_expr) goto BadEncoding; renaming_expr = next; - write_int (par_state, val, type_int (par_state)); + write_int (par_state, val, parse_type (par_state)->builtin_int); } else { @@ -1841,30 +1837,6 @@ write_name_assoc (struct parser_state *par_state, struct stoken name) push_association (ada_pop ()); } -static struct type * -type_int (struct parser_state *par_state) -{ - return parse_type (par_state)->builtin_int; -} - -static struct type * -type_long (struct parser_state *par_state) -{ - return parse_type (par_state)->builtin_long; -} - -static struct type * -type_long_long (struct parser_state *par_state) -{ - return parse_type (par_state)->builtin_long_long; -} - -static struct type * -type_long_double (struct parser_state *par_state) -{ - return parse_type (par_state)->builtin_long_double; -} - static struct type * type_for_char (struct parser_state *par_state, ULONGEST value) { @@ -1880,12 +1852,6 @@ type_for_char (struct parser_state *par_state, ULONGEST value) "wide_wide_character"); } -static struct type * -type_boolean (struct parser_state *par_state) -{ - return parse_type (par_state)->builtin_bool; -} - static struct type * type_system_address (struct parser_state *par_state) { diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index 69fc14f7107..0634f337cb2 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -471,9 +471,9 @@ processInt (struct parser_state *par_state, const char *base0, ULONGEST value = result.as_integer (); if (fits_in_type (1, value, int_bits, true)) - yylval.typed_val.type = type_int (par_state); + yylval.typed_val.type = parse_type (par_state)->builtin_int; else if (fits_in_type (1, value, long_bits, true)) - yylval.typed_val.type = type_long (par_state); + yylval.typed_val.type = parse_type (par_state)->builtin_long; else if (fits_in_type (1, value, long_bits, false)) { /* We have a number representable as an unsigned integer quantity. @@ -494,7 +494,7 @@ processInt (struct parser_state *par_state, const char *base0, return INT; } else if (fits_in_type (1, value, long_long_bits, true)) - yylval.typed_val.type = type_long_long (par_state); + yylval.typed_val.type = parse_type (par_state)->builtin_long_long; else if (fits_in_type (1, value, long_long_bits, false)) { yylval.typed_val.type @@ -518,7 +518,7 @@ processInt (struct parser_state *par_state, const char *base0, static int processReal (struct parser_state *par_state, const char *num0) { - yylval.typed_val_float.type = type_long_double (par_state); + yylval.typed_val_float.type = parse_type (par_state)->builtin_long_double; bool parsed = parse_float (num0, strlen (num0), yylval.typed_val_float.type, diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp index 5dd4fa705e9..8800dead53b 100644 --- a/gdb/testsuite/gdb.base/parse_number.exp +++ b/gdb/testsuite/gdb.base/parse_number.exp @@ -145,6 +145,8 @@ proc parse_number { lang n } { } elseif { [fits_in_type $n $long_long_bits u] } { # Note: Interprets ULLONG_MAX as -1. return [list "<$sizeof_long_long-byte integer>" $n] + } elseif { [fits_in_type $n 128 u] } { + return [list "<16-byte integer>" $n] } else { # Overflow. return [list $re_overflow $re_overflow] From patchwork Tue Mar 28 15:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67033 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FF8B387089E for ; Tue, 28 Mar 2023 15:51:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FF8B387089E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018690; bh=A1SuvcBgcUaR+k6dhVXlkf4e+NNYN0hayZQVT/8Ah3Q=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pdLB2mMNGw2SBUa8toLMD7m8/LtSTt5fJYt1OjIaDSmj500VatNNE5dIlCb+Uhzrx Z4XtINynut0rGncNFkxWosxLfUcJfD0Te3Ex6VXieAgxpLb/R2bE7yC4V3yhXioXKx r14gyJ0Q4WEcF+kT3QVu7LHUOk9P6W8tu87xwYHc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id BED10385EC09 for ; Tue, 28 Mar 2023 15:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BED10385EC09 Received: by mail-io1-xd2d.google.com with SMTP id f14so5536917iow.5 for ; Tue, 28 Mar 2023 08:49:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018583; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A1SuvcBgcUaR+k6dhVXlkf4e+NNYN0hayZQVT/8Ah3Q=; b=YrKYFg8KpJix/J/Xv6ZiynRxXFIvKS1wt1fDoEJsVPKk9g5pqqE8T77/lFixzYhyYc XtDfL+KvD9sowYz3RwNZ5Wdt5341QUxUmjUNT/RyNyo8o/JVZ6fpm8jD6NODXdqFGmoj RtwA0NY9x973KsWCGnlz9xbiJ/jkODtKZIvF9QbDHkmpQeLYSQPXhup0FTPP5YmM9yok paAjZfxy9my2pTrxPmqknqJJlz6IQEK6VaItCGLo6ZM43YDCsZIBYpLx7+uZ03uHWCsr UYn2aq0D0V889064c/qfAsUKSo0R9j1ogxx5Lda9iXRMfnriBvj0yVUitlA49UBkSK8R GoJg== X-Gm-Message-State: AO0yUKWYxLkU/oi+OMKTpHXjJPUVkaWjhnHwK/DPszaWS05BRIQuEQ4B Bl8cSDzX4KHJj3lsFDEBfFF1xhPk0WkCDwegnJOPaw== X-Google-Smtp-Source: AK7set93+NoZd0G8PKwxGm/w+5RdlcMvmx21ln27KqvRWpSk0MMw+2v3qrguqCTQ3TVcG2My5dk4Kg== X-Received: by 2002:a5e:9808:0:b0:753:cd5:abe1 with SMTP id s8-20020a5e9808000000b007530cd5abe1mr13409877ioj.7.1680018582959; Tue, 28 Mar 2023 08:49:42 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:42 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:42 -0600 Subject: [PATCH 6/6] Add 128-bit integer support to the Ada parser MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-6-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds support for 128-bit integers to the Ada parser. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30188 --- gdb/ada-exp.y | 22 ++++++++++--- gdb/ada-lang.c | 2 ++ gdb/ada-lex.l | 67 ++++++++++++++------------------------ gdb/testsuite/gdb.ada/verylong.exp | 5 +++ 4 files changed, 50 insertions(+), 46 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 4095106bb09..3e31d275046 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -68,6 +68,11 @@ static struct parser_state *pstate = NULL; /* The original expression string. */ static const char *original_expr; +/* We don't have a good way to manage non-POD data in Yacc, so store + values here. The storage here is only valid for the duration of + the parse. */ +static std::vector> int_storage; + int yyparse (void); static int yylex (void); @@ -416,9 +421,13 @@ make_tick_completer (struct stoken tok) { LONGEST lval; struct { - LONGEST val; + const gdb_mpz *val; struct type *type; } typed_val; + struct { + LONGEST val; + struct type *type; + } typed_char; struct { gdb_byte val[16]; struct type *type; @@ -433,7 +442,8 @@ make_tick_completer (struct stoken tok) %type aggregate_component_list %type var_or_type type_prefix opt_type_prefix -%token INT NULL_PTR CHARLIT +%token INT NULL_PTR +%token CHARLIT %token FLOAT %token TRUEKEYWORD FALSEKEYWORD %token COLONCOLON @@ -867,7 +877,7 @@ primary : primary TICK_ACCESS tick_arglist : %prec '(' { $$ = 1; } | '(' INT ')' - { $$ = $2.val; } + { $$ = $2.val->as_integer (); } ; type_prefix : @@ -888,7 +898,10 @@ opt_type_prefix : primary : INT - { write_int (pstate, (LONGEST) $1.val, $1.type); } + { + pstate->push_new ($1.type, *$1.val); + ada_wrap (); + } ; primary : CHARLIT @@ -1144,6 +1157,7 @@ ada_parse (struct parser_state *par_state) obstack_init (&temp_parse_space); components.clear (); associations.clear (); + int_storage.clear (); int result = yyparse (); if (!result) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e51fd082d73..9c683888ade 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13566,6 +13566,8 @@ class ada_language : public language_defn "long_float", gdbarch_double_format (gdbarch))); add (init_integer_type (alloc, gdbarch_long_long_bit (gdbarch), 0, "long_long_integer")); + add (init_integer_type (alloc, 128, 0, "long_long_long_integer")); + add (init_integer_type (alloc, 128, 1, "unsigned_long_long_long_integer")); add (init_float_type (alloc, gdbarch_long_double_bit (gdbarch), "long_long_float", gdbarch_long_double_format (gdbarch))); diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index 0634f337cb2..f2af21292f4 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -179,15 +179,15 @@ static int paren_depth; } "'"({GRAPHIC}|\")"'" { - yylval.typed_val.val = yytext[1]; - yylval.typed_val.type = type_for_char (pstate, yytext[1]); + yylval.typed_char.val = yytext[1]; + yylval.typed_char.type = type_for_char (pstate, yytext[1]); return CHARLIT; } "'[\""{HEXDIG}{2,}"\"]'" { ULONGEST v = strtoulst (yytext+3, nullptr, 16); - yylval.typed_val.val = v; - yylval.typed_val.type = type_for_char (pstate, v); + yylval.typed_char.val = v; + yylval.typed_char.type = type_for_char (pstate, v); return CHARLIT; } @@ -462,52 +462,35 @@ processInt (struct parser_state *par_state, const char *base0, return FLOAT; } - if (result > gdb_mpz (ULONGEST_MAX)) - error (_("Integer literal out of range")); + int_storage.emplace_back (new gdb_mpz (std::move (result))); + const gdb_mpz *value = int_storage.back ().get (); int int_bits = gdbarch_int_bit (par_state->gdbarch ()); int long_bits = gdbarch_long_bit (par_state->gdbarch ()); int long_long_bits = gdbarch_long_long_bit (par_state->gdbarch ()); - ULONGEST value = result.as_integer (); - if (fits_in_type (1, value, int_bits, true)) + if (fits_in_type (1, *value, int_bits, true)) yylval.typed_val.type = parse_type (par_state)->builtin_int; - else if (fits_in_type (1, value, long_bits, true)) + else if (fits_in_type (1, *value, long_bits, true)) yylval.typed_val.type = parse_type (par_state)->builtin_long; - else if (fits_in_type (1, value, long_bits, false)) - { - /* We have a number representable as an unsigned integer quantity. - For consistency with the C treatment, we will treat it as an - anonymous modular (unsigned) quantity. Alas, the types are such - that we need to store .val as a signed quantity. Sorry - for the mess, but C doesn't officially guarantee that a simple - assignment does the trick (no, it doesn't; read the reference manual). - */ - yylval.typed_val.type - = builtin_type (par_state->gdbarch ())->builtin_unsigned_long; - if (value & LONGEST_SIGN) - yylval.typed_val.val = - (LONGEST) (value & ~LONGEST_SIGN) - - (LONGEST_SIGN>>1) - (LONGEST_SIGN>>1); - else - yylval.typed_val.val = (LONGEST) value; - return INT; - } - else if (fits_in_type (1, value, long_long_bits, true)) + else if (fits_in_type (1, *value, long_bits, false)) + yylval.typed_val.type + = builtin_type (par_state->gdbarch ())->builtin_unsigned_long; + else if (fits_in_type (1, *value, long_long_bits, true)) yylval.typed_val.type = parse_type (par_state)->builtin_long_long; - else if (fits_in_type (1, value, long_long_bits, false)) - { - yylval.typed_val.type - = builtin_type (par_state->gdbarch ())->builtin_unsigned_long_long; - /* See unsigned long case above. */ - if (value & LONGEST_SIGN) - yylval.typed_val.val = - (LONGEST) (value & ~LONGEST_SIGN) - - (LONGEST_SIGN>>1) - (LONGEST_SIGN>>1); - else - yylval.typed_val.val = (LONGEST) value; - return INT; - } + else if (fits_in_type (1, *value, long_long_bits, false)) + yylval.typed_val.type + = builtin_type (par_state->gdbarch ())->builtin_unsigned_long_long; + else if (fits_in_type (1, *value, 128, true)) + yylval.typed_val.type + = language_lookup_primitive_type (par_state->language (), + par_state->gdbarch (), + "long_long_long_integer"); + else if (fits_in_type (1, *value, 128, false)) + yylval.typed_val.type + = language_lookup_primitive_type (par_state->language (), + par_state->gdbarch (), + "unsigned_long_long_long_integer"); else error (_("Integer literal out of range")); diff --git a/gdb/testsuite/gdb.ada/verylong.exp b/gdb/testsuite/gdb.ada/verylong.exp index 93df785862b..c8ae63f744b 100644 --- a/gdb/testsuite/gdb.ada/verylong.exp +++ b/gdb/testsuite/gdb.ada/verylong.exp @@ -35,3 +35,8 @@ gdb_test "print x - x" " = 0" gdb_test "print x - 99 + 1" " = 170141183460469231731687303715884105629" gdb_test "print -x" " = -170141183460469231731687303715884105727" gdb_test "print +x" " = 170141183460469231731687303715884105727" + +gdb_test "print 170141183460469231731687303715884105727" \ + " = 170141183460469231731687303715884105727" +gdb_test "print x = 170141183460469231731687303715884105727" \ + " = true"