]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
An error message is now printed if the mutex pointer passed to
authorBart Van Assche <bvanassche@acm.org>
Sat, 28 Jun 2008 16:28:49 +0000 (16:28 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sat, 28 Jun 2008 16:28:49 +0000 (16:28 +0000)
pthread_cond_wait() does not point to a mutex object, and also if the
mutex pointer passed to pthread_cond_wait() points to a recursive mutex
that has been locked recursively.

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

exp-drd/drd_cond.c
exp-drd/tests/tc23_bogus_condwait.stderr.exp

index 7cdd581ad8f5f8d9af0c2480e557176cc8bd7701..c5b04a4b77bcec17ca0fff4472eb2dc5d6a5f612 100644 (file)
@@ -182,10 +182,13 @@ void cond_post_destroy(const Addr cond)
   clientobj_remove(p->a1, ClientCondvar);
 }
 
-/** Called before pthread_cond_wait(). */
+/** Called before pthread_cond_wait(). Note: before this function is called,
+ *  mutex_unlock() has already been called from drd_clientreq.c.
+ */
 int cond_pre_wait(const Addr cond, const Addr mutex)
 {
   struct cond_info* p;
+  struct mutex_info* q;
 
   if (s_trace_cond)
   {
@@ -214,6 +217,23 @@ int cond_pre_wait(const Addr cond, const Addr mutex)
                             " and mutex",
                             &cwei);
   }
+  tl_assert(p->mutex);
+  q = mutex_get(p->mutex);
+  if (q && q->recursion_count > 0)
+  {
+    const ThreadId vg_tid = VG_(get_running_tid)();
+    MutexErrInfo MEI = { q->a1, q->recursion_count, q->owner };
+    VG_(maybe_record_error)(vg_tid,
+                            MutexErr,
+                            VG_(get_IP)(vg_tid),
+                            "Mutex locked recursively",
+                            &MEI);
+  }
+  else if (q == 0)
+  {
+    not_a_mutex(p->mutex);
+  }
+
   return ++p->waiter_count;
 }
 
index 7ce65f2c9cbc155434e8dd57e8a0be7f19946b3d..d1911d407c8cb94d289ca08be49a7b9c02fa0014 100644 (file)
@@ -1,4 +1,8 @@
 
+The object at address 0x........ is not a mutex.
+   at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
+   by 0x........: main (tc23_bogus_condwait.c:69)
+
 The object at address 0x........ is not a mutex.
    at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc23_bogus_condwait.c:69)
@@ -32,6 +36,10 @@ The object at address 0x........ is not a mutex.
    at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc23_bogus_condwait.c:75)
 
+The object at address 0x........ is not a mutex.
+   at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
+   by 0x........: main (tc23_bogus_condwait.c:75)
+
 Thread 3:
 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:?)
@@ -45,6 +53,10 @@ Mutex not locked by calling thread: mutex 0x........, recursion count 1, owner 2
    at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc23_bogus_condwait.c:78)
 
+Mutex locked recursively: mutex 0x........, recursion count 1, owner 2.
+   at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
+   by 0x........: main (tc23_bogus_condwait.c:78)
+
 Thread 3:
 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:?)
@@ -65,4 +77,4 @@ Mutex not locked by calling thread: mutex 0x........, recursion count 2, owner 1
    by 0x........: (within libpthread-?.?.so)
    by 0x........: clone (in /...libc...)
 
-ERROR SUMMARY: 9 errors from 9 contexts (suppressed: 0 from 0)
+ERROR SUMMARY: 12 errors from 12 contexts (suppressed: 0 from 0)