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 SourceInfo
31 private MethodInfo[] _methods;
32 public readonly string FileName;
34 public SourceInfo (string filename)
36 this.FileName = filename;
38 this._methods = new MethodInfo [0];
41 public MethodInfo[] GetMethods ()
46 public void AddMethod (MethodInfo method)
48 int i = _methods.Length;
49 MethodInfo[] new_m = new MethodInfo [i + 1];
50 Array.Copy (_methods, new_m, i);
56 protected struct MethodInfo
58 public MethodInfo (string name, SourceInfo source_file) {
60 this.SourceFile = source_file;
63 public void SetSourceRange (int startLine, int startColumn,
64 int endLine, int endColumn)
68 public readonly string Name;
69 public readonly SourceInfo 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, string name, string source_file)
181 int token = symbol_token.GetToken ();
182 SourceInfo source_info;
184 if (methods.ContainsKey (token))
185 methods.Remove (token);
187 if (sources.ContainsKey (source_file))
188 source_info = (SourceInfo) sources [source_file];
190 source_info = new SourceInfo (source_file);
191 sources.Add (source_file, source_info);
194 current_method = new MethodInfo (name, source_info);
196 source_info.AddMethod ((MethodInfo) current_method);
198 methods.Add (token, current_method);
200 OpenMethod (symbol_token);
203 public void SetMethodSourceRange (ISymbolDocumentWriter startDoc,
204 int startLine, int startColumn,
205 ISymbolDocumentWriter endDoc,
206 int endLine, int endColumn)
208 if ((startDoc == null) || (endDoc == null))
209 throw new NullReferenceException ();
211 if (!(startDoc is MonoSymbolDocumentWriter) || !(endDoc is MonoSymbolDocumentWriter))
212 throw new NotSupportedException ("both startDoc and endDoc must be of type "
213 + "MonoSymbolDocumentWriter");
215 if (!startDoc.Equals (endDoc))
216 throw new NotSupportedException ("startDoc and endDoc must be the same");
218 if (current_method != null)
219 ((MethodInfo) current_method).SetSourceRange (startLine, startColumn,
223 public void CloseMethod () {
224 current_method = null;
227 public void OpenNamespace (string name)
231 public int OpenScope (int startOffset)
233 throw new NotImplementedException ();
236 public void SetScopeRange (int scopeID, int startOffset, int endOffset)
240 public void SetSymAttribute (SymbolToken parent, string name, byte[] data)
244 public void SetUnderlyingWriter (IntPtr underlyingWriter)
248 public void SetUserEntryPoint (SymbolToken entryMethod)
252 public void UsingNamespace (string fullName)
257 // MonoSymbolWriter implementation
259 protected void WriteMethod (DwarfFileWriter.DieCompileUnit parent_die, MethodInfo method)
261 Console.WriteLine ("WRITING METHOD: " + method.Name);
263 DwarfFileWriter.DieSubProgram die;
265 die = new DwarfFileWriter.DieSubProgram (parent_die, method.Name);
268 protected void WriteSource (DwarfFileWriter writer, SourceInfo source)
270 Console.WriteLine ("WRITING SOURCE: " + source.FileName);
272 DwarfFileWriter.CompileUnit compile_unit = new DwarfFileWriter.CompileUnit (
273 writer, source.FileName);
275 DwarfFileWriter.DieCompileUnit die = new DwarfFileWriter.DieCompileUnit (compile_unit);
277 foreach (MethodInfo method in source.GetMethods ())
278 WriteMethod (die, method);
281 protected void CreateDwarfFile (string filename)
283 Console.WriteLine ("WRITING DWARF FILE: " + filename);
285 DwarfFileWriter writer = new DwarfFileWriter (filename);
287 foreach (SourceInfo source in sources.Values)
288 WriteSource (writer, source);
292 Console.WriteLine ("DONE WRITING DWARF FILE");