Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [RFC][gdb/threads] Fix FAIL in gdb.threads/current-lwp-dead.exp
Date: Thu, 7 Oct 2021 16:05:11 +0200	[thread overview]
Message-ID: <20211007140509.GA23194@delia.home> (raw)

Hi,

On openSUSE Tumbleweed, I run into:
...
(gdb) continue^M
Continuing.^M
[New Thread 0x7ffff7cc6740 (LWP 15909)]^M
[Thread 0x7ffff7cc6740 (LWP 15905) exited]^M
Cannot find user-level thread for LWP 15910: generic error^M
(gdb) FAIL: gdb.threads/current-lwp-dead.exp: \
  continue to breakpoint: fn_return
...

Debugging reveals that the error is thrown during a call to thread_from_lwp
from thread_db_notice_clone.

Fix this by:
- wrapping the call in a generic try-catch,
- handling a subsequent, similar call that causes the same error in the
  same way, and
- handling a segfault in thread_from_lwp by not calling it with stopped
  argument == nullptr in thread_db_target::wait.

This is all symptom handling without any analysis, but it makes the
test-case pass, in the same way as it passes on openSUSE Leap 15.2:
...
(gdb) continue^M
Continuing.^M
[New Thread 0x7ffff7cc6740 (LWP 16880)]^M
[Thread 0x7ffff7cc6740 (LWP 16876) exited]^M
[New LWP 16881]^M
[Thread 0x7ffff7cc6740 (LWP 16880) exited]^M
[Switching to LWP 16881]^M
Cannot remove breakpoints because program is no longer writable.^M
Further execution is probably impossible.^M
^M
Thread 3 hit Breakpoint 2, fn_return (unused=<error reading variable: \
  Cannot access memory at address 0x407298>) at current-lwp-dead.c:45^M
45        return 0;     /* at-fn_return */^M
(gdb) PASS: gdb.threads/current-lwp-dead.exp: \
  continue to breakpoint: fn_return
...

Tested gdb.threads/*.exp on x86_64-linux, no regressions.

Any comments?

Thanks,
- Tom

[gdb/threads] Fix FAIL in gdb.threads/current-lwp-dead.exp

---
 gdb/linux-thread-db.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 54e68ccd0d7..e65dce96efe 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -441,11 +441,24 @@ thread_db_notice_clone (ptid_t parent, ptid_t child)
 
   thread_info *stopped = find_thread_ptid (linux_target, parent);
 
-  thread_from_lwp (stopped, child);
+  try
+    {
+      thread_from_lwp (stopped, child);
+    }
+  catch (...)
+    {
+    }
 
   /* If we do not know about the main thread's pthread info yet, this
      would be a good time to find it.  */
-  thread_from_lwp (stopped, parent);
+  try
+    {
+      thread_from_lwp (stopped, parent);
+    }
+  catch (...)
+    {
+    }
+
   return 1;
 }
 
@@ -1424,7 +1437,9 @@ thread_db_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
     return ptid;
 
   /* Fill in the thread's user-level thread id and status.  */
-  thread_from_lwp (find_thread_ptid (beneath, ptid), ptid);
+  thread_info *stopped = find_thread_ptid (beneath, ptid);
+  if (stopped != nullptr)
+    thread_from_lwp (stopped, ptid);
 
   return ptid;
 }

                 reply	other threads:[~2021-10-07 14:05 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=20211007140509.GA23194@delia.home \
    --to=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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