2005-06-29 Miguel de Icaza <miguel@ximian.com>
[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>
10 #include <mono/metadata/image.h>
11 #include <mono/metadata/appdomain.h>
12
13 typedef struct _MonoSymbolTable                 MonoSymbolTable;
14
15 typedef struct _MonoSymbolFile                  MonoSymbolFile;
16 typedef struct _MonoSymbolFilePriv              MonoSymbolFilePriv;
17
18 typedef struct _MonoDebugHandle                 MonoDebugHandle;
19 typedef struct _MonoDebugHandlePriv             MonoDebugHandlePriv;
20
21 typedef struct _MonoDebugLineNumberEntry        MonoDebugLineNumberEntry;
22 typedef struct _MonoDebugLexicalBlockEntry      MonoDebugLexicalBlockEntry;
23
24 typedef struct _MonoDebugVarInfo                MonoDebugVarInfo;
25 typedef struct _MonoDebugMethodJitInfo          MonoDebugMethodJitInfo;
26 typedef struct _MonoDebugMethodAddress          MonoDebugMethodAddress;
27 typedef struct _MonoDebugClassEntry             MonoDebugClassEntry;
28
29 typedef struct _MonoDebuggerMetadataInfo        MonoDebuggerMetadataInfo;
30
31 typedef enum {
32         MONO_DEBUG_FORMAT_NONE,
33         MONO_DEBUG_FORMAT_MONO,
34         MONO_DEBUG_FORMAT_DEBUGGER
35 } MonoDebugFormat;
36
37 typedef enum {
38         MONO_DEBUGGER_TYPE_KIND_UNKNOWN = 1,
39         MONO_DEBUGGER_TYPE_KIND_FUNDAMENTAL,
40         MONO_DEBUGGER_TYPE_KIND_STRING,
41         MONO_DEBUGGER_TYPE_KIND_SZARRAY,
42         MONO_DEBUGGER_TYPE_KIND_ARRAY,
43         MONO_DEBUGGER_TYPE_KIND_POINTER,
44         MONO_DEBUGGER_TYPE_KIND_ENUM,
45         MONO_DEBUGGER_TYPE_KIND_OBJECT,
46         MONO_DEBUGGER_TYPE_KIND_STRUCT,
47         MONO_DEBUGGER_TYPE_KIND_CLASS,
48         MONO_DEBUGGER_TYPE_KIND_CLASS_INFO,
49         MONO_DEBUGGER_TYPE_KIND_REFERENCE
50 } MonoDebuggerTypeKind;
51
52 struct _MonoSymbolTable {
53         guint64 magic;
54         guint32 version;
55         guint32 total_size;
56
57         /*
58          * Corlib and metadata info.
59          */
60         MonoDebugHandle *corlib;
61         MonoDebuggerMetadataInfo *metadata_info;
62
63         /*
64          * The symbol files.
65          */
66         MonoDebugHandle **symbol_files;
67         guint32 num_symbol_files;
68
69         /*
70          * Data table.
71          * This is intentionally not a GPtrArray to make it more easy to
72          * read for the debugger.  The `data_tables' field contains
73          * `num_data_tables' pointers to continuous memory areas.
74          *
75          * The data table is basically a big continuous blob, but we need
76          * to split it up into pieces because we don't know the total size
77          * in advance and using g_realloc() doesn't work because that may
78          * reallocate the block to a different address.
79          */
80         guint32 num_data_tables;
81         gpointer *data_tables;
82         /*
83          * Current data table.
84          * The `current_data_table' points to a blob of `current_data_table_size'
85          * bytes.
86          */
87         gpointer current_data_table;
88         guint32 current_data_table_size;
89         /*
90          * The offset in the `current_data_table'.
91          */
92         guint32 current_data_table_offset;
93 };
94
95 typedef enum {
96         MONO_DEBUG_DATA_ITEM_UNKNOWN            = 0,
97         MONO_DEBUG_DATA_ITEM_METHOD,
98         MONO_DEBUG_DATA_ITEM_CLASS
99 } MonoDebugDataItemType;
100
101 struct _MonoDebugHandle {
102         guint32 index;
103         const char *image_file;
104         MonoImage *image;
105         MonoSymbolFile *symfile;
106         MonoDebugHandlePriv *_priv;
107 };
108
109 struct _MonoDebugMethodJitInfo {
110         MonoDebugMethodAddress *address;
111         const guint8 *code_start;
112         guint32 code_size;
113         guint32 prologue_end;
114         guint32 epilogue_begin;
115         const guint8 *wrapper_addr;
116         guint32 num_line_numbers;
117         MonoDebugLineNumberEntry *line_numbers;
118         guint32 num_lexical_blocks;
119         MonoDebugLexicalBlockEntry *lexical_blocks;
120         guint32 num_params;
121         MonoDebugVarInfo *this_var;
122         MonoDebugVarInfo *params;
123         guint32 num_locals;
124         MonoDebugVarInfo *locals;
125 };
126
127 struct _MonoDebugMethodAddress {
128         guint32 size;
129         guint32 symfile_id;
130         guint32 domain_id;
131         guint32 method_id;
132         guint32 code_size;
133         guint32 dummy;
134         const guint8 *code_start;
135         const guint8 *wrapper_addr;
136         MonoDebugMethodJitInfo *jit;
137         guint8 data [MONO_ZERO_LEN_ARRAY];
138 };
139
140 struct _MonoDebugClassEntry {
141         guint32 size;
142         guint32 symfile_id;
143         guint8 data [MONO_ZERO_LEN_ARRAY];
144 };
145
146 /*
147  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
148  * where the variable is actually stored.
149  *
150  * See relocate_variable() in debug-symfile.c for more info.
151  */
152 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
153
154 /* The variable is in register "index". */
155 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0
156
157 /* The variable is at offset "offset" from register "index". */
158 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET           0x10000000
159
160 /* The variable is in the two registers "offset" and "index". */
161 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
162
163 struct _MonoDebugVarInfo {
164         guint32 index;
165         guint32 offset;
166         guint32 size;
167         guint32 begin_scope;
168         guint32 end_scope;
169 };
170
171 #define MONO_DEBUGGER_VERSION                           50
172 #define MONO_DEBUGGER_MAGIC                             0x7aff65af4253d427ULL
173
174 extern MonoSymbolTable *mono_symbol_table;
175 extern MonoDebugFormat mono_debug_format;
176 extern GHashTable *mono_debug_handles;
177
178 void mono_debug_init (MonoDebugFormat format);
179 void mono_debug_init_1 (MonoDomain *domain);
180 void mono_debug_init_2 (MonoAssembly *assembly);
181 void mono_debug_cleanup (void);
182
183 MonoDebugMethodAddress *mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit,
184                                                MonoDomain *domain);
185 MonoDebugMethodJitInfo *mono_debug_read_method (MonoDebugMethodAddress *address);
186 void mono_debug_free_method_jit_info (MonoDebugMethodJitInfo *jit);
187 gchar *mono_debug_source_location_from_address (MonoMethod *method, guint32 address,
188                                                 guint32 *line_number, MonoDomain *domain);
189 gchar *mono_debug_source_location_from_il_offset (MonoMethod *method, guint32 offset,
190                                                   guint32 *line_number);
191 gint32 mono_debug_il_offset_from_address (MonoMethod *method, gint32 address, MonoDomain *domain);
192 gint32 mono_debug_address_from_il_offset (MonoMethod *method, gint32 il_offset, MonoDomain *domain);
193
194 #endif /* __MONO_DEBUG_H__ */