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