Merge pull request #948 from ermshiperete/bug-xamarin-2394
[mono.git] / mono / metadata / debug-mono-symfile.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  * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
5  */
6
7 #ifndef __MONO_DEBUG_MONO_SYMFILE_H__
8 #define __MONO_DEBUG_MONO_SYMFILE_H__
9
10 #include <glib.h>
11 #include <mono/metadata/class.h>
12 #include <mono/metadata/reflection.h>
13 #include <mono/metadata/mono-debug.h>
14
15 typedef struct MonoSymbolFileOffsetTable        MonoSymbolFileOffsetTable;
16 typedef struct MonoSymbolFileLineNumberEntry    MonoSymbolFileLineNumberEntry;
17 typedef struct MonoSymbolFileMethodAddress      MonoSymbolFileMethodAddress;
18 typedef struct MonoSymbolFileDynamicTable       MonoSymbolFileDynamicTable;
19 typedef struct MonoSymbolFileSourceEntry        MonoSymbolFileSourceEntry;
20 typedef struct MonoSymbolFileMethodEntry        MonoSymbolFileMethodEntry;
21
22 /* Keep in sync with OffsetTable in mcs/class/Mono.CSharp.Debugger/MonoSymbolTable.cs */
23 struct MonoSymbolFileOffsetTable {
24         uint32_t _total_file_size;
25         uint32_t _data_section_offset;
26         uint32_t _data_section_size;
27         uint32_t _compile_unit_count;
28         uint32_t _compile_unit_table_offset;
29         uint32_t _compile_unit_table_size;
30         uint32_t _source_count;
31         uint32_t _source_table_offset;
32         uint32_t _source_table_size;
33         uint32_t _method_count;
34         uint32_t _method_table_offset;
35         uint32_t _method_table_size;
36         uint32_t _type_count;
37         uint32_t _anonymous_scope_count;
38         uint32_t _anonymous_scope_table_offset;
39         uint32_t _anonymous_scope_table_size;
40         uint32_t _line_number_table_line_base;
41         uint32_t _line_number_table_line_range;
42         uint32_t _line_number_table_opcode_base;
43         uint32_t _is_aspx_source;
44 };
45
46 struct MonoSymbolFileSourceEntry {
47         uint32_t _index;
48         uint32_t _data_offset;
49 };
50
51 struct MonoSymbolFileMethodEntry {
52         uint32_t _token;
53         uint32_t _data_offset;
54         uint32_t _line_number_table;
55 };
56
57 struct MonoSymbolFileMethodAddress {
58         uint32_t size;
59         const uint8_t *start_address;
60         const uint8_t *end_address;
61         const uint8_t *method_start_address;
62         const uint8_t *method_end_address;
63         const uint8_t *wrapper_address;
64         uint32_t has_this;
65         uint32_t num_params;
66         uint32_t variable_table_offset;
67         uint32_t type_table_offset;
68         uint32_t num_line_numbers;
69         uint32_t line_number_offset;
70         uint8_t data [MONO_ZERO_LEN_ARRAY];
71 };
72
73 struct _MonoDebugMethodInfo {
74         MonoMethod *method;
75         MonoDebugHandle *handle;
76         uint32_t index;
77         uint32_t data_offset;
78         uint32_t lnt_offset;
79 };
80
81 typedef struct {
82         int parent;
83         int type;
84         /* IL offsets */
85         int start_offset, end_offset;
86 } MonoDebugCodeBlock;
87
88 typedef struct {
89         char *name;
90         int index;
91         /* Might be null for the main scope */
92         MonoDebugCodeBlock *block;
93 } MonoDebugLocalVar;
94
95 /*
96  * Information about local variables retrieved from a symbol file.
97  */
98 struct _MonoDebugLocalsInfo {
99         int num_locals;
100         MonoDebugLocalVar *locals;
101         int num_blocks;
102         MonoDebugCodeBlock *code_blocks;
103 };
104
105 struct _MonoDebugLineNumberEntry {
106         uint32_t il_offset;
107         uint32_t native_offset;
108 };
109
110 /*
111  * Information about a source file retrieved from a symbol file.
112  */
113 typedef struct {
114         char *source_file;
115         /* 16 byte long */
116         guint8 *guid, *hash;
117 } MonoDebugSourceInfo;
118
119 #define MONO_SYMBOL_FILE_MAJOR_VERSION          50
120 #define MONO_SYMBOL_FILE_MINOR_VERSION          0
121 #define MONO_SYMBOL_FILE_MAGIC                  0x45e82623fd7fa614ULL
122
123 MONO_BEGIN_DECLS
124
125 MONO_API MonoSymbolFile *
126 mono_debug_open_mono_symbols       (MonoDebugHandle          *handle,
127                                     const uint8_t            *raw_contents,
128                                     int                       size,
129                                     mono_bool                 in_the_debugger);
130
131 MONO_API void
132 mono_debug_close_mono_symbol_file  (MonoSymbolFile           *symfile);
133
134 MONO_API mono_bool
135 mono_debug_symfile_is_loaded       (MonoSymbolFile           *symfile);
136
137 MONO_API MonoDebugSourceLocation *
138 mono_debug_symfile_lookup_location (MonoDebugMethodInfo      *minfo,
139                                     uint32_t                  offset);
140
141 MONO_API void
142 mono_debug_symfile_free_location   (MonoDebugSourceLocation  *location);
143
144 int32_t
145 _mono_debug_address_from_il_offset (MonoDebugMethodJitInfo   *jit,
146                                     uint32_t                  il_offset);
147
148 MONO_API MonoDebugMethodInfo *
149 mono_debug_symfile_lookup_method   (MonoDebugHandle          *handle,
150                                     MonoMethod               *method);
151
152 MONO_API MonoDebugLocalsInfo*
153 mono_debug_symfile_lookup_locals (MonoDebugMethodInfo *minfo);
154
155 MONO_API void
156 mono_debug_symfile_free_locals (MonoDebugLocalsInfo *info);
157
158 MONO_API void
159 mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_file, int *n_il_offsets, int **il_offsets, int **line_numbers);
160
161 MONO_API void
162 mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **source_file, GPtrArray **source_file_list, int *n_il_offsets, int **il_offsets, int **line_numbers, int **column_numbers, int **source_files, int **end_line_numbers, int **end_column_numbers);
163
164 MONO_END_DECLS
165
166 #endif /* __MONO_SYMFILE_H__ */
167