2014-10-01 133 views
0

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

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

您必须订阅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 
    } 
};