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, int ns_id,
98 if (symwriter != null)
99 return symwriter.OpenMethod (file, ns_id, method);
104 public static void CloseMethod ()
106 if (symwriter != null)
107 symwriter.CloseMethod ();
110 public static int OpenScope (ILGenerator ig)
112 if (symwriter != null) {
113 int offset = GetILOffset (ig);
114 return symwriter.OpenScope (offset);
120 public static void CloseScope (ILGenerator ig)
122 if (symwriter != null) {
123 int offset = GetILOffset (ig);
124 symwriter.CloseScope (offset);
128 public static int DefineNamespace (string name, CompileUnitEntry source,
129 string[] using_clauses, int parent)
131 if (symwriter != null)
132 return symwriter.DefineNamespace (name, source, using_clauses, parent);
137 public static void DefineAnonymousScope (int id)
139 if (symwriter != null)
140 symwriter.DefineAnonymousScope (id);
143 public static void DefineScopeVariable (int scope, LocalBuilder builder)
145 if (symwriter != null) {
146 symwriter.DefineScopeVariable (scope, builder.LocalIndex);
150 public static void DefineScopeVariable (int scope)
152 if (symwriter != null)
153 symwriter.DefineScopeVariable (scope, -1);
156 public static void DefineCapturedLocal (int scope_id, string name,
157 string captured_name)
159 if (symwriter != null)
160 symwriter.DefineCapturedLocal (scope_id, name, captured_name);
163 public static void DefineCapturedParameter (int scope_id, string name,
164 string captured_name)
166 if (symwriter != null)
167 symwriter.DefineCapturedParameter (scope_id, name, captured_name);
170 public static void DefineCapturedThis (int scope_id, string captured_name)
172 if (symwriter != null)
173 symwriter.DefineCapturedThis (scope_id, captured_name);
176 public static void DefineCapturedScope (int scope_id, int id, string captured_name)
178 if (symwriter != null)
179 symwriter.DefineCapturedScope (scope_id, id, captured_name);
182 public static void OpenCompilerGeneratedBlock (EmitContext ec)
184 if (symwriter != null) {
185 int offset = GetILOffset (ec.ig);
186 symwriter.OpenCompilerGeneratedBlock (offset);
190 public static void CloseCompilerGeneratedBlock (EmitContext ec)
192 if (symwriter != null) {
193 int offset = GetILOffset (ec.ig);
194 symwriter.CloseCompilerGeneratedBlock (offset);
198 public static void StartIteratorBody (EmitContext ec)
200 if (symwriter != null) {
201 int offset = GetILOffset (ec.ig);
202 symwriter.StartIteratorBody (offset);
206 public static void EndIteratorBody (EmitContext ec)
208 if (symwriter != null) {
209 int offset = GetILOffset (ec.ig);
210 symwriter.EndIteratorBody (offset);
214 public static void StartIteratorDispatcher (EmitContext ec)
216 if (symwriter != null) {
217 int offset = GetILOffset (ec.ig);
218 symwriter.StartIteratorDispatcher (offset);
222 public static void EndIteratorDispatcher (EmitContext ec)
224 if (symwriter != null) {
225 int offset = GetILOffset (ec.ig);
226 symwriter.EndIteratorDispatcher (offset);
230 public static void MarkSequencePoint (ILGenerator ig, Location loc)
232 if (symwriter != null) {
233 SourceFileEntry file = loc.SourceFile.SourceFileEntry;
234 int offset = GetILOffset (ig);
235 symwriter.MarkSequencePoint (
236 offset, file, loc.Row, loc.Column, loc.Hidden);
240 public static void Reset ()