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);
        }
Example #2
0
 internal override string Print(TargetMemoryAccess target)
 {
     if (Location.GetAddress (target).IsNull)
         return "null";
     object obj = DoGetObject (target);
     return '"' + (string) obj + '"';
 }
        internal override TargetObject GetElement(TargetMemoryAccess target, int[] indices)
        {
            int offset = GetArrayOffset(target, indices);

            TargetBlob     blob;
            TargetLocation dynamic_location;

            try {
                blob = Location.ReadMemory(target, Type.Size);
                GetDynamicSize(target, blob, Location, out dynamic_location);
            } catch (TargetException ex) {
                throw new LocationInvalidException(ex);
            }

            TargetLocation new_loc = dynamic_location.GetLocationAtOffset(offset);

            if (Type.ElementType.IsByRef)
            {
                new_loc = new_loc.GetDereferencedLocation();
            }

            if (new_loc.HasAddress && new_loc.GetAddress(target).IsNull)
            {
                return(new TargetNullObject(Type.ElementType));
            }

            return(Type.ElementType.GetObject(target, new_loc));
        }
Example #4
0
        protected CoreFile(ThreadManager manager, ProcessStart start)
            : base(manager, start)
        {
            info = Inferior.GetTargetMemoryInfo(manager.AddressDomain);

            bfd = (Bfd)NativeLanguage.OperatingSystem.LoadExecutable(
                info, start.TargetApplication, true);

            core_file = start.CoreFile;

            core_bfd = bfd.OpenCoreFile(core_file);

#if FIXME
            string   crash_program      = core_bfd.CrashProgram;
            string[] crash_program_args = crash_program.Split(' ');

            if (crash_program_args [0] != application)
            {
                throw new TargetException(
                          TargetError.CannotStartTarget,
                          "Core file (generated from {0}) doesn't match executable {1}.",
                          crash_program, application);
            }

            bool ok;
            try {
                DateTime core_date = Directory.GetLastWriteTime(core_file);
                DateTime app_date  = Directory.GetLastWriteTime(application);

                ok = app_date < core_date;
            } catch {
                ok = false;
            }

            if (!ok)
            {
                throw new TargetException(
                          TargetError.CannotStartTarget,
                          "Executable {0} is more recent than core file {1}.",
                          application, core_file);
            }
#endif

            read_note_section();
            main_thread = (CoreFileThread)threads [0];

            TargetMemoryAccess target_access = ((CoreFileThread)threads [0]).TargetAccess;
            // bfd.UpdateSharedLibraryInfo (null, target_access);

            TargetAddress mdb_debug_info = bfd.GetSectionAddress(".mdb_debug_info");
            if (!mdb_debug_info.IsNull)
            {
                mdb_debug_info = main_thread.ReadAddress(mdb_debug_info);
                debugger_info  = MonoDebuggerInfo.Create(target_access, mdb_debug_info);
                read_thread_table();
                CreateMonoLanguage(debugger_info);
                mono_language.InitializeCoreFile(target_access);
                mono_language.Update(target_access);
            }
        }
Example #5
0
        internal override TargetAddress GetAddress(TargetMemoryAccess target)
        {
            if (!is_valid)
                throw new LocationInvalidException ();

            return address;
        }
Example #6
0
        internal MonoFieldInfo[] GetFields(TargetMemoryAccess target)
        {
            if (fields != null)
            {
                return(fields);
            }

            int field_count = MetadataHelper.MonoClassGetFieldCount(target, KlassAddress);

            if ((field_count != 0) && !MetadataHelper.MonoClassHasFields(target, KlassAddress))
            {
                throw new TargetException(TargetError.ClassNotInitialized);
            }

            fields        = new MonoFieldInfo [field_count];
            field_offsets = new int [field_count];
            field_types   = new TargetType [field_count];

            for (int i = 0; i < field_count; i++)
            {
                Cecil.FieldDefinition field = CecilType.Fields [i];

                TargetAddress type_addr = MetadataHelper.MonoClassGetFieldType(
                    target, KlassAddress, i);

                field_types [i]   = SymbolFile.MonoLanguage.ReadType(target, type_addr);
                field_offsets [i] = MetadataHelper.MonoClassGetFieldOffset(
                    target, KlassAddress, i);

                fields [i] = new MonoFieldInfo(struct_type, field_types [i], i, field);
            }

            return(fields);
        }
        internal override void WriteBuffer(TargetMemoryAccess target, byte[] data)
        {
            if (data.Length > blob.Size)
                throw new ArgumentException ();

            data.CopyTo (blob.Contents, 0);
        }
