From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Shahab Vahedi <shahab.vahedi@amd.com>,
Simon Marchi <simon.marchi@efficios.com>
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 [thread overview]
Message-ID: <20261016052100.1386999-6-simon.marchi@efficios.com> (raw)
In-Reply-To: <20261016052100.1386999-1-simon.marchi@efficios.com>
From: Shahab Vahedi <shahab.vahedi@amd.com>
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 <simon.marchi@efficios.com>
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 <http://www.gnu.org/licenses/>. */
+
+#include "hip/hip_runtime.h"
+#include <cassert>
+
+__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<<<dim3 (1), dim3 (1), 0, 0>>> (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 <http://www.gnu.org/licenses/>.
+
+# 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
next prev parent reply other threads:[~2026-10-16 5:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 5:20 [PATCH 0/6] Fix generating core files when GPU waves are present Simon Marchi
2026-10-16 5:20 ` [PATCH 1/6] gdb/testsuite: make with_rocm_gpu_lock transparent to return Simon Marchi
2026-10-16 5:20 ` [PATCH 2/6] gdb/corefile: handle no signalled thread when writing NT_GDB_TDESC Simon Marchi
2026-10-16 5:20 ` [PATCH 3/6] gdb/amd-dbgapi: handle regno == -1 in fetch_registers and store_registers Simon Marchi
2026-10-16 5:20 ` [PATCH 4/6] gdb/linux-tdep: don't write core file notes for non-Linux threads Simon Marchi
2026-10-16 5:20 ` Simon Marchi [this message]
2026-10-16 5:20 ` [PATCH 6/6] gdb/linux-tdep: ignore non-Linux threads in get_ptid_for_slash_proc Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261016052100.1386999-6-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
--cc=shahab.vahedi@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox