public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug threads/31579] New: Cannot find user-level thread for LWP
@ 2024-03-29 20:11 ssbssa at sourceware dot org
  2024-03-29 20:15 ` [Bug threads/31579] " ssbssa at sourceware dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ssbssa at sourceware dot org @ 2024-03-29 20:11 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31579

            Bug ID: 31579
           Summary: Cannot find user-level thread for LWP
           Product: gdb
           Version: 14.1
            Status: NEW
          Severity: normal
          Priority: P2
         Component: threads
          Assignee: unassigned at sourceware dot org
          Reporter: ssbssa at sourceware dot org
  Target Milestone: ---

With gdb-14.2 I get the following error:
```
Attaching to process 14793
[New LWP 14799]
[New LWP 14800]
[New LWP 14804]
[New LWP 14805]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x0000003ee780b68c in pthread_cond_wait@@GLIBC_2.3.2 () from
/lib64/libpthread.so.0
(gdb) c
Continuing.
Cannot find user-level thread for LWP 14805: generic error
```

The same program runs without problem with gdb-13:
```
Attaching to process 16559
[New LWP 16561]
[New LWP 16562]
[New LWP 16563]
[New LWP 16564]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x0000003ee780b68c in pthread_cond_wait@@GLIBC_2.3.2 () from
/lib64/libpthread.so.0
(gdb) c
Continuing.
[Detaching after fork from child process 16699]
[Detaching after fork from child process 16701]
[Detaching after fork from child process 16705]
[Detaching after fork from child process 16709]
[Detaching after fork from child process 16711]
[Detaching after fork from child process 16715]
```

I bisected it to this commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=6d30ada87b7a515a0f623687e2faadc1d4acf440
In particular, it's the proc-service.c hunk, and I got it to work again by
partly reverting the commit like this:
```
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 712f9b3..0753c34 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -771,12 +771,12 @@ class scoped_restore_current_inferior_for_memory
   /* Save the current globals and switch to the given inferior and the
      inferior's program space.  inferior_ptid is set to point to the
      inferior's process id (and not to any particular thread).  */
-  explicit scoped_restore_current_inferior_for_memory (inferior *inf)
+  explicit scoped_restore_current_inferior_for_memory (inferior *inf, ptid_t
ptid = null_ptid)
     : m_save_ptid (&inferior_ptid)
   {
     set_current_inferior (inf);
     set_current_program_space (inf->pspace);
-    inferior_ptid = ptid_t (inf->pid);
+    inferior_ptid = ptid == null_ptid ? ptid_t (inf->pid) : ptid;
   }

   DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior_for_memory);
diff --git a/gdb/proc-service.c b/gdb/proc-service.c
index f735eb0..dcb8e2b 100644
--- a/gdb/proc-service.c
+++ b/gdb/proc-service.c
@@ -72,7 +72,7 @@
 ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
                gdb_byte *buf, size_t len, int write)
 {
-  scoped_restore_current_inferior_for_memory save_inferior (ph->thread->inf);
+  scoped_restore_current_inferior_for_memory save_inferior (ph->thread->inf,
ph->thread->ptid);

   CORE_ADDR core_addr = ps_addr_to_core_addr (addr);

```

When I set a breakpoint at ps_xfer_memory, it stops there twice for each
"Detaching after fork from child process" message,
and it looks like this:
```
(top-gdb) bt
#0  ps_xfer_memory (ph=0x8f94c18, addr=0x3ee7a1c2a0 <__stack_user>,
buf=0x7ffec1dc5dc0 "", len=8, write=0) at ../../gdb/proc-service.c:74
#1  0x00007f46c7add770 in _td_fetch_value () from /lib64/libthread_db.so.1
#2  0x00007f46c7adad6d in td_ta_map_lwp2thr () from /lib64/libthread_db.so.1
#3  0x00000000008c07c5 in thread_from_lwp (stopped=0x249d420, ptid=...) at
../../gdb/linux-thread-db.c:415
#4  0x00000000008c179b in thread_db_target::wait (this=<optimized out>,
ptid=..., ourstatus=0x7ffec1dc6568, options=...) at
../../gdb/linux-thread-db.c:1421
#5  0x0000000000a449e1 in target_wait (ptid=...,
status=status@entry=0x7ffec1dc6568, options=..., options@entry=...) at
../../gdb/target.c:2613
#6  0x00000000008788d5 in do_target_wait_1 (inf=inf@entry=0x2274460, ptid=...,
status=status@entry=0x7ffec1dc6568, options=options@entry=...) at
../../gdb/infrun.c:3956
#7  0x0000000000889ecf in __lambda6::operator() (inf=0x2274460,
__closure=<synthetic pointer>) at ../../gdb/infrun.c:4015
#8  do_target_wait (options=..., ecs=0x7ffec1dc6540) at ../../gdb/infrun.c:4034
#9  fetch_inferior_event () at ../../gdb/infrun.c:4445
#10 0x0000000000bbdf2d in gdb_wait_for_event (block=block@entry=0) at
../../gdbsupport/event-loop.cc:694
#11 0x0000000000bbe6d7 in gdb_do_one_event (mstimeout=mstimeout@entry=-1) at
../../gdbsupport/event-loop.cc:217
#12 0x00000000008d07ca in start_event_loop () at ../../gdb/main.c:411
#13 captured_command_loop () at ../../gdb/main.c:475
#14 0x00000000008d25e5 in captured_main (data=data@entry=0x7ffec1dc6690) at
../../gdb/main.c:1348
#15 gdb_main (args=args@entry=0x7ffec1dc66b0) at ../../gdb/main.c:1367
#16 0x0000000000621e35 in main (argc=6, argv=0x7ffec1dc67c8) at
../../gdb/gdb.c:39
(top-gdb) p ph->thread->inf->pid
$1 = 20298
(top-gdb) p ph->thread->ptid
$2 = {m_pid = 20298, m_lwp = 20304, m_tid = 0}
```

I can't share the executable, but can try to make a reproducer if someone has a
suggestion what it should look like.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-05-03 16:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 20:11 [Bug threads/31579] New: Cannot find user-level thread for LWP ssbssa at sourceware dot org
2024-03-29 20:15 ` [Bug threads/31579] " ssbssa at sourceware dot org
2024-03-31 12:22 ` ssbssa at sourceware dot org
2024-04-11 11:41 ` pedro at palves dot net
2024-04-11 12:00 ` pedro at palves dot net
2024-04-26 21:02 ` cvs-commit at gcc dot gnu.org
2024-05-03 16:27 ` pedro at palves dot net
2024-05-03 16:28 ` pedro at palves dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).