Author: martin
Date: 2007-06-25 04:53:05 -0400 (Mon, 25 Jun 2007)
New Revision: 80672

Modified:
   trunk/mono/mono/mini/ChangeLog
   trunk/mono/mono/mini/debug-debugger.c
   trunk/mono/mono/mini/debug-debugger.h
   trunk/mono/mono/mini/debug-mini.c
   trunk/mono/mono/mini/debug-mini.h
Log:
2007-06-25  Martin Baulig  <[EMAIL PROTECTED]>

        Merged the `debugger-dublin' branch.

        * debug-mini.c
        (mono_debugger_insert_method_breakpoint): New public method.
        (mono_debugger_remove_method_breakpoint): Likewise.
        (mono_debugger_check_breakpoints): New static method.
        (mono_debug_close_method): Call mono_debugger_check_breakpoints().

        * debug-debugger.h (MonoDebuggerInfo):
        Renamed (to keep backward compatibility in the vtable):
        `insert_breakpoint' -> `old_insert_breakpoint'.
        `remove_breakpoint' -> `old_remove_breakpoint'.
        `create_string' -> `old_create_string'.
        `lookup_class' -> `old_lookup_class'.
        `lookup_type' -> removed; changed into a dummy field.
        `lookup_assembly' -> `old_lookup_assembly'.
        Added (same functionality, but different signature):
        `create_string', `lookup_class', `lookup_assembly'
        Added new:
        `get_method_addr_or_bpt', `remove_method_breakpoint',
        `runtime_class_init'.

        * debug-debugger.c: Merged the `debugger-dublin' branch.



Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog      2007-06-25 06:44:32 UTC (rev 80671)
+++ trunk/mono/mono/mini/ChangeLog      2007-06-25 08:53:05 UTC (rev 80672)
@@ -1,3 +1,29 @@
+2007-06-25  Martin Baulig  <[EMAIL PROTECTED]>
+
+       Merged the `debugger-dublin' branch.
+
+       * debug-mini.c
+       (mono_debugger_insert_method_breakpoint): New public method.
+       (mono_debugger_remove_method_breakpoint): Likewise.
+       (mono_debugger_check_breakpoints): New static method.
+       (mono_debug_close_method): Call mono_debugger_check_breakpoints().
+
+       * debug-debugger.h (MonoDebuggerInfo):
+       Renamed (to keep backward compatibility in the vtable):
+       `insert_breakpoint' -> `old_insert_breakpoint'.
+       `remove_breakpoint' -> `old_remove_breakpoint'.
+       `create_string' -> `old_create_string'.
+       `lookup_class' -> `old_lookup_class'.
+       `lookup_type' -> removed; changed into a dummy field.
+       `lookup_assembly' -> `old_lookup_assembly'.
+       Added (same functionality, but different signature):
+       `create_string', `lookup_class', `lookup_assembly'
+       Added new:
+       `get_method_addr_or_bpt', `remove_method_breakpoint',
+       `runtime_class_init'.
+
+       * debug-debugger.c: Merged the `debugger-dublin' branch.
+
 2007-06-23  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * mini-amd64.c (peephole_pass_1): Optimize away moves at the beginning 
of the bb as

Modified: trunk/mono/mono/mini/debug-debugger.c
===================================================================
--- trunk/mono/mono/mini/debug-debugger.c       2007-06-25 06:44:32 UTC (rev 
80671)
+++ trunk/mono/mono/mini/debug-debugger.c       2007-06-25 08:53:05 UTC (rev 
80672)
@@ -6,6 +6,7 @@
 #include <mono/metadata/mono-config.h>
 #define _IN_THE_MONO_DEBUGGER
 #include "debug-debugger.h"
+#include "debug-mini.h"
 #include <libgc/include/libgc-mono-debugger.h>
 #include "mini.h"
 #include <unistd.h>
@@ -25,22 +26,33 @@
 #error "Some clown #defined MONO_DEBUGGER_SUPPORTED without USE_INCLUDED_GC - 
fix configure.in!"
 #endif
 
-static guint64 debugger_insert_breakpoint (guint64 method_argument, const 
gchar *string_argument);
-static guint64 debugger_remove_breakpoint (guint64 breakpoint);
+static guint64 old_debugger_insert_breakpoint (guint64 method_arg, const gchar 
*string_arg);
+static guint64 old_debugger_remove_breakpoint (guint64 breakpoint);
 static guint64 debugger_compile_method (guint64 method_arg);
 static guint64 debugger_get_virtual_method (guint64 class_arg, guint64 
method_arg);
 static guint64 debugger_get_boxed_object (guint64 klass_arg, guint64 val_arg);
