private MDbgBreakpoint CreateBreakpointAtPosition(string location) { ISequencePointResolver bploc = shell.BreakpointParser.ParseFunctionBreakpoint(location); if (bploc == null) { throw new Exception("Invalid breakpoint syntax."); } MDbgBreakpoint bpnew = shell.Debugger.Processes.Active.Breakpoints.CreateBreakpoint(bploc); return(bpnew); }
// Toggle a breakpoint at the given line. // Called on UI thread. protected override void ToggleBreakpointAtLine(int row) { // Currently, we require an active process. // An alternative is if the source file remembered the unbound breakpoints and then bound them // when the process started (and modules got loaded). if (!GuiExtension.Shell.Debugger.Processes.HaveActive) { return; } // See if we have anything to remove. foreach (BreakpointPair p in m_Breakpoints) { if (p.m_iLine == row) { MainForm.ExecuteOnWorkerThreadIfStoppedAndBlock(delegate(MDbgProcess process) { p.m_bp.Delete(); }); m_Breakpoints.Remove(p); return; } } // Ideally, BreakpointCollection would fire events for new breakpoints being added and removed. // This would be good because: // - the Gui would then know about breakpoints set from the command line. // - the Gui could then set breakpoints by issuing a Text Command (instead of // duplicating the logic again here). // Nothing to remove, so must be adding. MDbgBreakpoint b = null; MainForm.ExecuteOnWorkerThreadIfStoppedAndBlock(delegate(MDbgProcess proc) { MDbgBreakpointCollection c = proc.Breakpoints; { b = c.CreateBreakpoint(this.Text, row); } }); Debug.Assert(b != null); m_Breakpoints.Add(new BreakpointPair(b, row)); }
public bool RemoveBreakpoint(string file, int line) { if (shell.Debugger.Processes.HaveActive) { MDbgBreakpoint itemToRemove = null; foreach (MDbgBreakpoint item in shell.Debugger.Processes.Active.Breakpoints) { var location = (BreakpointLineNumberLocation)item.Location; if (location.FileName == file && location.LineNumber == line) { itemToRemove = item; item.Delete(); return(true); } } } return(false); }
public static void BreakCmd(string arguments, O2Thread.FuncVoidT1 <string> o2Callback) { if (arguments.Length == 0) { ListBreakpoints(o2Callback); return; } // We're adding a breakpoint. Parse the argument string. MDbgBreakpointCollection breakpoints = CommandBase.Debugger.Processes.Active.Breakpoints; ISequencePointResolver bploc = CommandBase.Shell.BreakpointParser.ParseFunctionBreakpoint(arguments); if (bploc == null) { throw new MDbgShellException("Invalid breakpoint syntax."); } MDbgBreakpoint bpnew = CommandBase.Debugger.Processes.Active.Breakpoints.CreateBreakpoint(bploc); CommandBase.WriteOutput(bpnew.ToString()); }
public static void DeleteCmd(string arguments, O2Thread.FuncVoidT1 <string> o2Callback) { var ap = new ArgParser(arguments); if (ap.Count != 1) { CommandBase.WriteOutput("Please choose some breakpoint to delete"); MdbgCommands.BreakCmd(""); return; } MDbgBreakpoint breakpoint = CommandBase.Debugger.Processes.Active.Breakpoints[ap.AsInt(0)]; if (breakpoint == null) { throw new MDbgShellException("Could not find breakpint #:" + ap.AsInt(0)); } else { breakpoint.Delete(); } }
public virtual void DisplayCurrentLocation() { if (!Debugger.Processes.HaveActive) { CommandBase.WriteOutput("STOP: Process Exited"); return; // don't try to display current location } else { Debug.Assert(Debugger.Processes.HaveActive); Object stopReason = Debugger.Processes.Active.StopReason; Type stopReasonType = stopReason.GetType(); if (stopReasonType == typeof(StepCompleteStopReason)) { // just ignore those } else if (stopReasonType == typeof(ThreadCreatedStopReason)) { CommandBase.WriteOutput("STOP: Thread Created"); } else if (stopReasonType == typeof(BreakpointHitStopReason)) { MDbgBreakpoint b = (stopReason as BreakpointHitStopReason).Breakpoint; if (b.Number == 0) // specal case to keep compatibility with our test scripts. { CommandBase.WriteOutput("STOP: Breakpoint Hit"); } else { CommandBase.WriteOutput(String.Format(CultureInfo.InvariantCulture, "STOP: Breakpoint {0} Hit", new Object[] { b.Number })); } } else if (stopReasonType == typeof(ExceptionThrownStopReason)) { ExceptionThrownStopReason ex = (ExceptionThrownStopReason)stopReason; CommandBase.WriteOutput("STOP: Exception thrown"); PrintCurrentException(); if (Debugger.Options.StopOnExceptionEnhanced || ex.ExceptionEnhancedOn) { // when we are in ExceptionEnhanced mode, we print more information CommandBase.WriteOutput("\tOffset: " + ex.Offset); CommandBase.WriteOutput("\tEventType: " + ex.EventType); CommandBase.WriteOutput("\tIntercept: " + (ex.Flags != 0)); } } else if (stopReasonType == typeof(UnhandledExceptionThrownStopReason)) { CommandBase.WriteOutput("STOP: Unhandled Exception thrown"); PrintCurrentException(); CommandBase.WriteOutput(""); CommandBase.WriteOutput("This is unhandled exception, continuing will end the process"); } else if (stopReasonType == typeof(ExceptionUnwindStopReason)) { CommandBase.WriteOutput("STOP: Exception unwind"); CommandBase.WriteOutput("EventType: " + (stopReason as ExceptionUnwindStopReason).EventType); } else if (stopReasonType == typeof(ModuleLoadedStopReason)) { CommandBase.WriteOutput("STOP: Module loaded: " + (stopReason as ModuleLoadedStopReason).Module.CorModule.Name); } else if (stopReasonType == typeof(AssemblyLoadedStopReason)) { CommandBase.WriteOutput("STOP: Assembly loaded: " + (stopReason as AssemblyLoadedStopReason).Assembly.Name); } else if (stopReasonType == typeof(MDANotificationStopReason)) { CorMDA mda = (stopReason as MDANotificationStopReason).CorMDA; CommandBase.WriteOutput("STOP: MDANotification"); CommandBase.WriteOutput("Name=" + mda.Name); CommandBase.WriteOutput("XML=" + mda.XML); } else if (stopReasonType == typeof(MDbgErrorStopReason)) { Exception e = (stopReason as MDbgErrorStopReason).ExceptionThrown; CommandBase.WriteOutput("STOP: MdbgError"); CommandBase.WriteOutput(FormatExceptionDiagnosticText(e)); } else { CommandBase.WriteOutput("STOP " + Debugger.Processes.Active.StopReason); } } if (!Debugger.Processes.Active.Threads.HaveActive) { return; // we won't try to show current location } MDbgThread thr = Debugger.Processes.Active.Threads.Active; MDbgSourcePosition pos = thr.CurrentSourcePosition; if (pos == null) { MDbgFrame f = thr.CurrentFrame; if (f.IsManaged) { CorDebugMappingResult mappingResult; uint ip; f.CorFrame.GetIP(out ip, out mappingResult); string s = "IP: " + ip + " @ " + f.Function.FullName + " - " + mappingResult; CommandBase.WriteOutput(s); } else { CommandBase.WriteOutput("<Located in native code.>"); } } else { string fileLoc = FileLocator.GetFileLocation(pos.Path); if (fileLoc == null) { // Using the full path makes debugging output inconsistant during automated test runs. // For testing purposes we'll get rid of them. //CommandBase.WriteOutput("located at line "+pos.Line + " in "+ pos.Path); CommandBase.WriteOutput("located at line " + pos.Line + " in " + System.IO.Path.GetFileName(pos.Path)); } else { IMDbgSourceFile file = SourceFileMgr.GetSourceFile(fileLoc); string prefixStr = pos.Line.ToString(CultureInfo.InvariantCulture) + ":"; if (pos.Line < 1 || pos.Line > file.Count) { CommandBase.WriteOutput("located at line " + pos.Line + " in " + pos.Path); throw new MDbgShellException(string.Format("Could not display current location; file {0} doesn't have line {1}.", file.Path, pos.Line)); } Debug.Assert((pos.Line > 0) && (pos.Line <= file.Count)); string lineContent = file[pos.Line]; if (pos.StartColumn == 0 && pos.EndColumn == 0 || !(CommandBase.Shell.IO is IMDbgIO2)) // or we don't have support for IMDbgIO2 { // we don't know location in the line CommandBase.Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput, prefixStr + lineContent + "\n"); } else { int hiStart; if (pos.StartColumn > 0) { hiStart = pos.StartColumn - 1; } else { hiStart = 0; } int hiLen; if (pos.EndColumn == 0 || // we don't know ending position (pos.EndLine > pos.StartLine)) // multi-line statement, select whole 1st line { hiLen = lineContent.Length; } else { hiLen = pos.EndColumn - 1 - hiStart; } Debug.Assert(CommandBase.Shell.IO is IMDbgIO2); // see if condition above (CommandBase.Shell.IO as IMDbgIO2).WriteOutput(MDbgOutputConstants.StdOutput, prefixStr + lineContent + "\n", hiStart + prefixStr.Length, hiLen); } } } }
public virtual LocationState DisplayCurrentLocation() { var locationState = new LocationState(ProcessStateEnum.Stop); if (!Debugger.Processes.HaveActive) { CommandBase.WriteOutput("STOP: Process Exited"); return(new LocationState(processState: ProcessStateEnum.Stop, message: "Process Exited")); } else { Debug.Assert(Debugger.Processes.HaveActive); Object stopReason = Debugger.Processes.Active.StopReason; Type stopReasonType = stopReason.GetType(); if (stopReasonType == typeof(StepCompleteStopReason)) { // just ignore those } else if (stopReasonType == typeof(ThreadCreatedStopReason)) { CommandBase.WriteOutput("STOP: Thread Created"); return(new LocationState(processState: ProcessStateEnum.Stop, message: "Thread Created")); } else if (stopReasonType == typeof(BreakpointHitStopReason)) { MDbgBreakpoint b = (stopReason as BreakpointHitStopReason).Breakpoint; if (b.Number == 0) // specal case to keep compatibility with our test scripts. { CommandBase.WriteOutput("STOP: Breakpoint Hit"); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: "Breakpoint Hit"); } else { CommandBase.WriteOutput(String.Format(CultureInfo.InvariantCulture, "STOP: Breakpoint {0} Hit", new Object[] { b.Number })); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"Breakpoint { b.Number } Hit"); } } else if (stopReasonType == typeof(ExceptionThrownStopReason)) { ExceptionThrownStopReason ex = (ExceptionThrownStopReason)stopReason; CommandBase.WriteOutput("STOP: Exception thrown"); PrintCurrentException(); if (Debugger.Options.StopOnExceptionEnhanced || ex.ExceptionEnhancedOn) { // when we are in ExceptionEnhanced mode, we print more information CommandBase.WriteOutput("\tOffset: " + ex.Offset); CommandBase.WriteOutput("\tEventType: " + ex.EventType); CommandBase.WriteOutput("\tIntercept: " + (ex.Flags != 0)); } locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"Exception thrown"); } else if (stopReasonType == typeof(UnhandledExceptionThrownStopReason)) { CommandBase.WriteOutput("STOP: Unhandled Exception thrown"); PrintCurrentException(); CommandBase.WriteOutput(""); CommandBase.WriteOutput("This is unhandled exception, continuing will end the process"); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"Unhandled Exception thrown"); } else if (stopReasonType == typeof(ExceptionUnwindStopReason)) { CommandBase.WriteOutput("STOP: Exception unwind"); CommandBase.WriteOutput("EventType: " + (stopReason as ExceptionUnwindStopReason).EventType); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"Exception unwind"); } else if (stopReasonType == typeof(ModuleLoadedStopReason)) { CommandBase.WriteOutput("STOP: Module loaded: " + (stopReason as ModuleLoadedStopReason).Module.CorModule.Name); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"Module loaded: {(stopReason as ModuleLoadedStopReason).Module.CorModule.Name}"); } else if (stopReasonType == typeof(AssemblyLoadedStopReason)) { CommandBase.WriteOutput("STOP: Assembly loaded: " + (stopReason as AssemblyLoadedStopReason).Assembly.Name); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"Assembly loaded: {(stopReason as AssemblyLoadedStopReason).Assembly.Name}"); } else if (stopReasonType == typeof(MDANotificationStopReason)) { CorMDA mda = (stopReason as MDANotificationStopReason).CorMDA; CommandBase.WriteOutput("STOP: MDANotification"); CommandBase.WriteOutput("Name=" + mda.Name); CommandBase.WriteOutput("XML=" + mda.XML); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"MDANotification"); } else if (stopReasonType == typeof(MDbgErrorStopReason)) { Exception e = (stopReason as MDbgErrorStopReason).ExceptionThrown; CommandBase.WriteOutput("STOP: MdbgError"); CommandBase.WriteOutput(FormatExceptionDiagnosticText(e)); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: $"MdbgError"); } else { CommandBase.WriteOutput("STOP " + Debugger.Processes.Active.StopReason); locationState = new LocationState(processState: ProcessStateEnum.Stop, message: Debugger.Processes.Active.StopReason.ToString()); } } if (!Debugger.Processes.Active.Threads.HaveActive) { return(locationState); } MDbgThread thr = Debugger.Processes.Active.Threads.Active; MDbgSourcePosition pos = thr.CurrentSourcePosition; if (pos == null) { MDbgFrame f = thr.CurrentFrame; if (f.IsManaged) { CorDebugMappingResult mappingResult; uint offset; f.CorFrame.GetIP(out offset, out mappingResult); CommandBase.WriteOutput($"Offset:{offset} Function:{f.Function.FullName}"); locationState = new LocationState(processState: ProcessStateEnum.Running, message: $"Offset:{offset} Function:{f.Function.FullName}", function: f.Function.FullName); } else { CommandBase.WriteOutput("<Located in native code.>"); locationState = new LocationState(processState: ProcessStateEnum.Running, message: "<Located in native code.>"); } } else { string fileLoc = FileLocator.GetFileLocation(pos.Path); MDbgFrame f = thr.CurrentFrame; if (fileLoc == null) { // Using the full path makes debugging output inconsistant during automated test runs. // For testing purposes we'll get rid of them. //CommandBase.WriteOutput("located at line "+pos.Line + " in "+ pos.Path); Console.WriteLine($@"ln:{pos.Line} col:{pos.StartColumn}:{pos.EndColumn} in [{f.Function.FullName}] - {pos.Path}"); locationState = new LocationState(processState: ProcessStateEnum.Running, function: f.Function.FullName, lineNumber: pos.Line, file: pos.Path); } else { IMDbgSourceFile file = SourceFileMgr.GetSourceFile(fileLoc); string prefixStr = pos.Line.ToString(CultureInfo.InvariantCulture) + ":"; if (pos.Line < 1 || pos.Line > file.Count) { Console.WriteLine($@"ln:{pos.Line} col:{pos.StartColumn}:{pos.EndColumn} in [{f.Function.FullName}] - {pos.Path}"); locationState = new LocationState(processState: ProcessStateEnum.Running, function: f.Function.FullName, lineNumber: pos.Line, file: pos.Path); throw new MDbgShellException(string.Format("Could not display current location; file {0} doesn't have line {1}.", file.Path, pos.Line)); } Debug.Assert((pos.Line > 0) && (pos.Line <= file.Count)); string lineContent = file[pos.Line]; if (pos.StartColumn == 0 && pos.EndColumn == 0 || !(CommandBase.Shell.IO is IMDbgIO2)) // or we don't have support for IMDbgIO2 { // we don't know location in the line CommandBase.Shell.IO.WriteOutput(MDbgOutputConstants.StdOutput, prefixStr + lineContent + "\n"); } else { Console.WriteLine($@"ln:{pos.Line} col:{pos.StartColumn}:{pos.EndColumn} in [{f.Function.FullName}] - {pos.Path}"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(lineContent); Console.ResetColor(); locationState = new LocationState(processState: ProcessStateEnum.Running, function: f.Function.FullName, lineNumber: pos.Line, file: pos.Path, code: lineContent); } } } return(locationState); }
public BreakpointPair(MDbgBreakpoint bp, int iLine) { m_bp = bp; m_iLine = iLine; }