Mon Mar 25 13:04:56 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / debug-symfile.c
index a296d0dc904ca9f50894c1b6f132158f5ff02792..8556d970a717c98e1b3df751db1dc74fbad57871 100644 (file)
@@ -3,6 +3,8 @@
 #include <string.h>
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/rawbuffer.h>
+#include <mono/metadata/appdomain.h>
+#include <mono/metadata/exception.h>
 #include <mono/metadata/debug-symfile.h>
 
 #include <fcntl.h>
@@ -20,6 +22,8 @@
 #define MRT_method_end_address         0x04
 #define MRT_local_variable             0x05
 #define MRT_method_parameter           0x06
+#define MRT_type_sizeof                        0x07
+#define MRT_type_field_offset          0x08
 
 #define MRS_debug_info                 0x01
 #define MRS_debug_abbrev               0x02
@@ -253,7 +257,9 @@ mono_debug_update_symbol_file (MonoDebugSymbolFile *symfile,
                                continue;
                        }
 
+#if 0
                        g_message ("Start of `%s' relocated to %p", minfo->method->name, minfo->code_start);
+#endif
 
                        * (void **) base_ptr = minfo->code_start;
 
@@ -299,9 +305,11 @@ mono_debug_update_symbol_file (MonoDebugSymbolFile *symfile,
                                }
                        }
 
+#if 0
                        g_message ("Relocating IL offset %d in `%s' to %d (%p)",
                                   original, minfo->method->name, address,
                                   minfo->code_start + address);
+#endif
 
                        * (void **) base_ptr = minfo->code_start + address;
 
@@ -330,8 +338,10 @@ mono_debug_update_symbol_file (MonoDebugSymbolFile *symfile,
 
                        address = minfo->local_offsets [original];
 
+#if 0
                        g_message ("Relocating local variable %d (%s) to stack offset %d",
                                   original, minfo->method->name, address);
+#endif
 
                        * (gint32 *) base_ptr = address;
 
@@ -360,13 +370,48 @@ mono_debug_update_symbol_file (MonoDebugSymbolFile *symfile,
 
                        address = minfo->param_offsets [original];
 
+#if 0
                        g_message ("Relocating parameter %d (%s) to stack offset %d",
                                   original, minfo->method->name, address);
+#endif
 
                        * (gint32 *) base_ptr = address;
 
                        break;
                }
+               case MRT_type_sizeof: {
+                       guint32 token = *((guint32 *) tmp_ptr)++;
+                       MonoClass *klass = mono_class_get (symfile->image, token);
+
+                       g_message ("Setting size of type %u to %d", token, klass->instance_size);
+
+                       * (gint8 *) base_ptr = klass->instance_size;
+
+                       break;
+               }
+               case MRT_type_field_offset: {
+                       guint32 token = *((guint32 *) tmp_ptr)++;
+                       guint32 original = *((guint32 *) tmp_ptr)++;
+                       MonoClass *klass = mono_class_get (symfile->image, token);
+                       guint32 offset;
+
+                       if (original > klass->field.count) {
+                               g_warning ("Symbol file %s contains invalid field offset entry.",
+                                          symfile->file_name);
+                               continue;
+                       }
+
+                       offset = klass->fields [original].offset;
+                       if (klass->byval_arg.type == MONO_TYPE_VALUETYPE)
+                               offset -= sizeof (MonoObject);
+
+                       g_message ("Setting field %d of type %u to offset %d", original,
+                                  token, offset);
+
+                       * (guint32 *) base_ptr = offset;
+
+                       break;
+               }
                default:
                        g_warning ("Symbol file %s contains unknown relocation entry %d",
                                   symfile->file_name, type);
@@ -376,3 +421,61 @@ mono_debug_update_symbol_file (MonoDebugSymbolFile *symfile,
 
        mono_raw_buffer_update (symfile->raw_contents, symfile->raw_contents_size);
 }
+
+MonoReflectionType *
+ves_icall_Debugger_MonoSymbolWriter_get_local_type_from_sig (MonoReflectionAssembly *assembly,
+                                                            MonoArray *signature)
+{
+       MonoDomain *domain; 
+       MonoImage *image;
+       MonoClass *klass;
+       MonoType *type;
+       const char *ptr;
+       int len = 0;
+
+       MONO_CHECK_ARG_NULL (assembly);
+       MONO_CHECK_ARG_NULL (signature);
+
+       domain = mono_domain_get();
+       image = assembly->assembly->image;
+
+       ptr = mono_array_addr (signature, char, 0);
+       g_assert (*ptr++ == 0x07);
+       len = mono_metadata_decode_value (ptr, &ptr);
+       g_assert (len == 1);
+
+       type = mono_metadata_parse_type (image, MONO_PARSE_LOCAL, 0, ptr, &ptr);
+
+       klass = mono_class_from_mono_type (type);
+
+       mono_class_init (klass);
+
+       return mono_type_get_object (domain, type);
+}
+
+MonoReflectionMethod *
+ves_icall_Debugger_MonoSymbolWriter_method_from_token (MonoReflectionAssembly *assembly, guint32 token)
+{
+       MonoDomain *domain; 
+       MonoImage *image;
+       MonoMethod *method;
+
+       MONO_CHECK_ARG_NULL (assembly);
+
+       domain = mono_domain_get();
+       image = assembly->assembly->image;
+
+       method = mono_get_method (image, token, NULL);
+
+       return mono_method_get_object (domain, method);
+}
+
+guint32
+ves_icall_Debugger_DwarfFileWriter_get_type_token (MonoReflectionType *type)
+{
+    MonoClass *klass = mono_class_from_mono_type (type->type);
+
+    mono_class_init (klass);
+
+    return klass->type_token;
+}