Beispiel #1
0
 private static void AddSourceFiles(IDebuggee debuggee)
 {
     debuggee.AddSourceFiles(
         SourceMappingHelper.Main,
         Path.Combine(SourceMappingHelper.WriterFolder, SourceMappingHelper.Writer),
         Path.Combine(SourceMappingHelper.ManagerFolder, SourceMappingHelper.Manager));
 }
Beispiel #2
0
        public void CompileSourceMapForSourceMapping(ITestSettings settings)
        {
            this.TestPurpose("Compiles source map debuggee for source mapping.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SourceMappingHelper.OpenAndCompile(this, settings.CompilerSettings, DebuggeeMonikers.SourceMapping.Default);
        }
Beispiel #3
0
        public void CompileKitchenSinkForAttach(ITestSettings settings)
        {
            this.TestPurpose("Compiles the kitchen sink debuggee for attach.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.OpenAndCompile(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Attach);
        }
Beispiel #4
0
        public void BreakpointSettingsVerification(ITestSettings settings)
        {
            this.TestPurpose("Tests supported breakpoint settings");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Breakpoint);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee);

                Assert.True(runner.InitializeResponse.body.supportsConditionalBreakpoints.HasValue &&
                            runner.InitializeResponse.body.supportsConditionalBreakpoints.Value == true, "Conditional breakpoints should be supported");

                Assert.True(runner.InitializeResponse.body.supportsFunctionBreakpoints.HasValue &&
                            runner.InitializeResponse.body.supportsFunctionBreakpoints.Value == true, "Function breakpoints should be supported");

                this.Comment("Run to completion");
                runner.Expects.ExitedEvent()
                .TerminatedEvent()
                .AfterConfigurationDone();

                runner.DisconnectAndVerify();
            }
        }
Beispiel #5
0
        public void EvaluateInvalidExpression(ITestSettings settings)
        {
            this.TestPurpose("To test invalid expression evaluation return apropriate errors.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Expression);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch.");
                runner.Launch(settings.DebuggerSettings, debuggee, "-fExpression");

                this.Comment("Set a breakpoint so that we can stop at a line.");
                runner.SetBreakpoints(debuggee.Breakpoints(SinkHelper.Expression, 31));

                this.Comment("To start debugging and hit breakpoint.");
                runner.Expects.HitBreakpointEvent().AfterConfigurationDone();

                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    IFrameInspector currentFrame = threadInspector.Stack.First();

                    this.Comment("To evaluate some invalid expression on curren stack frame.");
                    currentFrame.AssertEvaluateAsError("notExistVar", EvaluateContext.Watch);
                }

                this.Comment("Continue to run to exist.");
                runner.Expects.TerminatedEvent().AfterContinue();

                runner.DisconnectAndVerify();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Compile the shared library
        /// </summary>
        private void CompileSharedLib(ITestSettings settings, int debuggeeMoniker)
        {
            IDebuggee debuggee = Debuggee.Create(this, settings.CompilerSettings, debuggeeName, debuggeeMoniker, outLibName, CompilerOutputType.SharedLibrary);

            debuggee.AddSourceFiles(srcLibName);
            debuggee.Compile();
        }
