From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6RwzHYW00WpERBcAWB0awg (envelope-from ) for ; Fri, 16 Oct 2026 01:22:13 -0400 Received: by simark.ca (Postfix, from userid 112) id 7467F1E050; Fri, 16 Oct 2026 01:22:13 -0400 (EDT) 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 24F511E047 for ; Fri, 16 Oct 2026 01:22:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BCC64BA2E1A for ; Fri, 16 Oct 2026 05:22:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BCC64BA2E1A Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id D59DF4BA2E2A for ; Fri, 16 Oct 2026 05:21:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D59DF4BA2E2A 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 D59DF4BA2E2A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792128068; cv=none; b=sdGhvaLpMmjPdprEalWyjISun1ghrh76l7+w+6IhBEEe1RkCQlyvTF0XCu5JVeE9F01Z8ImeLkBGSU/bY+oCb+JqDEBna+AMjWu1v2M1Kd9qzBwmJDOK2a/pH9Us07NPdkHQSlYHWFEOW1XGI6mcdl3SO4jM1dzrX8p2eGj1xho= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792128068; c=relaxed/simple; bh=utVcQBt+IzNOaHcajNJqVeg2TMeU/g2FCcEr2uVdwG4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=V+xT54iuTC9YiKlcvSw8ntEgMW0F1S0bZlw9jAFCu3vGbpc3l8NJ6iwrUsJl6Y7gU00EymzS1n8C2MDzMMuFKpflN6b28UrSdk9zbhX6tuFeDxCuBzV7UXxzLpCX3tlNStxelp3KR2Doc3of/HlYQZ+MStNiG6dEdHmZyEMlnXY= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D59DF4BA2E2A Received: by simark.ca (Postfix) id BFEFD1E091; Fri, 16 Oct 2026 01:21:04 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Shahab Vahedi , Simon Marchi Subject: [PATCH 5/6] gdb/amd-dbgapi: defer TARGET_OBJECT_AUXV xfers to the beneath target Date: Fri, 16 Oct 2026 01:20:10 -0400 Message-ID: <20261016052100.1386999-6-simon.marchi@efficios.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261016052100.1386999-1-simon.marchi@efficios.com> References: <20261016052100.1386999-1-simon.marchi@efficios.com> MIME-Version: 1.0 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 From: Shahab Vahedi Reading the auxiliary vector of the inferior fails when a GPU wave is the selected thread. The read goes through amd_dbgapi_target::xfer_partial, which only handles TARGET_OBJECT_MEMORY for GPU threads, and returns TARGET_XFER_E_IO for everything else. Most users of the auxiliary vector, including "info auxv", use the copy cached in the inferior, which is normally populated early, while a host thread is selected. But if the cache is cleared while a wave is selected, for instance by the "file" command, the next read fails, and the failure is cached too. A victim of that bug is the "gcore" command. linux_make_corefile_notes reads the auxiliary vector directly from the target (bypassing the cache) to write the NT_AUXV note, so the note is always missing when a GPU wave is selected. As a consequence, when loading such a core file, GDB can't find the shared libraries of a position independent executable, and can't find the full program name (AT_EXECFN), so it falls back to the possibly truncated name from the NT_PRPSINFO note. Fix this by making amd_dbgapi_target::xfer_partial always let the target beneath handle TARGET_OBJECT_AUXV. Add the gdb.rocm/auxv-wave-selected.exp test, which reproduces the "file" scenario above (perhaps we should have a maintenance command to flush the auxv cache though). The gcore scenario can't be tested yet, because generating a core file while a GPU wave is selected fails for another reason, fixed in the following patch. The amd-dbgapi-target.c part of this change comes from the downstream ROCgdb port, commit 47716f7de58 ("gdb/amd-dbgapi: defer TARGET_OBJECT_AUXV xfers to the beneath target"). Co-Authored-By: Simon Marchi Change-Id: I177eba5780706e4065e1b17f370a17dbea016d8d --- gdb/amd-dbgapi-target.c | 9 ++- gdb/testsuite/gdb.rocm/auxv-wave-selected.cpp | 42 ++++++++++++ gdb/testsuite/gdb.rocm/auxv-wave-selected.exp | 65 +++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.rocm/auxv-wave-selected.cpp create mode 100644 gdb/testsuite/gdb.rocm/auxv-wave-selected.exp diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c index 099deceaabad..1c6edb5a7fa3 100644 --- a/gdb/amd-dbgapi-target.c +++ b/gdb/amd-dbgapi-target.c @@ -752,9 +752,14 @@ amd_dbgapi_target::xfer_partial (enum target_object object, const char *annex, the parent, and inferior_ptid has the child's PTID. We can use the parent's process_stratum_target (the one below us) to do the memory operation, but dbgapi knows nothing about the child and - would try to update the parent's memory. */ + would try to update the parent's memory. + + The auxiliary vector is a property of the host process, so let the + target beneath handle it, even if the current thread is a GPU + thread. */ if ((!ptid_is_gpu (inferior_ptid) && object != TARGET_OBJECT_MEMORY) - || inferior_ptid.pid () != current_inferior ()->pid) + || inferior_ptid.pid () != current_inferior ()->pid + || object == TARGET_OBJECT_AUXV) return beneath ()->xfer_partial (object, annex, readbuf, writebuf, offset, requested_len, xfered_len); diff --git a/gdb/testsuite/gdb.rocm/auxv-wave-selected.cpp b/gdb/testsuite/gdb.rocm/auxv-wave-selected.cpp new file mode 100644 index 000000000000..0f8ca14fe90f --- /dev/null +++ b/gdb/testsuite/gdb.rocm/auxv-wave-selected.cpp @@ -0,0 +1,42 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + +#include "hip/hip_runtime.h" +#include + +__global__ void +kernel (int *out) +{ + *out = 1; +} + +int +main () +{ + int *result_ptr, result; + + hipError_t error = hipMalloc (&result_ptr, sizeof (int)); + assert (error == hipSuccess); + + kernel<<>> (result_ptr); + + error = hipMemcpyDtoH (&result, result_ptr, sizeof (int)); + assert (error == hipSuccess); + assert (result == 1); + + return 0; +} diff --git a/gdb/testsuite/gdb.rocm/auxv-wave-selected.exp b/gdb/testsuite/gdb.rocm/auxv-wave-selected.exp new file mode 100644 index 000000000000..637c5f2561b6 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/auxv-wave-selected.exp @@ -0,0 +1,65 @@ +# Copyright 2026 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 . + +# Test that GDB can read the auxiliary vector of the inferior while a GPU +# wave is selected. + +load_lib rocm.exp + +standard_testfile .cpp + +require allow_hip_tests + +# Build a position-independent executable. To find the shared libraries +# loaded by a PIE, GDB needs the auxiliary vector to find where the +# executable is loaded. +if {[build_executable "failed to prepare" $testfile $srcfile {debug hip pie}]} { + return +} + +clean_restart $testfile + +with_rocm_gpu_lock { + if {![runto_main]} { + return + } + + gdb_breakpoint "kernel" -allow-pending + + gdb_test "continue" \ + "Thread $::decimal hit Breakpoint ${::decimal}(?:\\.${::decimal})?, kernel .*" + + gdb_test "thread" "Current thread is $::decimal \\(AMDGPU Wave .*" \ + "wave is selected" + + delete_breakpoints + + # GDB caches the auxiliary vector, and the cache is normally populated + # early, while a host thread is selected. Use the "file" command while a + # wave is selected, which clears the cache, so that the auxiliary vector is + # read again while the wave is selected. + gdb_test "with confirm off -- file $::binfile" \ + "Reading symbols from [string_to_regexp $::binfile]\\.\\.\\..*" \ + "reload executable" + + gdb_test "info auxv" \ + "AT_ENTRY +Entry point of program +$::hex\r\n.*AT_NULL +End of vector +0x0" \ + "info auxv with wave selected" + + # Check that GDB still finds the shared libraries loaded by the + # program. + gdb_test "info sharedlibrary" "/libamdhip64\\.so.*" \ + "shared libraries after reload" +} -- 2.56.0