From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yGb7L3b+PGAGJAAAWB0awg (envelope-from ) for ; Mon, 01 Mar 2021 09:47:18 -0500 Received: by simark.ca (Postfix, from userid 112) id BE0331EF82; Mon, 1 Mar 2021 09:47:18 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7FB261EF64 for ; Mon, 1 Mar 2021 09:47:16 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A8F4393A41F; Mon, 1 Mar 2021 14:47:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A8F4393A41F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614610035; bh=v4L/+qGyt5edLaM7fucUTsY1OgQ7SGePs4OauLZokBM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Gl80gTpAGO/l3KrktS1bFd/3BlArUa3HKXHhGQpt7pNidtkPA947BjXTtxPAuPvPP 438cA+F5ZUukGQjwDhM2UlIuSk4tNg+JQhuJgXTW8JYHyN8uEW39spEs+gW4VFzxZD GUuj47G7B1Srjm31ftlaI+noS7Pc23Ejg3EdSQ1k= Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2070.outbound.protection.outlook.com [40.107.244.70]) by sourceware.org (Postfix) with ESMTPS id 0BCBB393A40F for ; Mon, 1 Mar 2021 14:47:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0BCBB393A40F ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FHKHW4EMBwV7VhHzp62WZeZDFNJ9KQDCDfgdsp4Y+iqwQJBo+wxDBagiqZco0w2KBzreaOcWMjVmLMoy3yZ1Tmm/augp2M3YhvgxcpsS8Bz1G57/xBbX4GwjgbX1Cxfl8IMPymG71UjsNl0Ut4SOxa2l4COxWLGbMmrFlc6hS4V0XVG3WbF9PCahypZMSO+ABW4KzQycXMF0D4jCr127S3KMID7X55QtM3B6fgLeQL/RNlE4Z36Fnn4yYc+FDbyWwQd44xdsblrQRi33NxtQqy+UWwJ2FYZGz6iUIahmLjrvypZmPsSsuRYHTVYLcR2Rww9bLvB5yc+xCzJGYScR7A== 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-SenderADCheck; bh=v4L/+qGyt5edLaM7fucUTsY1OgQ7SGePs4OauLZokBM=; b=bG5Gu+EfrIG9AHCnEoac7aw7Euvam6vi1N+bTK6/XDmztdcvhG4W/UU1yqw6GdUP+Vvhkw9+Mm+26WFzy79m4vFGka/3g3IqNw7VW2LbFtJYyvZzC4zq0uz/YtKM6EZC5Gux/qesmIauA8hEtUS5/LcpA5TZo0vzt4FmuI76ob/Fk5Cl53K7Dp/Q2WHtNrTdfjaVt6UUHLOrZ/5l/JwbySpTTBBHP4xrBmgHEkwprwosirHHxGDN5n438vFE011+dgck8vwhs5eN52iSoZe/FCh/5615Jbtw6PI/134PUa8MET/1BKKQFaLGdUjJ/y/VoONEt6S4ELzuJrB6LYZILQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none Received: from DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) by DM6PR12MB3676.namprd12.prod.outlook.com (2603:10b6:5:1c7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Mon, 1 Mar 2021 14:47:01 +0000 Received: from DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::31d8:f503:f7b2:f44]) by DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::31d8:f503:f7b2:f44%3]) with mapi id 15.20.3868.033; Mon, 1 Mar 2021 14:47:01 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 19/43] Add new memory access interface to expr.c Date: Mon, 1 Mar 2021 14:45:56 +0000 Message-Id: <20210301144620.103016-20-Zoran.Zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210301144620.103016-1-Zoran.Zaric@amd.com> References: <20210301144620.103016-1-Zoran.Zaric@amd.com> Content-Type: text/plain X-Originating-IP: [2a00:23c7:5a85:6801:b4ed:fe7b:8064:d4d] X-ClientProxiedBy: AM0PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:208:be::14) To DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a00:23c7:5a85:6801:b4ed:fe7b:8064:d4d) by AM0PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:208:be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 14:47:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 54bbcd12-8010-4fb1-d783-08d8dcc0df01 X-MS-TrafficTypeDiagnostic: DM6PR12MB3676: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xNalI4hkdgmXA79vgtturZgUAqGLoJk905z8TTOgnhBIFB5IDjbGHWGzjG/+TiS9+fX9neTcIkTOfNPG7RksQJ3CsmsGpSwbIfslnsZRDr3PzY8F2TIrLs7Cno/yalMzqiLj2fXw70FaAupHuk9ojBN2DDnoGMp6Sm6dRzJgPrVRYvC8eyumn65hEMaQRzfqEFSD/BcJj408tNizutJTNRiwy9hiuySO1D3jm1BeGIQe6N1Q5fb/JGCldHvi2+hPSUc0Jpt2tuuS5vH6Qo8P2H06cisj8DmJEGv5GJD2FQUYjmMQvMQDxoAr/clsRqEZjiMhFoqppiKrnzzH6VKB4tDd62KIVKIx4Sq+dK6b6Pq2kWoyaTnRl33/4lq2uy1PY/OyAEd12TpFoJpdohpASnh3POCEDZdQEnbQi1IxrAC4Qh8PDMRGTEdhJORtd/mQLJNKh7P4tBotNBAPyok5ry33NAhcK0R16bXN1narfqWKYdaP3u2uesAutb0FFp7FbJXdwJmTetcuA90FqvkXowe04V7RNTM7WGAKAEhXBwRcPaYhHb08MAKy2HemHInzLQ+2KMrVT/r5u4DVqwhQEA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB2762.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(396003)(346002)(136003)(39860400002)(6666004)(16526019)(1076003)(83380400001)(2616005)(69590400012)(2906002)(186003)(36756003)(66946007)(316002)(66476007)(8936002)(52116002)(86362001)(6506007)(478600001)(5660300002)(4326008)(6486002)(8676002)(6916009)(6512007)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Ap7Eva8MNqDP1xJ9mA/PPqBmr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yyF/HLd13TpGi18glLrr4hAY0S0ej8xTBuAXrzfTmXlMfK/JGiuK6yoOG5K?= =?us-ascii?Q?/UhgglO0w6Yf3Hjvwy+yEeElGemeDXZ+69bcHGCLYNHg3Z2k5ygi+pGg8E0p?= =?us-ascii?Q?XDU+bJl69GlvzYZUm9nsHfQSJOIUjUr52dKg2OAmG/k4HAwk0Juxbe3dUWAU?= =?us-ascii?Q?XivAHWsk5CgNSUFp3qPPoRxMqH2E7dc45ui2jMMIJfJqV6lnnI1pfSTBAYb2?= =?us-ascii?Q?aZZPdTN9OYX265w+ry+iAPRCQbJE9Wzf6B9MUUetGcUDAcoSbbie1E16WnoI?= =?us-ascii?Q?HsdcKM9oA6w4f/ZqDVruSNc2B9vQj225dYpxUxTlkhOup8IH+NOZ3pwNFFfY?= =?us-ascii?Q?SWQNzjFZSPQQKogMglnDFr6LN2NqNJbo0KQDINR+nK6gM1PX2QqgIURClavh?= =?us-ascii?Q?BpsxfYoOeau8hNTygv5aBl5zuGW6pCCAKqViSSXmXM+pROic8Qny71DlnVjV?= =?us-ascii?Q?4cYBPwKjDO1/y9Zsk6tgCZokbS39?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54bbcd12-8010-4fb1-d783-08d8dcc0df01 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 14:47:00.9064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bi47NWYKONqf/B4oZL68oJHSDWXsLPvxWN5tPus2UANuHDaNIZOnhuUenqf3B9O/gJTV3zE7lSeqMY1R5MCpOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3676 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: , From: Zoran Zaric via Gdb-patches Reply-To: Zoran Zaric Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 | 187 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 144 insertions(+), 43 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 5a1fd5b941f..1abece7d173 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -32,6 +32,8 @@ #include "frame.h" #include "gdbsupport/underlying.h" #include "gdbarch.h" +#include "inferior.h" +#include "observable.h" /* Cookie for gdbarch data. */ @@ -196,6 +198,85 @@ write_to_register (struct 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; + + enum 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_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. */ @@ -381,66 +462,86 @@ rw_pieced_value (struct value *v, struct value *from) 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 != NULL) - write_memory_with_notification (start_addr, - (from_contents - + offset / 8), - this_size_bits / 8); + 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 == NULL) - { - /* 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