protected DebuggerSession Start(string test) { DotNetExecutionCommand cmd = new DotNetExecutionCommand(); cmd.Command = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "MonoDevelop.Debugger.Tests.TestApp.exe"); cmd.Arguments = test; DebuggerStartInfo si = engine.CreateDebuggerStartInfo(cmd); DebuggerSession session = engine.CreateSession(); DebuggerSessionOptions ops = new DebuggerSessionOptions(); ops.EvaluationOptions = EvaluationOptions.DefaultOptions; ops.EvaluationOptions.EvaluationTimeout = 100000; FilePath path = Util.TestsRootDir; path = path.ParentDirectory.Combine("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", "Main.cs").FullPath; TextFile file = TextFile.ReadFile(path); int i = file.Text.IndexOf("void " + test); if (i == -1) { throw new Exception("Test not found: " + test); } i = file.Text.IndexOf("/*break*/", i); if (i == -1) { throw new Exception("Break marker not found: " + test); } int line, col; file.GetLineColumnFromPosition(i, out line, out col); Breakpoint bp = session.Breakpoints.Add(path, line); bp.Enabled = true; ManualResetEvent done = new ManualResetEvent(false); session.OutputWriter = delegate(bool isStderr, string text) { Console.WriteLine("PROC:" + text); }; session.TargetHitBreakpoint += delegate { done.Set(); }; session.Run(si, ops); if (!done.WaitOne(3000)) { throw new Exception("Timeout while waiting for initial breakpoint"); } return(session); }
protected DebuggerStartInfo CreateStartInfo(string test, string engineId) { var cmd = new DotNetExecutionCommand { TargetRuntime = runtime, Command = TargetExePath, Arguments = test }; var dsi = engine.CreateDebuggerStartInfo(cmd); return(dsi); }
protected void Start(string test) { TargetRuntime runtime; switch (EngineId) { case "MonoDevelop.Debugger.Win32": runtime = Runtime.SystemAssemblyService.GetTargetRuntime("MS.NET"); break; case "Mono.Debugger.Soft": runtime = Runtime.SystemAssemblyService.GetTargetRuntimes() .OfType <MonoTargetRuntime> () .OrderByDescending(o => o.Version) .FirstOrDefault(); break; default: runtime = Runtime.SystemAssemblyService.DefaultRuntime; break; } if (runtime == null) { Assert.Ignore("Runtime not found for: {0}", EngineId); return; } Console.WriteLine("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version); // main/build/tests FilePath path = Path.GetDirectoryName(GetType().Assembly.Location); var exe = Path.Combine(path, "MonoDevelop.Debugger.Tests.TestApp.exe"); var cmd = new DotNetExecutionCommand(); cmd.TargetRuntime = runtime; cmd.Command = exe; cmd.Arguments = test; if (Platform.IsWindows) { var monoRuntime = runtime as MonoTargetRuntime; if (monoRuntime != null) { var psi = new System.Diagnostics.ProcessStartInfo(Path.Combine(monoRuntime.Prefix, "bin", "pdb2mdb.bat"), cmd.Command); psi.UseShellExecute = false; psi.CreateNoWindow = true; System.Diagnostics.Process.Start(psi).WaitForExit(); } } var dsi = engine.CreateDebuggerStartInfo(cmd); var soft = dsi as SoftDebuggerStartInfo; if (soft != null) { var assemblyName = AssemblyName.GetAssemblyName(exe); soft.UserAssemblyNames = new List <AssemblyName> (); soft.UserAssemblyNames.Add(assemblyName); } Session = engine.CreateSession(); var ops = new DebuggerSessionOptions(); ops.EvaluationOptions = EvaluationOptions.DefaultOptions; ops.EvaluationOptions.AllowTargetInvoke = AllowTargetInvokes; ops.EvaluationOptions.EvaluationTimeout = 100000; path = path.ParentDirectory.ParentDirectory.Combine("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", test + ".cs").FullPath; SourceFile = TextFile.ReadFile(path); TestName = test; AddBreakpoint("break"); var done = new ManualResetEvent(false); Session.TargetHitBreakpoint += (sender, e) => { Frame = e.Backtrace.GetFrame(0); lastStoppedPosition = Frame.SourceLocation; targetStoppedEvent.Set(); done.Set(); }; Session.TargetExceptionThrown += (sender, e) => { Frame = e.Backtrace.GetFrame(0); for (int i = 0; i < e.Backtrace.FrameCount; i++) { if (!e.Backtrace.GetFrame(i).IsExternalCode) { Frame = e.Backtrace.GetFrame(i); break; } } lastStoppedPosition = Frame.SourceLocation; targetStoppedEvent.Set(); }; Session.TargetStopped += (sender, e) => { Frame = e.Backtrace.GetFrame(0); lastStoppedPosition = Frame.SourceLocation; targetStoppedEvent.Set(); }; var targetExited = new ManualResetEvent(false); Session.TargetExited += delegate { targetExited.Set(); }; Session.Run(dsi, ops); switch (WaitHandle.WaitAny(new WaitHandle[] { done, targetExited }, 30000)) { case 0: //Breakpoint is hit good... run tests now break; case 1: throw new Exception("Test application exited before hitting breakpoint"); default: throw new Exception("Timeout while waiting for initial breakpoint"); } }
protected DebuggerSession Start(string test) { TargetRuntime runtime; switch (EngineId) { case "MonoDevelop.Debugger.Win32": runtime = Runtime.SystemAssemblyService.GetTargetRuntime("MS.NET"); break; case "Mono.Debugger.Soft": runtime = Runtime.SystemAssemblyService.GetTargetRuntime("Mono"); break; default: runtime = Runtime.SystemAssemblyService.DefaultRuntime; break; } if (runtime == null) { return(null); } var cmd = new DotNetExecutionCommand(); cmd.Command = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "MonoDevelop.Debugger.Tests.TestApp.exe"); cmd.Arguments = test; cmd.TargetRuntime = runtime; DebuggerStartInfo si = engine.CreateDebuggerStartInfo(cmd); DebuggerSession session = engine.CreateSession(); var ops = new DebuggerSessionOptions(); ops.EvaluationOptions = EvaluationOptions.DefaultOptions; ops.EvaluationOptions.EvaluationTimeout = 100000; FilePath path = Util.TestsRootDir; path = path.ParentDirectory.Combine("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", "Main.cs").FullPath; TextFile file = TextFile.ReadFile(path); int i = file.Text.IndexOf("void " + test, StringComparison.Ordinal); if (i == -1) { throw new Exception("Test not found: " + test); } i = file.Text.IndexOf("/*break*/", i, StringComparison.Ordinal); if (i == -1) { throw new Exception("Break marker not found: " + test); } int line, col; file.GetLineColumnFromPosition(i, out line, out col); Breakpoint bp = session.Breakpoints.Add(path, line); bp.Enabled = true; var done = new ManualResetEvent(false); session.OutputWriter = (isStderr, text) => Console.WriteLine("PROC:" + text); session.TargetHitBreakpoint += delegate { done.Set(); }; session.Run(si, ops); if (!done.WaitOne(3000)) { throw new Exception("Timeout while waiting for initial breakpoint"); } return(session); }
protected void Start(string test) { TargetRuntime runtime; switch (EngineId) { case "MonoDevelop.Debugger.Win32": runtime = Runtime.SystemAssemblyService.GetTargetRuntime("MS.NET"); break; case "Mono.Debugger.Soft": runtime = Runtime.SystemAssemblyService.GetTargetRuntimes() .OfType <MonoTargetRuntime> () .OrderByDescending((o) => { //Attempt to find latest version of Mono registred in IDE and use that for unit tests if (string.IsNullOrWhiteSpace(o.Version) || o.Version == "Unknown") { return(new Version(0, 0, 0, 0)); } int indexOfBeforeDetails = o.Version.IndexOf(" (", StringComparison.Ordinal); if (indexOfBeforeDetails == -1) { return(new Version(0, 0, 0, 0)); } string hopefullyVersion = o.Version.Remove(indexOfBeforeDetails); Version version; if (Version.TryParse(hopefullyVersion, out version)) { return(version); } else { return(new Version(0, 0, 0, 0)); } }).FirstOrDefault(); break; default: runtime = Runtime.SystemAssemblyService.DefaultRuntime; break; } if (runtime == null) { Assert.Ignore("Runtime not found for: {0}", EngineId); return; } Console.WriteLine("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version + " " + (IntPtr.Size == 8 ? "64bit" : "32bit")); // main/build/tests FilePath path = Path.GetDirectoryName(GetType().Assembly.Location); var exe = Path.Combine(path, "MonoDevelop.Debugger.Tests.TestApp.exe"); var cmd = new DotNetExecutionCommand(); cmd.TargetRuntime = runtime; cmd.Command = exe; cmd.Arguments = test; if (Platform.IsWindows) { var monoRuntime = runtime as MonoTargetRuntime; if (monoRuntime != null) { var psi = new System.Diagnostics.ProcessStartInfo(Path.Combine(monoRuntime.Prefix, "bin", "pdb2mdb.bat"), cmd.Command); psi.UseShellExecute = false; psi.CreateNoWindow = true; System.Diagnostics.Process.Start(psi).WaitForExit(); } } var dsi = engine.CreateDebuggerStartInfo(cmd); var soft = dsi as SoftDebuggerStartInfo; if (soft != null) { var assemblyName = AssemblyName.GetAssemblyName(exe); soft.UserAssemblyNames = new List <AssemblyName> (); soft.UserAssemblyNames.Add(assemblyName); } Session = engine.CreateSession(); var ops = new DebuggerSessionOptions(); ops.ProjectAssembliesOnly = true; ops.EvaluationOptions = EvaluationOptions.DefaultOptions; ops.EvaluationOptions.AllowTargetInvoke = AllowTargetInvokes; ops.EvaluationOptions.EvaluationTimeout = 100000; path = path.ParentDirectory.ParentDirectory.Combine("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", test + ".cs").FullPath; SourceFile = TextFile.ReadFile(path); TestName = test; AddBreakpoint("break"); var done = new ManualResetEvent(false); Session.TargetHitBreakpoint += (sender, e) => { Frame = e.Backtrace.GetFrame(0); lastStoppedPosition = Frame.SourceLocation; targetStoppedEvent.Set(); done.Set(); }; Session.TargetExceptionThrown += (sender, e) => { Frame = e.Backtrace.GetFrame(0); for (int i = 0; i < e.Backtrace.FrameCount; i++) { if (!e.Backtrace.GetFrame(i).IsExternalCode) { Frame = e.Backtrace.GetFrame(i); break; } } lastStoppedPosition = Frame.SourceLocation; targetStoppedEvent.Set(); }; Session.TargetStopped += (sender, e) => { //This can be null in case of ForcedStop //which is called when exception is thrown //when Continue & Stepping is executed if (e.Backtrace != null) { Frame = e.Backtrace.GetFrame(0); lastStoppedPosition = Frame.SourceLocation; targetStoppedEvent.Set(); } else { Console.WriteLine("e.Backtrace is null"); } }; var targetExited = new ManualResetEvent(false); Session.TargetExited += delegate { targetExited.Set(); }; Session.Run(dsi, ops); Session.ExceptionHandler = (ex) => { Console.WriteLine("Session.ExceptionHandler:" + Environment.NewLine + ex.ToString()); return(true); }; switch (WaitHandle.WaitAny(new WaitHandle[] { done, targetExited }, 30000)) { case 0: //Breakpoint is hit good... run tests now break; case 1: throw new Exception("Test application exited before hitting breakpoint"); default: throw new Exception("Timeout while waiting for initial breakpoint"); } if (Session is SoftDebuggerSession) { Console.WriteLine("SDB protocol version:" + ((SoftDebuggerSession)Session).ProtocolVersion); } }