2003-01-16 Dietmar Maurer <dietmar@ximian.com>
authorDietmar Maurer <dietmar@mono-cvs.ximian.com>
Thu, 16 Jan 2003 15:56:52 +0000 (15:56 -0000)
committerDietmar Maurer <dietmar@mono-cvs.ximian.com>
Thu, 16 Jan 2003 15:56:52 +0000 (15:56 -0000)
* exception.c (arch_handle_exception): exclude runtime invoke
wrapper from the stack trace

* jit.c (mono_cfg_new): allocate extra space to store esp (used by exceptions)
(mono_thread_start_cb): save an additional LMF at thread start

svn path=/trunk/mono/; revision=10577

mono/jit/ChangeLog
mono/jit/exception.c
mono/jit/jit.c
mono/metadata/object.c
mono/metadata/object.h
mono/metadata/threads.c

index 91b38a8aff02973bbe3aa190439957a040fe677a..bfe99d98865f04f2351d7fe68c34c3ad053f62e6 100644 (file)
@@ -1,3 +1,11 @@
+2003-01-16  Dietmar Maurer  <dietmar@ximian.com>
+
+       * exception.c (arch_handle_exception): exclude runtime invoke
+       wrapper from the stack trace
+
+       * jit.c (mono_cfg_new): allocate extra space to store esp (used by exceptions)
+       (mono_thread_start_cb): save an additional LMF at thread start
+
 2003-01-16  Martin Baulig  <martin@ximian.com>
 
        * jit.c (mono_runtime_install_handlers): Use SYS_sigaction() for
index 29b938bbc67df49d4cce72d1e3964dbb87574105..fb623774527a08ae10b145d0c730723fab4477b7 100644 (file)
@@ -237,7 +237,7 @@ x86_unwind_native_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, struct sig
 
        frame = MONO_CONTEXT_GET_BP (ctx);
 
-       max_stack = lmf ? lmf : jit_tls->end_of_stack;
+       max_stack = lmf && lmf->method ? lmf : jit_tls->end_of_stack;
 
        *new_ctx = *ctx;
 
@@ -652,6 +652,9 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoContex
                
                *new_ctx = *ctx;
 
+               if (!(*lmf)->method)
+                       return (gpointer)-1;
+
                if (trace)
                        *trace = g_strdup_printf ("in (unmanaged) %s", mono_method_full_name ((*lmf)->method, TRUE));
                
