示例#1
0
文件: AttachTest.cs 项目: xNUTs/PTVS
        public void TestAttachThreadsBreakAllAndSetExitFlag()
        {
            string debugSolution = TestData.GetPath(@"TestData\DebugAttach\DebugAttach.sln");
            string startFile     = "fg.py";

            using (var app = new VisualStudioApp()) {
                var        dbg2            = (Debugger2)app.Dte.Debugger;
                SD.Process processToAttach = OpenSolutionAndLaunchFile(app, debugSolution, startFile, "", "");

                try {
                    Process2 proc = AttachAndWaitForMode(app, processToAttach, AD7Engine.DebugEngineName, dbgDebugMode.dbgRunMode);
                    dbg2.Break(WaitForBreakMode: false);
                    DebugProject.WaitForMode(app, dbgDebugMode.dbgBreakMode);

                    var x = proc.Threads.Cast <Thread2>()
                            .SelectMany <Thread2, StackFrame>(t => t.StackFrames.Cast <StackFrame>())
                            .SelectMany <StackFrame, Expression>(f => f.Locals.Cast <Expression>())
                            .Where(e => e.Name == "exit_flag")
                            .First();

                    Assert.IsNotNull(x, "Couldn't find a frame with 'exit_flag' defined!");

                    x.Value = "True";

                    dbg2.Go(WaitForBreakOrEnd: false);
                    DebugProject.WaitForMode(app, dbgDebugMode.dbgDesignMode);
                } finally {
                    if (!processToAttach.HasExited)
                    {
                        processToAttach.Kill();
                    }
                }
            }
        }
示例#2
0
        public void TestAttachBasic()
        {
            string debugSolution = TestData.GetPath(@"TestData\DebugAttach\DebugAttach.sln");
            string startFile     = "Simple.py";


            using (var app = new VisualStudioApp()) {
                var        dbg2            = (Debugger2)app.Dte.Debugger;
                SD.Process processToAttach = OpenSolutionAndLaunchFile(app, debugSolution, startFile, "", "");

                try {
                    AttachAndWaitForMode(app, processToAttach, AD7Engine.DebugEngineName, dbgDebugMode.dbgRunMode);
                } finally {
                    dbg2.DetachAll();
                    DebugProject.WaitForMode(app, dbgDebugMode.dbgDesignMode);
                    if (!processToAttach.HasExited)
                    {
                        processToAttach.Kill();
                    }
                }
            }
        }
示例#3
0
        private static Process2 AttachAndWaitForMode(VisualStudioApp app, SD.Process processToAttach, object debugEngines, dbgDebugMode expectedMode)
        {
            Debugger2 dbg2 = (Debugger2)app.Dte.Debugger;

            System.Threading.Thread.Sleep(1000);
            Process2  result  = null;
            Transport t       = dbg2.Transports.Item("Default");
            bool      foundit = false;

            foreach (Process2 p in dbg2.LocalProcesses)
            {
                if (p.ProcessID == processToAttach.Id)
                {
                    foundit = true;
                    p.Attach2(debugEngines);
                    result = p;
                    break;
                }
            }
            Assert.IsTrue(foundit, "The process to attach [{0}] could not be found in LocalProcesses (did it exit immediately?)", processToAttach.Id);
            DebugProject.WaitForMode(app, expectedMode);
            return(result);
        }