void WriteScope(MethodSymbols symbols, ScopeSymbol scope) { writer.OpenScope (scope.Start); foreach (var s in scope.Scopes) WriteScope (symbols, s); DefineVariables (symbols, scope.Variables, scope.Start, scope.End) ; writer.CloseScope (scope.End); }
static MetadataToken GetLocalVarToken (ByteBuffer buffer, MethodSymbols symbols) { if (symbols.variables.IsNullOrEmpty ()) return MetadataToken.Zero; buffer.position = 8; return new MetadataToken (buffer.ReadUInt32 ()); }
public SourceMethodSymbol(MethodSymbols symbols) { name = symbols.MethodName; token = symbols.MethodToken.ToInt32 (); }
void DefineSequencePoints(MethodSymbols symbols) { var instructions = symbols.instructions; if (instructions == null) return; for (int i = 0; i < instructions.Count; i++) { var instruction = instructions [i]; var sequence_point = instruction.SequencePoint; writer.DefineSequencePoints ( GetDocument (sequence_point.Document), new [] { instruction.Offset }, new [] { sequence_point.StartLine }, new [] { sequence_point.StartColumn }, new [] { sequence_point.EndLine }, new [] { sequence_point.EndColumn }); } }
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 ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols) { var buffer = new ByteBuffer (); symbols = new MethodSymbols (method.Name); this.method = method; reader.context = method; MoveTo (method.RVA); var flags = ReadByte (); MetadataToken local_var_token; switch (flags & 0x3) { case 0x2: // tiny buffer.WriteByte (flags); local_var_token = MetadataToken.Zero; symbols.code_size = flags >> 2; PatchRawCode (buffer, symbols.code_size, writer); break; case 0x3: // fat base.position--; PatchRawFatMethod (buffer, symbols, writer, out local_var_token); break; default: throw new NotSupportedException (); } var symbol_reader = reader.module.SymbolReader; if (symbol_reader != null && writer.metadata.write_symbols) { symbols.method_token = GetOriginalToken (writer.metadata, method); symbols.local_var_token = local_var_token; symbol_reader.Read (symbols); } return buffer; }
static void ReadScopeAndLocals(PdbScope scope, ScopeSymbol parent, MethodSymbols symbols) { if (scope == null) return; ScopeSymbol s = new ScopeSymbol (); s.start = (int) scope.offset; s.end = (int)(scope.offset + scope.length); if (parent != null) parent.Scopes.Add (s); else if (symbols.scope == null) symbols.scope = s; else throw new InvalidDataException () ; foreach (PdbSlot slot in scope.slots) { int index = (int) slot.slot; if (index < 0 || index >= symbols.Variables.Count) continue; VariableDefinition variable = symbols.Variables [index]; variable.Name = slot.name; s.Variables.Add (variable); } ReadScopeAndLocals (scope.scopes, s, symbols); }
public void Write (MethodSymbols symbols) { var sym_token = new SymbolToken (symbols.MethodToken.ToInt32 ()); var start_offset = 0; var end_offset = symbols.CodeSize; writer.OpenMethod (sym_token); writer.OpenScope (start_offset); DefineSequencePoints (symbols); DefineVariables (symbols, start_offset, end_offset); writer.CloseScope (end_offset); writer.CloseMethod (); }
public void Read(MethodSymbols symbols) { PdbFunction function; if (!functions.TryGetValue (symbols.MethodToken.ToUInt32 (), out function)) return; ReadSequencePoints (function, symbols); ReadScopeAndLocals (function.scopes, null, symbols); if (!string.IsNullOrEmpty (function.iteratorClass)) symbols.IteratorType = function.iteratorClass; if (function.iteratorScopes != null) foreach (Microsoft.Cci.ILocalScope scope in function.iteratorScopes) { RangeSymbol range = new RangeSymbol (); range.start = (int) scope.Offset; range.end = (int)(scope.Offset + scope.Length); symbols.IteratorScopes.Add (range); } }
static void ReadScopeAndLocals(PdbScope [] scopes, ScopeSymbol parent, MethodSymbols symbols) { foreach (PdbScope scope in scopes) ReadScopeAndLocals (scope, parent, symbols); }
int ICorDebugManagedCallback.LoadAssembly (CorDebugAppDomain pAppDomain, CorDebugAssembly pAssembly) { assemblies.Add (pAssembly); //CorMetadataImport mi = new CorMetadataImport(pAssembly); //Seems like this is always set on MicroFramework //pAssembly. JITCompilerFlags = CorDebugJITCompilerFlags.CORDEBUG_JIT_DISABLE_OPTIMIZATION; List<string> docPaths = new List<string> (); if (pAssembly.DebugData != null) { var md = pAssembly.MetaData; var reader = pAssembly.DebugData; if (!pAssembly.IsFrameworkAssembly) { foreach (var module in md.Assembly.Modules) { foreach (var t in module.Types) { foreach (var m in t.Methods) { var methodSymbols = new MethodSymbols (m.MetadataToken); //Ugly hack if(reader is Mono.Cecil.Mdb.MdbReader) { foreach(var variable in m.Body.Variables) methodSymbols.Variables.Add(variable); } reader.Read (methodSymbols); if (methodSymbols.Instructions.Count == 0) continue; DocInfo document; if (!documents.TryGetValue (methodSymbols.Instructions [0].SequencePoint.Document.Url, out document)) { document = new DocInfo (methodSymbols.Instructions [0].SequencePoint.Document.Url); document.Assembly = pAssembly; documents.Add (document.Url, document); } document.AddMethod (m, methodSymbols); if (!docPaths.Contains (document.Url)) docPaths.Add (document.Url); } } } } pAssembly.SetJmcStatus (true); } else { // Flag modules without debug info as not JMC. In this way // the debugger won't try to step into them pAssembly.SetJmcStatus (false); } foreach (var docPath in docPaths) BindSourceFileBreakpoints (docPath); pAppDomain.Process.Continue (); return 0; }
//For now I'm asuming there is no overlapping...(Is it even posible?) Delegate implementation inside method? public void AddMethod (MethodDefinition m, MethodSymbols methodSymbols) { int startLine = int.MaxValue; int endLine = -1; foreach (var instr in methodSymbols.Instructions) { if (instr.SequencePoint.StartLine > 0 && instr.SequencePoint.StartLine < startLine) startLine = instr.SequencePoint.StartLine; if (instr.SequencePoint.EndLine < 1000000 && instr.SequencePoint.EndLine > endLine) endLine = instr.SequencePoint.EndLine; } for (int i = 0; i < methods.Count; i++) { if (startLine < methods [i].startLine) { methods.Insert (i, new Method{ startLine = startLine, endLine = endLine, symbols = methodSymbols }); return; } } methods.Add (new Method{ startLine = startLine, endLine = endLine, symbols = methodSymbols }); }
public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols) { var buffer = new ByteBuffer(); symbols = new MethodSymbols(method.Name); this.method = method; reader.context = method; MoveTo(method.RVA); var flags = ReadByte(); MetadataToken local_var_token; switch (flags & 0x3) { case 0x2: // tiny buffer.WriteByte(flags); local_var_token = MetadataToken.Zero; symbols.code_size = flags >> 2; PatchRawCode(buffer, symbols.code_size, writer); break; case 0x3: // fat base.position--; PatchRawFatMethod(buffer, symbols, writer, out local_var_token); break; default: throw new NotSupportedException(); } var symbol_reader = reader.module.SymbolReader; if (symbol_reader != null && writer.metadata.write_symbols) { symbols.method_token = GetOriginalToken(writer.metadata, method); symbols.local_var_token = local_var_token; symbol_reader.Read(symbols); } return(buffer); }
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, })); } }
void DefineSequencePoints(MethodSymbols symbols) { writer.DefineSequencePoints ( GetDocument (symbols.Document), symbols.Offsets, symbols.StartRows, symbols.StartColumns, symbols.EndRows, symbols.EndColumns); }
public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols) { MetadataToken zero; ByteBuffer buffer = new ByteBuffer(); symbols = new MethodSymbols(method.Name); this.method = method; this.reader.context = method; this.MoveTo(method.RVA); byte num = base.ReadByte(); switch ((num & 3)) { case 2: buffer.WriteByte(num); zero = MetadataToken.Zero; symbols.code_size = num >> 2; this.PatchRawCode(buffer, symbols.code_size, writer); break; case 3: base.position--; this.PatchRawFatMethod(buffer, symbols, writer, out zero); break; default: throw new NotSupportedException(); } ISymbolReader reader = this.reader.module.symbol_reader; if ((reader != null) && writer.metadata.write_symbols) { symbols.method_token = GetOriginalToken(writer.metadata, method); symbols.local_var_token = zero; reader.Read(symbols); } return(buffer); }
void DefineVariables(MethodSymbols symbols) { if (!symbols.HasVariables) return; var start_offset = 0; var end_offset = symbols.CodeSize; writer.OpenScope (start_offset); var sym_token = new SymbolToken (symbols.LocalVarToken.ToInt32 ()); var variables = symbols.Variables; for (int i = 0; i < variables.Count; i++) { var variable = variables [i]; CreateLocalVariable (variable, sym_token, start_offset, end_offset); } writer.CloseScope (end_offset); }
void DefineVariables (MethodSymbols symbols, int start_offset, int end_offset) { if (!symbols.HasVariables) return; var sym_token = new SymbolToken (symbols.LocalVarToken.ToInt32 ()); var variables = symbols.Variables; for (int i = 0; i < variables.Count; i++) { var variable = variables [i]; CreateLocalVariable (variable, sym_token, start_offset, end_offset); } }
public void Write(MethodSymbols symbols) { var sym_token = new SymbolToken (symbols.MethodToken.ToInt32 ()); writer.OpenMethod (sym_token); DefineSequencePoints (symbols); DefineVariables (symbols); writer.CloseMethod (); }
void PatchRawFatMethod(ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token) { var flags = ReadUInt16 (); buffer.WriteUInt16 (flags); buffer.WriteUInt16 (ReadUInt16 ()); symbols.code_size = ReadInt32 (); buffer.WriteInt32 (symbols.code_size); local_var_token = ReadToken (); if (local_var_token.RID > 0) { var variables = symbols.variables = ReadVariables (local_var_token); buffer.WriteUInt32 (variables != null ? writer.GetStandAloneSignature (symbols.variables).ToUInt32 () : 0); } else buffer.WriteUInt32 (0); PatchRawCode (buffer, symbols.code_size, writer); if ((flags & 0x8) != 0) PatchRawSection (buffer, writer.metadata); }
void ReadLines(PdbLines lines, MethodSymbols symbols) { symbols.Document = GetDocument (lines.file); var count = lines.lines.Length; symbols.Offsets = new int [count]; symbols.StartRows = new int [count]; symbols.StartColumns = new int [count]; symbols.EndRows = new int [count]; symbols.EndColumns = new int [count]; for (int i = 0; i < lines.lines.Length; i++) { var line = lines.lines [i]; symbols.Offsets [i] = (int) line.offset; symbols.StartRows [i] = (int) line.lineBegin; symbols.StartColumns [i] = line.colBegin; symbols.EndRows [i] = (int) line.lineEnd; symbols.EndColumns [i] = line.colEnd; } }
public void Write(MethodSymbols symbols) { var method = new SourceMethodSymbol (symbols); var file = GetSourceFile (symbols.Instructions [0].SequencePoint.Document); var builder = writer.OpenMethod (file.CompilationUnit, 0, method); var count = symbols.Instructions.Count; for (int i = 0; i < count; i++) { var instruction = symbols.Instructions [i]; var sequence_point = instruction.SequencePoint; builder.MarkSequencePoint ( instruction.Offset, GetSourceFile (sequence_point.Document).CompilationUnit.SourceFile, sequence_point.StartLine, sequence_point.EndLine, false); } if (symbols.HasVariables) AddVariables (symbols.Variables); writer.CloseMethod (); }
public void Read(MethodSymbols symbols) { PdbFunction function; if (!functions.TryGetValue (symbols.MethodToken.ToUInt32 (), out function)) return; ReadSequencePoints (function, symbols); ReadLocals (function.scopes, symbols); }
public void Write(MethodSymbols symbols) { if (symbols.instructions.IsNullOrEmpty () && !symbols.HasVariables) return; var sym_token = new SymbolToken (symbols.MethodToken.ToInt32 ()); writer.OpenMethod (sym_token); DefineSequencePoints (symbols); if (symbols.Scope != null) WriteScope (symbols, symbols.Scope); else { var start_offset = 0; var end_offset = symbols.CodeSize; writer.OpenScope (start_offset); DefineVariables (symbols, symbols.Variables, start_offset, end_offset); writer.CloseScope (end_offset); } if (!string.IsNullOrEmpty (symbols.IteratorType)) DefineIteratorType (sym_token, symbols.IteratorType); if (symbols.iterator_scopes != null) DefineIteratorScopes (sym_token, symbols.IteratorScopes); writer.CloseMethod (); }
void ReadLines(PdbLines lines, MethodSymbols symbols) { for (int i = 0; i < lines.lines.Length; i++) { var line = lines.lines [i]; symbols.Instructions.Add (new InstructionSymbol ((int) line.offset, new SequencePoint (GetDocument (lines.file)) { StartLine = (int) line.lineBegin, StartColumn = (int) line.colBegin, EndLine = (int) line.lineEnd, EndColumn = (int) line.colEnd, })); } }
void DefineVariables(MethodSymbols symbols, Collection<VariableDefinition> variables, int start_offset, int end_offset) { var sym_token = new SymbolToken (symbols.LocalVarToken.ToInt32 ()); for (int i = 0; i < variables.Count; i++) { var variable = variables [i]; CreateLocalVariable (variable, sym_token, start_offset, end_offset); } }
void ReadLocals(PdbScope [] scopes, MethodSymbols symbols) { foreach (var scope in scopes) ReadLocals (scope, symbols); }
internal static StackFrame CreateFrame (MicroFrameworkDebuggerSession session, CorDebugFrame frame) { string file = ""; int line = 0; string method = ""; string lang = ""; if (frame.FrameType == CorFrameType.ILFrame) { if (frame.Function != null) { uint tk = TinyCLR_TypeSystem.SymbollessSupport.TinyCLRTokenFromMethodDefToken (frame.Function.Token); uint md = TinyCLR_TypeSystem.ClassMemberIndexFromTinyCLRToken (tk, frame.Function.Assembly); method = session.Engine.GetMethodName (md, true); var reader = frame.Function.Assembly.DebugData; if (reader != null) { var sim = new MethodSymbols (new Mono.Cecil.MetadataToken (frame.Function.Token)); //Ugliest hack ever if(reader is Mono.Cecil.Mdb.MdbReader) { for(int i = 0; i < 100; i++) sim.Variables.Add(new VariableDefinition(null)); } reader.Read (sim); InstructionSymbol prevSp = new InstructionSymbol (-1, null); foreach (var sp in sim.Instructions) { if (sp.Offset > frame.IP) break; prevSp = sp; } if (prevSp.Offset != -1) { line = prevSp.SequencePoint.StartLine; file = prevSp.SequencePoint.Document.Url; } } } lang = "Managed"; } // else if(frame.FrameType == CorFrameType.NativeFrame) // { // frame.GetNativeIP(out address); // method = "<Unknown>"; // lang = "Native"; // } else if (frame.FrameType == CorFrameType.InternalFrame) { switch (((CorDebugInternalFrame)frame).FrameInternalType) { case CorDebugInternalFrameType.STUBFRAME_M2U: method = "[Managed to Native Transition]"; break; case CorDebugInternalFrameType.STUBFRAME_U2M: method = "[Native to Managed Transition]"; break; case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION: method = "[Lightweight Method Call]"; break; case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION: method = "[Application Domain Transition]"; break; case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL: method = "[Function Evaluation]"; break; } } if (method == null) method = "<Unknown>"; var loc = new SourceLocation (method, file, line); return new StackFrame ((long)0, loc, lang); }
void ReadLocals(PdbScope scope, MethodSymbols symbols) { if (scope == null) return; foreach (var slot in scope.slots) { int index = (int) slot.slot; if (index < 0 || index >= symbols.Variables.Count) continue; var variable = symbols.Variables [index]; variable.Name = slot.name; } ReadLocals (scope.scopes, symbols); }
public void Read (MethodSymbols symbols) { var entry = symbol_file.GetMethodByToken (symbols.MethodToken.ToInt32 ()); if (entry == null) return; ReadLineNumbers (entry, symbols); ReadLocalVariables (entry, symbols); }
void ReadSequencePoints(PdbFunction function, MethodSymbols symbols) { if (function.lines == null) return; foreach (PdbLines lines in function.lines) ReadLines (lines, symbols); }
static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols) { foreach (var local in entry.GetLocals ()) { var variable = symbols.Variables [local.Index]; variable.Name = local.Name; } }
public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols) { MetadataToken zero; ByteBuffer byteBuffer = new ByteBuffer(); symbols = new MethodSymbols(method.Name); this.method = method; this.reader.context = method; this.MoveTo(method.RVA); byte num = base.ReadByte(); int num1 = num & 3; if (num1 == 2) { byteBuffer.WriteByte(num); zero = MetadataToken.Zero; symbols.code_size = num >> 2; this.PatchRawCode(byteBuffer, symbols.code_size, writer); } else { if (num1 != 3) { throw new NotSupportedException(); } this.position--; this.PatchRawFatMethod(byteBuffer, symbols, writer, out zero); } ISymbolReader symbolReader = this.reader.module.symbol_reader; if (symbolReader != null && writer.metadata.write_symbols) { symbols.method_token = CodeReader.GetOriginalToken(writer.metadata, method); symbols.local_var_token = zero; symbolReader.Read(symbols); } return(byteBuffer); }