Beispiel #7
0
        public void CompileKitchenSinkForExpressionTests(ITestSettings settings)
        {
            this.TestPurpose("Compile kitchen sink debuggee for expression tests.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.OpenAndCompile(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Expression);
        }
Beispiel #8
0
        public void CompileKitchenSinkForBreakpointTests(ITestSettings settings)
        {
            this.TestPurpose("Compiles the kitchen sink debuggee.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.OpenAndCompile(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Breakpoint);
        }
Beispiel #9
0
 void IDebuggeeListener.VSDebuggeeDisconnected(IDebuggee debugee)
 {
     //System.Threading.Thread.Sleep(500);
     lock (this) {
         toVSCode.SendMessage(new TerminatedEvent());
     }
 }
Beispiel #10
0
        public void CallStackBasic(ITestSettings settings)
        {
            this.TestPurpose("To check all frames of callstack on a thead and evaluation on each frame.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Expression);

            this.Comment("Here are stack frames in a list we expect the actual to match with this.");
            StackFrame[] expectedstackFrames = ExpressionTests.GenerateFramesList(settings.DebuggerSettings);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch.");
                runner.Launch(settings.DebuggerSettings, debuggee, "-fExpression");

                this.Comment("Set a breakpoint so that we can stop after starting debugging.");
                runner.SetBreakpoints(debuggee.Breakpoints(SinkHelper.Expression, 19));

                this.Comment("To start debugging and break");
                runner.Expects.StoppedEvent(StoppedReason.Breakpoint, SinkHelper.Expression, 19).AfterConfigurationDone();

                this.Comment("To step in several times into the innermost layer of a recursive call.");
                runner.ExpectStepAndStepToTarget(SinkHelper.Expression, 9, 10).AfterStepIn();
                runner.Expects.HitStepEvent(SinkHelper.Expression, 12).AfterStepIn();
                runner.ExpectStepAndStepToTarget(SinkHelper.Expression, 9, 10).AfterStepIn();
                runner.Expects.HitStepEvent(SinkHelper.Expression, 12).AfterStepIn();
                runner.ExpectStepAndStepToTarget(SinkHelper.Expression, 9, 10).AfterStepIn();

                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    IEnumerable <IFrameInspector> stackOfCurrentThread = threadInspector.Stack;
                    this.Comment("To verify the count of stack frames count.");
                    Assert.True(stackOfCurrentThread.Count() >= 13, "Expected the stack frame count to be at least 13 deep");

                    this.Comment("To verify each frame, include frame name, line number and source name.");
                    int index = 0;
                    foreach (IFrameInspector frame in stackOfCurrentThread)
                    {
                        if (index >= 13)
                        {
                            break;
                        }
                        StackFrame expectedstackFrame = expectedstackFrames[index];
                        this.Comment("Comparing Names. Expecected: {0}, Actual: {1}", expectedstackFrame.Name, frame.Name);
                        Assert.Contains(expectedstackFrame.Name, frame.Name, StringComparison.Ordinal);
                        this.Comment("Comparing line number. Expecected: {0}, Actual: {1}", expectedstackFrame.Line, frame.Line);
                        Assert.Equal(expectedstackFrame.Line, frame.Line);
                        this.Comment("Comparing Source Name. Expecected: {0}, Actual: {1}", expectedstackFrame.SourceName, frame.SourceName);
                        Assert.Equal(expectedstackFrame.SourceName, frame.SourceName);
                        index++;
                    }
                }

                this.Comment("Continue to run to exist.");
                runner.Expects.TerminatedEvent().AfterContinue();

                runner.DisconnectAndVerify();
            }
        }
Beispiel #11
0
        public void TestOptimizedBpsAndSource(ITestSettings settings)
        {
            this.TestPurpose("Tests basic operation of bps and source information for optimized app");
            this.WriteSettings(settings);

            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, Name, DebuggeeMonikers.Optimization.OptimizationWithSymbols);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee);

                SourceBreakpoints mainBreakpoints             = debuggee.Breakpoints(SourceName, 68);
                SourceBreakpoints userDefinedClassBreakpoints = debuggee.Breakpoints(UserDefinedClassName, 8, 15, 54);

                this.Comment("Set initial breakpoints");
                runner.SetBreakpoints(mainBreakpoints);
                runner.SetBreakpoints(userDefinedClassBreakpoints);

                this.Comment("Launch and run until 1st bp");
                runner.Expects.HitBreakpointEvent(UserDefinedClassName, 8)
                .AfterConfigurationDone();

                this.Comment("run until 2nd bp");
                runner.Expects.HitBreakpointEvent(UserDefinedClassName, 54)
                .AfterContinue();

                this.Comment("run until 3rd bp");
                runner.Expects.HitBreakpointEvent(SourceName, 68)
                .AfterContinue();

                //Todo: this has different behavior on Mac(:16), Other Platforms(15) I have logged bug#247891 to track
                this.Comment("run until 4th bp");
                runner.ExpectBreakpointAndStepToTarget(UserDefinedClassName, 15, 16).AfterContinue();

                this.Comment("continue to next bp");
                runner.Expects.HitBreakpointEvent(UserDefinedClassName, 54)
                .AfterContinue();

                this.Comment("Check the current callstack frame");
                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    this.Comment("Get current frame object");
                    IFrameInspector currentFrame = threadInspector.Stack.First();

                    this.Comment("Verify current frame");
                    threadInspector.AssertStackFrameNames(true, "Foo::Sum");
                }

                this.Comment("step out to main entry");
                runner.Expects.HitStepEvent(SourceName, 69)
                .AfterStepOut();

                runner.Expects.ExitedEvent(0).TerminatedEvent().AfterContinue();
                runner.DisconnectAndVerify();
            }
        }
