Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/ppc: fix gcore hang when the thread group leader has exited
@ 2026-11-25  7:11 Abhay Kandpal
  0 siblings, 0 replies; only message in thread
From: Abhay Kandpal @ 2026-11-25  7:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: Ulrich.Weigand, cel, abhay.k, Abhay Kandpal

On ppc64le Linux, gdb.threads/thread-leader-exited.exp times out at
"save a corefile", because gcore never finishes.

ppc_linux_nat_target::auxv_parse gets the auxv field size from
ppc_linux_target_wordsize, using the LWP of inferior_ptid.  That
function reads the MSR with PTRACE_PEEKUSER and returns 4 if the read
fails.  When the selected thread is an exited thread group leader,
the 64-bit auxv is therefore parsed as 32-bit fields.

The misparsed vector has a type field of 6 (AT_PAGESZ) with a value
of 0, taken from the upper half of the 64-bit type.
target_auxv_search continues past a false AT_NULL and returns this
entry, so gcore_copy_callback sets page_size to 0.  When a large
memory read fails, its page-by-page fallback then uses a chunk size
of 0 and never makes progress.

The hang was exposed by commit 2f4e6ea8c05 ("gdb: use the selected
thread's LWP ID when reading Linux procfs files"), which changed this
test.  The fallback loop came from commit c1da013915e ("gcore: Handle
unreadable pages within readable memory regions").

Fix this by using any_non_exited_thread_of_inferior to choose the
thread passed to ppc_linux_target_wordsize.

Tested on ppc64le Linux (Power10, Fedora 43).  thread-leader-exited.exp
now passes, with no new failures in the testsuite.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=35051
---
This patch is reg tested.

 gdb/ppc-linux-nat.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index 0eea4993fb4..b0a4a53ddbd 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -1945,9 +1945,17 @@ ppc_linux_nat_target::auxv_parse (const gdb_byte **readptr,
 {
   gdb_assert (inferior_ptid != null_ptid);
 
-  int tid = inferior_ptid.lwp ();
+  /* ppc_linux_target_wordsize reads the MSR with ptrace, which cannot
+     work on a thread that has exited, such as a zombie thread group
+     leader.  Prefer a thread of this inferior that is still alive.  */
+  ptid_t ptid = inferior_ptid;
+  thread_info *thr = any_non_exited_thread_of_inferior (current_inferior ());
+  if (thr != nullptr)
+    ptid = thr->ptid;
+
+  int tid = ptid.lwp ();
   if (tid == 0)
-    tid = inferior_ptid.pid ();
+    tid = ptid.pid ();
 
   int sizeof_auxv_field = ppc_linux_target_wordsize (tid);
 
-- 
2.51.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25  7:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25  7:11 [PATCH] gdb/ppc: fix gcore hang when the thread group leader has exited Abhay Kandpal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox