From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2049.outbound.protection.outlook.com [40.107.237.49]) by sourceware.org (Postfix) with ESMTPS id DEACE3857C53 for ; Fri, 5 Nov 2021 11:39:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DEACE3857C53 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m1Qmr4sb5At/5gW0drTtlgaMNrzg2BQr9Djc3mkxWyYAHZzqTsxdPd6/C4LdA47F0gwBU6WRZ8jMo218BbMws0d/B9HHXf+x36rhcg+G6qFrwJaKeWiIX7pcZNcK00QOxWKt17OvhpGERjS/QBx530l/R44J+sXyPDGype/0XjLJ+wvVJH21zthwkBjcrU95epxjgzVjoOmgVmn1aHs1LUd709AjpHZ+TcqbDr9tvSZwByMBlLFQGuxwwEWQA6w00skk41hqqGkgetmw8xmh0nD9MHg/g3RNteaZhrWe90HvL87jk85WRZI8Kc6rTUPOBWthINGcc9nRbRuCCUpFyw== 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=p0jVMvQd1gcroJIDB/xMqOyZfzN4EZReeDhymKhhbaA=; b=NCXXQMJYorlro6AYInNn9KlrPQeK898JOFTZJvJo2S8lb0xiz44pJ6UWe27VDrlBU4TUGkHuTJ0r2mJlZ4H7tp90KnmZrSoWNpb5DnfYeFWe8GP1lYvgxslne0Ev+udduc753gFPGGwJOh2wK2UKH8gKqoW3Q5mmNtGdoU9aLODbVMs3jTzii+AsKMKebRXjwK/IQeqG2+I2W2zrswalhVzNDdbSGXh2jQjZgQuii4pHVlgbFJ7UnXDf5DavmMgHw4Xf423rfkA3KSdW2m07yFF02MEXq5jhPABLZskbZvx1QScW1zvZ3ZvqcO+Vj+Xt/ZA0KNBAwVTsEDdjn3jNUg== 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 MW4PR04CA0175.namprd04.prod.outlook.com (2603:10b6:303:85::30) by CH0PR12MB5281.namprd12.prod.outlook.com (2603:10b6:610:d4::23) 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:17 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::86) by MW4PR04CA0175.outlook.office365.com (2603:10b6:303:85::30) 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:17 +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:16 +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:12 -0500 From: Zoran Zaric To: Subject: [PATCH v4 08/28] Add deref method to location description classes Date: Fri, 5 Nov 2021 11:38:29 +0000 Message-ID: <20211105113849.118800-9-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: 2cb48ec6-c201-40a4-d381-08d9a050e623 X-MS-TrafficTypeDiagnostic: CH0PR12MB5281: 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: 8VHZv1xSy1xrkQbn4F6UnFHcvFn66TCk4ovHqqWk1R5zQUT9ms9Jc1fZ8/z9+OrE9x8TGX0QbVZhrEbbqtxH5OwNqdtTskLKI5uTdPCh5kLtJ6FgkRpAChMtFIGEZcRh7Dg9dZt2Y0iteuJ4EgWizZdWsukt8gDYadNyJ2AAc97Ix6EfXVShxuY2cFBZGJzJ0IyMEwAlN9FDdgG7L1VTX0xC9VyihCl/id7Ol0ta+o1k/KCz0JgGbqMhKortVroTT4viMzxDzvVRhL9OetWLiuhx904CVUhDF/OU2WBZELsn+S9Ph663wQqK3xRQADD70D2ZdAMUdsMISQVQMevdXY98IBW+NLoLwnLVI/LUX9MLvV4s6sT3PBzFPgCRwEqVQr0g7zFS6RB/V6fgxuOpSBxgOqusTmWmUe/7mWRORkCwXbFdj9d53fjncHBOYNFzH3zdxAAQapqh8C0IHlb/cOzV3pCS8jgZtVDyqpyoSpP5nbIgXar45C/M6UpyUU/k0P/tpeUZR+Wihho+Rb4r6wbwc51wp76RcfqjSy5/fpbF2XXn+TtDVfn9Y8uKPyDE9BnWHuUUz+tYXCwkPQ8mG0DSWdoIslfaHnx+Hen/6rAHwfPXKY+rVYsh0VU3hfZZB406HNiv5GENiCIQkEFjwraI4fdGwYSonfxeZDHrAoVVbSB+wak4wKnpngVX2XTK/sBIHNBYJVtfu5+jfXsqJ6wplho/AYZFzTGY2JcJT5g= 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)(336012)(186003)(16526019)(2906002)(8676002)(36756003)(47076005)(82310400003)(508600001)(2616005)(426003)(26005)(4326008)(81166007)(356005)(86362001)(6916009)(83380400001)(1076003)(8936002)(70586007)(6666004)(70206006)(36860700001)(316002)(5660300002)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 11:39:16.6862 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2cb48ec6-c201-40a4-d381-08d9a050e623 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: CH0PR12MB5281 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:21 -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 a universal method that models 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 | 123 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 6129f4e8ec9..87a8b87eee7 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -413,6 +413,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 than the TYPE type size. + If SIZE is smaller than 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; @@ -485,6 +497,43 @@ class dwarf_value final : 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 dereference " + "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. */ @@ -537,6 +586,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; @@ -659,6 +713,75 @@ 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; + + if (offset < addr_info->valaddr.size () + && offset + this_size <= addr_info->valaddr.size ()) + { + /* Using second buffer here because the copy_bitwise + doesn't support in place copy. */ + gdb::byte_vector temp_buf (this_size); + + memcpy (temp_buf.data (), addr_info->valaddr.data () + offset, + 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 dereference " + "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