2003-01-07 Dietmar Maurer <dietmar@ximian.com>
[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         /* This format may only be used when the JIT is being run by the
22          * Mono Debugger.
23          */
24         MONO_DEBUG_FORMAT_MONO_DEBUGGER
25 } MonoDebugFormat;
26
27 extern MonoDebugFormat mono_debug_format;
28
29 /*
30  * This variable is intended to be set in a debugger.
31  *
32  * If it's non-zero, arch_compile_method() will insert a breakpoint next time
33  * it compiles a method.
34  *
35  * If it's positive, it acts as a counter which is decremented each time it's
36  * used. Set it to a negative value to make arch_compile_method() insert a
37  * breakpoint for each method.
38  *
39  * To use this, you should create a GDB macro like this:
40  *
41  *    define enter
42  *      set mono_debug_insert_breakpoint = 1
43  *      continue
44  *      set *mono_debug_last_breakpoint_address = 0x90
45  *      reload-symbol-files
46  *      frame
47  *    end
48  *
49  *    define reload-symbol-files
50  *      call mono_debug_make_symbols ()
51  *      add-symbol-file Test-debug.o
52  *      add-symbol-file /tmp/corlib.o
53  *    end
54  *
55  */
56 extern int mono_debug_insert_breakpoint;
57
58 MonoDebugHandle* mono_debug_open (MonoAssembly *assembly, MonoDebugFormat format, const char **args);
59
60 void           mono_debug_cleanup (void);
61
62 void           mono_debug_add_method (MonoFlowGraph *cfg);
63
64 void           mono_debug_add_type (MonoClass *klass);
65
66 gchar *        mono_debug_source_location_from_address (MonoMethod *method, guint32 address,
67                                                         guint32 *line_number);
68
69 gint32         mono_debug_il_offset_from_address (MonoMethod *method, gint32 address);
70
71 gint32         mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset);
72
73 int            mono_method_has_breakpoint (MonoMethod* method, gboolean use_trampoline);
74
75 int            mono_insert_breakpoint (const gchar *method_name, gboolean include_namespace);
76
77 int            mono_insert_breakpoint_full (MonoMethodDesc *desc, gboolean use_trampoline);
78
79 int            mono_remove_breakpoint (int breakpint_id);
80
81 void           mono_debugger_trampoline_breakpoint_callback (void);
82
83 int            mono_debugger_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]);
84
85
86 /* DEBUGGER PUBLIC FUNCTION:
87  *
88  * This is a public function which is supposed to be called from within a debugger
89  * each time the program stops. It's used to recreate the symbol file to tell the
90  * debugger about method addresses and such things. After calling this function,
91  * you must tell your debugger to reload its symbol file.
92  */
93 void           mono_debug_make_symbols (void);
94
95 void           mono_debug_write_symbols (MonoDebugHandle* debug);
96
97 /*
98  * Address of the x86 trampoline code.  This is used by the debugger to check
99  * whether a method is a trampoline.
100  */
101 extern guint8 *mono_generic_trampoline_code;
102
103 /*
104  * Address of a special breakpoint code which is used by the debugger to get a breakpoint
105  * after compiling a method.
106  */
107 extern guint8 *mono_breakpoint_trampoline_code;
108
109 /*
110  * There's a global data symbol called `MONO_DEBUGGER__debugger_info' which
111  * contains pointers to global variables and functions which must be accessed
112  * by the debugger.
113  */
114 struct _MonoDebuggerInfo {
115         guint64 magic;
116         guint32 version;
117         guint32 total_size;
118         guint8 **generic_trampoline_code;
119         guint8 **breakpoint_trampoline_code;
120         guint32 *symbol_file_generation;
121         guint32 *symbol_file_modified;
122         gconstpointer *notification_address;
123         MonoDebuggerSymbolFileTable **symbol_file_table;
124         gpointer (*compile_method) (MonoMethod *method);
125         guint64 (*insert_breakpoint) (guint64 method_argument, const gchar *string_argument);
126         guint64 (*remove_breakpoint) (guint64 breakpoint);
127         MonoInvokeFunc runtime_invoke;
128 };
129
130 struct _MonoDebuggerSymbolFileTable {
131         guint64 magic;
132         guint32 version;
133         guint32 total_size;
134         guint32 count;
135         guint32 generation;
136         MonoGlobalSymbolFile *global_symfile;
137         MonoSymbolFile *symfiles [MONO_ZERO_LEN_ARRAY];
138 };
139
140 struct _MonoDebuggerBreakpointInfo {
141         guint32 index;
142         gboolean use_trampoline;
143         MonoMethodDesc *desc;
144 };
145
146 #endif /* __MONO_JIT_DEBUG_H__ */