// Does the real work for an IL step. // fStepIn - true if step in; else false for step-over. // fVerbose - true if we should print out verbose diagnostic information. public static void ILStepWorker(bool stepIn, bool isVerbose, string args) { if ((args != null) && (args.Trim().Length > 0)) { throw new MDbgShellException("no arguments expected."); } // Do an IL-level step by single-stepping native code until our IL IP changes. MDbgProcess proc = GuiExtension.Shell.Debugger.Processes.Active; CorFrame curFrame = proc.Threads.Active.CurrentFrame.CorFrame; uint ipNative; uint offsetStart; uint offsetNew; ulong oldStackStart; ulong oldStackEnd; ulong newStackStart; ulong newStackEnd; CorDebugMappingResult result; curFrame.GetIP(out offsetStart, out result); curFrame.GetStackRange(out oldStackStart, out oldStackEnd); curFrame.GetNativeIP(out ipNative); if (isVerbose) { WriteOutput(String.Format(" IL step starting at offset IL_{0:x}, N=0x{1:x}, frame=({2:x},{3:x})", offsetStart, ipNative, oldStackStart, oldStackEnd)); } // We'll just do native single-steps until our IL ip changes. while (true) { // Single step native code. if (stepIn) { proc.StepInto(true).WaitOne(); } else { proc.StepOver(true).WaitOne(); } // Since we continued the process, our old frame becomes invalid and we need to get a new one. curFrame = proc.Threads.Active.CurrentFrame.CorFrame; curFrame.GetStackRange(out newStackStart, out newStackEnd); if ((newStackStart != oldStackStart) || (newStackEnd != oldStackEnd)) { // We're in a new frame. Maybe from step-in or step-out. if (isVerbose) { WriteOutput(String.Format(" IL step stopping at new frame =({0:x},{1:x})", newStackStart, newStackEnd)); } break; } curFrame.GetIP(out offsetNew, out result); curFrame.GetNativeIP(out ipNative); if ((offsetNew == offsetStart) && (proc.StopReason.GetType() == typeof(StepCompleteStopReason))) { if (isVerbose) { WriteOutput(String.Format(" IL step continuing. N=0x{0:x}", ipNative)); } continue; } if (isVerbose) { WriteOutput(String.Format(" IL step complete at IL_{0:x}", offsetNew)); } break; } }
internal static StackFrame CreateFrame(CorDebuggerSession session, CorFrame frame) { // TODO: Fix remaining. uint address = 0; //string typeFQN; //string typeFullName; string addressSpace = ""; string file = ""; int line = 0; int column = 0; string method = ""; string lang = ""; string module = ""; string type = ""; bool hasDebugInfo = false; bool hidden = false; bool external = true; if (frame.FrameType == CorFrameType.ILFrame) { if (frame.Function != null) { module = frame.Function.Module.Name; CorMetadataImport importer = new CorMetadataImport(frame.Function.Module); MethodInfo mi = importer.GetMethodInfo(frame.Function.Token); method = mi.DeclaringType.FullName + "." + mi.Name; type = mi.DeclaringType.FullName; addressSpace = mi.Name; ISymbolReader reader = session.GetReaderForModule(frame.Function.Module.Name); if (reader != null) { ISymbolMethod met = reader.GetMethod(new SymbolToken(frame.Function.Token)); if (met != null) { CorDebugMappingResult mappingResult; frame.GetIP(out address, out mappingResult); SequencePoint prevSp = null; foreach (SequencePoint sp in met.GetSequencePoints()) { if (sp.Offset > address) { break; } prevSp = sp; } if (prevSp != null) { line = prevSp.Line; column = prevSp.Offset; file = prevSp.Document.URL; address = (uint)prevSp.Offset; } } } // FIXME: Still steps into. //hidden = mi.GetCustomAttributes (true).Any (v => v is System.Diagnostics.DebuggerHiddenAttribute); } lang = "Managed"; hasDebugInfo = true; } else if (frame.FrameType == CorFrameType.NativeFrame) { frame.GetNativeIP(out address); method = "<Unknown>"; lang = "Native"; } else if (frame.FrameType == CorFrameType.InternalFrame) { switch (frame.InternalFrameType) { 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, column); return(new StackFrame((long)address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null)); }
internal static StackFrame CreateFrame(CorDebuggerSession session, CorFrame frame) { uint address = 0; string addressSpace = ""; string file = ""; int line = 0; int endLine = 0; int column = 0; int endColumn = 0; string method = "[Unknown]"; string lang = ""; string module = ""; string type = ""; bool hasDebugInfo = false; bool hidden = false; bool external = true; if (frame.FrameType == CorFrameType.ILFrame) { if (frame.Function != null) { module = frame.Function.Module.Name; CorMetadataImport importer = new CorMetadataImport(frame.Function.Module); MethodInfo mi = importer.GetMethodInfo(frame.Function.Token); var declaringType = mi.DeclaringType; if (declaringType != null) { method = declaringType.FullName + "." + mi.Name; type = declaringType.FullName; } else { method = mi.Name; } addressSpace = mi.Name; var sp = GetSequencePoint(session, frame); if (sp != null) { line = sp.StartLine; column = sp.StartColumn; endLine = sp.EndLine; endColumn = sp.EndColumn; file = sp.Document.URL; address = (uint)sp.Offset; } if (session.IsExternalCode(file)) { external = true; } else { if (session.Options.ProjectAssembliesOnly) { external = mi.GetCustomAttributes(true).Any(v => v is System.Diagnostics.DebuggerHiddenAttribute || v is System.Diagnostics.DebuggerNonUserCodeAttribute); } else { external = mi.GetCustomAttributes(true).Any(v => v is System.Diagnostics.DebuggerHiddenAttribute); } } hidden = mi.GetCustomAttributes(true).Any(v => v is System.Diagnostics.DebuggerHiddenAttribute); } lang = "Managed"; hasDebugInfo = true; } else if (frame.FrameType == CorFrameType.NativeFrame) { frame.GetNativeIP(out address); method = "[Native frame]"; lang = "Native"; } else if (frame.FrameType == CorFrameType.InternalFrame) { switch (frame.InternalFrameType) { 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; } } var loc = new SourceLocation(method, file, line, column, endLine, endColumn); return(new StackFrame(address, addressSpace, loc, lang, external, hasDebugInfo, hidden, module, type)); }
internal static StackFrame CreateFrame(CorDebuggerSession session, CorFrame frame) { uint address = 0; string file = ""; int line = 0; string method = ""; string lang = ""; string module = ""; if (frame.FrameType == CorFrameType.ILFrame) { if (frame.Function != null) { module = frame.Function.Module.Name; CorMetadataImport importer = new CorMetadataImport(frame.Function.Module); MethodInfo mi = importer.GetMethodInfo(frame.Function.Token); method = mi.DeclaringType.FullName + "." + mi.Name; ISymbolReader reader = session.GetReaderForModule(frame.Function.Module.Name); if (reader != null) { ISymbolMethod met = reader.GetMethod(new SymbolToken(frame.Function.Token)); if (met != null) { uint offset; CorDebugMappingResult mappingResult; frame.GetIP(out offset, out mappingResult); SequencePoint prevSp = null; foreach (SequencePoint sp in met.GetSequencePoints()) { if (sp.Offset > offset) { break; } prevSp = sp; } if (prevSp != null) { line = prevSp.Line; file = prevSp.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 (frame.InternalFrameType) { 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>"; } return(new StackFrame((long)address, module, method, file, line, lang)); }