Class DWARFCompilationUnit
- java.lang.Object
-
- ghidra.app.util.bin.format.dwarf4.DWARFCompilationUnit
-
public class DWARFCompilationUnit extends java.lang.Object
A DWARF "CompilationUnit" is a contiguous block ofDIE
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
, andgetCompileUnit()
).DIE records are identified by their byte offset in the ".debug_info" section.
-
-
Constructor Summary
Constructors Constructor Description DWARFCompilationUnit(DWARFProgram dwarfProgram, long startOffset, long endOffset, long length, int format, short version, long abbreviationOffset, byte pointerSize, int compUnitNumber, long firstDIEOffset, java.util.Map<java.lang.Integer,DWARFAbbreviation> codeToAbbreviationMap)
This ctor is public only for junit tests.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsOffset(long offset)
Returns true if theoffset
value is within this compUnit's start and end position in the debug_info section.java.util.Map<java.lang.Integer,DWARFAbbreviation>
getCodeToAbbreviationMap()
DWARFCompileUnit
getCompileUnit()
int
getCompUnitNumber()
long
getEndOffset()
Returns the byte offset to the end of this compilation unit.long
getFirstDIEOffset()
int
getFormat()
Returns either DWARF_32 or DWARF_64 depending on the current compilation unit formatlong
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.byte
getPointerSize()
A 1-byte unsigned integer representing the size in bytes of an address on the target architecture.DWARFProgram
getProgram()
long
getStartOffset()
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(java.util.List<DebugInfoEntry> entries, TaskMonitor monitor)
Reads theDebugInfoEntry
records for this compilation unit from the .debug_info section.protected void
setCompileUnit(DWARFCompileUnit compUnit)
java.lang.String
toString()
-
-
-
Field Detail
-
DWARF_32
public static final int DWARF_32
- See Also:
- Constant Field Values
-
DWARF_64
public static final int DWARF_64
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DWARFCompilationUnit
public DWARFCompilationUnit(DWARFProgram dwarfProgram, long startOffset, long endOffset, long length, int format, short version, long abbreviationOffset, byte pointerSize, int compUnitNumber, long firstDIEOffset, java.util.Map<java.lang.Integer,DWARFAbbreviation> codeToAbbreviationMap)
This ctor is public only for junit tests. Do not use directly.- Parameters:
dwarfProgram
-startOffset
-endOffset
-length
-format
-version
-abbreviationOffset
-pointerSize
-compUnitNumber
-firstDIEOffset
-codeToAbbreviationMap
-
-
-
Method Detail
-
readCompilationUnit
public static DWARFCompilationUnit readCompilationUnit(DWARFProgram dwarfProgram, BinaryReader debugInfoBR, BinaryReader debugAbbrBR, int cuNumber, TaskMonitor monitor) throws DWARFException, java.io.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.
- Parameters:
debugInfoBR
-debugAbbrBR
-cuNumber
-helper
-monitor
-- Returns:
- Throws:
DWARFException
java.io.IOException
CancelledException
-
getCompileUnit
public DWARFCompileUnit getCompileUnit()
-
setCompileUnit
protected void setCompileUnit(DWARFCompileUnit compUnit)
-
getProgram
public DWARFProgram 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCodeToAbbreviationMap
public java.util.Map<java.lang.Integer,DWARFAbbreviation> getCodeToAbbreviationMap()
-
getFirstDIEOffset
public long getFirstDIEOffset()
-
getCompUnitNumber
public int getCompUnitNumber()
-
readDIEs
public void readDIEs(java.util.List<DebugInfoEntry> entries, TaskMonitor monitor) throws java.io.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:
java.io.IOException
- if error reading dataDWARFException
- if error in DWARF structureCancelledException
- if user cancels.
-
-