Beispiel #12
0
 /// <summary>
 /// Open existing debuggee
 /// </summary>
 private static IDebuggee OpenDebuggee(ILoggingComponent logger, ITestSettings settings, int debuggeeMoniker)
 {
     lock (syncObject)
     {
         IDebuggee debuggee = Debuggee.Open(logger, settings.CompilerSettings, debuggeeName, debuggeeMoniker, outAppName);
         Assert.True(File.Exists(debuggee.OutputPath), "The debuggee was not compiled. Missing " + debuggee.OutputPath);
         return(debuggee);
     }
 }
Beispiel #13
0
 public static IDebuggee Open(ILoggingComponent logger, ICompilerSettings settings, int moniker, string name, string outputname)
 {
     lock (s_lock)
     {
         IDebuggee debuggee = Debuggee.Open(logger, settings, name, moniker, outputname);
         Assert.True(File.Exists(debuggee.OutputPath), "The debuggee was not compiled. Missing " + debuggee.OutputPath);
         return(debuggee);
     }
 }
Beispiel #14
0
        /// <summary>
        /// Creates a SourceBreakpoints object that can be used to keep
        /// track of all the breakpoints in a file.
        /// </summary>
        public static SourceBreakpoints Breakpoints(this IDebuggee debuggee, string sourceRelativePath, params int[] lineNumbers)
        {
            SourceBreakpoints breakpoints = new SourceBreakpoints(debuggee, sourceRelativePath);

            foreach (int lineNumber in lineNumbers)
            {
                breakpoints.Add(lineNumber);
            }
            return(breakpoints);
        }
Beispiel #15
0
 /// <summary>
 /// Create the debuggee and compile the application
 /// </summary>
 private static IDebuggee CompileApp(ILoggingComponent logger, ITestSettings settings, int debuggeeMoniker)
 {
     lock (syncObject)
     {
         IDebuggee debuggee = Debuggee.Create(logger, settings.CompilerSettings, debuggeeName, debuggeeMoniker, outAppName);
         debuggee.AddSourceFiles(srcClassName, srcAppName);
         debuggee.Compile();
         return(debuggee);
     }
 }
Beispiel #16
0
        public void CompileHelloDebuggee(ITestSettings settings)
        {
            this.TestPurpose("Create and compile the 'hello' debuggee");
            this.WriteSettings(settings);

            IDebuggee debuggee = Debuggee.Create(this, settings.CompilerSettings, HelloName, DebuggeeMonikers.HelloWorld.Sample);

            debuggee.AddSourceFiles(HelloSourceName);
            debuggee.Compile();
        }
Beispiel #17
0
 public static IDebuggee OpenAndCompile(ILoggingComponent logger, ICompilerSettings settings, int moniker, string name, string outputname, Action <IDebuggee> addSourceFiles)
 {
     Assert.NotNull(addSourceFiles);
     lock (s_lock)
     {
         IDebuggee debuggee = Debuggee.Create(logger, settings, name, moniker, outputname);
         addSourceFiles(debuggee);
         debuggee.Compile();
         return(debuggee);
     }
 }