-static guint64 debugger_create_string (guint64 dummy_argument, const gchar 
*string_argument);
+static guint64 old_debugger_create_string (G_GNUC_UNUSED guint64 dummy, const 
gchar *string_arg);
 static guint64 debugger_class_get_static_field_data (guint64 klass);
-static guint64 debugger_lookup_class (guint64 image_argument, guint64 
token_arg);
-static guint64 debugger_lookup_type (guint64 dummy_argument, const gchar 
*string_argument);
-static guint64 debugger_lookup_assembly (guint64 dummy_argument, const gchar 
*string_argument);
+
+static guint64 old_debugger_lookup_class (guint64 image_argument, guint64 
token_arg);
+static guint64 old_debugger_lookup_assembly (G_GNUC_UNUSED guint64 dummy, 
const gchar *string_arg);
+
 static guint64 debugger_run_finally (guint64 argument1, guint64 argument2);
 static guint64 debugger_get_current_thread (void);
 static void debugger_attach (void);
 static void debugger_detach (void);
 static void debugger_initialize (void);
 
+static guint64 debugger_create_string (G_GNUC_UNUSED guint64 dummy, 
G_GNUC_UNUSED guint64 dummy2,
+                                      const gchar *string_argument);
+static gint64 debugger_lookup_class (guint64 image_argument, G_GNUC_UNUSED 
guint64 dummy,
+                                    gchar *full_name);
+static guint64 debugger_lookup_assembly (G_GNUC_UNUSED guint64 dummy, 
G_GNUC_UNUSED guint64 dummy2,
+                                        const gchar *string_argument);
+static gint64 debugger_get_method_addr_or_bpt (guint64 method_argument, 
guint64 index);
+static void debugger_remove_method_breakpoint (G_GNUC_UNUSED guint64 dummy, 
guint64 index);
+static void debugger_runtime_class_init (guint64 klass_arg);
+
 static void (*mono_debugger_notification_function) (guint64 command, guint64 
data, guint64 data2);
 
 static MonoDebuggerMetadataInfo debugger_metadata_info = {
@@ -105,24 +117,31 @@
        &debugger_compile_method,
        &debugger_get_virtual_method,
        &debugger_get_boxed_object,
-       &debugger_insert_breakpoint,
-       &debugger_remove_breakpoint,
+       &old_debugger_insert_breakpoint,
+       &old_debugger_remove_breakpoint,
        &mono_debugger_runtime_invoke,
-       &debugger_create_string,
+       &old_debugger_create_string,
        &debugger_class_get_static_field_data,
-       &debugger_lookup_class,
-       &debugger_lookup_type,
-       &debugger_lookup_assembly,
+       &old_debugger_lookup_class,
+       0,
+       &old_debugger_lookup_assembly,
        &debugger_run_finally,
        &debugger_get_current_thread,
        &debugger_attach,
        &debugger_detach,
        &debugger_initialize,
-       (void*)&mono_get_lmf_addr
+       (void*)&mono_get_lmf_addr,
+
+       &debugger_create_string,
+       &debugger_lookup_class,
+       &debugger_lookup_assembly,
+       &debugger_get_method_addr_or_bpt,
+       &debugger_remove_method_breakpoint,
+       &debugger_runtime_class_init
 };
 
 static guint64
-debugger_insert_breakpoint (guint64 method_argument, const gchar 
*string_argument)
+old_debugger_insert_breakpoint (guint64 method_argument, const gchar 
*string_argument)
 {
        MonoMethodDesc *desc;
 
@@ -134,35 +153,28 @@
 }
 
 static guint64
-debugger_remove_breakpoint (guint64 breakpoint)
+old_debugger_remove_breakpoint (guint64 breakpoint)
 {
        return mono_debugger_remove_breakpoint (breakpoint);
 }
 
-static gpointer
-debugger_compile_method_cb (MonoMethod *method)
+static guint64
+debugger_compile_method (guint64 method_arg)
 {
-       gpointer retval;
+       MonoMethod *method = (MonoMethod *) GUINT_TO_POINTER ((gsize) 
method_arg);
+       gpointer addr;
 
        mono_debugger_lock ();
-       retval = mono_compile_method (method);
+       addr = mono_compile_method (method);
        mono_debugger_unlock ();
 
        mono_debugger_notification_function (
-               MONO_DEBUGGER_EVENT_METHOD_COMPILED, (guint64) (gsize) retval, 
0);
+               MONO_DEBUGGER_EVENT_METHOD_COMPILED, (guint64) (gsize) addr, 0);
 
-       return retval;
+       return (guint64) (gsize) addr;
 }
 
 static guint64
