Inheritance: TargetBinaryReader
Example #1
0
            public DieFormalParameter(DieSubprogram parent, DwarfBinaryReader reader,
						   CompilationUnit comp_unit, AbbrevEntry abbrev)
                : base(parent, reader, comp_unit, abbrev, null, false)
            {
            }
Example #2
0
        private long ReadEncodedValue(DwarfBinaryReader reader, int encoding)
        {
            long base_addr;
            switch (encoding & 0x70) {
            case 0:
                base_addr = 0;
                break;
            case (byte) DW_EH_PE.pcrel:
                base_addr = vma + reader.Position;
                break;
            default:
                throw new DwarfException (
                    reader.Bfd, "Unknown encoding `{0:x}' in CIE",
                    encoding);
            }

            long value;
            switch (encoding & 0x0f) {
            case (byte) DW_EH_PE.udata4:
                value = reader.ReadUInt32 ();
                break;
            case (byte) DW_EH_PE.sdata4:
                value = reader.ReadInt32 ();
                break;
            default:
                throw new DwarfException (
                    reader.Bfd, "Unknown encoding `{0:x}' in CIE",
                    encoding);
            }

            return base_addr + value;
        }
Example #3
0
            void read_cie(DwarfBinaryReader reader)
            {
                long length = reader.ReadInitialLength ();
                long end_pos = reader.Position + length;
                int id = reader.ReadInt32 ();

                bool is_cie;
                if (frame.is_ehframe)
                    is_cie = id == 0;
                else
                    is_cie = id == -1;
                if (!is_cie)
                    throw new InvalidOperationException ();

                int version = reader.ReadByte ();
                if (version != 1)
                    throw new DwarfException (
                        reader.Bfd, "Unknown version {0} in CIE",
                        version);

                string augmentation = reader.ReadString ();

                if (augmentation.StartsWith ("eh")) {
                    reader.ReadAddress ();
                    augmentation = augmentation.Substring (2);
                }

                code_alignment = reader.ReadLeb128 ();
                data_alignment = reader.ReadSLeb128 ();
                return_register = reader.ReadByte ();

                for (int pos = 0; pos < augmentation.Length; pos++) {
                    if (augmentation [pos] == 'z') {
                        reader.ReadLeb128 ();
                        // has_z_augmentation = true;
                        continue;
                    }

                    if (augmentation [pos] == 'L')
                        continue;
                    else if (augmentation [pos] == 'R') {
                        encoding = reader.ReadByte ();
                        continue;
                    }
                    else if (augmentation [pos] == 'P') {
                        continue;
                    }

                    throw new DwarfException (
                        reader.Bfd, "Unknown augmentation `{0}' in CIE",
                        augmentation[pos]);
                }

                columns = new Column [return_register + 2];
                for (int i = 0; i < columns.Length; i++)
                    columns [i] = new Column (State.Undefined);

                Entry entry = new Entry (this);
                entry.Read (reader, end_pos);

                reader.Position = end_pos;
            }
Example #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;
        }
Example #5
0
            public AbbrevEntry(DwarfReader dwarf, DwarfBinaryReader reader)
            {
                abbrev_id = reader.ReadLeb128 ();
                tag = (DwarfTag) reader.ReadLeb128 ();
                has_children = reader.ReadByte () != 0;

                Attributes = new ArrayList ();

                do {
                    int attr = reader.ReadLeb128 ();
                    int form = reader.ReadLeb128 ();

                    if ((attr == 0) && (form == 0))
                        break;

                    Attributes.Add (new AttributeEntry (
                        dwarf, (DwarfAttribute) attr, (DwarfForm) form));
                } while (true);
            }
Example #6
0
            public DieVariable(DieSubprogram parent, DwarfBinaryReader reader,
					    CompilationUnit comp_unit, AbbrevEntry abbrev,
					    DieLexicalBlock lexical)
                : base(parent, reader, comp_unit, abbrev, lexical, true)
            {
            }
Example #7
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);
            }
Example #8
0
            public DieNamespace(DwarfBinaryReader reader, CompilationUnit comp_unit,
					     long offset, AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
                this.offset = offset;
                comp_unit.AddNamespace (offset, this);

                if (extension != null) {
                    if (extension.name != null) {
                        if (name != null)
                            name = extension.name + "::" + name;
                        else
                            name = extension.name;
                    }
                }
            }
