Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Abhay Kandpal <abhay@linux.ibm.com>
To: gdb-patches@sourceware.org
Cc: Ulrich.Weigand@de.ibm.com, cel@linux.ibm.com, abhay.k@ibm.com,
	Abhay Kandpal <abhay@linux.ibm.com>
Subject: [PATCH] gdb/ppc: fix gcore hang when the thread group leader has exited
Date: Wed, 25 Nov 2026 02:11:06 -0500	[thread overview]
Message-ID: <20261125071106.2848287-1-abhay@linux.ibm.com> (raw)

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


                 reply	other threads:[~2026-11-25  7:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125071106.2848287-1-abhay@linux.ibm.com \
    --to=abhay@linux.ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=abhay.k@ibm.com \
    --cc=cel@linux.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /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