In .:
[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 typedef struct _MonoDebugDataTable              MonoDebugDataTable;
15
16 typedef struct _MonoSymbolFile                  MonoSymbolFile;
17
18 typedef struct _MonoDebugHandle                 MonoDebugHandle;
19
20 typedef struct _MonoDebugLineNumberEntry        MonoDebugLineNumberEntry;
21 typedef struct _MonoDebugLexicalBlockEntry      MonoDebugLexicalBlockEntry;
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         gconstpointer data;
48 };
49
50 struct _MonoSymbolTable {
51         guint64 magic;
52         guint32 version;
53         guint32 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         guint32 index;
70         char *image_file;
71         MonoImage *image;
72         MonoDebugDataTable *type_table;
73         MonoSymbolFile *symfile;
74 };
75
76 struct _MonoDebugMethodJitInfo {
77         const guint8 *code_start;
78         guint32 code_size;
79         guint32 prologue_end;
80         guint32 epilogue_begin;
81         const guint8 *wrapper_addr;
82         guint32 num_line_numbers;
83         MonoDebugLineNumberEntry *line_numbers;
84         guint32 num_lexical_blocks;
85         MonoDebugLexicalBlockEntry *lexical_blocks;
86         guint32 num_params;
87         MonoDebugVarInfo *this_var;
88         MonoDebugVarInfo *params;
89         guint32 num_locals;
90         MonoDebugVarInfo *locals;
91 };
92
93 struct _MonoDebugMethodAddressList {
94         guint32 size;
95         guint32 count;
96         guint8 data [MONO_ZERO_LEN_ARRAY];
97 };
98
99 struct _MonoDebugSourceLocation {
100         gchar *source_file;
101         guint32 row, column;
102         guint32 il_offset;
103 };
104
105 /*
106  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
107  * where the variable is actually stored.
108  *
109  * See relocate_variable() in debug-symfile.c for more info.
110  */
111 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
112
113 /* The variable is in register "index". */
114 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0
115
116 /* The variable is at offset "offset" from register "index". */
117 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET           0x10000000
118
119 /* The variable is in the two registers "offset" and "index". */
120 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
121
122 struct _MonoDebugVarInfo {
123         guint32 index;
124         guint32 offset;
125         guint32 size;
126         guint32 begin_scope;
127         guint32 end_scope;
128         MonoType *type;
129 };
130
131 #define MONO_DEBUGGER_VERSION                           66
132 #define MONO_DEBUGGER_MAGIC                             0x7aff65af4253d427ULL
133
134 extern MonoSymbolTable *mono_symbol_table;
135 extern MonoDebugFormat mono_debug_format;
136 extern GHashTable *mono_debug_handles;
137 extern gint32 mono_debug_debugger_version;
138
139 void mono_debug_list_add (MonoDebugList **list, gconstpointer data);
140 void mono_debug_list_remove (MonoDebugList **list, gconstpointer data);
141
142 void mono_debug_init (MonoDebugFormat format);
143 void mono_debug_open_image_from_memory (MonoImage *image, const guint8 *raw_contents, int size);
144 void mono_debug_cleanup (void);
145
146 void mono_debug_close_image (MonoImage *image);
147
148 void mono_debug_domain_unload (MonoDomain *domain);
149 void mono_debug_domain_create (MonoDomain *domain);
150
151 gboolean mono_debug_using_mono_debugger (void);
152
153 MonoDebugMethodAddress *
154 mono_debug_add_method (MonoMethod *method, MonoDebugMethodJitInfo *jit, MonoDomain *domain);
155
156 MonoDebugMethodInfo *
157 mono_debug_lookup_method (MonoMethod *method);
158
159 MonoDebugMethodAddressList *
160 mono_debug_lookup_method_addresses (MonoMethod *method);
161
162 MonoDebugMethodJitInfo*
163 mono_debug_find_method (MonoMethod *method, MonoDomain *domain);
164
165 void
166 mono_debug_add_delegate_trampoline (gpointer code, int size);
167
168 /*
169  * Line number support.
170  */
171
172 MonoDebugSourceLocation *
173 mono_debug_lookup_source_location (MonoMethod *method, guint32 address, MonoDomain *domain);
174
175 void
176 mono_debug_free_source_location (MonoDebugSourceLocation *location);
177
178 gchar *
179 mono_debug_print_stack_frame (MonoMethod *method, guint32 native_offset, MonoDomain *domain);
180
181 /*
182  * Mono Debugger support functions
183  *
184  * These methods are used by the JIT while running inside the Mono Debugger.
185  */
186
187 int             mono_debugger_method_has_breakpoint       (MonoMethod *method);
188 int             mono_debugger_insert_breakpoint           (const gchar *method_name, gboolean include_namespace);
189 gboolean        mono_debugger_unhandled_exception         (gpointer addr, gpointer stack, MonoObject *exc);
190 void            mono_debugger_handle_exception            (gpointer addr, gpointer stack, MonoObject *exc);
191 gboolean        mono_debugger_throw_exception             (gpointer addr, gpointer stack, MonoObject *exc);
192
193 #endif /* __MONO_DEBUG_H__ */