Exemplo n.º 1
0
        private GXDebugItem[] ReadItems(GXDebugStream stream, out Guid sessionGuid, out GXDebugGenId genId, IList <GXDebugError> errors)
        {
            sessionGuid = Guid.Empty;
            genId       = GXDebugGenId.INVALID;
            stream.InitializeNewBlock();
            if (!FindEscape(stream, GXDebugStream.ESCAPE.PROLOG, errors))
            {
                return(null);
            }
            short versionAndGenId = stream.ReadVLUShort();

            genId = (GXDebugGenId)(versionAndGenId & 0xF);
            short version = (short)(versionAndGenId >> 4);

            if (version != GXDebugManager.GXDEBUG_VERSION)
            {
                errors.Add(new GXDebugError(stream.Position, $"Cannot parse version { version } blocks"));
                FindEscape(stream, GXDebugStream.ESCAPE.EPILOG, errors);
                return(new GXDebugItem[0]);
            }
            int itemCount = stream.ReadVLUInt();

            if (itemCount == 0)
            {
                errors.Add(new GXDebugError(stream.Position, $"Invalid block. Item count = 0"));
                FindEscape(stream, GXDebugStream.ESCAPE.EPILOG, errors);
                return(new GXDebugItem[0]);
            }
            byte[] guid = new byte[16];
            sessionGuid = new Guid(stream.ReadFully(guid));
            GXDebugItem[] items = new GXDebugItem[itemCount];
            for (int idx = 0; idx < itemCount; idx++)
            {
                items[idx] = ReadItem(stream, errors);
                if (items[idx].MsgType == GXDebugMsgType.INVALID)
                {
                    while (++idx < itemCount)
                    {
                        items[idx] = NewInvalidItem();
                    }
                    break;
                }
            }
            FindEscape(stream, GXDebugStream.ESCAPE.EPILOG, errors);
            return(items);
        }
Exemplo n.º 2
0
        private GXDebugItem ReadItem(GXDebugStream stream, IList <GXDebugError> errors)
        {
            int value;

            if ((value = stream.ReadByte()) == -1)
            {
                throw new EndOfStreamException();
            }
            GXDebugItem dbgItem = new GXDebugItem();

            if ((value & GXDebugMsgType.SYSTEM.ToByte()) == GXDebugMsgType.SYSTEM.ToByte())
            {
                switch (value & 0xFC)
                {
                case 0xC0:
                {
                    dbgItem.MsgType     = GXDebugMsgType.REGISTER_PGM;
                    dbgItem.DbgInfo     = new GXDebugInfoLocal();
                    dbgItem.DbgInfo.SId = stream.ReadVLUInt();
                    dbgItem.Arg1        = stream.ReadVLUInt();
                    dbgItem.ArgObj      = new KeyValuePair <int, int>(stream.ReadVLUInt(), stream.ReadVLUInt());
                }
                break;

                case 0xA0:
                {
                    dbgItem.MsgType     = GXDebugMsgType.PGM_TRACE_RANGE;
                    dbgItem.DbgInfo     = new GXDebugInfoLocal();
                    dbgItem.DbgInfo.SId = stream.ReadVLUInt();
                    dbgItem.Arg1        = stream.ReadVLUInt();
                    dbgItem.Arg2        = stream.ReadVLUInt();
                    if ((value & GXDebugMsgType.PGM_TRACE_RANGE_WITH_COLS.ToByte()) == GXDebugMsgType.PGM_TRACE_RANGE_WITH_COLS.ToByte())
                    {
                        dbgItem.ArgObj = new KeyValuePair <int, int>(stream.ReadVLUInt(), stream.ReadVLUInt());
                    }
                    else
                    {
                        dbgItem.ArgObj = new KeyValuePair <int, int>(0, 0);
                    }
                }
                break;

                case 0x80:
                {
                    dbgItem.MsgType = GXDebugMsgType.SYSTEM;
                    dbgItem.Arg1    = value & GXDebugMsgCode.MASK_BITS.ToByte();
                    switch ((GXDebugMsgCode)(dbgItem.Arg1))
                    {
                    case GXDebugMsgCode.INITIALIZE:
                        dbgItem.ArgObj = new DateTime(stream.ReadLong(), DateTimeKind.Utc);
                        break;

                    case GXDebugMsgCode.OBJ_CLEANUP:
                        dbgItem.ArgObj = stream.ReadVLUInt();
                        break;

                    case GXDebugMsgCode.PGM_INFO:
                    {
                        KeyValuePair <int, int>  pgmKey  = new KeyValuePair <int, int>(stream.ReadVLUInt(), stream.ReadVLUInt());
                        KeyValuePair <int, long> pgmInfo = new KeyValuePair <int, long>(stream.ReadVLUInt(), stream.ReadIntAsLong());
                        dbgItem.ArgObj = new KeyValuePair <object, object>(pgmKey, pgmInfo);
                    }
                    break;

                    case GXDebugMsgCode.EXIT:
                        break;

                    default:
                        dbgItem.MsgType = GXDebugMsgType.INVALID;
                        errors.Add(new GXDebugError(stream.Position, $"Invalid Debug Item (type={ dbgItem.MsgType } - { value })"));
                        break;
                    }
                }
                break;

                default:
                    dbgItem.MsgType = GXDebugMsgType.INVALID;
                    errors.Add(new GXDebugError(stream.Position, $"Invalid Debug Item (type={ value })"));
                    break;
                }
            }
            else
            {
                stream.ReadPgmTrace(dbgItem, (byte)value);
            }

            return(dbgItem);
        }