2
// symbolwriter.cs: The debug symbol writer
4
// Authors: Martin Baulig (martin@ximian.com)
5
// Marek Safar (marek.safar@gmail.com)
7
// Dual licensed under the terms of the MIT X11 or GNU GPL
9
// Copyright 2003 Ximian, Inc (http://www.ximian.com)
10
// Copyright 2004-2010 Novell, Inc
16
using IKVM.Reflection;
17
using IKVM.Reflection.Emit;
19
using System.Reflection;
20
using System.Reflection.Emit;
23
using Mono.CompilerServices.SymbolWriter;
27
static class SymbolWriter
29
#if !NET_4_0 && !STATIC
30
delegate int GetILOffsetFunc (ILGenerator ig);
31
static GetILOffsetFunc get_il_offset_func;
33
delegate Guid GetGuidFunc (ModuleBuilder mb);
34
static GetGuidFunc get_guid_func;
36
static void Initialize ()
38
var mi = typeof (ILGenerator).GetMethod (
39
"Mono_GetCurrentOffset",
40
BindingFlags.Static | BindingFlags.NonPublic);
42
throw new MissingMethodException ("Mono_GetCurrentOffset");
44
get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
45
typeof (GetILOffsetFunc), mi);
47
mi = typeof (ModuleBuilder).GetMethod (
49
BindingFlags.Static | BindingFlags.NonPublic);
51
throw new MissingMethodException ("Mono_GetGuid");
53
get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
54
typeof (GetGuidFunc), mi);
58
static int GetILOffset (ILGenerator ig)
63
if (get_il_offset_func == null)
66
return get_il_offset_func (ig);
70
public static Guid GetGuid (ModuleBuilder module)
73
return module.ModuleVersionId;
75
if (get_guid_func == null)
78
return get_guid_func (module);
82
public static bool HasSymbolWriter {
83
get { return symwriter != null; }
86
public static MonoSymbolWriter symwriter;
88
public static void DefineLocalVariable (string name, LocalBuilder builder)
90
if (symwriter != null) {
91
symwriter.DefineLocalVariable (builder.LocalIndex, name);
95
public static SourceMethodBuilder OpenMethod (ICompileUnit file, IMethodDef method)
97
if (symwriter != null)
98
return symwriter.OpenMethod (file, -1 /* Not used */, method);
103
public static void CloseMethod ()
105
if (symwriter != null)
106
symwriter.CloseMethod ();
109
public static int OpenScope (ILGenerator ig)
111
if (symwriter != null) {
112
int offset = GetILOffset (ig);
113
return symwriter.OpenScope (offset);
119
public static void CloseScope (ILGenerator ig)
121
if (symwriter != null) {
122
int offset = GetILOffset (ig);
123
symwriter.CloseScope (offset);
127
public static void DefineAnonymousScope (int id)
129
if (symwriter != null)
130
symwriter.DefineAnonymousScope (id);
133
public static void DefineScopeVariable (int scope, LocalBuilder builder)
135
if (symwriter != null) {
136
symwriter.DefineScopeVariable (scope, builder.LocalIndex);
140
public static void DefineScopeVariable (int scope)
142
if (symwriter != null)
143
symwriter.DefineScopeVariable (scope, -1);
146
public static void DefineCapturedLocal (int scope_id, string name,
147
string captured_name)
149
if (symwriter != null)
150
symwriter.DefineCapturedLocal (scope_id, name, captured_name);
153
public static void DefineCapturedParameter (int scope_id, string name,
154
string captured_name)
156
if (symwriter != null)
157
symwriter.DefineCapturedParameter (scope_id, name, captured_name);
160
public static void DefineCapturedThis (int scope_id, string captured_name)
162
if (symwriter != null)
163
symwriter.DefineCapturedThis (scope_id, captured_name);
166
public static void DefineCapturedScope (int scope_id, int id, string captured_name)
168
if (symwriter != null)
169
symwriter.DefineCapturedScope (scope_id, id, captured_name);
172
public static void OpenCompilerGeneratedBlock (EmitContext ec)
174
if (symwriter != null) {
175
int offset = GetILOffset (ec.ig);
176
symwriter.OpenCompilerGeneratedBlock (offset);
180
public static void CloseCompilerGeneratedBlock (EmitContext ec)
182
if (symwriter != null) {
183
int offset = GetILOffset (ec.ig);
184
symwriter.CloseCompilerGeneratedBlock (offset);
188
public static void StartIteratorBody (EmitContext ec)
190
if (symwriter != null) {
191
int offset = GetILOffset (ec.ig);
192
symwriter.StartIteratorBody (offset);
196
public static void EndIteratorBody (EmitContext ec)
198
if (symwriter != null) {
199
int offset = GetILOffset (ec.ig);
200
symwriter.EndIteratorBody (offset);
204
public static void StartIteratorDispatcher (EmitContext ec)
206
if (symwriter != null) {
207
int offset = GetILOffset (ec.ig);
208
symwriter.StartIteratorDispatcher (offset);
212
public static void EndIteratorDispatcher (EmitContext ec)
214
if (symwriter != null) {
215
int offset = GetILOffset (ec.ig);
216
symwriter.EndIteratorDispatcher (offset);
220
public static void MarkSequencePoint (ILGenerator ig, Location loc)
222
if (symwriter != null) {
223
SourceFileEntry file = loc.SourceFile.SourceFileEntry;
224
int offset = GetILOffset (ig);
225
symwriter.MarkSequencePoint (offset, file, loc.Row, loc.Column, false);
229
public static void Reset ()