Fixed return address intrinsics in MSVC.
[mono.git] / mono / mini / trace.c
1 /*
2  * trace.c: Tracing facilities for the Mono Runtime.
3  *
4  * Author:
5  *   Paolo Molaro (lupus@ximian.com)
6  *   Dietmar Maurer (dietmar@ximian.com)
7  *
8  * (C) 2002 Ximian, Inc.
9  * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
10  */
11
12 #include <config.h>
13 #include <signal.h>
14 #ifdef HAVE_ALLOCA_H
15 #include <alloca.h>
16 #endif
17 #ifdef HAVE_UNISTD_H
18 #include <unistd.h>
19 #endif
20 #include <string.h>
21 #include "mini.h"
22 #include <mono/metadata/debug-helpers.h>
23 #include <mono/metadata/assembly.h>
24 #include <mono/utils/mono-time.h>
25 #include "trace.h"
26
27 #if defined (PLATFORM_ANDROID) || (defined (TARGET_IOS) && defined (TARGET_IOS))
28 #  undef printf
29 #  define printf(...) g_log("mono", G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
30 #  undef fprintf
31 #  define fprintf(__ignore, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
32 #endif
33
34 #ifdef __GNUC__
35
36 #define RETURN_ADDRESS_N(N) (__builtin_extract_return_addr (__builtin_return_address (N)))
37 #define RETURN_ADDRESS() RETURN_ADDRESS_N(0)
38
39 #elif defined(_MSC_VER)
40
41 #ifdef __cplusplus
42 extern "C"
43 #endif
44 void *_ReturnAddress(void);
45 #pragma intrinsic(_ReturnAddress)
46 #define RETURN_ADDRESS() _ReturnAddress()
47 #define RETURN_ADDRESS_N(N) NULL
48
49 #else
50
51 #define RETURN_ADDRESS() NULL
52 #define RETURN_ADDRESS_N(N) NULL
53
54 #endif
55
56 static MonoTraceSpec trace_spec;
57
58 gboolean
59 mono_trace_eval_exception (MonoClass *klass)
60 {
61         int include = 0;
62         int i;
63
64         if (!klass)
65                 return FALSE;
66
67         for (i = 0; i < trace_spec.len; i++) {
68                 MonoTraceOperation *op = &trace_spec.ops [i];
69                 int inc = 0;
70                 
71                 switch (op->op){
72                 case MONO_TRACEOP_EXCEPTION:
73                         if (strcmp ("", op->data) == 0 && strcmp ("all", op->data2) == 0)
74                                 inc = 1;
75                         else if (strcmp ("", op->data) == 0 || strcmp (klass->name_space, op->data) == 0)
76                                 if (strcmp (klass->name, op->data2) == 0)
77                                         inc = 1;
78                         break;
79                 default:
80                         break;
81                 }
82                 if (op->exclude){
83                         if (inc)
84                                 include = 0;
85                 } else if (inc)
86                         include = 1;
87         }
88
89         return include;
90 }
91
92 gboolean
93 mono_trace_eval (MonoMethod *method)
94 {
95         int include = 0;
96         int i;
97
98         for (i = 0; i < trace_spec.len; i++){
99                 MonoTraceOperation *op = &trace_spec.ops [i];
100                 int inc = 0;
101                 
102                 switch (op->op){
103                 case MONO_TRACEOP_ALL:
104                         inc = 1; break;
105                 case MONO_TRACEOP_PROGRAM:
106                         if (trace_spec.assembly && (method->klass->image == mono_assembly_get_image (trace_spec.assembly)))
107                                 inc = 1; break;
108                 case MONO_TRACEOP_WRAPPER:
109                         if ((method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) ||
110                                 (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE))
111                                 inc = 1; break;
112                 case MONO_TRACEOP_METHOD:
113                         if (mono_method_desc_full_match ((MonoMethodDesc *) op->data, method))
114                                 inc = 1; break;
115                 case MONO_TRACEOP_CLASS:
116                         if (strcmp (method->klass->name_space, op->data) == 0)
117                                 if (strcmp (method->klass->name, op->data2) == 0)
118                                         inc = 1;
119                         break;
120                 case MONO_TRACEOP_ASSEMBLY:
121                         if (strcmp (mono_image_get_name (method->klass->image), op->data) == 0)
122                                 inc = 1; break;
123                 case MONO_TRACEOP_NAMESPACE:
124                         if (strcmp (method->klass->name_space, op->data) == 0)
125                                 inc = 1;
126                 case MONO_TRACEOP_EXCEPTION:
127                         break;
128                 }
129                 if (op->exclude){
130                         if (inc)
131                                 include = 0;
132                 } else if (inc)
133                         include = 1;
134         }
135         return include;
136 }
137
138 static int is_filenamechar (char p)
139 {
140         if (p >= 'A' && p <= 'Z')
141                 return TRUE;
142         if (p >= 'a' && p <= 'z')
143                 return TRUE;
144         if (p >= '0' && p <= '9')
145                 return TRUE;
146         if (p == '.' || p == ':' || p == '_' || p == '-')
147                 return TRUE;
148         return FALSE;
149 }
150
151 static char *input;
152 static char *value;
153
154 static void get_string (void)
155 {
156         char *start = input;
157         while (is_filenamechar (*input)){
158                 input++;
159         }
160         if (value != NULL)
161                 g_free (value);
162         value = g_malloc (input - start + 1);
163         strncpy (value, start, input-start);
164         value [input-start] = 0;
165 }
166
167 enum Token {
168         TOKEN_METHOD,
169         TOKEN_CLASS,
170         TOKEN_ALL,
171         TOKEN_PROGRAM,
172         TOKEN_EXCEPTION,
173         TOKEN_NAMESPACE,
174         TOKEN_WRAPPER,
175         TOKEN_STRING,
176         TOKEN_EXCLUDE,
177         TOKEN_DISABLED,
178         TOKEN_SEPARATOR,
179         TOKEN_END,
180         TOKEN_ERROR
181 };
182
183 static int
184 get_token (void)
185 {
186         while (input [0] == '+')
187                 input++;
188
189         if (input [0] == '\0') {
190                 return TOKEN_END;
191         }
192         if (input [0] == 'M' && input [1] == ':'){
193                 input += 2;
194                 get_string ();
195                 return TOKEN_METHOD;
196         }
197         if (input [0] == 'N' && input [1] == ':'){
198                 input += 2;
199                 get_string ();
200                 return TOKEN_NAMESPACE;
201         }
202         if (input [0] == 'T' && input [1] == ':'){
203                 input += 2;
204                 get_string ();
205                 return TOKEN_CLASS;
206         }
207         if (input [0] == 'E' && input [1] == ':'){
208                 input += 2;
209                 get_string ();
210                 return TOKEN_EXCEPTION;
211         }
212         if (*input == '-'){
213                 input++;
214                 return TOKEN_EXCLUDE;
215         }
216         if (is_filenamechar (*input)){
217                 get_string ();
218                 if (strcmp (value, "all") == 0)
219                         return TOKEN_ALL;
220                 if (strcmp (value, "program") == 0)
221                         return TOKEN_PROGRAM;
222                 if (strcmp (value, "wrapper") == 0)
223                         return TOKEN_WRAPPER;
224                 if (strcmp (value, "disabled") == 0)
225                         return TOKEN_DISABLED;
226                 return TOKEN_STRING;
227         }
228         if (*input == ','){
229                 input++;
230                 return TOKEN_SEPARATOR;
231         }
232
233         fprintf (stderr, "Syntax error at or around '%s'\n", input);    
234         return TOKEN_ERROR;
235 }
236
237 static void
238 cleanup (void)
239 {
240         if (value != NULL)
241                 g_free (value);
242 }
243
244 static int
245 get_spec (int *last)
246 {
247         int token = get_token ();
248         if (token == TOKEN_EXCLUDE){
249                 token = get_spec (last);
250                 if (token == TOKEN_EXCLUDE){
251                         fprintf (stderr, "Expecting an expression");
252                         return TOKEN_ERROR;
253                 }
254                 if (token == TOKEN_ERROR)
255                         return token;
256                 trace_spec.ops [(*last)-1].exclude = 1;
257                 return TOKEN_SEPARATOR;
258         }
259         if (token == TOKEN_END || token == TOKEN_SEPARATOR || token == TOKEN_ERROR)
260                 return token;
261         
262         if (token == TOKEN_METHOD){
263                 MonoMethodDesc *desc = mono_method_desc_new (value, TRUE);
264                 if (desc == NULL){
265                         fprintf (stderr, "Invalid method name: %s\n", value);
266                         return TOKEN_ERROR;
267                 }
268                 trace_spec.ops [*last].op = MONO_TRACEOP_METHOD;
269                 trace_spec.ops [*last].data = desc;
270         } else if (token == TOKEN_ALL)
271                 trace_spec.ops [*last].op = MONO_TRACEOP_ALL;
272         else if (token == TOKEN_PROGRAM)
273                 trace_spec.ops [*last].op = MONO_TRACEOP_PROGRAM;
274         else if (token == TOKEN_WRAPPER)
275                 trace_spec.ops [*last].op = MONO_TRACEOP_WRAPPER;
276         else if (token == TOKEN_NAMESPACE){
277                 trace_spec.ops [*last].op = MONO_TRACEOP_NAMESPACE;
278                 trace_spec.ops [*last].data = g_strdup (value);
279         } else if (token == TOKEN_CLASS || token == TOKEN_EXCEPTION){
280                 char *p = strrchr (value, '.');
281                 if (p) {
282                         *p++ = 0;
283                         trace_spec.ops [*last].data = g_strdup (value);
284                         trace_spec.ops [*last].data2 = g_strdup (p);
285                 }
286                 else {
287                         trace_spec.ops [*last].data = g_strdup ("");
288                         trace_spec.ops [*last].data2 = g_strdup (value);
289                 }
290                 trace_spec.ops [*last].op = token == TOKEN_CLASS ? MONO_TRACEOP_CLASS : MONO_TRACEOP_EXCEPTION;
291         } else if (token == TOKEN_STRING){
292                 trace_spec.ops [*last].op = MONO_TRACEOP_ASSEMBLY;
293                 trace_spec.ops [*last].data = g_strdup (value);
294         } else if (token == TOKEN_DISABLED) {
295                 trace_spec.enabled = FALSE;
296         } else {
297                 fprintf (stderr, "Syntax error in trace option specification\n");
298                 return TOKEN_ERROR;
299         }
300         (*last)++;
301         return TOKEN_SEPARATOR;
302 }
303
304 MonoTraceSpec *
305 mono_trace_parse_options (const char *options)
306 {
307         char *p = (char*)options;
308         int size = 1;
309         int last_used;
310         int token;
311
312         trace_spec.enabled = TRUE;
313         if (*p == 0){
314                 trace_spec.len = 1;
315                 trace_spec.ops = g_new0 (MonoTraceOperation, 1);
316                 trace_spec.ops [0].op = MONO_TRACEOP_ALL;
317                 return &trace_spec;
318         }
319                 
320         for (p = (char*)options; *p != 0; p++)
321                 if (*p == ',')
322                         size++;
323         
324         trace_spec.ops = g_new0 (MonoTraceOperation, size);
325
326         input = (char*)options;
327         last_used = 0;
328         
329         while ((token = (get_spec (&last_used))) != TOKEN_END){
330                 if (token == TOKEN_ERROR)
331                         return NULL;
332                 if (token == TOKEN_SEPARATOR)
333                         continue;
334         }
335         trace_spec.len = last_used;
336         cleanup ();
337         return &trace_spec;
338 }
339
340 void
341 mono_trace_set_assembly (MonoAssembly *assembly)
342 {
343         trace_spec.assembly = assembly;
344 }
345
346 static
347 #ifdef HAVE_KW_THREAD
348 __thread 
349 #endif
350 int indent_level = 0;
351 static guint64 start_time = 0;
352
353 static double seconds_since_start (void)
354 {
355         guint64 diff = mono_100ns_ticks () - start_time;
356         return diff/10000000.0;
357 }
358
359 static void indent (int diff) {
360         if (diff < 0)
361                 indent_level += diff;
362         if (start_time == 0)
363                 start_time = mono_100ns_ticks ();
364         printf ("[%p: %.5f %d] ", (void*)GetCurrentThreadId (), seconds_since_start (), indent_level);
365         if (diff > 0)
366                 indent_level += diff;
367 }
368
369 static char *
370 string_to_utf8 (MonoString *s)
371 {
372         char *as;
373         GError *error = NULL;
374
375         g_assert (s);
376
377         if (!s->length)
378                 return g_strdup ("");
379
380         as = g_utf16_to_utf8 (mono_string_chars (s), s->length, NULL, NULL, &error);
381         if (error) {
382                 /* Happens with StringBuilders */
383                 g_error_free (error);
384                 return g_strdup ("<INVALID UTF8>");
385         }
386         else
387                 return as;
388 }
389
390 /*
391  * cpos (ebp + arg_info[n].offset) points to the beginning of the
392  * stack slot for this argument.  On little-endian systems, we can
393  * simply dereference it. On big-endian systems, we need to adjust
394  * cpos upward first if the datatype we're referencing is smaller than
395  * a stack slot. Also - one can't assume that gpointer is also the
396  * size of a stack slot - use SIZEOF_REGISTER instead. The following
397  * helper macro tries to keep down the mess of all the pointer
398  * calculations.
399  */
400 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
401 #define arg_in_stack_slot(cpos, type) ((type *)(cpos))
402 #else
403 #define arg_in_stack_slot(cpos, type) ((type *)((sizeof(type) < SIZEOF_REGISTER) ? (((gssize)(cpos)) + SIZEOF_REGISTER - sizeof(type)) : (gssize)(cpos)))
404 #endif
405
406 void
407 mono_trace_enter_method (MonoMethod *method, char *ebp)
408 {
409         int i, j;
410         MonoClass *class;
411         MonoObject *o;
412         MonoJitArgumentInfo *arg_info;
413         MonoMethodSignature *sig;
414         char *fname;
415         MonoGenericSharingContext *gsctx = NULL;
416
417         if (!trace_spec.enabled)
418                 return;
419
420         fname = mono_method_full_name (method, TRUE);
421         indent (1);
422         printf ("ENTER: %s(", fname);
423         g_free (fname);
424
425         if (!ebp) {
426                 printf (") ip: %p\n", RETURN_ADDRESS_N (1));
427                 return;
428         }       
429
430         sig = mono_method_signature (method);
431
432         arg_info = alloca (sizeof (MonoJitArgumentInfo) * (sig->param_count + 1));
433
434         if (method->is_inflated) {
435                 /* FIXME: Might be better to pass the ji itself */
436                 MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (), NULL);
437                 if (ji) {
438                         gsctx = mono_jit_info_get_generic_sharing_context (ji);
439                         if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
440                                 /* Needs a ctx to get precise method */
441                                 printf (") <gsharedvt>\n");
442                                 return;
443                         }
444                 }
445         }
446
447         mono_arch_get_argument_info (gsctx, sig, sig->param_count, arg_info);
448
449         if (MONO_TYPE_ISSTRUCT (mono_method_signature (method)->ret)) {
450                 g_assert (!mono_method_signature (method)->ret->byref);
451
452                 printf ("VALUERET:%p, ", *((gpointer *)(ebp + 8)));
453         }
454
455         if (mono_method_signature (method)->hasthis) {
456                 gpointer *this = (gpointer *)(ebp + arg_info [0].offset);
457                 if (method->klass->valuetype) {
458                         printf ("value:%p, ", *arg_in_stack_slot(this, gpointer *));
459                 } else {
460                         o = *arg_in_stack_slot(this, MonoObject *);
461
462                         if (o) {
463                                 class = o->vtable->klass;
464
465                                 if (class == mono_defaults.string_class) {
466                                         MonoString *s = (MonoString*)o;
467                                         char *as = string_to_utf8 (s);
468
469                                         printf ("this:[STRING:%p:%s], ", o, as);
470                                         g_free (as);
471                                 } else {
472                                         printf ("this:%p[%s.%s %s], ", o, class->name_space, class->name, o->vtable->domain->friendly_name);
473                                 }
474                         } else 
475                                 printf ("this:NULL, ");
476                 }
477         }
478
479         for (i = 0; i < mono_method_signature (method)->param_count; ++i) {
480                 gpointer *cpos = (gpointer *)(ebp + arg_info [i + 1].offset);
481                 int size = arg_info [i + 1].size;
482
483                 MonoType *type = mono_method_signature (method)->params [i];
484                 
485                 if (type->byref) {
486                         printf ("[BYREF:%p], ", *arg_in_stack_slot(cpos, gpointer *));
487                 } else switch (mono_type_get_underlying_type (type)->type) {
488                         
489                 case MONO_TYPE_I:
490                 case MONO_TYPE_U:
491                         printf ("%p, ", *arg_in_stack_slot(cpos, gpointer *));
492                         break;
493                 case MONO_TYPE_BOOLEAN:
494                 case MONO_TYPE_CHAR:
495                 case MONO_TYPE_I1:
496                 case MONO_TYPE_U1:
497                         printf ("%d, ", *arg_in_stack_slot(cpos, gint8));
498                         break;
499                 case MONO_TYPE_I2:
500                 case MONO_TYPE_U2:
501                         printf ("%d, ", *arg_in_stack_slot(cpos, gint16));
502                         break;
503                 case MONO_TYPE_I4:
504                 case MONO_TYPE_U4:
505                         printf ("%d, ", *arg_in_stack_slot(cpos, int));
506                         break;
507                 case MONO_TYPE_STRING: {
508                         MonoString *s = *arg_in_stack_slot(cpos, MonoString *);
509                         if (s) {
510                                 char *as;
511
512                                 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
513                                 as = string_to_utf8 (s);
514
515                                 printf ("[STRING:%p:%s], ", s, as);
516                                 g_free (as);
517                         } else 
518                                 printf ("[STRING:null], ");
519                         break;
520                 }
521                 case MONO_TYPE_CLASS:
522                 case MONO_TYPE_OBJECT: {
523                         o = *arg_in_stack_slot(cpos, MonoObject *);
524                         if (o) {
525                                 class = o->vtable->klass;
526                     
527                                 if (class == mono_defaults.string_class) {
528                                         char *as = string_to_utf8 ((MonoString*)o);
529
530                                         printf ("[STRING:%p:%s], ", o, as);
531                                         g_free (as);
532                                 } else if (class == mono_defaults.int32_class) {
533                                         printf ("[INT32:%p:%d], ", o, *(gint32 *)((char *)o + sizeof (MonoObject)));
534                                 } else if (class == mono_defaults.monotype_class) {
535                                         printf ("[TYPE:%s], ", mono_type_full_name (((MonoReflectionType*)o)->type));
536                                 } else
537                                         printf ("[%s.%s:%p], ", class->name_space, class->name, o);
538                         } else {
539                                 printf ("%p, ", *arg_in_stack_slot(cpos, gpointer));
540                         }
541                         break;
542                 }
543                 case MONO_TYPE_PTR:
544                 case MONO_TYPE_FNPTR:
545                 case MONO_TYPE_ARRAY:
546                 case MONO_TYPE_SZARRAY:
547                         printf ("%p, ", *arg_in_stack_slot(cpos, gpointer));
548                         break;
549                 case MONO_TYPE_I8:
550                 case MONO_TYPE_U8:
551                         printf ("0x%016llx, ", (long long)*arg_in_stack_slot(cpos, gint64));
552                         break;
553                 case MONO_TYPE_R4:
554                         printf ("%f, ", *arg_in_stack_slot(cpos, float));
555                         break;
556                 case MONO_TYPE_R8:
557                         printf ("%f, ", *arg_in_stack_slot(cpos, double));
558                         break;
559                 case MONO_TYPE_VALUETYPE: 
560                         printf ("[");
561                         for (j = 0; j < size; j++)
562                                 printf ("%02x,", *((guint8*)cpos +j));
563                         printf ("], ");
564                         break;
565                 default:
566                         printf ("XX, ");
567                 }
568         }
569
570         printf (")\n");
571         fflush (stdout);
572 }
573
574 void
575 mono_trace_leave_method (MonoMethod *method, ...)
576 {
577         MonoType *type;
578         char *fname;
579         va_list ap;
580         MonoGenericSharingContext *gsctx;
581
582         if (!trace_spec.enabled)
583                 return;
584
585         va_start(ap, method);
586
587         fname = mono_method_full_name (method, TRUE);
588         indent (-1);
589         printf ("LEAVE: %s", fname);
590         g_free (fname);
591
592         if (method->is_inflated) {
593                 /* FIXME: Might be better to pass the ji itself */
594                 MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), RETURN_ADDRESS (), NULL);
595                 if (ji) {
596                         gsctx = mono_jit_info_get_generic_sharing_context (ji);
597                         if (gsctx && (gsctx->var_is_vt || gsctx->mvar_is_vt)) {
598                                 /* Needs a ctx to get precise method */
599                                 printf (") <gsharedvt>\n");
600                                 return;
601                         }
602                 }
603         }
604
605         type = mono_method_signature (method)->ret;
606
607 handle_enum:
608         switch (type->type) {
609         case MONO_TYPE_VOID:
610                 break;
611         case MONO_TYPE_BOOLEAN: {
612                 int eax = va_arg (ap, int);
613                 if (eax)
614                         printf ("TRUE:%d", eax);
615                 else 
616                         printf ("FALSE");
617                         
618                 break;
619         }
620         case MONO_TYPE_CHAR:
621         case MONO_TYPE_I1:
622         case MONO_TYPE_U1:
623         case MONO_TYPE_I2:
624         case MONO_TYPE_U2:
625         case MONO_TYPE_I4:
626         case MONO_TYPE_U4:
627         case MONO_TYPE_I:
628         case MONO_TYPE_U: {
629                 int eax = va_arg (ap, int);
630                 printf ("result=%d", eax);
631                 break;
632         }
633         case MONO_TYPE_STRING: {
634                 MonoString *s = va_arg (ap, MonoString *);
635 ;
636                 if (s) {
637                         char *as;
638
639                         g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
640                         as = string_to_utf8 (s);
641                         printf ("[STRING:%p:%s]", s, as);
642                         g_free (as);
643                 } else 
644                         printf ("[STRING:null], ");
645                 break;
646         }
647         case MONO_TYPE_CLASS: 
648         case MONO_TYPE_OBJECT: {
649                 MonoObject *o = va_arg (ap, MonoObject *);
650
651                 if (o) {
652                         if (o->vtable->klass == mono_defaults.boolean_class) {
653                                 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));            
654                         } else if  (o->vtable->klass == mono_defaults.int32_class) {
655                                 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));    
656                         } else if  (o->vtable->klass == mono_defaults.int64_class) {
657                                 printf ("[INT64:%p:%lld]", o, (long long)*((gint64 *)((char *)o + sizeof (MonoObject))));       
658                         } else
659                                 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
660                 } else
661                         printf ("[OBJECT:%p]", o);
662                
663                 break;
664         }
665         case MONO_TYPE_PTR:
666         case MONO_TYPE_FNPTR:
667         case MONO_TYPE_ARRAY:
668         case MONO_TYPE_SZARRAY: {
669                 gpointer p = va_arg (ap, gpointer);
670                 printf ("result=%p", p);
671                 break;
672         }
673         case MONO_TYPE_I8: {
674                 gint64 l =  va_arg (ap, gint64);
675                 printf ("lresult=0x%16llx", (long long)l);
676                 break;
677         }
678         case MONO_TYPE_U8: {
679                 gint64 l =  va_arg (ap, gint64);
680                 printf ("lresult=0x%16llx", (long long)l);
681                 break;
682         }
683         case MONO_TYPE_R4:
684         case MONO_TYPE_R8: {
685                 double f = va_arg (ap, double);
686                 printf ("FP=%f", f);
687                 break;
688         }
689         case MONO_TYPE_VALUETYPE: 
690                 if (type->data.klass->enumtype) {
691                         type = mono_class_enum_basetype (type->data.klass);
692                         goto handle_enum;
693                 } else {
694                         guint8 *p = va_arg (ap, gpointer);
695                         int j, size, align;
696                         size = mono_type_size (type, &align);
697                         printf ("[");
698                         for (j = 0; p && j < size; j++)
699                                 printf ("%02x,", p [j]);
700                         printf ("]");
701                 }
702                 break;
703         default:
704                 printf ("(unknown return type %x)", mono_method_signature (method)->ret->type);
705         }
706
707         //printf (" ip: %p\n", RETURN_ADDRESS_N (1));
708         printf ("\n");
709         fflush (stdout);
710 }
711
712 void
713 mono_trace_enable (gboolean enable)
714 {
715         trace_spec.enabled = enable;
716 }
717
718 gboolean
719 mono_trace_is_enabled ()
720 {
721         return trace_spec.enabled;
722 }