9#ifndef LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H
33class AppleAcceleratorTable;
34class DWARFCompileUnit;
35class DWARFDebugAbbrev;
36class DWARFDebugAranges;
96 virtual std::shared_ptr<DWARFContext>
103 std::unique_ptr<DWARFDebugMacro>
112 std::unique_ptr<DWARFContextState> State;
115 unsigned MaxVersion = 0;
117 std::function<void(
Error)> RecoverableErrorHandler =
125 enum { EagerParse =
false, LazyParse =
true };
128 std::unique_ptr<const DWARFObject> DObj;
132 bool ParseCUTUIndexManually =
false;
136 std::string DWPName =
"",
137 std::function<
void(
Error)> RecoverableErrorHandler =
139 std::function<
void(
Error)> WarningHandler =
141 bool ThreadSafe =
false);
156 std::array<std::optional<uint64_t>,
DIDT_ID_Count> DumpOffsets);
159 std::array<std::optional<uint64_t>,
DIDT_ID_Count> DumpOffsets;
160 dump(
OS, DumpOpts, DumpOffsets);
172 NormalUnits.
begin() +
177 return State->getNormalUnits();
209 return State->getDWOUnits();
239 return State->getNormalUnits().getNumInfoUnits();
244 return State->getNormalUnits().getNumTypesUnits();
249 return State->getDWOUnits().getNumInfoUnits();
254 return State->getDWOUnits().getNumTypesUnits();
259 return State->getNormalUnits()[index].get();
264 return State->getDWOUnits()[index].get();
416 template <
typename... Ts>
418 std::error_code EC,
char const *Fmt,
424 Stream <<
format(Fmt, Vals...)
425 <<
" has unsupported address size: " << AddressSize
426 <<
" (supported are ";
429 Stream << LS <<
Size;
431 return make_error<StringError>(Buffer, EC);
437 return RecoverableErrorHandler;
444 static std::unique_ptr<DWARFContext>
448 std::function<
void(
Error)> RecoverableErrorHandler =
450 std::function<
void(
Error)> WarningHandler =
452 bool ThreadSafe =
false);
454 static std::unique_ptr<DWARFContext>
457 std::function<
void(
Error)> RecoverableErrorHandler =
459 std::function<
void(
Error)> WarningHandler =
461 bool ThreadSafe =
false);
496 std::vector<DILocal> &Result);
This file defines the StringMap class.
This file defines the SmallVector class.
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
DIContextKind getKind() const
A format-neutral container for inlined code description.
DWARFContextState This structure contains all member variables for DWARFContext that need to be prote...
virtual void clearLineTableForUnit(DWARFUnit *U)=0
virtual DWARFGdbIndex & getGdbIndex()=0
virtual Expected< const DWARFDebugFrame * > getEHFrame()=0
virtual const DWARFUnitIndex & getCUIndex()=0
MacroSecType
Helper enum to distinguish between macro[.dwo] and macinfo[.dwo] section.
virtual bool isThreadSafe() const =0
virtual const DWARFUnitIndex & getTUIndex()=0
virtual const DWARFDebugMacro * getDebugMacinfoDWO()=0
virtual const DWARFDebugMacro * getDebugMacroDWO()=0
virtual const DenseMap< uint64_t, DWARFTypeUnit * > & getTypeUnitMap(bool IsDWO)=0
virtual Expected< const DWARFDebugLine::LineTable * > getLineTableForUnit(DWARFUnit *U, function_ref< void(Error)> RecoverableErrHandler)=0
virtual const DWARFDebugAbbrev * getDebugAbbrevDWO()=0
virtual const DWARFDebugMacro * getDebugMacro()=0
virtual const DWARFDebugAranges * getDebugAranges()=0
virtual ~DWARFContextState()=default
virtual const AppleAcceleratorTable & getAppleNames()=0
std::unique_ptr< DWARFDebugMacro > parseMacroOrMacinfo(MacroSecType SectionType)
Parse a macro[.dwo] or macinfo[.dwo] section.
DWARFContextState(DWARFContext &DC)
virtual Expected< const DWARFDebugFrame * > getDebugFrame()=0
virtual DWARFUnitVector & getDWOUnits(bool Lazy=false)=0
virtual const DWARFDebugLoc * getDebugLoc()=0
virtual DWARFUnitVector & getNormalUnits()=0
virtual const DWARFDebugAbbrev * getDebugAbbrev()=0
virtual const DWARFDebugNames & getDebugNames()=0
virtual const AppleAcceleratorTable & getAppleTypes()=0
virtual const AppleAcceleratorTable & getAppleNamespaces()=0
virtual const DWARFDebugMacro * getDebugMacinfo()=0
virtual const AppleAcceleratorTable & getAppleObjC()=0
virtual std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)=0
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
DWARFCompileUnit * getCompileUnitForCodeAddress(uint64_t Address)
Return the compile unit which contains instruction with provided address.
uint8_t getCUAddrSize()
Get address size from CUs.
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Expected< const DWARFDebugFrame * > getDebugFrame()
Get a pointer to the parsed frame information object.
static bool isSupportedVersion(unsigned version)
Triple::ArchType getArch() const
function_ref< void(Error)> getRecoverableErrorHandler()
DWARFGdbIndex & getGdbIndex()
unsigned getNumCompileUnits()
Get the number of compile units in this context.
DWARFUnitVector::compile_unit_range compile_unit_range
static SmallVector< uint8_t, 3 > getSupportedAddressSizes()
DWARFDie getDIEForOffset(uint64_t Offset)
Get a DIE given an exact offset.
unsigned getNumTypeUnits()
Get the number of type units in this context.
DWARFUnitVector::iterator_range unit_iterator_range
static bool classof(const DIContext *DICtx)
DILineInfo getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
compile_unit_range compile_units()
Get compile units in this context.
const AppleAcceleratorTable & getAppleObjC()
Get a reference to the parsed accelerator table object.
const DWARFUnitIndex & getTUIndex()
DWARFCompileUnit * getCompileUnitForDataAddress(uint64_t Address)
Return the compile unit which contains data with the provided address.
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
DWARFUnit * getDWOUnitAtIndex(unsigned index)
Get the unit at the specified index for the DWO units.
std::vector< DILocal > getLocalsForAddress(object::SectionedAddress Address) override
DataExtractor getStringExtractor() const
void setParseCUTUIndexManually(bool PCUTU)
Sets whether CU/TU should be populated manually.
DWARFCompileUnit * getCompileUnitForOffset(uint64_t Offset)
Return the compile unit that includes an offset (relative to .debug_info).
const DWARFDebugNames & getDebugNames()
Get a reference to the parsed accelerator table object.
unsigned getNumDWOTypeUnits()
Get the number of type units in the DWO context.
const DWARFDebugMacro * getDebugMacroDWO()
Get a pointer to the parsed DebugMacroDWO information object.
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
bool isDWP() const
Return true of this DWARF context is a DWP file.
static Error checkAddressSizeSupported(unsigned AddressSize, std::error_code EC, char const *Fmt, const Ts &...Vals)
function_ref< void(Error)> getWarningHandler()
bool isLittleEndian() const
DWARFUnit * getUnitAtIndex(unsigned index)
Get the unit at the specified index.
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
DWARFContext & operator=(DWARFContext &)=delete
void clearLineTableForUnit(DWARFUnit *U)
const AppleAcceleratorTable & getAppleTypes()
Get a reference to the parsed accelerator table object.
const AppleAcceleratorTable & getAppleNames()
Get a reference to the parsed accelerator table object.
void setMaxVersionIfGreater(unsigned Version)
DWARFUnit * getUnitForOffset(uint64_t Offset)
Return the DWARF unit that includes an offset (relative to .debug_info).
compile_unit_range dwo_compile_units()
Get compile units in the DWO context.
const DWARFUnitVector & getNormalUnitsVector()
const DWARFDebugLoc * getDebugLoc()
Get a pointer to the parsed DebugLoc object.
const DWARFDebugMacro * getDebugMacinfoDWO()
Get a pointer to the parsed DebugMacinfoDWO information object.
unit_iterator_range dwo_types_section_units()
Get units from .debug_types.dwo in the DWO context.
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, std::array< std::optional< uint64_t >, DIDT_ID_Count > DumpOffsets)
Dump a textual representation to OS.
DWARFTypeUnit * getTypeUnitForHash(uint64_t Hash, bool IsDWO)
unit_iterator_range normal_units()
Get all normal compile/type units in this context.
static unsigned getMaxSupportedVersion()
unit_iterator_range types_section_units()
Get units from .debug_types in this context.
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
DWARFCompileUnit * getDWOCompileUnitForHash(uint64_t Hash)
void dump(raw_ostream &OS, DIDumpOptions DumpOpts) override
unsigned getNumDWOCompileUnits()
Get the number of compile units in the DWO context.
DWARFContext(DWARFContext &)=delete
DILineInfo getLineInfoForDataAddress(object::SectionedAddress Address) override
const DWARFDebugAranges * getDebugAranges()
Get a pointer to the parsed DebugAranges object.
const DWARFUnitIndex & getCUIndex()
Expected< const DWARFDebugFrame * > getEHFrame()
Get a pointer to the parsed eh frame information object.
DIEsForAddress getDIEsForAddress(uint64_t Address, bool CheckDWO=false)
Get the compilation unit, the function DIE and lexical block DIE for the given address where applicab...
DataExtractor getLineStringExtractor() const
unit_iterator_range info_section_units()
Get units from .debug_info in this context.
bool getParseCUTUIndexManually() const
Returns whether CU/TU should be populated manually.
unit_iterator_range dwo_info_section_units()
Get units from .debug_info..dwo in the DWO context.
DataExtractor getStringDWOExtractor() const
const AppleAcceleratorTable & getAppleNamespaces()
Get a reference to the parsed accelerator table object.
const DWARFDebugMacro * getDebugMacro()
Get a pointer to the parsed DebugMacro information object.
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, ProcessDebugRelocations RelocAction=ProcessDebugRelocations::Process, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler, bool ThreadSafe=false)
const DWARFDebugMacro * getDebugMacinfo()
Get a pointer to the parsed DebugMacinfo information object.
static bool isAddressSizeSupported(unsigned AddressSize)
const DWARFUnitVector & getDWOUnitsVector()
unit_iterator_range dwo_units()
Get all units in the DWO context.
const DWARFObject & getDWARFObj() const
unsigned getMaxDWOVersion()
.debug_names section consists of one or more units.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
virtual const object::ObjectFile * getFile() const
Describe a collection of units.
unsigned getNumInfoUnits() const
Returns number of units from all .debug_info[.dwo] sections.
llvm::iterator_range< typename UnitVector::iterator > iterator_range
decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
static void defaultWarningHandler(Error Warning)
Implement default handling for Warning.
static void defaultErrorHandler(Error Err)
Implement default handling for Error.
Stores all information relating to a compile unit, be it in its original instance in the object file ...
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This class is the base class for all object file types.
virtual Triple::ArchType getArch() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
static const bool IsLittleEndianHost
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool isCompileUnit(const std::unique_ptr< DWARFUnit > &U)
Container for dump options that control which debug information will be dumped.
Controls which fields of DILineInfo container should be filled with data.
A format-neutral container for source line information.
Wraps the returned DIEs for a given address.