PERFORCE change 50102 for review

Marcel Moolenaar marcel at FreeBSD.org
Wed Mar 31 22:57:00 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=50102

Change 50102 by marcel at 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;
 


More information about the p4-projects mailing list