Class DWARFCompilationUnit


  • public class DWARFCompilationUnit
    extends java.lang.Object
    A DWARF "CompilationUnit" is a contiguous block of DIE records found in a ".debug_info" section of an ELF program. The compilation unit block starts with a header that has a few important values and flags, and is followed by the DIE records.

    The first DIE record must be a DW_TAG_compile_unit (see DWARFCompileUnit, and getCompileUnit()).

    DIE records are identified by their byte offset in the ".debug_info" section.

    • Constructor Detail

      • DWARFCompilationUnit

        public DWARFCompilationUnit​(DWARFProgram dwarfProgram,
                                    long startOffset,
                                    long endOffset,
                                    long length,
                                    int format,
                                    short version,
                                    long abbreviationOffset,
                                    byte pointerSize,
                                    int compUnitNumber,
                                    long firstDIEOffset,
                                    java.util.Map<java.lang.Integer,​DWARFAbbreviation> codeToAbbreviationMap)
        This ctor is public only for junit tests. Do not use directly.
        Parameters:
        dwarfProgram - DWARFProgram
        startOffset - offset in provider where it starts
        endOffset - offset in provider where it ends
        length - how many bytes following the header the DIEs of this unit take
        format - DWARF_32 or DWARF_64
        version - 2, 3, 4
        abbreviationOffset - offset into abbrev section
        pointerSize - default size of pointers
        compUnitNumber - this compunits ordinal in the file
        firstDIEOffset - start of DIEs in the provider
        codeToAbbreviationMap - map of abbreviation numbers to DWARFAbbreviation instances
    • Method Detail

      • readCompilationUnit

        public static DWARFCompilationUnit readCompilationUnit​(DWARFProgram dwarfProgram,
                                                               BinaryReader debugInfoBR,
                                                               BinaryReader debugAbbrBR,
                                                               int cuNumber,
                                                               TaskMonitor monitor)
                                                        throws DWARFException,
                                                               java.io.IOException,
                                                               CancelledException
        Creates a new DWARFCompilationUnit by reading a compilationUnit's header data from the debug_info section and the debug_abbr section and its compileUnit DIE (ie. the first DIE right after the header).

        Returns NULL if there was an ignorable error while reading the compilation unit (and leaves the input stream at the next compilation unit to read), otherwise throws an IOException if there was an unrecoverable error.

        Also returns NULL (and leaves the stream at EOF) if the remainder of the stream is filled with null bytes.

        Parameters:
        dwarfProgram - the dwarf program.
        debugInfoBR - the debug info binary reader.
        debugAbbrBR - the debug abbreviation binary reader
        cuNumber - the compilation unit number
        monitor - the current task monitor
        Returns:
        the read compilation unit, or null if the compilation unit was bad/empty and should be ignored
        Throws:
        DWARFException - if an invalid or unsupported DWARF version is read.
        java.io.IOException - if the length of the compilation unit is invalid.
        CancelledException - if the task has been canceled.
      • getLength

        public long getLength()
        An unsigned long (4 bytes in 32-bit or 8 bytes in 64-bit format) representing the length of the .debug_info contribution for that compilation unit, not including the length field itself.
        Returns:
        the length in bytes of the this compilation unit
      • getPointerSize

        public byte getPointerSize()
        A 1-byte unsigned integer representing the size in bytes of an address on the target architecture. If the system uses segmented addressing, this value represents the size of the offset portion of an address.
        Returns:
        the size in bytes of pointers
      • getStartOffset

        public long getStartOffset()
        Returns the byte offset to the start of this compilation unit.
        Returns:
        the byte offset to the start of this compilation unit
      • getEndOffset

        public long getEndOffset()
        Returns the byte offset to the end of this compilation unit.
        Returns:
        the byte offset to the end of this compilation unit
      • getFormat

        public int getFormat()
        Returns either DWARF_32 or DWARF_64 depending on the current compilation unit format
        Returns:
        DWARF_32 or DWARF_64 constant depending on the current compilation unit format
      • containsOffset

        public boolean containsOffset​(long offset)
        Returns true if the offset value is within this compUnit's start and end position in the debug_info section.
        Parameters:
        offset - DIE offset
        Returns:
        true if within range of this compunit
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getCodeToAbbreviationMap

        public java.util.Map<java.lang.Integer,​DWARFAbbreviation> getCodeToAbbreviationMap()
      • getFirstDIEOffset

        public long getFirstDIEOffset()
      • getCompUnitNumber

        public int getCompUnitNumber()
      • readDIEs

        public void readDIEs​(java.util.List<DebugInfoEntry> entries,
                             TaskMonitor monitor)
                      throws java.io.IOException,
                             DWARFException,
                             CancelledException
        Reads the DebugInfoEntry records for this compilation unit from the .debug_info section.

        Parameters:
        entries - List of DIE records that is written to by this method. This list should be empty if the caller only wants this CU's records (ie. normal mode), or the list can be used to accumulate all DIE records (preload all DIE mode).
        monitor - TaskMonitor to watch for cancelation
        Throws:
        java.io.IOException - if error reading data
        DWARFException - if error in DWARF structure
        CancelledException - if user cancels.