|
From: <sv...@va...> - 2009-03-16 06:45:37
|
Author: njn
Date: 2009-03-16 06:45:22 +0000 (Mon, 16 Mar 2009)
New Revision: 9433
Log:
Take steps towards Helgrind working on Darwin.
- Doesn't just abort at startup now.
- Got the pthread wrappers redirecting correctly.
- Made some syswrap-darwin.c code more similar to the corresponding
syswrap-linux.c code.
- Added pre_thread_ll_exit events to Darwin, not sure if they're in the
right spot though.
The net result is that Helgrind now runs (previously it always asserted on
thread creation), but there are lots of what I assume are false positives.
Modified:
branches/DARWIN/coregrind/m_syswrap/syswrap-darwin.c
branches/DARWIN/coregrind/m_syswrap/syswrap-x86-darwin.c
branches/DARWIN/helgrind/hg_intercepts.c
branches/DARWIN/helgrind/hg_main.c
Modified: branches/DARWIN/coregrind/m_syswrap/syswrap-darwin.c
===================================================================
--- branches/DARWIN/coregrind/m_syswrap/syswrap-darwin.c 2009-03-16 04:34:41 UTC (rev 9432)
+++ branches/DARWIN/coregrind/m_syswrap/syswrap-darwin.c 2009-03-16 06:45:22 UTC (rev 9433)
@@ -84,14 +84,14 @@
// Run a thread from beginning to end and return the thread's
// scheduler-return-code.
-static VgSchedReturnCode ML_(thread_wrapper)(Word /*ThreadId*/ tidW)
+static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW)
{
VgSchedReturnCode ret;
ThreadId tid = (ThreadId)tidW;
ThreadState* tst = VG_(get_ThreadState)(tid);
- VG_(debugLog)(1, "core_os",
- "ML_(thread_wrapper)(tid=%lld): entry\n",
+ VG_(debugLog)(1, "syswrap-darwin",
+ "thread_wrapper(tid=%lld): entry\n",
(ULong)tidW);
vg_assert(tst->status == VgTs_Init);
@@ -118,8 +118,8 @@
vg_assert(tst->status == VgTs_Runnable);
vg_assert(VG_(is_running_thread)(tid));
- VG_(debugLog)(1, "core_os",
- "ML_(thread_wrapper)(tid=%lld): done\n",
+ VG_(debugLog)(1, "syswrap-darwin",
+ "thread_wrapper(tid=%lld): done\n",
(ULong)tidW);
/* Return to caller, still holding the lock. */
@@ -204,21 +204,22 @@
ThreadId tid = (ThreadId)tidW;
VG_(debugLog)(1, "syswrap-darwin",
- "run_a_thread_NORETURN(tid=%lld): "
- "ML_(thread_wrapper) called\n",
- (ULong)tidW);
+ "run_a_thread_NORETURN(tid=%lld): pre-thread_wrapper\n",
+ (ULong)tidW);
/* Run the thread all the way through. */
- src = ML_(thread_wrapper)(tid);
+ src = thread_wrapper(tid);
VG_(debugLog)(1, "syswrap-darwin",
- "run_a_thread_NORETURN(tid=%lld): "
- "ML_(thread_wrapper) done\n",
- (ULong)tidW);
+ "run_a_thread_NORETURN(tid=%lld): post-thread_wrapper\n",
+ (ULong)tidW);
c = VG_(count_living_threads)();
vg_assert(c >= 1); /* stay sane */
+ // Tell the tool this thread is exiting
+ VG_TRACK( pre_thread_ll_exit, tid );
+
if (c == 1) {
VG_(debugLog)(1, "syswrap-darwin",
@@ -5352,15 +5353,15 @@
tst->os_state.func_arg = (Addr)ARG2;
ARG2 = (Word)tst;
- // Create a semaphore that pthread_hijack will signal once it starts
- // POST(sys_bsdthread_create) needs to wait for the new memory map to appear
+ // Create a semaphore that pthread_hijack will signal once it starts.
+ // POST(sys_bsdthread_create) needs to wait for the new memory map to appear.
semaphore_create(mach_task_self(), &tst->os_state.bsdthread_create_sema,
SYNC_POLICY_FIFO, 0);
}
POST(sys_bsdthread_create)
{
- // Wait for pthreead_hijack to finish on new thread.
+ // Wait for pthread_hijack to finish on new thread.
// Otherwise V thinks the new pthread struct is still
// unmapped when we return to libc, causing false errors
@@ -5370,6 +5371,12 @@
// fixme semaphore destroy needed when thread creation fails
// fixme probably other cleanup too
+
+ // DDD: I'm not at all sure this is the right spot for this. It probably
+ // should be in pthread_hijack instead, just before the call to
+ // start_thread_NORETURN(), call_on_new_stack_0_1(), but we don't have the
+ // parent tid value there...
+ VG_TRACK ( pre_thread_ll_create, tid, tst->tid );
}
@@ -6383,8 +6390,8 @@
PRE(swtch_pri)
{
- PRINT("swtch ( %ld )", ARG1);
- PRE_REG_READ1(long, "swtch", int,"pri");
+ PRINT("swtch_pri ( %ld )", ARG1);
+ PRE_REG_READ1(long, "swtch_pri", int,"pri");
*flags |= SfMayBlock;
}
Modified: branches/DARWIN/coregrind/m_syswrap/syswrap-x86-darwin.c
===================================================================
--- branches/DARWIN/coregrind/m_syswrap/syswrap-x86-darwin.c 2009-03-16 04:34:41 UTC (rev 9432)
+++ branches/DARWIN/coregrind/m_syswrap/syswrap-x86-darwin.c 2009-03-16 06:45:22 UTC (rev 9433)
@@ -284,6 +284,7 @@
// Set thread's registers
// Do this FIRST because some code below tries to collect a backtrace,
// which requires valid register data.
+ // DDD: need to do post_reg_write events here?
LibVEX_GuestX86_initialise(vex);
vex->guest_EIP = pthread_starter;
vex->guest_EAX = self;
@@ -327,6 +328,10 @@
// initializing registers and mapping memory.
semaphore_signal(tst->os_state.bsdthread_create_sema);
+ // DDD: should this be here rather than in POST(sys_bsdthread_create)?
+ // But we don't have ptid here...
+ //VG_TRACK ( pre_thread_ll_create, ptid, tst->tid );
+
// Go!
call_on_new_stack_0_1(tst->os_state.valgrind_stack_init_SP, 0,
start_thread_NORETURN, (Word)tst);
Modified: branches/DARWIN/helgrind/hg_intercepts.c
===================================================================
--- branches/DARWIN/helgrind/hg_intercepts.c 2009-03-16 04:34:41 UTC (rev 9432)
+++ branches/DARWIN/helgrind/hg_intercepts.c 2009-03-16 06:45:22 UTC (rev 9433)
@@ -58,9 +58,16 @@
/*--- ---*/
/*----------------------------------------------------------------*/
-#define PTH_FUNC(ret_ty, f, args...) \
+#if defined(VGO_darwin)
+// Darwin pthread funcs appear to be in the main C library.
+# define PTH_FUNC(ret_ty, f, args...) \
+ ret_ty I_WRAP_SONAME_FNNAME_ZZ(libSystemZdZaZddylib,f)(args); \
+ ret_ty I_WRAP_SONAME_FNNAME_ZZ(libSystemZdZaZddylib,f)(args)
+#else
+# define PTH_FUNC(ret_ty, f, args...) \
ret_ty I_WRAP_SONAME_FNNAME_ZZ(libpthreadZdsoZd0,f)(args); \
ret_ty I_WRAP_SONAME_FNNAME_ZZ(libpthreadZdsoZd0,f)(args)
+#endif
// Do a client request. This is a macro rather than a function
// so as to avoid having an extra function in the stack trace.
@@ -195,7 +202,10 @@
}
// pthread_create
-PTH_FUNC(int, pthreadZucreateZAZa, // pthread_create@*
+// DDD: need to remove "@*" suffixes from all pthread functions that have
+// them for Darwin?
+//PTH_FUNC(int, pthreadZucreateZAZa, // pthread_create@*
+PTH_FUNC(int, pthreadZucreate, // pthread_create
pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg)
{
Modified: branches/DARWIN/helgrind/hg_main.c
===================================================================
--- branches/DARWIN/helgrind/hg_main.c 2009-03-16 04:34:41 UTC (rev 9432)
+++ branches/DARWIN/helgrind/hg_main.c 2009-03-16 06:45:22 UTC (rev 9433)
@@ -4173,12 +4173,6 @@
{
Thr* hbthr_root;
-#if defined(VGO_darwin)
- // This makes the (all-failing) regtests run much faster.
- VG_(printf)("Helgrind doesn't work on Darwin yet, sorry.\n");
- VG_(exit)(1);
-#endif
-
VG_(details_name) ("Helgrind");
VG_(details_version) (NULL);
VG_(details_description) ("a thread error detector");
|