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