* 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
+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
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);
}
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;
+}
#include <glib.h>
#include <stdio.h>
+#include <mono/metadata/debug-symfile.h>
#include <mono/metadata/loader.h>
#include <mono/jit/jit.h>
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
#include "jit.h"
#include "codegen.h"
+#include "debug.h"
#ifdef __FreeBSD__
# define SC_EAX sc_eax
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);