Only pass valid ThreadIDs to VG_(record_ExeContext).  (Bart Van Assche)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7261 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/exp-drd/TODO.txt b/exp-drd/TODO.txt
index cbe891f..3566e8c 100644
--- a/exp-drd/TODO.txt
+++ b/exp-drd/TODO.txt
@@ -4,6 +4,7 @@
 
 Data-race detection algorithm
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Implement glibc version detection in drd_main.c.
 - Implement segment merging, such that the number of segments per thread
   remains limited even when there is no synchronization between threads.
 - Find out why a race is reported on std::string::string(std::string const&)
diff --git a/exp-drd/drd_preloaded.c b/exp-drd/drd_preloaded.c
index 0a0b300..a0c6a1a 100644
--- a/exp-drd/drd_preloaded.c
+++ b/exp-drd/drd_preloaded.c
@@ -198,10 +198,6 @@
       {
          assert(0);
       }
-#if 0
-      printf("[%ld] Requested detach state for new thread: %d\n",
-             pthread_self(), vgargs.detachstate);
-#endif
    }
    assert(vgargs.detachstate == PTHREAD_CREATE_JOINABLE
           || vgargs.detachstate == PTHREAD_CREATE_DETACHED);
@@ -224,9 +220,12 @@
    // in this file (vg_preloaded.c) would be called instead of those in
    // libpthread.so. This loop is necessary because vgargs is allocated on the
    // stack, and the created thread reads it.
-   while (! vgargs.wrapper_started)
+   if (ret == 0)
    {
-      sched_yield();
+      while (! vgargs.wrapper_started)
+      {
+         sched_yield();
+      }
    }
 #endif
    return ret;
diff --git a/exp-drd/drd_segment.c b/exp-drd/drd_segment.c
index cb4b979..a83a414 100644
--- a/exp-drd/drd_segment.c
+++ b/exp-drd/drd_segment.c
@@ -23,15 +23,16 @@
 */
 
 
+#include "drd_error.h"
+#include "drd_segment.h"
+#include "drd_thread.h"
 #include "pub_tool_basics.h"      // Addr, SizeT
 #include "pub_tool_errormgr.h"    // VG_(unique_error)()
 #include "pub_tool_libcassert.h"  // tl_assert()
 #include "pub_tool_libcbase.h"    // VG_(strlen)()
 #include "pub_tool_libcprint.h"   // VG_(printf)()
 #include "pub_tool_mallocfree.h"  // VG_(malloc)(), VG_(free)()
-#include "drd_error.h"
-#include "drd_segment.h"
-#include "drd_thread.h"
+#include "pub_tool_threadstate.h" // VG_INVALID_THREADID
 
 
 // Local variables.
@@ -52,6 +53,7 @@
              DrdThreadId const created)
 {
   Segment* creator_sg;
+  ThreadId vg_created = DrdThreadIdToVgThreadId(created);
 
   tl_assert(sg);
   tl_assert(creator == DRD_INVALID_THREADID || IsValidDrdThreadId(creator));
@@ -62,7 +64,10 @@
   sg->next = 0;
   sg->prev = 0;
 
-  sg->stacktrace = VG_(record_ExeContext)(created, 0);
+  if (vg_created != VG_INVALID_THREADID)
+    sg->stacktrace = VG_(record_ExeContext)(vg_created, 0);
+  else
+    sg->stacktrace = 0;
 
   if (creator_sg)
     vc_copy(&sg->vc, &creator_sg->vc);