Beispiel #18
0
        public void RaisedUnhandledException(ITestSettings settings)
        {
            this.TestPurpose("This test checks to see if unhandled exception can work during debugging");
            this.WriteSettings(settings);
            this.Comment("Set initial debuggee for application");
            IDebuggee debuggee = OpenDebuggee(this, settings, DebuggeeMonikers.Exception.Default);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Launch the application");
                runner.Launch(settings.DebuggerSettings, debuggee, "-CallRaisedUnhandledException");

                this.Comment("Start debugging to hit the exception and verify it should stop at correct source file and line");
                runner.Expects.StoppedEvent(StoppedReason.Exception, srcClassName, 8).AfterConfigurationDone();

                this.Comment("Verify the callstack, variables and evaluation ");
                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    this.Comment("Get current frame object");
                    IFrameInspector currentFrame = threadInspector.Stack.First();

                    this.Comment("Verify current frame when stop at the exception");
                    threadInspector.AssertStackFrameNames(true, "myException::RaisedUnhandledException.*");

                    this.Comment("Verify the variables after stop at the exception");
                    Assert.Subset(new HashSet <string>()
                    {
                        "result", "temp", "this", "myvar"
                    }, currentFrame.Variables.ToKeySet());
                    currentFrame.AssertVariables("result", "10", "temp", "0", "myvar", "200");

                    // TODO: LLDB was affected by bug #240441, I wil update this once this bug get fixed
                    if (settings.DebuggerSettings.DebuggerType != SupportedDebugger.Lldb)
                    {
                        this.Comment("Evaluate an expression and verify the results after stop at the exception");
                        string varEvalResult = currentFrame.Evaluate("result = result + 1");
                        this.WriteLine("Expected: 11, Actual: {0}", varEvalResult);
                        Assert.Equal("11", varEvalResult);
                    }

                    // TODO: Mingw32 was affected by bug #242924, I wil update this once this bug get fixed
                    if (!(settings.DebuggerSettings.DebuggerType == SupportedDebugger.Gdb_MinGW && settings.DebuggerSettings.DebuggeeArchitecture == SupportedArchitecture.x86))
                    {
                        this.Comment("Evaluate a function and verify the the results after stop at exception");
                        string funEvalResult = currentFrame.Evaluate("EvalFunc(100,100)");
                        this.WriteLine("Expected: 200, Actual: {0}", funEvalResult);
                        Assert.Equal("200", funEvalResult);
                    }
                }

                this.Comment("Stop debugging");
                runner.DisconnectAndVerify();
            }
        }
Beispiel #19
0
        private void CompileSharedLib(ITestSettings settings, int debuggeeMoniker, bool symbol)
        {
            IDebuggee debuggee = Debuggee.Create(this, settings.CompilerSettings, Name, debuggeeMoniker, OutLibName, CompilerOutputType.SharedLibrary);

            debuggee.AddSourceFiles(SrcLibName);
            debuggee.CompilerOptions = CompilerOption.OptimizeLevel2;
            if (symbol)
            {
                debuggee.CompilerOptions = CompilerOption.GenerateSymbols;
            }
            debuggee.Compile();
        }
Beispiel #20
0
 private static void AddSourceFiles(IDebuggee debuggee)
 {
     // Add a source files, specify type, compile
     debuggee.AddSourceFiles(
         SinkHelper.Main,
         SinkHelper.Arguments,
         SinkHelper.Calling,
         SinkHelper.Environment,
         SinkHelper.Feature,
         SinkHelper.Threading,
         SinkHelper.NonTerminating,
         SinkHelper.Expression);
     debuggee.CompilerOptions |= CompilerOption.SupportThreading;
 }