Example #8
0
        //
        // MonoType
        //

        public MonoTypeEnum MonoTypeGetType(TargetMemoryAccess memory, TargetAddress type)
        {
            uint flags = (uint)memory.ReadInteger(
                type + memory.TargetMemoryInfo.TargetAddressSize);

            return((MonoTypeEnum)((flags & 0x00ff0000) >> 16));
        }
Example #9
0
 internal override string Print(TargetMemoryAccess target)
 {
     if (HasAddress)
         return String.Format ("{0} ({1})", Type.Name, GetAddress (target));
     else
         return String.Format ("{0} ({1})", Type.Name, Location);
 }
Example #10
0
        internal override TargetType GetCurrentType(TargetMemoryAccess target)
        {
            if (!Type.HasStaticType)
                throw new InvalidOperationException ();

            return Type.StaticType;
        }
Example #11
0
        public MonoMethodSignature GetMethodSignature(MonoLanguageBackend mono,
                                                      TargetMemoryAccess memory,
                                                      TargetAddress signature)
        {
            int count = memory.ReadInteger(signature + 4) & 0x0000ffff;

            int           offset = memory.TargetAddressSize == 8 ? 16 : 12;
            TargetAddress ret    = memory.ReadAddress(signature + offset);

            TargetType ret_type = mono.ReadType(memory, ret);

            if (count == 0)
            {
                return(new MonoMethodSignature(ret_type, new TargetType [0]));
            }

            offset += memory.TargetAddressSize;
            TargetReader reader = new TargetReader(
                memory.ReadMemory(signature + offset, count * memory.TargetAddressSize));

            TargetType[] param_types = new TargetType [count];
            for (int i = 0; i < count; i++)
            {
                param_types [i] = mono.ReadType(memory, reader.ReadAddress());
            }

            return(new MonoMethodSignature(ret_type, param_types));
        }
Example #12
0
        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();
                }
            }
        }
        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));
        }
Example #14
0
        public GenericParamInfo GetGenericParameter(TargetMemoryAccess memory,
                                                    TargetAddress address)
        {
            int addr_size = memory.TargetMemoryInfo.TargetAddressSize;

            TargetReader reader = new TargetReader(
                memory.ReadMemory(address, 4 * addr_size + 4));
            TargetAddress container = reader.ReadAddress();
            TargetAddress klass     = reader.ReadAddress();
            TargetAddress name_addr = reader.ReadAddress();

            reader.BinaryReader.ReadInt16();              /* flags */
            int pos = reader.BinaryReader.ReadInt16();

            string name;

            if (!name_addr.IsNull)
            {
                name = memory.ReadString(name_addr);
            }
            else
            {
                name = String.Format("!{0}", pos);
            }

            return(new GenericParamInfo(container, klass, name, pos));
        }
Example #15
0
 internal override string Print(TargetMemoryAccess target)
 {
     if (Location.HasAddress)
         return String.Format ("{0}", Location.GetAddress (target));
     else
         return String.Format ("{0}", Location);
 }
Example #16
0
        internal TargetObject GetInstanceField(TargetMemoryAccess target,
                                               TargetStructObject instance,
                                               TargetFieldInfo field)
        {
            GetFields(target);

            int        offset = field_offsets [field.Position];
            TargetType type   = field_types [field.Position];

            if (!Type.IsByRef)
            {
                offset -= 2 * target.TargetMemoryInfo.TargetAddressSize;
            }
            TargetLocation field_loc = instance.Location.GetLocationAtOffset(offset);

            TargetAddress orig_addr = field_loc.GetAddress(target);

            if (type.IsByRef)
            {
                field_loc = field_loc.GetDereferencedLocation();
            }

            TargetAddress addr = field_loc.GetAddress(target);

            if (field_loc.HasAddress && field_loc.GetAddress(target).IsNull)
            {
                return(new TargetNullObject(type));
            }

            return(type.GetObject(target, field_loc));
        }
