From: Bart Van Assche Date: Sat, 21 Feb 2009 16:17:50 +0000 (+0000) Subject: - Bug fix: swapped order of VG_(OSetGen_Remove)() and X-Git-Tag: svn/VALGRIND_3_5_0~951 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a290f86cbba293837a49f2e0c414b725b27c9df;p=thirdparty%2Fvalgrind.git - Bug fix: swapped order of VG_(OSetGen_Remove)() and (*p->any.cleanup)(p) such that the "first observed at" information is now included in error messages. - Performance optimization: started using VG_(OSetGen_ResetIterAt)(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9214 --- diff --git a/drd/drd_clientobj.c b/drd/drd_clientobj.c index d1f5f9641c..6c7620d8a2 100644 --- a/drd/drd_clientobj.c +++ b/drd/drd_clientobj.c @@ -85,9 +85,10 @@ DrdClientobj* DRD_(clientobj_get_any)(const Addr addr) return VG_(OSetGen_Lookup)(s_clientobj_set, &addr); } -/** Return the data associated with the client object at client address addr - * and that has object type t. Return 0 if there is no client object in the - * set with the specified start address. +/** + * Return the data associated with the client object at client address addr + * and that has object type t. Return 0 if there is no client object in the + * set with the specified start address. */ DrdClientobj* DRD_(clientobj_get)(const Addr addr, const ObjType t) { @@ -144,6 +145,12 @@ DrdClientobj* DRD_(clientobj_add)(const Addr a1, const ObjType t) return p; } +/** + * Remove the information that was stored about the client object. + * + * @param[in] addr Address of the client object in the client address space. + * @param[in] t Type of the client object. + */ Bool DRD_(clientobj_remove)(const Addr addr, const ObjType t) { DrdClientobj* p; @@ -154,27 +161,28 @@ Bool DRD_(clientobj_remove)(const Addr addr, const ObjType t) return clientobj_remove_obj(p); } +/** + * Remove the information that was stored about the client object p. + * + * @note The order of operations below is important. The client object is + * removed from the client object set after the cleanup function has been + * called such that if the cleanup function can still use the function + * DRD_(clientobj_get_any)(). This happens e.g. in the function + * first_observed() in drd_error.c. + */ static Bool clientobj_remove_obj(DrdClientobj* const p) { - DrdClientobj* q; + tl_assert(p); if (s_trace_clientobj) { VG_(message)(Vg_UserMsg, "Removing client object 0x%lx of type %d", p->any.a1, p->any.type); -#if 0 - VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), - VG_(clo_backtrace_size)); -#endif } - tl_assert(p); - q = VG_(OSetGen_Remove)(s_clientobj_set, &p->any.a1); - tl_assert(p == q); - - tl_assert(VG_(OSetGen_Lookup)(s_clientobj_set, &p->any.a1) == 0); tl_assert(p->any.cleanup); (*p->any.cleanup)(p); + VG_(OSetGen_Remove)(s_clientobj_set, &p->any.a1); VG_(OSetGen_FreeNode)(s_clientobj_set, p); return True; } @@ -196,13 +204,10 @@ void DRD_(clientobj_stop_using_mem)(const Addr a1, const Addr a2) if (a1 <= p->any.a1 && p->any.a1 < a2) { removed_at = p->any.a1; - DRD_(clientobj_remove)(p->any.a1, p->any.type); + clientobj_remove_obj(p); /* The above call removes an element from the oset and hence */ /* invalidates the iterator. Set the iterator back. */ - VG_(OSetGen_ResetIter)(s_clientobj_set); - while ((p = VG_(OSetGen_Next)(s_clientobj_set)) != 0 - && p->any.a1 <= removed_at) - { } + VG_(OSetGen_ResetIterAt)(s_clientobj_set, &removed_at); } else { diff --git a/drd/tests/bar_bad.stderr.exp b/drd/tests/bar_bad.stderr.exp index a159938542..6b50433a51 100644 --- a/drd/tests/bar_bad.stderr.exp +++ b/drd/tests/bar_bad.stderr.exp @@ -34,6 +34,9 @@ barrier 0x........ was first observed at: Destruction of barrier that is being waited upon: barrier 0x........ at 0x........: pthread_barrier_destroy (drd_pthread_intercepts.c:?) by 0x........: main (bar_bad.c:?) +barrier 0x........ was first observed at: + at 0x........: pthread_barrier_init (drd_pthread_intercepts.c:?) + by 0x........: main (bar_bad.c:?) destroy a barrier that was never initialised @@ -44,3 +47,6 @@ Not a barrier Destruction of barrier that is being waited upon: barrier 0x........ at 0x........: free (vg_replace_malloc.c:...) by 0x........: main (bar_bad.c:?) +barrier 0x........ was first observed at: + at 0x........: pthread_barrier_init (drd_pthread_intercepts.c:?) + by 0x........: main (bar_bad.c:?) diff --git a/drd/tests/tc04_free_lock.stderr.exp b/drd/tests/tc04_free_lock.stderr.exp index fbb85cd91f..76657545db 100644 --- a/drd/tests/tc04_free_lock.stderr.exp +++ b/drd/tests/tc04_free_lock.stderr.exp @@ -2,17 +2,32 @@ Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: free (vg_replace_malloc.c:...) by 0x........: main (tc04_free_lock.c:24) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc04_free_lock.c:20) Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: bar (tc04_free_lock.c:40) by 0x........: main (tc04_free_lock.c:26) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?) + by 0x........: bar (tc04_free_lock.c:38) + by 0x........: main (tc04_free_lock.c:26) Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: foo (tc04_free_lock.c:49) by 0x........: main (tc04_free_lock.c:27) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: foo (tc04_free_lock.c:46) + by 0x........: main (tc04_free_lock.c:27) Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: bar (tc04_free_lock.c:40) by 0x........: main (tc04_free_lock.c:28) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?) + by 0x........: bar (tc04_free_lock.c:38) + by 0x........: main (tc04_free_lock.c:28) ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0) diff --git a/drd/tests/tc09_bad_unlock.stderr.exp b/drd/tests/tc09_bad_unlock.stderr.exp index b8bf909dae..f78b25f56d 100644 --- a/drd/tests/tc09_bad_unlock.stderr.exp +++ b/drd/tests/tc09_bad_unlock.stderr.exp @@ -29,6 +29,10 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: nearly_main (tc09_bad_unlock.c:45) by 0x........: main (tc09_bad_unlock.c:49) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: nearly_main (tc09_bad_unlock.c:31) + by 0x........: main (tc09_bad_unlock.c:49) --------------------- Mutex not locked by calling thread: mutex 0x........, recursion count 0, owner 1. @@ -61,5 +65,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: nearly_main (tc09_bad_unlock.c:45) by 0x........: main (tc09_bad_unlock.c:50) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: nearly_main (tc09_bad_unlock.c:31) + by 0x........: main (tc09_bad_unlock.c:50) ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0) diff --git a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.3 b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.3 index a715c838a1..e8bae84d66 100644 --- a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.3 +++ b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.3 @@ -24,6 +24,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) make pthread_mutex_lock fail: skipped on glibc < 2.4 @@ -132,8 +135,14 @@ FIXME: can't figure out how to verify wrap of sem_post Destroying locked rwlock: rwlock 0x......... at 0x........: main (tc20_verifywrap.c:262) +rwlock 0x........ was first observed at: + at 0x........: pthread_rwlock_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:216) Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: main (tc20_verifywrap.c:262) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:145) ERROR SUMMARY: 15 errors from 15 contexts (suppressed: 0 from 0) diff --git a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5 b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5 index 1e531a84c8..62a85db611 100644 --- a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5 +++ b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5 @@ -24,6 +24,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) The object at address 0x........ is not a mutex. at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?) @@ -136,8 +139,14 @@ FIXME: can't figure out how to verify wrap of sem_post Destroying locked rwlock: rwlock 0x......... at 0x........: main (tc20_verifywrap.c:262) +rwlock 0x........ was first observed at: + at 0x........: pthread_rwlock_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:216) Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: main (tc20_verifywrap.c:262) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:145) ERROR SUMMARY: 16 errors from 16 contexts (suppressed: 0 from 0) diff --git a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5-ppc b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5-ppc index 93e3d8a55c..802e53c4cb 100644 --- a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5-ppc +++ b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.5-ppc @@ -24,6 +24,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) The object at address 0x........ is not a mutex. at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?) diff --git a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.8 b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.8 index f4290f4910..6e9c12c0f9 100644 --- a/drd/tests/tc20_verifywrap.stderr.exp-glibc2.8 +++ b/drd/tests/tc20_verifywrap.stderr.exp-glibc2.8 @@ -24,6 +24,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) The object at address 0x........ is not a mutex. at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?) diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 index 9e29a244e5..5e0a3d0c33 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 @@ -159,10 +159,16 @@ FIXME: can't figure out how to verify wrap of sem_post Destroying locked rwlock: rwlock 0x......... at 0x........: main (tc20_verifywrap.c:262) +rwlock 0x........ was first observed at: + at 0x........: pthread_rwlock_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:216) [1/1] mutex_destroy error checking mutex 0x........ rc 1 owner 1 Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: main (tc20_verifywrap.c:262) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:145) [1/1] mutex_destroy invalid mutex 0x........ rc 0 owner 0 [1/1] mutex_trylock recursive mutex 0x........ rc 0 owner 0 [1/1] post_mutex_lock recursive mutex 0x........ rc 0 owner 0 diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b index 4be55c3794..cc9e1e9c73 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b @@ -159,10 +159,16 @@ FIXME: can't figure out how to verify wrap of sem_post Destroying locked rwlock: rwlock 0x......... at 0x........: main (tc20_verifywrap.c:262) +rwlock 0x........ was first observed at: + at 0x........: pthread_rwlock_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:216) [1/1] mutex_destroy error checking mutex 0x........ rc 1 owner 1 Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: main (tc20_verifywrap.c:262) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:145) [1/1] mutex_destroy invalid mutex 0x........ rc 0 owner 0 [1/1] mutex_trylock recursive mutex 0x........ rc 0 owner 0 [1/1] post_mutex_lock recursive mutex 0x........ rc 0 owner 0 diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 index 9b729075ea..5e38246cd9 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 @@ -29,6 +29,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) [1/1] mutex_trylock invalid mutex 0x........ rc 0 owner 0 The object at address 0x........ is not a mutex. @@ -165,10 +168,16 @@ FIXME: can't figure out how to verify wrap of sem_post Destroying locked rwlock: rwlock 0x......... at 0x........: main (tc20_verifywrap.c:262) +rwlock 0x........ was first observed at: + at 0x........: pthread_rwlock_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:216) [1/1] mutex_destroy error checking mutex 0x........ rc 1 owner 1 Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: main (tc20_verifywrap.c:262) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:145) [1/1] mutex_destroy invalid mutex 0x........ rc 0 owner 0 [1/1] mutex_trylock recursive mutex 0x........ rc 0 owner 0 [1/1] post_mutex_lock recursive mutex 0x........ rc 0 owner 0 diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc index 0b7f0c14ae..1479e9b4ec 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc @@ -29,6 +29,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) [1/1] mutex_trylock invalid mutex 0x........ rc 0 owner 0 The object at address 0x........ is not a mutex. diff --git a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 index 5007779148..cb887e017c 100644 --- a/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 +++ b/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 @@ -29,6 +29,9 @@ The object at address 0x........ is not a mutex. Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: pthread_mutex_destroy (drd_pthread_intercepts.c:?) by 0x........: main (tc20_verifywrap.c:102) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:100) [1/1] mutex_trylock invalid mutex 0x........ rc 0 owner 0 The object at address 0x........ is not a mutex.