ReadOffset() public method

public ReadOffset ( ) : long
return long
Ejemplo n.º 1
0
        public StackFrame UnwindStack(StackFrame frame, TargetMemoryAccess target,
					       Architecture arch)
        {
            if (frame.TargetAddress.IsNull)
                return null;

            TargetAddress address = frame.TargetAddress;

            DwarfBinaryReader reader = new DwarfBinaryReader (bfd, blob, false);

            while (reader.Position < reader.Size) {
                long length = reader.ReadInitialLength ();
                if (length == 0)
                    break;
                long end_pos = reader.Position + length;

                long cie_pointer = reader.ReadOffset ();
                bool is_cie;
                if (is_ehframe)
                    is_cie = cie_pointer == 0;
                else
                    is_cie = cie_pointer == -1;

                if (is_cie) {
                    reader.Position = end_pos;
                    continue;
                }

                if (is_ehframe)
                    cie_pointer = reader.Position - cie_pointer -
                        target.TargetMemoryInfo.TargetAddressSize;

                CIE cie = find_cie (cie_pointer);

                long initial, range;
                if (is_ehframe) {
                    initial = ReadEncodedValue (reader, cie.Encoding);
                    range = ReadEncodedValue (reader, cie.Encoding & 0x0f);
                } else {
                    initial = reader.ReadAddress ();
                    range = reader.ReadAddress ();
                }

                TargetAddress start = new TargetAddress (target.AddressDomain, initial);

                if ((address < start) || (address > start + range)) {
                    reader.Position = end_pos;
                    continue;
                }

                Entry fde = new Entry (cie, start, address);
                fde.Read (reader, end_pos);
                return fde.Unwind (frame, target, arch);
            }

            return null;
        }
Ejemplo n.º 2
0
        Hashtable read_pubtypes()
        {
            if (debug_pubtypes_reader == null)
                return null;

            DwarfBinaryReader reader = new DwarfBinaryReader (
                bfd, (TargetBlob) debug_pubtypes_reader.Data, Is64Bit);

            Hashtable names = Hashtable.Synchronized (new Hashtable ());

            while (!reader.IsEof) {
                long length = reader.ReadInitialLength ();
                long stop = reader.Position + length;
                int version = reader.ReadInt16 ();
                long debug_offset = reader.ReadOffset ();
                reader.ReadOffset ();

                if (version != 2)
                    throw new DwarfException (
                        bfd, "Wrong version in .debug_pubtypes: {0}",
                        version);

                while (reader.Position < stop) {
                    long offset = reader.ReadInt32 ();
                    if (offset == 0)
                        break;

                    string name = reader.ReadString ();
                    if (!names.Contains (name))
                        names.Add (name, new NameEntry (debug_offset, offset));
                }
            }

            return names;
        }
Ejemplo n.º 3
0
            public LineNumberEngine(DieCompileUnit comp_unit, long offset,
						 string compilation_dir)
            {
                this.comp_unit = comp_unit;
                this.offset = offset;
                this.reader = comp_unit.dwarf.DebugLineReader;
                this.compilation_dir = compilation_dir;

                debug ("NEW LNE: {0}", offset);

                reader.Position = offset;
                length = reader.ReadInitialLength ();
                end_offset = reader.Position + length;
                version = reader.ReadInt16 ();
                header_length = reader.ReadOffset ();
                data_offset = reader.Position + header_length;
                minimum_insn_length = reader.ReadByte ();
                default_is_stmt = reader.ReadByte () != 0;
                line_base = (sbyte) reader.ReadByte ();
                line_range = reader.ReadByte ();
                opcode_base = reader.ReadByte ();
                standard_opcode_lengths = new int [opcode_base - 1];
                for (int i = 0; i < opcode_base - 1; i++)
                    standard_opcode_lengths [i] = reader.ReadByte ();
                include_dirs = new ArrayList ();
                while (reader.PeekByte () != 0)
                    include_dirs.Add (reader.ReadString ());
                reader.Position++;
                source_files = new ArrayList ();
                while (reader.PeekByte () != 0)
                    source_files.Add (new FileEntry (this, reader));
                reader.Position++;

                const_add_pc_range = ((0xff - opcode_base) / line_range) *
                    minimum_insn_length;

                debug ("NEW LNE #1: {0} {1} - {2} {3} {4}",
                       reader.Position, offset, length,
                       data_offset, end_offset);

                lines = new ArrayList ();

                stm = new StatementMachine (this, data_offset, end_offset);
                Read ();

                lines.Sort ();
                addresses = new LineNumber [lines.Count];
                lines.CopyTo (addresses, 0);
            }
Ejemplo n.º 4
0
        ArrayList read_aranges()
        {
            ArrayList ranges = new ArrayList ();

            if (debug_aranges_reader == null)
                return ranges;

            DwarfBinaryReader reader = new DwarfBinaryReader (
                bfd, (TargetBlob) debug_aranges_reader.Data, Is64Bit);

            while (!reader.IsEof) {
                long length = reader.ReadInitialLength ();
                long stop = reader.Position + length;
                int version = reader.ReadInt16 ();
                long offset = reader.ReadOffset ();
                int address_size = reader.ReadByte ();
                int segment_size = reader.ReadByte ();

                if ((address_size != 4) && (address_size != 8))
                    throw new DwarfException (
                        bfd, "Unknown address size: {0}", address_size);
                if (segment_size != 0)
                    throw new DwarfException (
                        bfd, "Segmented address mode not supported");

                if (version != 2)
                    throw new DwarfException (
                        bfd, "Wrong version in .debug_aranges: {0}",
                        version);

                if (AddressSize == 8)
                    reader.Position = ((reader.Position+15) >> 4) * 16;
                else
                    reader.Position = ((reader.Position+7) >> 3) * 8;

                while (reader.Position < stop) {
                    long address = reader.ReadAddress ();
                    long size = reader.ReadAddress ();

                    if ((address == 0) && (size == 0))
                        break;

                    TargetAddress taddress = GetAddress (address);
                    ranges.Add (new RangeEntry (this, offset, taddress, size));
                }
            }

            return ranges;
        }
Ejemplo n.º 5
0
            public CompilationUnit(DwarfReader dwarf, DwarfBinaryReader reader)
            {
                this.dwarf = dwarf;

                real_start_offset = reader.Position;
                unit_length = reader.ReadInitialLength ();
                start_offset = reader.Position;
                version = reader.ReadInt16 ();
                abbrev_offset = reader.ReadOffset ();
                address_size = reader.ReadByte ();

                if (version < 2)
                    throw new DwarfException (
                        dwarf.bfd, "Wrong DWARF version: {0}",
                        version);

                abbrevs = new Hashtable ();
                types = new Hashtable ();
                subprogs = new Hashtable ();
                namespaces = new Dictionary<long,DieNamespace> ();

                DwarfBinaryReader abbrev_reader = dwarf.DebugAbbrevReader;

                abbrev_reader.Position = abbrev_offset;
                while (abbrev_reader.PeekByte () != 0) {
                    AbbrevEntry entry = new AbbrevEntry (dwarf, abbrev_reader);
                    abbrevs.Add (entry.ID, entry);
                }

                comp_unit_die = Die.CreateDieCompileUnit (reader, this);

                reader.Position = start_offset + unit_length;
            }