Example #17
0
        internal override TargetBlob ReadMemory(TargetMemoryAccess target, int size)
        {
            if (!is_valid)
                throw new LocationInvalidException ();

            if (HasAddress)
                return base.ReadMemory (target, size);

            // If this is a valuetype, the register hold the whole data.
            long contents = address.Address;

            byte[] buffer;
            if (size == 1)
                buffer = BitConverter.GetBytes ((byte) contents);
            else if (size == 2)
                buffer = BitConverter.GetBytes ((short) contents);
            else if (size == 4)
                buffer = BitConverter.GetBytes ((int) contents);
            else if (size == 8)
                buffer = BitConverter.GetBytes (contents);
            else
                throw new ArgumentException ();

            return new TargetBlob (buffer, target.TargetMemoryInfo);
        }
Example #18
0
        internal override void SetObject(TargetMemoryAccess target, TargetLocation location,
                                         TargetObject obj)
        {
            TargetLocation flag_loc = location.GetLocationAtOffset(ElementType.Size);

            byte[] buffer = new byte [1];

            if (obj is TargetNullObject)
            {
                buffer [0] = 0;
                flag_loc.WriteBuffer(target, buffer);
                return;
            }

            MonoNullableObject nobj = obj as MonoNullableObject;

            if (nobj != null)
            {
                if (!nobj.HasValue(target))
                {
                    buffer [0] = 0;
                    flag_loc.WriteBuffer(target, buffer);
                    return;
                }
                else
                {
                    obj = nobj.GetValue(target);
                }
            }

            buffer [0] = 1;
            flag_loc.WriteBuffer(target, buffer);

            ElementType.SetObject(target, location, obj);
        }
Example #19
0
        public bool MonoTypeGetIsByRef(TargetMemoryAccess memory, TargetAddress type)
        {
            uint flags = (uint)memory.ReadInteger(
                type + memory.TargetMemoryInfo.TargetAddressSize);

            return((int)((flags & 0x40000000) >> 30) != 0);
        }
        StackFrame do_hacks(StackFrame frame, TargetMemoryAccess memory)
        {
            StackFrame new_frame;

            try {
                new_frame = try_pthread_cond_timedwait(frame, memory);
                if (new_frame != null)
                {
                    return(new_frame);
                }
            } catch {
                new_frame = null;
            }

            try {
                new_frame = try_syscall_trampoline(frame, memory);
                if (new_frame != null)
                {
                    return(new_frame);
                }
            } catch {
                new_frame = null;
            }

            return(null);
        }
Example #21
0
        public bool MonoClassHasMethods(TargetMemoryAccess memory, TargetAddress klass)
        {
            TargetAddress methods = memory.ReadAddress(
                klass + MonoMetadataInfo.KlassMethodsOffset);

            return(!methods.IsNull);
        }
        internal override StackFrame UnwindStack(StackFrame frame, TargetMemoryAccess memory,
                                                 byte[] code, int offset)
        {
            if ((code != null) && (code.Length > 4))
            {
                return(read_prologue(frame, memory, code, offset));
            }

            TargetAddress rbp = frame.FrameAddress;

            int addr_size = TargetAddressSize;

            Registers regs = CopyRegisters(frame.Registers);

            TargetAddress new_rbp = memory.ReadAddress(rbp);

            regs [(int)X86_Register.RBP].SetValue(rbp, new_rbp);

            TargetAddress new_rip = memory.ReadAddress(rbp + addr_size);

            regs [(int)X86_Register.RIP].SetValue(rbp + addr_size, new_rip);

            TargetAddress new_rsp = rbp + 2 * addr_size;

            regs [(int)X86_Register.RSP].SetValue(rbp, new_rsp);

            rbp -= addr_size;

            return(CreateFrame(frame.Thread, FrameType.Normal, memory, new_rip, new_rsp, new_rbp, regs));
        }
Example #23
0
        internal override TargetClassObject GetCurrentObject(TargetMemoryAccess target)
        {
            if (!type.IsByRef)
                return null;

            return type.GetCurrentObject (target, Location);
        }
Example #24
0
        internal override void WriteAddress(TargetMemoryAccess target,
                                            TargetAddress new_address)
        {
            if (!is_valid)
            {
                throw new LocationInvalidException();
            }

            if (is_regoffset)
            {
                TargetAddress the_addr;
                if (is_byref)
                {
                    the_addr = new TargetAddress(
                        target.AddressDomain, register.Value + regoffset);
                }
                else
                {
                    the_addr = address;
                }

                target.WriteAddress(the_addr, new_address);
                update(target);
            }
            else
            {
                register.WriteRegister(target, new_address.Address);
                update(target);
            }
        }
