2002-05-21 Martin Baulig <martin@gnome.org>
authorMartin Baulig <martin@novell.com>
Tue, 21 May 2002 11:52:37 +0000 (11:52 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 21 May 2002 11:52:37 +0000 (11:52 -0000)
* debug.c (mono_debug_source_location_from_address): New function.
(mono_debug_il_offset_from_address): New function.

* exception.c (arch_handle_exception): If we have debugging support, include
information about the source location and IL offset in the stack trace.

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

mono/jit/ChangeLog
mono/jit/debug.c
mono/jit/debug.h
mono/jit/exception.c

index bcd0c9e9617794189c290594944f132c8b6063b9..811895cf51fcf32bd8f8a76a4be3a2206ff8ba74 100644 (file)
@@ -1,3 +1,11 @@
+2002-05-21  Martin Baulig  <martin@gnome.org>
+
+       * debug.c (mono_debug_source_location_from_address): New function.
+       (mono_debug_il_offset_from_address): New function.
+
+       * exception.c (arch_handle_exception): If we have debugging support, include
+       information about the source location and IL offset in the stack trace.
+
 2002-05-21  Dietmar Maurer  <dietmar@ximian.com>
 
        * x86.brg (stmt): removed unnecessary assertion
index 51cf69c821db45436ed75b98092b3a7bbab90128..760ed778bebdaa6c02ec3c34e7631dc7de8afc32 100644 (file)
@@ -229,7 +229,7 @@ record_line_number (DebugMethodInfo *minfo, gpointer address, guint32 line, int
        lni->address = address;
        lni->line = line;
        lni->is_basic_block = is_basic_block;
-       lni->source_file = 0;
+       lni->source_file = minfo->source_file;
 
        g_ptr_array_add (minfo->line_numbers, lni);
 }
@@ -665,3 +665,60 @@ mono_debug_add_method (MonoFlowGraph *cfg)
 
        g_hash_table_insert (debug->methods, method, minfo);
 }
+
+gchar *
+mono_debug_source_location_from_address (MonoMethod *method, guint32 address)
+{
+       MonoDebugHandle *debug;
+       DebugMethodInfo *minfo = NULL;
+       int i;
+
+       for (debug = mono_debug_handles; debug; debug = debug->next) {
+               minfo = g_hash_table_lookup (debug->methods, method);
+
+               if (minfo)
+                       break;
+       }
+
+       if (!minfo || !minfo->line_numbers)
+               return NULL;
+
+       for (i = 0; i < minfo->line_numbers->len; i++) {
+               DebugLineNumberInfo *lni = g_ptr_array_index (minfo->line_numbers, i);
+
+               if ((gchar *)lni->address > minfo->method_info.code_start + address) {
+                       gchar *source_file = g_ptr_array_index (debug->source_files, lni->source_file);
+
+                       return g_strdup_printf ("%s:%d", source_file, lni->line);
+               }
+       }
+
+       return NULL;
+}
+
+gint32
+mono_debug_il_offset_from_address (MonoMethod *method, guint32 address)
+{
+       MonoDebugHandle *debug;
+       MonoDebugMethodInfo *minfo = NULL;
+       int i;
+
+       for (debug = mono_debug_handles; debug; debug = debug->next) {
+               minfo = g_hash_table_lookup (debug->methods, method);
+
+               if (minfo)
+                       break;
+       }
+
+       if (!minfo || !minfo->il_offsets)
+               return -1;
+
+       for (i = 0; i < minfo->num_il_offsets; i++) {
+               MonoDebugILOffsetInfo *ilo = &minfo->il_offsets [i];
+
+               if (ilo->address > address)
+                       return ilo->offset;
+       }
+
+       return -1;
+}
index b476ad44c72a4b2d436f6b4f4bd04630f9f09904..0dd13a4fd8f494da8c72c17b429d96f46d21efbd 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <glib.h>
 #include <stdio.h>
+#include <mono/metadata/debug-symfile.h>
 #include <mono/metadata/loader.h>
 #include <mono/jit/jit.h>
 
@@ -67,6 +68,12 @@ void           mono_debug_add_method (MonoFlowGraph *cfg);
 
 void           mono_debug_add_type (MonoClass *klass);
 
+gchar *
+mono_debug_source_location_from_address (MonoMethod *method, guint32 address);
+
+gint32
+mono_debug_il_offset_from_address (MonoMethod *method, guint32 address);
+
 /* DEBUGGER PUBLIC FUNCTION:
  *
  * This is a public function which is supposed to be called from within a debugger
index e059125e7b62cd94863b9c52b833f4e64e992925..b6cd24065072685ea69f0294f9fca55a1eed2662 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "jit.h"
 #include "codegen.h"
+#include "debug.h"
 
 #ifdef __FreeBSD__
 # define SC_EAX sc_eax
@@ -171,18 +172,34 @@ arch_handle_exception (struct sigcontext *ctx, gpointer obj)
                int offset;
 
                if (mono_object_isinst (obj, mono_defaults.exception_class)) {
-                       char  *strace = mono_string_to_utf8 (((MonoException*)obj)->stack_trace);
-                       char  *tmp, *tmpsig;
+                       char    *strace = mono_string_to_utf8 (((MonoException*)obj)->stack_trace);
+                       char    *tmp, *tmpsig, *source_location, *tmpaddr;
+                       gint32   address, iloffset;
 
                        if (!strcmp (strace, "TODO: implement stack traces")){
                                g_free (strace);
                                strace = g_strdup ("");
                        }
 
+                       address = (char *)ip - (char *)ji->code_start;
+
+                       source_location = mono_debug_source_location_from_address (m, address);
+                       iloffset = mono_debug_il_offset_from_address (m, address);
+
+                       if (iloffset < 0)
+                               tmpaddr = g_strdup_printf ("<0x%05x>", address);
+                       else
+                               tmpaddr = g_strdup_printf ("[0x%05x]", iloffset);
+
                        tmpsig = mono_signature_get_desc(m->signature, TRUE);
-                       tmp = g_strdup_printf ("%sin 0x%05x %s.%s:%s (%s)\n", strace, 
-                                              (char *)ip - (char *)ji->code_start,
-                                              m->klass->name_space, m->klass->name, m->name, tmpsig);
+                       if (source_location)
+                               tmp = g_strdup_printf ("%sin %s (at %s) %s.%s:%s (%s)\n", strace, tmpaddr,
+                                                      source_location, m->klass->name_space, m->klass->name,
+                                                      m->name, tmpsig);
+                       else
+                               tmp = g_strdup_printf ("%sin %s %s.%s:%s (%s)\n", strace, tmpaddr,
+                                                      m->klass->name_space, m->klass->name, m->name, tmpsig);
+                       g_free (source_location);
                        g_free (tmpsig);
                        g_free (strace);