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