X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Ftrace.c;h=f67b704c362727b2e9f80e000e3fda8b85849779;hb=0927129c35f5a2d6df891857b2155ad5fb6ba3d2;hp=4e5ca0316d8f85b49b7a77fb3b960a85dd742efe;hpb=217ddc29c40bc8b11f8fbd4800e61db7f4f22bbf;p=mono.git diff --git a/mono/mini/trace.c b/mono/mini/trace.c index 4e5ca0316d8..f67b704c362 100644 --- a/mono/mini/trace.c +++ b/mono/mini/trace.c @@ -6,6 +6,7 @@ * Dietmar Maurer (dietmar@ximian.com) * * (C) 2002 Ximian, Inc. + * Copyright 2011 Xamarin, Inc (http://www.xamarin.com) */ #include @@ -23,8 +24,49 @@ #include #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 + static MonoTraceSpec trace_spec; +gboolean +mono_trace_eval_exception (MonoClass *klass) +{ + int include = 0; + int i; + + if (!klass) + return FALSE; + + for (i = 0; i < trace_spec.len; i++) { + MonoTraceOperation *op = &trace_spec.ops [i]; + int inc = 0; + + switch (op->op){ + case MONO_TRACEOP_EXCEPTION: + if (strcmp ("", op->data) == 0 && strcmp ("all", op->data2) == 0) + inc = 1; + else if (strcmp ("", op->data) == 0 || strcmp (klass->name_space, op->data) == 0) + if (strcmp (klass->name, op->data2) == 0) + inc = 1; + break; + default: + break; + } + if (op->exclude){ + if (inc) + include = 0; + } else if (inc) + include = 1; + } + + return include; +} + gboolean mono_trace_eval (MonoMethod *method) { @@ -41,6 +83,10 @@ mono_trace_eval (MonoMethod *method) case MONO_TRACEOP_PROGRAM: if (trace_spec.assembly && (method->klass->image == mono_assembly_get_image (trace_spec.assembly))) inc = 1; break; + case MONO_TRACEOP_WRAPPER: + if ((method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) || + (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)) + inc = 1; break; case MONO_TRACEOP_METHOD: if (mono_method_desc_full_match ((MonoMethodDesc *) op->data, method)) inc = 1; break; @@ -55,6 +101,8 @@ mono_trace_eval (MonoMethod *method) case MONO_TRACEOP_NAMESPACE: if (strcmp (method->klass->name_space, op->data) == 0) inc = 1; + case MONO_TRACEOP_EXCEPTION: + break; } if (op->exclude){ if (inc) @@ -99,7 +147,9 @@ enum Token { TOKEN_CLASS, TOKEN_ALL, TOKEN_PROGRAM, + TOKEN_EXCEPTION, TOKEN_NAMESPACE, + TOKEN_WRAPPER, TOKEN_STRING, TOKEN_EXCLUDE, TOKEN_DISABLED, @@ -111,6 +161,9 @@ enum Token { static int get_token (void) { + while (input [0] == '+') + input++; + if (input [0] == '\0') { return TOKEN_END; } @@ -129,20 +182,27 @@ get_token (void) get_string (); return TOKEN_CLASS; } + if (input [0] == 'E' && input [1] == ':'){ + input += 2; + get_string (); + return TOKEN_EXCEPTION; + } + if (*input == '-'){ + input++; + return TOKEN_EXCLUDE; + } if (is_filenamechar (*input)){ get_string (); if (strcmp (value, "all") == 0) return TOKEN_ALL; if (strcmp (value, "program") == 0) return TOKEN_PROGRAM; + if (strcmp (value, "wrapper") == 0) + return TOKEN_WRAPPER; if (strcmp (value, "disabled") == 0) return TOKEN_DISABLED; return TOKEN_STRING; } - if (*input == '-'){ - input++; - return TOKEN_EXCLUDE; - } if (*input == ','){ input++; return TOKEN_SEPARATOR; @@ -189,10 +249,12 @@ get_spec (int *last) trace_spec.ops [*last].op = MONO_TRACEOP_ALL; else if (token == TOKEN_PROGRAM) trace_spec.ops [*last].op = MONO_TRACEOP_PROGRAM; + else if (token == TOKEN_WRAPPER) + trace_spec.ops [*last].op = MONO_TRACEOP_WRAPPER; else if (token == TOKEN_NAMESPACE){ trace_spec.ops [*last].op = MONO_TRACEOP_NAMESPACE; trace_spec.ops [*last].data = g_strdup (value); - } else if (token == TOKEN_CLASS){ + } else if (token == TOKEN_CLASS || token == TOKEN_EXCEPTION){ char *p = strrchr (value, '.'); if (p) { *p++ = 0; @@ -203,7 +265,7 @@ get_spec (int *last) trace_spec.ops [*last].data = g_strdup (""); trace_spec.ops [*last].data2 = g_strdup (value); } - trace_spec.ops [*last].op = MONO_TRACEOP_CLASS; + trace_spec.ops [*last].op = token == TOKEN_CLASS ? MONO_TRACEOP_CLASS : MONO_TRACEOP_EXCEPTION; } else if (token == TOKEN_STRING){ trace_spec.ops [*last].op = MONO_TRACEOP_ASSEMBLY; trace_spec.ops [*last].data = g_strdup (value); @@ -273,10 +335,8 @@ static double seconds_since_start (void) } static void indent (int diff) { - int v; if (diff < 0) indent_level += diff; - v = indent_level; if (start_time == 0) start_time = mono_100ns_ticks (); printf ("[%p: %.5f %d] ", (void*)GetCurrentThreadId (), seconds_since_start (), indent_level); @@ -305,6 +365,22 @@ string_to_utf8 (MonoString *s) return as; } +/* + * cpos (ebp + arg_info[n].offset) points to the beginning of the + * stack slot for this argument. On little-endian systems, we can + * simply dereference it. On big-endian systems, we need to adjust + * cpos upward first if the datatype we're referencing is smaller than + * a stack slot. Also - one can't assume that gpointer is also the + * size of a stack slot - use SIZEOF_REGISTER instead. The following + * helper macro tries to keep down the mess of all the pointer + * calculations. + */ +#if (G_BYTE_ORDER == G_LITTLE_ENDIAN) +#define arg_in_stack_slot(cpos, type) ((type *)(cpos)) +#else +#define arg_in_stack_slot(cpos, type) ((type *)((sizeof(type) < SIZEOF_REGISTER) ? (((gssize)(cpos)) + SIZEOF_REGISTER - sizeof(type)) : (gssize)(cpos))) +#endif + void mono_trace_enter_method (MonoMethod *method, char *ebp) { @@ -314,6 +390,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) MonoJitArgumentInfo *arg_info; MonoMethodSignature *sig; char *fname; + MonoGenericSharingContext *gsctx = NULL; if (!trace_spec.enabled) return; @@ -332,7 +409,20 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) arg_info = alloca (sizeof (MonoJitArgumentInfo) * (sig->param_count + 1)); - mono_arch_get_argument_info (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 (), __builtin_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 (") \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); @@ -343,9 +433,9 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) if (mono_method_signature (method)->hasthis) { gpointer *this = (gpointer *)(ebp + arg_info [0].offset); if (method->klass->valuetype) { - printf ("value:%p, ", *this); + printf ("value:%p, ", *arg_in_stack_slot(this, gpointer *)); } else { - o = *((MonoObject **)this); + o = *arg_in_stack_slot(this, MonoObject *); if (o) { class = o->vtable->klass; @@ -371,29 +461,29 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) MonoType *type = mono_method_signature (method)->params [i]; if (type->byref) { - printf ("[BYREF:%p], ", *cpos); + printf ("[BYREF:%p], ", *arg_in_stack_slot(cpos, gpointer *)); } else switch (mono_type_get_underlying_type (type)->type) { case MONO_TYPE_I: case MONO_TYPE_U: - printf ("%p, ", *((gpointer **)(cpos))); + printf ("%p, ", *arg_in_stack_slot(cpos, gpointer *)); break; case MONO_TYPE_BOOLEAN: case MONO_TYPE_CHAR: case MONO_TYPE_I1: case MONO_TYPE_U1: - printf ("%d, ", *((gint8 *)(cpos))); + printf ("%d, ", *arg_in_stack_slot(cpos, gint8)); break; case MONO_TYPE_I2: case MONO_TYPE_U2: - printf ("%d, ", *((gint16 *)(cpos))); + printf ("%d, ", *arg_in_stack_slot(cpos, gint16)); break; case MONO_TYPE_I4: case MONO_TYPE_U4: - printf ("%d, ", *((int *)(cpos))); + printf ("%d, ", *arg_in_stack_slot(cpos, int)); break; case MONO_TYPE_STRING: { - MonoString *s = *((MonoString **)cpos); + MonoString *s = *arg_in_stack_slot(cpos, MonoString *); if (s) { char *as; @@ -408,7 +498,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) } case MONO_TYPE_CLASS: case MONO_TYPE_OBJECT: { - o = *((MonoObject **)cpos); + o = *arg_in_stack_slot(cpos, MonoObject *); if (o) { class = o->vtable->klass; @@ -424,7 +514,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) } else printf ("[%s.%s:%p], ", class->name_space, class->name, o); } else { - printf ("%p, ", *((gpointer *)(cpos))); + printf ("%p, ", *arg_in_stack_slot(cpos, gpointer)); } break; } @@ -432,17 +522,17 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) case MONO_TYPE_FNPTR: case MONO_TYPE_ARRAY: case MONO_TYPE_SZARRAY: - printf ("%p, ", *((gpointer *)(cpos))); + printf ("%p, ", *arg_in_stack_slot(cpos, gpointer)); break; case MONO_TYPE_I8: case MONO_TYPE_U8: - printf ("0x%016llx, ", (long long)*((gint64 *)(cpos))); + printf ("0x%016llx, ", (long long)*arg_in_stack_slot(cpos, gint64)); break; case MONO_TYPE_R4: - printf ("%f, ", *((float *)(cpos))); + printf ("%f, ", *arg_in_stack_slot(cpos, float)); break; case MONO_TYPE_R8: - printf ("%f, ", *((double *)(cpos))); + printf ("%f, ", *arg_in_stack_slot(cpos, double)); break; case MONO_TYPE_VALUETYPE: printf ("["); @@ -465,6 +555,7 @@ mono_trace_leave_method (MonoMethod *method, ...) MonoType *type; char *fname; va_list ap; + MonoGenericSharingContext *gsctx; if (!trace_spec.enabled) return; @@ -476,6 +567,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 (), __builtin_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 (") \n"); + return; + } + } + } + type = mono_method_signature (method)->ret; handle_enum: @@ -557,12 +661,12 @@ 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: if (type->data.klass->enumtype) { - type = type->data.klass->enum_basetype; + type = mono_class_enum_basetype (type->data.klass); goto handle_enum; } else { guint8 *p = va_arg (ap, gpointer); @@ -594,4 +698,3 @@ mono_trace_is_enabled () { return trace_spec.enabled; } -