From patchwork Wed Mar 12 16:11:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 107787 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63E95385840D for ; Wed, 12 Mar 2025 16:12:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63E95385840D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fWyolg2A X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 4D65D3858C5F for ; Wed, 12 Mar 2025 16:11:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D65D3858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4D65D3858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741795874; cv=none; b=NOQWhuD6WSUHzbLbn3Jkm1gJz8edhxWZPti94D1auSk2yqHbsH+BFIIsqucX3qXciN03dklbqd8J8ZgsQ5gCy/LRNq1dW/jIQvelJuJo/EuPh2pSaeMJWYt8zQRSpbXsFlm8/JcTNiDBkj7xw2hNA15ns24k5HqAVDGNcHSrFCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741795874; c=relaxed/simple; bh=3u4NjqEFuERFz52WS7Da9N5ZDMta23n4KqYnoRJd4tI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZLLcDtekSv1Oml05UOdjpHATWsLhl/fDAJLi4Dttsivf1ftptuIcMDAtQdITYtKFHbzZnJ5TXvJmzD1bHCV/DQp/ez3wXY3WCT1GjAGLVbDDl1SjAN3oLrj/RaSubIR5WWuiKQEWoT5bRjci5yLMYyxcC1WLJ4smCyHDsf/yYes= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D65D3858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741795874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5wvjWBXDmCK6azCgUlxzw/O0+GddxXkJzk39rWz9DaI=; b=fWyolg2AhEsDsuFFhDOV8yZ2/6qDcJg2BNCJJcgijcmO96zMzJUGtgfElAEy4HWU/Q9v9Y VRizl2vsWGUnEIPXhAX2AnJGAS1HXWZbK8/LndKrfXdTDbo28/98o1pYLE5l5dQIX8CcL/ P5FPZZ+jwW2JThCU4iwL1Aw76TG3SoI= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-nvN6v6rHPze5Nv4GUmBO8A-1; Wed, 12 Mar 2025 12:11:12 -0400 X-MC-Unique: nvN6v6rHPze5Nv4GUmBO8A-1 X-Mimecast-MFC-AGG-ID: nvN6v6rHPze5Nv4GUmBO8A_1741795872 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43d08915f61so8003915e9.2 for ; Wed, 12 Mar 2025 09:11:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741795871; x=1742400671; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5wvjWBXDmCK6azCgUlxzw/O0+GddxXkJzk39rWz9DaI=; b=rkqTItHhEnjdGdPGi10uoDdSxS5Bye5A1LZYJ21Wetdemewc348zlyadeQ4L611aB8 mUWkA2yumrLaTLmvf7NREj+o86YLq4sGMXOBAZFlr+cBQ5ed+iH/Bf/1tSa7R3Y+wYM4 BHKwqgj9q1T12aHzpE5ar+RnoNkuDCd06/WkwuVOqRuerl2JYofJWE7qPqIOeo/i9fhC 5Eq4xIu9N51eAm3VZkVHjRVe6yniRvTR80cwVdFLXBJkQCNkK+jvRm65rjMWEF7jqy41 4EZMfNkpOXWJCDWsRjGNgAb3UHs+yC5cvHKer/Wo20Z4xqNJnGIaUmVC0uwuvrTmP/PW AIOQ== X-Gm-Message-State: AOJu0YxBwCpbh8H9yaMExLn4m8HOmB3g2R24zy+3vd2m935DpmPuIyCw 39A29dm1N/lqWxClaNw8fHF6D8jGwNadTHmHntF4ZLxhuutWaPUT/y6Ut1R3Hzl758wvYwAko9e 3dylMff2iddYCfsa8agpySRWUFG/fbOepJ0XpT74qvE+XpFKCOif11II2n/RPyQO2qIAvI63iSY CRz626mobQIHo1lYRsED0kHz3o6B1FQeK+F2jcOKHeVrA= X-Gm-Gg: ASbGncurc1Abzhr0vlhe110PCuyiTDQsjUBL3Z6GsIU9m0yWo8fKg7D5GKlXzAQFVHN 5LkycD8PMh2G5CzV5rIGJ/4U/LPE9VdzvCEWtO8i+wxlSBjadEwbJeF4Z1k8WMzvBuQQZ2MXAYy xKb8M9ItbyRtna0cYioHO0DdpDeSfrKDRvIdB0Y4K31PfjZX4wn/zTo2d2a+uEy4RblnRoe0NNf cDnXUyu+wYXBV0SnGHm52WpAomsxtrd+Ab8cTomvklAsZmVrJTyjKA2MuIei457CdlrC6osW/by C5QNz2WkJ+BgQh1C1gnz7AyICL7N6vlmGOE= X-Received: by 2002:a05:600c:5107:b0:43d:1c3:cb2e with SMTP id 5b1f17b1804b1-43d01c3cc32mr83632785e9.17.1741795870544; Wed, 12 Mar 2025 09:11:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlr4Il+2pJN4bmrPAfA37p8IzYjJ+Xix/9Csfdd3FOlns3g9i5Pp42wT7KAsCkZAM8kFj/Ww== X-Received: by 2002:a05:600c:5107:b0:43d:1c3:cb2e with SMTP id 5b1f17b1804b1-43d01c3cc32mr83626705e9.17.1741795863414; Wed, 12 Mar 2025 09:11:03 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d0a75b290sm25586035e9.23.2025.03.12.09.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 09:11:03 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb: silence some 'Can't open file' warnings from core file loading Date: Wed, 12 Mar 2025 16:11:01 +0000 Message-ID: <2757ddaa89bf778689ef1bad206126e263ecf59f.1741795857.git.aburgess@redhat.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: k_1BEASZ7O-NA1y1V6GS6tU3CEEWXO4lnR7VGxxQfIU_1741795872 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, POISEN_SPAM_PILL, POISEN_SPAM_PILL_1, POISEN_SPAM_PILL_3, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org But PR gdb/20126 highlights a case where GDB emits a large number of warnings like: warning: Can't open file /anon_hugepage (deleted) during file-backed mapping note processing warning: Can't open file /dev/shm/PostgreSQL.1150234652 during file-backed mapping note processing warning: Can't open file /dev/shm/PostgreSQL.535700290 during file-backed mapping note processing warning: Can't open file /SYSV604b7d00 (deleted) during file-backed mapping note processing ... etc ... when opening a core file. This commit aims to avoid at least some of these warnings. What we know is that, for at least some of these cases, (e.g. the '(deleted)' mappings), the content of the mapping will have been written into the core file itself. As such, the fact that the file isn't available ('/SYSV604b7d00' at least is a shared memory mapping), isn't really relevant, GDB can still provide access to the mapping, by reading the content from the core file itself. What I propose is that, when processing the file backed mappings, if all of the mappings for a file are covered by segments within the core file itself, then there is no need to warn the user that the file can't be opened again. The debug experience should be unchanged, as GDB would have read from the in-core mapping anyway. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30126 --- gdb/corelow.c | 38 ++++++++- gdb/testsuite/gdb.base/corefile3.c | 118 +++++++++++++++++++++++++++ gdb/testsuite/gdb.base/corefile3.exp | 73 +++++++++++++++++ 3 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.base/corefile3.c create mode 100644 gdb/testsuite/gdb.base/corefile3.exp base-commit: a6bc00ff35a42d6d555aa8de97d427074151ae47 diff --git a/gdb/corelow.c b/gdb/corelow.c index 59c16677109..213b53808bd 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -540,11 +540,41 @@ core_target::build_file_mappings () /* If ABFD was opened, but the wrong format, close it now. */ abfd = nullptr; + /* When true, this indicates that the mapped contents of this + file are available within the core file. When false, some of + the mapped contents are not available. If the contents are + available within the core file, then we don't need to warn + the user if the file is no longer available. */ + 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) - m_core_unavailable_mappings.emplace_back (region.start, - region.end - - region.start); + { + /* Check to see if the region is available within the core + file. */ + bool found_region_in_core_file = false; + for (const target_section &ts : m_core_section_table) + { + if (ts.addr <= region.start && ts.endaddr >= region.end + && (ts.the_bfd_section->flags & SEC_HAS_CONTENTS) != 0) + { + found_region_in_core_file = true; + break; + } + } + + /* This region is not available within the core file. + Without the file available to read from it is not possible + for GDB to read this mapping within the inferior. Warn + the user about this case. */ + if (!found_region_in_core_file) + content_is_in_core_file_p = false; + + /* Record the unavailable region. */ + m_core_unavailable_mappings.emplace_back (region.start, + region.end + - region.start); + } /* And give the user an appropriate warning. */ if (build_id_mismatch) @@ -564,7 +594,7 @@ core_target::build_file_mappings () styled_string (file_name_style.style (), expanded_fname.get ())); } - else + else if (!content_is_in_core_file_p) { if (expanded_fname == nullptr || filename == expanded_fname.get ()) diff --git a/gdb/testsuite/gdb.base/corefile3.c b/gdb/testsuite/gdb.base/corefile3.c new file mode 100644 index 00000000000..16030dd017c --- /dev/null +++ b/gdb/testsuite/gdb.base/corefile3.c @@ -0,0 +1,118 @@ +/* Copyright 1992-2025 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This file is based on coremaker.c. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAPSIZE (8 * 1024) + +/* Global pointers so it's easier to access them from GDB. */ + +char *rw_mapping = NULL; +char *malloc_buffer = NULL; +char *anon_mapping = NULL; +char *shm_mapping = NULL; + +/* Create mappings within this process. */ + +void +mmapdata () +{ + /* Allocate and initialize a buffer that will be used to write the file + that is later mapped in. */ + + malloc_buffer = (char *) malloc (MAPSIZE); + for (int j = 0; j < MAPSIZE; ++j) + malloc_buffer[j] = j; + + /* Write the file to map in. */ + + int fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666); + assert (fd != -1); + write (fd, malloc_buffer, MAPSIZE); + + /* Now map the file into our address space as RW_MAPPING. */ + + rw_mapping + = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + assert (rw_mapping != (char *) MAP_FAILED); + + /* Verify that the original data and the mapped data are identical. If + not, we'd rather fail now than when trying to access the mapped data + from the core file. */ + + for (int j = 0; j < MAPSIZE; ++j) + assert (malloc_buffer[j] == rw_mapping[j]); + + /* Touch RW_MAPPING so the kernel writes it out into 'core'. */ + rw_mapping[0] = malloc_buffer[0]; + + /* Create yet another region which is allocated, but not written to. */ + anon_mapping = mmap (NULL, MAPSIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + assert (anon_mapping != MAP_FAILED); + + /* Create a shared memory mapping. */ + int sid = shmget (IPC_PRIVATE, MAPSIZE, IPC_CREAT | IPC_EXCL | 0777); + assert (sid != -1); + shm_mapping = (char *) shmat (sid, NULL, 0); + int res = shmctl (sid, IPC_RMID, NULL); + assert (res == 0); + assert (shm_mapping != MAP_FAILED); +} + +void +func2 () +{ +#ifdef SA_FULLDUMP + /* Force a corefile that includes the data section for AIX. */ + { + struct sigaction sa; + + sigaction (SIGABRT, (struct sigaction *)0, &sa); + sa.sa_flags |= SA_FULLDUMP; + sigaction (SIGABRT, &sa, (struct sigaction *)0); + } +#endif + + abort (); +} + +void +func1 () +{ + func2 (); +} + +int +main (void) +{ + mmapdata (); + func1 (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/corefile3.exp b/gdb/testsuite/gdb.base/corefile3.exp new file mode 100644 index 00000000000..08e417eec10 --- /dev/null +++ b/gdb/testsuite/gdb.base/corefile3.exp @@ -0,0 +1,73 @@ +# Copyright 2025 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Create a core file with some mapped regions, but ensure that the +# types region mean that the kernel should write the region into the +# core file (e.g. r/w file backed mapping). +# +# We then delete the file that backed the mapping and load the core +# file into GDB. +# +# GDB shouldn't warn about the file being missing. It doesn't matter; +# the file contents can all be found in the core file itself. + +require isnative +require {!is_remote host} + +standard_testfile + +if {[build_executable $testfile.exp $testfile $srcfile] == -1} { + return +} + +# Do not delete coremap.data when calling core_find. This file is +# required for GDB to find mmap'd data in the "accessing read-only +# mmapped data in core file" test. +set corefile [core_find $binfile {}] +if {$corefile == ""} { + return +} + +# Move coremap.data file out of the way, so it cannot be found when we +# later load the core file into GDB. +set data_filename \ + [standard_output_file coredir.[getpid]/coremmap.data] +set backup_filename \ + [standard_output_file coredir.[getpid]/coremmap.data.backup] +remote_exec host "mv ${data_filename} ${backup_filename}" + +clean_restart $binfile + +# Load the core file. The 'coremap.data' file cannot be found by GDB, +# but all the mappings for that file are r/w and should be present in +# the core file, so we shouldn't get any warnings from GDB about it. +set warnings_seen 0 +gdb_test_multiple "core-file $corefile" "core-file command" { + -re "^warning: Can't open file \[^\r\n\]+ during file-backed mapping note processing\r\n" { + incr warnings_seen + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { $warnings_seen == 0 } $gdb_test_name + } + -re "^\[^\r\n\]*\r\n" { + exp_continue + } +} + +# Check the mappings are all readable. +foreach label { rw_mapping malloc_buffer anon_mapping shm_mapping } { + gdb_test "x/1wd $label" "^$hex:\\s+$decimal" +}