From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6751 invoked by alias); 18 Aug 2003 19:33:46 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 6702 invoked from network); 18 Aug 2003 19:33:45 -0000 Received: from unknown (HELO nevyn.them.org) (66.93.172.17) by sources.redhat.com with SMTP; 18 Aug 2003 19:33:45 -0000 Received: from drow by nevyn.them.org with local (Exim 4.20 #1 (Debian)) id 19oplA-0006cy-FU; Mon, 18 Aug 2003 15:33:44 -0400 Date: Mon, 18 Aug 2003 19:33:00 -0000 From: Daniel Jacobowitz To: Roland McGrath Cc: gdb@sources.redhat.com, libc-alpha@sources.redhat.com Subject: Re: Amusing problem in current libthread_db Message-ID: <20030818193344.GA21937@nevyn.them.org> Mail-Followup-To: Roland McGrath , gdb@sources.redhat.com, libc-alpha@sources.redhat.com References: <20030603220912.GA7922@nevyn.them.org> <200306032230.h53MUlA22339@magilla.sf.frob.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200306032230.h53MUlA22339@magilla.sf.frob.com> User-Agent: Mutt/1.5.1i X-SW-Source: 2003-08/txt/msg00207.txt.bz2 On Tue, Jun 03, 2003 at 03:30:47PM -0700, Roland McGrath wrote: > The reason that code is needed for linuxthreads is that the thread > descriptor might be uninitialized. The main thread and the manager thread > are always reported by td_ta_thr_iter. However, early on their descriptors > are all zeros and so td_thr_get_info et al need to be able to cope with > that. It might make more sense not to report any threads at all before > they are initialized enough to report useful information. But I think that > was deemed a more risky change (vs possible presumptions of old gdbs, etc) > than faking the all-zeros responses in the early stages. > > The reason this wasn't an issue before and got changed was that the array > of thread descriptors used to be in initialized data, where the first two > elements were initialized nonzero to set up the the main and manager threads. > Now the whole array is in uninitialized so it can go in bss and not take up > space on disk; thus the main and manager threads' elements start out zero too. > > td_thr_get_info does a somewhat more convincing job of faking info when > dealing with an uninitialized descriptor in the inferior, i.e. always just > use the main thread in that case. td_thr_getgregs et al could be made to > do that. Will the manager thread be reported as created only after its thread descriptor is initialized? I'm guessing "yes". In that case, using the main thread is sufficient. Here's a patch to fix the problem, since it turned out to be more than theoretical on ARM targets. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer 2003-08-18 Daniel Jacobowitz * td_thr_getfpregs.c (td_thr_getfpregs): Use the main thread if the descriptor is uninitialized. * td_thr_getgregs.c (td_thr_getgregs): Likewise. diff -urp -x '*~' glibc-2.3.2/linuxthreads_db.orig/td_thr_getfpregs.c glibc-2.3.2/linuxthreads_db/td_thr_getfpregs.c --- glibc-2.3.2/linuxthreads_db.orig/td_thr_getfpregs.c 2002-07-15 23:25:16.000000000 -0400 +++ glibc-2.3.2/linuxthreads_db/td_thr_getfpregs.c 2003-08-18 14:44:11.000000000 -0400 @@ -1,5 +1,5 @@ /* Get a thread's floating-point register set. - Copyright (C) 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1999. @@ -30,7 +30,10 @@ td_thr_getfpregs (const td_thrhandle_t * if (th->th_unique == NULL) { - memset (regset, '\0', sizeof (*regset)); + /* No data yet. Use the main thread. */ + pid_t pid = ps_getpid (th->th_ta_p->ph); + if (ps_lgetfpregs (th->th_ta_p->ph, pid, regset) != PS_OK) + return TD_ERR; return TD_OK; } diff -urp -x '*~' glibc-2.3.2/linuxthreads_db.orig/td_thr_getgregs.c glibc-2.3.2/linuxthreads_db/td_thr_getgregs.c --- glibc-2.3.2/linuxthreads_db.orig/td_thr_getgregs.c 2002-07-15 23:24:27.000000000 -0400 +++ glibc-2.3.2/linuxthreads_db/td_thr_getgregs.c 2003-08-18 14:43:08.000000000 -0400 @@ -1,5 +1,5 @@ /* Get a thread's general register set. - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1999. @@ -30,8 +30,10 @@ td_thr_getgregs (const td_thrhandle_t *t if (th->th_unique == NULL) { - /* No data yet. */ - memset (gregs, '\0', sizeof (prgregset_t)); + /* No data yet. Use the main thread. */ + pid_t pid = ps_getpid (th->th_ta_p->ph); + if (ps_lgetregs (th->th_ta_p->ph, pid, gregs) != PS_OK) + return TD_ERR; return TD_OK; }