Merge pull request #2819 from BrzVlad/fix-major-log
[mono.git] / mono / metadata / attach.c
index 4f5024a72f0bb61a91d78f648b0265e9500b47de..6b65259b962b437f20e121671fb189b8486219c3 100644 (file)
@@ -5,6 +5,7 @@
  *   Zoltan Varga (vargaz@gmail.com)
  *
  * Copyright 2007-2009 Novell, Inc (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -265,6 +266,7 @@ mono_attach_cleanup (void)
 static int
 mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject **exc)
 {
+       MonoError error;
        MonoAssembly *agent_assembly;
        MonoImage *image;
        MonoMethod *method;
@@ -292,9 +294,10 @@ mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject
                return 1;
        }
 
-       method = mono_get_method (image, entry, NULL);
+       method = mono_get_method_checked (image, entry, NULL, NULL, &error);
        if (method == NULL){
-               g_print ("The entry point method of assembly '%s' could not be loaded\n", agent);
+               g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, mono_error_get_message (&error));
+               mono_error_cleanup (&error);
                g_free (agent);
                return 1;
        }
@@ -309,7 +312,8 @@ mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject
        g_free (agent);
 
        pa [0] = main_args;
-       mono_runtime_invoke (method, NULL, pa, exc);
+       mono_runtime_try_invoke (method, NULL, pa, exc, &error);
+       mono_error_raise_exception (&error); /* FIXME don't raise here */
 
        return 0;
 }
@@ -471,11 +475,14 @@ transport_start_receive (void)
 static guint32 WINAPI
 receiver_thread (void *arg)
 {
+       MonoError error;
        int res, content_len;
        guint8 buffer [256];
        guint8 *p, *p_end;
        MonoObject *exc;
 
+       mono_thread_info_set_name (mono_native_thread_id_get (), "Attach receiver");
+
        printf ("attach: Listening on '%s'...\n", server_uri);
 
        while (TRUE) {
@@ -486,11 +493,13 @@ receiver_thread (void *arg)
 
                printf ("attach: Connected.\n");
 
-               mono_thread_attach (mono_get_root_domain ());
+               MonoThread *thread = mono_thread_attach (mono_get_root_domain ());
+               mono_thread_set_name_internal (thread->internal_thread, mono_string_new (mono_get_root_domain (), "Attach receiver"), TRUE, &error);
+               mono_error_assert_ok (&error);
                /* Ask the runtime to not abort this thread */
                //mono_thread_current ()->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
                /* Ask the runtime to not wait for this thread */
-               mono_thread_internal_current ()->state |= ThreadState_Background;
+               thread->internal_thread->state |= ThreadState_Background;
 
                while (TRUE) {
                        char *cmd, *agent_name, *agent_args;