2002-03-17 Martin Baulig <martin@gnome.org>
authorMartin Baulig <martin@novell.com>
Sat, 16 Mar 2002 19:19:35 +0000 (19:19 -0000)
committerMartin Baulig <martin@novell.com>
Sat, 16 Mar 2002 19:19:35 +0000 (19:19 -0000)
* debug.c (mono_debug_get_type): Recursively call this for all function members
of a class type.
(mono_debug_add_method): Don't mangle function names, this must be done by the
debugger backend if the debugging format needs mangled names.

* debug-dwarf2.c: Improved support for classes, added member functions.

svn path=/trunk/mono/; revision=3153

mono/jit/ChangeLog
mono/jit/debug-dwarf2.c
mono/jit/debug.c

index 4c72edf89c7877639bba3bfa73dab435f07e0d92..03ed51005ef083781c0f22b0d665a2c2485574a4 100644 (file)
@@ -1,3 +1,12 @@
+2002-03-17  Martin Baulig  <martin@gnome.org>
+
+       * debug.c (mono_debug_get_type): Recursively call this for all function members
+       of a class type.
+       (mono_debug_add_method): Don't mangle function names, this must be done by the
+       debugger backend if the debugging format needs mangled names.
+
+       * debug-dwarf2.c: Improved support for classes, added member functions.
+
 2002-03-16  Martin Baulig  <martin@gnome.org>
 
        * debug.c (mono_debug_get_type): Recursively call this for all members and
index 5707c06032c9d70439331776760bf34370af2b42..b24dd74255e4b7ff9a71e320230af9d497c44919 100644 (file)
@@ -25,6 +25,9 @@
 #define ABBREV_CLASS_TYPE              15
 #define ABBREV_CLASS_INHERITANCE       16
 #define ABBREV_POINTER_TYPE            17
+#define ABBREV_CLASS_METHOD            18
+#define ABBREV_CLASS_METHOD_RETVAL     19
+#define ABBREV_ARTIFICIAL_PARAMETER    20
 
 // The following constants are defined in the DWARF 2 specification
 #define DW_TAG_class_type              0x02
 #define DW_AT_producer                 0x25
 #define DW_AT_start_scope              0x2c
 #define DW_AT_accessibility            0x32
+#define DW_AT_artificial               0x34
 #define DW_AT_calling_convention       0x36
 #define DW_AT_data_member_location     0x38
 #define DW_AT_encoding                 0x3e
 #define DW_AT_external                 0x3f
 #define DW_AT_type                     0x49
+#define DW_AT_virtuality               0x4c
+#define DW_AT_vtable_elem_location     0x4d
 
 #define DW_FORM_addr                   0x01
 #define DW_FORM_block4                 0x04
 #define DW_ACCESS_protected            2
 #define DW_ACCESS_private              3
 
+#define DW_VIRTUALITY_none             0
+#define DW_VIRTUALITY_virtual          1
+#define DW_VIRTUALITY_pure_virtual     2
+
 #define DW_LANG_C_plus_plus            0x04
 #define DW_LANG_Java                   0x0b
 // This is NOT in the standard, we're using Java for the moment. */
@@ -404,6 +414,73 @@ dwarf2_write_class_field (AssemblyDebugInfo *info, MonoClass *klass, int index,
     dwarf2_write_long (info->f, subclass->instance_size);
 }
 
