* daemon-messages.c: Retry if the communication with the daemon is
[mono.git] / mono / metadata / debug-helpers.c
index e70a4b791c10597e277f397718269e811d3ab88a..4f129fcfcb2210bf260f1c1a4daf491f647342c2 100644 (file)
@@ -14,6 +14,39 @@ struct MonoMethodDesc {
        gboolean include_namespace;
 };
 
+static const char *wrapper_type_names [] = {
+       "none",
+       "delegate-invoke",
+       "delegate-begin-invoke",
+       "delegate-end-invoke",
+       "runtime-invoke",
+       "native-to-managed",
+       "managed-to-native",
+       "remoting-invoke",
+       "remoting-invoke-with-check",
+       "ldfld",
+       "stfld",
+       "synchronized",
+       "dynamic-method",
+       "unknown"
+};
+
+static void
+append_class_name (GString *res, MonoClass *class, gboolean include_namespace)
+{
+       if (!class) {
+               g_string_append (res, "Unknown");
+               return;
+       }
+       if (class->nested_in) {
+               append_class_name (res, class->nested_in, include_namespace);
+               g_string_append_c (res, '/');
+       }
+       if (include_namespace && *(class->name_space))
+               g_string_sprintfa (res, "%s.", class->name_space);
+       g_string_sprintfa (res, "%s", class->name);
+}
+
 void
 mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace) {
        switch (type->type) {
@@ -32,9 +65,9 @@ mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace) {
        case MONO_TYPE_I2:
                g_string_append (res, "int16"); break;
        case MONO_TYPE_U4:
-               g_string_append (res, "int"); break;
-       case MONO_TYPE_I4:
                g_string_append (res, "uint"); break;
+       case MONO_TYPE_I4:
+               g_string_append (res, "int"); break;
        case MONO_TYPE_U8:
                g_string_append (res, "ulong"); break;
        case MONO_TYPE_I8:
@@ -42,9 +75,9 @@ mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace) {
        case MONO_TYPE_FNPTR: /* who cares for the exact signature? */
                g_string_append (res, "*()"); break;
        case MONO_TYPE_U:
-               g_string_append (res, "intptr"); break;
-       case MONO_TYPE_I:
                g_string_append (res, "uintptr"); break;
+       case MONO_TYPE_I:
+               g_string_append (res, "intptr"); break;
        case MONO_TYPE_R4:
                g_string_append (res, "single"); break;
        case MONO_TYPE_R8:
@@ -58,25 +91,17 @@ mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace) {
                g_string_append_c (res, '*');
                break;
        case MONO_TYPE_ARRAY:
-               mono_type_get_desc (res, type->data.array->type, include_namespace);
+               append_class_name (res, type->data.array->eklass, include_namespace);
                g_string_sprintfa (res, "[%d]", type->data.array->rank);
                break;
        case MONO_TYPE_SZARRAY:
-               mono_type_get_desc (res, type->data.type, include_namespace);
+               mono_type_get_desc (res, &type->data.klass->byval_arg, include_namespace);
                g_string_append (res, "[]");
                break;
        case MONO_TYPE_CLASS:
-       case MONO_TYPE_VALUETYPE: {
-               MonoClass *class = type->data.klass;
-               if (!class) {
-                       g_string_append (res, "Unknown");
-                       break;
-               }
-               if (include_namespace && *(class->name_space))
-                       g_string_sprintfa (res, "%s.", class->name_space);
-               g_string_sprintfa (res, "%s", class->name);
+       case MONO_TYPE_VALUETYPE:
+               append_class_name (res, type->data.klass, include_namespace);
                break;
-       }
        default:
                break;
        }
@@ -84,6 +109,20 @@ mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace) {
                g_string_append_c (res, '&');
 }
 
+char*
+mono_type_full_name (MonoType *type)
+{
+       GString *str;
+       char *res;
+
+       str = g_string_new ("");
+       mono_type_get_desc (str, type, TRUE);
+
+       res = g_strdup (str->str);
+       g_string_free (str, TRUE);
+       return res;
+}
+
 char*
 mono_signature_get_desc (MonoMethodSignature *sig, gboolean include_namespace)
 {
@@ -154,12 +193,27 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
                while (*end) {
                        if (*end == ',')
                                result->num_args++;
+                       ++end;
                }
        }
 
        return result;
 }
 
+MonoMethodDesc*
+mono_method_desc_from_method (MonoMethod *method)
+{
+       MonoMethodDesc *result;
+       
+       result = g_new0 (MonoMethodDesc, 1);
+       result->include_namespace = TRUE;
+       result->name = g_strdup (method->name);
+       result->klass = g_strdup (method->klass->name);
+       result->namespace = g_strdup (method->klass->name_space);
+
+       return result;
+}
+
 void
 mono_method_desc_free (MonoMethodDesc *desc)
 {
@@ -264,12 +318,8 @@ dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned cha
        if (dh->label_format)
                g_string_sprintfa (str, dh->label_format, label);
        
-       i = *ip;
-       if (*ip == 0xfe) {
-               ip++;
-               i = *ip + 256;
-       }
-       ++ip;
+       i = mono_opcode_value (&ip);
+       ip++;
        opcode = &mono_opcodes [i];
        g_string_sprintfa (str, "%-10s", mono_opcode_names [i]);
 
@@ -383,14 +433,16 @@ default_dh = {
 };
 
 char*
-mono_disasm_code_one (MonoDisHelper *dh, MonoMethod *method, const guchar *ip)
+mono_disasm_code_one (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const guchar **endp)
 {
        char *result;
        GString *res = g_string_new ("");
 
        if (!dh)
                dh = &default_dh;
-       dis_one (res, dh, method, ip);
+       ip = dis_one (res, dh, method, ip);
+       if (endp)
+               *endp = ip;
        
        result = res->str;
        g_string_free (res, FALSE);
@@ -414,3 +466,42 @@ mono_disasm_code (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const
        return result;
 }
 
+static const char*
+wrapper_type_to_str (guint32 wrapper_type)
+{
+       g_assert (wrapper_type < sizeof (wrapper_type_names) / sizeof (char*));
+
+       return wrapper_type_names [wrapper_type];
+}
+
+char *
+mono_method_full_name (MonoMethod *method, gboolean signature)
+{
+       char *res;
+       char wrapper [64];
+       char *nspace;
+
+       nspace = method->klass->name_space;
+
+       if (signature) {
+               char *tmpsig = mono_signature_get_desc (method->signature, TRUE);
+
+               if (method->wrapper_type != MONO_WRAPPER_NONE)
+                       sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
+               else
+                       strcpy (wrapper, "");
+               res = g_strdup_printf ("%s%s%s%s:%s (%s)", wrapper, 
+                                                          nspace, *nspace ? "." : "",
+                                                          method->klass->name, method->name, tmpsig);
+               g_free (tmpsig);
+       } else {
+
+               res = g_strdup_printf ("%02d %s%s%s:%s", method->wrapper_type,
+                                                          nspace, *nspace ? "." : "",
+                                                          method->klass->name, method->name);
+       }
+
+       return res;
+}
+
+