internal override StackFrame GetLMF(ThreadServant thread, TargetMemoryAccess memory,
                                            ref TargetAddress lmf_address)
        {
            TargetAddress lmf = lmf_address;

            TargetBinaryReader reader = memory.ReadMemory(lmf, 36).GetReader();

            lmf_address = reader.ReadTargetAddress();              // prev

            reader.Position = 16;

            TargetAddress ebx = reader.ReadTargetAddress();
            TargetAddress edi = reader.ReadTargetAddress();
            TargetAddress esi = reader.ReadTargetAddress();
            TargetAddress ebp = reader.ReadTargetAddress();
            TargetAddress eip = reader.ReadTargetAddress();

            Registers regs = new Registers(this);

            regs [(int)X86_Register.RBX].SetValue(lmf + 16, ebx);
            regs [(int)X86_Register.RDI].SetValue(lmf + 20, edi);
            regs [(int)X86_Register.RSI].SetValue(lmf + 24, esi);
            regs [(int)X86_Register.RBP].SetValue(lmf + 28, ebp);
            regs [(int)X86_Register.RIP].SetValue(lmf + 32, eip);

            TargetAddress new_ebp = memory.ReadAddress(ebp);

            regs [(int)X86_Register.RBP].SetValue(ebp, new_ebp);

            TargetAddress new_esp = ebp + 8;

            regs [(int)X86_Register.RSP].SetValue(ebp, new_esp);

            return(CreateFrame(thread.Client, FrameType.LMF, memory, eip, new_esp, new_ebp, regs));
        }
        internal void MonoArrayTypeGetBounds(TargetMemoryAccess memory,
                                             TargetAddress data)
        {
            //
            // FIXME: Only check whether the low bounds are all zero
            //
            int num_sizes = memory.ReadByte(data + memory.TargetAddressSize + 1);

            if (num_sizes != 0)
            {
                throw new InternalError();
            }

            int num_lobounds = memory.ReadByte(data + memory.TargetAddressSize + 2);

            if (num_lobounds == 0)
            {
                return;
            }

            TargetAddress      array  = memory.ReadAddress(data + 3 * memory.TargetAddressSize);
            TargetBinaryReader bounds = memory.ReadMemory(array, num_lobounds * 4).GetReader();

            for (int i = 0; i < num_lobounds; i++)
            {
                int bound = bounds.ReadInt32();
                if (bound != 0)
                {
                    throw new InternalError();
                }
            }
        }
Beispiel #3
0
        protected override object DoGetObject(TargetMemoryAccess target)
        {
            TargetLocation dynamic_location;
            TargetBlob     object_blob = Location.ReadMemory(target, type.Size);
            long           size        = GetDynamicSize(
                target, object_blob, Location, out dynamic_location);

            if (size > (long)MonoStringType.MaximumStringLength)
            {
                size = MonoStringType.MaximumStringLength;
            }

            TargetBlob blob = dynamic_location.ReadMemory(target, (int)size);

            TargetBinaryReader reader = blob.GetReader();
            int length = (int)reader.Size / 2;

            char[] retval = new char [length];

            for (int i = 0; i < length; i++)
            {
                retval [i] = (char)reader.ReadInt16();
            }

            return(new String(retval));
        }
        protected override void DoGetArrayBounds(TargetMemoryAccess target)
        {
            TargetBinaryReader reader = Location.ReadMemory(target, type.Size).GetReader();

            reader.Position = 3 * reader.TargetMemoryInfo.TargetAddressSize;
            int length = reader.ReadInt32();

            if (Rank == 1)
            {
                bounds = TargetArrayBounds.MakeSimpleArray(length);
                return;
            }

            reader.Position = 2 * reader.TargetMemoryInfo.TargetAddressSize;
            TargetAddress bounds_address = new TargetAddress(
                target.AddressDomain, reader.ReadAddress());
            TargetBinaryReader breader = target.ReadMemory(
                bounds_address, 8 * Rank).GetReader();

            int[] lower = new int [Rank];
            int[] upper = new int [Rank];

            for (int i = 0; i < Rank; i++)
            {
                int b_length = breader.ReadInt32();
                int b_lower  = breader.ReadInt32();

                lower [i] = b_lower;
                upper [i] = b_lower + b_length - 1;
            }

            bounds = TargetArrayBounds.MakeMultiArray(lower, upper);
        }