Example #25
0
        internal TargetClassObject GetCurrentObject(TargetMemoryAccess target,
                                                    TargetLocation location)
        {
            // location.Address resolves to the address of the MonoObject,
            // dereferencing it once gives us the vtable, dereferencing it
            // twice the class.
            TargetAddress address;

            address = target.ReadAddress(location.GetAddress(target));
            address = target.ReadAddress(address);

            TargetType current = File.MonoLanguage.ReadMonoClass(target, address);

            if (current == null)
            {
                return(null);
            }

            if (IsByRef && !current.IsByRef)             // Unbox
            {
                location = location.GetLocationAtOffset(
                    2 * target.TargetMemoryInfo.TargetAddressSize);
            }

            return((TargetClassObject)current.GetObject(target, location));
        }
            public StackFrame Unwind(StackFrame frame, TargetMemoryAccess target,
                                     Architecture arch)
            {
                Registers old_regs = frame.Registers;

                Registers regs = arch.CopyRegisters(old_regs);

                SetRegisters(regs, target, arch, columns);

                Register eip = GetRegister(regs, 0);
                Register esp = GetRegister(regs, 1);
                Register ebp = GetRegister(regs, 2);

                if (!eip.Valid || !esp.Valid)
                {
                    return(null);
                }

                TargetAddress address = new TargetAddress(
                    target.AddressDomain, eip.Value);
                TargetAddress stack = new TargetAddress(
                    target.AddressDomain, esp.Value);

                TargetAddress frame_addr = TargetAddress.Null;

                if (ebp.Valid)
                {
                    frame_addr = new TargetAddress(
                        target.AddressDomain, ebp.Value);
                }

                return(arch.CreateFrame(
                           frame.Thread, FrameType.Normal, target, address, stack, frame_addr, regs));
            }
Example #27
0
        internal override void SetObject(TargetMemoryAccess target, TargetLocation location,
						  TargetObject obj)
        {
            TargetLocation flag_loc = location.GetLocationAtOffset (ElementType.Size);
            byte[] buffer = new byte [1];

            if (obj is TargetNullObject) {
                buffer [0] = 0;
                flag_loc.WriteBuffer (target, buffer);
                return;
            }

            MonoNullableObject nobj = obj as MonoNullableObject;
            if (nobj != null) {
                if (!nobj.HasValue (target)) {
                    buffer [0] = 0;
                    flag_loc.WriteBuffer (target, buffer);
                    return;
                } else {
                    obj = nobj.GetValue (target);
                }
            }

            buffer [0] = 1;
            flag_loc.WriteBuffer (target, buffer);

            ElementType.SetObject (target, location, obj);
        }
            void GetValue(TargetMemoryAccess target, Registers regs,
                          TargetAddress cfa, int reg, Column column)
            {
                switch (column.State)
                {
                case State.Register: {
                    GetRegisterValue(regs, reg, column);
                    break;
                }

                case State.SameValue:
                    regs [GetArchRegister(reg)].Valid = true;
                    break;

                case State.Undefined:
                    break;

                case State.Offset: {
                    TargetAddress addr  = cfa + column.Offset;
                    long          value = target.ReadAddress(addr).Address;
                    regs [GetArchRegister(reg)].SetValue(address, value);
                    break;
                }

                default:
                    throw new NotSupportedException();
                }
            }
Example #29
0
        void update(TargetMemoryAccess target)
        {
            // If this is a reference type, the register just holds the
            // address of the actual data, so read the address from the
            // register and return it.
            if (!register.Valid)
            {
                is_valid = false;
                return;
            }

            long contents = register.Value;

            if (contents == 0)
            {
                address = TargetAddress.Null;
            }
            else
            {
                address = new TargetAddress(
                    target.AddressDomain, contents + regoffset);
            }

            if (is_byref && is_regoffset)
            {
                address = target.ReadAddress(address);
            }
            is_valid = true;
        }
