From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2047.outbound.protection.outlook.com [40.107.244.47]) by sourceware.org (Postfix) with ESMTPS id 68955385800B for ; Thu, 14 Oct 2021 09:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 68955385800B ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SrnuZo2iBvYCRxMHD09PCALxFDYHngEXZziK9RnhzKS1Qvy4LwjxkQ9sACqfYBKf81Rdk0XZ/E5iSCD+yB/ZRdBomBSXdw7T18YkKTO3wG4U+nGRgynayd2Eg7K+T9d7s7chQkLrSYppvbC/mDEAiP2sNe62kMbAM1gu0b5BGPaf9Pd1Zi7smMO8eODQGFcexkPAed0HTW7O0gzPMdjG9bJbXfTlaqmZzz5KvZXf85fTwzMRMds1NK69PbFJOuVxSAguYQHjaWuOO+6B7JxU1IS/IdCJxSpzkB6dhpYgR7xV01OJBrgxoTAA+VVkSqsu8hiizt6OKvhoxqyiakQLUA== 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=tK4Cc5N62u8RHReOK/qV7bYaJ0iQ8Vnjeqr7o2c630g=; b=itMA108BlaMdKE8hWXLqBKyPuBmswmztBxbicqmrAtzBnOHrzSJWDIBKHMaCWiAGzU0faHpktzQ92Gx9PzgSdGAR63ZEcx4nohsEdcN4Sv4stV9K25QNdfNZigb5qT2aWD2Spa4St7d7p0N/OG4SOHz3WqIsTKPy93GkEOMnYO6fEKc3uuj5SqnWLG9a2qR4ZAKqQzaL1Z2KY1X5IFWScDYVQtlYWAlJRPouhlVr/vToRn0KA3ecXsArMowcoRcXb/lMtxfxyeHKytwp+wOj8L0ZxWhyaXP6DRGGBADzivWGLE0BMly0jY0+5/iUSudjOFdpazZIAkugI3/mO85wkg== 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 DM5PR1401CA0011.namprd14.prod.outlook.com (2603:10b6:4:4a::21) by DM5PR12MB1900.namprd12.prod.outlook.com (2603:10b6:3:10f::18) 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:32:57 +0000 Received: from DM6NAM11FT012.eop-nam11.prod.protection.outlook.com (2603:10b6:4:4a:cafe::30) by DM5PR1401CA0011.outlook.office365.com (2603:10b6:4:4a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Thu, 14 Oct 2021 09:32:57 +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 DM6NAM11FT012.mail.protection.outlook.com (10.13.173.109) 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:32:56 +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:32:54 -0500 From: Zoran Zaric To: Subject: [PATCH v3 02/28] Add new memory access interface to expr.c Date: Thu, 14 Oct 2021 10:32:09 +0100 Message-ID: <20211014093235.69756-3-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: 58c49627-c0ba-4eb5-99f9-08d98ef59b02 X-MS-TrafficTypeDiagnostic: DM5PR12MB1900: 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: Gn+CrnDnIET1k+Xj61lHG03LbfjB64M/oCCwsnWL35DxRWEBs8t3VK0Bbt3J8tBk4sstORDNx+24+Ao9mTTzeQ/v67m5lYhy/4NWlrdWCMN3gH0lzYZcPLTexWYnNX7DpSGgz3DhH21O7kVIgUzf8+R/mdOpzqOrMayg4CVLLuJ6LaeTBjKgz3G0phDVe7yUxvo1kDxPrJZehREGkHWW/XVo/j231GuaFa/MpfFl2KARisdKRJxTkF5ugLKnUCaiXCGv9wHTuwLk8vnUM7x7ymeDSHFP93eFzNEQgbVKDISdfXANp1E7FA8v7RH8gIPJlU3RE1RyX3aX2cEJXCnp0hNL5hY9xYjWrq/TAJRyNmr49NQDHufwLP8IjCLA4LLRQ8JSgetVrNahD6Pgw/T8KRbRPYpSmiqCZuy3OhzOPhhEIVC6kPH5WQsVzOrRyPjj8bF4T9Pm/6MBKBvDNcJvm2/jSoIGTILS+4faH/w8fw+qZzDSlEL9VeHyyy/L42aArJeNLdZPL9DUiyPTDDT9LNGwTBEFMHYO1I3hD2usoMpEEtuR2Fm2HLDOgFprR8oGCDePwtCuCPb3RgRTkI3TC2W+b4KyQusV3gMv4AohKppAs7vHIyvNZyunGvONO0fpXE8D2ttyprhNltkSaKa6nSXnKaYaE85fb0IBsiA31XMu8AXFyv+zIPI7edPFPVr3FKjiWEN4/FT2DXIZ++JgH1jUqLvqXLeUbTZWNTQ1tQw= 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)(46966006)(36840700001)(6666004)(426003)(6916009)(2616005)(47076005)(1076003)(36860700001)(8676002)(81166007)(2906002)(82310400003)(83380400001)(44832011)(36756003)(4326008)(86362001)(5660300002)(508600001)(336012)(186003)(70586007)(8936002)(26005)(70206006)(16526019)(316002)(356005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2021 09:32:56.7606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58c49627-c0ba-4eb5-99f9-08d98ef59b02 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: DM6NAM11FT012.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1900 X-Spam-Status: No, score=-11.6 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:04 -0000 From: Zoran Zaric DWARF expression evaluator is currently using a few different interfaces for memory access: write_memory_with_notification, read_value_memory, read_memory. They all seem incosistent, while some of them even need a struct value typed argument to be present. This patch is simplifying that interface by replacing it with two new low level functions: read_from_memory and write_to_memory. The advantage of this new interface is that it behaves in the same way as the register access interface from the previous patch. Both of these have the same error returning policy, which will be usefull for the following patches. * dwarf2/expr.c (xfer_memory): New function. (read_from_memory): New function. (write_to_memory): New function. (rw_pieced_value): Now calls the read_from_memory and write_to_memory functions. --- gdb/dwarf2/expr.c | 190 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 146 insertions(+), 44 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 3dfba38bdb3..c0ca78ce236 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -33,6 +33,8 @@ #include "gdbsupport/underlying.h" #include "gdbarch.h" #include "objfiles.h" +#include "inferior.h" +#include "observable.h" /* Cookie for gdbarch data. */ @@ -189,6 +191,86 @@ write_to_register (frame_info *frame, int regnum, return; } +/* Helper for read_from_memory and write_to_memory. */ + +static void +xfer_memory (CORE_ADDR address, gdb_byte *readbuf, + const gdb_byte *writebuf, + size_t length, bool stack, int *unavailable) +{ + *unavailable = 0; + + target_object object + = stack ? TARGET_OBJECT_STACK_MEMORY : TARGET_OBJECT_MEMORY; + + ULONGEST xfered_total = 0; + + while (xfered_total < length) + { + ULONGEST xfered_partial; + + enum target_xfer_status status + = target_xfer_partial (current_inferior ()->top_target (), + object, NULL, + (readbuf != nullptr + ? readbuf + xfered_total + : nullptr), + (writebuf != nullptr + ? writebuf + xfered_total + : nullptr), + address + xfered_total, length - xfered_total, + &xfered_partial); + + if (status == TARGET_XFER_OK) + { + xfered_total += xfered_partial; + QUIT; + } + else if (status == TARGET_XFER_UNAVAILABLE) + { + *unavailable = 1; + return; + } + else if (status == TARGET_XFER_EOF) + memory_error (TARGET_XFER_E_IO, address + xfered_total); + else + memory_error (status, address + xfered_total); + } +} + +/* Read LENGTH bytes of memory contents starting at ADDRESS. + + The data read is copied to a caller-managed buffer BUF. STACK + indicates whether the memory range specified belongs to a stack + memory region. + + If the memory is unavailable, the UNAVAILABLE output is set. */ + +static void +read_from_memory (CORE_ADDR address, gdb_byte *buffer, + size_t length, bool stack, int *unavailable) +{ + xfer_memory (address, buffer, nullptr, length, stack, unavailable); +} + +/* Write LENGTH bytes of memory contents starting at ADDRESS. + + The data written is copied from a caller-managed buffer buf. STACK + indicates whether the memory range specified belongs to a stack + memory region. + + If the memory is unavailable, the UNAVAILABLE output is set. */ + +static void +write_to_memory (CORE_ADDR address, const gdb_byte *buffer, + size_t length, bool stack, int *unavailable) +{ + xfer_memory (address, nullptr, buffer, length, stack, unavailable); + + gdb::observers::memory_changed.notify (current_inferior (), address, + length, buffer); +} + struct piece_closure { /* Reference count. */ @@ -387,66 +469,86 @@ rw_pieced_value (value *v, value *from, bool check_optimized) bits_to_skip += p->offset; CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8; + bool in_stack_memory = p->v.mem.in_stack_memory; + int unavail = 0; if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0 && offset % 8 == 0) { /* Everything is byte-aligned; no buffer needed. */ - if (from != nullptr) - write_memory_with_notification (start_addr, - (from_contents - + offset / 8), - this_size_bits / 8); + if (from != NULL) + write_to_memory (start_addr, (from_contents + offset / 8), + this_size_bits / 8, in_stack_memory, + &unavail); else - read_value_memory (v, offset, - p->v.mem.in_stack_memory, - p->v.mem.addr + bits_to_skip / 8, - v_contents + offset / 8, - this_size_bits / 8); - break; - } - - this_size = bits_to_bytes (bits_to_skip, this_size_bits); - buffer.resize (this_size); - - if (from == nullptr) - { - /* Read mode. */ - read_value_memory (v, offset, - p->v.mem.in_stack_memory, - p->v.mem.addr + bits_to_skip / 8, - buffer.data (), this_size); - copy_bitwise (v_contents, offset, - buffer.data (), bits_to_skip % 8, - this_size_bits, bits_big_endian); + read_from_memory (start_addr, (v_contents + offset / 8), + this_size_bits / 8, in_stack_memory, + &unavail); } else { - /* Write mode. */ - if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) + this_size = bits_to_bytes (bits_to_skip, this_size_bits); + buffer.resize (this_size); + + if (from == NULL) { - if (this_size <= 8) + /* Read mode. */ + read_from_memory (start_addr, buffer.data (), + this_size, in_stack_memory, + &unavail); + if (!unavail) + copy_bitwise (v_contents, offset, + buffer.data (), bits_to_skip % 8, + this_size_bits, bits_big_endian); + } + else + { + /* Write mode. */ + if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) { - /* Perform a single read for small sizes. */ - read_memory (start_addr, buffer.data (), - this_size); + if (this_size <= 8) + { + /* Perform a single read for small sizes. */ + read_from_memory (start_addr, buffer.data (), + this_size, in_stack_memory, + &unavail); + } + else + { + /* Only the first and last bytes can possibly have + any bits reused. */ + read_from_memory (start_addr, buffer.data (), + 1, in_stack_memory, + &unavail); + if (!unavail) + read_from_memory (start_addr + this_size - 1, + &buffer[this_size - 1], 1, + in_stack_memory, &unavail); + } } - else + + if (!unavail) { - /* Only the first and last bytes can possibly have - any bits reused. */ - read_memory (start_addr, buffer.data (), 1); - read_memory (start_addr + this_size - 1, - &buffer[this_size - 1], 1); + copy_bitwise (buffer.data (), bits_to_skip % 8, + from_contents, offset, + this_size_bits, bits_big_endian); + write_to_memory (start_addr, buffer.data (), + this_size, in_stack_memory, + &unavail); } } + } - copy_bitwise (buffer.data (), bits_to_skip % 8, - from_contents, offset, - this_size_bits, bits_big_endian); - write_memory_with_notification (start_addr, - buffer.data (), - this_size); + if (unavail) + { + if (from == NULL) + mark_value_bits_unavailable (v, (offset + bits_to_skip % 8), + this_size_bits); + else + throw_error (NOT_AVAILABLE_ERROR, + _("Can't do read-modify-write to " + "update bitfield; containing word " + "is unavailable")); } } break; -- 2.17.1