From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2082.outbound.protection.outlook.com [40.107.236.82]) by sourceware.org (Postfix) with ESMTPS id 6AD463858427 for ; Thu, 14 Oct 2021 09:33:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6AD463858427 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CYIoXuLTxjg915uaXrMbYNr02yrIAcSlTf/6riRcfezpD8fzgJhtPugrCQdpI/XY1YgoQH0CYQiej7HKyL3tetICUrX5wH64g+Z0If4lkQLHi2fg1R7i6VbIAE1BvCCepslWZT6i1j8Oss1xiKJVQA7Wbdiiube526MfXEKQ92oe8WWnETLkuA1C1W4rb05CmOKmsghGykEdJ+xojFDT3kA/sIy296cQn1BWp7o/dPSVNTrUHgXtwZ8/KPOSyn1bVxLL/vcLDH2gU4ixpHyTjAuh6AVDlE9OuDeOl0JmTgAdZ9cWnw3irOwQAgIU9uPZOBnP10NbDsJabF54+RI56A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hxmAGLDZgRrfEwks9B/diXA+GKPHqRkpsHOfERBdIz8=; b=ISiJq8ZbuiEUXWZeOqP6flnOV9fygr8Z9he12dYU27y76VOogs70BOAsVWwwMhfZYvOlJB1AZrPDVqhYoc54FV4S1zng3gSXv3zc8oDmu0LJyOCGfIgA47/ConoxgByIceGK0xWwbTWdudPnDEegpRRshCyMXUbTp9BovJyMmvcZ3ojJPLo4oVrSnEsxeQ6KzuHAmh0qJjIVQ+CbgJh4TEP7+A1F2JBiwyAjhxsZtXGxeWF4Gdj8eBhWRN2qLEyAUex8KbKnf4b1QRWowm6kzZPpC+G155okXbg4tfHnq3uSJGOCrHy1G49iIgLHJwIiwVvdaLsLHJVMzGIDzDFkLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from DM5PR13CA0029.namprd13.prod.outlook.com (2603:10b6:3:7b::15) by MN2PR12MB3504.namprd12.prod.outlook.com (2603:10b6:208:d1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Thu, 14 Oct 2021 09:33:05 +0000 Received: from DM6NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:3:7b:cafe::be) by DM5PR13CA0029.outlook.office365.com (2603:10b6:3:7b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.4 via Frontend Transport; Thu, 14 Oct 2021 09:33:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT047.mail.protection.outlook.com (10.13.172.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Thu, 14 Oct 2021 09:33:05 +0000 Received: from localhost.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 14 Oct 2021 04:33:02 -0500 From: Zoran Zaric To: Subject: [PATCH v3 08/28] Add deref method to location description classes Date: Thu, 14 Oct 2021 10:32:15 +0100 Message-ID: <20211014093235.69756-9-zoran.zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211014093235.69756-1-zoran.zaric@amd.com> References: <20211014093235.69756-1-zoran.zaric@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d9ab6fef-3ec5-4d56-9a4d-08d98ef5a037 X-MS-TrafficTypeDiagnostic: MN2PR12MB3504: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sbkh18RXBIqCA/Rs7qQNSKe+IKaNxfNLXF3DV7vwdyRouVN4w6NcsPICutOwxHiO2eUOhgg9mJMs8kS0ucm/K+Snify/vPjB6H7uPu0CwnGMivoUhuJn7xQvD2HYRoQ7Tkm5+90VxpdeVyEkSnlgSB9hEIlBfNZwfEn7Mwum4W/isVl0JhMNCbNSzrXFLClWEUYbSu3NWT8BbkSSfgfyzmqe6Ju6Y/4jQnm2pU4cQF+F2WiyTfKo52nozKbCeNovjXEXw7XZBK//20uw1N+rNHKxOKCTBvmFxYJ+H2rkZbxlbw+WTZVdR2T99ENeTPeI5sNCwrcSkXUCLTCsgodHXjafnvxgcNXynBjsQwIeD8K5pZHUh6ftrMcrd+IipavZumDMGwk5Cl7rhkG1OGPv6NLNv5Ya7g2dAwnLupIeEYEXydPNLpNi0SPiPr4KHhn12Ve8pqzo3aJGiKyJ/qnLHSfrhDTFf5B8R7xWN29yiPb7ChZ7ig8RHVJSzt5XPz/hThVhVhLDG5o+wPOf+BjmH0/qtfk2/N8su7J2lAm0abztYlYShfX0s3fO8bGrIRYF4WM8p2zhgkG2ywsDsr4nouYXdyWRVF3jfgOCxGzplAeXRbfegogC1AVvN0G7N5eMTUWmyirQPMVZQYIAig6gdjOF75xu0+EjDOP3gdP2+FHAgUQTqZK9kmFQHOEdG3UJyW6Cy4iqEWznVaiyvaj71mJ5B5oGdbz86XMgE67B1aw= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(1076003)(44832011)(82310400003)(8936002)(36756003)(508600001)(47076005)(6666004)(356005)(83380400001)(8676002)(36860700001)(26005)(70586007)(186003)(81166007)(336012)(2616005)(16526019)(70206006)(86362001)(6916009)(4326008)(426003)(316002)(5660300002)(2906002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2021 09:33:05.4962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9ab6fef-3ec5-4d56-9a4d-08d98ef5a037 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3504 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Thu, 14 Oct 2021 09:33:09 -0000 From: Zoran Zaric Concept of reading from a location seems to be too low level for the DWARF standard. 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 | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 83a2db028ca..87caba5fd62 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -422,6 +422,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::unique_ptr deref + (frame_info *frame, const property_addr_info *addr_info, + struct type *type, size_t size = 0) const; + protected: /* Architecture of the location. */ gdbarch *m_arch; @@ -489,6 +501,43 @@ class dwarf_value : public dwarf_entry using dwarf_value_up = std::unique_ptr; +std::unique_ptr +dwarf_location::deref (frame_info *frame, const 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 make_unique + (gdb::array_view (read_buf), type); +} + /* Undefined location description entry. This is a special location description type that describes the location description that is not known. */ @@ -541,6 +590,11 @@ class dwarf_memory final : public dwarf_location size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + std::unique_ptr deref (frame_info *frame, + const 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; @@ -663,6 +717,73 @@ dwarf_memory::write (frame_info *frame, const gdb_byte *buf, } } +std::unique_ptr +dwarf_memory::deref (frame_info *frame, const 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 + && addr_info->valaddr.data () != 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 make_unique + (gdb::array_view (read_buf), type); +} + /* Register location description entry. */ class dwarf_register final : public dwarf_location -- 2.17.1