Class DWARFCompilationUnit

java.lang.Object
ghidra.app.util.bin.format.dwarf.DWARFUnitHeader
ghidra.app.util.bin.format.dwarf.DWARFCompilationUnit

public class DWARFCompilationUnit extends DWARFUnitHeader
A DWARF CompilationUnit is a contiguous block of DIE records found in a .debug_info section of an 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.

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

  • Field Details

    • diea

      protected DIEAggregate diea
      The contents of the first DIE (that must be a compile unit) in this compUnit.
  • Constructor Details

    • DWARFCompilationUnit

      public DWARFCompilationUnit(DIEContainer dieContainer, long startOffset, long endOffset, int intSize, short dwarfVersion, byte pointerSize, int unitNumber, long firstDIEOffset, Map<Integer,DWARFAbbreviation> codeToAbbreviationMap)
      This ctor is public only for junit tests. Do not use directly.
      Parameters:
      dieContainer - holds all DIE records and related serialization info
      startOffset - offset in provider where it starts
      endOffset - offset in provider where it ends
      intSize - 4 (DWARF_32) or 8 (DWARF_64)
      dwarfVersion - 2-5
      pointerSize - default size of pointers
      unitNumber - this compunit's ordinal in the file
      firstDIEOffset - start of DIEs in the provider
      codeToAbbreviationMap - map of abbreviation numbers to DWARFAbbreviation instances
  • Method Details

    • readV4 NEW

      public static DWARFCompilationUnit readV4(DWARFUnitHeader partial, BinaryReader reader) throws DWARFException, IOException
      Creates a new DWARFCompilationUnit by reading a compilationUnit's header data from the debug_info section.

      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:
      partial - already read partial unit header
      reader - .debug_info BinaryReader
      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.
      IOException - if the length of the compilation unit is invalid.
    • readV5 NEW

      public static DWARFCompilationUnit readV5(DWARFUnitHeader partial, BinaryReader reader) throws DWARFException, IOException
      Creates a new DWARFCompilationUnit by reading a compilationUnit's header data from the debug_info section.

      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:
      partial - already read partial unit header
      reader - .debug_info BinaryReader
      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.
      IOException - if the length of the compilation unit is invalid.
    • init

      public void init(DebugInfoEntry rootDIE) throws IOException
      Initializes this compunit with the root DIE (first DIE) of the compunit. This comp unit isn't usable until this has happened.
      Parameters:
      rootDIE - DebugInfoEntry
      Throws:
      IOException - if error reading data from the DIE
    • getCompUnitDIEA

      public DIEAggregate getCompUnitDIEA()
      Returns this comp unit's root DIE as a DIE Aggregate.
      Returns:
      the aggregate containing the root element of this comp unit
    • getPointerSize

      public byte getPointerSize()
      Returns the size of pointers in this compUnit.
      Returns:
      the size in bytes of pointers
    • getCodeToAbbreviationMap

      public Map<Integer,DWARFAbbreviation> getCodeToAbbreviationMap()
    • getAbbreviation

      public DWARFAbbreviation getAbbreviation(int ac)
    • getFirstDIEOffset

      public long getFirstDIEOffset()
    • getLine

      public DWARFLine getLine()
    • getMacros

      public DWARFMacroHeader getMacros()
    • getName

      public String getName()
      Get the filename that produced the compile unit
      Returns:
      the filename that produced the compile unit
    • getProducer

      public String getProducer()
      Get the producer of the compile unit
      Returns:
      the producer of the compile unit
    • getCompileDirectory

      public String getCompileDirectory()
      Get the compile directory of the compile unit
      Returns:
      the compile directory of the compile unit
    • getLanguage

      public int getLanguage()
      Get the source language of the compile unit.

      See DWARFSourceLanguage for values.

      Returns:
      the source language of the compile unit, or -1 if not set
    • hasDWO

      public boolean hasDWO()
    • getAddrTableBase

      public long getAddrTableBase()
    • getRangeListsBase

      public long getRangeListsBase()
    • getLocListsBase

      public long getLocListsBase()
    • getStrOffsetsBase

      public long getStrOffsetsBase()
    • getPCRange

      public DWARFRange getPCRange()
      Returns the range covered by this CU, as defined by the lo_pc and high_pc attribute values, defaulting to (0,0] if missing.
      Returns:
      DWARFRange that this CU covers, never null
    • toString

      public String toString()
      Overrides:
      toString in class Object