This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: NPTL libthread_db changes for static debugging


I don't really like that fake creation event.  It's not really right.

I have had this patch sitting in my tree for, well, I guess about a year
and half.  I don't recall whether static pthreads was what this was about,
but I can't off hand see what else it would have been.  This makes
td_ta_map_lwp2thr, and thereby td_ta_thr_iter, fail with TD_NOTHR before
the thread register is set up.  That should prevent the confused results
you mentioned.  

This doesn't stop for the debugger as soon as things are initialized.  But
I don't really see the need for that.  You can try map_lwp2thr again the
next time the process stops for whatever reason.  You don't really need to
know it until first real thread creation event.

What do you think?


Thanks,
Roland


2004-09-09  Roland McGrath  <roland@redhat.com>

	* td_ta_map_lwp2thr.c (td_ta_map_lwp2thr): Check for uninitialized
	thread register in initial thread, and return TD_NOTHR for that case.

Index: nptl_db/td_ta_map_lwp2thr.c
===================================================================
RCS file: /cvs/glibc/libc/nptl_db/td_ta_map_lwp2thr.c,v
retrieving revision 1.5
diff -b -B -p -u -r1.5 td_ta_map_lwp2thr.c
--- nptl_db/td_ta_map_lwp2thr.c	9 Sep 2004 22:50:10 -0000	1.5
+++ nptl_db/td_ta_map_lwp2thr.c	3 Mar 2006 11:31:57 -0000
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <byteswap.h>
 #include <sys/procfs.h>
+#include <errno.h>
 
 
 td_err_e
@@ -119,8 +120,6 @@ td_ta_map_lwp2thr (const td_thragent_t *
   switch (ta->ta_howto)
     {
     case ta_howto_unknown:
-      return TD_DBERR;
-
     default:
       return TD_DBERR;
 
@@ -132,6 +131,13 @@ td_ta_map_lwp2thr (const td_thragent_t *
 				    0, regs, &addr);
       if (terr != TD_OK)
 	return terr;
+
+      /* If the inferior is too early in startup, its thread register
+	 is not initialized yet.  The only way we can really tell this
+	 is by assuming the uninitialized value is zero.  */
+      if (addr == (psaddr_t) 0)
+	return lwpid == ps_getpid (ta->ph) ? TD_NOTHR : TD_ERR;
+
       /* In this descriptor the nelem word is overloaded as the bias.  */
       addr += (int32_t) DB_DESC_NELEM (ta->ta_howto_data.reg);
       th->th_unique = addr;
@@ -146,8 +152,14 @@ td_ta_map_lwp2thr (const td_thragent_t *
        /* A la x86-64, there is a constant magic index for get_thread_area.  */
        if (ps_get_thread_area (ta->ph, lwpid,
 			       ta->ta_howto_data.const_thread_area,
-			       &th->th_unique) != PS_OK)
+			      &addr) != PS_OK)
 	 return TD_ERR;	/* XXX Other error value?  */
+
+      /* In early startup, the pseudo-register has not been set up yet.  */
+      if (addr == (psaddr_t) 0)
+	return lwpid == ps_getpid (ta->ph) ? TD_NOTHR : TD_ERR;
+
+      th->th_unique = addr;
        break;
 
      case ta_howto_reg_thread_area:
@@ -167,7 +179,13 @@ td_ta_map_lwp2thr (const td_thragent_t *
 	   ((addr - (psaddr_t) 0)
 	    >> DB_DESC_NELEM (ta->ta_howto_data.reg_thread_area)),
 	   &th->th_unique) != PS_OK)
+	{
+	  /* In early startup, the segment register has not been set up yet
+	     and is not a valid index for get_thread_area.  */
+	  if (errno == EINVAL)
+	    return lwpid == ps_getpid (ta->ph) ? TD_NOTHR : TD_ERR;
 	return TD_ERR;	/* XXX Other error value?  */
+	}
       break;
     }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]