Class DWARFProgram
- All Implemented Interfaces:
Closeable
,AutoCloseable
Ghidra program
with DWARF specific reference data
used by DWARFDataTypeImporter
and DWARFFunctionImporter
, along with some
helper functions.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final CategoryPath
static final String
static final int
static final int
static final CategoryPath
-
Constructor Summary
ConstructorsConstructorDescriptionDWARFProgram
(Program program, DWARFImportOptions importOptions, TaskMonitor monitor) Main constructor for DWARFProgram.DWARFProgram
(Program program, DWARFImportOptions importOptions, TaskMonitor monitor, DWARFSectionProvider sectionProvider) Constructor for DWARFProgram. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cacheDNIByOffset
(long offset, DWARFNameInfo dni) void
checkPreconditions
(TaskMonitor monitor) Iterates over all the DWARF DIE records in the program and checks for some pre-known issues, throwing an exception if there is a problem that would prevent a successful run.void
Releases the memory used by the DIE entries read when invokingcheckPreconditions(TaskMonitor)
.void
close()
getAggregate
(long offset) Returns theDIEAggregate
that contains theDebugInfoEntry
specified by the offset.Returns theDIEAggregate
that contains the specifiedDebugInfoEntry
.Returns the list of all currently loadedDIEAggregate
s, which will be either just the DIEA of the current CU, or all DIEA ifDWARFImportOptions.isPreloadAllDIEs()
.getCodeAddress
(Number offset) getCompilationUnitFor
(long offset) getDataAddress
(Number offset) int
Returns the count of the DIE records in this compilation unit.getEntryAtByteOffsetUnchecked
(long byteOffset) Returns the entry with the given byte offset.getEntryName
(DIEAggregate diea) boolean
getName
(DIEAggregate diea) long
A fixup value that needs to be applied to static addresses of the program.int
Returns the total number ofDIEAggregate
objects in the entire program.int
Returns the total number of DIE records in the entire program.getTypeReferers
(DIEAggregate targetDIEA, int tag) Returns a list ofDIEAggregate
s that refer to the targetDIEA via an attribute of the specified tag type.static boolean
hasDWARFData
(Program program, TaskMonitor monitor) Returns true if the specifiedprogram
has DWARF information.boolean
static boolean
Returns true if theprogram
probably has DWARF information, without doing all the work that querying all registered DWARFSectionProviders would take.boolean
lookupDNIByOffset
(long offset) void
setAttributeFactory
(DWARFAttributeFactory attributeFactory) void
setCurrentCompilationUnit
(DWARFCompilationUnit cu, TaskMonitor monitor) Sets the currently active compilation unit.void
setFoundCrossCURefs
(boolean b) void
setNameLengthCutoff
(int nameLenCutoff) Sets the maximum length of symbols and datatypes created during import.boolean
-
Field Details
-
DWARF_ROOT_NAME
- See Also:
-
DWARF_ROOT_CATPATH
-
UNCAT_CATPATH
-
DEFAULT_NAME_LENGTH_CUTOFF
public static final int DEFAULT_NAME_LENGTH_CUTOFF- See Also:
-
MAX_NAME_LENGTH_CUTOFF
public static final int MAX_NAME_LENGTH_CUTOFF- See Also:
-
MIN_NAME_LENGTH_CUTOFF
public static final int MIN_NAME_LENGTH_CUTOFF- See Also:
-
-
Constructor Details
-
DWARFProgram
public DWARFProgram(Program program, DWARFImportOptions importOptions, TaskMonitor monitor) throws CancelledException, IOException, DWARFException Main constructor for DWARFProgram.Auto-detects the DWARFSectionProvider and chains to the next constructor.
- Parameters:
program
- GhidraProgram
.importOptions
-DWARFImportOptions
to controls options during reading / parsing /importing.monitor
-TaskMonitor
to control canceling and progress.- Throws:
CancelledException
- if user cancelsIOException
- if error reading dataDWARFException
- if bad stuff happens.
-
DWARFProgram
public DWARFProgram(Program program, DWARFImportOptions importOptions, TaskMonitor monitor, DWARFSectionProvider sectionProvider) throws CancelledException, IOException, DWARFException Constructor for DWARFProgram.- Parameters:
program
- GhidraProgram
.importOptions
-DWARFImportOptions
to controls options during reading / parsing /importing.monitor
-TaskMonitor
to control canceling and progress.sectionProvider
-DWARFSectionProvider
factory that finds DWARF .debug_* sections wherever they live.- Throws:
CancelledException
- if user cancelsIOException
- if error reading dataDWARFException
- if bad stuff happens.
-
-
Method Details
-
isDWARF
Returns true if theprogram
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
Returns true if the specifiedprogram
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 testmonitor
-TaskMonitor
that can be used to cancel- Returns:
- boolean true if the program has DWARF info, false if not
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getImportOptions
-
getImportSummary
-
getGhidraProgram
-
getDwarfDTM
-
isBigEndian
public boolean isBigEndian() -
isLittleEndian
public boolean isLittleEndian() -
getEntryName
-
getName
-
lookupDNIByOffset
-
cacheDNIByOffset
-
getAggregate
Returns theDIEAggregate
that contains the specifiedDebugInfoEntry
.- Parameters:
die
-DebugInfoEntry
or null- Returns:
DIEAggregate
that contains the specified DIE, or null if DIE null or the aggregate was not found.
-
getAggregate
Returns theDIEAggregate
that contains theDebugInfoEntry
specified by the offset.- Parameters:
offset
- offset of a DIE record- Returns:
DIEAggregate
that contains the DIE record specified, or null if bad offset.
-
getAggregates
Returns the list of all currently loadedDIEAggregate
s, which will be either just the DIEA of the current CU, or all DIEA ifDWARFImportOptions.isPreloadAllDIEs()
.- Returns:
- List of
DIEAggregate
.
-
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 ofDIEAggregate
objects in the entire program.- Returns:
- the total number of
DIEAggregate
objects in the entire program.
-
setCurrentCompilationUnit
public void setCurrentCompilationUnit(DWARFCompilationUnit cu, TaskMonitor monitor) throws CancelledException, IOException, DWARFException Sets the currently active compilation unit. Used when 'paging' through the DIE records in a compilation-unit-at-a-time manner, vs theDWARFImportOptions.isPreloadAllDIEs()
where all DIE/DIEA records are loaded at once.- Parameters:
cu
-DWARFCompilationUnit
to set as the active element and load it's DIE records.monitor
-TaskMonitor
to update with status and check for cancelation.- Throws:
CancelledException
- if user cancelsIOException
- if error reading dataDWARFException
- if error in DWARF record structure
-
getCompilationUnits
-
getCompilationUnitFor
-
getDebugLocation
-
getDebugRanges
-
getDebugInfo
-
getDebugLine
-
getRegisterMappings
-
getRootDNI
-
getUncategorizedRootDNI
-
getDebugStrings
-
getStackSpace
-
getAttributeFactory
-
setAttributeFactory
-
getFoundCrossCURefs
public boolean getFoundCrossCURefs() -
setFoundCrossCURefs
public void setFoundCrossCURefs(boolean b) -
internAttributeSpec
-
getEntries
- Returns:
- the entries list
-
getDIECount
Returns the count of the DIE records in this compilation unit.Only valid if called after
checkPreconditions(TaskMonitor)
and beforeclearDIEIndexes()
.- Returns:
- number of DIE records in the compunit.
- Throws:
IOException
CancelledException
-
clearDIEIndexes
public void clearDIEIndexes()Releases the memory used by the DIE entries read when invokingcheckPreconditions(TaskMonitor)
. -
getEntryAtByteOffsetUnchecked
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
Returns a list ofDIEAggregate
s 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
- theDWARFTag
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.
-
checkPreconditions
public void checkPreconditions(TaskMonitor monitor) throws DWARFPreconditionException, DWARFException, CancelledException, IOException Iterates over all the DWARF DIE records in the program and checks for some pre-known issues, throwing an exception if there is a problem that would prevent a successful run.- Parameters:
monitor
-TaskMonitor
to check for cancel and upate with status.- Throws:
DWARFException
- if DWARF structure error.CancelledException
- if user cancels.IOException
- if error reading data.DWARFPreconditionException
-
setNameLengthCutoff
public void setNameLengthCutoff(int nameLenCutoff) Sets the maximum length of symbols and datatypes created during import.- Parameters:
nameLenCutoff
- int, should not be more thanSymbolUtilities.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.
-
getCodeAddress
-
getDataAddress
-
stackGrowsNegative
public boolean stackGrowsNegative() -
getFunctionFixups
-