From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2080.outbound.protection.outlook.com [40.107.220.80]) by sourceware.org (Postfix) with ESMTPS id 969193858D28 for ; Fri, 5 Nov 2021 11:39:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 969193858D28 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mke8JXve+1ICRA99cGnJEsNcxV7avHsQL6vLBfXXpJy0trh2i2oKzpULO8gdXXSNy8b+zJIriz4b3RseGbeSTil/5JIG7hLvqqN9Tm5KhO9yVdomdLmoqG4Uqi0VMXx/5w7jogSwgzwB5HpYxcTdZihXtoqClqqlNlKZ1ocUwhJKMzYTFfRAtboVszYMLmtfKKO+GIie6fBPo28cOhnCpiCeMHjMvfziNQ/tyWP2pstkvbyh1ww9p2N2Z5jlXeEHgnT2Ht/X6ZHQdUnzodTBVCucSQQWQ3eVVoGAMkpYXiHDFIqghJBf7MqiU6DAGD+S9E0wDLm5KhiCEmG3/qElpg== 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=lCVaUcVzteziuhd5yflx1r8oeUcBJ5PwgwN7kldcHzI=; b=kCVyHI/yUlSxbXyaiiGG76gjLoz9GChPFGhxe7ul7xgn2c3tmbUnthF5nFWfWdTXdEXhM7XzckHdBgJg9XchQHU108s0a5WXFZiuJSd9Dwb4qB8fXrgj4igL6BwO6KE9u2KLj2Ytmjkan2TmgKt+uyKnY1lYP3ETQOR38LJJpo9gQNaW+m+ds1XGSqndxkyzYJjmGoL4lwsczN36x8alXM1K1LbTjS1watzYoXgn45p2rmOCsIqKWYcqjFddNRYQT7AKNkgsejRXlTMIBAqmkslaxffzcuAJL8DipLgrhDQYyCU495oYyg+KKhCsGZIJSowj/TywwjfbHpqzcQvcPw== 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 MW4PR04CA0159.namprd04.prod.outlook.com (2603:10b6:303:85::14) by BYAPR12MB3192.namprd12.prod.outlook.com (2603:10b6:a03:139::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Fri, 5 Nov 2021 11:39:09 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::ee) by MW4PR04CA0159.outlook.office365.com (2603:10b6:303:85::14) 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:09 +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:09 +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:06 -0500 From: Zoran Zaric To: Subject: [PATCH v4 02/28] Add new memory access interface to expr.c Date: Fri, 5 Nov 2021 11:38:23 +0000 Message-ID: <20211105113849.118800-3-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: 55939de0-0d17-4fce-7579-08d9a050e197 X-MS-TrafficTypeDiagnostic: BYAPR12MB3192: 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: fUR3qa9E548+N2lQD4/dm/mjuf4v6MJBotvN36sKH6LlGsOFNg1gfpf6D32flrDpDC8JRCuaOSBJy4D1ThXQsco+CM0NPJK9bOoQSWUf3JZRRXbE+g2eQ12ZSnkH/BQ8yhyG2HtfbYXWAFQWNA0hlOsqcnhXo4Ucb0QpgfwqU+SA4BkLBO7R2cqrTLPJTdr+dGrPT5cLmEpkgj+wxC33BkunNqgVvLF0NuHACJc14H60K8Wi00/AByOVdM56IrEZa2/f/tgmot4hf+/I4IxbgZ03H2XiovQ0NNOylkDjwImsPY8eR3xAVc2xjRlu3gUVc67ax9xQNz2GlZQjpMh2RSQIexnzGbGJxWHaKR4jfobYa0m/Nn6K2RzzWGQTFC4S2fWCFAqm1F3qP8HUfwgMxtnmW3h9XTNQcuX9P/YR3pBy7c1qCVy0IAR97k8WKXjghV+PPj3lmiyuoa3gE2Cc3rZGoYiWdFqDu7avhxBl57ZnVp5bnvcNYBpnkcXUfEqNmosZbhLyTvOSGHq/ofV7YIxj9NET5lHnUeOdvQkbe/m2BnIsSWiXwxx9FnEZef/u2e1R4SdbbVeMDSKhdIqznshFwDXqIB/UcMHxf/JWHCGjx09h65ERPFZsvVl+g0cY8tObwPF3oJOris5kRke1vA2G2cyx2D3oByzamTmMG3qWf29Bf0rJzqYpLbd0ENCiSYw6EGwxPX2ABBv2LoACIvB22Jq2l/QcqmRjq9Oi8zw= 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)(82310400003)(186003)(86362001)(16526019)(336012)(356005)(81166007)(47076005)(5660300002)(36860700001)(508600001)(6916009)(26005)(36756003)(8936002)(6666004)(2906002)(1076003)(70206006)(4326008)(426003)(83380400001)(70586007)(8676002)(316002)(2616005)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 11:39:09.0564 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55939de0-0d17-4fce-7579-08d9a050e197 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: BYAPR12MB3192 X-Spam-Status: No, score=-12.3 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:14 -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 0ca8528298a..6419294a284 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