Merge pull request #2648 from BrzVlad/fix-cprop-vregs
[mono.git] / mono / metadata / debug-helpers.c
index ef60d033af07236171f6704ca121aae2ffb54f21..df32fb052af36efea073cd66d1d8e8f79a327a92 100644 (file)
@@ -72,21 +72,21 @@ wrapper_type_to_str (guint32 wrapper_type)
 #endif
 
 static void
-append_class_name (GString *res, MonoClass *class, gboolean include_namespace)
+append_class_name (GString *res, MonoClass *klass, gboolean include_namespace)
 {
-       if (!class) {
+       if (!klass) {
                g_string_append (res, "Unknown");
                return;
        }
-       if (class->nested_in) {
-               append_class_name (res, class->nested_in, include_namespace);
+       if (klass->nested_in) {
+               append_class_name (res, klass->nested_in, include_namespace);
                g_string_append_c (res, '/');
        }
-       if (include_namespace && *(class->name_space)) {
-               g_string_append (res, class->name_space);
+       if (include_namespace && *(klass->name_space)) {
+               g_string_append (res, klass->name_space);
                g_string_append_c (res, '.');
        }
-       g_string_append (res, class->name);
+       g_string_append (res, klass->name);
 }
 
 static MonoClass*
@@ -251,6 +251,31 @@ mono_signature_get_desc (MonoMethodSignature *sig, gboolean include_namespace)
        return result;
 }
 
+char*
+mono_signature_full_name (MonoMethodSignature *sig)
+{
+       int i;
+       char *result;
+       GString *res;
+
+       if (!sig)
+               return g_strdup ("<invalid signature>");
+
+       res = g_string_new ("");
+
+       mono_type_get_desc (res, sig->ret, TRUE);
+       g_string_append_c (res, '(');
+       for (i = 0; i < sig->param_count; ++i) {
+               if (i > 0)
+                       g_string_append_c (res, ',');
+               mono_type_get_desc (res, sig->params [i], TRUE);
+       }
+       g_string_append_c (res, ')');
+       result = res->str;
+       g_string_free (res, FALSE);
+       return result;
+}
+
 static void
 ginst_get_desc (GString *str, MonoGenericInst *ginst)
 {
@@ -394,8 +419,15 @@ mono_method_desc_free (MonoMethodDesc *desc)
        g_free (desc);
 }
 
-/*
+/**
+ * mono_method_descr_match:
+ * @desc: MonoMethoDescription
+ * @method: MonoMethod to test
+ *
+ * Determines whether the specified @method matches the provided @desc description.
+ *
  * namespace and class are supposed to match already if this function is used.
+ * Returns: True if the method matches the description, false otherwise.
  */
 gboolean
 mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
@@ -506,7 +538,7 @@ mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
        }
 
        if (desc->name_space && desc->klass) {
-               klass = mono_class_from_name (image, desc->name_space, desc->klass);
+               klass = mono_class_try_load_from_name (image, desc->name_space, desc->klass);
                if (!klass)
                        return NULL;
                return mono_method_desc_search_in_class (desc, klass);
@@ -516,12 +548,17 @@ mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
        mono_image_get_table_info (image, MONO_TABLE_TYPEDEF);
        methods = mono_image_get_table_info (image, MONO_TABLE_METHOD);
        for (i = 0; i < mono_table_info_get_rows (methods); ++i) {
+               MonoError error;
                guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME);
                const char *n = mono_metadata_string_heap (image, token);
 
                if (strcmp (n, desc->name))
                        continue;
-               method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL);
+               method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
+               if (!method) {
+                       mono_error_cleanup (&error);
+                       continue;
+               }
                if (mono_method_desc_full_match (desc, method))
                        return method;
        }
@@ -737,6 +774,12 @@ mono_disasm_code (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const
        return result;
 }
 
+/**
+ * mono_field_full_name:
+ * @field: field to retrieve information for
+ *
+ * Returns: the full name for the field, made up of the namespace, type name and the field name.
+ */
 char *
 mono_field_full_name (MonoClassField *field)
 {
@@ -750,7 +793,7 @@ mono_field_full_name (MonoClassField *field)
 }
 
 char *
