Пример #1
0
 public override void Setup()
 {
     base.Setup();
     runner = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Пример #2
0
 public override void Setup()
 {
     // Specify some of the requirements of IDE.
     fsr = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Пример #3
0
        internal static ProtoCore.Core DebugRunnerRunOnly(string code, out RuntimeCore runtimeCore)
        {
            ProtoCore.Core core;
            DebugRunner    fsr;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode     = ProtoCore.ExecutionMode.Serial;
            options.GCTempVarsOnDebug = false;

            string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\";

            options.IncludeDirectories.Add(testPath);

            core = new ProtoCore.Core(options);
            core.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(core));

            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.PreStart(code);
            DebugRunner.VMState vms = null;

            vms         = fsr.Run();
            runtimeCore = fsr.runtimeCore;
            return(core);
        }
Пример #4
0
        internal static ProtoCore.Core DebugRunnerRunOnly(string code)
        {
            ProtoCore.Core core;
            DebugRunner    fsr;

            ProtoScript.Config.RunConfiguration runnerConfig;
            string testPath = @"..\..\..\Scripts\Debugger\";

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;

            core = new ProtoCore.Core(options);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.PreStart(code, runnerConfig);
            DebugRunner.VMState vms = null;

            vms = fsr.Run();

            return(core);
        }
Пример #5
0
        public void TestCyclicPointer01()
        {
            DebugRunner fsr = new DebugRunner(core);

            // Execute and verify the main script in a debug session
            fsr.PreStart(
                @"
class Obj
{
    x : var;
    constructor Obj()
    {
        x = null;
    }
}

p = Obj.Obj();
p.x = p;        // Assign the member x to its own 'this' pointer. This creates a cycle
m = p.x;

            ");

            DebugRunner.VMState vms = fsr.StepOver();
            vms = fsr.StepOver();
            vms = fsr.StepOver();

            // Test the heap contains a cycle
            Assert.IsTrue(ProtoCore.Utils.HeapUtils.IsHeapCyclic(core));
        }
    public void InheritedClassDoingConstructionCall()
    {
        var type    = assemblyWeaver.Assembly.GetType("InheritedClassDoingConstructionCall");
        var message = DebugRunner.CaptureDebug(() => Activator.CreateInstance(type));

        Assert.AreEqual(1, message.Count);
        Assert.IsTrue(message[0].StartsWith("InheritedClassDoingConstructionCall.ctor "), message[0]);
    }
    public void MethodWithReturn()
    {
        var type     = assemblyWeaver.Assembly.GetType("MiscMethods");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() => instance.MethodWithReturn());

        Assert.AreEqual(1, message.Count);
        Assert.IsTrue(message.First().StartsWith("MiscMethods.MethodWithReturn "));
    }
    public void GenericClassWithMethod()
    {
        var type     = assemblyWeaver.Assembly.GetType("GenericClassWithMethod`1[[System.String, mscorlib]]");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() => instance.Method());

        Assert.AreEqual(1, message.Count);
        Assert.IsTrue(message.First().StartsWith("GenericClassWithMethod`1.Method "));
    }
    public void ClassWithAttribute()
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithAttribute");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() => instance.Method());

        Assert.AreEqual(1, message.Count);
        Assert.IsTrue(message.First().StartsWith("ClassWithAttribute.Method "));
    }
    public void ClassWithConstructor()
    {
        var type    = assemblyWeaver.Assembly.GetType("ClassWithConstructor");
        var message = DebugRunner.CaptureDebug(() => Activator.CreateInstance(type));

        Assert.AreEqual(2, message.Count);
        Assert.IsTrue(message[0].StartsWith("ClassWithConstructor.cctor "));
        Assert.IsTrue(message[1].StartsWith("ClassWithConstructor.ctor "));
    }
Пример #11
0
 public override void Setup()
 {
     // Specify some of the requirements of IDE.
     runnerConfig             = new ProtoScript.Config.RunConfiguration();
     runnerConfig.IsParrallel = false;
     fsr = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
Пример #12
0
 public override void Setup()
 {
     base.Setup();
     runconfig             = new ProtoScript.Config.RunConfiguration();
     runconfig.IsParrallel = false;
     runner = new DebugRunner(core);
     DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
     CLRModuleType.ClearTypes();
 }
    public void InheritedClass()
    {
        var type    = assemblyWeaver.Assembly.GetType("InheritedClass");
        var message = DebugRunner.CaptureDebug(() => Activator.CreateInstance(type));

        Assert.AreEqual(1, message.Count);
        var first = message.First();

        Assert.IsTrue(first.StartsWith("InheritedClass.ctor "), first);
    }
    public void ClassWithAsyncMethodWithFastPath(bool recurse)
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithAsyncMethod");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() =>
        {
            var task = (Task)instance.MethodWithFastPathAsync(recurse);
            task.Wait();
        });

        Assert.AreEqual(recurse ? 2 : 1, message.Count);
        Assert.IsTrue(message.First().StartsWith("ClassWithAsyncMethod.MethodWithFastPathAsync "));
    }
    public void ClassWithAsyncMethod()
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithCompilerGeneratedTypes");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() =>
        {
            var task = (Task)instance.AsyncMethod();
            task.Wait();
        });

        Assert.AreEqual(1, message.Count);
        Assert.IsTrue(message.First().StartsWith("ClassWithCompilerGeneratedTypes.AsyncMethod "));
    }
    public void ClassWithYieldMethod()
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithCompilerGeneratedTypes");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() =>
        {
            var task = (IEnumerable <string>)instance.YieldMethod();
            task.ToList();
        });

        Assert.AreEqual(0, message.Count);
        //TODO: support yield
        //Assert.IsTrue(message.First().StartsWith("ClassWithCompilerGeneratedTypes.YieldMethod "));
    }
