Class DWARFProgram

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class DWARFProgram
    extends java.lang.Object
    implements java.io.Closeable
    DWARFProgram encapsulates a Ghidra program with DWARF specific reference data used by DWARFDataTypeImporter and DWARFFunctionImporter, along with some helper functions.
    • Method Detail

      • isDWARF

        public static boolean isDWARF​(Program program)
        Returns true if the program probably has DWARF information.

        If the program is an Elf binary, it must have (at least) ".debug_info" and ".debug_abbr" program sections.

        If the program is a MachO binary (ie. Mac), it must have a ".dSYM" directory co-located next to the original binary file on the native filesystem. (ie. outside of Ghidra). See the DSymSectionProvider for more info.

        Parameters:
        program - Program to test
        Returns:
        boolean true if program has DWARF info, false if not
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • getGhidraProgram

        public Program getGhidraProgram()
      • isBigEndian

        public boolean isBigEndian()
      • isLittleEndian

        public boolean isLittleEndian()
      • getEntryName

        public java.lang.String getEntryName​(DIEAggregate diea)
      • lookupDNIByOffset

        public DWARFNameInfo lookupDNIByOffset​(long offset)
      • cacheDNIByOffset

        public void cacheDNIByOffset​(long offset,
                                     DWARFNameInfo dni)
      • getAggregate

        public DIEAggregate getAggregate​(long offset)
        Returns the DIEAggregate that contains the DebugInfoEntry specified by the offset.
        Parameters:
        offset - offset of a DIE record
        Returns:
        DIEAggregate that contains the DIE record specified, or null if bad offset.
      • getTotalDIECount

        public int getTotalDIECount()
        Returns the total number of DIE records in the entire program.
        Returns:
        the total number of DIE records in the entire program.
      • getTotalAggregateCount

        public int getTotalAggregateCount()
        Returns the total number of DIEAggregate objects in the entire program.
        Returns:
        the total number of DIEAggregate objects in the entire program.
      • getUncategorizedRootDNI

        public DWARFNameInfo getUncategorizedRootDNI()
      • getDebugStrings

        public StringTable getDebugStrings()
      • getFoundCrossCURefs

        public boolean getFoundCrossCURefs()
      • setFoundCrossCURefs

        public void setFoundCrossCURefs​(boolean b)
      • getEntries

        public java.util.List<DebugInfoEntry> getEntries()
        Returns:
        the entries list
      • getEntryAtByteOffsetUnchecked

        public DebugInfoEntry getEntryAtByteOffsetUnchecked​(long byteOffset)
        Returns the entry with the given byte offset.

        The byte offset corresponds to the byte index in the original file where the entry was defined.

        Returns null if the requested entry does not exist.

        Parameters:
        byteOffset - the byte offset
        Returns:
        the entry with the given byte offset
      • getTypeReferers

        public java.util.List<DIEAggregate> getTypeReferers​(DIEAggregate targetDIEA,
                                                            int tag)
        Returns a list of DIEAggregates that refer to the targetDIEA via an attribute of the specified tag type.
        Parameters:
        targetDIEA - DIEAggregate that might be pointed to by other DIEAs.
        tag - the DWARFTag attribute type that is pointing DIEAs are using to refer to the target DIEA.
        Returns:
        list of DIEAs that point to the target, empty list if nothing found.
      • setNameLengthCutoff

        public void setNameLengthCutoff​(int nameLenCutoff)
        Sets the maximum length of symbols and datatypes created during import.
        Parameters:
        nameLenCutoff - int, should not be more than SymbolUtilities.MAX_SYMBOL_NAME_LENGTH.
      • getProgramBaseAddressFixup

        public long getProgramBaseAddressFixup()
        A fixup value that needs to be applied to static addresses of the program.

        This value is necessary if the program's built-in base address is overridden at import time.

        Returns:
        long value to add to static addresses discovered in DWARF to make it agree with Ghidra's imported program.