Example #9
0
            protected override ArrayList ReadChildren(DwarfBinaryReader reader)
            {
                string old_ns = comp_unit.CurrentNamespace;
                if (name == null)
                    comp_unit.CurrentNamespace = null;
                else if (comp_unit.CurrentNamespace != null)
                    comp_unit.CurrentNamespace = comp_unit.CurrentNamespace + "::" + name;
                else
                    comp_unit.CurrentNamespace = name;

                try {
                    debug ("NS CHILDREN: {0} -> {1}", name, comp_unit.CurrentNamespace);
                    return base.ReadChildren (reader);
                    debug ("NS CHILDREN DONE: {0}", name);
                } finally {
                    comp_unit.CurrentNamespace = old_ns;
                }
            }
Example #10
0
            public DieMember(DwarfBinaryReader reader, CompilationUnit comp_unit,
					  AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
                this.target_info = reader.TargetMemoryInfo;
            }
Example #11
0
            public DieMethodVariable(DieSubprogram subprog, DwarfBinaryReader reader,
						  CompilationUnit comp_unit, AbbrevEntry abbrev,
						  DieLexicalBlock lexical_block, bool is_local)
                : base(reader, comp_unit, abbrev)
            {
                this.subprog = subprog;
                this.lexical_block = lexical_block;

                if (subprog != null) {
                    if (is_local)
                        subprog.AddLocal (this);
                    else
                        subprog.AddParameter (this);
                }
            }
Example #12
0
            protected override Die CreateDie(DwarfBinaryReader reader, CompilationUnit comp_unit,
							  long offset, AbbrevEntry abbrev)
            {
                switch (abbrev.Tag) {
                case DwarfTag.formal_parameter:
                    return new DieFormalParameter (subprog, reader, comp_unit, abbrev);

                case DwarfTag.variable:
                    return new DieVariable (subprog, reader, comp_unit, abbrev, this);

                case DwarfTag.lexical_block:
                    return new DieLexicalBlock (subprog, reader, comp_unit, abbrev);

                default:
                    debug ("LEXICAL BLOCK ({0}): unknown die: {1}", Offset, abbrev.Tag);
                    return base.CreateDie (reader, comp_unit, offset, abbrev);
                }
            }
Example #13
0
            public DieLexicalBlock(DieSubprogram subprog, DwarfBinaryReader reader,
						CompilationUnit comp_unit, AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
                this.subprog = subprog;
            }
Example #14
0
            public DieInheritance(DwarfBinaryReader reader,
					       CompilationUnit comp_unit,
					       AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
            }
Example #15
0
            public DieTypedef(DwarfBinaryReader reader, CompilationUnit comp_unit,
					   long offset, AbbrevEntry abbrev)
                : base(reader, comp_unit, offset, abbrev)
            {
            }
Example #16
0
            public DieStructureType(DwarfBinaryReader reader,
						 CompilationUnit comp_unit, long offset,
						 AbbrevEntry abbrev, bool is_union)
                : base(reader, comp_unit, offset, abbrev)
            {
                this.IsUnion = is_union;
            }
Example #17
0
            public DieVariable(DieSubprogram parent, DwarfBinaryReader reader,
					    CompilationUnit comp_unit, AbbrevEntry abbrev)
                : base(parent, reader, comp_unit, abbrev, null, true)
            {
            }
Example #18
0
            protected override Die CreateDie(DwarfBinaryReader reader, CompilationUnit comp_unit,
							  long offset, AbbrevEntry abbrev)
            {
                switch (abbrev.Tag) {
                case DwarfTag.inheritance:
                    return new DieInheritance (reader, comp_unit, abbrev);

                default:
                    return base.CreateDie (reader, comp_unit, offset, abbrev);
                }
            }
Example #19
0
            public DieVariableBase(DwarfBinaryReader reader, CompilationUnit comp_unit,
						AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
            }
Example #20
0
            public DieSubprogram(DwarfBinaryReader reader, CompilationUnit comp_unit,
					      long offset, AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
                this.real_offset = offset;
                if ((start_pc != 0) && (end_pc != 0))
                    is_continuous = true;

                comp_unit.AddSubprogram (offset, this);
            }
