From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SPS1DClRomkGQw0AWB0awg (envelope-from ) for ; Fri, 27 Feb 2026 21:21:29 -0500 Received: by simark.ca (Postfix, from userid 112) id 194161E08D; Fri, 27 Feb 2026 21:21:29 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 350961E08D for ; Fri, 27 Feb 2026 21:21:28 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 796CA4B9DB4F for ; Sat, 28 Feb 2026 02:21:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 796CA4B9DB4F Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 2066A4BA23C2 for ; Sat, 28 Feb 2026 02:21:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2066A4BA23C2 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2066A4BA23C2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772245263; cv=none; b=sKlA5ZdciLBFHw1Slku5Ha9Gio/R/36hUs+73uZhvpWwG0BQ0ssjRR4Og4i9qu0gPJjlr4HNy46HJDBXGtdFXENAULHscN7rOR3gXhnSqaPmA78pwVwJS9tqsSyOKGEFwXvq6VxvtrER59+hA4tC0JDfQeNK78oNrvb69xaIkCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772245263; c=relaxed/simple; bh=XHtmI3iL0f8FDa3HBLnRcorFPkegzLs/2GZIZKkYCIg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rvgh0UQJkpauP1ALkqshcFyzHpFp+n29HB75o6LV4X1o51U8M54+kPR6baXSVdxMr8HWhscLnBA6gDkw57C3M+RPMYECUYY05vez+tfb+wMvKgM3SccKHByNX5QUGC0fV8+5zgtYVawUM2Akt4o6P3X2B5g8MBew6A38ijyyWE8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2066A4BA23C2 Received: by simark.ca (Postfix) id E85251E08D; Fri, 27 Feb 2026 21:21:01 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb/corelow: mark bytes unavailable when reading from unavailable mapping Date: Fri, 27 Feb 2026 21:20:36 -0500 Message-ID: <20260228022059.117785-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 The main motivation for this change is to nicely support "lightweight" core files on ROCm (more on this below), but I think that the change also makes sense for regular core files. When handling a file mappings from a core file, the core target attempts to open the referenced file. If successful, the mappings from this file end up in the m_core_file_mappings vector. Otherwise, they end up in the m_core_unavailable_mappings vector. When trying to read from an address within an unavailable mapping, unless the executable target beneath is able to fulfill the request, the core target returns an error (TARGET_XFER_E_IO). This is from gdb.base/corefile.exp before the patch: (gdb) PASS: gdb.base/corefile.exp: accessing mmapped data in core file with coremmap.data removed x/8bd buf2ro 0x7f095a517000: Cannot access memory at address 0x7f095a517000 I think that this would be a good use case for the "unavailable" status. We know the memory was there at runtime, it's just not available during post-mortem debugging. That is the definition of "unavailable". After changing core_target::xfer_partial to report the bytes as unavailable, which this patch does, the same test now shows: (gdb) PASS: gdb.base/corefile.exp: accessing mmapped data in core file with coremmap.data removed x/8bd buf2ro 0x7f0250f52000: I would say that the output of the x command isn't great, but that is just a presentation issue. The original motivation for me to do this change is that we are working on lightweight GPU core dump support in ROCm. By default, the ROC runtime will dump all the memory allocated in the context of the crashing wave. This can result in absurdly big core dumps. With lightweight core dumps, the runtime only dumps a certain subset of the information that is considered essential. When trying to read a value from a segment of memory that was not dumped, I believe that it is natural to use the "unavailable" status. That is handled by this patch. In the following example, `d` is a kernel parameter of type `int *`. Its value was collected in the core dump, but the memory it points to, allocated with hipMalloc, was not. Before: (gdb) p data $1 = (int *) 0x78bf26e00000 (gdb) p data[5] ❌️ Cannot access memory at address 0x78bf26e00014 After: (gdb) p data $1 = (int *) 0x78bf26e00000 (gdb) p data[5] $2 = Note that the same concept exists on Linux with the minicoredumper project [1]. We could adjust the core target to act the same way when dealing with minicoredumps. [1] https://www.linutronix.de/minicoredumper/ Change-Id: I4df82ba4116e87545691facec0cb662c4b2b7797 --- gdb/corelow.c | 3 ++- gdb/testsuite/gdb.base/corefile.exp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index a28a707c293a..57d05504fa3c 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1470,7 +1470,8 @@ core_target::xfer_partial (enum target_object object, const char *annex, if (xfer_status == TARGET_XFER_OK) return TARGET_XFER_OK; - return TARGET_XFER_E_IO; + *xfered_len = len; + return TARGET_XFER_UNAVAILABLE; } } diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp index 957bccf43a40..f6a0a7a1ecad 100644 --- a/gdb/testsuite/gdb.base/corefile.exp +++ b/gdb/testsuite/gdb.base/corefile.exp @@ -229,7 +229,7 @@ gdb_test "x/8bd buf2" \ "accessing mmapped data in core file with coremmap.data removed" gdb_test "x/8bd buf2ro" \ - "$hex\[^:\]*:\\s+Cannot access memory at address $hex" \ + "$hex\[^:\]*:(\\s+){8}" \ "accessing read-only mmapped data in core file with coremmap.data removed" # Restore the coremmap.data file so later tests don't give warnings base-commit: d7f532cb3a46527c56963a2c713e29cee4f64eee -- 2.53.0