-debugger_compile_method (guint64 method_arg)
-{
-       MonoMethod *method = (MonoMethod *) GUINT_TO_POINTER ((gsize) 
method_arg);
-
-       return (guint64) (gsize) debugger_compile_method_cb (method);
-}
-
-static guint64
 debugger_get_virtual_method (guint64 object_arg, guint64 method_arg)
 {
        MonoObject *object = (MonoObject *) GUINT_TO_POINTER ((gsize) 
object_arg);
@@ -192,25 +204,20 @@
 }
 
 static guint64
-debugger_create_string (guint64 dummy_argument, const gchar *string_argument)
+old_debugger_create_string (G_GNUC_UNUSED guint64 dummy, const gchar 
*string_arg)
 {
-       return (guint64) (gsize) mono_string_new_wrapper (string_argument);
+       return (guint64) (gsize) mono_string_new_wrapper (string_arg);
 }
 
 static guint64
-debugger_lookup_type (guint64 dummy_argument, const gchar *string_argument)
+debugger_create_string (G_GNUC_UNUSED guint64 dummy, G_GNUC_UNUSED guint64 
dummy2,
+                       const gchar *string_argument)
 {
-       guint64 retval;
-
-       mono_debugger_lock ();
-       // retval = mono_debugger_lookup_type (string_argument);
-       retval = -1;
-       mono_debugger_unlock ();
-       return retval;
+       return (guint64) (gsize) mono_string_new_wrapper (string_argument);
 }
 
 static guint64
-debugger_lookup_class (guint64 image_argument, guint64 token_argument)
+old_debugger_lookup_class (guint64 image_argument, guint64 token_argument)
 {
        MonoImage *image = (MonoImage *) GUINT_TO_POINTER ((gsize) 
image_argument);
        guint32 token = (guint32) token_argument;
@@ -224,18 +231,56 @@
 }
 
 static guint64
-debugger_lookup_assembly (guint64 dummy_argument, const gchar *string_argument)
+old_debugger_lookup_assembly (G_GNUC_UNUSED guint64 dummy, const gchar 
*string_arg)
 {
        gint64 retval;
 
        mono_debugger_lock ();
+       retval = mono_debugger_lookup_assembly (string_arg);
+       mono_debugger_unlock ();
+       return retval;
+}
+
+static gint64
+debugger_lookup_class (guint64 image_argument, G_GNUC_UNUSED guint64 dummy,
+                      gchar *full_name)
+{
+       MonoImage *image = (MonoImage *) GUINT_TO_POINTER ((gsize) 
image_argument);
+       gchar *name_space, *name, *pos;
+       MonoClass *klass;
+
+       pos = strrchr (full_name, '.');
+       if (pos) {
+               name_space = full_name;
+               *pos = 0;
+               name = pos + 1;
+       } else {
+               name = full_name;
+               name_space = NULL;
+       }
+
+       klass = mono_class_from_name (image, name_space ? name_space : "", 
name);
+       if (!klass)
+               return -1;
+
+       mono_class_init (klass);
+       return (gint64) (gssize) klass;
+}
+
+static guint64
+debugger_lookup_assembly (G_GNUC_UNUSED guint64 dummy, G_GNUC_UNUSED guint64 
dummy2,
+                         const gchar *string_argument)
+{
+       gint64 retval;
+
+       mono_debugger_lock ();
        retval = mono_debugger_lookup_assembly (string_argument);
        mono_debugger_unlock ();
        return retval;
 }
 
 static guint64
-debugger_run_finally (guint64 context_argument, guint64 dummy)
+debugger_run_finally (guint64 context_argument, G_GNUC_UNUSED guint64 dummy)
 {
        mono_debugger_run_finally (GUINT_TO_POINTER ((gsize)context_argument));
        return 0;
@@ -249,7 +294,62 @@
        return (guint64) (gsize) mono_vtable_get_static_field_data (vtable);
 }
 
