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
14 using System.Reflection;
15 using System.Reflection.Emit;
17 using Mono.CompilerServices.SymbolWriter;
21 static class SymbolWriter
24 delegate int GetILOffsetFunc (ILGenerator ig);
25 static GetILOffsetFunc get_il_offset_func;
27 delegate Guid GetGuidFunc (ModuleBuilder mb);
28 static GetGuidFunc get_guid_func;
30 static void Initialize ()
32 var mi = typeof (ILGenerator).GetMethod (
33 "Mono_GetCurrentOffset",
34 BindingFlags.Static | BindingFlags.NonPublic);
36 throw new MissingMethodException ("Mono_GetCurrentOffset");
38 get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
39 typeof (GetILOffsetFunc), mi);
41 mi = typeof (ModuleBuilder).GetMethod (
43 BindingFlags.Static | BindingFlags.NonPublic);
45 throw new MissingMethodException ("Mono_GetGuid");
47 get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
48 typeof (GetGuidFunc), mi);
52 static int GetILOffset (ILGenerator ig)
57 if (get_il_offset_func == null)
60 return get_il_offset_func (ig);
64 public static Guid GetGuid (ModuleBuilder module)
67 return module.ModuleVersionId;
69 if (get_guid_func == null)
72 return get_guid_func (module);
76 public static bool HasSymbolWriter {
77 get { return symwriter != null; }
80 public static MonoSymbolWriter symwriter;
82 public static void DefineLocalVariable (string name, LocalBuilder builder)
84 if (symwriter != null) {
85 symwriter.DefineLocalVariable (builder.LocalIndex, name);
89 public static SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id,
92 if (symwriter != null)
93 return symwriter.OpenMethod (file, ns_id, method);
98 public static void CloseMethod ()
100 if (symwriter != null)
101 symwriter.CloseMethod ();
104 public static int OpenScope (ILGenerator ig)
106 if (symwriter != null) {
107 int offset = GetILOffset (ig);
108 return symwriter.OpenScope (offset);
114 public static void CloseScope (ILGenerator ig)
116 if (symwriter != null) {
117 int offset = GetILOffset (ig);
118 symwriter.CloseScope (offset);
122 public static int DefineNamespace (string name, CompileUnitEntry source,
123 string[] using_clauses, int parent)
125 if (symwriter != null)
126 return symwriter.DefineNamespace (name, source, using_clauses, parent);
131 public static void DefineAnonymousScope (int id)
133 if (symwriter != null)
134 symwriter.DefineAnonymousScope (id);
137 public static void DefineScopeVariable (int scope, LocalBuilder builder)
139 if (symwriter != null) {
140 symwriter.DefineScopeVariable (scope, builder.LocalIndex);
144 public static void DefineScopeVariable (int scope)
146 if (symwriter != null)
147 symwriter.DefineScopeVariable (scope, -1);
150 public static void DefineCapturedLocal (int scope_id, string name,
151 string captured_name)
153 if (symwriter != null)
154 symwriter.DefineCapturedLocal (scope_id, name, captured_name);
157 public static void DefineCapturedParameter (int scope_id, string name,
158 string captured_name)
160 if (symwriter != null)
161 symwriter.DefineCapturedParameter (scope_id, name, captured_name);
164 public static void DefineCapturedThis (int scope_id, string captured_name)
166 if (symwriter != null)
167 symwriter.DefineCapturedThis (scope_id, captured_name);
170 public static void DefineCapturedScope (int scope_id, int id, string captured_name)
172 if (symwriter != null)
173 symwriter.DefineCapturedScope (scope_id, id, captured_name);
176 public static void OpenCompilerGeneratedBlock (EmitContext ec)
178 if (symwriter != null) {
179 int offset = GetILOffset (ec.ig);
180 symwriter.OpenCompilerGeneratedBlock (offset);
184 public static void CloseCompilerGeneratedBlock (EmitContext ec)
186 if (symwriter != null) {
187 int offset = GetILOffset (ec.ig);
188 symwriter.CloseCompilerGeneratedBlock (offset);
192 public static void StartIteratorBody (EmitContext ec)
194 if (symwriter != null) {
195 int offset = GetILOffset (ec.ig);
196 symwriter.StartIteratorBody (offset);
200 public static void EndIteratorBody (EmitContext ec)
202 if (symwriter != null) {
203 int offset = GetILOffset (ec.ig);
204 symwriter.EndIteratorBody (offset);
208 public static void StartIteratorDispatcher (EmitContext ec)
210 if (symwriter != null) {
211 int offset = GetILOffset (ec.ig);
212 symwriter.StartIteratorDispatcher (offset);
216 public static void EndIteratorDispatcher (EmitContext ec)
218 if (symwriter != null) {
219 int offset = GetILOffset (ec.ig);
220 symwriter.EndIteratorDispatcher (offset);
224 public static void MarkSequencePoint (ILGenerator ig, Location loc)
226 if (symwriter != null) {
227 SourceFileEntry file = loc.SourceFile.SourceFileEntry;
228 int offset = GetILOffset (ig);
229 symwriter.MarkSequencePoint (
230 offset, file, loc.Row, loc.Column, loc.Hidden);
234 public static void Reset ()