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 TypeFieldDescriptionprotected TreeMap<Integer, DWARFCompilationUnit> protected List<DWARFCompilationUnit> protected long[]protected WeakValueHashMap<Long, DebugInfoEntry> static final Stringstatic final CategoryPathstatic final Stringprotected BitSetprotected int[]protected static final EnumSet<DWARFAttribute> protected 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 TypeMethodDescriptionReturns iterable that traverses allDIEAggregates in the program.voidclose()voiddumpDIEs(PrintStream ps) longgetAddress(DWARFForm form, long value, DWARFCompilationUnit cu) Returns an address value.getAddressRange(DWARFRange range, boolean isCode) getAggregate(long dieOffset) Returns theDIEAggregatethat contains theDebugInfoEntryspecified by the offset.Returns theDIEAggregatethat contains the specifiedDebugInfoEntry.getChildrenOf(int dieIndex) Returns the children of the specified DIEgetCodeAddress(long offset) getDataAddress(long offset) intgetDIEByOffset(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 theDWARFLocationListpointed to by the specified attribute value.getName(DIEAggregate diea) Returns aDWARFNamefor aDIEAggregate.longgetOffsetOfIndexedElement(DWARFForm form, int index, DWARFCompilationUnit cu) Returns the raw offset of an indexed item.intgetParentDepth(int dieIndex) Returns the depth of the specified DIE.intgetParentIndex(int dieIndex) Returns the index of the parent of the specified DIE.getParentOf(int dieIndex) Returns the parent DIE of the specified (by index) DIElongA fixup value that needs to be applied to static addresses of the program.getRangeList(DIEAggregate diea, DWARFAttribute attribute) Returns theDWARFRangeListpointed at by the specified attribute.static DIEAggregateReturns theDIEAggregateof 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.intReturns the total number ofDIEAggregateobjects in the entire program.getTypeReferers(DIEAggregate targetDIEA, DWARFTag tag) Returns a list ofDIEAggregates that refer to the targetDIEA via an attribute of the specified tag type.static booleanhasDWARFData(Program program, TaskMonitor monitor) Returns true if the specifiedprogramhas DWARF information.protected voidindexDIEAggregates(LongArrayList aggrTargets, TaskMonitor monitor) protected voidindexDIEATypeRefs(TaskMonitor monitor) voidinit(TaskMonitor monitor) Reads and indexes available DWARF information.booleanstatic booleanReturns true if theprogramprobably has DWARF information, without doing all the work that querying all registered DWARFSectionProviders would take.booleanvoidlogWarningAt(Address addr, String addrName, String msg) voidbooleanprotected voidupdateSiblingIndexes(IntArrayList siblingIndexList, IntArrayList parentIndexList, int index)
-
Field Details
-
DWARF_ROOT_NAME
- See Also:
-
DWARF_ROOT_CATPATH
-
UNCAT_CATPATH
-
DWARF_BOOKMARK_CAT
- See Also:
-
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-DWARFImportOptionsto controls options during reading / parsing /importing.monitor-TaskMonitorto 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-DWARFImportOptionsto controls options during reading / parsing /importing.monitor-TaskMonitorto control canceling and progress.sectionProvider-DWARFSectionProviderfactory 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 theprogramprobably 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-Programto test- Returns:
- boolean true if program probably has DWARF info, false if not
-
hasDWARFData
Returns true if the specifiedprogramhas 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-Programto testmonitor-TaskMonitorthat 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:
CancelledExceptionDWARFException
-
updateSiblingIndexes
protected void updateSiblingIndexes(IntArrayList siblingIndexList, IntArrayList parentIndexList, int index) -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getImportOptions
-
getImportSummary
-
getGhidraProgram
-
getDwarfDTM
-
getCompilationUnits
-
isBigEndian
public boolean isBigEndian() -
isLittleEndian
public boolean isLittleEndian() -
getDebugLineBR
-
getEntryName
-
getReferringTypedef
Returns theDIEAggregateof 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-DIEAggregateof a data type that might be the target of typedefs.- Returns:
DIEAggregateof the singular typedef that points to the arg, otherwise null if none or multiple found.
-
getName
Returns aDWARFNamefor 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:
DebugInfoEntryinstance, or null if invalid offset
-
dumpDIEs
-
getAggregate
Returns theDIEAggregatethat contains the specifiedDebugInfoEntry.- Parameters:
die-DebugInfoEntryor null- Returns:
DIEAggregatethat contains the specified DIE, or null if DIE null or the aggregate was not found.
-
getAggregate
Returns theDIEAggregatethat contains theDebugInfoEntryspecified by the offset.- Parameters:
dieOffset- offset of a DIE record- Returns:
DIEAggregatethat 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-DWARFFormoffset- offset or index of the valuecu-DWARFCompilationUnit- Returns:
- String value, never null
- Throws:
IOException- if invalid form or bad offset/index
-
getRangeList
Returns theDWARFRangeListpointed at by the specified attribute.- Parameters:
diea-DIEAggregateattribute- 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-DWARFFormof 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 theDWARFLocationListpointed to by the specified attribute value.- Parameters:
diea-DIEAggregateattribute- 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-DIEAggregateattribute- 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 allDIEAggregates in the program.- Returns:
- sequence of
DIEAggregatees
-
getTotalAggregateCount
public int getTotalAggregateCount()Returns the total number ofDIEAggregateobjects in the entire program.- Returns:
- the total number of
DIEAggregateobjects in the entire program.
-
getReaderForCompUnit
-
getRegisterMappings
-
getRootDNI
-
getUncategorizedRootDNI
-
getStackSpace
-
internAttributeSpec
-
getTypeReferers
Returns a list ofDIEAggregates that refer to the targetDIEA via an attribute of the specified tag type.- Parameters:
targetDIEA-DIEAggregatethat might be pointed to by other DIEAs.tag- theDWARFTagattribute 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
-