Merge pull request #587 from madewokherd/gdipdllmap
[mono.git] / mono / metadata / mono-debug.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_H__
7 #define __MONO_DEBUG_H__
8
9 #include <mono/utils/mono-publib.h>
10 #include <mono/metadata/image.h>
11 #include <mono/metadata/appdomain.h>
12
13 MONO_BEGIN_DECLS
14
15 typedef struct _MonoSymbolTable                 MonoSymbolTable;
16 typedef struct _MonoDebugDataTable              MonoDebugDataTable;
17
18 typedef struct _MonoSymbolFile                  MonoSymbolFile;
19
20 typedef struct _MonoDebugHandle                 MonoDebugHandle;
21
22 typedef struct _MonoDebugLineNumberEntry        MonoDebugLineNumberEntry;
23
24 typedef struct _MonoDebugVarInfo                MonoDebugVarInfo;
25 typedef struct _MonoDebugMethodJitInfo          MonoDebugMethodJitInfo;
26 typedef struct _MonoDebugMethodAddress          MonoDebugMethodAddress;
27 typedef struct _MonoDebugMethodAddressList      MonoDebugMethodAddressList;
28 typedef struct _MonoDebugClassEntry             MonoDebugClassEntry;
29
30 typedef struct _MonoDebugMethodInfo             MonoDebugMethodInfo;
31 typedef struct _MonoDebugLocalsInfo             MonoDebugLocalsInfo;
32 typedef struct _MonoDebugSourceLocation         MonoDebugSourceLocation;
33
34 typedef struct _MonoDebugList                   MonoDebugList;
35
36 typedef enum {
37         MONO_DEBUG_FORMAT_NONE,
38         MONO_DEBUG_FORMAT_MONO,
39         MONO_DEBUG_FORMAT_DEBUGGER
40 } MonoDebugFormat;
41
42 /*
43  * NOTE:
44  * We intentionally do not use GList here since the debugger needs to know about
45  * the layout of the fields.
46 */
47 struct _MonoDebugList {
48         MonoDebugList *next;
49         const void* data;
50 };
51
52 struct _MonoSymbolTable {
53         uint64_t magic;
54         uint32_t version;
55         uint32_t total_size;
56
57         /*
58          * Corlib and metadata info.
59          */
60         MonoDebugHandle *corlib;
61         MonoDebugDataTable *global_data_table;
62         MonoDebugList *data_tables;
63
64         /*
65          * The symbol files.
66          */
67         MonoDebugList *symbol_files;
68 };
69
70 struct _MonoDebugHandle {
71         uint32_t index;
72         char *image_file;
73         MonoImage *image;
74         MonoDebugDataTable *type_table;
75         MonoSymbolFile *symfile;
76 };
77
78 struct _MonoDebugMethodJitInfo {
79         const mono_byte *code_start;
80         uint32_t code_size;
81         uint32_t prologue_end;
82         uint32_t epilogue_begin;
83         const mono_byte *wrapper_addr;
84         uint32_t num_line_numbers;
85         MonoDebugLineNumberEntry *line_numbers;
86         uint32_t num_params;
87         MonoDebugVarInfo *this_var;
88         MonoDebugVarInfo *params;
89         uint32_t num_locals;
90         MonoDebugVarInfo *locals;
91         MonoDebugVarInfo *gsharedvt_info_var;
92         MonoDebugVarInfo *gsharedvt_locals_var;
93 };
94
95 struct _MonoDebugMethodAddressList {
96         uint32_t size;
97         uint32_t count;
98         mono_byte data [MONO_ZERO_LEN_ARRAY];
99 };
100
101 struct _MonoDebugSourceLocation {
102         char *source_file;
103         uint32_t row, column;
104         uint32_t il_offset;
105 };
106
107 /*
108  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
109  * where the variable is actually stored.
110  *
111  * See relocate_variable() in debug-symfile.c for more info.
112  */
113 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
114
115 /* The variable is in register "index". */
116 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0
117
118 /* The variable is at offset "offset" from register "index". */
119 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET           0x10000000
120
121 /* The variable is in the two registers "offset" and "index". */
122 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
123
124 /* The variable is dead. */
125 #define MONO_DEBUG_VAR_ADDRESS_MODE_DEAD                0x30000000
126
127 /* Same as REGOFFSET, but do an indirection */
128 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR             0x40000000
129
130 /* gsharedvt local */
131 #define MONO_DEBUG_VAR_ADDRESS_MODE_GSHAREDVT_LOCAL             0x50000000
132
133 /* variable is a vt address */
134 #define MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR              0x60000000
135
136 struct _MonoDebugVarInfo {
137         uint32_t index;
138         uint32_t offset;
139         uint32_t size;
140         uint32_t begin_scope;
141         uint32_t end_scope;
142         MonoType *type;
143 };
144
145 #define MONO_DEBUGGER_MAJOR_VERSION                     81
146 #define MONO_DEBUGGER_MINOR_VERSION                     6
147 #define MONO_DEBUGGER_MAGIC                             0x7aff65af4253d427ULL
148
149 extern MonoSymbolTable *mono_symbol_table;
150 extern MonoDebugFormat mono_debug_format;
151 extern int32_t mono_debug_debugger_version;
152 extern int32_t _mono_debug_using_mono_debugger;
153
154 MONO_API void mono_debug_list_add (MonoDebugList **list, const void* data);
155 MONO_API void mono_debug_list_remove (MonoDebugList **list, const void* data);
156
157 MONO_API void mono_debug_init (MonoDebugFormat format);
158 MONO_API void mono_debug_open_image_from_memory (MonoImage *image, const mono_byte *raw_contents, int size);
159 MONO_API void mono_debug_cleanup (void);
160
161 MONO_API void mono_debug_close_image (MonoImage *image);
162
163 MONO_API void mono_debug_domain_unload (MonoDomain *domain);
164 MONO_API void mono_debug_domain_create (MonoDomain *domain);
165
166 MONO_API mono_bool mono_debug_using_mono_debugger (void);
167
168 MONO_API MonoDebugMethodAddress *
169 mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDomain *domain);
170
171 MONO_API void
172 mono_debug_remove_method (MonoMethod *method, MonoDomain *domain);
173
174 MONO_API MonoDebugMethodInfo *
175 mono_debug_lookup_method (MonoMethod *method);
176
177 MONO_API MonoDebugMethodAddressList *
178 mono_debug_lookup_method_addresses (MonoMethod *method);
179
180 MONO_API MonoDebugMethodJitInfo*
181 mono_debug_find_method (MonoMethod *method, MonoDomain *domain);
182
183 MONO_API void
184 mono_debug_free_method_jit_info (MonoDebugMethodJitInfo *jit);
185
186
187 MONO_API void
188 mono_debug_add_delegate_trampoline (void* code, int size);
189
190 MONO_API MonoDebugLocalsInfo*
191 mono_debug_lookup_locals (MonoMethod *method);
192
193 /*
194  * Line number support.
195  */
196
197 MONO_API MonoDebugSourceLocation *
198 mono_debug_lookup_source_location (MonoMethod *method, uint32_t address, MonoDomain *domain);
199
200 MONO_API int32_t
201 mono_debug_il_offset_from_address (MonoMethod *method, MonoDomain *domain, uint32_t native_offset);
202
203 MONO_API void
204 mono_debug_free_source_location (MonoDebugSourceLocation *location);
205
206 MONO_API char *
207 mono_debug_print_stack_frame (MonoMethod *method, uint32_t native_offset, MonoDomain *domain);
208
209 /*
210  * Mono Debugger support functions
211  *
212  * These methods are used by the JIT while running inside the Mono Debugger.
213  */
214
215 MONO_API int             mono_debugger_method_has_breakpoint       (MonoMethod *method);
216 MONO_API int             mono_debugger_insert_breakpoint           (const char *method_name, mono_bool include_namespace);
217
218 MONO_API void mono_set_is_debugger_attached (mono_bool attached);
219 MONO_API mono_bool mono_is_debugger_attached (void);
220
221 MONO_END_DECLS
222
223 #endif /* __MONO_DEBUG_H__ */