private ProtoCore.Lang.Obj ExecExecutiveExpression(ExpressionInterpreterRunner exprInterpreter, string expression)
        {
            if (expression.Equals("@pc"))
            {
                int pc = core.CurrentExecutive.CurrentDSASMExec.PC;
                ProtoCore.DSASM.StackValue svpc = ProtoCore.DSASM.StackUtils.BuildInt(pc);
                return(new ProtoCore.Lang.Obj(svpc)
                {
                    Payload = pc, Type = new Type {
                        UID = (int)PrimitiveType.kTypeInt, IsIndexable = false
                    }
                });
            }
            else if (expression.StartsWith("@rc(") && expression.EndsWith(")"))
            {
                /*
                 * string subexpression = expression.Substring(4, expression.Length - 5);
                 * var watchMirror = exprInterpreter.Execute(subexpression);
                 * if (null != watchMirror)
                 * {
                 *  ProtoCore.Lang.Obj value = watchMirror.GetWatchValue();
                 *  if (value != null)
                 *  {
                 *      int rc = watchMirror.GetReferenceCount(value);
                 *      ProtoCore.DSASM.StackValue rcValue = ProtoCore.DSASM.StackUtils.BuildInt(rc);
                 *      return new ProtoCore.Lang.Obj(rcValue) { Payload = rc, Type = new Type { UID = (int)PrimitiveType.kTypeInt, IsIndexable = false } };
                 *  }
                 * }
                 */
            }

            return(null);
        }
Пример #2
0
        private Obj GetWatchValue(ProtoCore.Core core, string watchExpression)
        {
            ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core);
            ExecutionMirror             mirror      = watchRunner.Execute(watchExpression);

            return(mirror.GetWatchValue());
        }
Пример #3
0
        public void Defect_1467570_Crash_In_Debug_Mode()
        {
            string src = @" 
class Test 
{   

    IntArray : int[]; 
    
    constructor FirstApproach(intArray : int[]) 
    { 
        IntArray = intArray; 
    } 
    
    def Transform(adjust : int) 
    { 
        return = Test.FirstApproach(this.IntArray + adjust); 
    } 
        
} 

myTest = Test.FirstApproach({ 1, 2 }); 

myNeTwst = myTest.Transform(1); 
";

            fsr.PreStart(src, runnerConfig);
            DebugRunner.VMState vms = fsr.Step();   // myTest = Test.FirstApproach({ 1, 2 });

            ProtoCore.CodeModel.CodePoint cp = new ProtoCore.CodeModel.CodePoint
            {
                LineNo = 15,
                CharNo = 5
            };

            fsr.ToggleBreakpoint(cp);
            fsr.Run();  // line containing "this"

            ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core, null);
            ExecutionMirror             mirror      = watchRunner.Execute(@"this");
            Obj objExecVal = mirror.GetWatchValue();

            Assert.AreNotEqual(null, objExecVal);
            Assert.AreNotEqual(null, objExecVal.Payload);
            Assert.AreEqual(mirror.GetType(objExecVal), "Test");

            vms = fsr.StepOver();

            watchRunner = new ExpressionInterpreterRunner(core, null);
            mirror      = watchRunner.Execute(@"this");
            objExecVal  = mirror.GetWatchValue();
            Assert.AreNotEqual(null, objExecVal);
            Assert.AreEqual(-1, (Int64)objExecVal.Payload);
            Assert.AreEqual(mirror.GetType(objExecVal), "null");
        }
Пример #4
0
        public void Defect_1467570_Crash_In_Debug_Mode()
        {
            string src = @" 
class Test 
{   
    IntArray : int[]; 
    
    constructor FirstApproach(intArray : int[]) 
    { 
        IntArray = intArray; 
    } 
    
    def Transform(adjust : int) 
    { 
        return = Test.FirstApproach(this.IntArray + adjust); 
    } 
        
} 
myTest = Test.FirstApproach({ 1, 2 }); 
myNeTwst = myTest.Transform(1); 
";
            // Tracked by http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-3989
            string defectID = "MAGN-3989 Inspection of 'this' pointer has issues in expression interpreter";

            fsr.PreStart(src);
            DebugRunner.VMState           vms = fsr.Step(); // myTest = Test.FirstApproach({ 1, 2 });
            ProtoCore.CodeModel.CodePoint cp  = new ProtoCore.CodeModel.CodePoint
            {
                LineNo = 15,
                CharNo = 5
            };

            fsr.ToggleBreakpoint(cp);
            fsr.Run();  // line containing "this"

            ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core, fsr.runtimeCore);
            ExecutionMirror             mirror      = watchRunner.Execute(@"this");
            Obj objExecVal = mirror.GetWatchValue();

            Assert.AreNotEqual(null, objExecVal);
            Assert.AreNotEqual(null, objExecVal.Payload, defectID);
            Assert.AreEqual(mirror.GetType(objExecVal), "Test");
            vms = fsr.StepOver();

            watchRunner = new ExpressionInterpreterRunner(core, fsr.runtimeCore);
            mirror      = watchRunner.Execute(@"this");
            objExecVal  = mirror.GetWatchValue();
            Assert.AreNotEqual(null, objExecVal);
            Assert.AreEqual(-1, (Int64)objExecVal.Payload, defectID);
            Assert.AreEqual(mirror.GetType(objExecVal), "null");
        }
        private bool InterpretExpression(string expression)
        {
            if ((null != internalWorker) && internalWorker.IsBusy)
            {
                return(false); // Sorry but we're kinda busy right now.
            }
            if (string.IsNullOrEmpty(expression))
            {
                return(false);
            }

            Logger.LogInfo("InterpretExpression", expression);
            if (null == this.core || (null == debugRunner))
            {
                return(false); // Only in debug mode.
            }
            currentWatchedStackValue = null;
            ExpressionInterpreterRunner exprInterpreter = null;

            IOutputStream buildStream   = core.BuildStatus.MessageHandler;
            IOutputStream runtimeStream = core.RuntimeStatus.MessageHandler;

            // Disable output before interpret expression.
            core.BuildStatus.MessageHandler   = null;
            core.RuntimeStatus.MessageHandler = null;
            exprInterpreter = new ExpressionInterpreterRunner(this.core);

            try
            {
                currentWatchedStackValue = ExecExecutiveExpression(exprInterpreter, expression);
                if (currentWatchedStackValue == null)
                {
                    currentWatchedMirror = exprInterpreter.Execute(expression);
                    if (null != currentWatchedMirror)
                    {
                        currentWatchedStackValue = currentWatchedMirror.GetWatchValue();
                    }
                }
            }
            catch (ProtoCore.Exceptions.CompileErrorsOccured compileError)
            {
            }
            catch (Exception exception)
            {
            }

            // Re-enable output after execution is done.
            core.BuildStatus.MessageHandler   = buildStream;
            core.RuntimeStatus.MessageHandler = runtimeStream;
            return(null != currentWatchedStackValue);
        }
