MonoDroid needs a way to inform the debugger of possibly unhandled exceptions.
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 4 Sep 2012 20:58:50 +0000 (17:58 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 15 Nov 2012 17:47:59 +0000 (12:47 -0500)
* Debugger.cs: Add Mono_UnhandledException method that
triggers sdb to send an unhandled exception message to the agent.

This is needed since MonoDroid can't know at the Java->C# boundary
if a given C# exception is unmanaged or not.

mcs/class/corlib/System.Diagnostics/Debugger.cs
mono/mini/debugger-agent.c
mono/mini/debugger-agent.h
mono/mini/mini.c

index 02113358021b795cd8d3eb873ff73c66549469fa..d7b3544dfe5a9ee1ba57fbb171344fedc9492eaa 100644 (file)
@@ -110,5 +110,15 @@ namespace System.Diagnostics
                public Debugger()
                {
                }
+
+#if MONODROID
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               private extern static void Mono_UnhandledException_internal (Exception ex);
+
+               internal static void Mono_UnhandledException (Exception ex)
+               {
+                       Mono_UnhandledException_internal (ex);
+               }
+#endif
        }
 }
index 5e35d0ca0a21c235f42e4268b4da84e3762a7fc0..87f0096515fb35b00f5c3437e815a3d451863d28 100644 (file)
@@ -5119,6 +5119,28 @@ mono_debugger_agent_debug_log_is_enabled (void)
        return agent_config.enabled;
 }
 
+#ifdef PLATFORM_ANDROID
+void
+mono_debugger_agent_unhandled_exception (MonoException *exc)
+{
+       int suspend_policy;
+       GSList *events;
+       EventInfo ei;
+
+       if (!inited)
+               return;
+
+       memset (&ei, 0, sizeof (EventInfo));
+       ei.exc = (MonoObject*)exc;
+
+       mono_loader_lock ();
+       events = create_event_list (EVENT_KIND_EXCEPTION, NULL, NULL, &ei, &suspend_policy);
+       mono_loader_unlock ();
+
+       process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy);
+}
+#endif
+
 void
 mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx, 
                                      MonoContext *catch_ctx)
index 54c5dbb0188c46c5846136aa51da0cd376631058..7a7b9473a030166fbc2bfad1dfef82aded818b60 100644 (file)
@@ -30,6 +30,11 @@ mono_debugger_agent_free_domain_info (MonoDomain *domain) MONO_INTERNAL;
 
 gboolean mono_debugger_agent_thread_interrupt (void *sigctx, MonoJitInfo *ji) MONO_INTERNAL;
 
+#ifdef PLATFORM_ANDROID
+void
+mono_debugger_agent_unhandled_exception (MonoException *exc);
+#endif
+
 void
 mono_debugger_agent_handle_exception (MonoException *ext, MonoContext *throw_ctx, MonoContext *catch_ctx) MONO_INTERNAL;
 
index e9e15135a8a7374f77f02661b1be49dd4a450995..583babf3d81e1d70c1059aa10383463ce5b5cadf 100644 (file)
@@ -6568,6 +6568,11 @@ mini_init (const char *filename, const char *runtime_version)
        mono_add_internal_call ("Mono.Runtime::mono_runtime_install_handlers", 
                                mono_runtime_install_handlers);
 
+#ifdef PLATFORM_ANDROID
+       mono_add_internal_call ("System.Diagnostics.Debugger::Mono_UnhandledException_internal",
+                               mono_debugger_agent_unhandled_exception);
+#endif
+
        mono_create_helper_signatures ();
 
        register_jit_stats ();