**** Merged from MCS ****
[mono-project.git] / mcs / ilasm / codegen / DebuggingInfo.cs
blob23fcac2b771a0489b888ded70f2e16eab8c7872f
1 //
2 // Mono.ILASM.DebuggingInfo.cs
3 //
4 // Author(s):
5 // Martin Baulig (martin@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc.
8 //
10 using PEAPI;
11 using System;
12 using System.IO;
13 using System.Collections;
14 using Mono.CompilerServices.SymbolWriter;
16 namespace Mono.ILASM {
18 public class SymbolWriter : MonoSymbolWriter
20 ArrayList sources;
21 Mono.ILASM.SourceMethod current_method;
22 SourceFile current_source;
24 public SymbolWriter (string filename)
25 : base (filename)
27 sources = new ArrayList ();
30 public Mono.ILASM.SourceMethod BeginMethod (MethodDef method, Location location)
32 current_method = new Mono.ILASM.SourceMethod (method, location);
33 current_source.AddMethod (current_method);
34 return current_method;
37 public void EndMethod (Location location)
39 current_method.EndLine = location.line;
40 current_method = null;
43 public void BeginSourceFile (string filename)
45 current_source = new SourceFile (file, filename);
46 sources.Add (current_source);
49 public void EndSourceFile ()
51 current_source = null;
54 public void Write (Guid guid)
56 foreach (SourceFile source in sources)
57 source.Write ();
59 WriteSymbolFile (guid);
63 public class SourceFile : SourceFileEntry
65 private ArrayList methods = new ArrayList ();
67 public SourceFile (MonoSymbolFile file, string filename)
68 : base (file, filename)
69 { }
71 public void AddMethod (SourceMethod method)
73 methods.Add (method);
76 public void Write ()
78 foreach (SourceMethod method in methods)
79 method.Write (this);
83 public class SourceMethod
85 MethodDef method;
86 ArrayList lines;
87 public int StartLine, EndLine;
89 public SourceMethod (MethodDef method, Location start)
91 this.method = method;
92 this.StartLine = start.line;
94 lines = new ArrayList ();
95 MarkLocation (start.line, 0);
98 public void MarkLocation (int line, uint offset)
100 lines.Add (new LineNumberEntry (line, (int) offset));
103 public void Write (SourceFile file)
105 PEAPI.MethodDef pemethod = method.PeapiMethodDef;
107 LineNumberEntry[] lne = new LineNumberEntry [lines.Count];
108 lines.CopyTo (lne);
110 uint token = ((uint) PEAPI.MDTable.Method << 24) | pemethod.Row;
112 file.DefineMethod (
113 method.Name, (int) token, null, lne, null,
114 StartLine, EndLine, 0);