From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2057.outbound.protection.outlook.com [40.107.237.57]) by sourceware.org (Postfix) with ESMTPS id F0B403858402 for ; Fri, 5 Nov 2021 11:39:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F0B403858402 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HdPqYs/FVbGYFDwcRcvwmIRjL+xKnzz43OmrzbrSiSF8rzx0AqWJ2F8TktotlWOh3fPSK1zghKSrOcQNjCF74wBO6QNpW5jaZ5aba5i902aKsD+w4Bg6qECM2QhCWquX8NRxw1KZjdetqAA/ABt2IZIkGIS6fNn3kK7WPP1YdlQhhrz4MI59ck/wyzo04vooWLgbDYXlzt3DKmDOvJsbeUnPDRf2c+88ejgDpEwwXbeWxA5MwilNciaY9LRLdSp2dySLWZM3mXEoDpH1Wu2wjW8cApnslsgHRpho6JiI5sPUENqVMUxjEjNLeJyIgPgjj5NBgTCiMgSuTPojcWJsdA== 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=uEgCq4XQU0h1pVzJaQy3rl6NuM4h3Z6FyCZHtIU7/2w=; b=aRVx6XMPL1sz2K6u/ry/YvShR3Kieh9NYXqwjj7WF6BWZuyNcoe7BWchalrv/6H/M1al9REXYjTr4R5JsnDZPYw7/wdLCqs3a4fQYg2c7RGqr1j5qaT7F/6GpOOXw06xEj7rVrBKOPYd7Vm+xzWO/8kJUX42WjRFAjqAnSAMWVOA1OdirtEZfWCOGLJ2vlEkHE+oL+fHWBNP/aBm5FwZcqXhc73Mgh1x1+bkY6zeZj08y/rDo2rMaK4UIKLF8i3/QUooKzYUXSYk5cql0K+Dif/Br9zZa77iN8teJXnshVZ96LUIf+xwZbV/NlmGhgq4taFVvw947tGCaHWIvk3XeA== 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 MW4PR04CA0152.namprd04.prod.outlook.com (2603:10b6:303:85::7) by MW3PR12MB4428.namprd12.prod.outlook.com (2603:10b6:303:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Fri, 5 Nov 2021 11:39:16 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::24) by MW4PR04CA0152.outlook.office365.com (2603:10b6:303:85::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Fri, 5 Nov 2021 11:39:16 +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 CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4669.10 via Frontend Transport; Fri, 5 Nov 2021 11:39:15 +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.15; Fri, 5 Nov 2021 06:39:11 -0500 From: Zoran Zaric To: Subject: [PATCH v4 07/28] Add write method to location description classes Date: Fri, 5 Nov 2021 11:38:28 +0000 Message-ID: <20211105113849.118800-8-zoran.zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211105113849.118800-1-zoran.zaric@amd.com> References: <20211105113849.118800-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 765229ac-0b20-4eb8-f549-08d9a050e5ab X-MS-TrafficTypeDiagnostic: MW3PR12MB4428: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UTETHYRyGDIUpNGCafeRAfs0r4IdHLAg9pHEytWfGlH1y85CdFev+1u/wlD/fWjhpJI3hwNd838PX77mBgFUB/zMBg0eb4vekboWWregxgqXdUTsoJloEcdr6BXdbj6CgjtD5+crhIuqppWlZelVp7LjMoY01bhr0DHIZmb1yEmpH+6lo9n8duYR0+GG6mY83e8KjgcVNVqQY7yakQO0D71AuDinG0+l+gcaZYWXyL6dg6NL99vlCpuWctDqowKaFgoFRtQ4pFk0AjwgDSpVY+a3v50KFhxUfBeHQ0sB3aofNRoO4yXkm8oCrPALUt0+rZVgnVOwd7G7xgyFPRrOUmWVP7L25IRynbnYQcoglu1h5oX6hO1Y+d6i08F3NyXXEx58PukJ1NNN+I8geWxzlkPxpKGSOsuz8Z7C8r1z2FNSlWnJI1Bd/7lviRxRV0IIujBoGe+5r7kGsqUXTKqRywLHPsdBZhazmNk1CBiVnV80tm0QmqnFdM6KCnD/cGhXiOJ2uT+QXZDmzMiVXVX6HCFFB88ds4QdRNpK3M7AUBwyK1A4Vb/cuL/YipF+dVZfQJheUGypedOrlJdm4avfikiNtJZbwsTU6X9CStqNQ2tX4cOMHJuNOTh2QknYuwG2tarszgydGO1o0ffosePSXf/I4seQYOH/j9U6N8CFW8m9qcnxZID/R2G5Fn+wxepNZg+kIkFhJDe1dRnf3aVvyi1uXc1aiozpvPn9zOkgdWA= 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)(5660300002)(70586007)(36756003)(36860700001)(86362001)(70206006)(82310400003)(83380400001)(356005)(6666004)(8936002)(81166007)(2616005)(4326008)(8676002)(426003)(44832011)(2906002)(336012)(1076003)(30864003)(26005)(508600001)(6916009)(16526019)(47076005)(186003)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 11:39:15.9016 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 765229ac-0b20-4eb8-f549-08d9a050e5ab 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: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4428 X-Spam-Status: No, score=-12.4 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: Fri, 05 Nov 2021 11:39:20 -0000 From: Zoran Zaric After adding the interface for reading from the location, it also makes sense to add the interface for writing. To be clear, DWARF standard doesn't have a concept of writting to a location, but because of the way how callback functions are used to interact with the opaque implementation of the computed struct value objects, the choice was to either use the existing DWARF entry classes or to invent another way of representing the complexity behind those computed objects. Adding a write method seems to be a simpler option of the two. gdb/ChangeLog: * dwarf2/expr.c (dwarf_location::write): New method. (dwarf_undefined::write): New method. (dwarf_memory::write): New method. (dwarf_register::write): New method. (dwarf_implicit::write): New method. (dwarf_implicit_pointer::write): New method. (dwarf_composite::write): New method. --- gdb/dwarf2/expr.c | 211 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index f2349208412..6129f4e8ec9 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -391,6 +391,28 @@ class dwarf_location : public dwarf_entry bool big_endian, int *optimized, int *unavailable) const = 0; + /* Write contents to a described location. + + The write operation is performed in the context of a FRAME. + BIT_SIZE is the number of bits written. The data written is + copied from the caller-managed BUF buffer. BIG_ENDIAN defines an + endianness of the target. BITS_TO_SKIP is a bit offset into the + location and BUF_BIT_OFFSET is buffer BUF's bit offset. + LOCATION_BIT_LIMIT is a maximum number of bits that location can + hold, where value zero signifies that there is no such + restriction. + + Note that some location types can be written without a FRAME + context. + + If the location is optimized out or unavailable, the OPTIMIZED and + UNAVAILABLE outputs are set. */ + virtual void write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, + LONGEST bits_to_skip, size_t location_bit_limit, + bool big_endian, int *optimized, + int *unavailable) const = 0; + protected: /* Architecture of the location. */ gdbarch *m_arch; @@ -481,6 +503,14 @@ class dwarf_undefined final : public dwarf_location *unavailable = 0; *optimized = 1; } + + void write (frame_info *frame, const gdb_byte *buf, int buf_bit_offset, + size_t bit_size, LONGEST bits_to_skip, size_t location_bit_limit, + bool big_endian, int *optimized, int *unavailable) const override + { + *unavailable = 0; + *optimized = 1; + } }; class dwarf_memory final : public dwarf_location @@ -502,6 +532,11 @@ class dwarf_memory final : public dwarf_location size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + void write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, LONGEST bits_to_skip, + size_t location_bit_limit, bool big_endian, + int *optimized, int *unavailable) const override; + private: /* True if the location belongs to a stack memory region. */ bool m_stack; @@ -568,6 +603,62 @@ dwarf_memory::read (frame_info *frame, gdb_byte *buf, } } +void +dwarf_memory::write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, + LONGEST bits_to_skip, size_t location_bit_limit, + bool big_endian, int *optimized, int *unavailable) const +{ + LONGEST total_bits_to_skip = bits_to_skip; + CORE_ADDR start_address + = m_offset + (m_bit_suboffset + total_bits_to_skip) / HOST_CHAR_BIT; + gdb::byte_vector temp_buf; + + *optimized = 0; + total_bits_to_skip += m_bit_suboffset; + + if (total_bits_to_skip % HOST_CHAR_BIT == 0 + && bit_size % HOST_CHAR_BIT == 0 + && buf_bit_offset % HOST_CHAR_BIT == 0) + { + /* Everything is byte-aligned; no buffer needed. */ + write_to_memory (start_address, buf + buf_bit_offset / HOST_CHAR_BIT, + bit_size / HOST_CHAR_BIT, m_stack, unavailable); + } + else + { + LONGEST this_size = bits_to_bytes (total_bits_to_skip, bit_size); + temp_buf.resize (this_size); + + if (total_bits_to_skip % HOST_CHAR_BIT != 0 + || bit_size % HOST_CHAR_BIT != 0) + { + if (this_size <= HOST_CHAR_BIT) + /* Perform a single read for small sizes. */ + read_from_memory (start_address, temp_buf.data (), + this_size, m_stack, unavailable); + else + { + /* Only the first and last bytes can possibly have + any bits reused. */ + read_from_memory (start_address, temp_buf.data (), + 1, m_stack, unavailable); + + if (!*unavailable) + read_from_memory (start_address + this_size - 1, + &temp_buf[this_size - 1], 1, + m_stack, unavailable); + } + } + + copy_bitwise (temp_buf.data (), total_bits_to_skip % HOST_CHAR_BIT, + buf, buf_bit_offset, bit_size, big_endian); + + write_to_memory (start_address, temp_buf.data (), this_size, + m_stack, unavailable); + } +} + /* Register location description entry. */ class dwarf_register final : public dwarf_location @@ -581,6 +672,11 @@ class dwarf_register final : public dwarf_location size_t bit_size, LONGEST bits_to_skip, size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + void write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, LONGEST bits_to_skip, + size_t location_bit_limit, bool big_endian, + int *optimized, int *unavailable) const override; + private: /* DWARF register number. */ unsigned int m_regnum; @@ -627,6 +723,53 @@ dwarf_register::read (frame_info *frame, gdb_byte *buf, total_bits_to_skip % HOST_CHAR_BIT, bit_size, big_endian); } +void +dwarf_register::write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, + LONGEST bits_to_skip, size_t location_bit_limit, + bool big_endian, int *optimized, int *unavailable) const +{ + LONGEST total_bits_to_skip = bits_to_skip; + size_t write_bit_limit = location_bit_limit; + gdbarch *frame_arch = get_frame_arch (frame); + int reg = dwarf_reg_to_regnum_or_error (frame_arch, m_regnum); + ULONGEST reg_bits = HOST_CHAR_BIT * register_size (frame_arch, reg); + gdb::byte_vector temp_buf; + + if (frame == nullptr) + internal_error (__FILE__, __LINE__, _("invalid frame information")); + + if (big_endian) + { + if (!write_bit_limit || reg_bits <= write_bit_limit) + write_bit_limit = bit_size; + + total_bits_to_skip += reg_bits - (m_offset * HOST_CHAR_BIT + + m_bit_suboffset + write_bit_limit); + } + else + total_bits_to_skip += m_offset * HOST_CHAR_BIT + m_bit_suboffset; + + LONGEST this_size = bits_to_bytes (total_bits_to_skip, bit_size); + temp_buf.resize (this_size); + + if (total_bits_to_skip % HOST_CHAR_BIT != 0 + || bit_size % HOST_CHAR_BIT != 0) + { + /* Contents is copied non-byte-aligned into the register. + Need some bits from original register value. */ + read_from_register (frame, reg, + total_bits_to_skip / HOST_CHAR_BIT, + temp_buf, optimized, unavailable); + } + + copy_bitwise (temp_buf.data (), total_bits_to_skip % HOST_CHAR_BIT, buf, + buf_bit_offset, bit_size, big_endian); + + write_to_register (frame, reg, total_bits_to_skip / HOST_CHAR_BIT, + temp_buf, optimized, unavailable); +} + /* Implicit location description entry. Describes a location description not found on the target but instead saved in a gdb-allocated buffer. */ @@ -646,6 +789,15 @@ class dwarf_implicit final : public dwarf_location size_t bit_size, LONGEST bits_to_skip, size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + void write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, + LONGEST bits_to_skip, size_t location_bit_limit, + bool big_endian, int* optimized, int* unavailable) const override + { + *optimized = 1; + *unavailable = 0; + } + private: /* Implicit location contents as a stream of bytes in target byte-order. */ gdb::byte_vector m_contents; @@ -712,6 +864,15 @@ class dwarf_implicit_pointer final : public dwarf_location size_t bit_size, LONGEST bits_to_skip, size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + void write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, LONGEST bits_to_skip, + size_t location_bit_limit, bool big_endian, + int* optimized, int* unavailable) const override + { + *optimized = 1; + *unavailable = 0; + } + private: /* Per object file data of the implicit pointer. */ dwarf2_per_objfile *m_per_objfile; @@ -783,6 +944,11 @@ class dwarf_composite final : public dwarf_location size_t bit_size, LONGEST bits_to_skip, size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + void write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, LONGEST bits_to_skip, + size_t location_bit_limit, bool big_endian, + int *optimized, int *unavailable) const override; + private: /* Composite piece that contains a piece location description and it's size. */ @@ -848,6 +1014,51 @@ dwarf_composite::read (frame_info *frame, gdb_byte *buf, } } +void +dwarf_composite::write (frame_info *frame, const gdb_byte *buf, + int buf_bit_offset, size_t bit_size, + LONGEST bits_to_skip, size_t location_bit_limit, + bool big_endian, int *optimized, + int *unavailable) const +{ + LONGEST total_bits_to_skip = bits_to_skip; + unsigned int pieces_num = m_pieces.size (); + unsigned int i; + + total_bits_to_skip += m_offset * HOST_CHAR_BIT + m_bit_suboffset; + + /* Skip pieces covered by the write offset. */ + for (i = 0; i < pieces_num; i++) + { + LONGEST piece_bit_size = m_pieces[i].size; + + if (total_bits_to_skip < piece_bit_size) + break; + + total_bits_to_skip -= piece_bit_size; + } + + for (; i < pieces_num; i++) + { + LONGEST piece_bit_size = m_pieces[i].size; + LONGEST actual_bit_size = piece_bit_size; + + if (actual_bit_size > bit_size) + actual_bit_size = bit_size; + + m_pieces[i].location->write (frame, buf, buf_bit_offset, + actual_bit_size, total_bits_to_skip, + piece_bit_size, big_endian, + optimized, unavailable); + + if (bit_size == actual_bit_size || *optimized || *unavailable) + break; + + buf_bit_offset += actual_bit_size; + bit_size -= actual_bit_size; + } +} + struct piece_closure { /* Reference count. */ -- 2.17.1