Beispiel #5
0
 internal TargetReader(byte[] data, TargetMemoryInfo info)
 {
     if ((info == null) || (data == null))
         throw new ArgumentNullException ();
     this.reader = new TargetBinaryReader (data, info);
     this.info = info;
     this.data = data;
 }
Beispiel #6
0
 internal TargetReader(byte[] data, TargetMemoryInfo info)
 {
     if ((info == null) || (data == null))
     {
         throw new ArgumentNullException();
     }
     this.reader = new TargetBinaryReader(data, info);
     this.info   = info;
     this.data   = data;
 }
Beispiel #7
0
        internal override long GetDynamicSize(TargetMemoryAccess target, TargetBlob blob,
                                              TargetLocation location,
                                              out TargetLocation dynamic_location)
        {
            TargetBinaryReader reader = blob.GetReader();

            reader.Position  = Type.ObjectSize;
            dynamic_location = location.GetLocationAtOffset(Type.ObjectSize + 4);
            return(reader.ReadInteger(4) * 2);
        }
        internal override StackFrame GetLMF(ThreadServant thread, TargetMemoryAccess memory, ref TargetAddress lmf_address)
        {
            TargetAddress      lmf    = lmf_address;
            TargetBinaryReader reader = memory.ReadMemory(lmf_address, 88).GetReader();

            lmf_address = reader.ReadTargetAddress(); // prev
            reader.ReadTargetAddress();
            reader.ReadTargetAddress();               // method
            TargetAddress rip = reader.ReadTargetAddress();

            if (lmf_address.IsNull)
            {
                return(null);
            }

            TargetAddress rbx = reader.ReadTargetAddress();
            TargetAddress rbp = reader.ReadTargetAddress();
            TargetAddress rsp = reader.ReadTargetAddress();
            TargetAddress r12 = reader.ReadTargetAddress();
            TargetAddress r13 = reader.ReadTargetAddress();
            TargetAddress r14 = reader.ReadTargetAddress();
            TargetAddress r15 = reader.ReadTargetAddress();

            Registers regs = new Registers(this);

            if ((lmf_address.Address & 1) == 0)
            {
                rip = memory.ReadAddress(rsp - 8);
                regs [(int)X86_Register.RIP].SetValue(rsp - 8, rip);
                regs [(int)X86_Register.RBP].SetValue(lmf + 40, rbp);
            }
            else
            {
                TargetAddress new_rbp = memory.ReadAddress(rbp);
                regs [(int)X86_Register.RIP].SetValue(lmf + 24, rip);
                regs [(int)X86_Register.RBP].SetValue(rbp, new_rbp);
                rbp = new_rbp;
                lmf_address--;
            }

            regs [(int)X86_Register.RBX].SetValue(lmf + 32, rbx);
            regs [(int)X86_Register.RSP].SetValue(lmf + 48, rsp);
            regs [(int)X86_Register.R12].SetValue(lmf + 56, r12);
            regs [(int)X86_Register.R13].SetValue(lmf + 64, r13);
            regs [(int)X86_Register.R14].SetValue(lmf + 72, r14);
            regs [(int)X86_Register.R15].SetValue(lmf + 80, r15);

            return(CreateFrame(thread.Client, FrameType.LMF, memory, rip, rsp, rbp, regs));
        }
Beispiel #9
0
        protected override bool GetMonoTrampoline(TargetMemoryAccess memory,
                                                  TargetAddress call_target,
                                                  out TargetAddress trampoline)
        {
            TargetBinaryReader reader = memory.ReadMemory(call_target, 10).GetReader();
            byte opcode = reader.ReadByte();

            if (opcode == 0x6a)
            {
                reader.Position++;
            }
            else if (opcode == 0x68)
            {
                reader.Position += 4;
            }
            else
            {
                trampoline = TargetAddress.Null;
                return(false);
            }

            opcode = reader.ReadByte();
            if (opcode != 0xe9)
            {
                trampoline = TargetAddress.Null;
                return(false);
            }

            TargetAddress call = call_target + reader.ReadInt32() + reader.Position;

            if (!Opcodes.Process.MonoLanguage.IsTrampolineAddress(call))
            {
                trampoline = TargetAddress.Null;
                return(false);
            }

            trampoline = call_target;
            return(true);
        }
