Beispiel #1
0
        public EnumDef(BinaryReader stream, string name)
        {
            Name = name;
            while (true)
            {
                var typedValue = new TypedValue(stream);
                if (typedValue.Type == (0x80 | TypedValue.Definition))
                {
                    var taggedSymbol = stream.ReadTaggedSymbol(false);
                    var memberName   = stream.ReadPascalString();

                    if (taggedSymbol.Type == SymbolType.EndOfStruct)
                    {
                        break;
                    }

                    if (taggedSymbol.Type != SymbolType.EnumMember)
                    {
                        throw new Exception($"Unexpected {nameof(SymbolType)}");
                    }

                    _members.Add(memberName, typedValue.Value);
                }
                else if (typedValue.Type == (0x80 | TypedValue.ArrayDefinition))
                {
                    var taggedSymbol = stream.ReadTaggedSymbol(true);
                    if (taggedSymbol.DerivedTypeDef.Type != PrimitiveType.Null)
                    {
                        throw new Exception(
                                  $"Expected baseType={PrimitiveType.Null}, but it's {taggedSymbol.DerivedTypeDef.Type}");
                    }

                    if (taggedSymbol.Extents.Length != 0)
                    {
                        throw new Exception($"Expected dims=0, but it's {taggedSymbol.Extents.Length}");
                    }

                    if (taggedSymbol.Tag != name)
                    {
                        throw new Exception($"Expected name={name}, but it's {taggedSymbol.Tag}");
                    }

                    var tag = stream.ReadPascalString();
                    if (tag != ".eos")
                    {
                        throw new Exception($"Expected tag=.eos, but it's {tag}");
                    }

                    if (taggedSymbol.Type != SymbolType.EndOfStruct)
                    {
                        throw new Exception(
                                  $"Expected {nameof(SymbolType)}={SymbolType.EndOfStruct}, but it's {taggedSymbol.Type}");
                    }

                    _size = taggedSymbol.Size;
                    break;
                }
                else
                {
                    throw new Exception("Unexpected entry");
                }
            }
        }
Beispiel #2
0
        private bool ReadEntry(BinaryReader stream)
        {
            var basePos    = stream.BaseStream.Position;
            var typedValue = new TypedValue(stream);

            if (typedValue.Type == 8)
            {
                throw new Exception("Unexpected MX-Info");
            }

            if (typedValue.IsLabel)
            {
                var lbl = new Label(typedValue, stream);

                if (!Labels.ContainsKey(lbl.Offset))
                {
                    Labels.Add(lbl.Offset, new List <Label>());
                }

                Labels[lbl.Offset].Add(lbl);
                return(true);
            }

            switch (typedValue.Type & 0x7f)
            {
            case TypedValue.BeginSLD:
                stream.BaseStream.Position = basePos;
                SkipSLD(stream);
                return(true);

            case TypedValue.SetOverlay:
                stream.BaseStream.Position = basePos;
                return(false);

            case TypedValue.EndSLDInfo:
                return(false);

            case TypedValue.IncSLD:
            case TypedValue.AddSLD1:
            case TypedValue.AddSLD2:
            case TypedValue.SetSLD:
                throw new Exception($"Unexpected SLD entry 0x{typedValue.Type & 0x7f:X}");

            case TypedValue.Function:
                ReadFunction(stream, typedValue.Value);
                break;

            case TypedValue.Definition:
                if (!ReadTopLevelDef(stream, typedValue.Value))
                {
                    return(false);
                }

                break;

            case TypedValue.ArrayDefinition:
                ReadTopLevelArrayDef(stream, typedValue.Value);
                break;

            case TypedValue.Overlay:
                throw new Exception("Unexpected overlay definition");

            default:
                throw new Exception($"Unhandled debug type 0x{typedValue.Type:X}");
            }

            return(true);
        }
Beispiel #3
0
        private void dumpEntry(BinaryReader stream)
        {
            var typedValue = new TypedValue(stream);

            if (typedValue.type == 8)
            {
                m_mxInfo = $"${typedValue.value:X} MX-info {stream.ReadByte():X}";
                return;
            }

            if (typedValue.isLabel)
            {
                var lbl = new Label(typedValue, stream);

                if (!labels.ContainsKey(lbl.offset))
                {
                    labels.Add(lbl.offset, new List <Label>());
                }

                labels[lbl.offset].Add(lbl);
                return;
            }

            switch (typedValue.type & 0x7f)
            {
            case 0:
#if WITH_SLD
                writer.WriteLine($"${typedValue.value:X} Inc SLD linenum");
                #endif
                break;

            case 2:
#if WITH_SLD
                writer.WriteLine($"${typedValue.value:X} Inc SLD linenum by byte {stream.ReadU1()}");
                #else
                stream.skip(1);
#endif
                break;

            case 4:
#if WITH_SLD
                writer.WriteLine($"${typedValue.value:X} Inc SLD linenum by word {stream.ReadUInt16()}");
#else
                stream.skip(2);
#endif
                break;

            case 6:
#if WITH_SLD
                writer.WriteLine($"${typedValue.value:X} Set SLD linenum to {stream.ReadUInt32()}");
#else
                stream.skip(4);
#endif
                break;

            case 8:
#if WITH_SLD
                writer.WriteLine($"${typedValue.value:X} Set SLD to line {stream.ReadUInt32()} of file " +
                                 stream.readPascalString());
#else
                stream.skip(4);
                stream.skip(stream.ReadByte());
#endif
                break;

            case 10:
#if WITH_SLD
                writer.WriteLine($"${typedValue.value:X} End SLD info");
#endif
                break;

            case 12:
                dumpType12(stream, typedValue.value);
                break;

            case 20:
                dumpType20(stream, typedValue.value);
                break;

            case 22:
                dumpType22(stream, typedValue.value);
                break;

            default:
                throw new Exception("Sodom");
            }
        }