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