2007-09-24 Martin Baulig <martin@ximian.com>
[mono.git] / mono / metadata / mono-debug.h
1 /*
2  * This header is only installed for use by the debugger:
3  * the structures and the API declared here are not supported.
4  */
5
6 #ifndef __MONO_DEBUG_H__
7 #define __MONO_DEBUG_H__
8
9 #include <glib.h>
10 #include <mono/metadata/image.h>
11 #include <mono/metadata/appdomain.h>
12
13 typedef struct _MonoSymbolTable                 MonoSymbolTable;
14 typedef struct _MonoDebugDataTable              MonoDebugDataTable;
15
16 typedef struct _MonoSymbolFile                  MonoSymbolFile;
17
18 typedef struct _MonoDebugHandle                 MonoDebugHandle;
19
20 typedef struct _MonoDebugLineNumberEntry        MonoDebugLineNumberEntry;
21 typedef struct _MonoDebugLexicalBlockEntry      MonoDebugLexicalBlockEntry;
22
23 typedef struct _MonoDebugVarInfo                MonoDebugVarInfo;
24 typedef struct _MonoDebugMethodJitInfo          MonoDebugMethodJitInfo;
25 typedef struct _MonoDebugMethodAddress          MonoDebugMethodAddress;
26 typedef struct _MonoDebugMethodAddressList      MonoDebugMethodAddressList;
27 typedef struct _MonoDebugClassEntry             MonoDebugClassEntry;
28
29 typedef struct _MonoDebugMethodInfo             MonoDebugMethodInfo;
30 typedef struct _MonoDebugSourceLocation         MonoDebugSourceLocation;
31
32 typedef struct _MonoDebugList                   MonoDebugList;
33
34 typedef enum {
35         MONO_DEBUG_FORMAT_NONE,
36         MONO_DEBUG_FORMAT_MONO,
37         MONO_DEBUG_FORMAT_DEBUGGER
38 } MonoDebugFormat;
39
40 typedef enum {
41         MONO_DEBUGGER_TYPE_KIND_UNKNOWN = 1,
42         MONO_DEBUGGER_TYPE_KIND_FUNDAMENTAL,
43         MONO_DEBUGGER_TYPE_KIND_STRING,
44         MONO_DEBUGGER_TYPE_KIND_SZARRAY,
45         MONO_DEBUGGER_TYPE_KIND_ARRAY,
46         MONO_DEBUGGER_TYPE_KIND_POINTER,
47         MONO_DEBUGGER_TYPE_KIND_ENUM,
48         MONO_DEBUGGER_TYPE_KIND_OBJECT,
49         MONO_DEBUGGER_TYPE_KIND_STRUCT,
50         MONO_DEBUGGER_TYPE_KIND_CLASS,
51         MONO_DEBUGGER_TYPE_KIND_CLASS_INFO,
52         MONO_DEBUGGER_TYPE_KIND_REFERENCE
53 } MonoDebuggerTypeKind;
54
55 /*
56  * NOTE:
57  * We intentionally do not use GList here since the debugger needs to know about
58  * the layout of the fields.
59 */
60 struct _MonoDebugList {
61         MonoDebugList *next;
62         gconstpointer data;
63 };
64
65 struct _MonoSymbolTable {
66         guint64 magic;
67         guint32 version;
68         guint32 total_size;
69
70         /*
71          * Corlib and metadata info.
72          */
73         MonoDebugHandle *corlib;
74
75         MonoDebugList *data_tables;
76
77         /*
78          * The symbol files.
79          */
80         MonoDebugList *symbol_files;
81 };
82
83 struct _MonoDebugHandle {
84         guint32 index;
85         char *image_file;
86         MonoImage *image;
87         MonoDebugDataTable *type_table;
88         MonoSymbolFile *symfile;
89 };
90
91 struct _MonoDebugMethodJitInfo {
92         const guint8 *code_start;
93         guint32 code_size;
94         guint32 prologue_end;
95         guint32 epilogue_begin;
96         const guint8 *wrapper_addr;
97         guint32 num_line_numbers;
98         MonoDebugLineNumberEntry *line_numbers;
99         guint32 num_lexical_blocks;
100         MonoDebugLexicalBlockEntry *lexical_blocks;
101         guint32 num_params;
102         MonoDebugVarInfo *this_var;
103         MonoDebugVarInfo *params;
104         guint32 num_locals;
105         MonoDebugVarInfo *locals;
106 };
107
108 struct _MonoDebugMethodAddressList {
109         guint32 size;
110         guint32 count;
111         guint8 data [MONO_ZERO_LEN_ARRAY];
112 };
113
114 struct _MonoDebugSourceLocation {
115         gchar *source_file;
116         guint32 row, column;
117         guint32 il_offset;
118 };
119
120 /*
121  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
122  * where the variable is actually stored.
123  *
124  * See relocate_variable() in debug-symfile.c for more info.
125  */
126 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
127
128 /* The variable is in register "index". */
129 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0
130
131 /* The variable is at offset "offset" from register "index". */
132 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET           0x10000000
133
134 /* The variable is in the two registers "offset" and "index". */
135 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
136
137 struct _MonoDebugVarInfo {
138         guint32 index;
139         guint32 offset;
140         guint32 size;
141         guint32 begin_scope;
142         guint32 end_scope;
143         MonoClass *klass;
144 };
145
146 #define MONO_DEBUGGER_VERSION                           60
147 #define MONO_DEBUGGER_MAGIC                             0x7aff65af4253d427ULL
148
149 extern MonoSymbolTable *mono_symbol_table;
150 extern MonoDebugFormat mono_debug_format;
151 extern GHashTable *mono_debug_handles;
152 extern gint32 mono_debug_debugger_version;
153
154 void mono_debug_list_add (MonoDebugList **list, gconstpointer data);
155 void mono_debug_list_remove (MonoDebugList **list, gconstpointer data);
156
157 void mono_debug_init (MonoDebugFormat format);
158 void mono_debug_open_image_from_memory (MonoImage *image, const guint8 *raw_contents, int size);
159 void mono_debug_cleanup (void);
160
161 void mono_debug_close_image (MonoImage *image);
162
163 void mono_debug_domain_unload (MonoDomain *domain);
164 void mono_debug_domain_create (MonoDomain *domain);
165
166 gboolean mono_debug_using_mono_debugger (void);
167
168 MonoDebugMethodAddress *
169 mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDomain *domain);
170
171 MonoDebugMethodInfo *
172 mono_debug_lookup_method (MonoMethod *method);
173
174 MonoDebugMethodAddressList *
175 mono_debug_lookup_method_addresses (MonoMethod *method);
176
177 MonoDebugMethodJitInfo*
178 mono_debug_find_method (MonoMethod *method, MonoDomain *domain);
179
180 /*
181  * Line number support.
182  */
183
184 MonoDebugSourceLocation *
185 mono_debug_lookup_source_location (MonoMethod *method, guint32 address, MonoDomain *domain);
186
187 void
188 mono_debug_free_source_location (MonoDebugSourceLocation *location);
189
190 gchar *
191 mono_debug_print_stack_frame (MonoMethod *method, guint32 native_offset, MonoDomain *domain);
192
193 /*
194  * Mono Debugger support functions
195  *
196  * These methods are used by the JIT while running inside the Mono Debugger.
197  */
198
199 int             mono_debugger_method_has_breakpoint       (MonoMethod *method);
200 int             mono_debugger_insert_breakpoint           (const gchar *method_name, gboolean include_namespace);
201 gboolean        mono_debugger_unhandled_exception         (gpointer addr, gpointer stack, MonoObject *exc);
202 void            mono_debugger_handle_exception            (gpointer addr, gpointer stack, MonoObject *exc);
203 gboolean        mono_debugger_throw_exception             (gpointer addr, gpointer stack, MonoObject *exc);
204
205 #endif /* __MONO_DEBUG_H__ */