+static gint64
+debugger_get_method_addr_or_bpt (guint64 method_argument, guint64 index)
+{
+       MonoMethod *method = GUINT_TO_POINTER ((gsize) method_argument);
+       MonoDomain *domain = mono_get_root_domain ();
+       MonoJitInfo *info;
+
+       mono_domain_lock (domain);
+
+       if (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) {
+               const char *name = method->name;
+               MonoMethod *nm = NULL;
+
+               if (method->klass->parent == 
mono_defaults.multicastdelegate_class) {
+                       if (*name == 'I' && (strcmp (name, "Invoke") == 0))
+                               nm = mono_marshal_get_delegate_invoke (method);
+                       else if (*name == 'B' && (strcmp (name, "BeginInvoke") 
== 0))
+                               nm = mono_marshal_get_delegate_begin_invoke 
(method);
+                       else if (*name == 'E' && (strcmp (name, "EndInvoke") == 
0))
+                               nm = mono_marshal_get_delegate_end_invoke 
(method);
+               }
+
+               if (!nm) {
+                       mono_domain_unlock (domain);
+                       return -1;
+               }
+
+               method = nm;
+       }
+
+       if ((info = mono_internal_hash_table_lookup (&domain->jit_code_hash, 
method))) {
+               mono_domain_unlock (domain);
+               return (gint64) (gssize) info->code_start;
+       }
+
+       mono_debugger_insert_method_breakpoint (method, index);
+       mono_domain_unlock (domain);
+       return 0;
+}
+
 static void
+debugger_remove_method_breakpoint (G_GNUC_UNUSED guint64 dummy, guint64 index)
+{
+       mono_debugger_lock ();
+       mono_debugger_remove_method_breakpoint (index);
+       mono_debugger_unlock ();
+}
+
+static void
+debugger_runtime_class_init (guint64 klass_arg)
+{
+       MonoClass *klass = (MonoClass *) GUINT_TO_POINTER ((gsize) klass_arg);
+       mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
+}
+
+static void
 debugger_event_handler (MonoDebuggerEvent event, guint64 data, guint64 arg)
 {
        mono_debugger_notification_function (event, data, arg);

Modified: trunk/mono/mono/mini/debug-debugger.h
===================================================================
--- trunk/mono/mono/mini/debug-debugger.h       2007-06-25 06:44:32 UTC (rev 
80671)
+++ trunk/mono/mono/mini/debug-debugger.h       2007-06-25 08:53:05 UTC (rev 
80672)
@@ -39,20 +39,30 @@
        guint64 (*compile_method) (guint64 method_argument);
        guint64 (*get_virtual_method) (guint64 object_argument, guint64 
method_argument);
        guint64 (*get_boxed_object_method) (guint64 klass_argument, guint64 
val_argument);
-       guint64 (*insert_breakpoint) (guint64 method_argument, const gchar 
*string_argument);
-       guint64 (*remove_breakpoint) (guint64 breakpoint);
+       guint64 (*old_insert_breakpoint) (guint64 method_arg, const gchar 
*string_arg);
+       guint64 (*old_remove_breakpoint) (guint64 breakpoint);
        MonoInvokeFunc runtime_invoke;
-       guint64 (*create_string) (guint64 dummy_argument, const gchar 
*string_argument);
+       guint64 (*old_create_string) (G_GNUC_UNUSED guint64 dummy, const gchar 
*string_arg);
        guint64 (*class_get_static_field_data) (guint64 klass);
-       guint64 (*lookup_class) (guint64 image_argument, guint64 token_arg);
-       guint64 (*lookup_type) (guint64 dummy_argument, const gchar 
*string_argument);
-       guint64 (*lookup_assembly) (guint64 dummy_argument, const gchar 
*string_argument);
+       guint64 (*old_lookup_class) (guint64 image_argument, guint64 token_arg);
+       guint64 obsolete_dummy1;  /* `lookup_type' was already unused in 0.50 
"Dublin". */
+       guint64 (*old_lookup_assembly) (guint64 dummy_argument, const gchar 
*string_argument);
        guint64 (*run_finally) (guint64 argument1, guint64 argument2);
        guint64 (*get_current_thread) (void);
        void (*attach) (void);
        void (*detach) (void);
        void (*initialize) (void);
        void * (*get_lmf_addr) (void);
+
+       guint64 (*create_string) (G_GNUC_UNUSED guint64 dummy1, G_GNUC_UNUSED 
guint64 dummy2,
+                                 const gchar *string_argument);
+       gint64 (*lookup_class) (guint64 image_argument, G_GNUC_UNUSED guint64 
dummy,
+                               gchar *full_name);
+       guint64 (*lookup_assembly) (G_GNUC_UNUSED guint64 dummy, G_GNUC_UNUSED 
guint64 dummy2,
+                                   const gchar *string_argument);
+       gint64 (*get_method_addr_or_bpt) (guint64 method_argument, guint64 
index);
+       void (*remove_method_breakpoint) (G_GNUC_UNUSED guint64 dummy, guint64 
index);
+       void (*runtime_class_init) (guint64 klass_arg);
 };
 
 struct _MonoDebuggerMetadataInfo {

Modified: trunk/mono/mono/mini/debug-mini.c
===================================================================
--- trunk/mono/mono/mini/debug-mini.c   2007-06-25 06:44:32 UTC (rev 80671)
+++ trunk/mono/mono/mini/debug-mini.c   2007-06-25 08:53:05 UTC (rev 80672)
@@ -28,12 +28,21 @@
 
 typedef struct
 {
+       guint64 index;
+       MonoMethod *method;
+} MiniDebugMethodBreakpointInfo;
+
+typedef struct
+{
        MonoDebugMethodJitInfo *jit;
        GArray *line_numbers;
        guint32 has_line_numbers;
        guint32 breakpoint_id;
 } MiniDebugMethodInfo;
 
+static void
+mono_debugger_check_breakpoints (MonoMethod *method, gconstpointer address);
+
 static inline void
 record_line_number (MiniDebugMethodInfo *info, guint32 address, guint32 offset)
 {
@@ -250,6 +259,8 @@
        if (info->breakpoint_id)
                mono_debugger_breakpoint_callback (method, info->breakpoint_id);
 
+       mono_debugger_check_breakpoints (method, jit->code_start);
+
        mono_debug_free_method_jit_info (jit);
        g_array_free (info->line_numbers, TRUE);
        g_free (info);
@@ -628,6 +639,7 @@
        }
 }
 
