From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21742 invoked by alias); 16 Dec 2014 16:54:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 21692 invoked by uid 89); 16 Dec 2014 16:54:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 16 Dec 2014 16:54:02 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBGGrulC028156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 16 Dec 2014 11:54:00 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBGGrt51018425 for ; Tue, 16 Dec 2014 11:53:56 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 0/5] GNU/Linux, fix attach races/problems Date: Tue, 16 Dec 2014 16:54:00 -0000 Message-Id: <1418748834-27545-1-git-send-email-palves@redhat.com> X-SW-Source: 2014-12/txt/msg00447.txt.bz2 Investigating an "attach" bug seemingly caused by a race, related to the fact that on Linux we have to attach to each thread individually, I decided to write a test that stresses that aspect of attach. The test constantly spawns short-lived threads, and has GDB attach, debug a little, detach, attach, rinse/repeat a few times. That actually exposed a set of issues, both in GDB and in glibc/libthread_db. One is that the test defeats the current heuristics in place: we still fail to attach to some threads sometimes, if the program spawns them quickly enough. This is fixed by fetching the list of LWPs to attach to from /proc instead of relying on libthread_db for that. Another is that some times we'd try to attach to a bogus lwp with PID==-1, and do a dangerous waitpid, potentially eating an event by mistake and breaking the debug session as result. Yet another is a nasty libthread_db event reporting mechanism race related to detaching from the inferior just while a thread is reporting an event, resulting in a subsequent attach session tripping on broken libthread_db events. We work around this by no longer using libthread_db for thread event creation/death reporting, which is good on its own, for being much more robust and efficient. I've filed a couple glibc bugs as result of all this: Bug 17705 - nptl_db: stale thread create/death events if debugger detaches https://sourceware.org/bugzilla/show_bug.cgi?id=17705 Bug 17707 - nptl_db: terminated and joined threads https://sourceware.org/bugzilla/show_bug.cgi?id=17707 The series fixes the GDB issues and at the same time works around the glibc issues. Tested on x86_64 Fedora 20, native and gdbserver. Comments? Pedro Alves (5): libthread_db: debug output should go to gdb_stdlog Linux: on attach, attach to lwps listed under /proc/$pid/task/ libthread_db: Skip attaching to terminated and joined threads Linux: Skip thread_db thread event reporting if PTRACE_EVENT_CLONE is supported Test attaching to a program that constantly spawns short-lived threads gdb/gdbserver/linux-low.c | 152 ++++++++------------ gdb/gdbserver/linux-low.h | 6 - gdb/gdbserver/thread-db.c | 13 +- gdb/linux-nat.c | 94 +++++++++++++ gdb/linux-nat.h | 4 + gdb/linux-thread-db.c | 84 ++++++++--- gdb/nat/linux-procfs.c | 153 ++++++++++++++++++--- gdb/nat/linux-procfs.h | 32 ++++- gdb/nat/linux-ptrace.c | 33 ++++- gdb/nat/linux-ptrace.h | 8 ++ .../gdb.threads/attach-many-short-lived-threads.c | 117 ++++++++++++++++ .../attach-many-short-lived-threads.exp | 135 ++++++++++++++++++ gdb/testsuite/gdb.threads/fork-thread-pending.exp | 2 +- .../signal-command-multiple-signals-pending.c | 11 +- .../signal-command-multiple-signals-pending.exp | 7 + 15 files changed, 698 insertions(+), 153 deletions(-) create mode 100644 gdb/testsuite/gdb.threads/attach-many-short-lived-threads.c create mode 100644 gdb/testsuite/gdb.threads/attach-many-short-lived-threads.exp -- 1.9.3