Beispiel #21
0
        public void ExecutionStepBasic(ITestSettings settings)
        {
            this.TestPurpose("Verify basic step in/over/out should work during debugging");
            this.WriteSettings(settings);

            this.Comment("Open the kitchen sink debuggee for execution tests.");
            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Execution);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee, "-fCalling");

                this.Comment("Set initial source breakpoints");
                SourceBreakpoints bps = debuggee.Breakpoints(SinkHelper.Main, 21, 33);
                runner.SetBreakpoints(bps);

                this.Comment("Launch and run until hit the first entry");
                runner.Expects.HitBreakpointEvent(SinkHelper.Main, 21).AfterConfigurationDone();

                this.Comment("Step over the function");
                runner.Expects.HitStepEvent(SinkHelper.Main, 23).AfterStepOver();

                this.Comment("Continue to hit the second entry");
                runner.Expects.HitBreakpointEvent(SinkHelper.Main, 33).AfterContinue();

                this.Comment("Step in the function");
                runner.ExpectStepAndStepToTarget(SinkHelper.Feature, startLine: 19, targetLine: 20).AfterStepIn();

                this.Comment("Step over the function");
                runner.Expects.HitStepEvent(SinkHelper.Feature, 21).AfterStepOver();
                runner.Expects.HitStepEvent(SinkHelper.Feature, 22).AfterStepOver();

                this.Comment("Step in the function");
                runner.ExpectStepAndStepToTarget(SinkHelper.Calling, startLine: 47, targetLine: 48).AfterStepIn();

                this.Comment("Step out the function");
                runner.ExpectStepAndStepToTarget(SinkHelper.Feature, startLine: 22, targetLine: 23).AfterStepOut();

                this.Comment("Continue running at the end of application");
                runner.Expects.ExitedEvent()
                .TerminatedEvent()
                .AfterContinue();

                this.Comment("Verify debugger and debuggee closed");
                runner.DisconnectAndVerify();
            }
        }
Beispiel #22
0
        public void RunModeBreakpoints(ITestSettings settings)
        {
            this.TestPurpose("Tests setting breakpoints while in run mode");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Breakpoint);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee, "-fNonTerminating");
                runner.ConfigurationDone();

                // Wait a second to ensure the debuggee has entered run mode, then try to set a breakpoint
                Thread.Sleep(TimeSpan.FromSeconds(1));
                this.Comment("Set a function breakpoint while in run mode");
                FunctionBreakpoints functionBreakpoints = new FunctionBreakpoints("NonTerminating::DoSleep");
                runner.ExpectBreakpointAndStepToTarget(SinkHelper.NonTerminating, startLine: 37, targetLine: 38)
                .AfterSetFunctionBreakpoints(functionBreakpoints);

                this.Comment("Remove function breakpoint");
                functionBreakpoints.Remove("NonTerminating::DoSleep");
                runner.SetFunctionBreakpoints(functionBreakpoints);

                this.Comment("Continue, set a line breakpoint while in run mode");
                runner.Continue();

                // Wait a second to ensure the debuggee has entered run mode, then try to set a breakpoint
                Thread.Sleep(TimeSpan.FromSeconds(1));
                runner.Expects.HitBreakpointEvent(SinkHelper.NonTerminating, 28)
                .AfterSetBreakpoints(debuggee.Breakpoints(SinkHelper.NonTerminating, 28));

                this.Comment("Escape loop");
                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    IFrameInspector firstFrame = threadInspector.Stack.First();
                    this.WriteLine(firstFrame.ToString());
                    firstFrame.GetVariable("this", "shouldExit").Value = "1";
                }

                this.Comment("Continue until end");
                runner.Expects.ExitedEvent()
                .TerminatedEvent()
                .AfterContinue();

                runner.DisconnectAndVerify();
            }
        }
