public void GoBreakContinousVariablesChange() => ContinousTestExecutionWrapper(() => { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); int lastArgument = -1; for (int i = 0; i < 3; i++) { Debugger.ContinueExecution(); System.Threading.Thread.Sleep(300); Debugger.BreakExecution(); Thread mainThread = FindThreadHostingMain(); var functionNames = mainThread.StackTrace.Frames.Select(f => f.FunctionName).ToArray(); var lastFrame = mainThread.StackTrace.Frames.First(frame => frame.FunctionName.Contains("InfiniteRecursionTestCase")); var functionArgument = lastFrame.Arguments.First(arg => arg.GetName() == "arg"); Assert.True((int)functionArgument > lastArgument, "Argument did not increase"); lastArgument = (int)functionArgument; int depthOfMainThread = mainThread.StackTrace.Frames.Where(frame => frame.FunctionName.Contains("InfiniteRecursionTestCase")).Count(); Assert.Equal(depthOfMainThread, lastArgument + 1); } }, DefaultTimeout);
/// <summary> /// Start process in inactive mode, release it, break it, print state in the loop. /// Test checks whether argument on stack changes. /// Also test asserts whether argument matches the stack lenght. /// </summary> static void GoBreakContinousVariablesChangeBody() { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); Diagnostics.Debug.WriteLine($"Process {TestProcessPath} started."); int lastArgument = -1; for (int i = 0; i < 5; i++) { Debugger.ContinueExecution(); Diagnostics.Debug.WriteLine($"Process continue iteration {i}."); System.Threading.Thread.Sleep(1000); Debugger.BreakExecution(); Thread mainThread = FindThreadHostingMain(); var functionNames = mainThread.StackTrace.Frames.Select(f => f.FunctionName).ToArray(); var lastFrame = mainThread.StackTrace.Frames.First(frame => frame.FunctionName.Contains("InfiniteRecursionTestCase")); var functionArgument = lastFrame.Arguments.First(arg => arg.GetName() == "arg"); Assert.IsTrue((int)functionArgument > lastArgument, "Argument did not increase"); lastArgument = (int)functionArgument; int depthOfMainThread = mainThread.StackTrace.Frames.Where(frame => frame.FunctionName.Contains("InfiniteRecursionTestCase")).Count(); Diagnostics.Debug.WriteLine($"Depth of main thread is {depthOfMainThread}"); Assert.AreEqual(depthOfMainThread, lastArgument + 1); } }
public void CheckIsLiveModeDebugging() => ContinousTestExecutionWrapper(() => { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); DbgEngDll debugger = Context.Debugger as DbgEngDll; Assert.NotNull(debugger); Assert.True(debugger.IsLiveDebugging); Debugger.ContinueExecution(); Debugger.BreakExecution(); }, DefaultTimeout);
public void GoBreakContinuosTestDepth() => ContinousTestExecutionWrapper(() => { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); int lastStackDepth = -1; for (int i = 0; i < 3; i++) { Debugger.ContinueExecution(); System.Threading.Thread.Sleep(1000); Debugger.BreakExecution(); int depthOfMainThread = FindThreadHostingMain().StackTrace.Frames.Length; // Ensure that thread depth grew between the executions. // Assert.True(depthOfMainThread > lastStackDepth, "Stack did not grow between the executions"); lastStackDepth = depthOfMainThread; } }, DefaultTimeout);
public void BreakpointWithBreakAfterHit() => ContinousTestExecutionWrapper(() => { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); Diagnostics.Debug.WriteLine($"Process {TestProcessPath} started."); System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false); int breakpointHitCount = 0; ulong bpAddress = GetFunctionAddress("InfiniteRecursionTestCase"); BreakpointSpec bpSpec = new BreakpointSpec(bpAddress) { BreakpointAction = () => { Thread mainThread = FindThreadHostingMain(); int recursionDepthCount = mainThread.StackTrace.Frames. Where(frame => frame.FunctionName.Contains("InfiniteRecursionTestCase")).Count(); // Insure that top of main thread points to the same location as breakpoint address. // Assert.Equal(bpAddress, mainThread.StackTrace.Frames[0].InstructionOffset); breakpointHitCount++; Assert.Equal(breakpointHitCount, recursionDepthCount); if (recursionDepthCount == 5) { are.Set(); } return(BreakpointHitResult.Continue); } }; Debugger.AddBreakpoint(bpSpec); Debugger.ContinueExecution(); are.WaitOne(); Debugger.BreakExecution(); }, DefaultTimeout);
/// <summary> /// Tests running multiple processes. /// </summary> static void GoBreakMultipleProcessesBody() { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); var ps = CsDebugScript.Process.All; Context.Debugger.ContinueExecution(ps[1]); Context.Debugger.ContinueExecution(ps[0]); foreach (var process in CsDebugScript.Process.All) { Debugger.ContinueExecution(process); } System.Threading.Thread.Sleep(1000); foreach (var process in CsDebugScript.Process.All) { Debugger.BreakExecution(process); } }
/// <summary> /// Start process in inactive mode, release it, break it, print state in the loop. /// Test runs a sample exe which recursivly calls the same function and increments the argument. /// Test checks whether stack trully grows between the continue/break calls. /// </summary> static void GoBreakContinuosTestDepthBody() { InitializeProcess(TestProcessPath, ProcessArguments, DefaultSymbolPath); Diagnostics.Debug.WriteLine($"Process {TestProcessPath} started."); int lastStackDepth = -1; for (int i = 0; i < 5; i++) { Debugger.ContinueExecution(); Diagnostics.Debug.WriteLine($"Process continue iteration {i}."); System.Threading.Thread.Sleep(1000); Debugger.BreakExecution(); int depthOfMainThread = FindThreadHostingMain().StackTrace.Frames.Length; // Ensure that thread depth grows between the executions. // Assert.IsTrue(depthOfMainThread > lastStackDepth, "Stack did not grow between the executions"); lastStackDepth = depthOfMainThread; } }