From patchwork Tue Nov 28 21:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 80945 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 475D3386180E for ; Tue, 28 Nov 2023 21:54:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id D34C33858409 for ; Tue, 28 Nov 2023 21:54:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D34C33858409 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D34C33858409 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701208461; cv=none; b=umYVEzbkcLeECuNfn3lgqV7R0x9JI07oAHbV/M2ijYf5Qzg6KqMD9L4tsx01OH39e+tvEjm/sGrDsXgz/B2lyj8XtqLvR/wyK9mIlkXSPg9gzvZ7CVMYElPjhyw7zxG1612tjUoYYKgcvx8yDCP8K2L86oRql2/s98FzRDKRonM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701208461; c=relaxed/simple; bh=Y3gX14JooCZ6G31VAxmPxiy9229HnXkzNivUn+YIVQI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZiFBBxP+h6U59sZrH79PfMAY5gPtVmSJYYz4FtXYc2IS/TZkQ55p/UStJ/JxUpLrz+TmJDcQTetzGdAbPYYLumcbWNoaRT27/5jVO/ms9g7Mr2mOgSKN1IWfm3JoDbcFaxYZBKlALfV0+/Zz8F9RRPyyjX5s9TbDn4MzcsJJseY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTPS id 7vp3r4ShHjtZ3862Brim9X; Tue, 28 Nov 2023 21:54:23 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 8624rubSeqmEo8624r0v37; Tue, 28 Nov 2023 21:54:16 +0000 X-Authority-Analysis: v=2.4 cv=P+8pOwMu c=1 sm=1 tr=0 ts=65666188 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=BNY50KLci1gA:10 a=Qbun_eYptAEA:10 a=5bO5kDvfAAAA:8 a=CCpqsmhAAAAA:8 a=mDV3o1hIAAAA:8 a=RqKjROrYunPy74NjgQwA:9 a=ZqR_6EhbDGDjxU5desHT:22 a=ul9cdbp4aOFLsgKbc677:22 a=_FVE-zBwftR9WsbkzFJk: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=9jNlF83YY2vbzrqIAsloeoS55DYVke31dmp5NJtaXJ8=; b=YGGnkGS9H0KikxUk42GUFvMrwN e7kJ35UKbPlgfLVr9uxq3+VRZTdhXi92T2tw0IlVxfQfecD3wwVyD4UwXo+gZT61SE2VvOh968dZX kIgxaF4T9ySshegNzqVhVUFbi; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:37596 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1r8624-0029Qy-0B; Tue, 28 Nov 2023 14:54:16 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix dynamic type resolution for LOC_CONST and LOC_CONST_BYTES symbols Date: Tue, 28 Nov 2023 14:54:22 -0700 Message-ID: <20231128215422.1697343-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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: 97.122.77.73 X-Source-L: No X-Exim-ID: 1r8624-0029Qy-0B X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net (localhost.localdomain) [97.122.77.73]:37596 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfImevh4LvIs0r9n/mTou/eYzmgEkSGwwjMpg3k5VOPW6mzCMBVl3BaAiKR3Wq8iTrKS7OtDahis+rIR80Pjaxupt8gJdFi6BqNSg3I5JE5PL6OQShSaX Kiuj510SCHTxoXHdGbfOcZ3DJHqS+XXmFejbAVN54KyTfCXJx3AYO5w61hHppllRy83N6BkfciURzpmkFRBR/kgqQ+AYN3NAbp4= X-Spam-Status: No, score=-3023.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org PR rust/31005 points out that dynamic type resolution of a LOC_CONST or LOC_CONST_BYTES symbol will fail, leading to output like: from_index= This patch fixes the problem by using the constant value or bytes when performing type resolution. Thanks for tpzker@thepuzzlemaker.info for a first version of this patch. I also tested this on a big-endian PPC system (cfarm203). Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31005 --- gdb/findvar.c | 19 +++- gdb/testsuite/gdb.dwarf2/rust-enum.exp | 120 +++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/rust-enum.exp diff --git a/gdb/findvar.c b/gdb/findvar.c index 952ec20c0b7..c23b26febd7 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -534,8 +534,16 @@ language_defn::read_var_value (struct symbol *var, case LOC_CONST: if (is_dynamic_type (type)) { - /* Value is a constant byte-sequence and needs no memory access. */ - type = resolve_dynamic_type (type, {}, /* Unused address. */ 0); + gdb_byte bytes[sizeof (LONGEST)]; + + size_t len = std::min (sizeof (LONGEST), type->length ()); + store_unsigned_integer (bytes, len, + type_byte_order (type), + var->value_longest ()); + gdb::array_view view (bytes, len); + + /* Value is a constant byte-sequence. */ + type = resolve_dynamic_type (type, view, /* Unused address. */ 0); } /* Put the constant back in target format. */ v = value::allocate (type); @@ -575,8 +583,11 @@ language_defn::read_var_value (struct symbol *var, case LOC_CONST_BYTES: if (is_dynamic_type (type)) { - /* Value is a constant byte-sequence and needs no memory access. */ - type = resolve_dynamic_type (type, {}, /* Unused address. */ 0); + gdb::array_view view (var->value_bytes (), + type->length ()); + + /* Value is a constant byte-sequence. */ + type = resolve_dynamic_type (type, view, /* Unused address. */ 0); } v = value::allocate (type); memcpy (v->contents_raw ().data (), var->value_bytes (), diff --git a/gdb/testsuite/gdb.dwarf2/rust-enum.exp b/gdb/testsuite/gdb.dwarf2/rust-enum.exp new file mode 100644 index 00000000000..a052c11fe46 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/rust-enum.exp @@ -0,0 +1,120 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +standard_testfile main.c -dw.S + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + upvar cu_lang cu_lang + + declare_labels uinteger_label discr_1_label + declare_labels one_label two_label simple_label + + cu { addr_size 4 } { + compile_unit { + {name file1.txt} + {language @DW_LANG_Rust} + } { + uinteger_label: DW_TAG_base_type { + {DW_AT_byte_size 1 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_unsigned} + {DW_AT_name {unsigned integer}} + } + + one_label: structure_type { + {name One} + {byte_size 1 DW_FORM_sdata} + } { + member { + {name __0} + {type :$uinteger_label} + {data_member_location 0 data1} + } + } + + two_label: structure_type { + {name Two} + {byte_size 1 DW_FORM_sdata} + } { + member { + {name __0} + {type :$uinteger_label} + {data_member_location 0 data1} + } + } + + simple_label: structure_type { + {name Simple} + {byte_size 2 DW_FORM_sdata} + } { + variant_part { + {discr :$discr_1_label DW_FORM_ref4} + } { + discr_1_label: member { + {type :$uinteger_label} + {data_member_location 0 data1} + {artificial 1 DW_FORM_flag_present} + } + + variant { + {discr_value 65 udata} + } { + member { + {type :$one_label} + {data_member_location 1 data1} + } + } + + variant { + } { + member { + {type :$two_label} + {data_member_location 1 data1} + } + } + } + } + + # In PR rust/31005, a constant Rust enum value could not + # be correctly resolved. + DW_TAG_variable { + {name constant_variable} + {const_value 0x4141 udata} + {type :$simple_label} + } + DW_TAG_variable { + {name constant_variable2} + {const_value "AA" DW_FORM_block1} + {type :$simple_label} + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +gdb_test_no_output "set language rust" + +gdb_test "print constant_variable" [string_to_regexp "One(65)"] +gdb_test "print constant_variable2" [string_to_regexp "One(65)"]