2005-02-05 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / debug-mini.c
index 7fc906898c670948c7a35d051d0de6e695efb786..e3ebbfd41bc0615bfc3d83643174147fdc7e8e98 100644 (file)
@@ -26,8 +26,8 @@ record_line_number (MonoDebugMethodJitInfo *jit, guint32 address, guint32 offset
 {
        MonoDebugLineNumberEntry lne;
 
-       lne.address = address;
-       lne.offset = offset;
+       lne.native_offset = address;
+       lne.il_offset = offset;
 
        g_array_append_val (jit->line_numbers, lne);
 }
@@ -51,8 +51,10 @@ mono_debug_init_method (MonoCompile *cfg, MonoBasicBlock *start_block, guint32 b
        if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
            (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
            (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
-           (method->flags & METHOD_ATTRIBUTE_ABSTRACT) ||
-           (method->wrapper_type != MONO_WRAPPER_NONE))
+           (method->flags & METHOD_ATTRIBUTE_ABSTRACT))
+               return;
+       if ((method->wrapper_type != MONO_WRAPPER_NONE) &&
+           (method->wrapper_type != MONO_WRAPPER_MANAGED_TO_NATIVE))
                return;
 
        info = g_new0 (MiniDebugMethodInfo, 1);
@@ -74,9 +76,9 @@ mono_debug_open_method (MonoCompile *cfg)
 
        mono_class_init (cfg->method->klass);
 
-       g_assert (((MonoMethodNormal*)cfg->method)->header);
-       header = ((MonoMethodNormal*)cfg->method)->header;
-
+       header = mono_method_get_header (cfg->method);
+       g_assert (header);
+       
        info->jit = jit = g_new0 (MonoDebugMethodJitInfo, 1);
        jit->line_numbers = g_array_new (FALSE, TRUE, sizeof (MonoDebugLineNumberEntry));
        jit->num_locals = header->num_locals;
@@ -115,7 +117,7 @@ mono_debug_add_vg_method (MonoMethod *method, MonoDebugMethodJitInfo *jit)
        if (!RUNNING_ON_VALGRIND)
                return;
 
-       header = ((MonoMethodNormal*)method)->header;
+       header = mono_method_get_header (method);
 
        full_name = mono_method_full_name (method, TRUE);
 
@@ -192,15 +194,20 @@ mono_debug_close_method (MonoCompile *cfg)
        MiniDebugMethodInfo *info;
        MonoDebugMethodJitInfo *jit;
        MonoMethodHeader *header;
+       MonoMethodSignature *sig;
        MonoMethod *method;
        int i;
 
        info = (MiniDebugMethodInfo *) cfg->debug_info;
-       if (!info || !info->jit)
+       if (!info || !info->jit) {
+               if (info)
+                       g_free (info);
                return;
+       }
 
        method = cfg->method;
-       header = ((MonoMethodNormal*)method)->header;
+       header = mono_method_get_header (method);
+       sig = mono_method_signature (method);
 
        jit = info->jit;
        jit->code_start = cfg->native_code;
@@ -209,19 +216,19 @@ mono_debug_close_method (MonoCompile *cfg)
 
        record_line_number (jit, jit->epilogue_begin, header->code_size);
 
-       jit->num_params = method->signature->param_count;
+       jit->num_params = sig->param_count;
        jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
 
        for (i = 0; i < jit->num_locals; i++)
                write_variable (cfg->varinfo [cfg->locals_start + i], &jit->locals [i]);
 
-       if (method->signature->hasthis) {
+       if (sig->hasthis) {
                jit->this_var = g_new0 (MonoDebugVarInfo, 1);
                write_variable (cfg->varinfo [0], jit->this_var);
        }
 
        for (i = 0; i < jit->num_params; i++)
-               write_variable (cfg->varinfo [i + method->signature->hasthis], &jit->params [i]);
+               write_variable (cfg->varinfo [i + sig->hasthis], &jit->params [i]);
 
        mono_debug_add_method (method, jit, cfg->domain);
 
@@ -229,6 +236,8 @@ mono_debug_close_method (MonoCompile *cfg)
 
        if (info->breakpoint_id)
                mono_debugger_breakpoint_callback (method, info->breakpoint_id);
+
+       g_free (info);
 }
 
 void
@@ -242,8 +251,8 @@ mono_debug_record_line_number (MonoCompile *cfg, MonoInst *ins, guint32 address)
        if (!info || !info->jit || !ins->cil_code)
                return;
 
-       g_assert (((MonoMethodNormal*)cfg->method)->header);
-       header = ((MonoMethodNormal*)cfg->method)->header;
+       header = mono_method_get_header (cfg->method);
+       g_assert (header);
 
        if ((ins->cil_code < header->code) ||
            (ins->cil_code > header->code + header->code_size))
@@ -271,7 +280,7 @@ encode_value (gint32 value, char *buf, char **endbuf)
         */
        if ((value >= 0) && (value <= 127))
                *p++ = value;
-       else if ((value >= 0) && (value <= 16384)) {
+       else if ((value >= 0) && (value <= 16383)) {
                p [0] = 0x80 | (value >> 8);
                p [1] = value & 0xff;
                p += 2;
@@ -371,7 +380,7 @@ mono_debug_serialize_debug_info (MonoCompile *cfg,
        for (i = 0; i < jit->num_params; ++i)
                serialize_variable (&jit->params [i], p, &p);
 
-       if (cfg->method->signature->hasthis)
+       if (mono_method_signature (cfg->method)->hasthis)
                serialize_variable (jit->this_var, p, &p);
 
        for (i = 0; i < jit->num_locals; i++)
@@ -386,10 +395,10 @@ mono_debug_serialize_debug_info (MonoCompile *cfg,
                MonoDebugLineNumberEntry *lne = &g_array_index (jit->line_numbers, 
                                                                                                                MonoDebugLineNumberEntry,
                                                                                                                i);
-               encode_value (lne->offset - prev_offset, p, &p);
-               encode_value (lne->address - prev_native_offset, p, &p);
-               prev_offset = lne->offset;
-               prev_native_offset = lne->address;
+               encode_value (lne->il_offset - prev_offset, p, &p);
+               encode_value (lne->native_offset - prev_native_offset, p, &p);
+               prev_offset = lne->il_offset;
+               prev_native_offset = lne->native_offset;
        }
 
        g_assert (p - buf < size);
@@ -430,15 +439,15 @@ deserialize_debug_info (MonoMethod *method,
        char *p;
        int i;
 
-       g_assert (((MonoMethodNormal*)method)->header);
-       header = ((MonoMethodNormal*)method)->header;
+       header = mono_method_get_header (method);
+       g_assert (header);
 
        jit = g_new0 (MonoDebugMethodJitInfo, 1);
        jit->code_start = code_start;
        jit->line_numbers = g_array_new (FALSE, TRUE, sizeof (MonoDebugLineNumberEntry));
        jit->num_locals = header->num_locals;
        jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals);
-       jit->num_params = method->signature->param_count;
+       jit->num_params = mono_method_signature (method)->param_count;
        jit->params = g_new0 (MonoDebugVarInfo, jit->num_params);
 
        p = buf;
@@ -449,7 +458,7 @@ deserialize_debug_info (MonoMethod *method,
        for (i = 0; i < jit->num_params; ++i)
                deserialize_variable (&jit->params [i], p, &p);
 
-       if (method->signature->hasthis) {
+       if (mono_method_signature (method)->hasthis) {
                jit->this_var = g_new0 (MonoDebugVarInfo, 1);
                deserialize_variable (jit->this_var, p, &p);
        }
@@ -528,3 +537,12 @@ mono_init_debugger (const char *file, const char *opt_flags)
 
        return domain;
 }
+
+void
+mono_debug_add_icall_wrapper (MonoMethod *method, MonoJitICallInfo* callinfo)
+{
+       if (mono_debug_format == MONO_DEBUG_FORMAT_NONE)
+               return;
+
+       mono_debug_add_wrapper (method, callinfo->func, mono_get_root_domain ());
+}