0

假设我有简单的 C# 控制台应用程序(下面的代码)。我想使用 mdbg 管理器包装器逐步调试它。

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?
}
4

1 回答 1

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
    }
};
于 2015-02-07T01:08:35.510 回答