Example #30
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));
        }
        StackFrame try_unwind_sigreturn(StackFrame frame, TargetMemoryAccess memory)
        {
            byte[] data = memory.ReadMemory(frame.TargetAddress, 9).Contents;

            /*
             * Check for signal return trampolines:
             *
             *   mov __NR_rt_sigreturn, %eax
             *   syscall
             */
            if ((data [0] != 0x48) || (data [1] != 0xc7) ||
                (data [2] != 0xc0) || (data [3] != 0x0f) ||
                (data [4] != 0x00) || (data [5] != 0x00) ||
                (data [6] != 0x00) || (data [7] != 0x0f) ||
                (data [8] != 0x05))
            {
                return(null);
            }

            TargetAddress stack = frame.StackPointer;

            /* See `struct sigcontext' in <asm/sigcontext.h> */
            int[] regoffsets =
            {
                (int)X86_Register.R8,  (int)X86_Register.R9,
                (int)X86_Register.R10, (int)X86_Register.R11,
                (int)X86_Register.R12, (int)X86_Register.R13,
                (int)X86_Register.R14, (int)X86_Register.R15,
                (int)X86_Register.RDI, (int)X86_Register.RSI,
                (int)X86_Register.RBP, (int)X86_Register.RBX,
                (int)X86_Register.RDX, (int)X86_Register.RAX,
                (int)X86_Register.RCX, (int)X86_Register.RSP,
                (int)X86_Register.RIP, (int)X86_Register.EFLAGS
            };

            Registers regs = CopyRegisters(frame.Registers);

            int offset = 0x28;

            /* The stack contains the `struct ucontext' from <asm/ucontext.h>; the
             * `struct sigcontext' starts at offset 0x28 in it. */
            foreach (int regoffset in regoffsets)
            {
                TargetAddress new_value = memory.ReadAddress(stack + offset);
                regs [regoffset].SetValue(new_value);
                offset += 8;
            }

            TargetAddress rip = new TargetAddress(
                memory.AddressDomain, regs [(int)X86_Register.RIP].GetValue());
            TargetAddress rsp = new TargetAddress(
                memory.AddressDomain, regs [(int)X86_Register.RSP].GetValue());
            TargetAddress rbp = new TargetAddress(
                memory.AddressDomain, regs [(int)X86_Register.RBP].GetValue());

            Symbol name = new Symbol("<signal handler>", rip, 0);

            return(new StackFrame(
                       frame.Thread, FrameType.Signal, rip, rsp, rbp, regs, frame.Thread.NativeLanguage, name));
        }
Example #32
0
        protected string ReadString(TargetMemoryAccess target, TargetLocation start)
        {
            if (start.HasAddress && start.GetAddress(target).IsNull)
            {
                return("null");
            }

            StringBuilder sb   = new StringBuilder();
            bool          done = false;

            int offset = 0;

            while (!done && (offset < MaximumDynamicSize))
            {
                TargetLocation location = start.GetLocationAtOffset(offset);
                byte[]         buffer   = location.ReadBuffer(target, ChunkSize);

                int    pos         = 0;
                int    size        = buffer.Length;
                char[] char_buffer = new char [size * 3];
                for (int i = 0; i < size; i++)
                {
                    if (buffer [i] == 0)
                    {
                        done = true;
                        break;
                    }

                    char ch = (char)buffer [i];
                    if (Char.IsLetterOrDigit(ch) || Char.IsPunctuation(ch) ||
                        Char.IsWhiteSpace(ch) || (ch == '<') || (ch == '>'))
                    {
                        char_buffer [pos++] = ch;
                    }
                    else if (ch == '\\')
                    {
                        char_buffer [pos++] = '\\';
                        char_buffer [pos++] = '\\';
                    }
                    else if ((ch == '\'') || (ch == '`'))
                    {
                        char_buffer [pos++] = ch;
                    }
                    else
                    {
                        char_buffer [pos++] = '\\';
                        char_buffer [pos++] = hex_chars [(ch & 0xf0) >> 4];
                        char_buffer [pos++] = hex_chars [ch & 0x0f];
                    }
                }

                string str = new String(char_buffer, 0, pos);
                sb.Append(str);

                offset += size;
            }

            return(sb.ToString());
        }
Example #33
0
 protected override object DoGetObject(TargetMemoryAccess target)
 {
     try {
         return ReadString (target, Location);
     } catch (TargetException ex) {
         throw new LocationInvalidException (ex);
     }
 }
Example #34
0
 internal override TargetObject GetDereferencedObject(TargetMemoryAccess target)
 {
     if (Type.StaticType is TargetPointerType) {
         TargetLocation loc = GetDereferencedLocation ();
         return Type.StaticType.GetObject (target, loc);
     } else
         return Type.StaticType.GetObject (target, Location);
 }
Example #35
0
 protected override object DoGetObject(TargetMemoryAccess target)
 {
     try {
         return(ReadString(target, Location));
     } catch (TargetException ex) {
         throw new LocationInvalidException(ex);
     }
 }
