2004-11-28 Martin Baulig <martin@ximian.com>
[mono.git] / mono / metadata / mono-debug-debugger.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_DEBUGGER_H__
7 #define __MONO_DEBUG_DEBUGGER_H__
8
9 #include <glib.h>
10 #include <mono/metadata/debug-helpers.h>
11 #include <mono/metadata/debug-mono-symfile.h>
12 #include <mono/io-layer/io-layer.h>
13
14 typedef struct _MonoDebuggerBreakpointInfo      MonoDebuggerBreakpointInfo;
15 typedef struct _MonoDebuggerBuiltinTypeInfo     MonoDebuggerBuiltinTypeInfo;
16 typedef struct _MonoDebuggerBuiltinTypes        MonoDebuggerBuiltinTypes;
17 typedef struct _MonoDebuggerSymbolTable         MonoDebuggerSymbolTable;
18 typedef struct _MonoDebuggerSymbolFile          MonoDebuggerSymbolFile;
19 typedef struct _MonoDebuggerSymbolFilePriv      MonoDebuggerSymbolFilePriv;
20 typedef struct _MonoDebuggerRangeInfo           MonoDebuggerRangeInfo;
21 typedef struct _MonoDebuggerClassEntry          MonoDebuggerClassEntry;
22 typedef struct _MonoDebuggerClassInfo           MonoDebuggerClassInfo;
23 typedef struct _MonoDebuggerClassTable          MonoDebuggerClassTable;
24 typedef struct _MonoDebuggerIOLayer             MonoDebuggerIOLayer;
25
26 typedef enum {
27         MONO_DEBUGGER_EVENT_BREAKPOINT,
28         MONO_DEBUGGER_EVENT_RELOAD_SYMTABS,
29         MONO_DEBUGGER_EVENT_UNHANDLED_EXCEPTION,
30         MONO_DEBUGGER_EVENT_EXCEPTION,
31         MONO_DEBUGGER_EVENT_THROW_EXCEPTION
32 } MonoDebuggerEvent;
33
34 typedef enum {
35         MONO_DEBUGGER_TYPE_KIND_UNKNOWN = 1,
36         MONO_DEBUGGER_TYPE_KIND_FUNDAMENTAL,
37         MONO_DEBUGGER_TYPE_KIND_STRING,
38         MONO_DEBUGGER_TYPE_KIND_SZARRAY,
39         MONO_DEBUGGER_TYPE_KIND_ARRAY,
40         MONO_DEBUGGER_TYPE_KIND_POINTER,
41         MONO_DEBUGGER_TYPE_KIND_ENUM,
42         MONO_DEBUGGER_TYPE_KIND_OBJECT,
43         MONO_DEBUGGER_TYPE_KIND_STRUCT,
44         MONO_DEBUGGER_TYPE_KIND_CLASS,
45         MONO_DEBUGGER_TYPE_KIND_CLASS_INFO,
46         MONO_DEBUGGER_TYPE_KIND_REFERENCE
47 } MonoDebuggerTypeKind;
48
49 typedef enum {
50         MONO_DEBUGGER_TYPE_UNKNOWN      = 0,
51         MONO_DEBUGGER_TYPE_VOID,
52         MONO_DEBUGGER_TYPE_BOOLEAN,
53         MONO_DEBUGGER_TYPE_CHAR,
54         MONO_DEBUGGER_TYPE_I1,
55         MONO_DEBUGGER_TYPE_U1,
56         MONO_DEBUGGER_TYPE_I2,
57         MONO_DEBUGGER_TYPE_U2,
58         MONO_DEBUGGER_TYPE_I4,
59         MONO_DEBUGGER_TYPE_U4,
60         MONO_DEBUGGER_TYPE_I8,
61         MONO_DEBUGGER_TYPE_U8,
62         MONO_DEBUGGER_TYPE_R4,
63         MONO_DEBUGGER_TYPE_R8,
64         MONO_DEBUGGER_TYPE_I,
65         MONO_DEBUGGER_TYPE_U,
66         MONO_DEBUGGER_TYPE_STRING,
67         MONO_DEBUGGER_TYPE_ARRAY,
68         MONO_DEBUGGER_TYPE_ENUM,
69         MONO_DEBUGGER_TYPE_MAX          = 100
70 } MonoDebuggerType;
71
72 struct _MonoDebuggerBreakpointInfo {
73         guint32 index;
74         MonoMethodDesc *desc;
75 };
76
77 struct _MonoDebuggerBuiltinTypeInfo
78 {
79         MonoDebuggerClassEntry *centry;
80         MonoClass *klass;
81         guint32 type_info;
82         guint32 class_info;
83         guint8 *type_data;
84 };
85
86 struct _MonoDebuggerBuiltinTypes {
87         guint32 total_size;
88         guint32 type_info_size;
89         MonoDebuggerBuiltinTypeInfo *object_type;
90         MonoDebuggerBuiltinTypeInfo *valuetype_type;
91         MonoDebuggerBuiltinTypeInfo *byte_type;
92         MonoDebuggerBuiltinTypeInfo *void_type;
93         MonoDebuggerBuiltinTypeInfo *boolean_type;
94         MonoDebuggerBuiltinTypeInfo *sbyte_type;
95         MonoDebuggerBuiltinTypeInfo *int16_type;
96         MonoDebuggerBuiltinTypeInfo *uint16_type;
97         MonoDebuggerBuiltinTypeInfo *int32_type;
98         MonoDebuggerBuiltinTypeInfo *uint32_type;
99         MonoDebuggerBuiltinTypeInfo *int_type;
100         MonoDebuggerBuiltinTypeInfo *uint_type;
101         MonoDebuggerBuiltinTypeInfo *int64_type;
102         MonoDebuggerBuiltinTypeInfo *uint64_type;
103         MonoDebuggerBuiltinTypeInfo *single_type;
104         MonoDebuggerBuiltinTypeInfo *double_type;
105         MonoDebuggerBuiltinTypeInfo *char_type;
106         MonoDebuggerBuiltinTypeInfo *string_type;
107         MonoDebuggerBuiltinTypeInfo *enum_type;
108         MonoDebuggerBuiltinTypeInfo *array_type;
109         MonoDebuggerBuiltinTypeInfo *exception_type;
110         MonoDebuggerBuiltinTypeInfo *type_type;
111 };
112
113 struct _MonoDebuggerSymbolTable {
114         guint64 magic;
115         guint32 version;
116         guint32 total_size;
117
118         /*
119          * Corlib and builtin types.
120          */
121         MonoDebuggerSymbolFile *corlib;
122         MonoDebuggerBuiltinTypes *builtin_types;
123
124         /*
125          * The symbol files.
126          */
127         guint32 num_symbol_files;
128         MonoDebuggerSymbolFile **symbol_files;
129
130         /*
131          * Type table.
132          * This is intentionally not a GPtrArray to make it more easy to
133          * read for the debugger.  The `type_tables' field contains
134          * `num_type_tables' pointers to continuous memory areas of
135          * `type_table_chunk_size' bytes each.
136          *
137          * The type table is basically a big continuous blob, but we need
138          * to split it up into pieces because we don't know the total size
139          * in advance and using g_realloc() doesn't work because that may
140          * reallocate the block to a different address.
141          */
142         guint32 num_type_tables;
143         guint32 type_table_chunk_size;
144         gpointer *type_tables;
145         /*
146          * Current type table.
147          * The `current_type_table' points to a blob of `type_table_chunk_size'
148          * bytes.
149          */
150         gpointer current_type_table;
151         /*
152          * This is the total size of the type table, including all the tables
153          * in the `type_tables' vector.
154          */
155         guint32 type_table_size;
156         /*
157          * These are global offsets - the `current_type_table' starts at global
158          * offset `type_table_start' and we've already allocated stuff in it
159          * until offset `type_table_offset'.
160          */
161         guint32 type_table_offset;
162         guint32 type_table_start;
163
164         /*
165          * New in version 44.
166          */
167         guint32 num_misc_tables;
168         guint32 misc_table_chunk_size;
169         gpointer *misc_tables;
170         gpointer current_misc_table;
171         guint32 misc_table_size;
172         guint32 misc_table_offset;
173         guint32 misc_table_start;
174 };
175
176 struct _MonoDebuggerSymbolFile {
177         guint32 index;
178         MonoSymbolFile *symfile;
179         MonoImage *image;
180         const char *image_file;
181         guint32 class_entry_size;
182         /* Pointer to the malloced range table. */
183         guint32 locked;
184         guint32 generation;
185         MonoDebuggerRangeInfo *range_table;
186         guint32 range_entry_size;
187         guint32 num_range_entries;
188         /* Pointer to the class table. */
189         guint32 class_table_size;
190         MonoDebuggerClassTable *current_class_table;
191         MonoDebuggerClassTable *class_table_start;
192         /* Private. */
193         MonoDebuggerSymbolFilePriv *_priv;
194 };
195
196 struct _MonoDebuggerRangeInfo {
197         const guint8 *start_address;
198         const guint8 *end_address;
199         guint32 index;
200         gpointer dynamic_data;
201         guint32 dynamic_size;
202 };
203
204 struct _MonoDebuggerClassTable {
205         MonoDebuggerClassTable *next;
206         guint32 index, size;
207         MonoDebuggerClassInfo *data;
208 };
209
210 struct _MonoDebuggerClassInfo {
211         MonoClass *klass;
212         guint32 rank;
213         guint32 token;
214         guint32 type_info;
215 };
216
217 struct _MonoDebuggerClassEntry {
218         MonoDebuggerClassInfo *info;
219         guint32 type_reference;
220 };
221
222 enum {
223         MONO_DEBUGGER_MISC_ENTRY_TYPE_UNKNOWN   = 0,
224         MONO_DEBUGGER_MISC_ENTRY_TYPE_WRAPPER
225 };
226
227 extern MonoDebuggerSymbolTable *mono_debugger_symbol_table;
228
229 /*
230  * Address of the x86 trampoline code.  This is used by the debugger to check
231  * whether a method is a trampoline.
232  */
233 extern guint8 *mono_generic_trampoline_code;
234
235 #ifndef PLATFORM_WIN32
236
237 /*
238  * Functions we export to the debugger.
239  */
240 struct _MonoDebuggerIOLayer
241 {
242         void (*InitializeCriticalSection) (WapiCriticalSection *section);
243         void (*DeleteCriticalSection) (WapiCriticalSection *section);
244         gboolean (*TryEnterCriticalSection) (WapiCriticalSection *section);
245         void (*EnterCriticalSection) (WapiCriticalSection *section);
246         void (*LeaveCriticalSection) (WapiCriticalSection *section);
247
248         guint32 (*WaitForSingleObject) (gpointer handle, guint32 timeout, 
249                                         gboolean alertable);
250         guint32 (*SignalObjectAndWait) (gpointer signal_handle, gpointer wait,
251                                         guint32 timeout, gboolean alertable);
252         guint32 (*WaitForMultipleObjects) (guint32 numobjects, gpointer *handles,
253                                       gboolean waitall, guint32 timeout, gboolean alertable);
254
255         gpointer (*CreateSemaphore) (WapiSecurityAttributes *security,
256                                      gint32 initial, gint32 max,
257                                      const gunichar2 *name);
258         gboolean (*ReleaseSemaphore) (gpointer handle, gint32 count, gint32 *prevcount);
259
260         gpointer (*CreateThread) (WapiSecurityAttributes *security,
261                                   guint32 stacksize, WapiThreadStart start,
262                                   gpointer param, guint32 create, guint32 *tid);
263         guint32 (*GetCurrentThreadId) (void);
264 };
265
266 extern MonoDebuggerIOLayer mono_debugger_io_layer;
267
268 #endif
269
270 extern void (*mono_debugger_event_handler) (MonoDebuggerEvent event, gpointer data, guint32 arg);
271
272 void            mono_debugger_initialize                  (void);
273 void            mono_debugger_cleanup                     (void);
274
275 void            mono_debugger_lock                        (void);
276 void            mono_debugger_unlock                      (void);
277 void            mono_debugger_event                       (MonoDebuggerEvent event, gpointer data, guint32 arg);
278
279 MonoDebuggerSymbolFile   *_mono_debugger_get_symfile      (MonoImage *image);
280 MonoDebuggerSymbolFile   *mono_debugger_add_symbol_file   (MonoDebugHandle *handle);
281 void                      mono_debugger_start_add_type    (MonoDebuggerSymbolFile *symfile,
282                                                            MonoClass *klass);
283 void                      mono_debugger_add_type          (MonoDebuggerSymbolFile *symfile,
284                                                            MonoClass *klass);
285 MonoDebuggerBuiltinTypes *mono_debugger_add_builtin_types (MonoDebuggerSymbolFile *symfile);
286
287 void            mono_debugger_add_method                  (MonoDebuggerSymbolFile *symfile,
288                                                            MonoDebugMethodInfo *minfo,
289                                                            MonoDebugMethodJitInfo *jit);
290
291 void            mono_debugger_add_wrapper                 (MonoMethod *wrapper,
292                                                            MonoDebugMethodJitInfo *jit,
293                                                            gpointer addr);
294
295
296 int             mono_debugger_insert_breakpoint_full      (MonoMethodDesc *desc);
297 int             mono_debugger_remove_breakpoint           (int breakpoint_id);
298 int             mono_debugger_insert_breakpoint           (const gchar *method_name, gboolean include_namespace);
299 int             mono_debugger_method_has_breakpoint       (MonoMethod *method);
300 void            mono_debugger_breakpoint_callback         (MonoMethod *method, guint32 idx);
301
302 gpointer        mono_debugger_create_notification_function (gpointer *notification_address);
303
304 MonoObject     *mono_debugger_runtime_invoke              (MonoMethod *method, void *obj,
305                                                            void **params, MonoObject **exc);
306
307 guint32         mono_debugger_lookup_type                 (const gchar *type_name);
308 gint32          mono_debugger_lookup_assembly             (const gchar *name);
309 gboolean        mono_debugger_unhandled_exception         (gpointer addr, gpointer stack, MonoObject *exc);
310 void            mono_debugger_handle_exception            (gpointer addr, gpointer stack, MonoObject *exc);
311 gboolean        mono_debugger_throw_exception             (gpointer addr, gpointer stack, MonoObject *exc);
312
313
314
315 void *
316 mono_vtable_get_static_field_data (MonoVTable *vt);
317
318
319 MonoReflectionMethod *
320 ves_icall_MonoDebugger_GetMethod (MonoReflectionAssembly *assembly, guint32 token);
321
322 int
323 ves_icall_MonoDebugger_GetMethodToken (MonoReflectionAssembly *assembly, MonoReflectionMethod *method);
324
325 MonoReflectionType *
326 ves_icall_MonoDebugger_GetLocalTypeFromSignature (MonoReflectionAssembly *assembly, MonoArray *signature);
327
328 MonoReflectionType *
329 ves_icall_MonoDebugger_GetType (MonoReflectionAssembly *assembly, guint32 token);
330
331 gchar *
332 mono_debugger_check_runtime_version (const char *filename);
333
334 #endif /* __MONO_DEBUG_DEBUGGER_H__ */