Debian Codegraph @

symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs

raw
1 //
2 // Author:
3 // Juerg Billeter ([email protected])
4 //
5 // (C) 2008 Juerg Billeter
6 //
7 // Licensed under the MIT/X11 license.
8 //
9
10 using System;
11 using System.Collections.Generic;
12 using System.Diagnostics.SymbolStore;
13 using System.Runtime.InteropServices;
14
15 using Mono.Cecil.Cil;
16 using Mono.Collections.Generic;
17
18 #if !READ_ONLY
19
20 namespace Mono.Cecil.Pdb
21 {
22 internal class SymWriter
23 {
24 [DllImport("ole32.dll")]
25 static extern int CoCreateInstance (
26 [In] ref Guid rclsid,
27 [In, MarshalAs (UnmanagedType.IUnknown)] object pUnkOuter,
28 [In] uint dwClsContext,
29 [In] ref Guid riid,
30 [Out, MarshalAs (UnmanagedType.Interface)] out object ppv);
31
32 static Guid s_symUnmangedWriterIID = new Guid("0b97726e-9e6d-4f05-9a26-424022093caa");
33 static Guid s_CorSymWriter_SxS_ClassID = new Guid ("108296c1-281e-11d3-bd22-0000f80849bd");
34
35 readonly ISymUnmanagedWriter2 m_writer;
36 readonly Collection<ISymUnmanagedDocumentWriter> documents;
37
38 public SymWriter ()
39 {
40 object objWriter;
41 CoCreateInstance (ref s_CorSymWriter_SxS_ClassID, null, 1, ref s_symUnmangedWriterIID, out objWriter);
42
43 m_writer = (ISymUnmanagedWriter2) objWriter;
44 documents = new Collection<ISymUnmanagedDocumentWriter> ();
45 }
46
47 public byte[] GetDebugInfo (out ImageDebugDirectory idd)
48 {
49 int size;
50
51 // get size of debug info
52 m_writer.GetDebugInfo (out idd, 0, out size, null);
53
54 byte[] debug_info = new byte[size];
55 m_writer.GetDebugInfo (out idd, size, out size, debug_info);
56
57 return debug_info;
58 }
59
60 public void DefineLocalVariable2 (
61 string name,
62 FieldAttributes attributes,
63 SymbolToken sigToken,
64 SymAddressKind addrKind,
65 int addr1,
66 int addr2,
67 int addr3,
68 int startOffset,
69 int endOffset)
70 {
71 m_writer.DefineLocalVariable2 (name, (int)attributes, sigToken, (int)addrKind, addr1, addr2, addr3, startOffset, endOffset);
72 }
73
74 public void Close ()
75 {
76 m_writer.Close ();
77 Marshal.ReleaseComObject (m_writer);
78
79 foreach (var document in documents)
80 Marshal.ReleaseComObject (document);
81 }
82
83 public void CloseMethod ()
84 {
85 m_writer.CloseMethod ();
86 }
87
88 public void CloseNamespace ()
89 {
90 m_writer.CloseNamespace ();
91 }
92
93 public void CloseScope (int endOffset)
94 {
95 m_writer.CloseScope (endOffset);
96 }
97
98 public SymDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType)
99 {
100 ISymUnmanagedDocumentWriter unmanagedDocumentWriter;
101 m_writer.DefineDocument (url, ref language, ref languageVendor, ref documentType, out unmanagedDocumentWriter);
102
103 documents.Add (unmanagedDocumentWriter);
104 return new SymDocumentWriter (unmanagedDocumentWriter);
105 }
106
107 public void DefineParameter (string name, ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1, int addr2, int addr3)
108 {
109 throw new Exception ("The method or operation is not implemented.");
110 }
111
112 public void DefineSequencePoints (SymDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
113 {
114 m_writer.DefineSequencePoints (document.GetUnmanaged(), offsets.Length, offsets, lines, columns, endLines, endColumns);
115 }
116
117 public void Initialize (object emitter, string filename, bool fFullBuild)
118 {
119 m_writer.Initialize (emitter, filename, null, fFullBuild);
120 }
121
122 public void SetUserEntryPoint (SymbolToken method)
123 {
124 m_writer.SetUserEntryPoint (method);
125 }
126
127 public void OpenMethod (SymbolToken method)
128 {
129 m_writer.OpenMethod (method);
130 }
131
132 public void OpenNamespace (string name)
133 {
134 m_writer.OpenNamespace (name);
135 }
136
137 public int OpenScope (int startOffset)
138 {
139 int result;
140 m_writer.OpenScope (startOffset, out result);
141 return result;
142 }
143
144 public void UsingNamespace (string fullName)
145 {
146 m_writer.UsingNamespace (fullName);
147 }
148 }
149 }
150
151 #endif