Beispiel #23
0
        public void TestArguments(ITestSettings settings)
        {
            this.TestPurpose("This test checks to see if arguments are passed to the debugee.");
            this.WriteSettings(settings);

            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, HelloName, DebuggeeMonikers.HelloWorld.Sample);

            this.Comment("Run the debuggee, check argument count");
            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                runner.Launch(settings.DebuggerSettings, debuggee, "Param 1", "Param 2");
                int args = 2;
                runner.Expects.ExitedEvent(exitCode: args).TerminatedEvent().AfterConfigurationDone();
                runner.DisconnectAndVerify();
            }
        }
Beispiel #24
0
        public void TestSharedLibWithoutSymbol(ITestSettings settings)
        {
            this.TestPurpose("Tests basic bps and source information for shared library without symbols");
            this.WriteSettings(settings);

            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, Name, DebuggeeMonikers.Optimization.OptimizationWithoutSymbols);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee);

                SourceBreakpoints mainBreakpoints = debuggee.Breakpoints(SourceName, 87, 91);

                this.Comment("Set initial breakpoints");
                runner.SetBreakpoints(mainBreakpoints);

                this.Comment("Launch and run until 1st bp");
                runner.Expects.HitBreakpointEvent(SourceName, 87)
                .AfterConfigurationDone();

                this.Comment("Step into the library source");
                runner.Expects.HitStepEvent(SourceName, 89)
                .AfterStepIn();

                this.Comment("Check the stack for debugging shared library without symbols");
                using (IThreadInspector inspector = runner.GetThreadInspector())
                {
                    IFrameInspector currentFrame = inspector.Stack.First();
                    inspector.AssertStackFrameNames(true, "main");

                    this.Comment("run to continue to 2nd bp");
                    runner.Expects.HitBreakpointEvent(SourceName, 91)
                    .AfterContinue();

                    this.Comment("Check the stack for debugging shared library without symbols");
                    currentFrame = inspector.Stack.First();
                    inspector.AssertStackFrameNames(true, "main");
                    this.Comment("Check the local variables in main function");
                    IVariableInspector age = currentFrame.Variables["age"];
                    Assert.Matches("31", age.Value);
                }

                runner.DisconnectAndVerify();
            }
        }
Beispiel #25
0
        public void AttachAsyncBreak(ITestSettings settings)
        {
            this.TestPurpose("Verifies attach and that breakpoints can be set from break mode.");
            this.WriteSettings(settings);

            IDebuggee debuggee        = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Attach);
            Process   debuggeeProcess = debuggee.Launch("-fNonTerminating", "-fCalling");

            using (ProcessHelper.ProcessCleanup(this, debuggeeProcess))
                using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
                {
                    this.Comment("Attach to debuggee");
                    runner.Attach(settings.DebuggerSettings, debuggeeProcess);
                    runner.ConfigurationDone();

                    this.Comment("Attempt to break all");
                    StoppedEvent breakAllEvent = new StoppedEvent(StoppedReason.Pause);
                    runner.Expects.Event(breakAllEvent)
                    .AfterAsyncBreak();

                    this.WriteLine("Break all stopped on:");
                    this.WriteLine(breakAllEvent.ActualEvent.ToString());

                    this.Comment("Set breakpoint while breaking code.");
                    runner.SetBreakpoints(debuggee.Breakpoints(SinkHelper.NonTerminating, 28));

                    this.Comment("Start running after the async break (since we have no idea where we are) and then hit the breakpoint");
                    runner.Expects.HitBreakpointEvent(SinkHelper.NonTerminating, 28)
                    .AfterContinue();

                    this.Comment("Evaluate the shouldExit member to true to stop the infinite loop.");
                    using (IThreadInspector threadInspector = runner.GetThreadInspector())
                    {
                        IFrameInspector firstFrame = threadInspector.Stack.First();
                        this.WriteLine(firstFrame.ToString());
                        firstFrame.GetVariable("shouldExitLocal").Value = "true";
                    }

                    this.Comment("Continue until debuggee exists");
                    runner.Expects.ExitedEvent(exitCode: 0).TerminatedEvent().AfterContinue();

                    this.Comment("Verify debugger and debuggee closed");
                    runner.DisconnectAndVerify();
                    Assert.True(debuggeeProcess.HasExited, "Debuggee still running.");
                }
        }
