Class DWARFProgram

java.lang.Object
ghidra.app.util.bin.format.dwarf.DWARFProgram
All Implemented Interfaces:
Closeable, AutoCloseable

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

    • DWARF_ROOT_NAME

      public static final String DWARF_ROOT_NAME
      See Also:
    • DWARF_ROOT_CATPATH

      public static final CategoryPath DWARF_ROOT_CATPATH
    • UNCAT_CATPATH

      public static final CategoryPath UNCAT_CATPATH
    • DWARF_BOOKMARK_CAT

      public static final String DWARF_BOOKMARK_CAT
      See Also:
    • REF_ATTRS MODIFIED

      protected static final EnumSet<DWARFAttributeId> REF_ATTRS
      type: EnumSet → EnumSet
      -static java.util.EnumSet<ghidra.app.util.bin.format.dwarf.attribs.DWARFAttribute> REF_ATTRS
      +static java.util.EnumSet<ghidra.app.util.bin.format.dwarf.attribs.DWARFAttributeId> REF_ATTRS
    • programBaseAddressFixup

      protected long programBaseAddressFixup
    • dieContainer NEW

      protected DIEContainer dieContainer
  • Constructor Details

  • Method Details

    • isDWARF

      public static boolean isDWARF(Program program)
      Returns true if the program probably has DWARF information, without doing all the work that querying all registered DWARFSectionProviders would take.

      If the program is an Elf binary, it must have (at least) ".debug_info" and ".debug_abbr", program sections, or their compressed "z" versions, or ExternalDebugInfo that would point to an external DWARF file.

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

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

      public static boolean hasDWARFData(Program program, TaskMonitor monitor)
      Returns true if the specified program has DWARF information.

      This is similar to isDWARF(Program), but is a stronger check that is more expensive as it could involve searching for external files.

      Parameters:
      program - Program to test
      monitor - TaskMonitor that can be used to cancel
      Returns:
      boolean true if the program has DWARF info, false if not
    • getDIEContainer NEW

      public DIEContainer getDIEContainer()
    • init

      public void init(TaskMonitor monitor) throws IOException, DWARFException, CancelledException
      Reads and indexes available DWARF information.
      Parameters:
      monitor - TaskMonitor
      Throws:
      IOException - if error reading data
      DWARFException - if bad or invalid DWARF information
      CancelledException - if cancelled
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getImportOptions

      public DWARFImportOptions getImportOptions()
    • getImportSummary

      public DWARFImportSummary getImportSummary()
    • getGhidraProgram

      public Program getGhidraProgram()
    • getDwarfDTM

      public DWARFDataTypeManager getDwarfDTM()
    • getCompilationUnits

      public List<DWARFCompilationUnit> getCompilationUnits()
    • isBigEndian

      public boolean isBigEndian()
    • isLittleEndian

      public boolean isLittleEndian()
    • getSectionProvider NEW

      public DWARFSectionProvider getSectionProvider()
    • getEntryName

      public String getEntryName(DIEAggregate diea)
    • getName

      public DWARFName getName(DIEAggregate diea)
      Returns a DWARFName for a DIEAggregate.
      Parameters:
      diea - DIEAggregate
      Returns:
      DWARFName, never null
    • getCharset

      public Charset getCharset()
      Returns charset to use when decoding debug strings.
      Returns:
      charset to use when decoding debug strings
    • allAggregates

      public Iterable<DIEAggregate> allAggregates()
      Returns iterable that traverses all DIEAggregates in the program.
      Returns:
      sequence of DIEAggregatees
    • 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.
    • getRegisterMappings

      public DWARFRegisterMappings getRegisterMappings()
    • getRootDNI

      public DWARFName getRootDNI()
    • getUncategorizedRootDNI

      public DWARFName getUncategorizedRootDNI()
    • getStackSpace

      public AddressSpace getStackSpace()
    • 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.
    • setProgramBaseAddressFixup NEW

      public void setProgramBaseAddressFixup(long programBaseAddressFixup)
    • getAddressRange

      public AddressRange getAddressRange(DWARFRange range, boolean isCode)
    • getCodeAddress

      public Address getCodeAddress(long offset)
    • getDataAddress

      public Address getDataAddress(long offset)
    • isZeroDataAddress NEW

      public boolean isZeroDataAddress(Address addr)
    • stackGrowsNegative

      public boolean stackGrowsNegative()
    • getFunctionFixups

      public List<DWARFFunctionFixup> getFunctionFixups()
    • getDefaultIntSize

      public int getDefaultIntSize()
    • logWarningAt

      public void logWarningAt(Address addr, String addrName, String msg)