假设我有简单的C#控制台应用程序(下面的代码)。 我想使用mdbg manager wrapper逐步调试它。
using System;
namespace TestApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("1");
Console.WriteLine("2");
Console.WriteLine("3");
Console.WriteLine("4");
Console.WriteLine("5");
}
}
}
如何使用MDbgEngine逐步调试此代码?
[MTAThread]
static void Main(string[] args)
{
var debugger = new MDbgEngine();
debugger.Options.CreateProcessWithNewConsole = true;
debugger.Options.StopOnException = true;
var process = debugger.CreateProcess("TestApplication.exe", "", DebugModeFlag.Debug, null);
process.Go();
//HOW TO GO STEP BY STEP TROUGH THE TestApplication?
}
答案 0 :(得分:1)
您必须订阅process.PostDebugEvent
事件,希望调试器将在应用程序的最开始时停止,或者您可以使用process.Breakpoints.CreateBreakpoint()
process.PostDebugEvent += (ss, ee) => {
if (ee.CallbackType == ManagedCallbackType.OnBreakpoint)
{
// here do what you want and then you can
// process.StepInto, StepOver, or StepOut to move from here
}
};