[llvm] Allow phi instructions where some incoming nodes are not defined because they...
[mono.git] / mono / mini / trace.c
index 024ddaf20eeb4d58867fd192e6f13bba711a0659..abd79479169cf069619ed65c68f3b33858550e4b 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include <config.h>
-#include <signal.h>
 #ifdef HAVE_ALLOCA_H
 #include <alloca.h>
 #endif
 #  define fprintf(__ignore, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
 #endif
 
+#ifdef __GNUC__
+
+#define RETURN_ADDRESS_N(N) (__builtin_extract_return_addr (__builtin_return_address (N)))
+#define RETURN_ADDRESS() RETURN_ADDRESS_N(0)
+
+#elif defined(_MSC_VER)
+
+#include <intrin.h>
+#pragma intrinsic(_ReturnAddress)
+
+#define RETURN_ADDRESS() _ReturnAddress()
+#define RETURN_ADDRESS_N(N) NULL
+
+#else
+
+#error "Missing return address intrinsics implementation"
+
+#endif
+
 static MonoTraceSpec trace_spec;
 
 gboolean
@@ -121,7 +139,7 @@ static int is_filenamechar (char p)
                return TRUE;
        if (p >= '0' && p <= '9')
                return TRUE;
-       if (p == '.' || p == ':' || p == '_' || p == '-')
+       if (p == '.' || p == ':' || p == '_' || p == '-' || p == '`')
                return TRUE;
        return FALSE;
 }
@@ -385,7 +403,7 @@ void
 mono_trace_enter_method (MonoMethod *method, char *ebp)
 {
        int i, j;
-       MonoClass *class;
+       MonoClass *klass;
        MonoObject *o;
        MonoJitArgumentInfo *arg_info;
        MonoMethodSignature *sig;
@@ -401,7 +419,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
        g_free (fname);
 
        if (!ebp) {
-               printf (") ip: %p\n", __builtin_return_address (1));
+               printf (") ip: %p\n", RETURN_ADDRESS_N (1));
                return;
        }       
 
@@ -411,10 +429,10 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
 
        if (method->is_inflated) {
                /* FIXME: Might be better to pass the ji itself */
-               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), __builtin_return_address (0), NULL);
+               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (), NULL);
                if (ji) {
                        gsctx = mono_jit_info_get_generic_sharing_context (ji);
-                       if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
+                       if (gsctx && gsctx->is_gsharedvt) {
                                /* Needs a ctx to get precise method */
                                printf (") <gsharedvt>\n");
                                return;
@@ -422,7 +440,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
                }
        }
 
-       mono_arch_get_argument_info (gsctx, sig, sig->param_count, arg_info);
+       mono_arch_get_argument_info (sig, sig->param_count, arg_info);
 
        if (MONO_TYPE_ISSTRUCT (mono_method_signature (method)->ret)) {
                g_assert (!mono_method_signature (method)->ret->byref);
@@ -438,16 +456,16 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
                        o = *arg_in_stack_slot(this, MonoObject *);
 
                        if (o) {
-                               class = o->vtable->klass;
+                               klass = o->vtable->klass;
 
-                               if (class == mono_defaults.string_class) {
+                               if (klass == mono_defaults.string_class) {
                                        MonoString *s = (MonoString*)o;
                                        char *as = string_to_utf8 (s);
 
                                        printf ("this:[STRING:%p:%s], ", o, as);
                                        g_free (as);
                                } else {
-                                       printf ("this:%p[%s.%s %s], ", o, class->name_space, class->name, o->vtable->domain->friendly_name);
+                                       printf ("this:%p[%s.%s %s], ", o, klass->name_space, klass->name, o->vtable->domain->friendly_name);
                                }
                        } else 
                                printf ("this:NULL, ");
@@ -500,19 +518,19 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
                case MONO_TYPE_OBJECT: {
                        o = *arg_in_stack_slot(cpos, MonoObject *);
                        if (o) {
-                               class = o->vtable->klass;
+                               klass = o->vtable->klass;
                    
-                               if (class == mono_defaults.string_class) {
+                               if (klass == mono_defaults.string_class) {
                                        char *as = string_to_utf8 ((MonoString*)o);
 
                                        printf ("[STRING:%p:%s], ", o, as);
                                        g_free (as);
-                               } else if (class == mono_defaults.int32_class) {
+                               } else if (klass == mono_defaults.int32_class) {
                                        printf ("[INT32:%p:%d], ", o, *(gint32 *)((char *)o + sizeof (MonoObject)));
-                               } else if (class == mono_defaults.monotype_class) {
+                               } else if (klass == mono_defaults.monotype_class) {
                                        printf ("[TYPE:%s], ", mono_type_full_name (((MonoReflectionType*)o)->type));
                                } else
-                                       printf ("[%s.%s:%p], ", class->name_space, class->name, o);
+                                       printf ("[%s.%s:%p], ", klass->name_space, klass->name, o);
                        } else {
                                printf ("%p, ", *arg_in_stack_slot(cpos, gpointer));
                        }
@@ -569,10 +587,10 @@ mono_trace_leave_method (MonoMethod *method, ...)
 
        if (method->is_inflated) {
                /* FIXME: Might be better to pass the ji itself */
-               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), __builtin_return_address (0), NULL);
+               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (), NULL);
                if (ji) {
                        gsctx = mono_jit_info_get_generic_sharing_context (ji);
-                       if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
+                       if (gsctx && gsctx->is_gsharedvt) {
                                /* Needs a ctx to get precise method */
                                printf (") <gsharedvt>\n");
                                return;
@@ -661,7 +679,7 @@ handle_enum:
        case MONO_TYPE_R4:
        case MONO_TYPE_R8: {
                double f = va_arg (ap, double);
-               printf ("FP=%f\n", f);
+               printf ("FP=%f", f);
                break;
        }
        case MONO_TYPE_VALUETYPE: 
@@ -682,7 +700,7 @@ handle_enum:
                printf ("(unknown return type %x)", mono_method_signature (method)->ret->type);
        }
 
-       //printf (" ip: %p\n", __builtin_return_address (1));
+       //printf (" ip: %p\n", RETURN_ADDRESS_N (1));
        printf ("\n");
        fflush (stdout);
 }