Пример #17
0
        public void Setup()
        {
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            core_ = new ProtoCore.Core(options);
            core_.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core_));
            core_.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core_));
            runconfig_             = new ProtoScript.Config.RunConfiguration();
            runconfig_.IsParrallel = false;
            runner_ = new DebugRunner(core_);
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();
        }
Пример #18
0
        public void Setup()
        {
            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            core = new ProtoCore.Core(options);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);
            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();
        }
Пример #19
0
        private bool SetupDebugRunner(string scriptPath)
        {
            if (string.IsNullOrEmpty(scriptPath))
            {
                return(false); // No script to execute.
            }
            if (File.Exists(scriptPath) == false)
            {
                return(false); // File does not exist.
            }
            Logger.LogInfo("SetupDebugRunner", "Init");
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            SetupCommonRunner(true);

            RunConfiguration runnerConfig = new RunConfiguration();

            runnerConfig.IsParrallel = false;

#if DEBUG
            var dumpBytecCodeFlag = this.core.Options.DumpByteCode;
            var verboseFlag       = this.core.Options.Verbose;
            var prevAsmOutput     = this.core.AsmOutput;

            this.core.Options.DumpByteCode = true;
            this.core.Options.Verbose      = true;

            this.ByteCodeStream = new MemoryStream();
            this.core.AsmOutput = new StreamWriter(this.ByteCodeStream);
#endif

            debugRunner = new DebugRunner(this.core);
            bool startSucceeded = debugRunner.LoadAndPreStart(scriptPath, runnerConfig);

#if DEBUG
            this.core.Options.DumpByteCode = dumpBytecCodeFlag;
            this.core.Options.Verbose      = verboseFlag;
            this.core.AsmOutput.Close();
            this.core.AsmOutput = prevAsmOutput == null ? Console.Out : prevAsmOutput;
#endif

            Logger.LogPerf("SetupDebugRunner", sw.ElapsedMilliseconds + " ms");
            return(startSucceeded);
        }
Пример #20
0
        internal static ProtoCore.Core DebugRunnerStepOver(string code, out RuntimeCore runtimeCore)
        {
            //Internal setup

            ProtoCore.Core core;
            DebugRunner    fsr;

            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            options.GCTempVarsOnDebug   = false;

            string testPath = @"..\..\..\test\Engine\ProtoTest\ImportFiles\";

            options.IncludeDirectories.Add(testPath);

            core = new ProtoCore.Core(options);
            core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
            core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));


            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            fsr.PreStart(code, runnerConfig);
            DebugRunner.VMState vms = null;

            while (!fsr.isEnded)
            {
                vms = fsr.StepOver();
            }

            runtimeCore = fsr.runtimeCore;
            return(core);
        }
    public void ClassWithAsyncMethod()
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithAsyncMethod");
        var instance = (dynamic)Activator.CreateInstance(type);

        DebugRunner.CaptureDebug(() =>
        {
            var task = (Task)instance.MethodWithAwaitAsync();
            task.Wait();
        });

        var methodBases = GetMethodInfoField();

        Assert.AreEqual(1, methodBases.Count);
        var methodBase = methodBases.First();

        Assert.AreEqual(methodBase.Name, "MethodWithAwaitAsync");
    }
    public void ClassWithAsyncMethodThatThrowsException()
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithAsyncMethod");
        var instance = (dynamic)Activator.CreateInstance(type);
        var message  = DebugRunner.CaptureDebug(() =>
        {
            try
            {
                var task = (Task)instance.MethodWithAwaitAndExceptionAsync();
                task.Wait();
            }
            catch (Exception)
            {
                // Expected
            }
        });

        Assert.AreEqual(1, message.Count);
        Assert.IsTrue(message.First().StartsWith("ClassWithAsyncMethod.MethodWithAwaitAndExceptionAsync "));
    }
    public void ClassWithAsyncMethodWithFastPath(bool recurse)
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithAsyncMethod");
        var instance = (dynamic)Activator.CreateInstance(type);

        DebugRunner.CaptureDebug(() =>
        {
            var task = (Task)instance.MethodWithFastPathAsync(recurse);
            task.Wait();
        });

        var methodBases = GetMethodInfoField();

        // Interceptor can't deal with 2 test cases
        //Assert.AreEqual(recurse ? 2 : 1, methodBases.Count);

        var methodBase = methodBases.Last();

        Assert.AreEqual("MethodWithFastPathAsync", methodBase.Name);
    }
        private void CleanUpRunners()
        {
            Logger.LogInfo("DetachFromDebugger", "Detach");

            // Clear up all watch related data members.
            this.workerParams.CurrentVmState = null;
            this.currentWatchedMirror        = null;
            this.currentWatchedStackValue    = null;

            if (null != scriptRunner)
            {
                scriptRunner = null;
            }

            if (null != debugRunner)
            {
                debugRunner.Shutdown();
                debugRunner = null;
            }

            if (null != internalWorker)
            {
                // @TODO(Ben): Perhaps cancellation is needed?
                internalWorker = null;
            }

            //Fix DG-1464973 Sprint25: rev 3444 : Multiple import issue - dispose core after execution
            //Core Cleanup should happen only after execution has finished,
            //DebugRunner is ShutDown.
            if (null != this.core)
            {
                this.core.Cleanup();
                this.core = null;
            }

            workerParams.ResetStates();
            SetExecutionState(ExecutionStateChangedEventArgs.States.None);
        }
    public void ClassWithAsyncMethodThatThrowsException()
    {
        var type     = assemblyWeaver.Assembly.GetType("ClassWithAsyncMethod");
        var instance = (dynamic)Activator.CreateInstance(type);

        DebugRunner.CaptureDebug(() =>
        {
            try
            {
                var task = (Task)instance.MethodWithAwaitAndExceptionAsync();
                task.Wait();
            }
            catch (Exception)
            {
                // Expected
            }
        });

        var methodBases = GetMethodInfoField();
        var methodBase  = methodBases.Last();

        Assert.AreEqual(methodBase.Name, "MethodWithAwaitAndExceptionAsync");
    }
