[exdoc] Handle punctuation better in code formatting.
[mono.git] / mono / metadata / debug-helpers.c
index fb5aede58fc0c65506281e7504224df2d76f5fd5..e5c5c23fb74ea025a01d51bdc960321404cd2c07 100644 (file)
@@ -1,10 +1,11 @@
-/*
- * debug-helpers.c:
+/**
+ * \file
  *
  * Author:
  *     Mono Project (http://www.mono-project.com)
  *
  * Copyright (C) 2005-2008 Novell, Inc. (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <string.h>
@@ -162,7 +163,10 @@ mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace)
                break;
        case MONO_TYPE_ARRAY:
                mono_type_get_desc (res, &type->data.array->eklass->byval_arg, include_namespace);
-               g_string_append_printf (res, "[%d]", type->data.array->rank);
+               g_string_append_c (res, '[');
+               for (i = 1; i < type->data.array->rank; ++i)
+                       g_string_append_c (res, ',');
+               g_string_append_c (res, ']');
                break;
        case MONO_TYPE_SZARRAY:
                mono_type_get_desc (res, &type->data.klass->byval_arg, include_namespace);
@@ -276,8 +280,8 @@ mono_signature_full_name (MonoMethodSignature *sig)
        return result;
 }
 
-static void
-ginst_get_desc (GString *str, MonoGenericInst *ginst)
+void
+mono_ginst_get_desc (GString *str, MonoGenericInst *ginst)
 {
        int i;
 
@@ -298,11 +302,11 @@ mono_context_get_desc (MonoGenericContext *context)
        g_string_append (str, "<");
 
        if (context->class_inst)
-               ginst_get_desc (str, context->class_inst);
+               mono_ginst_get_desc (str, context->class_inst);
        if (context->method_inst) {
                if (context->class_inst)
                        g_string_append (str, "; ");
-               ginst_get_desc (str, context->method_inst);
+               mono_ginst_get_desc (str, context->method_inst);
        }
 
        g_string_append (str, ">");
@@ -313,10 +317,10 @@ mono_context_get_desc (MonoGenericContext *context)
 
 /**
  * mono_method_desc_new:
- * @name: the method name.
- * @include_namespace: whether the name includes a namespace or not.
+ * \param name the method name.
+ * \param include_namespace whether the name includes a namespace or not.
  *
- * Creates a method description for @name, which conforms to the following
+ * Creates a method description for \p name, which conforms to the following
  * specification:
  *
  * [namespace.]classname:methodname[(args...)]
@@ -325,7 +329,7 @@ mono_context_get_desc (MonoGenericContext *context)
  *
  * Both classname and methodname can contain '*' which matches anything.
  *
- * Returns: a parsed representation of the method description.
+ * \returns a parsed representation of the method description.
  */
 MonoMethodDesc*
 mono_method_desc_new (const char *name, gboolean include_namespace)
@@ -333,6 +337,7 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
        MonoMethodDesc *result;
        char *class_name, *class_nspace, *method_name, *use_args, *end;
        int use_namespace;
+       int generic_delim_stack;
        
        class_nspace = g_strdup (name);
        use_args = strchr (class_nspace, '(');
@@ -379,8 +384,14 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
                end = use_args;
                if (*end)
                        result->num_args = 1;
+               generic_delim_stack = 0;
                while (*end) {
-                       if (*end == ',')
+                       if (*end == '<')
+                               generic_delim_stack++;
+                       else if (*end == '>')
+                               generic_delim_stack--;
+
+                       if (*end == ',' && generic_delim_stack == 0)
                                result->num_args++;
                        ++end;
                }
@@ -405,9 +416,8 @@ mono_method_desc_from_method (MonoMethod *method)
 
 /**
  * mono_method_desc_free:
- * @desc: method description to be released
- *
- * Releases the MonoMethodDesc object @desc.
+ * \param desc method description to be released
+ * Releases the MonoMethodDesc object \p desc.
  */
 void
 mono_method_desc_free (MonoMethodDesc *desc)
@@ -421,13 +431,13 @@ mono_method_desc_free (MonoMethodDesc *desc)
 
 /**
  * mono_method_descr_match:
- * @desc: MonoMethoDescription
- * @method: MonoMethod to test
+ * \param desc \c MonoMethoDescription
+ * \param method \c MonoMethod to test
  *
- * Determines whether the specified @method matches the provided @desc description.
+ * Determines whether the specified \p method matches the provided \p 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.
+ * \returns TRUE if the method matches the description, FALSE otherwise.
  */
 gboolean
 mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
@@ -436,10 +446,6 @@ mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
        gboolean name_match;
 
        name_match = strcmp (desc->name, method->name) == 0;
-#ifndef _EGLIB_MAJOR
-       if (!name_match && desc->name_glob)
-               name_match = g_pattern_match_simple (desc->name, method->name);
-#endif
        if (!name_match)
                return FALSE;
        if (!desc->args)
