Example #1
0
        static void Main(string[] args)
        {
            var stop    = new ManualResetEvent(false);
            var engine  = new MDbgEngine();
            var process = engine.CreateProcess(@"c:\users\marcin\documents\visual studio 2010\Projects\ConsoleApplication9\ConsoleApplication9\bin\Release\ConsoleApplication9.exe", "", DebugModeFlag.Default, null);

            process.Go();

            process.PostDebugEvent +=
                (sender, e) =>
            {
                if (e.CallbackType == ManagedCallbackType.OnBreakpoint)
                {
                    process.Go();
                }

                if (e.CallbackType == ManagedCallbackType.OnException2)
                {
                    var e2 = (CorException2EventArgs)e.CallbackArgs;
                    //Console.WriteLine(ClrDump.CreateDump(process.CorProcess.Id, @"E:\temp.dmp", (int)MINIDUMP_TYPE.MiniDumpWithFullMemory, 0, IntPtr.Zero));
                }

                if (e.CallbackType == ManagedCallbackType.OnProcessExit)
                {
                    stop.Set();
                }
            };

            stop.WaitOne();
        }
Example #2
0
        private static void RunDebugger(string args)
        {
            Console.WriteLine("Starting debugger for: {0}", args);
            var stop = new ManualResetEvent(false);

            var engine = new MDbgEngine();

            engine.Options.CreateProcessWithNewConsole = true;

            var process = engine.CreateProcess(
                null,
                string.Format("\"{0}\" {1}", Assembly.GetExecutingAssembly().Location, args),
                DebugModeFlag.Default, null);

            process.PostDebugEvent +=
                (sender, e) =>
            {
                if (e.CallbackType == ManagedCallbackType.OnBreakpoint)
                {
                    SetBreakPoint(process);

                    Console.WriteLine();
                    Console.WriteLine("--- Can I haz breakpoint? ---");
                    var ce = (CorBreakpointEventArgs)e.CallbackArgs;

                    DumpLocals(process.Threads.Lookup(ce.Thread).CurrentFrame);
                    process.Go();
                }

                if (e.CallbackType == ManagedCallbackType.OnException2)
                {
                    Console.WriteLine();
                    Console.WriteLine("--- Oh noes, exception! ---");
                    var ce = (CorException2EventArgs)e.CallbackArgs;

                    if (ce.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE)
                    {
                        //DumpThread(process.Threads.Lookup(ce.Thread));
                        MiniDump(Path.Combine(Directory.GetCurrentDirectory(), "minidump.dmp"), process.CorProcess.Id);
                    }
                }

                if (e.CallbackType == ManagedCallbackType.OnProcessExit)
                {
                    stop.Set();
                }
            };

            process.Go();
            stop.WaitOne();
        }
Example #3
0
 public static MDbgEngine startProcess(this MDbgEngine engine, string exeToDebug, string arguments = "")
 {
     engine.CreateProcess(exeToDebug, arguments, DebugModeFlag.Debug, null);
     return(engine);
 }