From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gHXaKoD+PGCHJAAAWB0awg (envelope-from ) for ; Mon, 01 Mar 2021 09:47:28 -0500 Received: by simark.ca (Postfix, from userid 112) id 696181E590; Mon, 1 Mar 2021 09:47:26 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 C30D01EFC1 for ; Mon, 1 Mar 2021 09:47:22 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D4DC393BC1C; Mon, 1 Mar 2021 14:47:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D4DC393BC1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614610040; bh=mv5Xi+DnXEal4GcUGQzRpJTgjUD7zc2OEb46lsvGe/g=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=VjPM9HcdSHc7c4boUwiquwDovLsvkHMOQKC9QreJjsTAXNPHpE46TbtLzDwhxbaU9 s4dbNDXt+6johSEy5h+f/dEi72H2gv/QlHFACShqrcYYsjgpBc0+AsjXZn3zGjXN6w YG97onX/C7rP0675Uh9xGoC4HQBODqwKVRBWPw8s= Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2056.outbound.protection.outlook.com [40.107.244.56]) by sourceware.org (Postfix) with ESMTPS id 9FC20393BC06 for ; Mon, 1 Mar 2021 14:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9FC20393BC06 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NlSX3zSLFCXsJjfM6HLeagNaPE1BUIfOAQ8W37eHlc8Tdk2Rr6mMzTgLnSXV3ndfC86QLIKVyzDNniTzZdxzrwPxFfau4PDbXVEYIrnyIpnL5N7t6+RuwXoxVz8+Hig7RRH5/LheguTgxENwTTkbgsp0GxXaze1D/LcDDOoMknYBbFwUbOyDPQjtq8v2mxsJ4lUmQNjyNSbk+Rw/D1e4iHDPL4Z6fEtmql6bHIrXRA2nWljShHsSD/5Srl+wftmi4m33Fmqp4Aad9eBpKlI99FVRhCxAUKZ24p+DJqG/gG4PM7wzCnW4baqQlokpPcOaPP7vmLp5W472a961KJDQ/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mv5Xi+DnXEal4GcUGQzRpJTgjUD7zc2OEb46lsvGe/g=; b=QsC1BVkAoiYqkOSRodJUdz/T0XxO88rha2BPqIRsS146VugEMTxKk7sJC9HSKCKzYRvQUsoPUMot+Aj47cNEoYpewCKjkqLENGijqMIKeKnFbD5ZH2IXdRTnki5CLuYN9D0nd4qSqNjtsKYWrbzgEXhlCTUCq2I93uA39VMFVnnP7WCrbO+VHwwzdMoS399ySB8NxVbdoyuITitGxbq3nW1f4KA0bEKepzAlLhp9+63SvZu+9cqJ7T5OZta3EOYxBKfHgZxcIFaKl47khcJQP2swXllDzqrnpCmhFiQCtxdYGnuz1CjVos9EW3UoyMhAtAxNB22cQARKWTwQp0nQ4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none Received: from DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) by DM6PR12MB3676.namprd12.prod.outlook.com (2603:10b6:5:1c7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Mon, 1 Mar 2021 14:47:08 +0000 Received: from DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::31d8:f503:f7b2:f44]) by DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::31d8:f503:f7b2:f44%3]) with mapi id 15.20.3868.033; Mon, 1 Mar 2021 14:47:08 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 25/43] Add deref method to location description classes Date: Mon, 1 Mar 2021 14:46:02 +0000 Message-Id: <20210301144620.103016-26-Zoran.Zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210301144620.103016-1-Zoran.Zaric@amd.com> References: <20210301144620.103016-1-Zoran.Zaric@amd.com> Content-Type: text/plain X-Originating-IP: [2a00:23c7:5a85:6801:b4ed:fe7b:8064:d4d] X-ClientProxiedBy: AM0PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:208:be::14) To DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a00:23c7:5a85:6801:b4ed:fe7b:8064:d4d) by AM0PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:208:be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 14:47:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 970ac4e5-8115-4333-db32-08d8dcc0e327 X-MS-TrafficTypeDiagnostic: DM6PR12MB3676: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j1ksU5j3TLv0pTnH1W6tIRt4Tgb/k3t5BICApB5gSM6FW9BWDCk6ooQtH4wVP3vwFSkUkP0X46Fu003Q8vqze8U125O5PkQsZPinLJWOdAxOqsAJGImT/fe7L7C7c/TPupgu4zdLKbkHxshnyWEnVS6lDgPvYdYac4wNmlX0JQ0moUTUtthwR85e2rN+1vfBTiQPk11aT/oey0g6zbUeIdoiZDOFO+bGzXPiBnfU8Tqxls8ZM1E+2+LmuZqPEy6Fk2WzXwGR5TV7RQA5RByNHldLTZtZorAiUKrE+PtJqcl3j/qUe8fLsoXLHcF+tIiQ/VzKOwTr3E1ulWPjdEYI1xBGKNJeDKjRW1UW+EqGPqIPqEvpy2fX+HUFL6Xz9E8jZxvnuAHevI17iR/QouZHtMn1uwX8N6EkxJjk2z28aW3N47MPOQnlvUB+ENYxHKZ1DQnWff3hGO4x8rW+l3MYzZoKXIE54XrnQIJk6GvcpBQ1g/Gf4U6yalLtCBsKhHa/D2BaECAnuM1MxGiTUgGrEdlIlu+CHDOMAoBXSGakGNjN6BSFrrY9L3+P7wE9J5gOmDUUzxbqeCBhcFD9vub2eg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB2762.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(396003)(346002)(136003)(39860400002)(6666004)(16526019)(1076003)(83380400001)(2616005)(69590400012)(2906002)(186003)(36756003)(66946007)(316002)(66476007)(8936002)(52116002)(86362001)(6506007)(478600001)(5660300002)(4326008)(6486002)(8676002)(6916009)(6512007)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?DS90wi6e7VIQU8zv2mNJEyeT0WN7IeGUsq1SKLN0k5mp6r9s746R21qsvAGB?= =?us-ascii?Q?qntVTuziXtn4rsCW2x9usBx2st33cIa608OhiqxyD7xWN2tOodLs8I5ZAA7b?= =?us-ascii?Q?GTlzewtko1aktsO8vO0vYYe+dSkm/ooNyadcJgV/zFanMS5GrHXH438jY8hS?= =?us-ascii?Q?Y/i3e2wazhS5Qt2zqWsrh4pQkJxFtywrEbswVaZf4OOXyXNhnFSVpDaoNCo/?= =?us-ascii?Q?k2mFHh+DRnjfZnRieDwzUWOzKvW6fDC5oxtZDgslbjBwDnfxunXX+GLSVR0J?= =?us-ascii?Q?skCHATQQrWB6R4BSfEKjXbdYqrbnU7CIzEBAGPtEzzpKnVpodiWvKj4YRD9f?= =?us-ascii?Q?fHZNCyOLzDZwl1NIvMEktzzJP0pb9GpbV1+gyUEwHus9GSwkIKqX8fmYUczZ?= =?us-ascii?Q?DiO0Dwa2RYHq1TsObVl3/jz2JM6c+igsXKZJBpKTqV/QSlxw9B52kWv7tX65?= =?us-ascii?Q?oqWcDmEJMsHT3FvC5hSGMekP8FiCD86lvk3q681/Y6DKGF1pi17rfJ2L9Lih?= =?us-ascii?Q?8kr+LNBNNCdVUlI/bnDEIB4NQ7P9FzgWcEh5JYGsFNu56nrACoefh/39pq6/?= =?us-ascii?Q?H3HNxFOJxgzC3v8c7v9/WRpTu6HKgcPepv/yupPvttcJg610Op/J7p4aE1MK?= =?us-ascii?Q?cL5iw92ML3e7KBg751D3UyAzepevAAbv7KXJtehR3cWjxMO08Z+W3AhyNVqX?= =?us-ascii?Q?gMuwnJcca9axwyZYKknjkP1kLcl3gLO87VoBLCy0KfefW+6uW96RCtTpWJ16?= =?us-ascii?Q?ACMlhFV1cgDGRy4AcdkkXL1EfGNapdlFVx6e+pAKAPTIt5Y8cPApD0JnxmgS?= =?us-ascii?Q?I1d+SQhuN9nRyzzTnT8U81Z84m20fTQSYlTgkxZadF/kOezekcFDdLx2dwtE?= =?us-ascii?Q?yWke3qm2Nh3VLTPG0rCDv8U3Xm2EC8xa+DAXQ+qjAP3srwwiswTggnvYDLI/?= =?us-ascii?Q?Hf/wH2FrZF8NWzKYIqZ9gy+R7c/lsLVBGYKh8ZkA44CUJSKR+9Ty9jT9e19Q?= =?us-ascii?Q?xiPZTexQ4SVzFcHaVk1R+K3WSpJNMh/xIj3R0PfUs6douMjhV0TBOck0Rfz0?= =?us-ascii?Q?DxidtVYaozuU0tpuki1rBhNfs7MWvE8RQefG6wARqMejeWaiGGStTt5cmC5P?= =?us-ascii?Q?x1zd1uclLcjE/5MqKN/iUH6vSD6rIrkY+MwCl3bPKsSdl+AAM5Uivo/Lj9Qq?= =?us-ascii?Q?4Rd9b39etwSKNNm3N4siFPdSCBZSgt33yA6Yc1xE+7JNwbOotemrArKz024/?= =?us-ascii?Q?NdzBElzfISgHUJgeuQbZmMBW7M0UYajWm/uGfMgkXSgo+KClwQQFKElGKq3s?= =?us-ascii?Q?/apwOIJBiqXUri/NxeesEsHISjJkADJvsN7SCyck3gljjNvSJ+XwVTdZX7BO?= =?us-ascii?Q?9w28CKdvNxdzbgkW2Oj4rZfrajhC?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 970ac4e5-8115-4333-db32-08d8dcc0e327 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 14:47:07.8825 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5vFhZnuO3dfq99C8Xczp69r3/beEGQOPmAzKslPAgjRFW38P25VuQUpbgbVVvul0MjFT5bDFEpetZwvDwJYzlg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3676 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: Zoran Zaric via Gdb-patches Reply-To: Zoran Zaric Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Looking at the DWARF standard, the concept of reading from a location seems to be too low level. What the standard actually describes is a concept of dereferencing where the type of the operation result can be specified in advance. This can be seen in the definition of the DW_OP_derefX family of expression operations, but it is also happening implicitly in the case of DW_OP_fbreg, DW_OP_regval_type and DW_OP_bregX family of operations. Currently, the DW_OP_derefX operations will take the value from the DWARF expression stack and implicitly convert it to a memory location description (in reality treat it as a memory address for a given target) and apply the dereference operation to it. When we allow any location description on a DWARF expression stack, these operations need to work in the same way. The conclusion here is that we need an universal method that model the dereference operation for any class derived from a location description class. It is worth mentioning that because of how the passed in buffers are currently being implemented, we needed a specialisation for the deref method of the dwarf_memory class to support them. gdb/ChangeLog: * dwarf2/expr.c (dwarf_location::deref): New method. (dwarf_memory::deref): New method. --- gdb/dwarf2/expr.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index ef7adb1f959..ff9c88087d8 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -443,6 +443,18 @@ class dwarf_location : public dwarf_entry bool big_endian, int *optimized, int *unavailable) const = 0; + /* Apply dereference operation on the DWARF location description. + Operation returns a DWARF value of a given TYPE type while FRAME + contains a frame context information of the location. ADDR_INFO + (if present) describes a passed in memory buffer if a regular + memory read is not desired for certain address range. If the SIZE + is specified, it must be equal or smaller then the TYPE type size. + If SIZE is smaller then the type size, the value will be zero + extended to the difference. */ + virtual std::shared_ptr deref + (struct frame_info *frame, const struct property_addr_info *addr_info, + struct type *type, size_t size = 0) const; + protected: /* Architecture of the location. */ struct gdbarch *m_arch; @@ -458,6 +470,43 @@ class dwarf_location : public dwarf_entry bool m_initialised; }; +std::shared_ptr +dwarf_location::deref (struct frame_info *frame, + const struct property_addr_info *addr_info, + struct type *type, size_t size) const +{ + bool big_endian = type_byte_order (type) == BFD_ENDIAN_BIG; + size_t actual_size = size != 0 ? size : TYPE_LENGTH (type); + + if (actual_size > TYPE_LENGTH (type)) + ill_formed_expression (); + + /* If the size of the object read from memory is different + from the type length, we need to zero-extend it. */ + gdb::byte_vector read_buf (TYPE_LENGTH (type), 0); + gdb_byte *buf_ptr = read_buf.data (); + int optimized, unavailable; + + if (big_endian) + buf_ptr += TYPE_LENGTH (type) - actual_size; + + this->read (frame, buf_ptr, 0, actual_size * HOST_CHAR_BIT, + 0, 0, big_endian, &optimized, &unavailable); + + if (optimized) + throw_error (OPTIMIZED_OUT_ERROR, + _("Can't do read-modify-write to " + "update bitfield; containing word " + "has been optimized out")); + if (unavailable) + throw_error (NOT_AVAILABLE_ERROR, + _("Can't dereference " + "update bitfield; containing word " + "is unavailable")); + + return std::make_shared (read_buf.data (), type); +} + /* Value entry found on a DWARF expression evaluation stack. */ class dwarf_value : public dwarf_entry @@ -594,6 +643,10 @@ class dwarf_memory : public dwarf_location size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + std::shared_ptr deref + (struct frame_info *frame, const struct property_addr_info *addr_info, + struct type *type, size_t size = 0) const override; + private: /* True if the location belongs to a stack memory region. */ bool m_stack; @@ -701,6 +754,72 @@ dwarf_memory::write (struct frame_info *frame, const gdb_byte *buf, } } +std::shared_ptr +dwarf_memory::deref (struct frame_info *frame, + const struct property_addr_info *addr_info, + struct type *type, size_t size) const +{ + bool big_endian = type_byte_order (type) == BFD_ENDIAN_BIG; + size_t actual_size = size != 0 ? size : TYPE_LENGTH (type); + + if (actual_size > TYPE_LENGTH (type)) + ill_formed_expression (); + + gdb::byte_vector read_buf (TYPE_LENGTH (type), 0); + size_t size_in_bits = actual_size * HOST_CHAR_BIT; + gdb_byte *buf_ptr = read_buf.data (); + bool passed_in_buf = false; + + if (big_endian) + buf_ptr += TYPE_LENGTH (type) - actual_size; + + /* Covers the case where we have a passed in memory that is not + part of the target and requires for the location description + to address it instead of addressing the actual target + memory. */ + LONGEST this_size = bits_to_bytes (m_bit_suboffset, size_in_bits); + + /* We shouldn't have a case where we read from a passed in + memory and the same memory being marked as stack. */ + if (!m_stack && this_size && addr_info != nullptr) + { + CORE_ADDR offset = (CORE_ADDR) m_offset - addr_info->addr; + /* Using second buffer here because the copy_bitwise + doesn't support in place copy. */ + gdb::byte_vector temp_buf (this_size); + + if (offset < addr_info->valaddr.size () + && offset + this_size <= addr_info->valaddr.size ()) + { + memcpy (temp_buf.data (), addr_info->valaddr.data (), this_size); + copy_bitwise (buf_ptr, 0, temp_buf.data (), + m_bit_suboffset, size_in_bits, big_endian); + passed_in_buf = true; + } + } + + if (!passed_in_buf) + { + int optimized, unavailable; + + this->read (frame, buf_ptr, 0, size_in_bits, 0, 0, + big_endian, &optimized, &unavailable); + + if (optimized) + throw_error (OPTIMIZED_OUT_ERROR, + _("Can't do read-modify-write to " + "update bitfield; containing word " + "has been optimized out")); + if (unavailable) + throw_error (NOT_AVAILABLE_ERROR, + _("Can't dereference " + "update bitfield; containing word " + "is unavailable")); + } + + return std::make_shared (read_buf.data (), type); +} + /* Register location description entry. */ class dwarf_register : public dwarf_location -- 2.17.1