Beispiel #26
0
        private void TestEnvironmentVariable(ITestSettings settings, string variableName, string variableValue, bool newTerminal)
        {
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Environment);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                LaunchCommand launch = new LaunchCommand(settings.DebuggerSettings, debuggee.OutputPath, false, "-fEnvironment")
                {
                    StopAtEntry = false
                };
                if (variableValue != null)
                {
                    launch.Args.environment = new EnvironmentEntry[] {
                        new EnvironmentEntry {
                            Name = variableName, Value = variableValue
                        }
                    };
                }

                launch.Args.externalConsole = newTerminal;
                runner.RunCommand(launch);

                this.Comment("Set breakpoint");
                runner.SetBreakpoints(debuggee.Breakpoints(SinkHelper.Environment, 14));

                runner.Expects.StoppedEvent(StoppedReason.Breakpoint).AfterConfigurationDone();

                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    IFrameInspector currentFrame = threadInspector.Stack.First();
                    this.Comment("Verify locals variables on current frame.");
                    currentFrame.AssertEvaluateAsString("varValue1", EvaluateContext.Watch, variableValue);
                }

                this.Comment("Continue until end");
                runner.Expects.ExitedEvent()
                .TerminatedEvent()
                .AfterContinue();

                runner.DisconnectAndVerify();
            }
        }
Beispiel #27
0
        private void CompileApp(ITestSettings settings, int debuggeeMoniker)
        {
            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, Name, debuggeeMoniker, null, CompilerOutputType.Executable);

            switch (settings.DebuggerSettings.DebuggerType)
            {
            case SupportedDebugger.Gdb_Cygwin:
            case SupportedDebugger.Gdb_Gnu:
            case SupportedDebugger.Lldb:
                debuggee.AddLibraries("dl");
                break;
            }

            debuggee.AddSourceFiles(SourceName, UserDefinedClassName);
            debuggee.CompilerOptions = CompilerOption.OptimizeLevel2;
            debuggee.CompilerOptions = CompilerOption.GenerateSymbols;
            debuggee.Compile();
        }
Beispiel #28
0
        public void TestOptimizedLocals(ITestSettings settings)
        {
            this.TestPurpose("Tests basic local expression which is not been optimized");
            this.WriteSettings(settings);

            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, Name, DebuggeeMonikers.Optimization.OptimizationWithSymbols);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee);

                SourceBreakpoints userDefinedClassBreakpoints = debuggee.Breakpoints(UserDefinedClassName, 54);

                this.Comment("Set initial breakpoints");
                runner.SetBreakpoints(userDefinedClassBreakpoints);

                this.Comment("Launch and run until 1st bp");
                runner.Expects.HitBreakpointEvent(UserDefinedClassName, 54)
                .AfterConfigurationDone();

                this.Comment("Check the un-optimized values");
                using (IThreadInspector inspector = runner.GetThreadInspector())
                {
                    IFrameInspector    currentFrame = inspector.Stack.First();
                    IVariableInspector sum          = currentFrame.Variables["sum"];
                    IVariableInspector first        = currentFrame.Variables["first"];

                    this.Comment("Check the local variables in sub function");
                    Assert.Matches("^0", sum.Value);
                    Assert.Matches("^1", first.Value);

                    this.Comment("Step out");
                    runner.Expects.HitStepEvent(SourceName, 66)
                    .AfterStepOut();

                    this.Comment("Evaluate the expression:");
                    currentFrame = inspector.Stack.First();
                    inspector.AssertStackFrameNames(true, "main");
                }

                runner.DisconnectAndVerify();
            }
        }
