2 // System.Diagnostics.SymbolStore/MonoSymbolWriter.cs
5 // Martin Baulig (martin@gnome.org)
7 // This is the default implementation of the System.Diagnostics.SymbolStore.ISymbolWriter
10 // (C) 2002 Ximian, Inc. http://www.ximian.com
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Diagnostics.SymbolStore;
17 using System.Collections;
20 namespace Mono.CSharp.Debugger
23 public class MonoSymbolWriter : IMonoSymbolWriter
25 protected string output_filename = null;
26 protected Hashtable methods = null;
27 protected Hashtable sources = null;
29 protected class MySourceInfo
31 private MyMethodInfo[] _methods;
32 public readonly string FileName;
34 public MySourceInfo (string filename)
36 this.FileName = filename;
38 this._methods = new MyMethodInfo [0];
41 public MyMethodInfo[] GetMethods ()
46 public void AddMethod (MyMethodInfo method)
48 int i = _methods.Length;
49 MyMethodInfo[] new_m = new MyMethodInfo [i + 1];
50 Array.Copy (_methods, new_m, i);
56 protected struct MyMethodInfo
58 public MyMethodInfo (MethodInfo method_info, MySourceInfo source_file) {
59 this.MethodInfo = method_info;
60 this.SourceFile = source_file;
63 public void SetSourceRange (int startLine, int startColumn,
64 int endLine, int endColumn)
68 public readonly MethodInfo MethodInfo;
69 public readonly MySourceInfo SourceFile;
72 protected Object current_method = null;
75 // Interface IMonoSymbolWriter
78 public MonoSymbolWriter ()
80 methods = new Hashtable ();
81 sources = new Hashtable ();
84 public void Close () {
85 CreateDwarfFile (output_filename);
88 public void CloseNamespace () {
91 public void CloseScope (int endOffset) {
94 // Create and return a new IMonoSymbolDocumentWriter.
95 public ISymbolDocumentWriter DefineDocument (string url,
100 return new MonoSymbolDocumentWriter (url);
103 public void DefineField (
106 FieldAttributes attributes,
108 SymAddressKind addrKind,
115 public void DefineGlobalVariable (
117 FieldAttributes attributes,
119 SymAddressKind addrKind,
126 public void DefineLocalVariable (string name,
127 FieldAttributes attributes,
129 SymAddressKind addrKind,
136 Console.WriteLine ("WRITE LOCAL: " + name + " " + addr1);
139 public void DefineParameter (
141 ParameterAttributes attributes,
143 SymAddressKind addrKind,
150 public void DefineSequencePoints (
151 ISymbolDocumentWriter document,
160 public void Initialize (IntPtr emitter, string filename, bool fFullBuild)
162 throw new NotSupportedException ("Please use the 'Initialize (string filename)' "
163 + "constructor and read the documentation in "
164 + "Mono.CSharp.Debugger/IMonoSymbolWriter.cs");
167 // This is documented in IMonoSymbolWriter.cs
168 public void Initialize (string filename)
170 this.output_filename = filename;
173 public void OpenMethod (SymbolToken method)
178 // This is documented in IMonoSymbolWriter.cs
179 public void OpenMethod (SymbolToken symbol_token, MethodInfo method_info,
182 int token = symbol_token.GetToken ();
183 MySourceInfo source_info;
185 if (methods.ContainsKey (token))
186 methods.Remove (token);
188 if (sources.ContainsKey (source_file))
189 source_info = (MySourceInfo) sources [source_file];
191 source_info = new MySourceInfo (source_file);
192 sources.Add (source_file, source_info);
195 current_method = new MyMethodInfo (method_info, source_info);
197 source_info.AddMethod ((MyMethodInfo) current_method);
199 methods.Add (token, current_method);
201 OpenMethod (symbol_token);
204 public void SetMethodSourceRange (ISymbolDocumentWriter startDoc,
205 int startLine, int startColumn,
206 ISymbolDocumentWriter endDoc,
207 int endLine, int endColumn)
209 if ((startDoc == null) || (endDoc == null))
210 throw new NullReferenceException ();
212 if (!(startDoc is MonoSymbolDocumentWriter) || !(endDoc is MonoSymbolDocumentWriter))
213 throw new NotSupportedException ("both startDoc and endDoc must be of type "
214 + "MonoSymbolDocumentWriter");
216 if (!startDoc.Equals (endDoc))
217 throw new NotSupportedException ("startDoc and endDoc must be the same");
219 if (current_method != null)
220 ((MyMethodInfo) current_method).SetSourceRange (startLine, startColumn,
224 public void CloseMethod () {
225 current_method = null;
228 public void OpenNamespace (string name)
232 public int OpenScope (int startOffset)
234 throw new NotImplementedException ();
237 public void SetScopeRange (int scopeID, int startOffset, int endOffset)
241 public void SetSymAttribute (SymbolToken parent, string name, byte[] data)
245 public void SetUnderlyingWriter (IntPtr underlyingWriter)
249 public void SetUserEntryPoint (SymbolToken entryMethod)
253 public void UsingNamespace (string fullName)
258 // MonoSymbolWriter implementation
260 protected void WriteMethod (DwarfFileWriter.DieCompileUnit parent_die, MyMethodInfo method)
262 Console.WriteLine ("WRITING METHOD: " + method.MethodInfo.Name);
264 DwarfFileWriter.DieSubProgram die;
266 die = new DwarfFileWriter.DieSubProgram (parent_die, method.MethodInfo);
269 protected void WriteSource (DwarfFileWriter writer, MySourceInfo source)
271 Console.WriteLine ("WRITING SOURCE: " + source.FileName);
273 DwarfFileWriter.CompileUnit compile_unit = new DwarfFileWriter.CompileUnit (
274 writer, source.FileName);
276 DwarfFileWriter.DieCompileUnit die = new DwarfFileWriter.DieCompileUnit (compile_unit);
278 foreach (MyMethodInfo method in source.GetMethods ())
279 WriteMethod (die, method);
282 protected void CreateDwarfFile (string filename)
284 Console.WriteLine ("WRITING DWARF FILE: " + filename);
286 DwarfFileWriter writer = new DwarfFileWriter (filename);
288 foreach (MySourceInfo source in sources.Values)
289 WriteSource (writer, source);
293 Console.WriteLine ("DONE WRITING DWARF FILE");