Пример #26
0
        internal static void DebugRunnerStepIn(string includePath, string code, /*string logFile*/ Dictionary <int, List <string> > map, bool watchNestedMode = false)
        {
            //Internal setup
            ProtoCore.Core core;
            DebugRunner    fsr;

            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;
            options.GCTempVarsOnDebug   = false;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            if (!String.IsNullOrEmpty(includePath))
            {
                includePath = Path.GetDirectoryName(includePath);
                options.IncludeDirectories.Add(includePath);
            }


            core = new ProtoCore.Core(options);

            // Use the InjectionExecutive to overload POP and POPM
            // as we still need the symbol names and line nos. in debug mode for comparisons
            core.ExecutiveProvider = new InjectionExecutiveProvider();

            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new DebugRunner(core);

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

            //Run
            fsr.PreStart(code, runnerConfig);

            //StreamReader log = new StreamReader(logFile);

            //bool isPrevBreakAtPop = false;
            int    lineAtPrevBreak = -1;
            string symbolName      = null;

            DebugRunner.VMState vms = null;

            while (!fsr.isEnded)
            {
                vms = fsr.LastState;

                OpCode    opCode = OpCode.NONE;
                DebugInfo debug  = null;
                if (vms != null)
                {
                    // check if previous break is a POP
                    // if so, get the line no. and LHS
                    opCode = fsr.CurrentInstruction.opCode;
                    debug  = fsr.CurrentInstruction.debug;

                    if (opCode == ProtoCore.DSASM.OpCode.POP)
                    {
                        //isPrevBreakAtPop = true;
                        lineAtPrevBreak = vms.ExecutionCursor.StartInclusive.LineNo;
                    }
                }

                DebugRunner.VMState currentVms = fsr.Step();

                //if (isPrevBreakAtPop)

                if (debug != null)
                {
                    // Do not do the verification for imported DS files, for which the FilePath is non null
                    if (debug.Location.StartInclusive.SourceLocation.FilePath == null)
                    {
                        if (opCode == ProtoCore.DSASM.OpCode.POP)
                        {
                            VerifyWatch_Run(lineAtPrevBreak, core.DebugProps.CurrentSymbolName, core, map, watchNestedMode);
                        }
                        // if previous breakpoint was at a CALLR
                        else if (opCode == ProtoCore.DSASM.OpCode.CALLR)
                        {
                            if (core.DebugProps.IsPopmCall)
                            {
                                int ci = (int)currentVms.mirror.MirrorTarget.rmem.GetAtRelative(ProtoCore.DSASM.StackFrame.kFrameIndexClass).opdata;
                                VerifyWatch_Run(InjectionExecutive.callrLineNo, core.DebugProps.CurrentSymbolName, core, map, watchNestedMode, ci);
                            }
                        }
                    }
                }
                //isPrevBreakAtPop = false;
            }
            core.Cleanup();
        }