Merge pull request #347 from JamesB7/master
[mono.git] / mcs / class / IKVM.Reflection / Impl / SymbolSupport.cs
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   jeroen@frijters.net
22   
23 */
24 using System;
25 using System.Runtime.InteropServices;
26 using System.Diagnostics.SymbolStore;
27 using IKVM.Reflection.Emit;
28
29 namespace IKVM.Reflection.Impl
30 {
31         [StructLayout(LayoutKind.Sequential)]
32         struct IMAGE_DEBUG_DIRECTORY
33         {
34                 public uint Characteristics;
35                 public uint TimeDateStamp;
36                 public ushort MajorVersion;
37                 public ushort MinorVersion;
38                 public uint Type;
39                 public uint SizeOfData;
40                 public uint AddressOfRawData;
41                 public uint PointerToRawData;
42         }
43
44         interface ISymbolWriterImpl : ISymbolWriter
45         {
46                 byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
47                 void RemapToken(int oldToken, int newToken);
48                 void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
49                 void OpenMethod(SymbolToken symbolToken, MethodBase mb);
50         }
51
52         static class SymbolSupport
53         {
54                 internal static ISymbolWriterImpl CreateSymbolWriterFor(ModuleBuilder moduleBuilder)
55                 {
56 #if NO_SYMBOL_WRITER
57                         throw new NotSupportedException("IKVM.Reflection compiled with NO_SYMBOL_WRITER does not support writing debugging symbols.");
58 #else
59                         if (Universe.MonoRuntime)
60                         {
61 #if MONO
62                                 return new MdbWriter(moduleBuilder);
63 #else
64                                 throw new NotSupportedException("IKVM.Reflection must be compiled with MONO defined to support writing Mono debugging symbols.");
65 #endif
66                         }
67                         else
68                         {
69                                 return new PdbWriter(moduleBuilder);
70                         }
71 #endif
72                 }
73
74                 internal static byte[] GetDebugInfo(ISymbolWriterImpl writer, ref IMAGE_DEBUG_DIRECTORY idd)
75                 {
76                         return writer.GetDebugInfo(ref idd);
77                 }
78
79                 internal static void RemapToken(ISymbolWriterImpl writer, int oldToken, int newToken)
80                 {
81                         writer.RemapToken(oldToken, newToken);
82                 }
83         }
84 }