Debian Codegraph @

external/cecil-legacy/symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs

raw symbols SCIP
1 //
2 // SymWriter.cs
3 //
4 // Author:
5 // Juerg Billeter ([email protected])
6 //
7 // (C) 2008 Juerg Billeter
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections.Generic;
31 using System.Diagnostics.SymbolStore;
32 using System.Runtime.InteropServices;
33
34 using Mono.Cecil.Cil;
35 using Mono.Collections.Generic;
36
37 #if !READ_ONLY
38
39 namespace Mono.Cecil.Pdb
40 {
41 internal class SymWriter
42 {
43 [DllImport("ole32.dll")]
44 static extern int CoCreateInstance (
45 [In] ref Guid rclsid,
46 [In, MarshalAs (UnmanagedType.IUnknown)] object pUnkOuter,
47 [In] uint dwClsContext,
48 [In] ref Guid riid,
49 [Out, MarshalAs (UnmanagedType.Interface)] out object ppv);
50
51 static Guid s_symUnmangedWriterIID = new Guid("0b97726e-9e6d-4f05-9a26-424022093caa");
52 static Guid s_CorSymWriter_SxS_ClassID = new Guid ("108296c1-281e-11d3-bd22-0000f80849bd");
53
54 readonly ISymUnmanagedWriter2 m_writer;
55 readonly Collection<ISymUnmanagedDocumentWriter> documents;
56
57 public SymWriter ()
58 {
59 object objWriter;
60 CoCreateInstance (ref s_CorSymWriter_SxS_ClassID, null, 1, ref s_symUnmangedWriterIID, out objWriter);
61
62 m_writer = (ISymUnmanagedWriter2) objWriter;
63 documents = new Collection<ISymUnmanagedDocumentWriter> ();
64 }
65
66 public byte[] GetDebugInfo (out ImageDebugDirectory idd)
67 {
68 int size;
69
70 // get size of debug info
71 m_writer.GetDebugInfo (out idd, 0, out size, null);
72
73 byte[] debug_info = new byte[size];
74 m_writer.GetDebugInfo (out idd, size, out size, debug_info);
75
76 return debug_info;
77 }
78
79 public void DefineLocalVariable2 (
80 string name,
81 FieldAttributes attributes,
82 SymbolToken sigToken,
83 SymAddressKind addrKind,
84 int addr1,
85 int addr2,
86 int addr3,
87 int startOffset,
88 int endOffset)
89 {
90 m_writer.DefineLocalVariable2 (name, (int)attributes, sigToken, (int)addrKind, addr1, addr2, addr3, startOffset, endOffset);
91 }
92
93 public void Close ()
94 {
95 m_writer.Close ();
96 Marshal.ReleaseComObject (m_writer);
97
98 foreach (var document in documents)
99 Marshal.ReleaseComObject (document);
100 }
101
102 public void CloseMethod ()
103 {
104 m_writer.CloseMethod ();
105 }
106
107 public void CloseNamespace ()
108 {
109 m_writer.CloseNamespace ();
110 }
111
112 public void CloseScope (int endOffset)
113 {
114 m_writer.CloseScope (endOffset);
115 }
116
117 public SymDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType)
118 {
119 ISymUnmanagedDocumentWriter unmanagedDocumentWriter;
120 m_writer.DefineDocument (url, ref language, ref languageVendor, ref documentType, out unmanagedDocumentWriter);
121
122 documents.Add (unmanagedDocumentWriter);
123 return new SymDocumentWriter (unmanagedDocumentWriter);
124 }
125
126 public void DefineParameter (string name, ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1, int addr2, int addr3)
127 {
128 throw new Exception ("The method or operation is not implemented.");
129 }
130
131 public void DefineSequencePoints (SymDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
132 {
133 m_writer.DefineSequencePoints (document.GetUnmanaged(), offsets.Length, offsets, lines, columns, endLines, endColumns);
134 }
135
136 public void Initialize (object emitter, string filename, bool fFullBuild)
137 {
138 m_writer.Initialize (emitter, filename, null, fFullBuild);
139 }
140
141 public void SetUserEntryPoint (SymbolToken method)
142 {
143 m_writer.SetUserEntryPoint (method);
144 }
145
146 public void OpenMethod (SymbolToken method)
147 {
148 m_writer.OpenMethod (method);
149 }
150
151 public void OpenNamespace (string name)
152 {
153 m_writer.OpenNamespace (name);
154 }
155
156 public int OpenScope (int startOffset)
157 {
158 int result;
159 m_writer.OpenScope (startOffset, out result);
160 return result;
161 }
162
163 public void UsingNamespace (string fullName)
164 {
165 m_writer.UsingNamespace (fullName);
166 }
167 }
168 }
169
170 #endif