/// <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); }
// // 1. Get the graphnode given the varname // 2. Get the sv of the symbol // 3. set the sv to the new value // 4. Get all graphnpodes dependent on the symbol and mark them dirty // 5. Re-execute the script // proc AssociativeEngine.SetValue(string varname, int block, StackValue, sv) // symbol = dsEXE.GetSymbol(varname, block) // globalStackIndex = symbol.stackindex // runtime.stack[globalStackIndex] = sv // AssociativeEngine.Propagate(symbol) // runtime.Execute() // end // private bool SetValue(string varName, int?value, out int nodesMarkedDirty) { int blockId = 0; // 1. Get the graphnode given the varname AssociativeGraph.GraphNode graphNode = MirrorTarget.GetFirstGraphNode(varName, out blockId); if (graphNode == null) { nodesMarkedDirty = 0; return(false); } SymbolNode symbol = graphNode.updateNodeRefList[0].nodeList[0].symbol; // 2. Get the sv of the symbol int globalStackIndex = symbol.index; // 3. set the sv to the new value StackValue sv; if (null == value) { sv = StackValue.Null; } else { sv = StackValue.BuildInt((long)value); } MirrorTarget.rmem.Stack[globalStackIndex] = sv; // 4. Get all graphnpodes dependent on the symbol and mark them dirty const int outerBlock = 0; ProtoCore.DSASM.Executable exe = MirrorTarget.exe; List <AssociativeGraph.GraphNode> reachableGraphNodes = AssociativeEngine.Utils.UpdateDependencyGraph( graphNode, MirrorTarget, graphNode.exprUID, false, runtimeCore.Options.ExecuteSSA, outerBlock, false); // Mark reachable nodes as dirty Validity.Assert(reachableGraphNodes != null); nodesMarkedDirty = reachableGraphNodes.Count; foreach (AssociativeGraph.GraphNode gnode in reachableGraphNodes) { gnode.isDirty = true; } // 5. Re-execute the script - re-execution occurs after this call return(true); }
public StackValue GetRawFirstValue(string name, int startBlock = 0, int classcope = Constants.kGlobalScope) { ProtoCore.DSASM.Executable exe = MirrorTarget.exe; for (int block = startBlock; block < exe.runtimeSymbols.Length; block++) { int index = exe.runtimeSymbols[block].IndexOf(name, classcope, Constants.kGlobalScope); if (Constants.kInvalidIndex != index) { //Q(Luke): This seems to imply that the LHS is an array index? var symbol = exe.runtimeSymbols[block].symbolList[index]; return(MirrorTarget.rmem.GetSymbolValue(symbol)); } } throw new NotImplementedException("{F5ACC95F-AEC9-486D-BC82-FF2CB26E7E6A}"); //@TODO(Luke): Replace this with a symbol lookup exception }
public StackValue GetGlobalValue(string name, int startBlock = 0) { ProtoCore.DSASM.Executable exe = MirrorTarget.exe; for (int block = startBlock; block < exe.runtimeSymbols.Length; block++) { int index = exe.runtimeSymbols[block].IndexOf(name, Constants.kInvalidIndex, Constants.kGlobalScope); if (Constants.kInvalidIndex != index) { SymbolNode symNode = exe.runtimeSymbols[block].symbolList[index]; if (symNode.absoluteFunctionIndex == Constants.kGlobalScope) { return(MirrorTarget.rmem.GetAtRelative(symNode.index)); } } } return(StackValue.Null); }
/// <summary> /// Searching variable name starting from specified block. /// Exception: /// SymbolNotFoundException if variable not found. /// </summary> /// <param name="name"></param> /// <param name="startBlock"></param> /// <returns></returns> public StackValue GetValue(string name, int startBlock = 0) { ProtoCore.DSASM.Executable exe = MirrorTarget.exe; for (int block = startBlock; block < exe.runtimeSymbols.Length; block++) { var symbolTable = exe.runtimeSymbols[block]; if (symbolTable == null) { continue; } int index = symbolTable.IndexOf(name, Constants.kInvalidIndex, Constants.kGlobalScope); if (Constants.kInvalidIndex != index) { SymbolNode symNode = symbolTable.symbolList[index]; if (symNode.absoluteFunctionIndex == Constants.kGlobalScope) { return(MirrorTarget.rmem.GetAtRelative(symNode.index)); } } } throw new SymbolNotFoundException(name); }
private int GetSymbolIndex(string name, out int ci, ref int block, out SymbolNode symbol) { RuntimeMemory rmem = MirrorTarget.rmem; ProtoCore.DSASM.Executable exe = runtimeCore.DSExecutable; int functionIndex = Constants.kGlobalScope; ci = Constants.kInvalidIndex; int functionBlock = Constants.kGlobalScope; if (runtimeCore.DebugProps.DebugStackFrameContains(DebugProperties.StackFrameFlagOptions.FepRun)) { ci = runtimeCore.watchClassScope = rmem.CurrentStackFrame.ClassScope; functionIndex = rmem.CurrentStackFrame.FunctionScope; functionBlock = rmem.CurrentStackFrame.FunctionBlock; } // TODO Jun: 'block' is incremented only if there was no other block provided by the programmer // This is only to address NUnit issues when retrieving a global variable // Some predefined functions are hard coded in the AST so isSingleAssocBlock will never be true //if (exe.isSingleAssocBlock) //{ // ++block; //} int index = -1; if (ci != Constants.kInvalidIndex) { ClassNode classnode = runtimeCore.DSExecutable.classTable.ClassNodes[ci]; if (functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex && functionBlock != runtimeCore.RunningBlock) { index = exe.runtimeSymbols[block].IndexOf(name, Constants.kGlobalScope, Constants.kGlobalScope); } if (index == Constants.kInvalidIndex) { index = classnode.Symbols.IndexOfClass(name, ci, functionIndex); } if (index != Constants.kInvalidIndex) { symbol = classnode.Symbols.symbolList[index]; return(index); } } else { CodeBlock searchBlock = runtimeCore.DSExecutable.CompleteCodeBlocks[block]; // To detal with the case that a language block defined in a function // // def foo() // { // [Imperative] // { // a; // } // } if (functionIndex != ProtoCore.DSASM.Constants.kInvalidIndex) { if (searchBlock.IsMyAncestorBlock(functionBlock)) { while (searchBlock.codeBlockId != functionBlock) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { searchBlock = searchBlock.parent; } else { break; } } } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, functionIndex); } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); } } else { index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); } if (index == ProtoCore.DSASM.Constants.kInvalidIndex) { searchBlock = searchBlock.parent; while (searchBlock != null) { block = searchBlock.codeBlockId; index = exe.runtimeSymbols[searchBlock.codeBlockId].IndexOf(name, ci, ProtoCore.DSASM.Constants.kInvalidIndex); if (index != ProtoCore.DSASM.Constants.kInvalidIndex) { break; } else { searchBlock = searchBlock.parent; } } } if (index != ProtoCore.DSASM.Constants.kInvalidIndex) { block = searchBlock.codeBlockId; symbol = exe.runtimeSymbols[searchBlock.codeBlockId].symbolList[index]; return(index); } } throw new NameNotFoundException { Name = name }; //throw new NotImplementedException("{F5ACC95F-AEC9-486D-BC82-FF2CB26E7E6A}"); //@TODO(Luke): Replace this with a symbol lookup exception }
private string GetGlobalVarTrace(List <string> variableTraces) { // Prints out the final Value of every symbol in the program // Traverse order: // Exelist, Globals symbols StringBuilder globaltrace = null; if (null == variableTraces) { globaltrace = new StringBuilder(); } ProtoCore.DSASM.Executable exe = MirrorTarget.exe; // Only display symbols defined in the default top-most langauge block; // Otherwise garbage information may be displayed. if (exe.runtimeSymbols.Length > 0) { int blockId = 0; // when this code block is of type construct, such as if, else, while, all the symbols inside are local //if (exe.instrStreamList[blockId] == null) // continue; SymbolTable symbolTable = exe.runtimeSymbols[blockId]; for (int i = 0; i < symbolTable.symbolList.Count; ++i) { formatParams.ResetOutputDepth(); SymbolNode symbolNode = symbolTable.symbolList[i]; bool isLocal = Constants.kGlobalScope != symbolNode.functionIndex; bool isStatic = (symbolNode.classScope != Constants.kInvalidIndex && symbolNode.isStatic); if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp) { // These have gone out of scope, their values no longer exist continue; } RuntimeMemory rmem = MirrorTarget.rmem; StackValue sv = rmem.GetSymbolValue(symbolNode); string formattedString = GetFormattedValue(symbolNode.name, 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); } if (null != variableTraces) { variableTraces.Add(formattedString); } } formatParams.ResetOutputDepth(); } return((null == globaltrace) ? string.Empty : globaltrace.ToString()); }