Added MonoString<->UTF-32 conversion helper functions.
[mono.git] / mono / metadata / debug-helpers.c
index 87f336b9194e5c7a483bd0deaa2104d4574efcd7..aa62ad230e5cc51e95cabfaa96f6748dcc51e4f4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * console-io.c: ConsoleDriver internal calls
+ * debug-helpers.c:
  *
  * Author:
  *     Mono Project (http://www.mono-project.com)
@@ -12,6 +12,7 @@
 #include "mono/metadata/opcodes.h"
 #include "mono/metadata/metadata-internals.h"
 #include "mono/metadata/class-internals.h"
+#include "mono/metadata/object-internals.h"
 #include "mono/metadata/mono-endian.h"
 #include "mono/metadata/debug-helpers.h"
 #include "mono/metadata/tabledefs.h"
@@ -86,6 +87,31 @@ append_class_name (GString *res, MonoClass *class, gboolean include_namespace)
        g_string_append_printf (res, "%s", class->name);
 }
 
+static MonoClass*
+find_system_class (const char *name)
+{
+       if (!strcmp (name, "void")) 
+               return mono_defaults.void_class;
+       else if (!strcmp (name, "char")) return mono_defaults.char_class;
+       else if (!strcmp (name, "bool")) return mono_defaults.boolean_class;
+       else if (!strcmp (name, "byte")) return mono_defaults.byte_class;
+       else if (!strcmp (name, "sbyte")) return mono_defaults.sbyte_class;
+       else if (!strcmp (name, "uint16")) return mono_defaults.uint16_class;
+       else if (!strcmp (name, "int16")) return mono_defaults.int16_class;
+       else if (!strcmp (name, "uint")) return mono_defaults.uint32_class;
+       else if (!strcmp (name, "int")) return mono_defaults.int32_class;
+       else if (!strcmp (name, "ulong")) return mono_defaults.uint64_class;
+       else if (!strcmp (name, "long")) return mono_defaults.int64_class;
+       else if (!strcmp (name, "uintptr")) return mono_defaults.uint_class;
+       else if (!strcmp (name, "intptr")) return mono_defaults.int_class;
+       else if (!strcmp (name, "single")) return mono_defaults.single_class;
+       else if (!strcmp (name, "double")) return mono_defaults.double_class;
+       else if (!strcmp (name, "string")) return mono_defaults.string_class;
+       else if (!strcmp (name, "object")) return mono_defaults.object_class;
+       else
+               return NULL;
+}
+
 void
 mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace)
 {
@@ -284,6 +310,9 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
        class_nspace = g_strdup (name);
        use_args = strchr (class_nspace, '(');
        if (use_args) {
+               /* Allow a ' ' between the method name and the signature */
+               if (use_args > class_nspace && use_args [-1] == ' ')
+                       use_args [-1] = 0;
                *use_args++ = 0;
                end = strchr (use_args, ')');
                if (!end) {
@@ -297,10 +326,10 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
                g_free (class_nspace);
                return NULL;
        }
-       *method_name++ = 0;
        /* allow two :: to separate the method name */
-       if (*method_name == ':')
-               method_name++;
+       if (method_name != class_nspace && method_name [-1] == ':')
+               method_name [-1] = 0;
+       *method_name++ = 0;
        class_name = strrchr (class_nspace, '.');
        if (class_name) {
                *class_name++ = 0;
@@ -439,6 +468,8 @@ match_class (MonoMethodDesc *desc, int pos, MonoClass *klass)
 gboolean
 mono_method_desc_full_match (MonoMethodDesc *desc, MonoMethod *method)
 {
+       if (!desc->klass)
+               return FALSE;
        if (!match_class (desc, strlen (desc->klass), method->klass))
                return FALSE;
 
@@ -466,6 +497,13 @@ mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
        MonoMethod *method;
        int i;
 
+       /* Handle short names for system classes */
+       if (!desc->namespace && image == mono_defaults.corlib) {
+               klass = find_system_class (desc->klass);
+               if (klass)
+                       return mono_method_desc_search_in_class (desc, klass);
+       }
+
        if (desc->namespace && desc->klass) {
                klass = mono_class_from_name (image, desc->namespace, desc->klass);
                if (!klass)
@@ -537,7 +575,7 @@ dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned cha
                size_t len2;
                char *blob2 = NULL;
 
-               if (!method->klass->image->dynamic) {
+               if (!image_is_dynamic (method->klass->image) && !method_is_dynamic (method)) {
                        token = read32 (ip);
                        blob = mono_metadata_user_string (method->klass->image, mono_metadata_token_index (token));
 
@@ -648,6 +686,7 @@ dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned cha
        if (dh->newline)
                g_string_append (str, dh->newline);
 
+       mono_metadata_free_mh (header);
        return ip;
 }
 
@@ -807,7 +846,7 @@ mono_object_describe (MonoObject *obj)
                MonoArray *array = (MonoArray*)obj;
                sep = print_name_space (klass);
                g_print ("%s%s", sep, klass->name);
-               g_print (" at %p, rank: %d, length: %d\n", obj, klass->rank, mono_array_length (array));
+               g_print (" at %p, rank: %d, length: %d\n", obj, klass->rank, (int)mono_array_length (array));
        } else {
                sep = print_name_space (klass);
                g_print ("%s%s", sep, klass->name);
@@ -966,7 +1005,7 @@ mono_class_describe_statics (MonoClass* klass)
 
        if (!vtable)
                return;
-       if (!(addr = vtable->data))
+       if (!(addr = mono_vtable_get_static_field_data (vtable)))
                return;
 
        for (p = klass; p != NULL; p = p->parent) {
@@ -983,4 +1022,3 @@ mono_class_describe_statics (MonoClass* klass)
                }
        }
 }
-