From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id 7CD463856261 for ; Thu, 20 Jul 2023 22:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CD463856261 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 753F810064D9F for ; Thu, 20 Jul 2023 22:11:26 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id Mbrqqk8yMNX2aMbrqqAOKT; Thu, 20 Jul 2023 22:11:26 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Zt4ol/3G c=1 sm=1 tr=0 ts=64b9b10e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=ws7JD89P4LkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=37kq5D-ibJjRdkrQQSAA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=TbbXNeEEp6HsDI6O9VaP343yLy0yOag/gtt4HUjVEKM=; b=EQq9z+gYNRpCEqvllicWa9qwIU P+na2RIKvb5Dmkk3AmkWBCPPySnK4SNqgUm89ounNG+UrP6ngm36umDr+gAZtdPBr4Xs/y5q5M8kD y/XRouC/yvyGpoYbeKa6yEbwd; Received: from 75-166-135-140.hlrn.qwest.net ([75.166.135.140]:55818 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qMbrq-003TFT-0b; Thu, 20 Jul 2023 16:11:26 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix crash with DW_FORM_implicit_const Date: Thu, 20 Jul 2023 16:11:18 -0600 Message-ID: <20230720221118.1966110-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.135.140 X-Source-L: No X-Exim-ID: 1qMbrq-003TFT-0b X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-135-140.hlrn.qwest.net (localhost.localdomain) [75.166.135.140]:55818 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Jakub pointed out that using DW_FORM_implicit_const with DW_AT_bit_size would cause gdb to crash. This happened because DW_FORM_implicit_const is not an "unsigned" form, causing as_unsigned to assert. This patch fixes the problem. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30651 --- gdb/dwarf2/read.c | 29 ++++++++++++++++------------ gdb/testsuite/gdb.dwarf2/intbits.exp | 2 +- gdb/testsuite/lib/dwarf.exp | 4 ++++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3508f2c29ee..b1f1c1d7257 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15420,20 +15420,25 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT) { attr = dwarf2_attr (die, DW_AT_bit_size, cu); - if (attr != nullptr && attr->as_unsigned () <= 8 * type->length ()) + if (attr != nullptr && attr->form_is_constant ()) { - unsigned real_bit_size = attr->as_unsigned (); - attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); - /* Only use the attributes if they make sense together. */ - if (attr == nullptr - || (attr->as_unsigned () + real_bit_size - <= 8 * type->length ())) + unsigned real_bit_size = attr->constant_value (0); + if (real_bit_size >= 0 && real_bit_size <= 8 * type->length ()) { - TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size - = real_bit_size; - if (attr != nullptr) - TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset - = attr->as_unsigned (); + attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); + /* Only use the attributes if they make sense together. */ + if (attr == nullptr + || (attr->form_is_constant () + && attr->constant_value (0) >= 0 + && (attr->constant_value (0) + real_bit_size + <= 8 * type->length ()))) + { + TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size + = real_bit_size; + if (attr != nullptr) + TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset + = attr->constant_value (0); + } } } } diff --git a/gdb/testsuite/gdb.dwarf2/intbits.exp b/gdb/testsuite/gdb.dwarf2/intbits.exp index c52e709316b..cf44d26b721 100644 --- a/gdb/testsuite/gdb.dwarf2/intbits.exp +++ b/gdb/testsuite/gdb.dwarf2/intbits.exp @@ -43,7 +43,7 @@ Dwarf::assemble ${asm_file} { {DW_AT_endianity @DW_END_little} {DW_AT_name "i7"} {DW_AT_byte_size 2 DW_FORM_udata} - {DW_AT_bit_size 7 DW_FORM_udata} + {DW_AT_bit_size 7 DW_FORM_implicit_const} } DW_TAG_variable { diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 434495df24a..f09da0430ab 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -693,6 +693,7 @@ namespace eval Dwarf { _op .ascii [_quote $value] } + DW_FORM_implicit_const - DW_FORM_flag_present { # We don't need to emit anything. } @@ -917,6 +918,9 @@ namespace eval Dwarf { } _op .uleb128 $_constants($attr_name) $attr_name _op .uleb128 $_constants($attr_form) $attr_form_comment + if {$attr_form eq "DW_FORM_implicit_const"} { + _op .sleb128 $attr_value "the constant" + } } } -- 2.41.0