+
 /*
  * Debugger breakpoint interface.
  *
@@ -636,6 +648,80 @@
  * breakpoint when the method is JITed.
  */
 
+static GPtrArray *method_breakpoints = NULL;
+
+void
+mono_debugger_insert_method_breakpoint (MonoMethod *method, guint64 index)
+{
+       MiniDebugMethodBreakpointInfo *info;
+
+       info = g_new0 (MiniDebugMethodBreakpointInfo, 1);
+       info->method = method;
+       info->index = index;
+
+       if (!method_breakpoints)
+               method_breakpoints = g_ptr_array_new ();
+
+       g_ptr_array_add (method_breakpoints, info);
+}
+
+int
+mono_debugger_remove_method_breakpoint (guint64 index)
+{
+       int i;
+
+       if (!method_breakpoints)
+               return 0;
+
+       for (i = 0; i < method_breakpoints->len; i++) {
+               MiniDebugMethodBreakpointInfo *info = g_ptr_array_index 
(method_breakpoints, i);
+
+               if (info->index != index)
+                       continue;
+
+               g_ptr_array_remove (method_breakpoints, info);
+               g_free (info);
+               return 1;
+       }
+
+       return 0;
+}
+
+static void
+mono_debugger_check_breakpoints (MonoMethod *method, gconstpointer address)
+{
+       gboolean first = TRUE;
+       int i;
+
+       if (!method_breakpoints)
+               return;
+
+       for (i = 0; i < method_breakpoints->len; i++) {
+               MiniDebugMethodBreakpointInfo *info = g_ptr_array_index 
(method_breakpoints, i);
+
+               if (method != info->method)
+                       continue;
+
+               if (first) {
+                       mono_debugger_event (
+                               MONO_DEBUGGER_EVENT_METHOD_COMPILED, (guint64) 
(gsize) method,
+                               (guint64) (gsize) address);
+                       first = FALSE;
+               }
+
+               mono_debugger_event (MONO_DEBUGGER_EVENT_JIT_BREAKPOINT,
+                                    (guint64) (gsize) address, info->index);
+       }
+}
+
+/*
+ * The old Debugger breakpoint interface.
+ *
+ * This interface is used to insert breakpoints on methods which are not yet 
JITed.
+ * The debugging code keeps a list of all such breakpoints and automatically 
inserts the
+ * breakpoint when the method is JITed.
+ */
+
 static GPtrArray *breakpoints = NULL;
 
 int

Modified: trunk/mono/mono/mini/debug-mini.h
===================================================================
--- trunk/mono/mono/mini/debug-mini.h   2007-06-25 06:44:32 UTC (rev 80671)
+++ trunk/mono/mono/mini/debug-mini.h   2007-06-25 08:53:05 UTC (rev 80672)
@@ -4,6 +4,15 @@
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/mono-debug-debugger.h>
 
+void            mono_debugger_insert_method_breakpoint    (MonoMethod *method, 
guint64 idx);
+int             mono_debugger_remove_method_breakpoint    (guint64 index);
+
+/*
+ * This is the old breakpoint interface.
+ * It isn't used by the debugger anymore, but still when using the `--break' 
command
+ * line argument.
+ */
+
 int             mono_debugger_insert_breakpoint_full      (MonoMethodDesc 
*desc);
 int             mono_debugger_remove_breakpoint           (int breakpoint_id);
 void            mono_debugger_breakpoint_callback         (MonoMethod *method, 
guint32 idx);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to