2002-10-01 Martin Baulig <martin@gnome.org>
[mono.git] / mono / jit / debug.h
1 #ifndef __MONO_JIT_DEBUG_H__
2 #define __MONO_JIT_DEBUG_H__
3
4 #include <glib.h>
5 #include <stdio.h>
6 #include <mono/metadata/debug-helpers.h>
7 #include <mono/metadata/debug-mono-symfile.h>
8 #include <mono/metadata/loader.h>
9 #include <mono/jit/jit.h>
10
11 typedef struct _MonoDebugHandle                 MonoDebugHandle;
12 typedef struct _MonoDebuggerInfo                MonoDebuggerInfo;
13 typedef struct _MonoDebuggerSymbolFileTable     MonoDebuggerSymbolFileTable;
14 typedef struct _MonoDebuggerBreakpointInfo      MonoDebuggerBreakpointInfo;
15
16 typedef enum {
17         MONO_DEBUG_FORMAT_NONE,
18         MONO_DEBUG_FORMAT_STABS,
19         MONO_DEBUG_FORMAT_DWARF2,
20         MONO_DEBUG_FORMAT_MONO
21 } MonoDebugFormat;
22
23 extern MonoDebugFormat mono_debug_format;
24
25 /*
26  * This variable is intended to be set in a debugger.
27  *
28  * If it's non-zero, arch_compile_method() will insert a breakpoint next time
29  * it compiles a method.
30  *
31  * If it's positive, it acts as a counter which is decremented each time it's
32  * used. Set it to a negative value to make arch_compile_method() insert a
33  * breakpoint for each method.
34  *
35  * To use this, you should create a GDB macro like this:
36  *
37  *    define enter
38  *      set mono_debug_insert_breakpoint = 1
39  *      continue
40  *      set *mono_debug_last_breakpoint_address = 0x90
41  *      reload-symbol-files
42  *      frame
43  *    end
44  *
45  *    define reload-symbol-files
46  *      call mono_debug_make_symbols ()
47  *      add-symbol-file Test-debug.o
48  *      add-symbol-file /tmp/corlib.o
49  *    end
50  *
51  */
52 extern int mono_debug_insert_breakpoint;
53
54 MonoDebugHandle* mono_debug_open (MonoAssembly *assembly, MonoDebugFormat format, const char **args);
55
56 void           mono_debug_cleanup (void);
57
58 void           mono_debug_add_method (MonoFlowGraph *cfg);
59
60 void           mono_debug_add_type (MonoClass *klass);
61
62 gchar *        mono_debug_source_location_from_address (MonoMethod *method, guint32 address,
63                                                         guint32 *line_number);
64
65 gint32         mono_debug_il_offset_from_address (MonoMethod *method, gint32 address);
66
67 gint32         mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset);
68
69 int            mono_method_has_breakpoint (MonoMethod* method, gboolean use_trampoline);
70
71 int            mono_insert_breakpoint (const gchar *method_name, gboolean include_namespace);
72
73 int            mono_insert_breakpoint_full (MonoMethodDesc *desc, gboolean use_trampoline);
74
75 int            mono_remove_breakpoint (int breakpint_id);
76
77 /* DEBUGGER PUBLIC FUNCTION:
78  *
79  * This is a public function which is supposed to be called from within a debugger
80  * each time the program stops. It's used to recreate the symbol file to tell the
81  * debugger about method addresses and such things. After calling this function,
82  * you must tell your debugger to reload its symbol file.
83  */
84 void           mono_debug_make_symbols (void);
85
86 void           mono_debug_write_symbols (MonoDebugHandle* debug);
87
88 /*
89  * Address of the x86 trampoline code.  This is used by the debugger to check
90  * whether a method is a trampoline.
91  */
92 extern guint8 *mono_generic_trampoline_code;
93
94 /*
95  * Address of a special breakpoint code which is used by the debugger to get a breakpoint
96  * after compiling a method.
97  */
98 extern guint8 *mono_breakpoint_trampoline_code;
99
100 /*
101  * There's a global data symbol called `MONO_DEBUGGER__debugger_info' which
102  * contains pointers to global variables and functions which must be accessed
103  * by the debugger.
104  */
105 struct _MonoDebuggerInfo {
106         guint64 magic;
107         guint32 version;
108         guint32 total_size;
109         guint8 **generic_trampoline_code;
110         guint8 **breakpoint_trampoline_code;
111         guint32 *symbol_file_generation;
112         MonoDebuggerSymbolFileTable **symbol_file_table;
113         int (*update_symbol_file_table) (void);
114         gpointer (*compile_method) (MonoMethod *method);
115         guint64 (*insert_breakpoint) (guint64 method_argument, const gchar *string_argument);
116         guint64 (*remove_breakpoint) (guint64 breakpoint);
117         MonoInvokeFunc runtime_invoke;
118 };
119
120 struct _MonoDebuggerSymbolFileTable {
121         guint64 magic;
122         guint32 version;
123         guint32 total_size;
124         guint32 count;
125         guint32 generation;
126         MonoSymbolFile *symfiles [MONO_ZERO_LEN_ARRAY];
127 };
128
129 struct _MonoDebuggerBreakpointInfo {
130         guint32 index;
131         gboolean use_trampoline;
132         MonoMethodDesc *desc;
133 };
134
135 #endif /* __MONO_JIT_DEBUG_H__ */