Beispiel #10
0
        public static MonoDebuggerInfo Create(TargetMemoryAccess memory, TargetAddress info)
        {
            TargetBinaryReader header = memory.ReadMemory(info, 24).GetReader();
            long magic = header.ReadInt64();

            if (magic != DynamicMagic)
            {
                Report.Error("`MONO_DEBUGGER__debugger_info' at {0} has unknown magic {1:x}.", info, magic);
                return(null);
            }

            int version = header.ReadInt32();

            if (version < MinDynamicVersion)
            {
                Report.Error("`MONO_DEBUGGER__debugger_info' has version {0}, " +
                             "but expected at least {1}.", version,
                             MonoDebuggerInfo.MinDynamicVersion);
                return(null);
            }
            if (version > MaxDynamicVersion)
            {
                Report.Error("`MONO_DEBUGGER__debugger_info' has version {0}, " +
                             "but expected at most {1}.", version,
                             MonoDebuggerInfo.MaxDynamicVersion);
                return(null);
            }

            header.ReadInt32();              // minor version
            header.ReadInt32();

            int size = header.ReadInt32();

            TargetReader reader = new TargetReader(memory.ReadMemory(info, size));

            return(new MonoDebuggerInfo(memory, reader));
        }
            public MetadataInfo(TargetMemoryAccess memory, TargetAddress address)
            {
                int size = memory.ReadInteger(address);
                TargetBinaryReader reader = memory.ReadMemory(address, size).GetReader();

                reader.ReadInt32();

                MonoDefaultsSize    = reader.ReadInt32();
                MonoDefaultsAddress = new TargetAddress(
                    memory.AddressDomain, reader.ReadAddress());

                TypeSize      = reader.ReadInt32();
                ArrayTypeSize = reader.ReadInt32();
                KlassSize     = reader.ReadInt32();
                ThreadSize    = reader.ReadInt32();

                ThreadTidOffset      = reader.ReadInt32();
                ThreadStackPtrOffset = reader.ReadInt32();
                ThreadEndStackOffset = reader.ReadInt32();

                KlassImageOffset            = reader.ReadInt32();
                KlassInstanceSizeOffset     = reader.ReadInt32();
                KlassParentOffset           = reader.ReadInt32();
                KlassTokenOffset            = reader.ReadInt32();
                KlassFieldOffset            = reader.ReadInt32();
                KlassMethodsOffset          = reader.ReadInt32();
                KlassMethodCountOffset      = reader.ReadInt32();
                KlassThisArgOffset          = reader.ReadInt32();
                KlassByValArgOffset         = reader.ReadInt32();
                KlassGenericClassOffset     = reader.ReadInt32();
                KlassGenericContainerOffset = reader.ReadInt32();
                KlassVTableOffset           = reader.ReadInt32();

                FieldInfoSize         = reader.ReadInt32();
                FieldInfoTypeOffset   = reader.ReadInt32();
                FieldInfoOffsetOffset = reader.ReadInt32();

                KlassFieldCountOffset = KlassMethodCountOffset - 8;

                MonoDefaultsCorlibOffset    = reader.ReadInt32();
                MonoDefaultsObjectOffset    = reader.ReadInt32();
                MonoDefaultsByteOffset      = reader.ReadInt32();
                MonoDefaultsVoidOffset      = reader.ReadInt32();
                MonoDefaultsBooleanOffset   = reader.ReadInt32();
                MonoDefaultsSByteOffset     = reader.ReadInt32();
                MonoDefaultsInt16Offset     = reader.ReadInt32();
                MonoDefaultsUInt16Offset    = reader.ReadInt32();
                MonoDefaultsInt32Offset     = reader.ReadInt32();
                MonoDefaultsUInt32Offset    = reader.ReadInt32();
                MonoDefaultsIntOffset       = reader.ReadInt32();
                MonoDefaultsUIntOffset      = reader.ReadInt32();
                MonoDefaultsInt64Offset     = reader.ReadInt32();
                MonoDefaultsUInt64Offset    = reader.ReadInt32();
                MonoDefaultsSingleOffset    = reader.ReadInt32();
                MonoDefaultsDoubleOffset    = reader.ReadInt32();
                MonoDefaultsCharOffset      = reader.ReadInt32();
                MonoDefaultsStringOffset    = reader.ReadInt32();
                MonoDefaultsEnumOffset      = reader.ReadInt32();
                MonoDefaultsArrayOffset     = reader.ReadInt32();
                MonoDefaultsDelegateOffset  = reader.ReadInt32();
                MonoDefaultsExceptionOffset = reader.ReadInt32();

                MonoMethodKlassOffset    = reader.ReadInt32();
                MonoMethodTokenOffset    = reader.ReadInt32();
                MonoMethodFlagsOffset    = reader.ReadInt32();
                MonoMethodInflatedOffset = reader.ReadInt32();

                MonoVTableKlassOffset  = reader.ReadInt32();
                MonoVTableVTableOffset = reader.ReadInt32();
            }