Пример #6
0
        /*internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, StreamReader log,
         *  bool watchNestedMode = false)
         * {
         *  //bool check = true;
         *
         *  // search for the line and LHS string in the log file
         *  // verify that the LHS identifier name equals 'symbolName'
         *  // pass the LHS string to GetWatchValue() and inspect it
         *  // verify the watch values with the log output
         *  string line = null;
         *  while ((line = log.ReadLine()) != null)
         *  {
         *      // Get line no.
         *      Match m = Regex.Match(line, @"At line, (\d+)");
         *      if (m.Success)
         *      {
         *          int lineNo = int.Parse(m.Groups[1].Value);
         *          if (lineNo == lineAtPrevBreak)
         *          {
         *              // Get lhs string
         *              // m = Regex.Match(line, @"(\d+), (\w+)");
         *              m = Regex.Match(line, @"(\d+), (.*)([^\s]+)");
         *              if (m.Success)
         *              {
         *                  string lhsString = m.Groups[2].Value;
         *
         *                  // Get lhs symbol name
         *                  m = Regex.Match(lhsString, @"(\w+)");
         *                  if (m.Success)
         *                  {
         *                      string lhsName = m.Groups[1].Value;
         *                      if (lhsName.Equals(symbolName))
         *                      {
         *                          ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core);
         *                          ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(lhsString);
         *                          Obj obj = mirror.GetWatchValue();
         *
         *                          if (!watchNestedMode)
         *                          {
         *                              // Cheat by peeking into heap etc. to dump output string
         *                              // match string with log output to verify
         *                              string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true);
         *                              line = log.ReadLine();
         *
         *                              m = Regex.Match(line, @"Info: (.*)");
         *                              if (m.Success)
         *                              {
         *                                  string output = m.Groups[1].Value;
         *                                  if (!output.Equals(result))
         *                                  {
         *                                      Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", lhsString));
         *                                      return;
         *                                  }
         *                              }
         *                          }
         *                          else
         *                          {
         *                              // TODO: Implement this - pratapa
         *                              // if obj is a class pointer, handle separately
         *                              // if obj is an array pointer, handle separately
         *                              // if obj is a literal, verify watch value with log output directly
         *                              GetStringValue(obj, mirror);
         *                          }
         *                          break;
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *  }
         * }*/

        internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core,
                                             Dictionary <int, List <string> > map, bool watchNestedMode = false, int ci = Constants.kInvalidIndex)
        {
            //bool check = true;

            // search for the line and LHS string in the map
            // verify that the LHS identifier name equals 'symbolName'
            // pass the LHS string to GetWatchValue() and inspect it
            // verify the watch values with the log output

            if (!map.ContainsKey(lineAtPrevBreak))
            {
                return;
            }

            List <string> expressions = map[lineAtPrevBreak];

            foreach (string exp in expressions)
            {
                // Get line no.
                // Get lhs symbol name
                string lhsName = null;
                int    index   = exp.IndexOf('.');
                if (index != -1)
                {
                    string[] parts = exp.Split('.');
                    lhsName = parts[parts.Length - 1];
                }
                else
                {
                    Match m = Regex.Match(exp, @"(\w+)");
                    if (m.Success)
                    {
                        lhsName = m.Groups[1].Value;
                    }
                }
                if (lhsName.Equals(symbolName))
                {
                    ExpressionInterpreterRunner            watchRunner = new ExpressionInterpreterRunner(core);
                    ProtoCore.DSASM.Mirror.ExecutionMirror mirror      = watchRunner.Execute(exp);
                    Obj obj = mirror.GetWatchValue();

                    if (!watchNestedMode)
                    {
                        // Cheat by peeking into heap etc. to dump output string
                        // match string with map output to verify
                        string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true);

                        Expression expr = new Expression(lineAtPrevBreak, exp, ci);
                        if (!InjectionExecutive.ExpressionMap.ContainsKey(expr))
                        {
                            return;
                        }

                        List <string> values = InjectionExecutive.ExpressionMap[expr];

                        if (!values.Contains(result))
                        {
                            Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", exp));
                            return;
                        }
                    }
                    else
                    {
                        // TODO: Implement this! - pratapa
                        // if obj is a class pointer, handle separately
                        // if obj is an array pointer, handle separately
                        // if obj is a literal, verify watch value with log output directly
                        GetStringValue(obj, mirror);
                    }
                    //break;
                }
            }
        }