@@ -735,7 +738,10 @@ mono_jit_walk_stack (MonoStackWalk func, gpointer user_data) {
                
                ji = mono_arch_find_jit_info (domain, jit_tls, &ctx, &new_ctx, NULL, &lmf, &native_offset, &managed);
                g_assert (ji);
-               
+
+               if (ji == (gpointer)-1)
+                       return;
+
                il_offset = mono_debug_il_offset_from_address (ji->method, native_offset);
 
                if (func (ji->method, native_offset, il_offset, managed, user_data))
@@ -766,7 +772,7 @@ ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
                ji = mono_arch_find_jit_info (domain, jit_tls, &ctx, &new_ctx, NULL, &lmf, native_offset, NULL);
                ctx = new_ctx;
                
-               if (!ji || MONO_CONTEXT_GET_BP (&ctx) >= jit_tls->end_of_stack)
+               if (!ji || ji == (gpointer)-1 || MONO_CONTEXT_GET_BP (&ctx) >= jit_tls->end_of_stack)
                        return FALSE;
 
                if (ji->method->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE)
@@ -845,14 +851,14 @@ arch_handle_exception (MonoContext *ctx, gpointer obj, gboolean test_only)
                
                ji = mono_arch_find_jit_info (domain, jit_tls, ctx, &new_ctx, 
                                              test_only ? &trace : NULL, &lmf, NULL, NULL);
+
                if (!ji) {
                        g_warning ("Exception inside function without unwind info");
                        g_assert_not_reached ();
                }
 
-               if (ji->method != mono_start_method) {
-                       
-                       if (test_only) {
+               if (ji != (gpointer)-1) {
+                       if (test_only && ji->method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE) {
                                char *tmp, *strace;
 
                                trace_ips = g_list_append (trace_ips, MONO_CONTEXT_GET_IP (ctx));
@@ -861,7 +867,7 @@ arch_handle_exception (MonoContext *ctx, gpointer obj, gboolean test_only)
                                        strace = g_strdup ("");
                                else
                                        strace = mono_string_to_utf8 (((MonoException*)obj)->stack_trace);
-
+                       
                                tmp = g_strdup_printf ("%s%s\n", strace, trace);
                                g_free (strace);
 
@@ -917,7 +923,7 @@ arch_handle_exception (MonoContext *ctx, gpointer obj, gboolean test_only)
                        
                *ctx = new_ctx;
 
-               if (ji->method == mono_start_method || MONO_CONTEXT_GET_BP (ctx) >= jit_tls->end_of_stack) {
+               if ((ji == (gpointer)-1) || MONO_CONTEXT_GET_BP (ctx) >= jit_tls->end_of_stack) {
                        if (!test_only) {
                                jit_tls->lmf = lmf;
                                jit_tls->abort_func (obj);
index 189845a4ca58de01300c391bc18b630be3c52c12..5242a045906626835027812a7cb86cd9b0b40ead 100644 (file)
@@ -307,7 +307,7 @@ mono_jit_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObjec
        MonoObject *(*runtime_invoke) (MonoObject *this, void **params, MonoObject **exc);
 
        invoke = mono_marshal_get_runtime_invoke (method);
-       runtime_invoke = mono_compile_method (invoke);       
+       runtime_invoke = mono_compile_method (invoke);
        return runtime_invoke (obj, params, exc);
 }
 
@@ -3661,8 +3661,11 @@ mono_cfg_new (MonoMethod *method)
        /* reserve space to save LMF */
        cfg->locals_size = sizeof (MonoLMF);
        
+       cfg->locals_size += sizeof (gpointer);
        mono_exc_esp_offset = - cfg->locals_size;
 
+       cfg->locals_size += sizeof (gpointer);
+
        /* aligment check */
        g_assert (!(cfg->locals_size & 0x7));
 
@@ -3773,7 +3776,7 @@ mono_method_blittable (MonoMethod *method)
 #endif
 
 /**
- * mono_compile_method:
+ * mono_jit_compile_method:
  * @method: pointer to the method info
  *
  * JIT compilation of a single method. 
@@ -3894,10 +3897,11 @@ mono_jit_compile_method (MonoMethod *method)
 
                mono_jit_stats.native_code_size += ji->code_size;
 
+               ji->num_clauses = header->num_clauses;
+
                if (header->num_clauses) {
                        int i, start_block, end_block, filter_block;
 
-                       ji->num_clauses = header->num_clauses;
                        ji->clauses = mono_mempool_alloc0 (target_domain->mp, 
                                sizeof (MonoJitExceptionInfo) * header->num_clauses);
 
@@ -4093,6 +4097,7 @@ static void
 mono_thread_start_cb (gpointer stack_start)
 {
        MonoJitTlsData *jit_tls;
+       MonoLMF *lmf;
 
        jit_tls = g_new0 (MonoJitTlsData, 1);
 
@@ -4100,6 +4105,11 @@ mono_thread_start_cb (gpointer stack_start)
 
        jit_tls->abort_func = mono_thread_abort;
        jit_tls->end_of_stack = stack_start;
+
+       lmf = g_new0 (MonoLMF, 1);
+       lmf->ebp = -1;
+
+       jit_tls->lmf = lmf;
 }
 
 void (*mono_thread_attach_aborted_cb ) (MonoObject *obj) = NULL;
@@ -4117,6 +4127,7 @@ static void
 mono_thread_attach_cb (gpointer stack_start)
 {
        MonoJitTlsData *jit_tls;
+       MonoLMF *lmf;
 
        jit_tls = g_new0 (MonoJitTlsData, 1);
 
@@ -4124,6 +4135,11 @@ mono_thread_attach_cb (gpointer stack_start)
 
        jit_tls->abort_func = mono_thread_abort_dummy;
        jit_tls->end_of_stack = stack_start;
+
+       lmf = g_new0 (MonoLMF, 1);
+       lmf->ebp = -1;
+
+       jit_tls->lmf = lmf;
 }
 
 static CRITICAL_SECTION ms;
index 8ff463164bddd9f1bc180dd2ea85d2d08618534a..a0cdf8ad58b8a26677d04153cb38b501adcd6f9b 100644 (file)
@@ -580,8 +580,6 @@ mono_runtime_get_main_args (void)
        return main_args;
 }
 
-MonoMethod *mono_start_method = NULL;
-
 /*
  * Execute a standard Main() method (argc/argv contains the
  * executable name). This method also sets the command line argument value
@@ -614,8 +612,6 @@ mono_runtime_run_main (MonoMethod *method, int argc, char* argv[],
        
        mono_assembly_set_main (method->klass->image->assembly);
 
-       mono_start_method = mono_marshal_get_runtime_invoke (method);
-       
        return mono_runtime_exec_main (method, args, exc);
 }
 
@@ -663,6 +659,7 @@ mono_runtime_exec_main (MonoMethod *method, MonoArray *args, MonoObject **exc)
 {
        MonoDomain *domain;
        gpointer pa [1];
+       MonoObject *res;
        int rval;
 
        g_assert (args);
index 0a49172bbcdfa5fbb8cc1eed64d035c4a6ffab3b..f35af0360f2167ad5d9a7a449f7330a1cd745b9c 100644 (file)
@@ -212,8 +212,6 @@ typedef gpointer    (*MonoCompileFunc)       (MonoMethod *method);
 #define mono_string_chars(s) ((gunichar2*)(s)->chars)
 #define mono_string_length(s) ((s)->length)
 
-extern MonoMethod *mono_start_method;
-
 void *
 mono_object_allocate        (size_t size);
 
index d92703435916735feb8c46fcafae0993f2600283..cb1cdb76a3c0c57283760d32c2f234dcef96406e 100644 (file)
@@ -242,6 +242,14 @@ mono_thread_attach (MonoDomain *domain)
        HANDLE thread_handle;
        guint32 tid;
 
+       if ((thread = mono_thread_current ())) {
+               g_warning ("mono_thread_attach called for an already attached thread");
+               if (mono_thread_attach_cb) {
+                       mono_thread_attach_cb (&tid);
+               }
+               return thread;
+       }
+
        thread = (MonoThread *)mono_object_new (domain,
                                                mono_defaults.thread_class);