示例#1
0
        /// <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);
        }