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