Example #21
0
                public FileEntry(LineNumberEngine engine, DwarfBinaryReader reader)
                {
                    FileName = reader.ReadString ();
                    Directory = reader.ReadLeb128 ();
                    LastModificationTime = reader.ReadLeb128 ();
                    Length = reader.ReadLeb128 ();

                    string dir_name;
                    if (Directory > 0)
                        dir_name = (string) engine.include_dirs [Directory - 1];
                    else
                        dir_name = engine.compilation_dir;

                    string full_name;
                    if (dir_name != null)
                        full_name = Path.Combine (dir_name, FileName);
                    else
                        full_name = FileName;

                    File = engine.comp_unit.dwarf.GetSourceFile (full_name);
                }
Example #22
0
            protected override Die CreateDie(DwarfBinaryReader reader, CompilationUnit comp_unit,
							  long offset, AbbrevEntry abbrev)
            {
                switch (abbrev.Tag) {
                case DwarfTag.formal_parameter:
                    return new DieFormalParameter (this, reader, comp_unit, abbrev);

                case DwarfTag.variable:
                    return new DieVariable (this, reader, comp_unit, abbrev);

                case DwarfTag.lexical_block:
                    return new DieLexicalBlock (this, reader, comp_unit, abbrev);

                default:
                    return base.CreateDie (reader, comp_unit, offset, abbrev);
                }
            }
Example #23
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;
        }
Example #24
0
            public DieSubrangeType(DwarfBinaryReader reader, CompilationUnit comp_unit,
						AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
            }
Example #25
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;
        }
Example #26
0
            protected override Die CreateDie(DwarfBinaryReader reader, CompilationUnit comp_unit,
							  long offset, AbbrevEntry abbrev)
            {
                switch (abbrev.Tag) {
                case DwarfTag.formal_parameter:
                    return new DieFormalParameter (null, reader, comp_unit, abbrev);

                default:
                    return base.CreateDie (reader, comp_unit, offset, abbrev);
                }
            }
Example #27
0
            public CIE(DwarfFrameReader frame, long offset, CIE next)
            {
                this.frame = frame;
                this.offset = offset;
                this.next = next;

                DwarfBinaryReader reader = new DwarfBinaryReader (
                    frame.bfd, frame.blob, false);
                read_cie (reader);
            }
Example #28
0
            public DieType(DwarfBinaryReader reader, CompilationUnit comp_unit,
					long offset, AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
                this.offset = offset;
                this.language = reader.Bfd.NativeLanguage;
                comp_unit.AddType (offset, this);

                if (specification != null) {
                    if ((name == null) && (specification.name != null))
                        name = specification.Name;
                }

                if (name != null) {
                    if (comp_unit.CurrentNamespace != null)
                        name = comp_unit.CurrentNamespace + "::" + name;
                    comp_unit.DwarfReader.AddType (this);
                }
            }
Example #29
0
            public void Read(DwarfBinaryReader reader, long end_pos)
            {
                while (reader.Position < end_pos) {
                    byte first = reader.ReadByte ();
                    int opcode = first >> 6;
                    int low = first & 0x3f;

                    if (opcode == (int) DW_CFA.offset) {
                        int offset = reader.ReadLeb128 ();
                        offset *= cie.DataAlignment;

                        columns [low + 1].State = State.Offset;
                        columns [low + 1].Register = 0;
                        columns [low + 1].Offset = offset;
                        continue;
                    } else if (opcode == (int) DW_CFA.advance_loc) {
                        current_address += low;
                        if (current_address > address)
                            return;
                        continue;
                    } else if (opcode != 0) {
                        continue;
                    }

                    switch ((DW_CFA) low) {
                    case DW_CFA.nop:
                        break;
                    case DW_CFA.def_cfa:
                        columns [0].State = State.Register;
                        columns [0].Register = reader.ReadLeb128 ();
                        columns [0].Offset = reader.ReadLeb128 ();
                        break;
                    case DW_CFA.def_cfa_register:
                        columns [0].State = State.Register;
                        columns [0].Register = reader.ReadLeb128 ();
                        break;
                    case DW_CFA.def_cfa_offset:
                        columns [0].Offset = reader.ReadLeb128 ();
                        break;
                    case DW_CFA.gnu_args_size:
                        // Ignored.
                        reader.ReadLeb128 ();
                        break;
                    default:
                        break;
                    }
                }
            }
Example #30
0
            public DieEnumerator(DwarfBinaryReader reader, CompilationUnit comp_unit,
					      AbbrevEntry abbrev)
                : base(reader, comp_unit, abbrev)
            {
            }