+static void
+dwarf2_write_class_method (AssemblyDebugInfo *info, MonoClass *klass, MonoMethod *method)
+{
+       MonoType *ret_type = NULL;
+       gchar **names;
+       int i;
+
+       if (method->signature->ret->type != MONO_TYPE_VOID)
+               ret_type = method->signature->ret;
+
+       // DW_TAG_subprogram
+       if (ret_type)
+               dwarf2_write_byte (info->f, ABBREV_CLASS_METHOD_RETVAL);
+       else
+               dwarf2_write_byte (info->f, ABBREV_CLASS_METHOD);
+       dwarf2_write_string (info->f, method->name);
+
+       if (method->flags & METHOD_ATTRIBUTE_PUBLIC)
+               dwarf2_write_byte (info->f, DW_ACCESS_public);
+       else if (method->flags & METHOD_ATTRIBUTE_PRIVATE)
+               dwarf2_write_byte (info->f, DW_ACCESS_private);
+       else
+               dwarf2_write_byte (info->f, DW_ACCESS_protected);
+
+       if (method->flags & METHOD_ATTRIBUTE_VIRTUAL)
+               dwarf2_write_byte (info->f, DW_VIRTUALITY_pure_virtual);
+       else
+               dwarf2_write_byte (info->f, DW_VIRTUALITY_none);
+
+       if (ret_type) {
+               MonoClass *klass = mono_class_from_mono_type (ret_type);
+               int type_index = mono_debug_get_type (info, klass);
+               dwarf2_write_type_ref (info->f, type_index);
+       }
+
+       if (method->signature->hasthis) {
+               int type_index = mono_debug_get_type (info, klass);
+
+               dwarf2_write_byte (info->f, ABBREV_ARTIFICIAL_PARAMETER);
+               dwarf2_write_string (info->f, "this");
+               dwarf2_write_type_ptr_ref (info->f, type_index);
+               dwarf2_write_byte (info->f, 1);
+       }
+
+       names = g_new (char *, method->signature->param_count);
+       mono_method_get_param_names (method, (const char **) names);
+
+       for (i = 0; i < method->signature->param_count; i++) {
+               MonoType *subtype = method->signature->params [i];
+               MonoClass *subklass = mono_class_from_mono_type (subtype);
+               int type_index = mono_debug_get_type (info, subklass);
+
+               // DW_TAG_formal_parameter
+               dwarf2_write_byte (info->f, ABBREV_FORMAL_PARAMETER);
+               dwarf2_write_string (info->f, names [i]);
+               if (subklass->valuetype)
+                       dwarf2_write_type_ref (info->f, type_index);
+               else
+                       dwarf2_write_type_ptr_ref (info->f, type_index);
+       }
+
+       g_free (names);
+
+       dwarf2_write_byte (info->f, 0);
+       // DW_TAG_subprogram ends here
+}
+
 static void
 dwarf2_write_struct_type (AssemblyDebugInfo *info, MonoClass *klass)
 {
@@ -466,6 +543,13 @@ dwarf2_write_class_type (AssemblyDebugInfo *info, MonoClass *klass)
        for (i = 0; i < klass->field.count; i++)
                dwarf2_write_class_field (info, klass, i, idxs [i], 0);
 
+       for (i = 0; i < klass->method.count; i++) {
+               if (!strcmp (klass->methods [i]->name, ".ctor"))
+                       continue;
+
+               dwarf2_write_class_method (info, klass, klass->methods [i]);
+       }
+
        dwarf2_write_byte (info->f, 0);
        // DW_TAG_class_type ends here
 
@@ -503,7 +587,8 @@ dwarf2_write_class (AssemblyDebugInfo *info, MonoClass *klass, int index)
        else if (klass->byval_arg.type == MONO_TYPE_CLASS)
                dwarf2_write_class_type (info, klass);
        else {
-               g_message (G_STRLOC ": %s - %s - %x", klass->name_space, klass->name, klass->flags);
+               g_warning (G_STRLOC ": %s.%s - 0x%x - 0x%x", klass->name_space, klass->name,
+                          klass->byval_arg.type, klass->flags);
 
                // DW_TAG_basic_type
                dwarf2_write_byte (info->f, ABBREV_BASE_TYPE);
@@ -550,7 +635,7 @@ dwarf2_write_variable (AssemblyDebugInfo *info, DebugMethodInfo *minfo, const gc
        sprintf (start, "DT3_%ld", ++label_index);
        sprintf (end, "DT4_%ld", label_index);
                
-       // DW_TAG_format_parameter
+       // DW_TAG_formal_parameter
        dwarf2_write_byte (info->f, ABBREV_LOCAL_VARIABLE);
        dwarf2_write_string (info->f, name);
        if (klass->valuetype)
@@ -769,8 +854,6 @@ write_method_dwarf2 (AssemblyDebugInfo *info, DebugMethodInfo *minfo)
                MonoType *type = minfo->method->signature->params [i];
                MonoClass *klass = mono_class_from_mono_type (type);
 
-               g_message (G_STRLOC ": %s - %s - %d", klass->name, names [i], minfo->params [i].offset);
-
                dwarf2_write_parameter (info, minfo, names [i], minfo->params [i].offset, klass);
        }
 
@@ -849,6 +932,14 @@ mono_debug_write_assembly_dwarf2 (AssemblyDebugInfo *info)
        dwarf2_write_pair (info->f, DW_AT_type, DW_FORM_ref4);
        dwarf2_write_pair (info->f, 0, 0);
 
+       dwarf2_write_byte (info->f, ABBREV_ARTIFICIAL_PARAMETER);
+       dwarf2_write_byte (info->f, DW_TAG_formal_parameter);
+       dwarf2_write_byte (info->f, DW_CHILDREN_no);
+       dwarf2_write_pair (info->f, DW_AT_name, DW_FORM_string);
+       dwarf2_write_pair (info->f, DW_AT_type, DW_FORM_ref4);
+       dwarf2_write_pair (info->f, DW_AT_artificial, DW_FORM_data1);
+       dwarf2_write_pair (info->f, 0, 0);
+
        dwarf2_write_byte (info->f, ABBREV_PARAMETER);
        dwarf2_write_byte (info->f, DW_TAG_formal_parameter);
        dwarf2_write_byte (info->f, DW_CHILDREN_no);
@@ -940,6 +1031,23 @@ mono_debug_write_assembly_dwarf2 (AssemblyDebugInfo *info)
        dwarf2_write_pair (info->f, DW_AT_type, DW_FORM_ref4);
        dwarf2_write_pair (info->f, 0, 0);
 
+       dwarf2_write_byte (info->f, ABBREV_CLASS_METHOD);
+       dwarf2_write_byte (info->f, DW_TAG_subprogram);
+       dwarf2_write_byte (info->f, DW_CHILDREN_yes);
+       dwarf2_write_pair (info->f, DW_AT_name, DW_FORM_string);
+       dwarf2_write_pair (info->f, DW_AT_accessibility, DW_FORM_data1);
+       dwarf2_write_pair (info->f, DW_AT_virtuality, DW_FORM_data1);
+       dwarf2_write_pair (info->f, 0, 0);
+
+       dwarf2_write_byte (info->f, ABBREV_CLASS_METHOD_RETVAL);
+       dwarf2_write_byte (info->f, DW_TAG_subprogram);
+       dwarf2_write_byte (info->f, DW_CHILDREN_yes);
+       dwarf2_write_pair (info->f, DW_AT_name, DW_FORM_string);
+       dwarf2_write_pair (info->f, DW_AT_accessibility, DW_FORM_data1);
+       dwarf2_write_pair (info->f, DW_AT_virtuality, DW_FORM_data1);
+       dwarf2_write_pair (info->f, DW_AT_type, DW_FORM_ref4);
+       dwarf2_write_pair (info->f, 0, 0);
+
        dwarf2_write_label (info->f, "debug_abbrev_e");
        dwarf2_write_section_end (info->f);
 
index 6314985922f0d76ca07acb5efa0490146fc3e99f..baa8a76d843098c6a60db3fb8228a46b3c523b4d 100644 (file)
@@ -305,6 +305,26 @@ mono_debug_get_type (AssemblyDebugInfo* info, MonoClass *klass)
        case MONO_TYPE_CLASS:
                if (klass->parent)
                        mono_debug_get_type (info, klass->parent);
+
+               for (i = 0; i < klass->method.count; i++) {
+                       MonoMethod *method = klass->methods [i];
+                       MonoType *ret_type = NULL;
+                       int j;
+
+                       if (method->signature->ret->type != MONO_TYPE_VOID)
+                               ret_type = method->signature->ret;
+
+                       if (ret_type) {
+                               MonoClass *ret_klass = mono_class_from_mono_type (ret_type);
+                               mono_debug_get_type (info, ret_klass);
+                       }
+
+                       for (j = 0; j < method->signature->param_count; j++) {
+                               MonoType *sub_type = method->signature->params [j];
+                               MonoClass *sub_klass = mono_class_from_mono_type (sub_type);
+                               mono_debug_get_type (info, sub_klass);
+                       }
+               }
                // fall through
        case MONO_TYPE_VALUETYPE:
                for (i = 0; i < klass->field.count; i++) {
@@ -357,12 +377,8 @@ mono_debug_add_method (MonoDebugHandle* debug, MonoFlowGraph *cfg)
                ;
        start_line = i + 1;
 
-       /* FIXME: we should mangle the name better */
-       name = g_strdup_printf ("%s%s%s__%s_%p", klass->name_space, klass->name_space [0]? "_": "",
-                               klass->name, method->name, method);
-
-       for (i = 0; name [i]; ++i)
-               if (name [i] == '.') name [i] = '_';
+       name = g_strdup_printf ("%s%s%s.%s", klass->name_space, klass->name_space [0]? ".": "",
+                               klass->name, method->name);
 
        minfo = g_new0 (DebugMethodInfo, 1);
        minfo->name = name;