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 -
        startOffset -
        endOffset -
        length -
        format -
        version -
        abbreviationOffset -
        pointerSize -
        compUnitNumber -
        firstDIEOffset -
        codeToAbbreviationMap -
    • 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.

        Parameters:
        debugInfoBR -
        debugAbbrBR -
        cuNumber -
        helper -
        monitor -
        Returns:
        Throws:
        DWARFException
        java.io.IOException
        CancelledException
      • 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.