From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11656 invoked by alias); 20 Jun 2006 18:54:22 -0000 Received: (qmail 11647 invoked by uid 22791); 20 Jun 2006 18:54:21 -0000 X-Spam-Check-By: sourceware.org Received: from ip-85-160-1-89.eurotel.cz (HELO host0.dyn.jankratochvil.net) (85.160.1.89) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 20 Jun 2006 18:54:14 +0000 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.13.6/8.13.4) with ESMTP id k5KIrRsT009560; Tue, 20 Jun 2006 20:53:28 +0200 Received: (from lace@localhost) by host0.dyn.jankratochvil.net (8.13.6/8.13.6/Submit) id k5KIrQXg009559; Tue, 20 Jun 2006 20:53:26 +0200 Date: Tue, 20 Jun 2006 18:54:00 -0000 From: Jan Kratochvil To: Daniel Jacobowitz Cc: gdb-patches@sourceware.org, Christoph Bartoschek Subject: Re: RFC: Re: [patch] Fix for 'info threads' crashes if zombie threads exist Message-ID: <20060620185326.GA9482@host0.dyn.jankratochvil.net> References: <20060620135351.GA9853@host0.dyn.jankratochvil.net> <200606201821.41941.bartoschek@or.uni-bonn.de> <200606191719.00530.bartoschek@or.uni-bonn.de> <200606201456.57681.bartoschek@or.uni-bonn.de> <20060620130932.GA21490@nevyn.them.org> <200606201524.45099.bartoschek@or.uni-bonn.de> <20060620132737.GA21951@nevyn.them.org> <20060619165609.GA14691@host0.dyn.jankratochvil.net> <20060620170451.GA17022@host0.dyn.jankratochvil.net> <20060620171109.GA28310@nevyn.them.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="huq684BweRXVnRxX" Content-Disposition: inline In-Reply-To: <20060620171109.GA28310@nevyn.them.org> User-Agent: Mutt/1.4.2.1i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00283.txt.bz2 --huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1620 Hi Daniel, On Tue, 20 Jun 2006 19:11:09 +0200, Daniel Jacobowitz wrote: ... > TD_DEATH events were supported because there are all sorts of things > which can go wrong when you ask libthread_db about a thread that it > considers dead. At that point, as far as the library is concerned, the > thread is gone. > After your patch, I strongly suspect there are places where you could hit > control-c and get mysterious errors from GDB. OK... I checked now that my patch may have problems accessing TCB after: if (IS_DETACHED (pd)) __free_tcb (pd); for the detached threads and it even has problems before this point (not analysed why): Program received signal SIGTRAP, Trace/breakpoint trap. [Switching to Thread -1208153184 (unknown thread_db state 1)] 0x00000000 in ?? () Proposing the attached reduced patch with only the most important+safe part. It still catches the initial terminating state with EXITING_BIT (->TD_THR_ZOMBIE) where I hope most of the crashes/breakpoints may occur. Still the perfect functionality would require patching libthread_db and it looks to me a bit as a chicken&egg problem. :-) > A new thread can be created with the same thread ID - even before this one > exits. Not sure of how much are non-Linux platforms a concern for these minor issues. Apparently on Linux kernel the same LWP id cannot be created until the final syscall __NR_exit. Regards, Jan Kratochvil > A little patience, please. It takes a while to review GDB patches, > especially non-obvious ones - and thread-db support seems to be quite > complicated. (Sorry, I only did not want to get the patch lost.) --huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-cvs20060620-pthread_exit.patch" Content-length: 1415 Index: linux-thread-db.c =================================================================== RCS file: /cvs/src/src/gdb/linux-thread-db.c,v retrieving revision 1.16 diff -u -p -r1.16 linux-thread-db.c --- linux-thread-db.c 5 May 2006 22:42:43 -0000 1.16 +++ linux-thread-db.c 20 Jun 2006 17:51:01 -0000 @@ -1006,6 +1006,9 @@ thread_db_fetch_registers (int regno) } thread_info = find_thread_pid (inferior_ptid); + if (!thread_info) + error (_("Stopped at dead thread %ld; should not happen."), + (long) GET_THREAD (inferior_ptid)); thread_db_map_id2thr (thread_info, 1); err = td_thr_getgregs_p (&thread_info->private->th, gregset); @@ -1127,6 +1130,8 @@ thread_db_thread_alive (ptid_t ptid) struct thread_info *thread_info; thread_info = find_thread_pid (ptid); + if (!thread_info) + return 0; thread_db_map_id2thr (thread_info, 0); if (!thread_info->private->th_valid) return 0; @@ -1145,9 +1150,9 @@ thread_db_thread_alive (ptid_t ptid) thread_info->private->ti_valid = 1; } - if (thread_info->private->ti.ti_state == TD_THR_UNKNOWN - || thread_info->private->ti.ti_state == TD_THR_ZOMBIE) - return 0; /* A zombie thread. */ + /* Never 0 on TD_THR_ZOMBIE to be able to trace pthread_exit(3). */ + if (thread_info->private->ti.ti_state == TD_THR_UNKNOWN) + return 0; /* A disappeared thread. */ return 1; } --huq684BweRXVnRxX--