2006-09-18 Zoltan Varga <vargaz@gmail.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
15 typedef struct _MonoSymbolFile                  MonoSymbolFile;
16 typedef struct _MonoSymbolFilePriv              MonoSymbolFilePriv;
17
18 typedef struct _MonoDebugHandle                 MonoDebugHandle;
19 typedef struct _MonoDebugHandlePriv             MonoDebugHandlePriv;
20
21 typedef struct _MonoDebugLineNumberEntry        MonoDebugLineNumberEntry;
22 typedef struct _MonoDebugLexicalBlockEntry      MonoDebugLexicalBlockEntry;
23
24 typedef struct _MonoDebugVarInfo                MonoDebugVarInfo;
25 typedef struct _MonoDebugMethodJitInfo          MonoDebugMethodJitInfo;
26 typedef struct _MonoDebugMethodAddress          MonoDebugMethodAddress;
27 typedef struct _MonoDebugWrapperData            MonoDebugWrapperData;
28 typedef struct _MonoDebugClassEntry             MonoDebugClassEntry;
29
30 typedef struct _MonoDebugMethodInfo             MonoDebugMethodInfo;
31 typedef struct _MonoDebugSourceLocation         MonoDebugSourceLocation;
32
33 typedef enum {
34         MONO_DEBUG_FORMAT_NONE,
35         MONO_DEBUG_FORMAT_MONO,
36         MONO_DEBUG_FORMAT_DEBUGGER
37 } MonoDebugFormat;
38
39 typedef enum {
40         MONO_DEBUGGER_TYPE_KIND_UNKNOWN = 1,
41         MONO_DEBUGGER_TYPE_KIND_FUNDAMENTAL,
42         MONO_DEBUGGER_TYPE_KIND_STRING,
43         MONO_DEBUGGER_TYPE_KIND_SZARRAY,
44         MONO_DEBUGGER_TYPE_KIND_ARRAY,
45         MONO_DEBUGGER_TYPE_KIND_POINTER,
46         MONO_DEBUGGER_TYPE_KIND_ENUM,
47         MONO_DEBUGGER_TYPE_KIND_OBJECT,
48         MONO_DEBUGGER_TYPE_KIND_STRUCT,
49         MONO_DEBUGGER_TYPE_KIND_CLASS,
50         MONO_DEBUGGER_TYPE_KIND_CLASS_INFO,
51         MONO_DEBUGGER_TYPE_KIND_REFERENCE
52 } MonoDebuggerTypeKind;
53
54 struct _MonoSymbolTable {
55         guint64 magic;
56         guint32 version;
57         guint32 total_size;
58
59         /*
60          * Corlib and metadata info.
61          */
62         MonoDebugHandle *corlib;
63
64         /*
65          * The symbol files.
66          */
67         MonoDebugHandle **symbol_files;
68         guint32 num_symbol_files;
69
70         /*
71          * Data table.
72          * This is intentionally not a GPtrArray to make it more easy to
73          * read for the debugger.  The `data_tables' field contains
74          * `num_data_tables' pointers to continuous memory areas.
75          *
76          * The data table is basically a big continuous blob, but we need
77          * to split it up into pieces because we don't know the total size
78          * in advance and using g_realloc() doesn't work because that may
79          * reallocate the block to a different address.
80          */
81         guint32 num_data_tables;
82         gpointer *data_tables;
83         /*
84          * Current data table.
85          * The `current_data_table' points to a blob of `current_data_table_size'
86          * bytes.
87          */
88         gpointer current_data_table;
89         guint32 current_data_table_size;
90         /*
91          * The offset in the `current_data_table'.
92          */
93         guint32 current_data_table_offset;
94 };
95
96 typedef enum {
97         MONO_DEBUG_DATA_ITEM_UNKNOWN            = 0,
98         MONO_DEBUG_DATA_ITEM_METHOD,
99         MONO_DEBUG_DATA_ITEM_CLASS,
100         MONO_DEBUG_DATA_ITEM_WRAPPER
101 } MonoDebugDataItemType;
102
103 struct _MonoDebugHandle {
104         guint32 index;
105         const char *image_file;
106         MonoImage *image;
107         MonoSymbolFile *symfile;
108         MonoDebugHandlePriv *_priv;
109 };
110
111 struct _MonoDebugMethodJitInfo {
112         MonoDebugMethodAddress *address;
113         const guint8 *code_start;
114         guint32 code_size;
115         guint32 prologue_end;
116         guint32 epilogue_begin;
117         const guint8 *wrapper_addr;
118         guint32 num_line_numbers;
119         MonoDebugLineNumberEntry *line_numbers;
120         guint32 num_lexical_blocks;
121         MonoDebugLexicalBlockEntry *lexical_blocks;
122         guint32 num_params;
123         MonoDebugVarInfo *this_var;
124         MonoDebugVarInfo *params;
125         guint32 num_locals;
126         MonoDebugVarInfo *locals;
127 };
128
129 struct _MonoDebugMethodAddress {
130         guint32 size;
131         guint32 symfile_id;
132         guint32 domain_id;
133         guint32 method_id;
134         guint32 code_size;
135         guint32 dummy;
136         const guint8 *code_start;
137         const guint8 *wrapper_addr;
138         MonoDebugMethodJitInfo *jit;
139         guint8 data [MONO_ZERO_LEN_ARRAY];
140 };
141
142 struct _MonoDebugWrapperData {
143         guint32 size;
144         guint32 code_size;
145         MonoMethod *method;
146         const guint8 *code_start;
147         const gchar *name;
148         const gchar *cil_code;
149         guint8 data [MONO_ZERO_LEN_ARRAY];
150 };
151
152 struct _MonoDebugClassEntry {
153         guint32 size;
154         guint32 symfile_id;
155         guint8 data [MONO_ZERO_LEN_ARRAY];
156 };
157
158 struct _MonoDebugSourceLocation {
159         gchar *source_file;
160         guint32 row, column;
161         guint32 il_offset;
162 };
163
164 /*
165  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
166  * where the variable is actually stored.
167  *
168  * See relocate_variable() in debug-symfile.c for more info.
169  */
170 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
171
172 /* The variable is in register "index". */
173 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0
174
175 /* The variable is at offset "offset" from register "index". */
176 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET           0x10000000
177
178 /* The variable is in the two registers "offset" and "index". */
179 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
180
181 struct _MonoDebugVarInfo {
182         guint32 index;
183         guint32 offset;
184         guint32 size;
185         guint32 begin_scope;
186         guint32 end_scope;
187 };
188
189 #define MONO_DEBUGGER_VERSION                           57
190 #define MONO_DEBUGGER_MAGIC                             0x7aff65af4253d427ULL
191
192 extern MonoSymbolTable *mono_symbol_table;
193 extern MonoDebugFormat mono_debug_format;
194 extern GHashTable *mono_debug_handles;
195
196 void mono_debug_init (MonoDebugFormat format);
197 void mono_debug_init_1 (MonoDomain *domain);
198 void mono_debug_init_2 (MonoAssembly *assembly);
199 void mono_debug_init_2_memory (MonoImage *image, const guint8 *raw_contents, int size);
200 void mono_debug_cleanup (void);
201
202 gboolean mono_debug_using_mono_debugger (void);
203
204 MonoDebugMethodAddress *mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit,
205                                                MonoDomain *domain);
206 MonoDebugMethodJitInfo *mono_debug_read_method (MonoDebugMethodAddress *address);
207 void mono_debug_free_method_jit_info (MonoDebugMethodJitInfo *jit);
208
209 MonoDebugMethodInfo *mono_debug_lookup_method (MonoMethod *method);
210
211 /*
212  * Line number support.
213  */
214
215 MonoDebugSourceLocation *
216 mono_debug_lookup_source_location (MonoMethod *method, guint32 address, MonoDomain *domain);
217
218 void
219 mono_debug_free_source_location (MonoDebugSourceLocation *location);
220
221 gchar *
222 mono_debug_print_stack_frame (MonoMethod *method, guint32 native_offset, MonoDomain *domain);
223
224 /*
225  * Mono Debugger support functions
226  *
227  * These methods are used by the JIT while running inside the Mono Debugger.
228  */
229
230 int             mono_debugger_method_has_breakpoint       (MonoMethod *method);
231 int             mono_debugger_insert_breakpoint           (const gchar *method_name, gboolean include_namespace);
232 gboolean        mono_debugger_unhandled_exception         (gpointer addr, gpointer stack, MonoObject *exc);
233 void            mono_debugger_handle_exception            (gpointer addr, gpointer stack, MonoObject *exc);
234 gboolean        mono_debugger_throw_exception             (gpointer addr, gpointer stack, MonoObject *exc);
235
236 #endif /* __MONO_DEBUG_H__ */