Ejemplo n.º 1
0
        static void process_OnBreakpoint(CorBreakpointEventArgs ev)
        {
            Console.WriteLine("Breakpoint hit.");

            var source = ev.Thread.GetCurrentSourcePosition();

            DisplayCurrentSourceCode(source);

            ProcessCommand((ev.Controller is CorProcess process) ? process : ((CorAppDomain)ev.Controller).GetProcess());
        }
Ejemplo n.º 2
0
        void OnBreakpoint(object sender, CorBreakpointEventArgs e)
        {
            lock (debugLock) {
                if (evaluating)
                {
                    e.Continue = true;
                    return;
                }
            }
            OnStopped();
            e.Continue = false;
            // If a breakpoint is hit while stepping, cancel the stepping operation
            if (stepper != null && stepper.IsActive())
            {
                stepper.Deactivate();
            }
            SetActiveThread(e.Thread);
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetHitBreakpoint);

            args.Process   = GetProcess(process);
            args.Thread    = GetThread(e.Thread);
            args.Backtrace = new Backtrace(new CorBacktrace(e.Thread, this));
            OnTargetEvent(args);
        }
Ejemplo n.º 3
0
        void OnBreakpoint(object sender, CorBreakpointEventArgs e)
        {
            lock (debugLock) {
                if (evaluating)
                {
                    e.Continue = true;
                    return;
                }
            }

            BreakEventInfo binfo;

            if (breakpoints.TryGetValue(e.Breakpoint, out binfo))
            {
                e.Continue = true;
                Breakpoint bp = (Breakpoint)binfo.BreakEvent;

                if (bp.HitCount > 1)
                {
                    // Just update the count and continue
                    binfo.UpdateHitCount(bp.HitCount - 1);
                    return;
                }

                if (!string.IsNullOrEmpty(bp.ConditionExpression))
                {
                    string res = EvaluateExpression(e.Thread, bp.ConditionExpression);
                    if (bp.BreakIfConditionChanges)
                    {
                        if (res == bp.LastConditionValue)
                        {
                            return;
                        }
                        bp.LastConditionValue = res;
                    }
                    else
                    {
                        if (res != null && res.ToLower() == "false")
                        {
                            return;
                        }
                    }
                }
                switch (bp.HitAction)
                {
                case HitAction.CustomAction:
                    // If custom action returns true, execution must continue
                    if (binfo.RunCustomBreakpointAction(bp.CustomActionId))
                    {
                        return;
                    }
                    break;

                case HitAction.PrintExpression: {
                    string exp = EvaluateTrace(e.Thread, bp.TraceExpression);
                    binfo.UpdateLastTraceValue(exp);
                    return;
                }
                }
            }

            OnStopped();
            e.Continue = false;
            // If a breakpoint is hit while stepping, cancel the stepping operation
            if (stepper != null && stepper.IsActive())
            {
                stepper.Deactivate();
            }
            SetActiveThread(e.Thread);
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetHitBreakpoint);

            args.Process   = GetProcess(process);
            args.Thread    = GetThread(e.Thread);
            args.Backtrace = new Backtrace(new CorBacktrace(e.Thread, this));
            OnTargetEvent(args);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var stop   = new ManualResetEvent(false);
            var engine = new MDbgEngine();

            int    pid       = 0;
            int    lineStart = 0;
            int    lineEnd   = 0;
            string fileName  = "";

            try
            {
                pid = Int32.Parse(args[0]);

                lineStart = Int32.Parse(args[1]);
                lineEnd   = Int32.Parse(args[2]);

                fileName = args[3];
            }
            catch
            {
                Console.WriteLine("Usage: qndprof <pid> <lineStart> <lineEnd> <filename>");
            }

            var process = engine.Attach(pid);

            for (var l = lineStart; l < lineEnd; l++)
            {
                process.Breakpoints.CreateBreakpoint(fileName, l);
            }

            process.Go().WaitOne();

            // Process will stop when debugger attaches
            process.StopEvent.WaitOne();

            Console.WriteLine("Attaching events");


            var stopwatch = new Stopwatch();

            process.PostDebugEvent +=
                (sender, e) =>
            {
                //Console.Write("Event: ");
                //Console.WriteLine(e.CallbackType.ToString(), e.CallbackArgs.ToString());
                if (e.CallbackType == ManagedCallbackType.OnBreakpoint)
                {
                    // Do timer
                    stopwatch.Stop();
                    Console.Write(stopwatch.Elapsed);
                    Console.Write(" ");
                    Console.WriteLine(process.Threads.Active.CurrentSourcePosition.ToString());
                    CorBreakpointEventArgs a = (CorBreakpointEventArgs)e.CallbackArgs;
                    process.Go();
                    stopwatch.Reset();
                    stopwatch.Start();

                    // Delete the breakpoint to prevent loops from hitting it twice
                    process.Breakpoints.Lookup(a.Breakpoint).Delete();

                    if (process.Threads.Active.CurrentSourcePosition.Line == lineEnd)
                    {
                        stop.Set();
                    }
                }

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

                if (e.CallbackType == ManagedCallbackType.OnProcessExit)
                {
                    Console.WriteLine("Exit");
                    stop.Set();
                }
            };

            process.Go();

            //while (true) {
            //    Console.WriteLine("Waiting for stop");
            //    process.StopEvent.WaitOne();
            //    Console.WriteLine("Stop Reason: ", process.StopReason.ToString());
            //    if (Console.ReadKey().KeyChar != 'n')
            //    {
            //        Console.WriteLine("exit");
            //        break;
            //    }

            //    process.Go();
            //}

            stop.WaitOne();

            process.AsyncStop().WaitOne();
            process.Detach();
        }