X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fmono-debug-debugger.c;h=981072583fd341d0601cadea1bf54d6edf05d81a;hb=cd0f05d6fd528c0f63327a908e2be2f4a9620933;hp=8d8aee051e247eebf41972b0f5709fd4a2031958;hpb=cfff213e97da8f3efae9db3eea6154509c8ed9ef;p=mono.git diff --git a/mono/metadata/mono-debug-debugger.c b/mono/metadata/mono-debug-debugger.c index 8d8aee051e2..981072583fd 100644 --- a/mono/metadata/mono-debug-debugger.c +++ b/mono/metadata/mono-debug-debugger.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -21,16 +22,6 @@ static gboolean must_reload_symtabs = FALSE; 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 { \ @@ -54,20 +45,12 @@ typedef struct { 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++; } @@ -75,6 +58,7 @@ mono_debugger_lock (void) 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); @@ -95,6 +79,7 @@ mono_debugger_initialize (gboolean use_debugger) InitializeCriticalSection (&debugger_lock_mutex); mono_debugger_use_debugger = use_debugger; + initialized = 1; } void @@ -103,89 +88,16 @@ mono_debugger_add_symbol_file (MonoDebugHandle *handle) 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) { @@ -196,7 +108,8 @@ 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; } /* @@ -285,19 +198,29 @@ mono_debugger_method_has_breakpoint (MonoMethod *method) 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; } @@ -316,8 +239,8 @@ mono_debugger_handle_exception (gpointer addr, gpointer stack, MonoObject *exc) 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 @@ -335,8 +258,8 @@ mono_debugger_throw_exception (gpointer addr, gpointer stack, MonoObject *exc) 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; }