2
// Mono.CSharp.Debugger/MonoSymbolWriter.cs
5
// Martin Baulig (martin@ximian.com)
7
// This is the default implementation of the System.Diagnostics.SymbolStore.ISymbolWriter
10
// (C) 2002 Ximian, Inc. http://www.ximian.com
14
// Permission is hereby granted, free of charge, to any person obtaining
15
// a copy of this software and associated documentation files (the
16
// "Software"), to deal in the Software without restriction, including
17
// without limitation the rights to use, copy, modify, merge, publish,
18
// distribute, sublicense, and/or sell copies of the Software, and to
19
// permit persons to whom the Software is furnished to do so, subject to
20
// the following conditions:
22
// The above copyright notice and this permission notice shall be
23
// included in all copies or substantial portions of the Software.
25
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
using System.Runtime.CompilerServices;
36
using System.Collections.Generic;
39
namespace Mono.CompilerServices.SymbolWriter
41
public class MonoSymbolWriter
43
List<SourceMethodBuilder> methods;
44
List<SourceFileEntry> sources;
45
List<CompileUnitEntry> comp_units;
46
protected readonly MonoSymbolFile file;
49
private SourceMethodBuilder current_method;
51
System.Collections.Stack current_method_stack = new System.Collections.Stack ();
53
Stack<SourceMethodBuilder> current_method_stack = new Stack<SourceMethodBuilder> ();
56
public MonoSymbolWriter (string filename)
58
this.methods = new List<SourceMethodBuilder> ();
59
this.sources = new List<SourceFileEntry> ();
60
this.comp_units = new List<CompileUnitEntry> ();
61
this.file = new MonoSymbolFile ();
63
this.filename = filename + ".mdb";
66
public MonoSymbolFile SymbolFile {
70
public void CloseNamespace ()
73
public void DefineLocalVariable (int index, string name)
75
if (current_method == null)
78
current_method.AddLocal (index, name);
81
public void DefineCapturedLocal (int scope_id, string name, string captured_name)
83
file.DefineCapturedVariable (scope_id, name, captured_name,
84
CapturedVariable.CapturedKind.Local);
87
public void DefineCapturedParameter (int scope_id, string name, string captured_name)
89
file.DefineCapturedVariable (scope_id, name, captured_name,
90
CapturedVariable.CapturedKind.Parameter);
93
public void DefineCapturedThis (int scope_id, string captured_name)
95
file.DefineCapturedVariable (scope_id, "this", captured_name,
96
CapturedVariable.CapturedKind.This);
99
public void DefineCapturedScope (int scope_id, int id, string captured_name)
101
file.DefineCapturedScope (scope_id, id, captured_name);
104
public void DefineScopeVariable (int scope, int index)
106
if (current_method == null)
109
current_method.AddScopeVariable (scope, index);
112
public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column,
115
if (current_method == null)
118
current_method.MarkSequencePoint (offset, file, line, column, is_hidden);
121
public SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id, IMethodDef method)
123
SourceMethodBuilder builder = new SourceMethodBuilder (file, ns_id, method);
124
current_method_stack.Push (current_method);
125
current_method = builder;
126
methods.Add (current_method);
130
public void CloseMethod ()
132
current_method = (SourceMethodBuilder) current_method_stack.Pop ();
135
public SourceFileEntry DefineDocument (string url)
137
SourceFileEntry entry = new SourceFileEntry (file, url);
142
public SourceFileEntry DefineDocument (string url, byte[] guid, byte[] checksum)
144
SourceFileEntry entry = new SourceFileEntry (file, url, guid, checksum);
149
public CompileUnitEntry DefineCompilationUnit (SourceFileEntry source)
151
CompileUnitEntry entry = new CompileUnitEntry (file, source);
152
comp_units.Add (entry);
156
public int DefineNamespace (string name, CompileUnitEntry unit,
157
string[] using_clauses, int parent)
159
if ((unit == null) || (using_clauses == null))
160
throw new NullReferenceException ();
162
return unit.DefineNamespace (name, using_clauses, parent);
165
public int OpenScope (int start_offset)
167
if (current_method == null)
170
current_method.StartBlock (CodeBlockEntry.Type.Lexical, start_offset);
174
public void CloseScope (int end_offset)
176
if (current_method == null)
179
current_method.EndBlock (end_offset);
182
public void OpenCompilerGeneratedBlock (int start_offset)
184
if (current_method == null)
187
current_method.StartBlock (CodeBlockEntry.Type.CompilerGenerated,
191
public void CloseCompilerGeneratedBlock (int end_offset)
193
if (current_method == null)
196
current_method.EndBlock (end_offset);
199
public void StartIteratorBody (int start_offset)
201
current_method.StartBlock (CodeBlockEntry.Type.IteratorBody,
205
public void EndIteratorBody (int end_offset)
207
current_method.EndBlock (end_offset);
210
public void StartIteratorDispatcher (int start_offset)
212
current_method.StartBlock (CodeBlockEntry.Type.IteratorDispatcher,
216
public void EndIteratorDispatcher (int end_offset)
218
current_method.EndBlock (end_offset);
221
public void DefineAnonymousScope (int id)
223
file.DefineAnonymousScope (id);
226
public void WriteSymbolFile (Guid guid)
228
foreach (SourceMethodBuilder method in methods)
229
method.DefineMethod (file);
232
// We mmap the file, so unlink the previous version since it may be in use
233
File.Delete (filename);
235
// We can safely ignore
237
using (FileStream fs = new FileStream (filename, FileMode.Create, FileAccess.Write)) {
238
file.CreateSymbolFile (guid, fs);