| 1 |
/* |
| 2 |
Copyright (C) 2008, 2009 Jeroen Frijters |
| 3 |
|
| 4 |
This software is provided 'as-is', without any express or implied |
| 5 |
warranty. In no event will the authors be held liable for any damages |
| 6 |
arising from the use of this software. |
| 7 |
|
| 8 |
Permission is granted to anyone to use this software for any purpose, |
| 9 |
including commercial applications, and to alter it and redistribute it |
| 10 |
freely, subject to the following restrictions: |
| 11 |
|
| 12 |
1. The origin of this software must not be misrepresented; you must not |
| 13 |
claim that you wrote the original software. If you use this software |
| 14 |
in a product, an acknowledgment in the product documentation would be |
| 15 |
appreciated but is not required. |
| 16 |
2. Altered source versions must be plainly marked as such, and must not be |
| 17 |
misrepresented as being the original software. |
| 18 |
3. This notice may not be removed or altered from any source distribution. |
| 19 |
|
| 20 |
Jeroen Frijters |
| 21 |
[email protected] |
| 22 |
|
| 23 |
*/ |
| 24 |
using System; |
| 25 |
using System.Runtime.InteropServices; |
| 26 |
#if !NO_SYMBOL_WRITER |
| 27 |
using System.Diagnostics.SymbolStore; |
| 28 |
#endif |
| 29 |
using IKVM.Reflection.Emit; |
| 30 |
|
| 31 |
namespace IKVM.Reflection.Impl |
| 32 |
{ |
| 33 |
[StructLayout(LayoutKind.Sequential)] |
| 34 |
struct IMAGE_DEBUG_DIRECTORY |
| 35 |
{ |
| 36 |
public uint Characteristics; |
| 37 |
public uint TimeDateStamp; |
| 38 |
public ushort MajorVersion; |
| 39 |
public ushort MinorVersion; |
| 40 |
public uint Type; |
| 41 |
public uint SizeOfData; |
| 42 |
public uint AddressOfRawData; |
| 43 |
public uint PointerToRawData; |
| 44 |
} |
| 45 |
|
| 46 |
#if NO_SYMBOL_WRITER |
| 47 |
struct SymbolToken |
| 48 |
{ |
| 49 |
internal SymbolToken(int value) { } |
| 50 |
} |
| 51 |
|
| 52 |
interface ISymbolWriterImpl |
| 53 |
{ |
| 54 |
byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd); |
| 55 |
void RemapToken(int oldToken, int newToken); |
| 56 |
void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset); |
| 57 |
void OpenMethod(SymbolToken symbolToken, MethodBase mb); |
| 58 |
bool IsDeterministic { get; } |
| 59 |
} |
| 60 |
#else |
| 61 |
interface ISymbolWriterImpl : ISymbolWriter |
| 62 |
{ |
| 63 |
byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd); |
| 64 |
void RemapToken(int oldToken, int newToken); |
| 65 |
void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset); |
| 66 |
void OpenMethod(SymbolToken symbolToken, MethodBase mb); |
| 67 |
bool IsDeterministic { get; } |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 71 |
static class SymbolSupport |
| 72 |
{ |
| 73 |
internal static ISymbolWriterImpl CreateSymbolWriterFor(ModuleBuilder moduleBuilder) |
| 74 |
{ |
| 75 |
#if NO_SYMBOL_WRITER |
| 76 |
throw new NotSupportedException("IKVM.Reflection compiled with NO_SYMBOL_WRITER does not support writing debugging symbols."); |
| 77 |
#else |
| 78 |
if (Universe.MonoRuntime) |
| 79 |
{ |
| 80 |
#if MONO |
| 81 |
return new MdbWriter(moduleBuilder); |
| 82 |
#else |
| 83 |
throw new NotSupportedException("IKVM.Reflection must be compiled with MONO defined to support writing Mono debugging symbols."); |
| 84 |
#endif |
| 85 |
} |
| 86 |
else |
| 87 |
{ |
| 88 |
return new PdbWriter(moduleBuilder); |
| 89 |
} |
| 90 |
#endif |
| 91 |
} |
| 92 |
|
| 93 |
internal static byte[] GetDebugInfo(ISymbolWriterImpl writer, ref IMAGE_DEBUG_DIRECTORY idd) |
| 94 |
{ |
| 95 |
return writer.GetDebugInfo(ref idd); |
| 96 |
} |
| 97 |
|
| 98 |
internal static void RemapToken(ISymbolWriterImpl writer, int oldToken, int newToken) |
| 99 |
{ |
| 100 |
writer.RemapToken(oldToken, newToken); |
| 101 |
} |
| 102 |
} |
| 103 |
} |