From owner-p4-projects@FreeBSD.ORG Wed Mar 31 22:57:00 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D518D16A4D1; Wed, 31 Mar 2004 22:56:59 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7AF5F16A4CE for ; Wed, 31 Mar 2004 22:56:59 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5DA7F43D2D for ; Wed, 31 Mar 2004 22:56:59 -0800 (PST) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.10/8.12.10) with ESMTP id i316uxGe034554 for ; Wed, 31 Mar 2004 22:56:59 -0800 (PST) (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.10/8.12.10/Submit) id i316uwPo034545 for perforce@freebsd.org; Wed, 31 Mar 2004 22:56:58 -0800 (PST) (envelope-from marcel@freebsd.org) Date: Wed, 31 Mar 2004 22:56:58 -0800 (PST) Message-Id: <200404010656.i316uwPo034545@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Subject: PERFORCE change 50102 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2004 06:57:00 -0000 http://perforce.freebsd.org/chv.cgi?CH=50102 Change 50102 by marcel@marcel_nfs on 2004/03/31 22:56:45 When dumping the state of each thread in the process, start with the initial thread (the one which has an ID equal to the PID). This makes sure that bfd creates pseudo-sections with the non-threaded names (i.e. without the TID) for the initial thread. Any tool that doesn't look for the threaded pseudo-sections will behave as before we started dumping all the threads. For example: athlon% objdump -s crash.core | fgrep .reg Contents of section .reg/539: Contents of section .reg: Contents of section .reg2/539: Contents of section .reg2: Contents of section .reg/100005: Contents of section .reg2/100005: Contents of section .reg/100004: Contents of section .reg2/100004: Contents of section .reg/100003: Contents of section .reg2/100003: Contents of section .reg/100002: Contents of section .reg2/100002: Contents of section .reg/100001: Contents of section .reg2/100001: Contents of section .reg/100000: Contents of section .reg2/100000: BTW: Now that we dump all (kernel) threads in the corefile, we can actually see them in gdb(1): athlon% gdb crash crash.core GNU gdb 5.2.1 (FreeBSD) Copyright 2002 Free Software Foundation, Inc. *snip* This GDB was configured as "i386-undermydesk-freebsd"... Core was generated by `crash'. Program terminated with signal 11, Segmentation fault. Reading symbols from /usr/lib/libthr.so.1...done. Loaded symbols for /usr/lib/libthr.so.1 Reading symbols from /lib/libc.so.5...done. Loaded symbols for /lib/libc.so.5 Reading symbols from /libexec/ld-elf.so.1...done. Loaded symbols for /libexec/ld-elf.so.1 #0 main (argc=1, argv=0xbfbfeca8) at crash.c:89 89 *(int*)0 = 0; (gdb) info thread 7 process 100000 0x280dea2f in _umtx_unlock () from /lib/libc.so.5 6 process 100001 0x280df3af in sigtimedwait () from /lib/libc.so.5 5 process 100002 0x280dea4f in _umtx_lock () from /lib/libc.so.5 4 process 100003 0x280df3af in sigtimedwait () from /lib/libc.so.5 3 process 100004 0x280dea4f in _umtx_lock () from /lib/libc.so.5 2 process 100005 0x280df3af in sigtimedwait () from /lib/libc.so.5 * 1 process 539 main (argc=1, argv=0xbfbfeca8) at crash.c:89 (gdb) This gives us basic debugging support for libthr. Affected files ... .. //depot/projects/gdb/sys/kern/imgact_elf.c#5 edit Differences ... ==== //depot/projects/gdb/sys/kern/imgact_elf.c#5 (text+ko) ==== @@ -1137,7 +1137,7 @@ prstatus_t *status; prfpregset_t *fpregset; prpsinfo_t *psinfo; - struct thread *thr; + struct thread *first, *thr; size_t ehoff, noteoff, notesz, phoff; ehoff = *off; @@ -1177,8 +1177,20 @@ __elfN(putnote)(dst, off, "FreeBSD", NT_PRPSINFO, psinfo, sizeof *psinfo); - thr = TAILQ_FIRST(&p->p_threads); - while (thr != NULL) { + /* + * We want to start with the registers of the first thread in the + * process so that the .reg and .reg2 pseudo-sections created by bfd + * will be identical to the .reg/$PID and .reg2/$PID pseudo-sections. + * This makes sure that any tool that only looks for .reg and .reg2 + * and not for .reg/$PID and .reg2/$PID will behave the same as + * before. The first thread is the thread with an ID equal to the + * process' ID. + */ + first = TAILQ_FIRST(&p->p_threads); + while (first->td_tid > PID_MAX) + first = TAILQ_NEXT(first, td_plist); + thr = first; + do { if (dst != NULL) { status->pr_version = PRSTATUS_VERSION; status->pr_statussz = sizeof(prstatus_t); @@ -1194,11 +1206,12 @@ sizeof *status); __elfN(putnote)(dst, off, "FreeBSD", NT_FPREGSET, fpregset, sizeof *fpregset); - /* - * XXX allow for MD specific notes. - */ - thr = TAILQ_NEXT(thr, td_plist); - } + /* XXX allow for MD specific notes. */ + thr = (thr == first) ? TAILQ_FIRST(&p->p_threads) : + TAILQ_NEXT(thr, td_plist); + if (thr == first) + thr = TAILQ_NEXT(thr, td_plist); + } while (thr != NULL); notesz = *off - noteoff;