Beispiel #29
0
        public void ThreadingBreakpoint(ITestSettings settings)
        {
            this.TestPurpose("Test breakpoint on multiple threads.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Threading);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Launching debuggee. Set breakpoint in worker thread code.");
                runner.Launch(settings.DebuggerSettings, true, debuggee, "-fThreading");
                runner.SetBreakpoints(debuggee.Breakpoints(SinkHelper.Threading, 16));

                // Turned on stop at entry, so should stop before anything is executed.
                // On Concord, this is a reason of "entry" versus "step" when it is hit.
                if (settings.DebuggerSettings.DebuggerType == SupportedDebugger.VsDbg)
                {
                    runner.Expects.HitEntryEvent().AfterConfigurationDone();
                }
                else
                {
                    runner.Expects.HitStepEvent()
                    .AfterConfigurationDone();
                }
                // Since there are 4 worker threads, expect to hit the
                // breakpoint 4 times, once on each thread.
                for (int i = 1; i <= 4; i++)
                {
                    StoppedEvent breakpointEvent = new StoppedEvent(StoppedReason.Breakpoint, SinkHelper.Threading, 16);
                    this.Comment("Run until breakpoint #{0}.", i);
                    runner.Expects.Event(breakpointEvent).AfterContinue();
                    this.WriteLine("Stopped on thread: {0}", breakpointEvent.ThreadId);

                    this.WriteLine("Ensure stopped thread exists in ThreadList");
                    IEnumerable <IThreadInfo> threadInfo = runner.GetThreads();
                    Assert.True(threadInfo.Any(thread => thread.Id == breakpointEvent.ThreadId), string.Format(CultureInfo.CurrentCulture, "ThreadId {0} should exist in ThreadList", breakpointEvent.ThreadId));
                }

                this.Comment("Run to end.");
                runner.Expects.TerminatedEvent().AfterContinue();

                runner.DisconnectAndVerify();
            }
        }
Beispiel #30
0
        public void WatchBasic(ITestSettings settings)
        {
            this.TestPurpose("Evaluate some expressions in watch.");
            this.WriteSettings(settings);

            IDebuggee debuggee = SinkHelper.Open(this, settings.CompilerSettings, DebuggeeMonikers.KitchenSink.Expression);

            using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
            {
                this.Comment("Configure launch");
                runner.Launch(settings.DebuggerSettings, debuggee, "-fExpression");

                this.Comment("Set a line breakpoints so that we can stop.");
                runner.SetBreakpoints(debuggee.Breakpoints(SinkHelper.Expression, 31));

                this.Comment("To start debugging and break");
                runner.Expects.StoppedEvent(StoppedReason.Breakpoint).AfterConfigurationDone();

                using (IThreadInspector threadInspector = runner.GetThreadInspector())
                {
                    IFrameInspector currentFrame = threadInspector.Stack.First();

                    this.Comment("To evaluate variables and functions in watch.");
                    string evalMyInt = currentFrame.Evaluate("myint-=100", EvaluateContext.Watch);
                    currentFrame.AssertEvaluateAsChar("mychar", EvaluateContext.Watch, 'A');
                    string evalMyBool = currentFrame.Evaluate("mybool", EvaluateContext.Watch);
                    currentFrame.AssertEvaluateAsWChar("mywchar", EvaluateContext.Watch, 'z');
                    currentFrame.AssertEvaluateAsDouble("mydouble", EvaluateContext.Watch, 321);
                    currentFrame.AssertEvaluateAsFloat("myfloat", EvaluateContext.Watch, 299);
                    string evalFuncMaxInt = currentFrame.Evaluate("Test::max(myint,1)", EvaluateContext.Watch);
                    currentFrame.AssertEvaluateAsDouble("Test::max(mydouble,0.0)-321.0", EvaluateContext.Watch, 0);

                    Assert.Equal("0", evalMyInt);
                    Assert.Equal("true", evalMyBool);
                    Assert.Equal("1", evalFuncMaxInt);
                }

                this.Comment("Run to completion");
                runner.Expects.TerminatedEvent().AfterContinue();

                runner.DisconnectAndVerify();
            }
        }