]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DRD now prints where a mutex appeared for the first time in addition to
authorBart Van Assche <bvanassche@acm.org>
Sat, 28 Jun 2008 13:40:41 +0000 (13:40 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sat, 28 Jun 2008 13:40:41 +0000 (13:40 +0000)
the mutex address when an error message is printed for condition
variables.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8296

exp-drd/drd_clientobj.h
exp-drd/drd_error.c
exp-drd/drd_mutex.c
exp-drd/drd_mutex.h
exp-drd/tests/pth_cond_race.stderr.exp
exp-drd/tests/tc23_bogus_condwait.stderr.exp

index 0068dc33d7d1fa6f06d63c05ce2181e964cb3609..b8297b7f11285776b988195b9bc747773adc1ccd 100644 (file)
@@ -66,6 +66,7 @@ struct mutex_info
   DrdThreadId owner;           // owner if locked, last owner if free.
   Segment*    last_locked_segment;
   ULong       acquiry_time_ms;
+  ExeContext* first_observed_at;
   ExeContext* acquired_at;
 };
 
index e4f35815b691e9f25aae5f3544cd3bb5caedd8f7..842a6379dc4f0d44b987b18d9ab37f62d16a2770 100644 (file)
 */
 
 
+#include "drd_clientobj.h"        /* struct mutex_info        */
 #include "drd_error.h"
 #include "drd_malloc_wrappers.h"
-#include "drd_mutex.h"            // struct mutex_info
-#include "drd_suppression.h"      // drd_start_suppression()
-#include "pub_drd_bitmap.h"       // LHS_W, ...
+#include "drd_mutex.h"
+#include "drd_suppression.h"      /* drd_start_suppression()  */
+#include "pub_drd_bitmap.h"       /* LHS_W, ...               */
 #include "pub_tool_vki.h"
 #include "pub_tool_basics.h"
-#include "pub_tool_libcassert.h"  // tl_assert()
-#include "pub_tool_libcbase.h"    // strlen()
-#include "pub_tool_libcfile.h"    // VG_(get_startup_wd)()
-#include "pub_tool_libcprint.h"   // VG_(printf)()
+#include "pub_tool_libcassert.h"  /* tl_assert()              */
+#include "pub_tool_libcbase.h"    /* strlen()                 */
+#include "pub_tool_libcfile.h"    /* VG_(get_startup_wd)()    */
+#include "pub_tool_libcprint.h"   /* VG_(printf)()            */
 #include "pub_tool_machine.h"
-#include "pub_tool_mallocfree.h"  // VG_(malloc), VG_(free)
-#include "pub_tool_threadstate.h" // VG_(get_pthread_id)()
-#include "pub_tool_tooliface.h"   // VG_(needs_tool_errors)()
+#include "pub_tool_mallocfree.h"  /* VG_(malloc), VG_(free)   */
+#include "pub_tool_threadstate.h" /* VG_(get_pthread_id)()    */
+#include "pub_tool_tooliface.h"   /* VG_(needs_tool_errors)() */
 
 
 /* Local variables. */
@@ -50,8 +51,9 @@ void set_show_conflicting_segments(const Bool scs)
   s_drd_show_conflicting_segments = scs;
 }
 
-/* Describe a data address range [a,a+len[ as good as possible, for error */
-/* messages, putting the result in ai. */
+/** Describe a data address range [a,a+len[ as good as possible, for error
+ *  messages, putting the result in ai.
+ */
 static
 void describe_malloced_addr(Addr const a, SizeT const len, AddrInfo* const ai)
 {
@@ -68,6 +70,24 @@ void describe_malloced_addr(Addr const a, SizeT const len, AddrInfo* const ai)
   }
 }
 
+/** Report where a mutex has been observed for the first time. The printed
+ *  call stack will either refer to a pthread_mutex_init() or a
+ *  pthread_mutex_lock() call.
+ */
+static void mutex_first_observed(const Addr mutex)
+{
+  struct mutex_info* mi;
+
+  mi = mutex_get(mutex);
+  if (mi)
+  {
+    tl_assert(mi->first_observed_at);
+    VG_(message)(Vg_UserMsg,
+                 "Mutex 0x%lx was first observed at:", mutex);
+    VG_(pp_ExeContext)(mi->first_observed_at);
+  }
+}
+
 static
 void drd_report_data_race2(Error* const err, const DataRaceErrInfo* const dri)
 {
@@ -171,10 +191,11 @@ static void drd_tool_error_pp(Error* const e)
     CondRaceErrInfo* cei = (CondRaceErrInfo*)(VG_(get_error_extra)(e));
     VG_(message)(Vg_UserMsg,
                  "Probably a race condition: condition variable 0x%lx has been"
-                 " signalled but the associated mutex 0x%lx is not locked"
-                 " by the signalling thread",
+                 " signaled but the associated mutex 0x%lx is not locked"
+                 " by the signalling thread.",
                  cei->cond, cei->mutex);
     VG_(pp_ExeContext)(VG_(get_error_where)(e));
+    mutex_first_observed(cei->mutex);
     break;
   }
   case CondDestrErr: {
@@ -185,10 +206,11 @@ static void drd_tool_error_pp(Error* const e)
                  cdi->cond, cdi->mutex,
                  DrdThreadIdToVgThreadId(cdi->tid), cdi->tid);
     VG_(pp_ExeContext)(VG_(get_error_where)(e));
