#include <mono/metadata/tokentype.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/gc-internal.h>
+#include <mono/metadata/threads.h>
#include <mono/os/gc_wrapper.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/class-internals.h>
static gboolean mono_debugger_use_debugger = FALSE;
static MonoObject *last_exception = NULL;
-struct _MonoDebuggerMetadataInfo {
- int size;
- int mono_defaults_size;
- MonoDefaults *mono_defaults;
- int klass_field_offset;
- int klass_methods_offset;
- int klass_method_count_offset;
- int field_info_size;
-};
-
void (*mono_debugger_event_handler) (MonoDebuggerEvent event, guint64 data, guint64 arg) = NULL;
#define WRITE_UINT32(ptr,value) G_STMT_START { \
guint32 stop;
} MonoDebuggerExceptionInfo;
-#ifndef PLATFORM_WIN32
-
-MonoDebuggerIOLayer mono_debugger_io_layer = {
- InitializeCriticalSection, DeleteCriticalSection, TryEnterCriticalSection,
- EnterCriticalSection, LeaveCriticalSection, WaitForSingleObjectEx, SignalObjectAndWait,
- WaitForMultipleObjectsEx, CreateSemaphore, ReleaseSemaphore, CreateThread,
- GetCurrentThreadId
-};
-
-#endif
+static int initialized = 0;
void
mono_debugger_lock (void)
{
+ g_assert (initialized);
EnterCriticalSection (&debugger_lock_mutex);
debugger_lock_level++;
}
void
mono_debugger_unlock (void)
{
+ g_assert (initialized);
if (debugger_lock_level == 1) {
if (must_reload_symtabs && mono_debugger_use_debugger) {
mono_debugger_event (MONO_DEBUGGER_EVENT_RELOAD_SYMTABS, 0, 0);
InitializeCriticalSection (&debugger_lock_mutex);
mono_debugger_use_debugger = use_debugger;
+ initialized = 1;
}
void
g_assert (mono_debugger_use_debugger);
mono_debugger_lock ();
- mono_debugger_event (MONO_DEBUGGER_EVENT_ADD_MODULE, GPOINTER_TO_UINT (handle), 0);
+ mono_debugger_event (MONO_DEBUGGER_EVENT_ADD_MODULE, (guint64) (gsize) handle, 0);
mono_debugger_unlock ();
}
-void
-mono_debugger_add_builtin_types (MonoDebugHandle *symfile)
-{
- MonoDebuggerMetadataInfo *info;
- MonoClass klass;
-
- mono_symbol_table->corlib = symfile;
- mono_symbol_table->metadata_info = info = g_new0 (MonoDebuggerMetadataInfo, 1);
-
- info->size = sizeof (MonoDebuggerMetadataInfo);
- info->mono_defaults = &mono_defaults;
- info->mono_defaults_size = sizeof (MonoDefaults);
- info->klass_field_offset = (guint8*)&klass.fields - (guint8*)&klass;
- info->klass_methods_offset = (guint8*)&klass.methods - (guint8*)&klass;
- info->klass_method_count_offset = (guint8*)&klass.method.count - (guint8*)&klass;
- info->field_info_size = sizeof (MonoClassField);
-}
-
void
mono_debugger_start_add_type (MonoDebugHandle *symfile, MonoClass *klass)
{
must_reload_symtabs = TRUE;
}
-MonoReflectionMethod *
-ves_icall_MonoDebugger_GetMethod (MonoReflectionAssembly *assembly, guint32 token)
-{
- MonoMethod *method;
-
- method = mono_get_method (mono_assembly_get_image (assembly->assembly), token, NULL);
-
- return mono_method_get_object (mono_domain_get (), method, NULL);
-}
-
-int
-ves_icall_MonoDebugger_GetMethodToken (MonoReflectionAssembly *assembly, MonoReflectionMethod *method)
-{
- return method->method->token;
-}
-
-MonoReflectionType *
-ves_icall_MonoDebugger_GetType (MonoReflectionAssembly *assembly, guint32 token)
-{
- MonoClass *klass;
-
- klass = mono_class_get (mono_assembly_get_image (assembly->assembly), token);
- if (!klass) {
- g_warning (G_STRLOC ": %x", token);
- return NULL;
- }
-
- return mono_type_get_object (mono_domain_get (), &klass->byval_arg);
-}
-
-MonoReflectionType *
-ves_icall_MonoDebugger_GetLocalTypeFromSignature (MonoReflectionAssembly *assembly, MonoArray *signature)
-{
- MonoDomain *domain;
- MonoImage *image;
- MonoType *type;
- const char *ptr;
- int len = 0;
-
- MONO_CHECK_ARG_NULL (assembly);
- MONO_CHECK_ARG_NULL (signature);
-
- domain = mono_domain_get();
- image = mono_assembly_get_image (assembly->assembly);
-
- ptr = mono_array_addr (signature, char, 0);
- g_assert (*ptr++ == 0x07);
- len = mono_metadata_decode_value (ptr, &ptr);
- g_assert (len == 1);
-
- type = mono_metadata_parse_type (image, MONO_PARSE_LOCAL, 0, ptr, &ptr);
-
- return mono_type_get_object (domain, type);
-}
-
void
mono_debugger_event (MonoDebuggerEvent event, guint64 data, guint64 arg)
{
void
mono_debugger_cleanup (void)
{
- /* Do nothing yet. */
+ mono_debugger_event (MONO_DEBUGGER_EVENT_FINALIZE_MANAGED_CODE, 0, 0);
+ mono_debugger_event_handler = NULL;
}
/*
void
mono_debugger_breakpoint_callback (MonoMethod *method, guint32 index)
{
- mono_debugger_event (MONO_DEBUGGER_EVENT_BREAKPOINT, GPOINTER_TO_UINT (method), index);
+ mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT, (guint64) (gsize) method, index);
}
gboolean
mono_debugger_unhandled_exception (gpointer addr, gpointer stack, MonoObject *exc)
{
+ const gchar *name;
+
if (!mono_debugger_use_debugger)
return FALSE;
// Prevent the object from being finalized.
last_exception = exc;
+
+ name = mono_class_get_name (mono_object_get_class (exc));
+ if (!strcmp (name, "ThreadAbortException")) {
+ MonoThread *thread = mono_thread_current ();
+ mono_debugger_event (MONO_DEBUGGER_EVENT_THREAD_ABORT, 0, thread->tid);
+ mono_thread_exit ();
+ }
+
mono_debugger_event (MONO_DEBUGGER_EVENT_UNHANDLED_EXCEPTION,
- GPOINTER_TO_UINT (exc), GPOINTER_TO_UINT (addr));
+ (guint64) (gsize) exc, (guint64) (gsize) addr);
return TRUE;
}
info.exception_obj = exc;
info.stop = 0;
- mono_debugger_event (MONO_DEBUGGER_EVENT_EXCEPTION, GPOINTER_TO_UINT (&info),
- GPOINTER_TO_UINT (addr));
+ mono_debugger_event (MONO_DEBUGGER_EVENT_HANDLE_EXCEPTION, (guint64) (gsize) &info,
+ (guint64) (gsize) addr);
}
gboolean
info.exception_obj = exc;
info.stop = 0;
- mono_debugger_event (MONO_DEBUGGER_EVENT_THROW_EXCEPTION, GPOINTER_TO_UINT (&info),
- GPOINTER_TO_UINT (addr));
+ mono_debugger_event (MONO_DEBUGGER_EVENT_THROW_EXCEPTION, (guint64) (gsize) &info,
+ (guint64) (gsize) addr);
return info.stop != 0;
}