Class DWARFProgram
- java.lang.Object
-
- ghidra.app.util.bin.format.dwarf4.next.DWARFProgram
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class DWARFProgram extends java.lang.Object implements java.io.CloseableDWARFProgram encapsulates aGhidra programwith DWARF specific reference data used byDWARFDataTypeImporterandDWARFFunctionImporter, along with some helper functions.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_NAME_LENGTH_CUTOFFstatic java.lang.StringDWARF_ROOT_NAMEstatic intMAX_NAME_LENGTH_CUTOFFstatic intMIN_NAME_LENGTH_CUTOFF
-
Constructor Summary
Constructors Constructor Description DWARFProgram(Program program, DWARFImportOptions importOptions, TaskMonitor monitor)Main constructor for DWARFProgram.DWARFProgram(Program program, DWARFImportOptions importOptions, TaskMonitor monitor, DWARFSectionProvider sectionProvider)Constructor for DWARFProgram.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanalreadyDWARFImported(Program prog)voidcacheDNIByOffset(long offset, DWARFNameInfo dni)voidcheckPreconditions(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.voidclearDIEIndexes()Releases the memory used by the DIE entries read by#readDIEs().voidclose()DIEAggregategetAggregate(long offset)Returns theDIEAggregatethat contains theDebugInfoEntryspecified by the offset.DIEAggregategetAggregate(DebugInfoEntry die)Returns theDIEAggregatethat contains the specifiedDebugInfoEntry.java.util.List<DIEAggregate>getAggregates()Returns the list of all currently loadedDIEAggregates, which will be either just the DIEA of the current CU, or all DIEA ifDWARFImportOptions.isPreloadAllDIEs().DWARFAttributeFactorygetAttributeFactory()DWARFCompilationUnitgetCompilationUnitFor(long offset)java.util.List<DWARFCompilationUnit>getCompilationUnits()BinaryReadergetDebugInfo()BinaryReadergetDebugLine()BinaryReadergetDebugLocation()ByteProvidergetDebugRanges()StringTablegetDebugStrings()intgetDIECount()Returns the count of the DIE records in this compilation unit.java.util.List<DebugInfoEntry>getEntries()DebugInfoEntrygetEntryAtByteOffsetUnchecked(long byteOffset)Returns the entry with the given byte offset.java.lang.StringgetEntryName(DIEAggregate diea)booleangetFoundCrossCURefs()ProgramgetGhidraProgram()DWARFImportOptionsgetImportOptions()DWARFNameInfogetName(DIEAggregate diea)longgetProgramBaseAddressFixup()A fixup value that needs to be applied to static addresses of the program.DWARFRegisterMappingsgetRegisterMappings()DWARFNameInfogetRootDNI()intgetTotalAggregateCount()Returns the total number ofDIEAggregateobjects in the entire program.intgetTotalDIECount()Returns the total number of DIE records in the entire program.java.util.List<DIEAggregate>getTypeReferers(DIEAggregate targetDIEA, int tag)Returns a list ofDIEAggregates that refer to the targetDIEA via an attribute of the specified tag type.DWARFNameInfogetUncategorizedRootDNI()DWARFAttributeSpecificationinternAttributeSpec(DWARFAttributeSpecification das)booleanisBigEndian()static booleanisDWARF(Program program, TaskMonitor monitor)Returns true if theprogramprobably DWARF information.booleanisLittleEndian()DWARFNameInfolookupDNIByOffset(long offset)voidsetAttributeFactory(DWARFAttributeFactory attributeFactory)voidsetCurrentCompilationUnit(DWARFCompilationUnit cu, TaskMonitor monitor)Sets the currently active compilation unit.voidsetFoundCrossCURefs(boolean b)voidsetNameLengthCutoff(int nameLenCutoff)Sets the maximum length of symbols and datatypes created during import.
-
-
-
Field Detail
-
DWARF_ROOT_NAME
public static final java.lang.String DWARF_ROOT_NAME
- See Also:
- Constant Field Values
-
DEFAULT_NAME_LENGTH_CUTOFF
public static final int DEFAULT_NAME_LENGTH_CUTOFF
- See Also:
- Constant Field Values
-
MAX_NAME_LENGTH_CUTOFF
public static final int MAX_NAME_LENGTH_CUTOFF
- See Also:
- Constant Field Values
-
MIN_NAME_LENGTH_CUTOFF
public static final int MIN_NAME_LENGTH_CUTOFF
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DWARFProgram
public DWARFProgram(Program program, DWARFImportOptions importOptions, TaskMonitor monitor) throws CancelledException, java.io.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 cancelsjava.io.IOException- if error reading dataDWARFException- if bad stuff happens.
-
DWARFProgram
public DWARFProgram(Program program, DWARFImportOptions importOptions, TaskMonitor monitor, DWARFSectionProvider sectionProvider) throws CancelledException, java.io.IOException, DWARFException
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 cancelsjava.io.IOException- if error reading dataDWARFException- if bad stuff happens.
-
-
Method Detail
-
alreadyDWARFImported
public static boolean alreadyDWARFImported(Program prog)
-
isDWARF
public static boolean isDWARF(Program program, TaskMonitor monitor)
Returns true if theprogramprobably 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-monitor-- Returns:
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
getImportOptions
public DWARFImportOptions getImportOptions()
-
getGhidraProgram
public Program getGhidraProgram()
-
isBigEndian
public boolean isBigEndian()
-
isLittleEndian
public boolean isLittleEndian()
-
getEntryName
public java.lang.String getEntryName(DIEAggregate diea)
-
getName
public DWARFNameInfo getName(DIEAggregate diea)
-
lookupDNIByOffset
public DWARFNameInfo lookupDNIByOffset(long offset)
-
cacheDNIByOffset
public void cacheDNIByOffset(long offset, DWARFNameInfo dni)
-
getAggregate
public DIEAggregate getAggregate(DebugInfoEntry die)
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
public DIEAggregate getAggregate(long offset)
Returns theDIEAggregatethat contains theDebugInfoEntryspecified by the offset.- Parameters:
offset- offset of a DIE record- Returns:
DIEAggregatethat contains the DIE record specified, or null if bad offset.
-
getAggregates
public java.util.List<DIEAggregate> getAggregates()
Returns the list of all currently loadedDIEAggregates, 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 ofDIEAggregateobjects in the entire program.- Returns:
- the total number of
DIEAggregateobjects in the entire program.
-
setCurrentCompilationUnit
public void setCurrentCompilationUnit(DWARFCompilationUnit cu, TaskMonitor monitor) throws CancelledException, java.io.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-DWARFCompilationUnitto set as the active element and load it's DIE records.monitor-TaskMonitorto update with status and check for cancelation.- Throws:
CancelledException- if user cancelsjava.io.IOException- if error reading dataDWARFException- if error in DWARF record structure
-
getCompilationUnits
public java.util.List<DWARFCompilationUnit> getCompilationUnits()
-
getCompilationUnitFor
public DWARFCompilationUnit getCompilationUnitFor(long offset)
-
getDebugLocation
public BinaryReader getDebugLocation()
-
getDebugRanges
public ByteProvider getDebugRanges()
-
getDebugInfo
public BinaryReader getDebugInfo()
-
getDebugLine
public BinaryReader getDebugLine()
-
getRegisterMappings
public DWARFRegisterMappings getRegisterMappings()
-
getRootDNI
public DWARFNameInfo getRootDNI()
-
getUncategorizedRootDNI
public DWARFNameInfo getUncategorizedRootDNI()
-
getDebugStrings
public StringTable getDebugStrings()
-
getAttributeFactory
public DWARFAttributeFactory getAttributeFactory()
-
setAttributeFactory
public void setAttributeFactory(DWARFAttributeFactory attributeFactory)
-
getFoundCrossCURefs
public boolean getFoundCrossCURefs()
-
setFoundCrossCURefs
public void setFoundCrossCURefs(boolean b)
-
internAttributeSpec
public DWARFAttributeSpecification internAttributeSpec(DWARFAttributeSpecification das)
-
getEntries
public java.util.List<DebugInfoEntry> getEntries()
- Returns:
- the entries list
-
getDIECount
public int getDIECount() throws java.io.IOException, CancelledExceptionReturns the count of the DIE records in this compilation unit.Only valid if called after
#readDIEs()and before#clearEntries().- Returns:
- number of DIE records in the compunit.
- Throws:
java.io.IOExceptionCancelledException
-
clearDIEIndexes
public void clearDIEIndexes()
Releases the memory used by the DIE entries read by#readDIEs().
-
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 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.
-
checkPreconditions
public void checkPreconditions(TaskMonitor monitor) throws DWARFPreconditionException, DWARFException, CancelledException, java.io.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-TaskMonitorto check for cancel and upate with status.- Throws:
DWARFException- if DWARF structure error.CancelledException- if user cancels.java.io.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.
-
-