2002-07-08 Radek Doulik <rodo@ximian.com>
[mono.git] / mono / metadata / debug-symfile.h
1 #ifndef __MONO_DEBUG_SYMFILE_H__
2 #define __MONO_DEBUG_SYMFILE_H__
3
4 #include <glib.h>
5 #include <mono/metadata/class.h>
6 #include <mono/metadata/reflection.h>
7
8 typedef struct MonoDebugSymbolFile              MonoDebugSymbolFile;
9 typedef struct MonoDebugSymbolFileSection       MonoDebugSymbolFileSection;
10 typedef struct MonoDebugMethodInfo              MonoDebugMethodInfo;
11 typedef struct MonoDebugVarInfo                 MonoDebugVarInfo;
12 typedef struct MonoDebugILOffsetInfo            MonoDebugILOffsetInfo;
13 typedef struct MonoDebugLineNumberBlock         MonoDebugLineNumberBlock;
14
15 /* Machine dependent information about a method.
16  *
17  * This structure is created by the MonoDebugMethodInfoFunc callback of
18  * mono_debug_update_symbol_file (). */
19 struct MonoDebugMethodInfo {
20         MonoMethod *method;
21         char *code_start;
22         guint32 code_size;
23         guint32 num_params;
24         MonoDebugVarInfo *this_var;
25         MonoDebugVarInfo *params;
26         guint32 num_locals;
27         MonoDebugVarInfo *locals;
28         guint32 num_il_offsets;
29         MonoDebugILOffsetInfo *il_offsets;
30         guint32 prologue_end;
31         guint32 epilogue_begin;
32         gpointer _priv;
33 };
34
35 /*
36  * These bits of the MonoDebugLocalInfo's "index" field are flags specifying
37  * where the variable is actually stored.
38  *
39  * See relocate_variable() in debug-symfile.c for more info.
40  */
41 #define MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS               0xf0000000
42
43 /* If "index" is zero, the variable is at stack offset "offset". */
44 #define MONO_DEBUG_VAR_ADDRESS_MODE_STACK               0
45
46 /* The variable is in the register whose number is contained in bits 0..4 of the
47  * "index" field plus an offset of "offset" (which can be zero).
48  */
49 #define MONO_DEBUG_VAR_ADDRESS_MODE_REGISTER            0x10000000
50
51 /* The variables in in the two registers whose numbers are contained in bits 0..4
52  * and 5..9 of the "index" field plus an offset of "offset" (which can be zero).
53  */
54 #define MONO_DEBUG_VAR_ADDRESS_MODE_TWO_REGISTERS       0x20000000
55
56 struct MonoDebugVarInfo {
57         guint32 index;
58         guint32 offset;
59         guint32 begin_scope;
60         guint32 end_scope;
61 };
62
63 struct MonoDebugILOffsetInfo {
64         guint32 offset;
65         guint32 address;
66 };
67
68 struct MonoDebugLineNumberBlock {
69         guint32 token;
70         const char *source_file;
71         guint32 start_line;
72         guint32 file_offset;
73 };
74
75 struct MonoDebugSymbolFile {
76         int fd;
77         char *file_name;
78         MonoImage *image;
79         /* Pointer to the mmap()ed contents of the file. */
80         char *raw_contents;
81         size_t raw_contents_size;
82         /* Array of MONO_DEBUG_SYMBOL_SECTION_MAX elements. */
83         MonoDebugSymbolFileSection *section_offsets;
84         GHashTable *line_number_table;
85         guint32 num_types;
86         MonoClass **type_table;
87         gpointer user_data;
88 };
89
90 struct MonoDebugSymbolFileSection {
91         int type;
92         gulong file_offset;
93         gulong size;
94 };
95
96 #define MONO_DEBUG_SYMBOL_FILE_VERSION                  15
97
98 /* Keep in sync with Mono.CSharp.Debugger.MonoDwarfFileWriter.Section */
99 #define MONO_DEBUG_SYMBOL_SECTION_DEBUG_INFO            0x01
100 #define MONO_DEBUG_SYMBOL_SECTION_DEBUG_ABBREV          0x02
101 #define MONO_DEBUG_SYMBOL_SECTION_DEBUG_LINE            0x03
102 #define MONO_DEBUG_SYMBOL_SECTION_MONO_RELOC_TABLE      0x04
103 #define MONO_DEBUG_SYMBOL_SECTION_MONO_LINE_NUMBERS     0x05
104 #define MONO_DEBUG_SYMBOL_SECTION_MONO_SYMBOL_TABLE     0x06
105
106 #define MONO_DEBUG_SYMBOL_SECTION_MAX                   0x07
107
108 /* Tries to load `filename' as a debugging information file, if `emit_warnings" is set,
109  * use g_warning() to signal error messages on failure, otherwise silently return NULL. */
110 MonoDebugSymbolFile *mono_debug_open_symbol_file   (MonoImage                 *image,
111                                                     const char                *filename,
112                                                     gboolean                   emit_warnings);
113
114 /* This callback function needs to return a MonoDebugMethodInfo structure containing the
115  * machine-dependent information about method associated with the metadata_token.
116  * It's highly recommended to cache the generated data since this function can be called
117  * several times per method. */
118 typedef MonoDebugMethodInfo * (*MonoDebugMethodInfoFunc) (MonoDebugSymbolFile *symbol_file,
119                                                           guint32              metadata_token,
120                                                           gpointer             user_data);
121
122 void    mono_debug_update_symbol_file (MonoDebugSymbolFile      *symbol_file,
123                                        MonoDebugMethodInfoFunc   method_info_func,
124                                        gpointer                  user_data);
125
126 void    mono_debug_close_symbol_file  (MonoDebugSymbolFile      *symbol_file);
127
128 gchar *
129 mono_debug_find_source_location (MonoDebugSymbolFile *symfile, MonoMethod *method, guint32 offset,
130                                  guint32 *line_number);
131
132
133 #endif /* __MONO_DEBUG_SYMFILE_H__ */
134