public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug threads/10838] New: attach;detach not idempotent under Linux/threads
@ 2009-10-24  0:29 ppluzhnikov at google dot com
  2009-10-24  0:29 ` [Bug threads/10838] " ppluzhnikov at google dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ppluzhnikov at google dot com @ 2009-10-24  0:29 UTC (permalink / raw)
  To: gdb-prs

Attach followed by detach leaves libpthread with some event reporting
enabled.

If any thread exits after detach, all subsequent attach;continue will fail
with "Cannot get thread event message: debugger service failed" error.

Test case:

#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <syscall.h>
#include <unistd.h>

void *fn (void *p)
{
  pid_t tid = syscall(SYS_gettid);
  printf ("Thread %d starts.\n", tid);
  sleep (2);
  printf ("Thread %d exits.\n", tid);
  return NULL;
}

int main ()
{
  pid_t pid = getpid ();

  printf ("Execute:\ngdb -p %d -ex 'detach' -ex 'shell sleep 3' -ex 'attach %d'
-ex cont\n", pid, pid);
  while (1)
    {
      pthread_t tid;

      assert (0 == pthread_create (&tid, NULL, fn, NULL));
      assert (0 == pthread_join (tid, NULL));
    }
  return 0;
}

gcc -g -pthread t.c && ./a.out
Execute:
gdb -p 26361 -ex 'detach' -ex 'shell sleep 3' -ex 'attach 26361' -ex cont
Thread 26362 starts.
Thread 26362 exits.
Thread 26363 starts.
Thread 26363 exits.
Thread 26364 starts.
Thread 26364 exits.
Thread 26366 starts.
Thread 26366 exits.
Thread 26367 starts.
Thread 26367 exits.
Thread 26369 starts.
Thread 26369 exits.
Thread 26370 starts.
Thread 26370 exits.
Thread 26376 starts.
Thread 26376 exits.
Thread 26378 starts.
Thread 26378 exits.

### in another window ###

 ./gdb -nx -p 26361 -ex 'detach' -ex 'shell sleep 3' -ex 'attach 26361' -ex cont

GNU gdb (GDB) 7.0.50.20091023-cvs
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Attaching to process 26361
Reading symbols from /home/ppluzhnikov/bugs/2209373/a.out...done.
Reading symbols from /lib/libpthread.so.0...Reading symbols from
/usr/lib/debug/lib/libpthread-2.7.so...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x412d1950 (LWP 26370)]
(no debugging symbols found)...done.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libc.so.6...Reading symbols from
/usr/lib/debug/lib/libc-2.7.so...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from
/usr/lib/debug/lib/ld-2.7.so...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007f552773e796 in pthread_join () from /lib/libpthread.so.0
Detaching from program: /home/ppluzhnikov/bugs/2209373/a.out, process 26361
Attaching to program: /home/ppluzhnikov/bugs/2209373/a.out, process 26361
Reading symbols from /lib/libpthread.so.0...Reading symbols from
/usr/lib/debug/lib/libpthread-2.7.so...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x412d1950 (LWP 26378)]
(no debugging symbols found)...done.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libc.so.6...Reading symbols from
/usr/lib/debug/lib/libc-2.7.so...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from
/usr/lib/debug/lib/ld-2.7.so...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007f552773e796 in pthread_join () from /lib/libpthread.so.0
Continuing.
Cannot get thread event message: debugger service failed
(gdb) 


AFAICT, what's happening is:
- a live at the first attach thread 26370 has TD_DEATH reporting enabled
  (by GDB).
- GDB detaches.
- thread 26370 exits, and is enqueued on __nptl_last_event as TD_DEATH event
  (__nptl_last_event == 0x412d1950).

- a new thread 26378 is created, but *reuses* the same thread descriptor
  0x412d1950. Its eventbuf is copied from parent (which has no events
  pending) in __pthread_create_2_1:

    /* The debug events are inherited from the parent.  */
    pd->eventbuf = self->eventbuf;

  Voila: __nptl_last_event->eventbuf.eventnum == 0, and that triggers the
  error in td_ta_event_getmsg:
  
    /* If the structure is on the list there better be an event recorded.  */
    if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
      return TD_DBERR;

-- 
           Summary: attach;detach not idempotent under Linux/threads
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: threads
        AssignedTo: ppluzhnikov at google dot com
        ReportedBy: ppluzhnikov at google dot com
                CC: gdb-prs at sourceware dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=10838

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug threads/10838] attach;detach not idempotent under Linux/threads
  2009-10-24  0:29 [Bug threads/10838] New: attach;detach not idempotent under Linux/threads ppluzhnikov at google dot com
@ 2009-10-24  0:29 ` ppluzhnikov at google dot com
  2009-11-12  0:47 ` cvs-commit at gcc dot gnu dot org
  2009-11-12  0:49 ` ppluzhnikov at google dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ppluzhnikov at google dot com @ 2009-10-24  0:29 UTC (permalink / raw)
  To: gdb-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|                            |1


