Class DWARFCompilationUnit
java.lang.Object
ghidra.app.util.bin.format.dwarf4.DWARFCompilationUnit
A DWARF "CompilationUnit" is a contiguous block of
DIE
records found
in a ".debug_info" section of an ELF program. The compilation unit block starts with a
header that has a few important values and flags, and is followed by the DIE records.
The first DIE record must be a DW_TAG_compile_unit (see DWARFCompileUnit
,
and getCompileUnit()
).
DIE records are identified by their byte offset in the ".debug_info" section.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDWARFCompilationUnit
(DWARFProgram dwarfProgram, long startOffset, long endOffset, long length, int format, short version, long abbreviationOffset, byte pointerSize, int compUnitNumber, long firstDIEOffset, Map<Integer, DWARFAbbreviation> codeToAbbreviationMap) This ctor is public only for junit tests. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsOffset
(long offset) Returns true if theoffset
value is within this compUnit's start and end position in the debug_info section.int
long
Returns the byte offset to the end of this compilation unit.long
int
Returns either DWARF_32 or DWARF_64 depending on the current compilation unit formatlong
An unsigned long (4 bytes in 32-bit or 8 bytes in 64-bit format) representing the length of the .debug_info contribution for that compilation unit, not including the length field itself.byte
A 1-byte unsigned integer representing the size in bytes of an address on the target architecture.long
Returns the byte offset to the start of this compilation unit.static DWARFCompilationUnit
readCompilationUnit
(DWARFProgram dwarfProgram, BinaryReader debugInfoBR, BinaryReader debugAbbrBR, int cuNumber, TaskMonitor monitor) Creates a newDWARFCompilationUnit
by reading a compilationUnit's header data from the debug_info section and the debug_abbr section and its compileUnit DIE (ie.void
readDIEs
(List<DebugInfoEntry> entries, TaskMonitor monitor) Reads theDebugInfoEntry
records for this compilation unit from the .debug_info section.protected void
setCompileUnit
(DWARFCompileUnit compUnit) toString()
-
Field Details
-
DWARF_32
public static final int DWARF_32- See Also:
-
DWARF_64
public static final int DWARF_64- See Also:
-
-
Constructor Details
-
DWARFCompilationUnit
public DWARFCompilationUnit(DWARFProgram dwarfProgram, long startOffset, long endOffset, long length, int format, short version, long abbreviationOffset, byte pointerSize, int compUnitNumber, long firstDIEOffset, Map<Integer, DWARFAbbreviation> codeToAbbreviationMap) This ctor is public only for junit tests. Do not use directly.- Parameters:
dwarfProgram
-DWARFProgram
startOffset
- offset in provider where it startsendOffset
- offset in provider where it endslength
- how many bytes following the header the DIEs of this unit takeformat
- DWARF_32 or DWARF_64version
- 2, 3, 4abbreviationOffset
- offset into abbrev sectionpointerSize
- default size of pointerscompUnitNumber
- this compunits ordinal in the filefirstDIEOffset
- start of DIEs in the providercodeToAbbreviationMap
- map of abbreviation numbers toDWARFAbbreviation
instances
-
-
Method Details
-
readCompilationUnit
public static DWARFCompilationUnit readCompilationUnit(DWARFProgram dwarfProgram, BinaryReader debugInfoBR, BinaryReader debugAbbrBR, int cuNumber, TaskMonitor monitor) throws DWARFException, IOException, CancelledException Creates a newDWARFCompilationUnit
by reading a compilationUnit's header data from the debug_info section and the debug_abbr section and its compileUnit DIE (ie. the first DIE right after the header).Returns
NULL
if there was an ignorable error while reading the compilation unit (and leaves the input stream at the next compilation unit to read), otherwise throws an IOException if there was an unrecoverable error.Also returns
NULL
(and leaves the stream at EOF) if the remainder of the stream is filled with null bytes.- Parameters:
dwarfProgram
- the dwarf program.debugInfoBR
- the debug info binary reader.debugAbbrBR
- the debug abbreviation binary readercuNumber
- the compilation unit numbermonitor
- the current task monitor- Returns:
- the read compilation unit, or null if the compilation unit was bad/empty and should be ignored
- Throws:
DWARFException
- if an invalid or unsupported DWARF version is read.IOException
- if the length of the compilation unit is invalid.CancelledException
- if the task has been canceled.
-
getCompileUnit
-
setCompileUnit
-
getProgram
-
getLength
public long getLength()An unsigned long (4 bytes in 32-bit or 8 bytes in 64-bit format) representing the length of the .debug_info contribution for that compilation unit, not including the length field itself.- Returns:
- the length in bytes of the this compilation unit
-
getPointerSize
public byte getPointerSize()A 1-byte unsigned integer representing the size in bytes of an address on the target architecture. If the system uses segmented addressing, this value represents the size of the offset portion of an address.- Returns:
- the size in bytes of pointers
-
getStartOffset
public long getStartOffset()Returns the byte offset to the start of this compilation unit.- Returns:
- the byte offset to the start of this compilation unit
-
getEndOffset
public long getEndOffset()Returns the byte offset to the end of this compilation unit.- Returns:
- the byte offset to the end of this compilation unit
-
getFormat
public int getFormat()Returns either DWARF_32 or DWARF_64 depending on the current compilation unit format- Returns:
- DWARF_32 or DWARF_64 constant depending on the current compilation unit format
-
containsOffset
public boolean containsOffset(long offset) Returns true if theoffset
value is within this compUnit's start and end position in the debug_info section.- Parameters:
offset
- DIE offset- Returns:
- true if within range of this compunit
-
toString
-
getCodeToAbbreviationMap
-
getFirstDIEOffset
public long getFirstDIEOffset() -
getCompUnitNumber
public int getCompUnitNumber() -
readDIEs
public void readDIEs(List<DebugInfoEntry> entries, TaskMonitor monitor) throws IOException, DWARFException, CancelledException Reads theDebugInfoEntry
records for this compilation unit from the .debug_info section.- Parameters:
entries
- List of DIE records that is written to by this method. This list should be empty if the caller only wants this CU's records (ie. normal mode), or the list can be used to accumulate all DIE records (preload all DIE mode).monitor
-TaskMonitor
to watch for cancelation- Throws:
IOException
- if error reading dataDWARFException
- if error in DWARF structureCancelledException
- if user cancels.
-