@@ -784,9 +790,8 @@ mono_disasm_code (MonoDisHelper *dh, MonoMethod *method, const guchar *ip, const
 
 /**
  * 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.
+ * \param 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)
@@ -807,6 +812,7 @@ mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret,
        char wrapper [64];
        char *klass_desc;
        char *inst_desc = NULL;
+       MonoError error;
 
        if (format == MONO_TYPE_NAME_FORMAT_IL)
                klass_desc = mono_type_full_name (&method->klass->byval_arg);
@@ -819,7 +825,7 @@ mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret,
                        g_string_append (str, "<");
                else
                        g_string_append (str, "[");
-               ginst_get_desc (str, ((MonoMethodInflated*)method)->context.method_inst);
+               mono_ginst_get_desc (str, ((MonoMethodInflated*)method)->context.method_inst);
                if (format == MONO_TYPE_NAME_FORMAT_IL)
                        g_string_append_c (str, '>');
                else
@@ -835,7 +841,7 @@ mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret,
                        g_string_append (str, "<");
                else
                        g_string_append (str, "[");
-               ginst_get_desc (str, container->context.method_inst);
+               mono_ginst_get_desc (str, container->context.method_inst);
                if (format == MONO_TYPE_NAME_FORMAT_IL)
                        g_string_append_c (str, '>');
                else
@@ -851,14 +857,22 @@ mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret,
                strcpy (wrapper, "");
 
        if (signature) {
-               char *tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE);
+               MonoMethodSignature *sig = mono_method_signature_checked (method, &error);
+               char *tmpsig;
+
+               if (!is_ok (&error)) {
+                       tmpsig = g_strdup_printf ("<unable to load signature>");
+                       mono_error_cleanup (&error);
+               } else {
+                       tmpsig = mono_signature_get_desc (sig, TRUE);
+               }
 
                if (method->wrapper_type != MONO_WRAPPER_NONE)
                        sprintf (wrapper, "(wrapper %s) ", wrapper_type_to_str (method->wrapper_type));
                else
                        strcpy (wrapper, "");
-               if (ret) {
-                       char *ret_str = mono_type_full_name (mono_method_signature (method)->ret);
+               if (ret && sig) {
+                       char *ret_str = mono_type_full_name (sig->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);
@@ -908,12 +922,13 @@ print_name_space (MonoClass *klass)
 /**
  * mono_object_describe:
  *
- * Prints to stdout a small description of the object @obj.
+ * Prints to stdout a small description of the object \p obj.
  * For use in a debugger.
  */
 void
 mono_object_describe (MonoObject *obj)
 {
+       MonoError error;
        MonoClass* klass;
        const char* sep;
        if (!obj) {
@@ -922,14 +937,19 @@ mono_object_describe (MonoObject *obj)
        }
        klass = mono_object_class (obj);
        if (klass == mono_defaults.string_class) {
-               char *utf8 = mono_string_to_utf8 ((MonoString*)obj);
-               if (strlen (utf8) > 60) {
+               char *utf8 = mono_string_to_utf8_checked ((MonoString*)obj, &error);
+               mono_error_cleanup (&error); /* FIXME don't swallow the error */
+               if (utf8 && strlen (utf8) > 60) {
                        utf8 [57] = '.';
                        utf8 [58] = '.';
                        utf8 [59] = '.';
                        utf8 [60] = 0;
                }
-               g_print ("String at %p, length: %d, '%s'\n", obj, mono_string_length ((MonoString*) obj), utf8);
+               if (utf8) {
+                       g_print ("String at %p, length: %d, '%s'\n", obj, mono_string_length ((MonoString*) obj), utf8);
+               } else {
+                       g_print ("String at %p, length: %d, unable to decode UTF16\n", obj, mono_string_length ((MonoString*) obj));
+               }
                g_free (utf8);
        } else if (klass->rank) {
                MonoArray *array = (MonoArray*)obj;
@@ -1054,7 +1074,7 @@ objval_describe (MonoClass *klass, const char *addr)
 /**
  * mono_object_describe_fields:
  *
- * Prints to stdout a small description of each field of the object @obj.
+ * Prints to stdout a small description of each field of the object \p obj.
  * For use in a debugger.
  */
 void
@@ -1068,7 +1088,7 @@ mono_object_describe_fields (MonoObject *obj)
  * mono_value_describe_fields:
  *
  * Prints to stdout a small description of each field of the value type
- * stored at @addr of type @klass.
+ * stored at \p addr of type \p klass.
  * For use in a debugger.
  */
 void
@@ -1080,7 +1100,7 @@ mono_value_describe_fields (MonoClass* klass, const char* addr)
 /**
  * mono_class_describe_statics:
  *
- * Prints to stdout a small description of each static field of the type @klass
+ * Prints to stdout a small description of each static field of the type \p klass
  * in the current application domain.
  * For use in a debugger.
  */
@@ -1119,7 +1139,7 @@ mono_class_describe_statics (MonoClass* klass)
 
 /**
  * mono_print_method_code
- * @MonoMethod: a pointer to the method
+ * \param method: a pointer to the method
  *
  * This method is used from a debugger to print the code of the method.
  *