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