-mono_method_get_name_full (MonoMethod *method, gboolean signature, MonoTypeNameFormat format)
+mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format)
 {
        char *res;
        char wrapper [64];
@@ -806,8 +849,15 @@ mono_method_get_name_full (MonoMethod *method, gboolean signature, MonoTypeNameF
                        sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
                else
                        strcpy (wrapper, "");
-               res = g_strdup_printf ("%s%s:%s%s (%s)", wrapper, klass_desc, 
-                                                          method->name, inst_desc ? inst_desc : "", tmpsig);
+               if (ret) {
+                       char *ret_str = mono_type_full_name (mono_method_signature (method)->ret);
+                       res = g_strdup_printf ("%s%s %s:%s%s (%s)", wrapper, ret_str, klass_desc,
+                                                                  method->name, inst_desc ? inst_desc : "", tmpsig);
+                       g_free (ret_str);
+               } else {
+                       res = g_strdup_printf ("%s%s:%s%s (%s)", wrapper, klass_desc,
+                                                                  method->name, inst_desc ? inst_desc : "", tmpsig);
+               }
                g_free (tmpsig);
        } else {
                res = g_strdup_printf ("%s%s:%s%s", wrapper, klass_desc,
@@ -823,7 +873,13 @@ mono_method_get_name_full (MonoMethod *method, gboolean signature, MonoTypeNameF
 char *
 mono_method_full_name (MonoMethod *method, gboolean signature)
 {
-       return mono_method_get_name_full (method, signature, MONO_TYPE_NAME_FORMAT_IL);
+       return mono_method_get_name_full (method, signature, FALSE, MONO_TYPE_NAME_FORMAT_IL);
+}
+
+char *
+mono_method_get_full_name (MonoMethod *method)
+{
+       return mono_method_get_name_full (method, TRUE, TRUE, MONO_TYPE_NAME_FORMAT_IL);
 }
 
 static const char*
@@ -956,23 +1012,24 @@ print_field_value (const char *field_ptr, MonoClassField *field, int type_offset
 }
 
 static void
-objval_describe (MonoClass *class, const char *addr)
+objval_describe (MonoClass *klass, const char *addr)
 {
        MonoClassField *field;
        MonoClass *p;
        const char *field_ptr;
        gssize type_offset = 0;
-       if (class->valuetype)
+
+       if (klass->valuetype)
                type_offset = -sizeof (MonoObject);
 
-       for (p = class; p != NULL; p = p->parent) {
+       for (p = klass; p != NULL; p = p->parent) {
                gpointer iter = NULL;
                int printed_header = FALSE;
                while ((field = mono_class_get_fields (p, &iter))) {
                        if (field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA))
                                continue;
 
-                       if (p != class && !printed_header) {
+                       if (p != klass && !printed_header) {
                                const char *sep;
                                g_print ("In class ");
                                sep = print_name_space (p);
@@ -995,8 +1052,8 @@ objval_describe (MonoClass *class, const char *addr)
 void
 mono_object_describe_fields (MonoObject *obj)
 {
-       MonoClass *class = mono_object_class (obj);
-       objval_describe (class, (char*)obj);
+       MonoClass *klass = mono_object_class (obj);
+       objval_describe (klass, (char*)obj);
 }
 
 /**
@@ -1030,7 +1087,7 @@ mono_class_describe_statics (MonoClass* klass)
 
        if (!vtable)
                return;
-       if (!(addr = mono_vtable_get_static_field_data (vtable)))
+       if (!(addr = (const char *)mono_vtable_get_static_field_data (vtable)))
                return;
 
        for (p = klass; p != NULL; p = p->parent) {
@@ -1040,9 +1097,6 @@ mono_class_describe_statics (MonoClass* klass)
                                continue;
                        if (!(field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)))
                                continue;
-                       // Special static fields don't have a domain-level static slot
-                       if (mono_class_field_is_special_static (field))
-                               continue;
 
                        field_ptr = (const char*)addr + field->offset;