* debugger-agent.c: Implementation for Windows platform.
* mini-x86.c: Add support for Windows. Use mono-* synchronization
primitives. Use SEH to implement breakpoints and single stepping.
* mini-x86.h: Enable soft debugger on Windows.
Code contributed under MIT/X11 license.
svn path=/trunk/mono/; revision=146168
+2009-11-13 Jonathan Chambers <joncham@gmail.com>
+
+ * mono-mutex.h: Implementation for Windows platform.
+
+ Code contributed under MIT/X11 license.
+
2009-11-13 Zoltan Varga <vargaz@gmail.com>
* processes.c: Include mono-path.h.
int mono_cond_timedwait (pthread_cond_t *cond, mono_mutex_t *mutex, const struct timespec *timeout);
#define mono_cond_signal(cond) pthread_cond_signal (cond)
#define mono_cond_broadcast(cond) pthread_cond_broadcast (cond)
+#define mono_cond_destroy(cond)
#else /* system is equipped with a fully-functional pthread mutex library */
#define mono_cond_timedwait(cond,mutex,timeout) pthread_cond_timedwait (cond, mutex, timeout)
#define mono_cond_signal(cond) pthread_cond_signal (cond)
#define mono_cond_broadcast(cond) pthread_cond_broadcast (cond)
+#define mono_cond_destroy(cond)
#endif /* USE_MONO_MUTEX */
#else
-typedef HANDLE mono_mutex_t;
+typedef CRITICAL_SECTION mono_mutex_t;
typedef HANDLE mono_cond_t;
-#define mono_mutex_lock(mutex) do { WaitForSingleObject ((mutex), INFINITE);} while (0)
-#define mono_mutex_unlock(mutex) ReleaseMutex ((mutex))
+#define mono_mutex_init(mutex,attr) InitializeCriticalSection((mutex))
+#define mono_mutex_lock(mutex) EnterCriticalSection((mutex))
+#define mono_mutex_unlock(mutex) LeaveCriticalSection((mutex))
+#define mono_mutex_destroy(mutex) DeleteCriticalSection((mutex))
-#define mono_cond_init(cond,attr) pthread_cond_init (cond,attr)
-#define mono_cond_wait(cond,mutex) WaitForSingleObject (cond, INFINITE)
-#define mono_cond_timedwait(cond,mutex,timeout) pthread_cond_timedwait (cond, mutex, timeout)
-#define mono_cond_signal(cond) SetEvent (cond)
-#define mono_cond_broadcast(cond) SetEvent (cond)
+#define mono_cond_init(cond,attr) do{*(cond) = CreateEvent(NULL,FALSE,FALSE,NULL); } while (0)
+#define mono_cond_wait(cond,mutex) WaitForSingleObject(*(cond),INFINITE)
+#define mono_cond_timedwait(cond,mutex,timeout) WaitForSingleObject(*(cond),timeout)
+#define mono_cond_signal(cond) SetEvent(*(cond))
+#define mono_cond_broadcast(cond) (!SetEvent(*(cond)))
+#define mono_cond_destroy(cond) CloseHandle(*(cond))
#define MONO_MUTEX_INITIALIZER NULL
#define MONO_COND_INITIALIZER NULL
+2009-11-13 Jonathan Chambers <joncham@gmail.com>
+
+ * debugger-agent.c: Implementation for Windows platform.
+
+ * mini-x86.c: Add support for Windows. Use mono-* synchronization
+ primitives. Use SEH to implement breakpoints and single stepping.
+
+ * mini-x86.h: Enable soft debugger on Windows.
+
+ Code contributed under MIT/X11 license.
+
2009-11-13 Zoltan Varga <vargaz@gmail.com>
* mini-amd64.c (emit_call_body): Disable usage of near calls when running
static gboolean debugger_thread_exited;
/* Cond variable used to wait for debugger_thread_exited becoming true */
-static mono_cond_t debugger_thread_exited_cond = MONO_COND_INITIALIZER;
+static mono_cond_t debugger_thread_exited_cond;
/* Mutex for the cond var above */
-static mono_mutex_t debugger_thread_exited_mutex = MONO_MUTEX_INITIALIZER;
+static mono_mutex_t debugger_thread_exited_mutex;
static DebuggerProfiler debugger_profiler;
event_requests = g_ptr_array_new ();
+ mono_mutex_init (&debugger_thread_exited_mutex, NULL);
+ mono_cond_init (&debugger_thread_exited_cond, NULL);
+
mono_profiler_install ((MonoProfiler*)&debugger_profiler, runtime_shutdown);
mono_profiler_set_events (MONO_PROFILE_APPDOMAIN_EVENTS | MONO_PROFILE_THREADS | MONO_PROFILE_ASSEMBLY_EVENTS | MONO_PROFILE_JIT_COMPILATION | MONO_PROFILE_METHOD_EVENTS);
mono_profiler_install_runtime_initialized (runtime_initialized);
breakpoints_cleanup ();
objrefs_cleanup ();
ids_cleanup ();
+
+
+ mono_mutex_destroy (&debugger_thread_exited_mutex);
+ mono_cond_destroy (&debugger_thread_exited_cond);
}
/*
if (host) {
sprintf (port_string, "%d", port);
+ mono_network_init ();
+
/* Obtain address(es) matching host/port */
memset (&hints, 0, sizeof (struct addrinfo));
/* Write handshake message */
sprintf (handshake_msg, "DWP-Handshake");
- res = write (conn_fd, handshake_msg, strlen (handshake_msg));
+ res = send (conn_fd, handshake_msg, strlen (handshake_msg), 0);
g_assert (res != -1);
/* Read answer */
- res = read (conn_fd, buf, strlen (handshake_msg));
+ res = recv (conn_fd, buf, strlen (handshake_msg), 0);
if ((res != strlen (handshake_msg)) || (memcmp (buf, handshake_msg, strlen (handshake_msg) != 0))) {
fprintf (stderr, "debugger-agent: DWP handshake failed.\n");
exit (1);
{
int res;
- res = write (conn_fd, data, len);
+ res = send (conn_fd, data, len, 0);
if (res != len)
return FALSE;
else
*/
static gint32 threads_suspend_count;
-static mono_mutex_t suspend_mutex = MONO_MUTEX_INITIALIZER;
+static mono_mutex_t suspend_mutex;
/* Cond variable used to wait for suspend_count becoming 0 */
-static mono_cond_t suspend_cond = MONO_COND_INITIALIZER;
+static mono_cond_t suspend_cond;
/* Semaphore used to wait for a thread becoming suspended */
static MonoSemType suspend_sem;
static void
suspend_init (void)
{
+ mono_mutex_init (&suspend_mutex, NULL);
+ mono_cond_init (&suspend_cond, NULL);
MONO_SEM_INIT (&suspend_sem, 0);
}
}
}
+#ifdef PLATFORM_WIN32
+static void CALLBACK notify_thread_apc (ULONG_PTR param)
+{
+ //DebugBreak ();
+ mono_debugger_agent_thread_interrupt (NULL);
+}
+#endif /* PLATFORM_WIN32 */
+
/*
* notify_thread:
*
*/
InterlockedIncrement (&tls->interrupt_count);
#ifdef PLATFORM_WIN32
- /*FIXME: Abort thread */
+ // g_assert_not_reached ();
+ QueueUserAPC (notify_thread_apc, thread->handle, NULL);
#else
pthread_kill ((pthread_t) tid, mono_thread_get_abort_signal ());
#endif
g_assert (err == 0);
}
- err = mono_mutex_unlock (&suspend_mutex);
- g_assert (err == 0);
+ mono_mutex_unlock (&suspend_mutex);
+ //g_assert (err == 0);
mono_loader_unlock ();
}
DEBUG(1, fprintf (log_file, "[%p] Suspended.\n", (gpointer)GetCurrentThreadId ()));
while (suspend_count > 0) {
+#ifdef PLATFORM_WIN32
+ if (WAIT_TIMEOUT == WaitForSingleObject(suspend_cond, 0))
+ {
+ mono_mutex_unlock (&suspend_mutex);
+ Sleep(0);
+ mono_mutex_lock (&suspend_mutex);
+ }
+ else
+ {
+ }
+#else
err = mono_cond_wait (&suspend_cond, &suspend_mutex);
g_assert (err == 0);
+#endif
}
tls->suspended = FALSE;
mono_set_is_debugger_attached (TRUE);
while (TRUE) {
- res = read (conn_fd, header, HEADER_LENGTH);
+ res = recv (conn_fd, header, HEADER_LENGTH, 0);
/* This will break if the socket is closed during shutdown too */
if (res != HEADER_LENGTH)
DEBUG (1, fprintf (log_file, "[dbg] Received command %s(%d), id=%d.\n", command_set_to_string (command_set), command, id));
data = g_malloc (len - HEADER_LENGTH);
- res = read (conn_fd, data, len - HEADER_LENGTH);
- if (res != len - HEADER_LENGTH)
- break;
+ if (len - HEADER_LENGTH > 0)
+ {
+ res = recv (conn_fd, data, len - HEADER_LENGTH, 0);
+ if (res != len - HEADER_LENGTH)
+ break;
+ }
p = data;
end = data + (len - HEADER_LENGTH);
mono_arch_is_single_step_event (void *info, void *sigctx)
{
#ifdef PLATFORM_WIN32
- EXCEPTION_RECORD* einfo = (EXCEPTION_RECORD*)info;
- return FALSE;
+ EXCEPTION_RECORD* einfo = (EXCEPTION_RECORD*)info; /* Sometimes the address is off by 4 */
+ if ((einfo->ExceptionInformation[1] >= ss_trigger_page && (guint8*)einfo->ExceptionInformation[1] <= (guint8*)ss_trigger_page + 128))
+ return TRUE;
+ else
+ return FALSE;
#else
siginfo_t* sinfo = (siginfo_t*) info;
/* Sometimes the address is off by 4 */
mono_arch_is_breakpoint_event (void *info, void *sigctx)
{
#ifdef PLATFORM_WIN32
- EXCEPTION_RECORD* einfo = (EXCEPTION_RECORD*)info;
- return FALSE;
+ EXCEPTION_RECORD* einfo = (EXCEPTION_RECORD*)info; /* Sometimes the address is off by 4 */
+ if ((einfo->ExceptionInformation[1] >= bp_trigger_page && (guint8*)einfo->ExceptionInformation[1] <= (guint8*)bp_trigger_page + 128))
+ return TRUE;
+ else
+ return FALSE;
#else
siginfo_t* sinfo = (siginfo_t*)info;
/* Sometimes the address is off by 4 */
#define MONO_ARCH_GSHARED_SUPPORTED 1
#define MONO_ARCH_HAVE_LLVM_IMT_TRAMPOLINE 1
-#ifndef PLATFORM_WIN32
#define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
-#else
-#define DISABLE_DEBUGGER_AGENT 1
-#endif
#define MONO_ARCH_HAVE_FIND_JIT_INFO_EXT 1
/* Used for optimization, not complete */
+2009-11-13 Jonathan Chambers <joncham@gmail.com>
+
+ * mono-semaphore.h: Implementation for Windows platform.
+
+ Code contributed under MIT/X11 license.
+
2009-11-12 Geoff Norton <gnorton@novell.com>
* mono-path.c: When resolving symlinks in a path, we need to
#elif defined(PLATFORM_WIN32)
# define MONO_HAS_SEMAPHORES
typedef HANDLE MonoSemType;
-# define MONO_SEM_INIT(addr,value) do {*(addr) = CreateSemaphore( NULL, (value), 10, NULL);} while(0)
-# define MONO_SEM_WAIT(sem) WaitForSingleObject ((sem), INFINITE)
-# define MONO_SEM_POST(sem) ReleaseSemaphore ((sem), 1, NULL)
-# define MONO_SEM_DESTROY(sem) CloseHandle ((sem))
+# define MONO_SEM_INIT(addr,value) do {*(addr) = CreateSemaphore ( NULL,(value),10,NULL);} while(0)
+# define MONO_SEM_WAIT(sem) WaitForSingleObjectEx (*(sem),INFINITE, TRUE)
+# define MONO_SEM_POST(sem) (!(ReleaseSemaphore (*(sem),1,NULL)))
+# define MONO_SEM_DESTROY(sem) CloseHandle (*(sem))
#endif
#endif /* _MONO_SEMAPHORE_H_ */