예제 #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            if (String.Equals(args[0], "-p", StringComparison.Ordinal))
            {
                // attaching to the process
                Int32 pid;
                if (args.Length != 2)
                {
                    PrintUsage();
                    return;
                }
                if (!Int32.TryParse(args[1], out pid))
                {
                    PrintUsage();
                    return;
                }
                var debugger = DebuggingFacility.CreateDebuggerForProcess(pid);
                debugger.DebugActiveProcess(pid);
            }
            else
            {
                var debugger = DebuggingFacility.CreateDebuggerForExecutable(args[0]);
                var process  = debugger.CreateProcess(args[0]);

                process.OnBreakpoint += new MinDbg.CorDebug.CorProcess.CorBreakpointEventHandler(process_OnBreakpoint);
            }
            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            if (String.Equals(args[0], "-p", StringComparison.Ordinal))
            {
                // attaching to the process
                if (args.Length != 2)
                {
                    PrintUsage();
                    return;
                }
                if (!Int32.TryParse(args[1], out var pid))
                {
                    PrintUsage();
                    return;
                }
                var debugger = DebuggingFacility.CreateDebuggerForProcess(pid);
                debugger.DebugActiveProcess(pid);
            }
            else
            {
                //Console.WriteLine("Calling DebuggingFacility.CreateDebuggerForExecutable()");
                var debugger = DebuggingFacility.CreateDebuggerForExecutable(args[0]);
                //Console.WriteLine("DebuggingFacility.CreateDebuggerForExecutable() completed");
                var process = debugger.CreateProcess(args[0]);
                //Console.WriteLine("debugger.CreateProcess() completed");

                process.OnBreakpoint += process_OnBreakpoint;
                process.OnModuleLoad += ev =>
                {
                    Console.WriteLine($"ModuleLoad: {ev.Module.GetName()}");
                    if (Path.GetFileName(ev.Module.GetName()) != "TestApp-NetFramework.exe")
                    {
                        return;
                    }

                    foreach (var typeDef in ev.Module.TypeDefs())
                    {
                        Console.WriteLine($"  TypeDef: {typeDef.Item1} - {typeDef.Item2}");
                    }
                };

                process.OnException += ev =>
                {
                    Console.WriteLine($"EXCEPTION: {ev.Exception.TypeName} - {ev.Exception.Message}");
                };
            }
            Console.ReadKey();
        }