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