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