From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YTH0LJIF7WiBiy4AWB0awg (envelope-from ) for ; Mon, 13 Oct 2025 09:58:42 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Hl/lXM4W; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A8EBC1E047; Mon, 13 Oct 2025 09:58:42 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 697E61E047 for ; Mon, 13 Oct 2025 09:58:40 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1FFE73858C40 for ; Mon, 13 Oct 2025 13:58:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FFE73858C40 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Hl/lXM4W Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012062.outbound.protection.outlook.com [40.93.195.62]) by sourceware.org (Postfix) with ESMTPS id A84FB3858D37 for ; Mon, 13 Oct 2025 13:58:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A84FB3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A84FB3858D37 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.93.195.62 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1760363882; cv=pass; b=H8oI5ENu3rHOBfJ0NzS7gShwTxb7VEZ5u1ijgPHEZ7Tv3JZjkqqgxiAd92dM6r0Aos65vj4GvKKGUVJw3H2xWOSm3L0oJsSmJPLFYSsCrLQ8oGUBxb3Gfs4Gm3Y3FOA31nl6gk8aX7rt/b1fJ25rU2/3u7RvOz7WF/lVzwGKsEs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1760363882; c=relaxed/simple; bh=Q4CDPP+zPT6EhNY/JEF05rnkg9BMFT+zyx0p0dwMzhM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=YYs/X3aszkRNxZrlyCwYZkc52CHMqn7R/t8s8pBI3Y1zDVAk3YH/dnURLd0vI8FhptSNLZGmHFd/Q44y/twS74/OSOZxNCXfoc+Tt4CcMF33psn8wUPffOEpbzCqTBRqcH5+lmDF/Fdjt6UrhyB/TYuTkNpZy72h5wgXJ7pFXHE= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A84FB3858D37 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AQ0HK8ogJs2dtp5FS7cg/0AL1eQ7pAFmcP4VoG1EOFGRtmCPGo12N+gw2k8f4Tp/08guM4c0hGXpe0jZ1e+7pO3nDYvhloS5UMstst1e6uym5L+vEW9Vo7GWYZQWJN2uda994vkG3xDjkJfToVFvycWO8FU5k1l8YU85njqzNN+C/noqVPybEEhzdCpQIn5bQ9I1EdRhBmmrQ42PIUjFpM3FGAlu1MxNYzVS5aFbLhiSx2dwHDLc6UEOHY3TK2MdeXCMhoWotKwrmDnlVbCSHe/6BBkGK07fxUjdCgssm9NzCAm94+z0vb/CBt7WbgjgTTd5d109XNn/DVJsrRUgag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=KMs4GYsr+wcM4S7pZZSnJ3oxPccOPaceGY89OTLGHXQ=; b=WzUgKgyg6G6ea4KIQCs8qoi6R4PS93lm+R1aLOM1Mw0OlE9P+Arqa6IdvfAWolxEW+Xg90MDwyc9dFHSuoJrgVk3sF/zZHJmjH5hgyxaTF5Gz0i/GuvGupInWLOHFWKnUTDt90lef8nUKlsTFfPbywzlNjmn6wIXvkuz2BSsr1m1zf7VphcXnDYA2wLueR278uAN2jI8x7wdmwPoh0WXJ4o8iADU9SBmzli90/tUGB8D1g3K8BtTdMWkXOwgU7bNLf/2l7Ocqb64sYphNdGMrojMTJfsavjiHIq2OxOjd0NZ9BKbpZnvIWa8dXFycjcHp57fm0fZqyXfBFKGJVyPvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KMs4GYsr+wcM4S7pZZSnJ3oxPccOPaceGY89OTLGHXQ=; b=Hl/lXM4WsYinTFogb5Fz/BUpXEuK+VMK4iO249e4I8tIglj3GMo5tPFkzVB4SQUnay9BoxscFxJRhU0L+yLYSS2D3B2xDuEiYCjFGFFLb/MxxsOJZ6N5r7F/rGNL4XiEXBJTLG/ZC34hn2QcYVZTRO1LNdzaKKQu3ng2XvaDwSc= Received: from MW4PR04CA0084.namprd04.prod.outlook.com (2603:10b6:303:6b::29) by PH7PR12MB6612.namprd12.prod.outlook.com (2603:10b6:510:210::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9203.12; Mon, 13 Oct 2025 13:57:58 +0000 Received: from CO1PEPF000066EA.namprd05.prod.outlook.com (2603:10b6:303:6b:cafe::74) by MW4PR04CA0084.outlook.office365.com (2603:10b6:303:6b::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9203.12 via Frontend Transport; Mon, 13 Oct 2025 13:57:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CO1PEPF000066EA.mail.protection.outlook.com (10.167.249.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.7 via Frontend Transport; Mon, 13 Oct 2025 13:57:58 +0000 Received: from khazad-dum (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 13 Oct 2025 06:57:56 -0700 Date: Mon, 13 Oct 2025 14:57:48 +0100 From: Lancelot SIX To: Andrew Burgess CC: , Tom Tromey Subject: Re: [PATCHv2 2/3] gdb: make structured core file mappings processing global Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EA:EE_|PH7PR12MB6612:EE_ X-MS-Office365-Filtering-Correlation-Id: cd14a554-dec1-461a-af40-08de0a608418 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?SkRjK0l0WDg1Zm5jL1QrSE5idXBsUG9sM0VjVnZrSEJkV3c5b29hazFDZEpP?= =?utf-8?B?UjhjS1B4dGM2ZnFYRzhtZUMvRmlGeVcvb2cwYkNPRXV3T096T0FZbFVUWUp3?= =?utf-8?B?N0V0SFdKWUN4bGdiMjlFcFhEYUg1ZkxUbnVaNE9WWWs2T3ZJU1Y1cW83b0gy?= =?utf-8?B?VDd2bDh2aWttZUY4ZmVvaCtVSEVvS1pmejVzQjRJZjVPYXhVYnJEUSsyekFE?= =?utf-8?B?MVpRYXRsYWJGR0R3QVZpUG1leXFhT0hXN3VVVjJwaThEN0tGRkZCSVlpeG1B?= =?utf-8?B?VWIwTnZ1VUI0SzRtdEJ4cGUyekorUlBmL0dCMGs3VzRHVlc3cnpZVVg5SkI0?= =?utf-8?B?ZTkxVmR2WEY3Z0R5WGtaaGpSVmQ1MjlLSEczS29VTFFyRGV2K3FsVG05RkVE?= =?utf-8?B?Z253aGFXSXBybkozZ3dtQ1M0UThGbWdMdVNlRUpMcTR4TzVEY0h5L05tVHZx?= =?utf-8?B?YjFJcmpzRWhZVXdyUDhUNWx2SlR2bzd2ZmY5MTVscitiMVlTamh5MHRLMTls?= =?utf-8?B?U3VjcHhFL0NUd293L1lkU2J4N1JHdTdDaHZUWEduOEEybHk5MVA4enZGamhY?= =?utf-8?B?dWhiRWJYSG1Jcnh1N0lLL1ZTR3EvejZMdlZPRE5LQ2tLeHN3TGZLTWVhSWxE?= =?utf-8?B?Mm1rSm5FOC9IaEpGbnVKVzlTZjFUWXR1bVpZd2ZZSnIvRUNaWjRQNFE1VVFL?= =?utf-8?B?UmhFY3pCM3A1NXBiWEdDdmRwV1dDb1UxMnF3UmdpZDZMSDR1NXNhL1JmRW10?= =?utf-8?B?dmJVMmQrV3VtRHRyUmZqdmt6OVFEZEF6KzhnQ3RONGkxaWRHZ21tcjJLUGNq?= =?utf-8?B?MWVqb0JRdE9haktmRTZnSUNkeEgwNWordlFmUVdFR29yUnNHNnlNNnUwblRK?= =?utf-8?B?NmVnajJSblFPOWJKRFRjTmZYV3J6YjFzS2NGMTZWUm5kVGpZbTRob0wyY1VU?= =?utf-8?B?aUxSSXEvUXVwWkJWbHFvM29zTlJLK0ltUXlJZnRCLy8rQUM1eWwyb1NZM1VN?= =?utf-8?B?TW5SZGRFZzYwaDMzMnZmcE5yeStvS0ZjNDB1TkI0WnRwZWFSUnNWWitFa0dX?= =?utf-8?B?RzRTWm1IYlZCU1NTS3NZVW9zQWNEZDFiTjQ2d1QyS1dtY1FtK1ZacE5VcUtK?= =?utf-8?B?K1dYa0hXTDNIUGtSQWZrRW5ma0toNnI1cFRjTjBtUThkYTdNaGhDZWJ3OUN2?= =?utf-8?B?RUZmNytSWVN5eVhzdDl1NjRMTktSa0tJdU5LbmxyQjNQbktkT3R0QjJTL1R6?= =?utf-8?B?MkxIYWJtbGhJYnlWdUlkSjZ0a3c0M1lwb0NCUUZIMkJ1alF2eUx5WjVkV3lY?= =?utf-8?B?eXd3VHBCZ0JiQlR2Y0Q4N1hhNlQrMjFYNVhxZUY4RHFENjlmS1BPSi9kODVG?= =?utf-8?B?ZEZUc01sUXVSSUdYUXdLOXJnR3lrQXoranB4QTQzaDFhOWZtdTlzRkR2T2dG?= =?utf-8?B?OHd1NjRZQkhuSmV5S0pTMFQ3M2xxZ2x6Si95d3RleHpNTzdPL09JaCs3OGhj?= =?utf-8?B?OGJhQktOZWpwS3RXSENEb1puK0IranZrSExLTjdYakFCUHFtd0svU3BEOWJm?= =?utf-8?B?WVhVdzJDa3VpUmlwVmZOYU8zNUxlNWQvVVNUT2I0cldldUlTUTd4Y2ZteGho?= =?utf-8?B?NlVzanIzRUdCRndtb3MycmRUeUJseHZMQm1yRzZMUVVMTnNMVGpOOHduM2dl?= =?utf-8?B?VmVMcEhSNGJ3U1hXaEc5UnAweDFVOXJ1RnVEZEtkVWdhNDFWTFJlbmR4QkZK?= =?utf-8?B?bTlibFpNVkdCOWlpNmpGdVRXS0JUMVNEUU1DakdSYjJTdGtKdGxDblE3bkR0?= =?utf-8?B?MSs4L25RRy9TVEFyNFJLdERYeEo4SlBKRzhxajRyZ1M5Z0p6S1pVam5vSFI2?= =?utf-8?B?TzJyWUo3b2oyMHlvMlcwYU8zSG12V3BTYmM1ck9DeUtLRzN6RlhueWdkR1o5?= =?utf-8?B?QnhTN211UzJyNlpBSEorLzZKQzNkbmo3bVI1R21QbVhndU1NbFlVV01wdXJ1?= =?utf-8?Q?GbaM1jspVR939Lr+07dEXdfo7tOhpc=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2025 13:57:58.1191 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd14a554-dec1-461a-af40-08de0a608418 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000066EA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6612 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi Andrew, I think there is an issue with this patch. When running with this and address sanitizer, I end-up with use-after-free errors. See below for what I think is the issue. On Tue, Sep 23, 2025 at 02:44:07PM +0100, Andrew Burgess wrote: > In corelow.c, within core_target::build_file_mappings, we have code > that wraps around a call to gdbarch_read_core_file_mappings and > provides more structure to the results. > > Specifically, gdbarch_read_core_file_mappings calls a callback once > for every region of every mapped file. The wrapper code groups all of > the mappings for one file into an instance of 'struct mapped_file', > this allows all of the mapped regions to be associated with the > build-id and filename of a file. > > In the next commit I plan to make this information available via the > Python API, and so I need to allow access to this structured wrapping > outside of corelow.c. > > This commit renames 'struct mapped_file' to 'struct core_mapped_file' > and moves the struct into gdbcore.h. Then a new global function > gdb_read_core_file_mappings is created into which I move the code to > build the structured data. > > Then corelow.c is updated to call gdb_read_core_file_mappings. > > This commit does not extend the Python API, that is for the next > commit. > > There should be no user visible changes after this commit. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32844 > > Approved-By: Tom Tromey > --- > gdb/corelow.c | 218 +++++++++++++++++++++++++++----------------------- > gdb/gdbcore.h | 43 ++++++++++ > 2 files changed, 160 insertions(+), 101 deletions(-) > > diff --git a/gdb/corelow.c b/gdb/corelow.c > index 2f202dc1fbf..ee97e29556e 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -366,108 +366,27 @@ core_target::core_target () > void > core_target::build_file_mappings () > { > - /* Type holding information about a single file mapped into the inferior > - at the point when the core file was created. Associates a build-id > - with the list of regions the file is mapped into. */ > - struct mapped_file > - { > - /* Type for a region of a file that was mapped into the inferior when > - the core file was generated. */ > - struct region > - { > - /* Constructor. See member variables for argument descriptions. */ > - region (CORE_ADDR start_, CORE_ADDR end_, CORE_ADDR file_ofs_) > - : start (start_), > - end (end_), > - file_ofs (file_ofs_) > - { /* Nothing. */ } > - > - /* The inferior address for the start of the mapped region. */ > - CORE_ADDR start; > - > - /* The inferior address immediately after the mapped region. */ > - CORE_ADDR end; > - > - /* The offset within the mapped file for this content. */ > - CORE_ADDR file_ofs; > - }; > - > - /* If not nullptr, then this is the build-id associated with this > - file. */ > - const bfd_build_id *build_id = nullptr; > - > - /* If true then we have seen multiple different build-ids associated > - with the same filename. The build_id field will have been set back > - to nullptr, and we should not set build_id in future. */ > - bool ignore_build_id_p = false; > - > - /* All the mapped regions of this file. */ > - std::vector regions; > - }; > - > gdb::unordered_map bfd_map; > gdb::unordered_set unavailable_paths; > > /* All files mapped into the core file. The key is the filename. */ > - gdb::unordered_map mapped_files; > + std::vector mapped_files > + = gdb_read_core_file_mappings (m_core_gdbarch, > + current_program_space->core_bfd ()); > > - /* See linux_read_core_file_mappings() in linux-tdep.c for an example > - read_core_file_mappings method. */ > - gdbarch_read_core_file_mappings (m_core_gdbarch, > - current_program_space->core_bfd (), > - > - /* After determining the number of mappings, read_core_file_mappings > - will invoke this lambda. */ > - [&] (ULONGEST) > - { > - }, > - > - /* read_core_file_mappings will invoke this lambda for each mapping > - that it finds. */ > - [&] (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, > - const char *filename, const bfd_build_id *build_id) > - { > - /* Architecture-specific read_core_mapping methods are expected to > - weed out non-file-backed mappings. */ > - gdb_assert (filename != nullptr); > - > - /* Add this mapped region to the data for FILENAME. */ > - mapped_file &file_data = mapped_files[filename]; > - file_data.regions.emplace_back (start, end, file_ofs); > - if (build_id != nullptr && !file_data.ignore_build_id_p) > - { > - if (file_data.build_id == nullptr) > - file_data.build_id = build_id; > - else if (!build_id_equal (build_id, file_data.build_id)) > - { > - warning (_("Multiple build-ids found for %ps"), > - styled_string (file_name_style.style (), filename)); > - file_data.build_id = nullptr; > - file_data.ignore_build_id_p = true; > - } > - } > - }); > - > - /* Get the build-id of the core file. */ > - const bfd_build_id *core_build_id > - = build_id_bfd_get (current_program_space->core_bfd ()); > - > - for (const auto &[filename, file_data] : mapped_files) > + for (const core_mapped_file &file_data : mapped_files) > { > - /* If this mapped file has the same build-id as was discovered for > - the core-file itself, then we assume this is the main > - executable. Record the filename as we can use this later. */ > - if (file_data.build_id != nullptr > - && m_expected_exec_filename.empty () > - && build_id_equal (file_data.build_id, core_build_id)) > - m_expected_exec_filename = filename; > + /* If this mapped file is marked as the main executable then record > + the filename as we can use this later. */ > + if (file_data.is_main_exec && m_expected_exec_filename.empty ()) > + m_expected_exec_filename = file_data.filename; > > /* Use exec_file_find() to do sysroot expansion. It'll > also strip the potential sysroot "target:" prefix. If > there is no sysroot, an equivalent (possibly more > canonical) pathname will be provided. */ > gdb::unique_xmalloc_ptr expanded_fname > - = exec_file_find (filename.c_str (), nullptr); > + = exec_file_find (file_data.filename.c_str (), nullptr); > > bool build_id_mismatch = false; > if (expanded_fname != nullptr && file_data.build_id != nullptr) > @@ -509,7 +428,7 @@ core_target::build_file_mappings () > { > abfd = find_objfile_by_build_id (current_program_space, > file_data.build_id, > - filename.c_str ()); > + file_data.filename.c_str ()); > > if (abfd != nullptr) > { > @@ -527,7 +446,7 @@ core_target::build_file_mappings () > } > > std::vector ranges; > - for (const mapped_file::region ®ion : file_data.regions) > + for (const core_mapped_file::region ®ion : file_data.regions) > ranges.emplace_back (region.start, region.end - region.start); > > if (expanded_fname == nullptr > @@ -545,7 +464,7 @@ core_target::build_file_mappings () > bool content_is_in_core_file_p = true; > > /* Record all regions for this file as unavailable. */ > - for (const mapped_file::region ®ion : file_data.regions) > + for (const core_mapped_file::region ®ion : file_data.regions) > { > /* Check to see if the region is available within the core > file. */ > @@ -577,33 +496,33 @@ core_target::build_file_mappings () > if (build_id_mismatch) > { > if (expanded_fname == nullptr > - || filename == expanded_fname.get ()) > + || file_data.filename == expanded_fname.get ()) > warning (_("File %ps doesn't match build-id from core-file " > "during file-backed mapping processing"), > styled_string (file_name_style.style (), > - filename.c_str ())); > + file_data.filename.c_str ())); > else > warning (_("File %ps which was expanded to %ps, doesn't match " > "build-id from core-file during file-backed " > "mapping processing"), > styled_string (file_name_style.style (), > - filename.c_str ()), > + file_data.filename.c_str ()), > styled_string (file_name_style.style (), > expanded_fname.get ())); > } > else if (!content_is_in_core_file_p) > { > if (expanded_fname == nullptr > - || filename == expanded_fname.get ()) > + || file_data.filename == expanded_fname.get ()) > warning (_("Can't open file %ps during file-backed mapping " > "note processing"), > styled_string (file_name_style.style (), > - filename.c_str ())); > + file_data.filename.c_str ())); > else > warning (_("Can't open file %ps which was expanded to %ps " > "during file-backed mapping note processing"), > styled_string (file_name_style.style (), > - filename.c_str ()), > + file_data.filename.c_str ()), > styled_string (file_name_style.style (), > expanded_fname.get ())); > } > @@ -617,7 +536,7 @@ core_target::build_file_mappings () > abfd.get ()); > > /* Create sections for each mapped region. */ > - for (const mapped_file::region ®ion : file_data.regions) > + for (const core_mapped_file::region ®ion : file_data.regions) > { > /* Make new BFD section. All sections have the same name, > which is permitted by bfd_make_section_anyway(). */ > @@ -653,7 +572,7 @@ core_target::build_file_mappings () > soname = gdb_bfd_read_elf_soname (actual_filename); > } > > - m_mapped_file_info.add (soname.get (), filename.c_str (), > + m_mapped_file_info.add (soname.get (), file_data.filename.c_str (), > actual_filename, std::move (ranges), > file_data.build_id); > } > @@ -2163,6 +2082,103 @@ mapped_file_info::lookup (const char *filename, > > /* See gdbcore.h. */ > > +std::vector > +gdb_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd) > +{ > + std::vector results; > + > + /* A map entry used while building RESULTS. */ > + struct map_entry > + { > + explicit map_entry (core_mapped_file *ptr) > + : file_data (ptr) > + { /* Nothing. */ } > + > + /* Points to an entry in RESULTS, this allows entries to be quickly > + looked up and updated as new mappings are read. */ > + core_mapped_file *file_data = nullptr; > + > + /* If true then we have seen multiple different build-ids associated > + with the filename of FILE_DATA. The FILE_DATA->build_id field will > + have been set to nullptr, and we should not set FILE_DATA->build_id > + in future. */ > + bool ignore_build_id_p = false; > + }; > + > + /* All files mapped into the core file. The key is the filename. */ > + gdb::unordered_map mapped_files; > + > + /* Get the build-id of the core file. At least on Linux, this will be > + the build-id for the main executable. If other targets add the > + gdbarch_read_core_file_mappings method, then it might turn out that > + this logic is no longer true, in which case this might need to move > + into the gdbarch_read_core_file_mappings method. */ > + const bfd_build_id *core_build_id = build_id_bfd_get (cbfd); > + > + /* See linux_read_core_file_mappings() in linux-tdep.c for an example > + read_core_file_mappings method. */ > + gdbarch_read_core_file_mappings (gdbarch, cbfd, > + /* After determining the number of mappings, read_core_file_mappings > + will invoke this lambda. */ > + [&] (ULONGEST) > + { > + }, > + > + /* read_core_file_mappings will invoke this lambda for each mapping > + that it finds. */ > + [&] (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, > + const char *filename, const bfd_build_id *build_id) > + { > + /* Architecture-specific read_core_mapping methods are expected to > + weed out non-file-backed mappings. */ > + gdb_assert (filename != nullptr); > + > + /* Add this mapped region to the data for FILENAME. */ > + auto iter = mapped_files.find (filename); > + if (iter == mapped_files.end ()) > + { > + /* Create entry in results list. */ > + results.emplace_back (); > + > + /* The entry to be added to the lookup map. */ > + map_entry entry (&results.back ()); This bit is (I think) invalid. You are taking the address of an element in the vector to place it in the map_entry cache (mapped_files). However, taking the address of the element of a vector in this case is wrong. As you grow the vector (results.emplace_back), the backing storage might be grown, and as a consequence values moved and existing pointers/references/iterators are invalidated. Using a list could be a drop-in replacement, or storing the index in the vector rather than the element address would fix the issue. I can submit a patch doing either of those, depending on what you prefer. Best, Lancelot. > + entry.file_data->filename = filename; > + > + /* Add entry to the quick lookup map and update ITER. */ > + auto inserted_result > + = mapped_files.insert ({filename, std::move (entry)}); > + gdb_assert (inserted_result.second); > + iter = inserted_result.first; > + } > + > + core_mapped_file &file_data = *iter->second.file_data; > + bool &ignore_build_id_p = iter->second.ignore_build_id_p; > + > + file_data.regions.emplace_back (start, end, file_ofs); > + if (build_id != nullptr && !ignore_build_id_p) > + { > + if (file_data.build_id == nullptr) > + file_data.build_id = build_id; > + else if (!build_id_equal (build_id, file_data.build_id)) > + { > + warning (_("Multiple build-ids found for %ps"), > + styled_string (file_name_style.style (), filename)); > + file_data.build_id = nullptr; > + ignore_build_id_p = true; > + } > + } > + > + if (build_id != nullptr > + && core_build_id != nullptr > + && build_id_equal (build_id, core_build_id)) > + file_data.is_main_exec = true; > + }); > + > + return results; > +} > + > +/* See gdbcore.h. */ > + > std::optional > core_target_find_mapped_file (const char *filename, > std::optional addr) > diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h > index e0e3843c97b..23432ecbd07 100644 > --- a/gdb/gdbcore.h > +++ b/gdb/gdbcore.h > @@ -258,4 +258,47 @@ std::optional > core_target_find_mapped_file (const char *filename, > std::optional addr); > > +/* Type holding information about a single file mapped into the inferior > + at the point when the core file was created. Associates a build-id > + with the list of regions the file is mapped into. */ > +struct core_mapped_file > +{ > + /* Type for a region of a file that was mapped into the inferior when > + the core file was generated. */ > + struct region > + { > + /* Constructor. See member variables for argument descriptions. */ > + region (CORE_ADDR start_, CORE_ADDR end_, CORE_ADDR file_ofs_) > + : start (start_), > + end (end_), > + file_ofs (file_ofs_) > + { /* Nothing. */ } > + > + /* The inferior address for the start of the mapped region. */ > + CORE_ADDR start; > + > + /* The inferior address immediately after the mapped region. */ > + CORE_ADDR end; > + > + /* The offset within the mapped file for this content. */ > + CORE_ADDR file_ofs; > + }; > + > + /* The filename as recorded in the core file. */ > + std::string filename; > + > + /* If not nullptr, then this is the build-id associated with this > + file. */ > + const bfd_build_id *build_id = nullptr; > + > + /* All the mapped regions of this file. */ > + std::vector regions; > + > + /* True if this is the main executable. */ > + bool is_main_exec = false; > +}; > + > +extern std::vector gdb_read_core_file_mappings > + (struct gdbarch *gdbarch, struct bfd *cbfd); > + > #endif /* GDB_GDBCORE_H */ > -- > 2.47.1 > >