TOKEN_NAMESPACE,
TOKEN_STRING,
TOKEN_EXCLUDE,
+ TOKEN_DISABLED,
TOKEN_SEPARATOR,
TOKEN_END,
TOKEN_ERROR
static int
get_token (void)
{
- while (*input != 0){
- if (input [0] == 'M' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_METHOD;
- }
- if (input [0] == 'N' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_NAMESPACE;
- }
- if (input [0] == 'T' && input [1] == ':'){
- input += 2;
- get_string ();
- return TOKEN_CLASS;
- }
- if (is_filenamechar (*input)){
- get_string ();
- if (strcmp (value, "all") == 0)
- return TOKEN_ALL;
- if (strcmp (value, "program") == 0)
- return TOKEN_PROGRAM;
- return TOKEN_STRING;
- }
- if (*input == '-'){
- input++;
- return TOKEN_EXCLUDE;
- }
- if (*input == ','){
- input++;
- return TOKEN_SEPARATOR;
- }
+ if (input [0] == '\0') {
+ return TOKEN_END;
+ }
+ if (input [0] == 'M' && input [1] == ':'){
+ input += 2;
+ get_string ();
+ return TOKEN_METHOD;
+ }
+ if (input [0] == 'N' && input [1] == ':'){
+ input += 2;
+ get_string ();
+ return TOKEN_NAMESPACE;
+ }
+ if (input [0] == 'T' && input [1] == ':'){
+ input += 2;
+ get_string ();
+ return TOKEN_CLASS;
+ }
+ 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, "disabled") == 0)
+ return TOKEN_DISABLED;
+ return TOKEN_STRING;
+ }
+ if (*input == '-'){
input++;
-
+ return TOKEN_EXCLUDE;
+ }
+ if (*input == ','){
+ input++;
+ return TOKEN_SEPARATOR;
}
- return TOKEN_END;
+
+ fprintf (stderr, "Syntax error at or around '%s'\n", input);
+ return TOKEN_ERROR;
}
static void
} else if (token == TOKEN_STRING){
trace_spec.ops [*last].op = MONO_TRACEOP_ASSEMBLY;
trace_spec.ops [*last].data = g_strdup (value);
- }
- else {
+ } else if (token == TOKEN_DISABLED) {
+ trace_spec.enabled = FALSE;
+ } else {
fprintf (stderr, "Syntax error in trace option specification\n");
return TOKEN_ERROR;
}
int size = 1;
int last_used;
int token;
-
+
+ trace_spec.enabled = TRUE;
if (*p == 0){
trace_spec.len = 1;
trace_spec.ops = g_new0 (MonoTraceOperation, 1);
indent_level += diff;
}
-static gboolean enable_trace = TRUE;
+static char *
+string_to_utf8 (MonoString *s)
+{
+ char *as;
+ GError *error = NULL;
+
+ g_assert (s);
+
+ if (!s->length)
+ return g_strdup ("");
+
+ as = g_utf16_to_utf8 (mono_string_chars (s), s->length, NULL, NULL, &error);
+ if (error) {
+ /* Happens with StringBuilders */
+ g_error_free (error);
+ return g_strdup ("<INVALID UTF8>");
+ }
+ else
+ return as;
+}
void
mono_trace_enter_method (MonoMethod *method, char *ebp)
MonoMethodSignature *sig;
char *fname;
- if (!enable_trace)
+ if (!trace_spec.enabled)
return;
fname = mono_method_full_name (method, TRUE);
printf (") ip: %p\n", __builtin_return_address (1));
return;
}
- if (((int)ebp & (MONO_ARCH_FRAME_ALIGNMENT - 1)) != 0) {
+ if ((GPOINTER_TO_INT (ebp) & (MONO_ARCH_FRAME_ALIGNMENT - 1)) != 0) {
g_error ("unaligned stack detected (%p)", ebp);
}
class = o->vtable->klass;
if (class == mono_defaults.string_class) {
- printf ("this:[STRING:%p:%s], ", o, mono_string_to_utf8 ((MonoString *)o));
+ 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);
}
if (type->byref) {
printf ("[BYREF:%p], ", *cpos);
- } else switch (type->type) {
+ } else switch (mono_type_get_underlying_type (type)->type) {
case MONO_TYPE_I:
case MONO_TYPE_U:
- printf ("%p, ", (gpointer)*((int *)(cpos)));
+ printf ("%p, ", *((gpointer **)(cpos)));
break;
case MONO_TYPE_BOOLEAN:
case MONO_TYPE_CHAR:
case MONO_TYPE_STRING: {
MonoString *s = *((MonoString **)cpos);
if (s) {
+ char *as;
+
g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
- printf ("[STRING:%p:%s], ", s, mono_string_to_utf8 (s));
+ as = string_to_utf8 (s);
+
+ printf ("[STRING:%p:%s], ", s, as);
+ g_free (as);
} else
printf ("[STRING:null], ");
break;
class = o->vtable->klass;
if (class == mono_defaults.string_class) {
- printf ("[STRING:%p:%s], ", o, mono_string_to_utf8 ((MonoString *)o));
+ char *as = string_to_utf8 ((MonoString*)o);
+
+ printf ("[STRING:%p:%s], ", o, as);
+ g_free (as);
} else if (class == mono_defaults.int32_class) {
printf ("[INT32:%p:%d], ", o, *(gint32 *)((char *)o + sizeof (MonoObject)));
} else
break;
case MONO_TYPE_I8:
case MONO_TYPE_U8:
- printf ("0x%016llx, ", *((gint64 *)(cpos)));
+ printf ("0x%016llx, ", (long long)*((gint64 *)(cpos)));
break;
case MONO_TYPE_R4:
printf ("%f, ", *((float *)(cpos)));
}
printf (")\n");
+ fflush (stdout);
}
void
char *fname;
va_list ap;
- if (!enable_trace)
+ if (!trace_spec.enabled)
return;
va_start(ap, method);
MonoString *s = va_arg (ap, MonoString *);
;
if (s) {
+ char *as;
+
g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
- printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
+ as = string_to_utf8 (s);
+ printf ("[STRING:%p:%s]", s, as);
+ g_free (as);
} else
printf ("[STRING:null], ");
break;
} else if (o->vtable->klass == mono_defaults.int32_class) {
printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
} else if (o->vtable->klass == mono_defaults.int64_class) {
- printf ("[INT64:%p:%lld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
+ printf ("[INT64:%p:%lld]", o, (long long)*((gint64 *)((char *)o + sizeof (MonoObject))));
} else
printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
} else
}
case MONO_TYPE_I8: {
gint64 l = va_arg (ap, gint64);
- printf ("lresult=0x%16llx", l);
+ printf ("lresult=0x%16llx", (long long)l);
break;
}
case MONO_TYPE_U8: {
gint64 l = va_arg (ap, gint64);
- printf ("lresult=0x%16llx", l);
+ printf ("lresult=0x%16llx", (long long)l);
break;
}
case MONO_TYPE_R4:
//printf (" ip: %p\n", __builtin_return_address (1));
printf ("\n");
+ fflush (stdout);
}
+
+void
+mono_trace_enable (gboolean enable)
+{
+ trace_spec.enabled = enable;
+}
+
+gboolean
+mono_trace_is_enabled ()
+{
+ return trace_spec.enabled;
+}
+