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