Example #36
0
        internal override long GetDynamicSize(TargetMemoryAccess target, TargetBlob blob,
						       TargetLocation location,
						       out TargetLocation dynamic_location)
        {
            int element_size = Type.GetElementSize (target);
            dynamic_location = location.GetLocationAtOffset (Type.Size);
            return element_size * GetLength (target);
        }
Example #37
0
        public AppDomainInfo GetAppDomainInfo(MonoLanguageBackend mono, TargetMemoryAccess memory,
						       TargetAddress address)
        {
            int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
            TargetReader reader = new TargetReader (memory.ReadMemory (address, 12 * addr_size));

            return new AppDomainInfo (mono, memory, reader);
        }
Example #38
0
 internal override string Print(TargetMemoryAccess target)
 {
     TargetAddress address = GetAddress (target);
     if (address.IsNull)
         return "null";
     else
         return String.Format ("{0}", address);
 }
Example #39
0
        public AppDomainInfo GetAppDomainInfo(MonoLanguageBackend mono, TargetMemoryAccess memory,
                                              TargetAddress address)
        {
            int          addr_size = memory.TargetMemoryInfo.TargetAddressSize;
            TargetReader reader    = new TargetReader(memory.ReadMemory(address, 12 * addr_size));

            return(new AppDomainInfo(mono, memory, reader));
        }
 internal override TargetAddress GetAddress(TargetMemoryAccess target)
 {
     TargetAddress address = reference.GetAddress (target);
     if (address.IsNull)
         return TargetAddress.Null;
     else
         return target.ReadAddress (address);
 }
Example #41
0
        internal override TargetAddress GetAddress(TargetMemoryAccess target)
        {
            if (!is_valid)
            {
                throw new LocationInvalidException();
            }

            return(address);
        }
Example #42
0
        internal override TargetClassObject GetCurrentObject(TargetMemoryAccess target)
        {
            if (!type.IsByRef)
            {
                return(null);
            }

            return(type.GetCurrentObject(target, Location));
        }
Example #43
0
 public TargetAddress GetMethodAddress(TargetMemoryAccess target, int token)
 {
     get_methods(target);
     if ((methods_by_token == null) || !methods_by_token.ContainsKey(token))
     {
         return(TargetAddress.Null);
     }
     return(methods_by_token [token]);
 }
Example #44
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 TargetClassType GetParentType(TargetMemoryAccess target)
        {
            if (!HasParent)
            {
                throw new InvalidOperationException();
            }

            return(base_info.BaseType);
        }
Example #46
0
        public static MonoVariableLocation Create(TargetMemoryAccess target, bool is_regoffset,
							   Register register, long regoffset,
							   bool is_byref)
        {
            MonoVariableLocation location = new MonoVariableLocation (
                is_regoffset, register, regoffset, is_byref);
            location.update (target);
            return location;
        }
        internal override TargetClass GetClass(TargetMemoryAccess target)
        {
            if (class_info == null)
            {
                class_info = new NativeClass(this, fields);
            }

            return(class_info);
        }
Example #48
0
        internal override TargetObject GetElement(TargetMemoryAccess target, int[] indices)
        {
            int offset = GetArrayOffset (target, indices);

            TargetLocation new_location = Location.GetLocationAtOffset (offset);
            if (Type.ElementType.IsByRef)
                new_location = new_location.GetDereferencedLocation ();

            return Type.ElementType.GetObject (target, new_location);
        }
Example #49
0
        internal static string ReadString(MonoLanguageBackend mono, TargetMemoryAccess target,
						   TargetAddress address)
        {
            if (address.IsNull)
                return null;

            TargetLocation location = new AbsoluteTargetLocation (address);
            MonoStringObject so = new MonoStringObject (mono.BuiltinTypes.StringType, location);
            return (string) so.DoGetObject (target);
        }
