public static void DumpLineNumberTable(TextWriter writer, MonoSymbolFile file, Cecil.MethodDefinition mdef, C.MethodEntry entry) { try { DumpLineNumberTable_internal(writer, file, mdef, entry); } catch (Exception ex) { writer.WriteLine("DUMP LNT EX: {0}", ex); } }
void ReadLocalVariables (MethodEntry entry, MethodBody body) { LocalVariableEntry[] locals = entry.GetLocals (); foreach (LocalVariableEntry loc in locals) { VariableDefinition var = body.Variables [loc.Index]; var.Name = loc.Name; Scope scope = m_scopes [loc.BlockIndex] as Scope; if (scope == null) continue; scope.Variables.Add (var); } }
void ReadLineNumbers (MethodEntry entry, IDictionary instructions) { LineNumberTable lnt = entry.GetLineNumberTable (); foreach (LineNumberEntry line in lnt.LineNumbers) { Instruction instr = instructions [line.Offset] as Instruction; if (instr == null) continue; Document doc = GetDocument (entry.CompileUnit.SourceFile); instr.SequencePoint = new SequencePoint (doc); instr.SequencePoint.StartLine = line.Row; instr.SequencePoint.EndLine = line.Row; } }
internal MethodEntry(MonoSymbolFile file, CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, MethodEntry.Flags flags, int namespace_id) { this.SymbolFile = file; this.real_name = real_name; this.locals = locals; this.code_blocks = code_blocks; this.scope_vars = scope_vars; this.flags = flags; this.index = -1; this.Token = token; this.CompileUnitIndex = comp_unit.Index; this.CompileUnit = comp_unit; this.NamespaceID = namespace_id; this.CheckLineNumberTable(lines); this.lnt = new LineNumberTable(file, lines); file.NumLineNumbers += lines.Length; int num_locals = (locals != null) ? locals.Length : 0; if (num_locals <= 32) { for (int i = 0; i < num_locals; i++) { string nm = locals[i].Name; for (int j = i + 1; j < num_locals; j++) { if (locals[j].Name == nm) { flags |= MethodEntry.Flags.LocalNamesAmbiguous; goto IL_108; } } } IL_108:; } else { Dictionary<string, LocalVariableEntry> local_names = new Dictionary<string, LocalVariableEntry>(); for (int k = 0; k < locals.Length; k++) { LocalVariableEntry local = locals[k]; if (local_names.ContainsKey(local.Name)) { flags |= MethodEntry.Flags.LocalNamesAmbiguous; break; } local_names.Add(local.Name, local); } } }
static void ReadLocalVariables (MethodEntry entry, MethodBody body, Scope [] scopes) { var locals = entry.GetLocals (); foreach (var local in locals) { var variable = body.Variables [local.Index]; variable.Name = local.Name; var index = local.BlockIndex; if (index < 0 || index >= scopes.Length) continue; var scope = scopes [index]; if (scope == null) continue; scope.Variables.Add (variable); } }
private static void ReadLocalVariables(MethodEntry entry, MethodBody body, Scope[] scopes) { LocalVariableEntry[] locals = entry.GetLocals(); LocalVariableEntry[] array = locals; for (int i = 0; i < array.Length; i++) { LocalVariableEntry local = array[i]; VariableDefinition variable = body.Variables[local.Index]; variable.Name = local.Name; int index = local.BlockIndex; if (index >= 0 && index < scopes.Length) { Scope scope = scopes[index]; if (scope != null) { scope.Variables.Add(variable); } } } }
static void DumpLineNumberTable_internal(TextWriter writer, MonoSymbolFile file, Cecil.MethodDefinition mdef, C.MethodEntry entry) { string full_name = MonoSymbolFile.GetMethodName(mdef); if (mdef.MetadataToken.TokenType != Cecil.Metadata.TokenType.Method) { writer.WriteLine("UNKNOWN METHOD: {0}", full_name); return; } writer.WriteLine(); writer.WriteLine("Symfile Line Numbers (file / row / offset):"); writer.WriteLine("-------------------------------------------"); C.LineNumberEntry[] lnt; lnt = entry.GetLineNumberTable().LineNumbers; for (int i = 0; i < lnt.Length; i++) { C.LineNumberEntry lne = lnt [i]; writer.WriteLine("{0,4} {1,4} {2,4} {3,4:x}{4}", i, lne.File, lne.Row, lne.Offset, lne.IsHidden ? " (hidden)" : ""); } writer.WriteLine("-------------------------------------------"); writer.WriteLine(); List <string> lines; Dictionary <int, int> offsets; if (!DisassembleMethod_internal(file.ImageFile, (int)mdef.MetadataToken.RID, out lines, out offsets)) { writer.WriteLine("Cannot disassemble method: {0}", full_name); return; } writer.WriteLine("Disassembling {0}:\n\n{1}\n", full_name, String.Join("\n", lines.ToArray())); }
private void ReadLineNumbers(MethodEntry entry, InstructionMapper mapper) { Document document = null; LineNumberTable table = entry.GetLineNumberTable(); LineNumberEntry[] lineNumbers = table.LineNumbers; for (int i = 0; i < lineNumbers.Length; i++) { LineNumberEntry line = lineNumbers[i]; Instruction instruction = mapper(line.Offset); if (instruction != null) { if (document == null) { document = this.GetDocument(entry.CompileUnit.SourceFile); } instruction.SequencePoint = new SequencePoint(document) { StartLine = line.Row, EndLine = line.Row }; } } }
public void DefineMethod(MonoSymbolFile file) { LineNumberEntry[] lines = new LineNumberEntry[this.method_lines_pos]; Array.Copy(this.method_lines, lines, this.method_lines_pos); MethodEntry entry = new MethodEntry(file, this._comp_unit.Entry, this._method.Token, this.ScopeVariables, this.Locals, lines, this.Blocks, this.RealMethodName, (MethodEntry.Flags)0, this._ns_id); file.AddMethod(entry); }
void ReadLineNumbers (MethodEntry entry, MethodSymbols symbols) { var table = entry.GetLineNumberTable (); var lines = table.LineNumbers; var instructions = symbols.instructions = new Collection<InstructionSymbol> (lines.Length); for (int i = 0; i < lines.Length; i++) { var line = lines [i]; instructions.Add (new InstructionSymbol (line.Offset, new SequencePoint (GetDocument (entry.CompileUnit.SourceFile)) { StartLine = line.Row, EndLine = line.Row, })); } }
public void DefineMethod (MonoSymbolFile file, int token) { MethodEntry entry = new MethodEntry ( file, _comp_unit.Entry, token, ScopeVariables, Locals, method_lines.ToArray (), Blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id); file.AddMethod (entry); }
private void ProcessMethod (MethodBase monoMethod, MethodEntry entry, ClassCoverageItem klass, string methodName, string cov_info)
void read_methods () { lock (this) { if (method_token_hash != null) return; method_token_hash = new Dictionary<int, MethodEntry> (); method_list = new List<MethodEntry> (); long old_pos = reader.BaseStream.Position; reader.BaseStream.Position = ot.MethodTableOffset; for (int i = 0; i < MethodCount; i++) { MethodEntry entry = new MethodEntry (this, reader, i + 1); method_token_hash.Add (entry.Token, entry); method_list.Add (entry); } reader.BaseStream.Position = old_pos; } }
internal void AddMethod (MethodEntry entry) { methods.Add (entry); }
static void ReadLocalVariables(MethodEntry entry, ScopeDebugInformation [] scopes) { var locals = entry.GetLocals (); foreach (var local in locals) { var variable = new VariableDebugInformation (local.Index, local.Name); var index = local.BlockIndex; if (index < 0 || index >= scopes.Length) continue; var scope = scopes [index]; if (scope == null) continue; scope.Variables.Add (variable); } }
static ScopeDebugInformation[] ReadScopes(MethodEntry entry, MethodDebugInformation info) { var blocks = entry.GetCodeBlocks (); var scopes = new ScopeDebugInformation [blocks.Length + 1]; info.scope = scopes [0] = new ScopeDebugInformation { Start = new InstructionOffset (0), End = new InstructionOffset (info.code_size), }; foreach (var block in blocks) { if (block.BlockType != CodeBlockEntry.Type.Lexical && block.BlockType != CodeBlockEntry.Type.CompilerGenerated) continue; var scope = new ScopeDebugInformation (); scope.Start = new InstructionOffset (block.StartOffset); scope.End = new InstructionOffset (block.EndOffset); scopes [block.Index + 1] = scope; if (!AddScope (info.scope.Scopes, scope)) info.scope.Scopes.Add (scope); } return scopes; }
public void DefineMethod (MonoSymbolFile file, int token) { var blocks = Blocks; // // When index is provided by user it can be inserted in // any order but mdb format does not store its value. It // uses store order instead as the index. // Array.Sort (blocks, (x, y) => x.Index.CompareTo (y.Index)); var entry = new MethodEntry ( file, _comp_unit.Entry, token, ScopeVariables, Locals, method_lines.ToArray (), blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id); file.AddMethod (entry); }
void ReadScopes (MethodEntry entry, MethodBody body, IDictionary instructions) { CodeBlockEntry[] blocks = entry.GetCodeBlocks (); foreach (CodeBlockEntry cbe in blocks) { if (cbe.BlockType != CodeBlockEntry.Type.Lexical) continue; Scope s = new Scope (); s.Start = GetInstruction (body, instructions, cbe.StartOffset); s.End = GetInstruction(body, instructions, cbe.EndOffset); m_scopes [entry.Index] = s; if (!AddScope (body, s)) body.Scopes.Add (s); } }
void Write(MyBinaryWriter bw, Guid guid) { // Magic number and file version. bw.Write(OffsetTable.Magic); bw.Write(MajorVersion); bw.Write(MinorVersion); bw.Write(guid.ToByteArray()); // // Offsets of file sections; we must write this after we're done // writing the whole file, so we just reserve the space for it here. // long offset_table_offset = bw.BaseStream.Position; ot.Write(bw, MajorVersion, MinorVersion); // // Sort the methods according to their tokens and update their index. // methods.Sort(); for (int i = 0; i < methods.Count; i++) { methods [i].Index = i + 1; } // // Write data sections. // ot.DataSectionOffset = (int)bw.BaseStream.Position; foreach (SourceFileEntry source in sources) { source.WriteData(bw); } foreach (CompileUnitEntry comp_unit in comp_units) { comp_unit.WriteData(bw); } foreach (MethodEntry method in methods) { method.WriteData(this, bw); } ot.DataSectionSize = (int)bw.BaseStream.Position - ot.DataSectionOffset; // // Write the method index table. // ot.MethodTableOffset = (int)bw.BaseStream.Position; for (int i = 0; i < methods.Count; i++) { MethodEntry entry = methods [i]; entry.Write(bw); } ot.MethodTableSize = (int)bw.BaseStream.Position - ot.MethodTableOffset; // // Write source table. // ot.SourceTableOffset = (int)bw.BaseStream.Position; for (int i = 0; i < sources.Count; i++) { SourceFileEntry source = sources [i]; source.Write(bw); } ot.SourceTableSize = (int)bw.BaseStream.Position - ot.SourceTableOffset; // // Write compilation unit table. // ot.CompileUnitTableOffset = (int)bw.BaseStream.Position; for (int i = 0; i < comp_units.Count; i++) { CompileUnitEntry unit = comp_units [i]; unit.Write(bw); } ot.CompileUnitTableSize = (int)bw.BaseStream.Position - ot.CompileUnitTableOffset; // // Write anonymous scope table. // ot.AnonymousScopeCount = anonymous_scopes != null ? anonymous_scopes.Count : 0; ot.AnonymousScopeTableOffset = (int)bw.BaseStream.Position; if (anonymous_scopes != null) { foreach (AnonymousScopeEntry scope in anonymous_scopes.Values) { scope.Write(bw); } } ot.AnonymousScopeTableSize = (int)bw.BaseStream.Position - ot.AnonymousScopeTableOffset; // // Fixup offset table. // ot.TypeCount = last_type_index; ot.MethodCount = methods.Count; ot.SourceCount = sources.Count; ot.CompileUnitCount = comp_units.Count; // // Write offset table. // ot.TotalFileSize = (int)bw.BaseStream.Position; bw.Seek((int)offset_table_offset, SeekOrigin.Begin); ot.Write(bw, MajorVersion, MinorVersion); bw.Seek(0, SeekOrigin.End); #if false Console.WriteLine("TOTAL: {0} line numbes, {1} bytes, extended {2} bytes, " + "{3} methods.", NumLineNumbers, LineNumberSize, ExtendedLineNumberSize, methods.Count); #endif }
public MonoMethod(MonoSymbolFile file, MethodSource source, int domain, C.MethodEntry method, Cecil.MethodDefinition mdef) : base(source.Name, file.ImageFile, file.Module) { this.file = file; this.source = source; this.domain = domain; this.method = method; this.mdef = mdef; foreach (Cecil.CustomAttribute cattr in mdef.CustomAttributes) { string cname = cattr.Constructor.DeclaringType.FullName; if ((cname == "System.Diagnostics.DebuggerHiddenAttribute") || (cname == "System.Runtime.CompilerServices.CompilerGeneratedAttribute")) is_compiler_generated = true; } }
void ReadLineNumbers(MethodEntry entry, MethodDebugInformation info) { var table = entry.GetLineNumberTable (); info.sequence_points = new Collection<SequencePoint> (table.LineNumbers.Length); for (var i = 0; i < table.LineNumbers.Length; i++) { var line = table.LineNumbers [i]; if (i > 0 && table.LineNumbers [i - 1].Offset == line.Offset) continue; info.sequence_points.Add (LineToSequencePoint (line)); } }
public MonoMethodLineNumberTable(MonoSymbolFile file, MonoMethod method, MethodSource source, C.MethodEntry entry, JitLineNumberEntry[] jit_lnt) : base(file, method) { this.method = method; this.entry = entry; this.line_numbers = jit_lnt; }
public void DefineMethod (MonoSymbolFile file) { LineNumberEntry[] lines = new LineNumberEntry [method_lines_pos]; Array.Copy (method_lines, lines, method_lines_pos); MethodEntry entry = new MethodEntry ( file, _comp_unit.Entry, _method.Token, ScopeVariables, Locals, lines, Blocks, RealMethodName, _method_flags, _ns_id); file.AddMethod (entry); }
public MonoMethodSource(MonoSymbolFile file, SourceFile source_file, C.MethodEntry method, Cecil.MethodDefinition mdef, MonoClassType klass, MonoFunctionType function) { this.file = file; this.source_file = source_file; this.method = method; this.mdef = mdef; this.function = function; this.klass = klass; full_name = method.GetRealName (); if (full_name == null) full_name = MonoSymbolFile.GetMethodName (mdef); C.LineNumberEntry start, end; C.LineNumberTable lnt = method.GetLineNumberTable (); if (lnt.GetMethodBounds (out start, out end)) start_row = start.Row; end_row = end.Row; }
public MethodEntry DefineMethod (CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, MethodEntry.Flags flags, int namespace_id) { if (reader != null) throw new InvalidOperationException (); MethodEntry method = new MethodEntry ( this, comp_unit, token, scope_vars, locals, lines, code_blocks, real_name, flags, namespace_id); AddMethod (method); return method; }
public void AddMethod(MethodEntry entry) { methods.Add(entry); }
static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols) { foreach (var local in entry.GetLocals ()) { if (local.Index < 0 || local.Index >= symbols.Variables.Count) // Mono 2.6 emits wrong local infos for iterators continue; var variable = symbols.Variables [local.Index]; variable.Name = local.Name; } }
public void DefineMethod(MonoSymbolFile file, int token) { var blocks = Blocks; if (blocks.Length > 0) { // // When index is provided by user it can be inserted in // any order but mdb format does not store its value. It // uses stored order as the index instead. // var sorted = new List <CodeBlockEntry> (blocks.Length); int max_index = 0; for (int i = 0; i < blocks.Length; ++i) { max_index = System.Math.Max(max_index, blocks [i].Index); } for (int i = 0; i < max_index; ++i) { var scope_index = i + 1; // // Common fast path // if (i < blocks.Length && blocks [i].Index == scope_index) { sorted.Add(blocks [i]); continue; } bool found = false; for (int ii = 0; ii < blocks.Length; ++ii) { if (blocks [ii].Index == scope_index) { sorted.Add(blocks [ii]); found = true; break; } } if (found) { continue; } // // Ideally this should never happen but with current design we can // generate scope index for unreachable code before reachable code // sorted.Add(new CodeBlockEntry(scope_index, -1, CodeBlockEntry.Type.CompilerGenerated, 0)); } blocks = sorted.ToArray(); //for (int i = 0; i < blocks.Length; ++i) { // if (blocks [i].Index - 1 != i) // throw new ArgumentException ("CodeBlocks cannot be converted to mdb format"); //} } var entry = new MethodEntry( file, _comp_unit.Entry, token, ScopeVariables, Locals, method_lines.ToArray(), blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id); file.AddMethod(entry); }
private void ProcessMethod (MethodDefinition monoMethod, MethodEntry entry, ClassCoverageItem klass, string methodName, string cov_info) #endif { if (entry == null) // Compiler generated, abstract method etc. return; LineNumberEntry[] lines = entry.GetLineNumberTable ().LineNumbers; if (lines.Length == 0) return; int start_line = lines [0].Row; int end_line = lines [lines.Length - 1].Row; MethodCoverageItem method = new MethodCoverageItem (klass, methodName); method.startLine = start_line; method.endLine = end_line; #if USE_REFLECTION method.filtered = IsFiltered ("[" + monoMethod.DeclaringType.Assembly + "]" + monoMethod.DeclaringType + "::" + monoMethod.Name); #else method.filtered = IsFiltered ("[" + monoMethod.DeclaringType.Module.Name + "]" + monoMethod.DeclaringType + "::" + monoMethod.Name); #endif klass.methodsByMethod [monoMethod] = method; if (klass.sourceFile == null) { string sourceFile = entry.CompileUnit.SourceFile.FileName; SourceFileCoverageData source = (SourceFileCoverageData)sources [sourceFile]; if (source == null) { source = new SourceFileCoverageData (sourceFile); sources [sourceFile] = source; } klass.sourceFile = source; } computeMethodCoverage (method, lines, cov_info); }
static SequencePoint LineToSequencePoint(LineNumberEntry line, MethodEntry entry, Document document) { return new SequencePoint (document) { StartLine = line.Row, EndLine = line.EndRow, StartColumn = line.Column, EndColumn = line.EndColumn, }; }
static Scope [] ReadScopes (MethodEntry entry, MethodBody body, InstructionMapper mapper) { var blocks = entry.GetCodeBlocks (); var scopes = new Scope [blocks.Length]; foreach (var block in blocks) { if (block.BlockType != CodeBlockEntry.Type.Lexical) continue; var scope = new Scope (); scope.Start = mapper (block.StartOffset); scope.End = mapper (block.EndOffset); scopes [block.Index] = scope; if (body.Scope == null) body.Scope = scope; if (!AddScope (body.Scope, scope)) body.Scope = scope; } return scopes; }
private void read_methods() { if (this.method_token_hash == null) { this.method_token_hash = new Dictionary<int, MethodEntry>(); this.method_list = new List<MethodEntry>(); long old_pos = this.reader.BaseStream.Position; this.reader.BaseStream.Position = (long)this.ot.MethodTableOffset; for (int i = 0; i < this.MethodCount; i++) { MethodEntry entry = new MethodEntry(this, this.reader, i + 1); this.method_token_hash.Add(entry.Token, entry); this.method_list.Add(entry); } this.reader.BaseStream.Position = old_pos; } }
static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols) { foreach (var local in entry.GetLocals ()) { var variable = symbols.Variables [local.Index]; variable.Name = local.Name; } }
public void AddMethod(MethodEntry entry) { methods.Add (entry); }
void ReadLineNumbers (MethodEntry entry, InstructionMapper mapper) { Document document = null; var table = entry.GetLineNumberTable (); foreach (var line in table.LineNumbers) { var instruction = mapper (line.Offset); if (instruction == null) continue; if (document == null) document = GetDocument (entry.CompileUnit.SourceFile); instruction.SequencePoint = new SequencePoint (document) { StartLine = line.Row, EndLine = line.Row, }; } }
internal void AddMethod(MethodEntry entry) { methods.Add(entry); }