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