/// <summary> /// Create a mirror for a given executive /// </summary> /// <param name="exec"></param> public ExecutionMirror(ProtoCore.DSASM.Executive exec, ProtoCore.RuntimeCore coreObj) { Validity.Assert(exec != null, "Can't mirror a null executive"); runtimeCore = coreObj; MirrorTarget = exec; }
/// <summary> /// VM Debugging API for general Debugging purposes /// temporarily used by Cmmand Line REPL /// </summary> /// <returns></returns> public string GetCoreDump() { // Prints out the final Value of every symbol in the program // Traverse order: // Exelist, Globals symbols StringBuilder globaltrace = null; ProtoCore.DSASM.Executive exec = runnerCore.CurrentExecutive.CurrentDSASMExec; ProtoCore.DSASM.Mirror.ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(exec, runnerCore); ProtoCore.DSASM.Executable exe = exec.rmem.Executable; // Only display symbols defined in the default top-most langauge block; // Otherwise garbage information may be displayed. string formattedString = string.Empty; if (exe.runtimeSymbols.Length > 0) { int blockId = 0; ProtoCore.DSASM.SymbolTable symbolTable = exe.runtimeSymbols[blockId]; for (int i = 0; i < symbolTable.symbolList.Count; ++i) { //int n = symbolTable.symbolList.Count - 1; //formatParams.ResetOutputDepth(); ProtoCore.DSASM.SymbolNode symbolNode = symbolTable.symbolList[i]; bool isLocal = ProtoCore.DSASM.Constants.kGlobalScope != symbolNode.functionIndex; bool isStatic = (symbolNode.classScope != ProtoCore.DSASM.Constants.kInvalidIndex && symbolNode.isStatic); if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp) { // These have gone out of scope, their values no longer exist //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); continue; } ProtoCore.Runtime.RuntimeMemory rmem = exec.rmem; ProtoCore.DSASM.StackValue sv = rmem.GetStackData(blockId, i, ProtoCore.DSASM.Constants.kGlobalScope); formattedString = formattedString + string.Format("{0} = {1}\n", symbolNode.name, execMirror.GetStringValue(sv, rmem.Heap, blockId)); //if (null != globaltrace) //{ // int maxLength = 1020; // while (formattedString.Length > maxLength) // { // globaltrace.AppendLine(formattedString.Substring(0, maxLength)); // formattedString = formattedString.Remove(0, maxLength); // } // globaltrace.AppendLine(formattedString); //} } //formatParams.ResetOutputDepth(); } //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); return(formattedString); }
public override ProtoCore.DSASM.StackValue Execute(ProtoCore.Runtime.Context c, List <ProtoCore.DSASM.StackValue> formalParameters, ProtoCore.DSASM.StackFrame stackFrame, Core core) { ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(core, true); ProtoCore.DSASM.Executive oldDSASMExec = null; if (core.CurrentExecutive != null) { oldDSASMExec = core.CurrentExecutive.CurrentDSASMExec; core.CurrentExecutive.CurrentDSASMExec = interpreter.runtime; } // Assert for the block type activation.globs = core.DSExecutable.runtimeSymbols[core.RunningBlock].GetGlobalSize(); // Params formalParameters.Reverse(); for (int i = 0; i < formalParameters.Count; i++) { interpreter.Push(formalParameters[i]); } ProtoCore.DSASM.StackValue svThisPtr = stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kThisPtr); ProtoCore.DSASM.StackValue svBlockDecl = stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kFunctionBlock); // Jun: Make sure we have no empty or unaligned frame data Validity.Assert(DSASM.StackFrame.kStackFrameSize == stackFrame.Frame.Length); // Setup the stack frame data //int thisPtr = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kThisPtr).opdata; int ci = activation.classIndex; int fi = activation.funcIndex; int returnAddr = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kReturnAddress).opdata; int blockDecl = (int)svBlockDecl.opdata; int blockCaller = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kFunctionCallerBlock).opdata; int framePointer = core.Rmem.FramePointer; int locals = activation.locals; // Update the running block to tell the execution engine which set of instruction to execute // TODO(Jun/Jiong): Considering store the orig block id to stack frame int origRunningBlock = core.RunningBlock; core.RunningBlock = (int)svBlockDecl.opdata; // Set SX register interpreter.runtime.SX = svBlockDecl; DSASM.StackFrameType callerType = (DSASM.StackFrameType)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kCallerStackFrameType).opdata; List <ProtoCore.DSASM.StackValue> registers = new List <DSASM.StackValue>(); ProtoCore.DSASM.StackValue svCallConvention; bool isDispose = procedureNode.name.Equals(ProtoCore.DSDefinitions.Kw.kw_Dispose); bool explicitCall = !c.IsReplicating && !c.IsImplicitCall && !isDispose; if (explicitCall) { svCallConvention = ProtoCore.DSASM.StackUtils.BuildNode(ProtoCore.DSASM.AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.CallType.kExplicit); } else { svCallConvention = ProtoCore.DSASM.StackUtils.BuildNode(ProtoCore.DSASM.AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.CallType.kImplicit); } stackFrame.SetAt(DSASM.StackFrame.AbsoluteIndex.kRegisterTX, svCallConvention); interpreter.runtime.TX = svCallConvention; // Set SX register stackFrame.SetAt(DSASM.StackFrame.AbsoluteIndex.kRegisterSX, svBlockDecl); interpreter.runtime.SX = svBlockDecl; // TODO Jun: // The stackframe carries the current set of registers // Determine if this can be done even for the non explicit call implementation registers.AddRange(stackFrame.GetRegisters()); // Comment Jun: the depth is always 0 for a function call as we are reseting this for each function call // This is only incremented for every language block bounce int depth = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kStackFrameDepth).opdata; DSASM.StackFrameType type = (DSASM.StackFrameType)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kStackFrameType).opdata; Validity.Assert(depth == 0); Validity.Assert(type == DSASM.StackFrameType.kTypeFunction); core.Rmem.PushStackFrame(svThisPtr, ci, fi, returnAddr, blockDecl, blockCaller, callerType, type, depth, framePointer, registers, locals); ProtoCore.DSASM.StackValue svRet; if (explicitCall) { svRet = ProtoCore.DSASM.StackUtils.BuildNode(DSASM.AddressType.ExplicitCall, activation.pc); } else { if (core.ExecMode != DSASM.InterpreterMode.kExpressionInterpreter && core.Options.IDEDebugMode) { svRet = interpreter.Run(core.Breakpoints, core.RunningBlock, activation.pc, Language.kInvalid); } else { svRet = interpreter.Run(core.RunningBlock, activation.pc, Language.kInvalid); } core.RunningBlock = origRunningBlock; } if (core.CurrentExecutive != null) { core.CurrentExecutive.CurrentDSASMExec = oldDSASMExec; } return(svRet); //DSASM.Mirror.ExecutionMirror.Unpack(svRet, core.heap, core); }