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