Merge branch 'master' into msbuilddll2
[mono.git] / mono / mini / trace.c
index f8643d77cdf7acc45e68701666102cd430497dbf..551b2a2fdaf61777910edb599686a6abacf8cfd7 100644 (file)
 #include <mono/utils/mono-time.h>
 #include "trace.h"
 
+#if defined (PLATFORM_ANDROID) || (defined (TARGET_IOS) && defined (TARGET_IOS))
+#  undef printf
+#  define printf(...) g_log("mono", G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
+#  undef fprintf
+#  define fprintf(__ignore, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
+#endif
+
+#define RETURN_ADDRESS(N) (__builtin_extract_return_addr (__builtin_return_address (N)))
+
 static MonoTraceSpec trace_spec;
 
 gboolean
@@ -383,6 +392,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
        MonoJitArgumentInfo *arg_info;
        MonoMethodSignature *sig;
        char *fname;
+       MonoGenericSharingContext *gsctx = NULL;
 
        if (!trace_spec.enabled)
                return;
@@ -393,7 +403,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 (1));
                return;
        }       
 
@@ -401,7 +411,20 @@ mono_trace_enter_method (MonoMethod *method, char *ebp)
 
        arg_info = alloca (sizeof (MonoJitArgumentInfo) * (sig->param_count + 1));
 
-       mono_arch_get_argument_info (NULL, sig, sig->param_count, arg_info);
+       if (method->is_inflated) {
+               /* FIXME: Might be better to pass the ji itself */
+               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (0), NULL);
+               if (ji) {
+                       gsctx = mono_jit_info_get_generic_sharing_context (ji);
+                       if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
+                               /* Needs a ctx to get precise method */
+                               printf (") <gsharedvt>\n");
+                               return;
+                       }
+               }
+       }
+
+       mono_arch_get_argument_info (gsctx, sig, sig->param_count, arg_info);
 
        if (MONO_TYPE_ISSTRUCT (mono_method_signature (method)->ret)) {
                g_assert (!mono_method_signature (method)->ret->byref);
@@ -534,6 +557,7 @@ mono_trace_leave_method (MonoMethod *method, ...)
        MonoType *type;
        char *fname;
        va_list ap;
+       MonoGenericSharingContext *gsctx;
 
        if (!trace_spec.enabled)
                return;
@@ -545,6 +569,19 @@ mono_trace_leave_method (MonoMethod *method, ...)
        printf ("LEAVE: %s", fname);
        g_free (fname);
 
+       if (method->is_inflated) {
+               /* FIXME: Might be better to pass the ji itself */
+               MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (0), NULL);
+               if (ji) {
+                       gsctx = mono_jit_info_get_generic_sharing_context (ji);
+                       if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
+                               /* Needs a ctx to get precise method */
+                               printf (") <gsharedvt>\n");
+                               return;
+                       }
+               }
+       }
+
        type = mono_method_signature (method)->ret;
 
 handle_enum:
@@ -626,7 +663,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: 
@@ -647,7 +684,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 (1));
        printf ("\n");
        fflush (stdout);
 }