Exemple #1
0
        public static MondValue JsonBreakpoint(MondDebugInfo.Statement statement)
        {
            var obj = MondValue.Object();

            obj["address"]   = statement.Address;
            obj["line"]      = statement.StartLineNumber;
            obj["column"]    = statement.StartColumnNumber;
            obj["endLine"]   = statement.EndLineNumber;
            obj["endColumn"] = statement.EndColumnNumber;
            return(obj);
        }
Exemple #2
0
        private void UpdateState(MondDebugContext context, int address)
        {
            var program   = context.Program;
            var debugInfo = program.DebugInfo;

            // find out where we are in the source code
            var statement = debugInfo.FindStatement(address);

            if (!statement.HasValue)
            {
                var position = debugInfo.FindPosition(address);

                if (position.HasValue)
                {
                    var line   = position.Value.LineNumber;
                    var column = position.Value.ColumnNumber;
                    statement = new MondDebugInfo.Statement(0, line, column, line, column);
                }
                else
                {
                    statement = new MondDebugInfo.Statement(0, -1, -1, -1, -1);
                }
            }

            // refresh all watches
            List <Watch> watches;

            lock (_sync)
                watches = _watches.ToList();

            foreach (var watch in watches)
            {
                RefreshWatch(_context, watch);
            }

            // apply new state and broadcast it
            MondValue message;

            lock (_sync)
            {
                var stmtValue = statement.Value;
                var programId = FindProgramIndex(program);

                _position = new BreakPosition(
                    programId,
                    stmtValue.StartLineNumber,
                    stmtValue.StartColumnNumber,
                    stmtValue.EndLineNumber,
                    stmtValue.EndColumnNumber);

                message                = new MondValue(MondValueType.Object);
                message["Type"]        = "State";
                message["Running"]     = false;
                message["Id"]          = _position.Id;
                message["StartLine"]   = _position.StartLine;
                message["StartColumn"] = _position.StartColumn;
                message["EndLine"]     = _position.EndLine;
                message["EndColumn"]   = _position.EndColumn;
                message["Watches"]     = new MondValue(watches.Select(Utility.JsonWatch));
                message["CallStack"]   = BuildCallStackArray(_context.CallStack);
            }

            Broadcast(message);
        }
Exemple #3
0
        /// <summary>
        /// Loads Mond bytecode from the specified stream.
        /// </summary>
        /// <param name="stream">Stream to read from.</param>
        public static MondProgram LoadBytecode(Stream stream)
        {
            var reader = new BinaryReader(stream, Encoding.UTF8);

            if (reader.ReadUInt32() != MagicId)
            {
                throw new NotSupportedException("Stream data is not valid Mond bytecode.");
            }

            byte version;

            if ((version = reader.ReadByte()) != FormatVersion)
            {
                throw new NotSupportedException(string.Format("Wrong bytecode version. Expected 0x{0:X2}, got 0x{1:X2}.", FormatVersion, version));
            }

            var hasDebugInfo = reader.ReadBoolean();

            var stringCount = reader.ReadInt32();
            var strings     = new List <string>(stringCount);

            for (var i = 0; i < stringCount; ++i)
            {
                var len = reader.ReadInt32();
                var buf = reader.ReadBytes(len);
                var str = Encoding.UTF8.GetString(buf);
                strings.Add(str);
            }

            var numberCount = reader.ReadInt32();
            var numbers     = new List <double>(numberCount);

            for (var i = 0; i < numberCount; ++i)
            {
                numbers.Add(reader.ReadDouble());
            }

            var bytecodeLength = reader.ReadInt32();
            var bytecode       = new int[bytecodeLength];

            for (var i = 0; i < bytecodeLength; i++)
            {
                bytecode[i] = reader.ReadInt32();
            }

            MondDebugInfo debugInfo = null;

            if (hasDebugInfo)
            {
                var fileName   = reader.ReadString();
                var sourceCode = reader.ReadString();

                var functionCount = reader.ReadInt32();
                List <MondDebugInfo.Function> functions = null;

                if (functionCount >= 0)
                {
                    functions = new List <MondDebugInfo.Function>(functionCount);
                    for (var i = 0; i < functionCount; ++i)
                    {
                        var address  = reader.ReadInt32();
                        var name     = reader.ReadInt32();
                        var function = new MondDebugInfo.Function(address, name);
                        functions.Add(function);
                    }
                }

                var lineCount = reader.ReadInt32();
                List <MondDebugInfo.Position> lines = null;

                if (lineCount >= 0)
                {
                    lines = new List <MondDebugInfo.Position>(lineCount);
                    for (var i = 0; i < lineCount; ++i)
                    {
                        var address      = reader.ReadInt32();
                        var lineNumber   = reader.ReadInt32();
                        var columnNumber = reader.ReadInt32();

                        var line = new MondDebugInfo.Position(address, lineNumber, columnNumber);
                        lines.Add(line);
                    }
                }

                var statementCount = reader.ReadInt32();
                List <MondDebugInfo.Statement> statements = null;

                if (statementCount >= 0)
                {
                    statements = new List <MondDebugInfo.Statement>(statementCount);
                    for (var i = 0; i < statementCount; ++i)
                    {
                        var address     = reader.ReadInt32();
                        var startLine   = reader.ReadInt32();
                        var startColumn = reader.ReadInt32();
                        var endLine     = reader.ReadInt32();
                        var endColumn   = reader.ReadInt32();

                        var statement = new MondDebugInfo.Statement(address, startLine, startColumn, endLine, endColumn);
                        statements.Add(statement);
                    }
                }

                var scopeCount = reader.ReadInt32();
                List <MondDebugInfo.Scope> scopes = null;

                if (scopeCount >= 0)
                {
                    scopes = new List <MondDebugInfo.Scope>(scopeCount);
                    for (var i = 0; i < scopeCount; ++i)
                    {
                        var id           = reader.ReadInt32();
                        var depth        = reader.ReadInt32();
                        var parentId     = reader.ReadInt32();
                        var startAddress = reader.ReadInt32();
                        var endAddress   = reader.ReadInt32();

                        var identCount = reader.ReadInt32();
                        var idents     = new List <MondDebugInfo.Identifier>(identCount);
                        for (var j = 0; j < identCount; ++j)
                        {
                            var name       = reader.ReadInt32();
                            var isReadOnly = reader.ReadBoolean();
                            var frameIndex = reader.ReadInt32();
                            var idx        = reader.ReadInt32();

                            idents.Add(new MondDebugInfo.Identifier(name, isReadOnly, frameIndex, idx));
                        }

                        scopes.Add(new MondDebugInfo.Scope(id, depth, parentId, startAddress, endAddress, idents));
                    }
                }

                debugInfo = new MondDebugInfo(fileName, sourceCode, functions, lines, statements, scopes);
            }

            return(new MondProgram(bytecode, numbers, strings, debugInfo));
        }