+    mutex_first_observed(cdi->mutex);
     break;
   }
   case SemaphoreErr: {
-    SemaphoreErrInfo* sei =(SemaphoreErrInfo*)(VG_(get_error_extra)(e));
+    SemaphoreErrInfo* sei = (SemaphoreErrInfo*)(VG_(get_error_extra)(e));
     tl_assert(sei);
     VG_(message)(Vg_UserMsg,
                  "%s: semaphore 0x%lx",
index dd009de1462bc95b9e27bd689dcbe3027d2b919a..823da1cd5bd3355fac3427922a02afbe001142e8 100644 (file)
@@ -77,6 +77,7 @@ void mutex_initialize(struct mutex_info* const p,
   p->owner               = DRD_INVALID_THREADID;
   p->last_locked_segment = 0;
   p->acquiry_time_ms     = 0;
+  p->first_observed_at   = VG_(record_ExeContext)(VG_(get_running_tid)(), 0);
   p->acquired_at         = 0;
 }
 
@@ -109,6 +110,7 @@ static void mutex_cleanup(struct mutex_info* p)
   p->last_locked_segment = 0;
 }
 
+/** Let Valgrind report that there is no mutex object at address 'mutex'. */
 static void not_a_mutex(const Addr mutex)
 {
   MutexErrInfo MEI = { mutex, -1, DRD_INVALID_THREADID };
index 3babae473ef390ba8a17c404851c5fba34266a79..e241f673fccbdf2884b19619702caee801d67c80 100644 (file)
@@ -23,9 +23,6 @@
 */
 
 
-// Mutex state information: owner thread and recursion count.
-
-
 #ifndef __DRD_MUTEX_H
 #define __DRD_MUTEX_H
 
index 6cea56a3b93964dda24970bd746b5c6263eadae5..8e38ee6eb96bf5b6c9af0778a32e1e3d7468b2ae 100644 (file)
@@ -1,10 +1,13 @@
 
 Thread 2:
-Probably a race condition: condition variable 0x........ has been signalled but the associated mutex 0x........ is not locked by the signalling thread
+Probably a race condition: condition variable 0x........ has been signaled but the associated mutex 0x........ is not locked by the signalling thread.
    at 0x........: pthread_cond_signal* (drd_pthread_intercepts.c:?)
    by 0x........: thread_func (pth_cond_race.c:?)
    by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
    by 0x........: (within libpthread-?.?.so)
    by 0x........: clone (in /...libc...)
+Mutex 0x........ was first observed at:
+   at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?)
+   by 0x........: main (pth_cond_race.c:?)
 
 ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
index b64e170388272acf61c48ed7b6b8603818e9eade..7ce65f2c9cbc155434e8dd57e8a0be7f19946b3d 100644 (file)
@@ -4,7 +4,7 @@ The object at address 0x........ is not a mutex.
    by 0x........: main (tc23_bogus_condwait.c:69)
 
 Thread 3:
-Probably a race condition: condition variable 0x........ has been signalled but the associated mutex 0x........ is not locked by the signalling thread
+Probably a race condition: condition variable 0x........ has been signaled but the associated mutex 0x........ is not locked by the signalling thread.
    at 0x........: pthread_cond_signal* (drd_pthread_intercepts.c:?)
    by 0x........: rescue_me (tc23_bogus_condwait.c:20)
    by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
@@ -17,12 +17,15 @@ Mutex not locked: mutex 0x........, recursion count 0, owner 0.
    by 0x........: main (tc23_bogus_condwait.c:72)
 
 Thread 3:
-Probably a race condition: condition variable 0x........ has been signalled but the associated mutex 0x........ is not locked by the signalling thread
+Probably a race condition: condition variable 0x........ has been signaled but the associated mutex 0x........ is not locked by the signalling thread.
    at 0x........: pthread_cond_signal* (drd_pthread_intercepts.c:?)
    by 0x........: rescue_me (tc23_bogus_condwait.c:24)
    by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
    by 0x........: (within libpthread-?.?.so)
    by 0x........: clone (in /...libc...)
+Mutex 0x........ was first observed at:
+   at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?)
+   by 0x........: main (tc23_bogus_condwait.c:51)
 
 Thread 1:
 The object at address 0x........ is not a mutex.
@@ -30,7 +33,7 @@ The object at address 0x........ is not a mutex.
    by 0x........: main (tc23_bogus_condwait.c:75)
 
 Thread 3:
-Probably a race condition: condition variable 0x........ has been signalled but the associated mutex 0x........ is not locked by the signalling thread
+Probably a race condition: condition variable 0x........ has been signaled but the associated mutex 0x........ is not locked by the signalling thread.
    at 0x........: pthread_cond_signal* (drd_pthread_intercepts.c:?)
    by 0x........: rescue_me (tc23_bogus_condwait.c:28)
    by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
@@ -43,12 +46,15 @@ Mutex not locked by calling thread: mutex 0x........, recursion count 1, owner 2
    by 0x........: main (tc23_bogus_condwait.c:78)
 
 Thread 3:
-Probably a race condition: condition variable 0x........ has been signalled but the associated mutex 0x........ is not locked by the signalling thread
+Probably a race condition: condition variable 0x........ has been signaled but the associated mutex 0x........ is not locked by the signalling thread.
    at 0x........: pthread_cond_signal* (drd_pthread_intercepts.c:?)
    by 0x........: rescue_me (tc23_bogus_condwait.c:32)
    by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
    by 0x........: (within libpthread-?.?.so)
    by 0x........: clone (in /...libc...)
+Mutex 0x........ was first observed at:
+   at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?)
+   by 0x........: main (tc23_bogus_condwait.c:53)
 The impossible happened: mutex 0x........ is locked simultaneously by two threads (recursion count 1, owners 2 and 1) !
 
 Thread 2: