コード例 #1
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);
     }
 }
コード例 #2
0
ファイル: DebuggeeHelpers.cs プロジェクト: optikos/MIEngine
 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);
     }
 }
コード例 #3
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();
            }
        }
コード例 #4
0
ファイル: SampleTests.cs プロジェクト: optikos/MIEngine
        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();
            }
        }
コード例 #5
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();
            }
        }
コード例 #6
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();
        }
コード例 #7
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();
            }
        }
コード例 #8
0
        /// <summary>
        /// Apply changes in shared library so that the source and symbols is not matached anymore
        /// </summary>
        private void ApplyChangesInSharedLib(ITestSettings settings, int debuggeeMoniker)
        {
            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, debuggeeName, debuggeeMoniker, outLibName);
            string    libPath  = string.Format(CultureInfo.InvariantCulture, Path.Combine(debuggee.SourceRoot, srcLibName));

            Assert.True(File.Exists(libPath), string.Format(CultureInfo.InvariantCulture, "ERROR: Didn't find the source file:{0} under {1}", libPath, debuggee.SourceRoot));
            try
            {
                using (StreamWriter writer = File.AppendText(libPath))
                {
                    //TODO: I just simply added a new line to make the symbols mismatch after compile the library, we can add some real code changes here if need it.
                    writer.WriteLine(System.Environment.NewLine);
                }
            }
            catch
            {
                this.Comment("ERROR: Didn't apply the changes in shared library successfully.");
                throw;
            }
        }
コード例 #9
0
        /// <summary>
        /// Compile the application
        /// </summary>
        private void CompileApp(ITestSettings settings, int debuggeeMoniker)
        {
            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, debuggeeName, debuggeeMoniker, outAppName);

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

            case SupportedDebugger.Gdb_MinGW:
                // The sharedlib debuggee contains both POSIX and Windows support on loading dynamic library, we use "_MinGW" to identify the relevant testing code
                debuggee.AddDefineConstant("_MINGW");
                break;
            }

            debuggee.AddSourceFiles(srcAppName);

            debuggee.Compile();
        }
コード例 #10
0
        public void TestOptimizedSharedLib(ITestSettings settings)
        {
            this.TestPurpose("Tests basic bps and source information for shared library");
            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, 87, 89);
                SourceBreakpoints libBreakpoints  = debuggee.Breakpoints(SrcLibName, 9, 12);

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

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

                //Todo: this has different behavior on Mac, I have logged bug#247895 to track
                //Del said that Different compilers generate symbols differently.
                //Our tests have to be resilient to this fact. The location of the step is reasonable,
                //so this is by design.
                this.Comment("enter into the library source");
                runner.ExpectBreakpointAndStepToTarget(SrcLibName, 8, 9).AfterContinue();

                this.Comment("Step over");
                runner.Expects.HitStepEvent(SrcLibName, 10).AfterStepOver();

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

                    this.Comment("Check the local variable in sub function");
                    Assert.Matches("31", age.Value);

                    this.Comment("run to continue");
                    if (settings.DebuggerSettings.DebuggerType == SupportedDebugger.Lldb)
                    {
                        runner.Expects.HitBreakpointEvent(SourceName, 89)
                        .AfterContinue();
                        this.Comment("Verify current frame for main func");
                        inspector.AssertStackFrameNames(true, "main");
                    }
                    else
                    {
                        runner.Expects.HitBreakpointEvent(SrcLibName, 12)
                        .AfterContinue();
                        this.Comment("Verify current frame for library func");
                        inspector.AssertStackFrameNames(true, "myClass::DisplayAge");

                        this.Comment("Step out to main entry");
                        runner.Expects.HitBreakpointEvent(SourceName, 89).AfterContinue();

                        this.Comment("Verify current frame for main entry");
                        inspector.AssertStackFrameNames(true, "main");
                    }

                    this.Comment("Evaluate the expression:");
                    //skip the Mac's verification as bug#247893
                    currentFrame = inspector.Stack.First();
                    string strAge = currentFrame.Evaluate("myclass->DisplayAge(30)");

                    if (settings.DebuggerSettings.DebuggerType == SupportedDebugger.Gdb_MinGW ||
                        settings.DebuggerSettings.DebuggerType == SupportedDebugger.Gdb_Cygwin)
                    {
                        Assert.Equal("Cannot evaluate function -- may be inlined", strAge);
                    }
                }

                runner.DisconnectAndVerify();
            }
        }
コード例 #11
0
ファイル: SampleTests.cs プロジェクト: optikos/MIEngine
        public void TestFolderol(ITestSettings settings)
        {
            this.TestPurpose("This test checks a bunch of commands and events.");
            this.WriteSettings(settings);

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

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

                StoppedEvent stopAtBreak = new StoppedEvent(StoppedReason.Breakpoint);

                // VsDbg does not fire Breakpoint Change events when breakpoints are set.
                // Instead it sends a new breakpoint event when it is bound (after configuration done).
                bool bindsLate = (settings.DebuggerSettings.DebuggerType == SupportedDebugger.VsDbg);

                this.Comment("Set a breakpoint on line 8, but expect it to resolve to line 9.");
                runner.Expects.ConditionalEvent(!bindsLate, x => x.BreakpointChangedEvent(BreakpointReason.Changed, 9))
                .AfterSetBreakpoints(debuggee.Breakpoints(HelloSourceName, 8));

                this.Comment("Start debuggging until breakpoint is hit.");
                runner.Expects.ConditionalEvent(bindsLate, x => x.BreakpointChangedEvent(BreakpointReason.Changed, 9))
                .Event(stopAtBreak)
                .AfterConfigurationDone();

                Assert.Equal(HelloSourceName, stopAtBreak.ActualEventInfo.Filename);
                Assert.Equal(9, stopAtBreak.ActualEventInfo.Line);
                Assert.Equal(StoppedReason.Breakpoint, stopAtBreak.ActualEventInfo.Reason);

                this.Comment("Step forward twice until we have initialized variables");
                runner.Expects.StoppedEvent(StoppedReason.Step, HelloSourceName, 10)
                .AfterStepOver();
                runner.Expects.StoppedEvent(StoppedReason.Step, HelloSourceName, 11)
                .AfterStepIn();

                this.Comment("Inspect the stack and try evaluation.");
                using (IThreadInspector inspector = runner.GetThreadInspector())
                {
                    this.Comment("Get the stack trace");
                    IFrameInspector mainFrame = inspector.Stack.First();
                    inspector.AssertStackFrameNames(true, "main.*");

                    this.WriteLine("Main frame: {0}", mainFrame);

                    this.Comment("Get variables");
                    Assert.Subset(new HashSet <string>()
                    {
                        "x", "y", "argc", "argv"
                    }, mainFrame.Variables.ToKeySet());
                    mainFrame.AssertVariables(
                        "x", "6",
                        "argc", "1");

                    IVariableInspector argv = mainFrame.Variables["argv"];
                    Assert.Matches(HexNumberPattern, argv.Value);

                    this.Comment("Expand a variable (argv has *argv under it)");
                    string variableName = "*argv";
                    if (settings.DebuggerSettings.DebuggerType == SupportedDebugger.VsDbg)
                    {
                        variableName = String.Empty;
                    }
                    Assert.Contains(variableName, argv.Variables.Keys);
                    Assert.Matches(HexNumberPattern, argv.Variables[variableName].Value);

                    this.Comment("Evaluate with side effect");
                    string result = mainFrame.Evaluate("x = x + 1");
                    Assert.Equal("7", result);
                }

                this.Comment("Step to force stack info to refresh");
                runner.Expects.StoppedEvent(StoppedReason.Step).AfterStepOver();

                using (IThreadInspector inspector = runner.GetThreadInspector())
                {
                    this.Comment("Evaluation has side effect, make sure it propagates");
                    Assert.Equal("7", inspector.Stack.First().Variables["x"].Value);
                }

                runner.Expects.ExitedEvent(0).TerminatedEvent().AfterContinue();
                runner.DisconnectAndVerify();
            }
        }
コード例 #12
0
        /// <summary>
        /// Testing the common targeted scenarios
        /// </summary>
        private void RunTargetedScenarios(ITestSettings settings, string outputName, int debuggeeMoniker)
        {
            this.Comment("Set initial debuggee");
            IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, debuggeeName, debuggeeMoniker, outAppName);

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

                this.Comment("Set initial function breakpoints");
                FunctionBreakpoints functionBreakpoints = new FunctionBreakpoints("main", "myClass::DisplayName", "myClass::DisplayAge");
                runner.SetFunctionBreakpoints(functionBreakpoints);

                this.Comment("Set line breakpoints to the lines with entry of shared library");
                SourceBreakpoints bps = debuggee.Breakpoints(srcAppName, 71, 77);
                runner.SetBreakpoints(bps);

                this.Comment("Launch and run until first breakpoint in the entry of main");
                runner.ExpectBreakpointAndStepToTarget(srcAppName, startLine: 62, targetLine: 63)
                .AfterConfigurationDone();

                this.Comment("Continue to go to the line which is the first entry of shared library");
                runner.Expects.HitBreakpointEvent(srcAppName, 71)
                .AfterContinue();

                this.Comment("Step into the function in shared library");
                runner.Expects.HitStepEvent(srcLibName, 23)
                .AfterStepIn();

                this.Comment("Step out to go back to the entry in main function");
                runner.Expects.HitStepEvent(srcAppName, 71)
                .AfterStepOut();

                this.Comment("Step over to go to the line which is the second entry of shared library");
                runner.Expects.HitStepEvent(srcAppName, 73).AfterStepOver();

                this.Comment("Step over a function which have a breakpoint set in shared library");
                runner.ExpectBreakpointAndStepToTarget(srcLibName, startLine: 8, targetLine: 9).AfterStepOver();

                this.Comment("Step over a line in function which is inside shared library");
                runner.Expects.HitStepEvent(srcLibName, 10).AfterStepOver();

                this.Comment("Step out to go back to the entry in main function");
                runner.ExpectStepAndStepToTarget(srcAppName, startLine: 73, targetLine: 75).AfterStepOut();

                this.Comment("Continue to hit breakpoint in function which is inside shared library");
                runner.ExpectBreakpointAndStepToTarget(srcLibName, startLine: 15, targetLine: 16)
                .AfterContinue();

                this.Comment("Continue to hit breakpoint which set in the last entry of shared library");
                runner.Expects.HitBreakpointEvent(srcAppName, 77).AfterContinue();

                this.Comment("Step over a function which don't have breakpoint set in shared library");

                runner.Expects.HitStepEvent(srcAppName, 79)
                .AfterStepOver();

                this.Comment("Continue to run till at the end of the application");
                runner.Expects.TerminatedEvent().AfterContinue();

                runner.DisconnectAndVerify();
            }
        }