|
From: Julian S. <js...@ac...> - 2006-08-27 00:44:56
|
> I don't have an answer yet why drd fails on pth_cvsimple.
Fixed. The wrapper function for pthread_cond_wait in vg_preloaded.c
never took effect, because (1) it was for a function "pthread_cont_wait"
and (2), even when you fix the typo, libpthread.so does not export
a function with exactly the name "pthread_cond_wait":
sewardj@suse10:~/VgTRUNK/drd$ nm /lib/tls/libpthread-2.3.5.so \
| grep " T " \
| | grep pthread_cond_wait
00008060 T pthread_cond_wait@GLIBC_2.0
000079f0 T pthread_cond_wait@@GLIBC_2.3.2
These are versioned glibc symbols, and to be reliable we need to
intercept both. Therefore I asked the wrapper instead to intercept
any function in libpthread.so whose name matches "pthread_cond_wait@*";
that way it intercepts both entry points. A similar trick already
applies to the pthread_create intercept.
The actual fix is trivial; vg_preloaded.c:260 needs to be changed to
PTH_FUNC(int, pthreadZucondZuwaitZAZa, // pthread_cond_wait@*
The Z-encodings for _, @ and * are Zu, ZA, Za respectively; that's
how the name is generated. With this change pth_cvsimple runs
successfully.
--trace-redir=yes is your friend for such games. It tells you
(repeatedly) the redirection specifications in effect. A
specification is basically a statement saying
"redirect function F in object with soname S to some
replacement function G."
Both F and S may have wildcards, to make it more flexible.
It also shows you the active redirections, that is, the subset
of the specifications currently in effect. Both the spec and
active sets are updated after every .so load/unload.
---------
This fix means knode in KDE 3.5.4 (a threaded app) does not crash at
exit any more. Now it appears to hang instead :-)
If you intercept pthread_cond_wait, do you also need to intercept
pthread_cond_broadcast too?
J
> But when I enable
> mutex tracing in drd, it looks like threads 2 and 3 were able to both lock
> count_lock. How can I verify that the pthread_mutex_lock() implementation
> of libpthread.so.0 is called and not the implementation of libc.so.6 ? For
> most pthread functions there are dummy implementation present in glibc.
>
> > inst/bin/valgrind --tool=drd --trace-mutex=yes none/tests/pth_cvsimple
>
> ==13717== drd, a data race detector.
> ==13717== Copyright (C) 2006, and GNU GPL'd, by Bart Van Assche.
> THIS SOFTWARE IS A PROTOTYPE, AND IS NOT YET RELEASED
> ==13717== Using LibVEX rev 1579, a library for dynamic binary translation.
> ==13717== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
> ==13717== Using valgrind-3.3.0.SVN, a dynamic binary instrumentation
> framework.
> ==13717== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
> ==13717== For more details, rerun with: -v
> ==13717==
> --13717-- drd_post_mutex_lock tid = 1, mutex 0x401B2E0 rc 0 owner 0
> --13717-- drd_pre_mutex_unlock tid = 1, mutex 0x401B2E0 rc 1 owner 1
> --13717-- drd_post_mutex_lock tid = 2, mutex 0x8049A48 rc 0 owner 0
> --13717-- drd_post_mutex_lock tid = 3, mutex 0x8049A48 rc 1 owner 2
> --13717-- The impossible happened: mutex 0x8049A48 is locked simultaneously
> by two threads (recursion count 1, owners 2 and 3) !
>
> drd: drd_mutex.c:96 (mutex_lock): the 'impossible' happened.
> ==13717== at 0x38007585: report_and_quit (m_libcassert.c:136)
> ==13717== by 0x380078AF: vgPlain_assert_fail (m_libcassert.c:200)
> ==13717== by 0x380021B8: mutex_lock (drd_mutex.c:96)
> ==13717== by 0x380016F3: drd_post_mutex_lock (drd_main.c:202)
> ==13717== by 0x380265EE: do_client_request (scheduler.c:1256)
> ==13717== by 0x38027C5B: vgPlain_scheduler (scheduler.c:872)
> ==13717== by 0x38046B63: run_a_thread_NORETURN (syswrap-linux.c:87)
> ==13717== by 0x38046DC3: vgModuleLocal_start_thread_NORETURN (
> syswrap-linux.c:207)
> ==13717== by 0x38049088: (within
> /home/bart/software/valgrind-svn/inst/lib/valgrind/x86-linux/drd)
> ==13717== by 0x382450AF: temporary (in
> /home/bart/software/valgrind-svn/inst/lib/valgrind/x86-linux/drd)
> ==13717== by 0x8: ???
>
> sched status:
> running_tid=3
>
> Thread 1: status = VgTs_Yielding
> ==13717== at 0x410A648: clone (in /lib/libc-2.4.so)
> ==13717== by 0x403E9BC: pthread_create@@GLIBC_2.1 (in /lib/libpthread-
> 2.4.so)
> ==13717== by 0x401CAAF: pthread_create@* (vg_preloaded.c:135)
> ==13717== by 0x80486FF: main (pth_cvsimple.c:68)
>
> Thread 2: status = VgTs_WaitSys
> ==13717== at 0x40417E6: pthread_cond_wait@@GLIBC_2.3.2 (in
> /lib/libpthread-2.4.so)
> ==13717== by 0x401CB3A: vg_thread_wrapper (vg_preloaded.c:109)
> ==13717== by 0x403E34A: start_thread (in /lib/libpthread-2.4.so)
> ==13717== by 0x410A65D: clone (in /lib/libc-2.4.so)
>
> Thread 3: status = VgTs_Runnable
> ==13717== at 0x401C71D: pthread_mutex_lock (vg_preloaded.c:211)
> ==13717== by 0x80485F5: inc_count (pth_cvsimple.c:34)
> ==13717== by 0x401CB3A: vg_thread_wrapper (vg_preloaded.c:109)
> ==13717== by 0x403E34A: start_thread (in /lib/libpthread-2.4.so)
> ==13717== by 0x410A65D: clone (in /lib/libc-2.4.so)
|