1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
//
// symbolwriter.cs: The debug symbol writer
//
// Authors: Martin Baulig (martin@ximian.com)
// Marek Safar (marek.safar@gmail.com)
//
// Dual licensed under the terms of the MIT X11 or GNU GPL
//
// Copyright 2003 Ximian, Inc (http://www.ximian.com)
// Copyright 2004-2010 Novell, Inc
//
using System;
#if STATIC
using IKVM.Reflection;
using IKVM.Reflection.Emit;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using Mono.CompilerServices.SymbolWriter;
namespace Mono.CSharp
{
static class SymbolWriter
{
#if !NET_4_0 && !STATIC
delegate int GetILOffsetFunc (ILGenerator ig);
static GetILOffsetFunc get_il_offset_func;
delegate Guid GetGuidFunc (ModuleBuilder mb);
static GetGuidFunc get_guid_func;
static void Initialize ()
{
var mi = typeof (ILGenerator).GetMethod (
"Mono_GetCurrentOffset",
BindingFlags.Static | BindingFlags.NonPublic);
if (mi == null)
throw new MissingMethodException ("Mono_GetCurrentOffset");
get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
typeof (GetILOffsetFunc), mi);
mi = typeof (ModuleBuilder).GetMethod (
"Mono_GetGuid",
BindingFlags.Static | BindingFlags.NonPublic);
if (mi == null)
throw new MissingMethodException ("Mono_GetGuid");
get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
typeof (GetGuidFunc), mi);
}
#endif
static int GetILOffset (ILGenerator ig)
{
#if NET_4_0 || STATIC
return ig.ILOffset;
#else
if (get_il_offset_func == null)
Initialize ();
return get_il_offset_func (ig);
#endif
}
public static Guid GetGuid (ModuleBuilder module)
{
#if NET_4_0 || STATIC
return module.ModuleVersionId;
#else
if (get_guid_func == null)
Initialize ();
return get_guid_func (module);
#endif
}
public static bool HasSymbolWriter {
get { return symwriter != null; }
}
public static MonoSymbolWriter symwriter;
public static void DefineLocalVariable (string name, LocalBuilder builder)
{
if (symwriter != null) {
symwriter.DefineLocalVariable (builder.LocalIndex, name);
}
}
public static SourceMethodBuilder OpenMethod (ICompileUnit file, IMethodDef method)
{
if (symwriter != null)
return symwriter.OpenMethod (file, -1 /* Not used */, method);
else
return null;
}
public static void CloseMethod ()
{
if (symwriter != null)
symwriter.CloseMethod ();
}
public static int OpenScope (ILGenerator ig)
{
if (symwriter != null) {
int offset = GetILOffset (ig);
return symwriter.OpenScope (offset);
} else {
return -1;
}
}
public static void CloseScope (ILGenerator ig)
{
if (symwriter != null) {
int offset = GetILOffset (ig);
symwriter.CloseScope (offset);
}
}
public static void DefineAnonymousScope (int id)
{
if (symwriter != null)
symwriter.DefineAnonymousScope (id);
}
public static void DefineScopeVariable (int scope, LocalBuilder builder)
{
if (symwriter != null) {
symwriter.DefineScopeVariable (scope, builder.LocalIndex);
}
}
public static void DefineScopeVariable (int scope)
{
if (symwriter != null)
symwriter.DefineScopeVariable (scope, -1);
}
public static void DefineCapturedLocal (int scope_id, string name,
string captured_name)
{
if (symwriter != null)
symwriter.DefineCapturedLocal (scope_id, name, captured_name);
}
public static void DefineCapturedParameter (int scope_id, string name,
string captured_name)
{
if (symwriter != null)
symwriter.DefineCapturedParameter (scope_id, name, captured_name);
}
public static void DefineCapturedThis (int scope_id, string captured_name)
{
if (symwriter != null)
symwriter.DefineCapturedThis (scope_id, captured_name);
}
public static void DefineCapturedScope (int scope_id, int id, string captured_name)
{
if (symwriter != null)
symwriter.DefineCapturedScope (scope_id, id, captured_name);
}
public static void OpenCompilerGeneratedBlock (EmitContext ec)
{
if (symwriter != null) {
int offset = GetILOffset (ec.ig);
symwriter.OpenCompilerGeneratedBlock (offset);
}
}
public static void CloseCompilerGeneratedBlock (EmitContext ec)
{
if (symwriter != null) {
int offset = GetILOffset (ec.ig);
symwriter.CloseCompilerGeneratedBlock (offset);
}
}
public static void StartIteratorBody (EmitContext ec)
{
if (symwriter != null) {
int offset = GetILOffset (ec.ig);
symwriter.StartIteratorBody (offset);
}
}
public static void EndIteratorBody (EmitContext ec)
{
if (symwriter != null) {
int offset = GetILOffset (ec.ig);
symwriter.EndIteratorBody (offset);
}
}
public static void StartIteratorDispatcher (EmitContext ec)
{
if (symwriter != null) {
int offset = GetILOffset (ec.ig);
symwriter.StartIteratorDispatcher (offset);
}
}
public static void EndIteratorDispatcher (EmitContext ec)
{
if (symwriter != null) {
int offset = GetILOffset (ec.ig);
symwriter.EndIteratorDispatcher (offset);
}
}
public static void MarkSequencePoint (ILGenerator ig, Location loc)
{
if (symwriter != null) {
SourceFileEntry file = loc.SourceFile.SourceFileEntry;
int offset = GetILOffset (ig);
symwriter.MarkSequencePoint (offset, file, loc.Row, loc.Column, false);
}
}
public static void Reset ()
{
symwriter = null;
}
}
}
|