http://sourceware.org/bugzilla/show_bug.cgi?id=10838

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug threads/10838] attach;detach not idempotent under Linux/threads
  2009-10-24  0:29 [Bug threads/10838] New: attach;detach not idempotent under Linux/threads ppluzhnikov at google dot com
  2009-10-24  0:29 ` [Bug threads/10838] " ppluzhnikov at google dot com
@ 2009-11-12  0:47 ` cvs-commit at gcc dot gnu dot org
  2009-11-12  0:49 ` ppluzhnikov at google dot com
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2009-11-12  0:47 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2009-11-12 00:47 -------
Subject: Bug 10838

CVSROOT:	/cvs/src
Module name:	src
Changes by:	ppluzhnikov@sourceware.org	2009-11-12 00:47:39

Modified files:
	gdb            : ChangeLog linux-thread-db.c 
	gdb/gdbserver  : ChangeLog thread-db.c 

Log message:
	gdb/ChangeLog:
	
	2009-11-11  Paul Pluzhnikov  <ppluzhnikov@google.com>
	
	PR gdb/10838
	* linux-thread-db.c (thread_db_info): New member.
	(disable_thread_event_reporting): Call td_ta_clear_event.
	
	gdbserver/ChangeLog:
	
	2009-11-11  Paul Pluzhnikov  <ppluzhnikov@google.com>
	
	PR gdb/10838
	* thread-db.c (thread_db_free): Call td_ta_clear_event.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11060&r2=1.11061
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/linux-thread-db.c.diff?cvsroot=src&r1=1.67&r2=1.68
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/ChangeLog.diff?cvsroot=src&r1=1.296&r2=1.297
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/thread-db.c.diff?cvsroot=src&r1=1.26&r2=1.27



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10838

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug threads/10838] attach;detach not idempotent under Linux/threads
  2009-10-24  0:29 [Bug threads/10838] New: attach;detach not idempotent under Linux/threads ppluzhnikov at google dot com
  2009-10-24  0:29 ` [Bug threads/10838] " ppluzhnikov at google dot com
  2009-11-12  0:47 ` cvs-commit at gcc dot gnu dot org
@ 2009-11-12  0:49 ` ppluzhnikov at google dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ppluzhnikov at google dot com @ 2009-11-12  0:49 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From ppluzhnikov at google dot com  2009-11-12 00:49 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://sourceware.org/bugzilla/show_bug.cgi?id=10838

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

end of thread, other threads:[~2009-11-12  0:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-24  0:29 [Bug threads/10838] New: attach;detach not idempotent under Linux/threads ppluzhnikov at google dot com
2009-10-24  0:29 ` [Bug threads/10838] " ppluzhnikov at google dot com
2009-11-12  0:47 ` cvs-commit at gcc dot gnu dot org
2009-11-12  0:49 ` ppluzhnikov at google dot com

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).