Beispiel #12
0
 public override string Print()
 {
     return(TargetBinaryReader.HexDump(blob.Contents));
 }
Beispiel #13
0
 public override string ToString()
 {
     return(String.Format("MemoryReader ([{0}])", TargetBinaryReader.HexDump(data)));
 }
Beispiel #14
0
            TargetLocation GetLocation(StackFrame frame, TargetMemoryAccess memory,
						    byte[] data)
            {
                TargetBinaryReader locreader = new TargetBinaryReader (
                    data, comp_unit.DwarfReader.TargetMemoryInfo);

                byte opcode = locreader.ReadByte ();
                bool is_regoffset;
                int reg, off;

                if ((opcode >= 0x50) && (opcode <= 0x6f)) { // DW_OP_reg
                    reg = opcode - 0x50 + 3;
                    off = 0;
                    is_regoffset = false;
                } else if ((opcode >= 0x70) && (opcode <= 0x8f)) { // DW_OP_breg
                    reg = opcode - 0x70 + 3;
                    off = locreader.ReadSLeb128 ();
                    is_regoffset = true;
                } else if (opcode == 0x90) { // DW_OP_regx
                    reg = locreader.ReadLeb128 () + 3;
                    off = 0;
                    is_regoffset = false;
                } else if (opcode == 0x91) { // DW_OP_fbreg
                    off = locreader.ReadSLeb128 ();

                    if (frame_base != null) {
                        TargetLocation rloc = new RelativeTargetLocation (
                            frame_base.GetLocation (frame, memory), off);
                        if (is_byref)
                            return new DereferencedTargetLocation (rloc);
                        else
                            return rloc;
                    } else {
                        is_regoffset = true;
                        reg = 2;
                    }
                } else if (opcode == 0x92) { // DW_OP_bregx
                    reg = locreader.ReadLeb128 () + 3;
                    off = locreader.ReadSLeb128 ();
                    is_regoffset = true;
                } else if (opcode == 0x03) { // DW_OP_addr
                    TargetAddress addr = new TargetAddress (
                        memory.AddressDomain, locreader.ReadAddress ());
                    TargetLocation aloc = new AbsoluteTargetLocation (addr);
                    if (is_byref)
                        return new DereferencedTargetLocation (aloc);
                    else
                        return aloc;
                } else {
                    Console.WriteLine ("UNKNOWN OPCODE: {0:x}", opcode);
                    return null;
                }

                reg = comp_unit.DwarfReader.bfd.Architecture.DwarfFrameRegisterMap [reg];

                MonoVariableLocation loc = MonoVariableLocation.Create (
                    memory, is_regoffset, frame.Registers [reg],
                    off, is_byref);

                if (!locreader.IsEof) {
                    Console.WriteLine ("LOCREADER NOT AT EOF!");
                    return null;
                }

                return loc;
            }
Beispiel #15
0
            public TargetLocation GetLocation(TargetLocation location)
            {
                if (location_block == null)
                    throw new NotImplementedException ();

                TargetBinaryReader locreader = new TargetBinaryReader (
                    location_block, comp_unit.DwarfReader.TargetMemoryInfo);

                byte opcode = locreader.ReadByte ();

                if (opcode == 0x23) // DW_OP_plus_uconst
                    location = new RelativeTargetLocation (location, locreader.ReadLeb128 ());
                else {
                    Console.WriteLine ("UNKNOWN OPCODE: {0:x}", opcode);
                    return null;
                }

                if (!locreader.IsEof) {
                    Console.WriteLine ("LOCREADER NOT AT EOF!");
                    return null;
                }

                return location;
            }
Beispiel #16
0
            bool read_location()
            {
                TargetBinaryReader locreader = new TargetBinaryReader (
                    location, target_info);

                switch (locreader.ReadByte ()) {
                case 0x23: // DW_OP_plus_uconstant
                    offset = locreader.ReadLeb128 ();
                    return locreader.IsEof;

                default:
                    return false;
                }
            }