2003-02-21 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / metadata / debug-mono-symfile.h
1 #ifndef __MONO_DEBUG_MONO_SYMFILE_H__
2 #define __MONO_DEBUG_MONO_SYMFILE_H__
3
4 #include <glib.h>
5 #include <mono/metadata/class.h>
6 #include <mono/metadata/reflection.h>
7
8 typedef struct MonoSymbolFile                   MonoSymbolFile;
9 typedef struct MonoGlobalSymbolFile             MonoGlobalSymbolFile;
10 typedef struct MonoSymbolFilePriv               MonoSymbolFilePriv;
11 typedef struct MonoSymbolFileOffsetTable        MonoSymbolFileOffsetTable;
12 typedef struct MonoSymbolFileLineNumberEntry    MonoSymbolFileLineNumberEntry;
13 typedef struct MonoSymbolFileMethodEntry        MonoSymbolFileMethodEntry;
14 typedef struct MonoSymbolFileMethodAddress      MonoSymbolFileMethodAddress;
15 typedef struct MonoSymbolFileDynamicTable       MonoSymbolFileDynamicTable;
16 typedef struct MonoSymbolFileSourceEntry        MonoSymbolFileSourceEntry;
17 typedef struct MonoSymbolFileMethodIndexEntry   MonoSymbolFileMethodIndexEntry;
18
19 typedef struct MonoDebugMethodInfo              MonoDebugMethodInfo;
20 typedef struct MonoDebugMethodJitInfo           MonoDebugMethodJitInfo;
21 typedef struct MonoDebugVarInfo                 MonoDebugVarInfo;
22 typedef struct MonoDebugLineNumberEntry         MonoDebugLineNumberEntry;
23 typedef struct MonoDebugRangeInfo               MonoDebugRangeInfo;
24 typedef struct MonoDebugClassInfo               MonoDebugClassInfo;
25
26 /* Keep in sync with OffsetTable in mcs/class/Mono.CSharp.Debugger/MonoSymbolTable.cs */
27 struct MonoSymbolFileOffsetTable {
28         guint32 total_file_size;
29         guint32 data_section_offset;
30         guint32 data_section_size;
31         guint32 source_count;
32         guint32 source_table_offset;
33         guint32 source_table_size;
34         guint32 method_count;
35         guint32 method_table_offset;
36         guint32 method_table_size;
37         guint32 type_count;
38 };
39
40 struct MonoSymbolFileMethodEntry {
41         guint32 source_index;
42         guint32 token;
43         guint32 start_row;
44         guint32 end_row;
45         guint32 class_type_index;
46         guint32 num_parameters;
47         guint32 num_locals;
48         guint32 num_line_numbers;
49         guint32 name_offset;
50         guint32 full_name_offset;
51         guint32 type_index_table_offset;
52         guint32 local_variable_table_offset;
53         guint32 line_number_table_offset;
54         guint32 namespace_idx;
55 };
56
57 struct MonoSymbolFileSourceEntry {
58         guint32 index;
59         guint32 num_methods;
60         guint32 num_namespaces;
61         guint32 name_offset;
62         guint32 method_offset;
63         guint32 nstable_offset;
64 };
65
66 struct MonoSymbolFileMethodIndexEntry {
67         guint32 file_offset;
68         guint32 full_name_offset;
69         guint32 token;
70 };
71
72 struct MonoSymbolFileMethodAddress {
73         guint32 size;
74         const guint8 *start_address;
75         const guint8 *end_address;
76         const guint8 *method_start_address;
77         const guint8 *method_end_address;
78         const guint8 *wrapper_address;
79         guint32 has_this;
80         guint32 variable_table_offset;
81         guint32 type_table_offset;
82         guint32 num_line_numbers;
83         guint32 line_number_offset;
84         guint8 data [MONO_ZERO_LEN_ARRAY];
85 };
86
87 struct MonoSymbolFileLineNumberEntry {
88         guint32 row;
89         guint32 offset;
90 };
91
92 struct MonoDebugMethodInfo {
93         MonoMethod *method;
94         MonoSymbolFile *symfile;
95         guint32 index;
96         guint32 num_il_offsets;
97         guint32 start_line;
98         guint32 end_line;
99         MonoSymbolFileLineNumberEntry *il_offsets;
100         MonoDebugMethodJitInfo *jit;
101         gpointer user_data;
102 };
103
104 struct MonoDebugLineNumberEntry {
105         guint32 line;
106         guint32 offset;
107         guint32 address;
108 };
109
110 struct MonoDebugMethodJitInfo {
111         const guint8 *code_start;
112         guint32 code_size;
113         guint32 prologue_end;
114         guint32 epilogue_begin;
115         const guint8 *wrapper_addr;
116         // Array of MonoDebugLineNumberEntry
117         GArray *line_numbers;
118         guint32 num_params;
119         MonoDebugVarInfo *this_var;
120         MonoDebugVarInfo *params;
121         guint32 num_locals;
122         MonoDebugVarInfo *locals;
123 };
124
125 /*
126  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
127  * where the variable is actually stored.
128  *
129  * See relocate_variable() in debug-symfile.c for more info.
130  */
131 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
132
133 /* If "index" is zero, the variable is at stack offset "offset". */
134 #define MONO_DEBUG_VAR_ADDRESS_MODE_STACK               0
135
136 /* The variable is in the register whose number is contained in bits 0..4 of the
137  * "index" field plus an offset of "offset" (which can be zero).
138  */
139 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0x10000000
140
141 /* The variables in in the two registers whose numbers are contained in bits 0..4
142  * and 5..9 of the "index" field plus an offset of "offset" (which can be zero).
143  */
144 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
145
146 struct MonoDebugVarInfo {
147         guint32 index;
148         guint32 offset;
149         guint32 size;
150         guint32 begin_scope;
151         guint32 end_scope;
152 };
153
154 struct MonoDebugRangeInfo {
155         const guint8 *start_address;
156         const guint8 *end_address;
157         guint32 index;
158         gpointer dynamic_data;
159         guint32 dynamic_size;
160 };
161
162 struct MonoDebugClassInfo {
163         MonoClass *klass;
164         guint32 rank;
165         guint32 token;
166         guint32 type_info;
167 };
168
169 /*
170  * This is shared between all symbol files.
171  */
172 struct MonoGlobalSymbolFile {
173         /*
174          * Type table.
175          * This is intentionally not a GPtrArray to make it more easy to
176          * read for the debugger.  The `type_tables' field contains
177          * `num_type_tables' pointers to continuous memory areas of
178          * `type_table_chunk_size' bytes each.
179          *
180          * The type table is basically a big continuous blob, but we need
181          * to split it up into pieces because we don't know the total size
182          * in advance and using g_realloc() doesn't work because that may
183          * reallocate the block to a different address.
184          */
185         guint32 num_type_tables;
186         guint32 type_table_chunk_size;
187         gpointer *type_tables;
188         /*
189          * Current type table.
190          * The `current_type_table' points to a blob of `type_table_chunk_size'
191          * bytes.
192          */
193         gpointer current_type_table;
194         /*
195          * This is the total size of the type table, including all the tables
196          * in the `type_tables' vector.
197          */
198         guint32 type_table_size;
199         /*
200          * These are global offsets - the `current_type_table' starts at global
201          * offset `type_table_start' and we've already allocated stuff in it
202          * until offset `type_table_offset'.
203          */
204         guint32 type_table_offset;
205         guint32 type_table_start;
206 };
207
208 struct MonoSymbolFile {
209         guint64 dynamic_magic;
210         guint32 dynamic_version;
211         const char *image_file;
212         MonoGlobalSymbolFile *global;
213         /* Pointer to the malloced range table. */
214         guint32 locked;
215         guint32 generation;
216         MonoDebugRangeInfo *range_table;
217         guint32 range_entry_size;
218         guint32 num_range_entries;
219         /* Pointer to the malloced class table. */
220         MonoDebugClassInfo *class_table;
221         guint32 class_entry_size;
222         guint32 num_class_entries;
223         /* Private. */
224         MonoSymbolFilePriv *_priv;
225 };
226
227 #define MONO_SYMBOL_FILE_VERSION                32
228 #define MONO_SYMBOL_FILE_MAGIC                  0x45e82623fd7fa614
229
230 #define MONO_SYMBOL_FILE_DYNAMIC_VERSION        25
231 #define MONO_SYMBOL_FILE_DYNAMIC_MAGIC          0x7aff65af4253d427
232
233 extern MonoGlobalSymbolFile *mono_debugger_global_symbol_file;
234
235 MonoSymbolFile *
236 mono_debug_open_mono_symbol_file   (MonoImage                 *image,
237                                     gboolean                   create_symfile);
238
239 void
240 mono_debug_symfile_add_method      (MonoSymbolFile           *symfile,
241                                     MonoMethod               *method);
242
243 void
244 mono_debug_symfile_add_type        (MonoSymbolFile           *symfile,
245                                     MonoClass                *klass);
246
247 void
248 mono_debug_close_mono_symbol_file  (MonoSymbolFile           *symfile);
249
250 gchar *
251 mono_debug_find_source_location    (MonoSymbolFile           *symfile,
252                                     MonoMethod               *method,
253                                     guint32                   offset,
254                                     guint32                  *line_number);
255
256 MonoDebugMethodInfo *
257 mono_debug_find_method             (MonoSymbolFile           *symfile,
258                                     MonoMethod               *method);
259
260 MonoReflectionMethod *
261 ves_icall_MonoDebugger_GetMethod   (MonoReflectionAssembly   *assembly,
262                                     guint32                   token);
263
264 int
265 ves_icall_MonoDebugger_GetMethodToken (MonoReflectionAssembly   *assembly,
266                                        MonoReflectionMethod     *method);
267
268 MonoReflectionType *
269 ves_icall_MonoDebugger_GetLocalTypeFromSignature (MonoReflectionAssembly *assembly,
270                                                   MonoArray              *signature);
271
272 MonoReflectionType *
273 ves_icall_MonoDebugger_GetType     (MonoReflectionAssembly   *assembly,
274                                     guint32                   token);
275
276 #endif /* __MONO_SYMFILE_H__ */
277