Example #50
0
        public static MonoVoidType Create(MonoSymbolFile corlib, TargetMemoryAccess memory)
        {
            MonoVoidType type = new MonoVoidType (
                corlib, corlib.ModuleDefinition.Types ["System.Void"]);

            TargetAddress klass = corlib.MonoLanguage.MetadataHelper.GetVoidClass (memory);
            type.create_type (memory, klass);

            return type;
        }
 internal override string Print(TargetMemoryAccess target)
 {
     object obj = DoGetObject (target);
     if (obj is IntPtr)
         return String.Format ("0x{0:x}", ((IntPtr) obj).ToInt64 ());
     else if (obj is UIntPtr)
         return String.Format ("0x{0:x}", ((UIntPtr) obj).ToUInt64 ());
     else
         return obj.ToString ();
 }
        internal override TargetBlob ReadMemory(TargetMemoryAccess target, int size)
        {
            if (size > blob.Size)
                throw new ArgumentException ();

            byte[] data = new byte [size];
            Array.Copy (blob.Contents, 0, data, 0, size);

            return new TargetBlob (data, blob.TargetMemoryInfo);
        }
Example #53
0
        internal override TargetType GetCurrentType(TargetMemoryAccess target)
        {
            // location.Address resolves to the address of the MonoObject,
            // dereferencing it once gives us the vtable, dereferencing it
            // twice the class.
            TargetAddress address;
            address = target.ReadAddress (Location.GetAddress (target));
            address = target.ReadAddress (address);

            return Type.File.MonoLanguage.ReadMonoClass (target, address);
        }
Example #54
0
        internal override TargetClassObject GetParentObject(TargetMemoryAccess target)
        {
            if (!type.HasParent || !type.IsByRef)
                return null;

            TargetClassType sparent = type.GetParentType (target);
            if (sparent == null)
                return null;

            return (TargetClassObject) sparent.GetObject (target, Location);
        }
Example #55
0
        internal override TargetObject GetDereferencedObject(TargetMemoryAccess target)
        {
            if (!Type.HasStaticType)
                throw new InvalidOperationException ();

            TargetLocation new_loc = Location;
            if (Type.StaticType.IsByRef)
                new_loc = Location.GetDereferencedLocation ();

            return Type.StaticType.GetObject (target, new_loc);
        }
Example #56
0
        protected MonoClassInfo(MonoSymbolFile file, Cecil.TypeDefinition typedef,
					 TargetMemoryAccess target, TargetAddress klass)
        {
            this.SymbolFile = file;
            this.KlassAddress = klass;
            this.CecilType = typedef;

            parent_klass = MetadataHelper.MonoClassGetParent (target, klass);
            GenericClass = MetadataHelper.MonoClassGetGenericClass (target, klass);
            GenericContainer = MetadataHelper.MonoClassGetGenericContainer (target, klass);
        }
Example #57
0
        public static MonoStringType Create(MonoSymbolFile corlib, TargetMemoryAccess memory)
        {
            int object_size = 2 * memory.TargetMemoryInfo.TargetAddressSize;

            MonoStringType type = new MonoStringType (
                corlib, corlib.ModuleDefinition.GetType ("System.String"),
                object_size, object_size + 4);

            TargetAddress klass = corlib.MonoLanguage.MetadataHelper.GetStringClass (memory);
            type.create_type (memory, klass);

            return type;
        }
Example #58
0
        internal override TargetObject GetArrayElement(TargetMemoryAccess target, int index)
        {
            if (!Type.IsArray)
                throw new InvalidOperationException ();

            int size = Type.Size;
            TargetLocation new_loc = Location.GetLocationAtOffset (index * size);

            if (Type.StaticType.IsByRef)
                new_loc = new_loc.GetDereferencedLocation ();

            return Type.StaticType.GetObject (target, new_loc);
        }
Example #59
0
        internal override int GetElementSize(TargetMemoryAccess target)
        {
            TargetType element_type;
            if (ElementType is MonoEnumType)
                element_type = ((MonoEnumType) ElementType).ClassType;
            else
                element_type = ElementType;

            IMonoStructType stype = element_type as IMonoStructType;
            if ((stype == null) || stype.Type.IsByRef)
                return base.GetElementSize (target);

            MonoClassInfo cinfo = stype.ResolveClass (target, true);
            return cinfo.GetInstanceSize (target);
        }
Example #60
0
        internal override TargetObject GetDereferencedObject(TargetMemoryAccess target)
        {
            TargetType current_type = GetCurrentType (target);
            if (current_type == null)
                return null;

            // If this is a reference type, then the `MonoObject *' already
            // points to the boxed object itself.
            // If it's a valuetype, then the boxed contents is immediately
            // after the `MonoObject' header.

            int offset = current_type.IsByRef ? 0 : type.Size;
            TargetLocation new_location = Location.GetLocationAtOffset (offset);
            TargetObject obj = current_type.GetObject (target, new_location);
            return obj;
        }