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
Modifier and TypeFieldDescriptionprotected TreeMap
<Integer, DWARFCompilationUnit> protected List
<DWARFCompilationUnit> protected long[]
protected WeakValueHashMap
<Long, DebugInfoEntry> static final CategoryPath
static final String
protected BitSet
protected int[]
protected static final EnumSet
<DWARFAttribute> protected int[]
static final CategoryPath
-
Constructor Summary
ConstructorDescriptionDWARFProgram
(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 TypeMethodDescriptionReturns iterable that traverses allDIEAggregate
s in the program.void
close()
void
dumpDIEs
(PrintStream ps) long
getAddress
(DWARFForm form, long value, DWARFCompilationUnit cu) Returns an address value.getAddressRange
(DWARFRange range, boolean isCode) getAggregate
(long dieOffset) Returns theDIEAggregate
that contains theDebugInfoEntry
specified by the offset.Returns theDIEAggregate
that contains the specifiedDebugInfoEntry
.getChildrenOf
(int dieIndex) Returns the children of the specified DIEgetCodeAddress
(long offset) getDataAddress
(long offset) int
getDIEByOffset
(long dieOffset) Returns the specified DIE record.getDIEChildIndexes
(int dieIndex) Returns list of indexes of the children of the specified DIEgetEntryName
(DIEAggregate diea) getLine
(DIEAggregate diea, DWARFAttribute attribute) Returns the DWARFLine info pointed to by the specified attribute.getLocationList
(DIEAggregate diea, DWARFAttribute attribute) Returns theDWARFLocationList
pointed to by the specified attribute value.getName
(DIEAggregate diea) Returns aDWARFName
for aDIEAggregate
.long
getOffsetOfIndexedElement
(DWARFForm form, int index, DWARFCompilationUnit cu) Returns the raw offset of an indexed item.int
getParentDepth
(int dieIndex) Returns the depth of the specified DIE.int
getParentIndex
(int dieIndex) Returns the index of the parent of the specified DIE.getParentOf
(int dieIndex) Returns the parent DIE of the specified (by index) DIElong
A fixup value that needs to be applied to static addresses of the program.getRangeList
(DIEAggregate diea, DWARFAttribute attribute) Returns theDWARFRangeList
pointed at by the specified attribute.static DIEAggregate
Returns theDIEAggregate
of a typedef that points to the specified datatype.getString
(DWARFForm form, long offset, DWARFCompilationUnit cu) Returns a DWARF attribute string value, as specified by a form, offset/index, and the cu.int
Returns the total number ofDIEAggregate
objects in the entire program.getTypeReferers
(DIEAggregate targetDIEA, DWARFTag 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.protected void
indexDIEAggregates
(LongArrayList aggrTargets, TaskMonitor monitor) protected void
indexDIEATypeRefs
(TaskMonitor monitor) void
init
(TaskMonitor monitor) Reads and indexes available 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
void
logWarningAt
(Address addr, String addrName, String msg) void
boolean
protected void
updateSiblingIndexes
(IntArrayList siblingIndexList, IntArrayList parentIndexList, int index)
-
Field Details
-
DWARF_ROOT_NAME
- See Also:
-
DWARF_ROOT_CATPATH
-
UNCAT_CATPATH
-
REF_ATTRS
-
dieOffsets
protected long[] dieOffsets -
siblingIndexes
protected int[] siblingIndexes -
parentIndexes
protected int[] parentIndexes -
compUnitDieIndex
-
compUnits
-
indexHasRef
-
diesByOffset
-
-
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 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
-
init
Reads and indexes available DWARF information.- Parameters:
monitor
-TaskMonitor
- Throws:
IOException
- if error reading dataDWARFException
- if bad or invalid DWARF informationCancelledException
- if cancelled
-
indexDIEATypeRefs
- Throws:
CancelledException
-
indexDIEAggregates
protected void indexDIEAggregates(LongArrayList aggrTargets, TaskMonitor monitor) throws CancelledException, DWARFException - Throws:
CancelledException
DWARFException
-
updateSiblingIndexes
protected void updateSiblingIndexes(IntArrayList siblingIndexList, IntArrayList parentIndexList, int index) -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getImportOptions
-
getImportSummary
-
getGhidraProgram
-
getDwarfDTM
-
getCompilationUnits
-
isBigEndian
public boolean isBigEndian() -
isLittleEndian
public boolean isLittleEndian() -
getDebugLineBR
-
getEntryName
-
getReferringTypedef
Returns theDIEAggregate
of a typedef that points to the specified datatype.Returns null if there is no typedef pointing to the specified DIEA or if there are multiple.
- Parameters:
diea
-DIEAggregate
of a data type that might be the target of typedefs.- Returns:
DIEAggregate
of the singular typedef that points to the arg, otherwise null if none or multiple found.
-
getName
Returns aDWARFName
for aDIEAggregate
.- Parameters:
diea
-DIEAggregate
- Returns:
DWARFName
, never null
-
getParentOf
Returns the parent DIE of the specified (by index) DIE- Parameters:
dieIndex
- index of a DIE record- Returns:
- parent DIE, or null if no parent (eg. root DIE)
-
getParentIndex
public int getParentIndex(int dieIndex) Returns the index of the parent of the specified DIE.- Parameters:
dieIndex
- index of a DIE record- Returns:
- index of the parent of specified DIE, or -1 if no parent (eg. root DIE)
-
getParentDepth
public int getParentDepth(int dieIndex) Returns the depth of the specified DIE.- Parameters:
dieIndex
- index of a DIE record- Returns:
- parent/child depth of specified record, where 0 is the root DIE
-
getChildrenOf
Returns the children of the specified DIE- Parameters:
dieIndex
- index of a DIE record- Returns:
- list of DIE instances that are children of the specified DIE
-
getDIEChildIndexes
Returns list of indexes of the children of the specified DIE- Parameters:
dieIndex
- index of a DIE record- Returns:
- list of DIE indexes that are children of the specified DIE
-
getDIEByOffset
Returns the specified DIE record.- Parameters:
dieOffset
- offset of a DIE record- Returns:
DebugInfoEntry
instance, or null if invalid offset
-
dumpDIEs
-
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:
dieOffset
- offset of a DIE record- Returns:
DIEAggregate
that contains the DIE record specified, or null if bad offset.
-
getString
Returns a DWARF attribute string value, as specified by a form, offset/index, and the cu.- Parameters:
form
-DWARFForm
offset
- offset or index of the valuecu
-DWARFCompilationUnit
- Returns:
- String value, never null
- Throws:
IOException
- if invalid form or bad offset/index
-
getRangeList
Returns theDWARFRangeList
pointed at by the specified attribute.- Parameters:
diea
-DIEAggregate
attribute
- attribute id to find in the DIEA- Returns:
DWARFRangeList
, or null if attribute is not present- Throws:
IOException
- if error reading range list
-
getOffsetOfIndexedElement
public long getOffsetOfIndexedElement(DWARFForm form, int index, DWARFCompilationUnit cu) throws IOException Returns the raw offset of an indexed item. For DW_FORM_addrx values, the returned value is not fixed up with Ghidra load offset.- Parameters:
form
-DWARFForm
of the indexindex
- int index into a lookup table (seeaddressListTable
,locationListTable
,rangeListTable
,stringsOffsetTable
)cu
-DWARFCompilationUnit
- Returns:
- raw offset of indexed item
- Throws:
IOException
- if error reading index table
-
getAddress
Returns an address value.- Parameters:
form
- the format of the numeric valuevalue
- raw offset or indirect address index (depending on the DWARFForm)cu
-DWARFCompilationUnit
- Returns:
- address
- Throws:
IOException
- if error reading indirect lookup tables
-
getLocationList
public DWARFLocationList getLocationList(DIEAggregate diea, DWARFAttribute attribute) throws IOException Returns theDWARFLocationList
pointed to by the specified attribute value.- Parameters:
diea
-DIEAggregate
attribute
- attribute id that points to the location list- Returns:
DWARFLocationList
, never null- Throws:
IOException
- if specified attribute is not the correct type, or if other error reading data
-
getLine
Returns the DWARFLine info pointed to by the specified attribute.- Parameters:
diea
-DIEAggregate
attribute
- attribute id that points to the line info- Returns:
DWARFLine
, never null, seeDWARFLine.empty()
- Throws:
IOException
- if error reading line data
-
allAggregates
Returns iterable that traverses allDIEAggregate
s in the program.- Returns:
- sequence of
DIEAggregate
es
-
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.
-
getReaderForCompUnit
-
getRegisterMappings
-
getRootDNI
-
getUncategorizedRootDNI
-
getStackSpace
-
internAttributeSpec
-
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.
-
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.
-
getAddressRange
-
getCodeAddress
-
getDataAddress
-
stackGrowsNegative
public boolean stackGrowsNegative() -
getFunctionFixups
-
getDefaultIntSize
public int getDefaultIntSize() -
logWarningAt
-
setStringTable
-