9#ifndef LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H
31class AppleAcceleratorTable;
32class DWARFCompileUnit;
33class DWARFDebugAbbrev;
34class DWARFDebugAranges;
48 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> NormalTypeUnits;
49 std::unique_ptr<DWARFUnitIndex> CUIndex;
50 std::unique_ptr<DWARFGdbIndex> GdbIndex;
51 std::unique_ptr<DWARFUnitIndex> TUIndex;
52 std::unique_ptr<DWARFDebugAbbrev> Abbrev;
53 std::unique_ptr<DWARFDebugLoc> Loc;
54 std::unique_ptr<DWARFDebugAranges> Aranges;
55 std::unique_ptr<DWARFDebugLine> Line;
56 std::unique_ptr<DWARFDebugFrame> DebugFrame;
57 std::unique_ptr<DWARFDebugFrame> EHFrame;
58 std::unique_ptr<DWARFDebugMacro> Macro;
59 std::unique_ptr<DWARFDebugMacro> Macinfo;
60 std::unique_ptr<DWARFDebugNames> Names;
61 std::unique_ptr<AppleAcceleratorTable> AppleNames;
62 std::unique_ptr<AppleAcceleratorTable> AppleTypes;
63 std::unique_ptr<AppleAcceleratorTable> AppleNamespaces;
64 std::unique_ptr<AppleAcceleratorTable> AppleObjC;
67 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> DWOTypeUnits;
68 std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
69 std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
70 std::unique_ptr<DWARFDebugMacro> MacroDWO;
73 unsigned MaxVersion = 0;
77 std::unique_ptr<DWARFContext>
Context;
80 std::weak_ptr<DWOFile> DWP;
81 bool CheckedForDWP =
false;
83 std::function<void(
Error)> RecoverableErrorHandler =
90 void parseNormalUnits();
96 enum { EagerParse =
false, LazyParse =
true };
97 void parseDWOUnits(
bool Lazy =
false);
99 std::unique_ptr<const DWARFObject> DObj;
112 bool ParseCUTUIndexManually =
false;
116 std::string DWPName =
"",
117 std::function<
void(
Error)> RecoverableErrorHandler =
119 std::function<
void(
Error)> WarningHandler =
135 std::array<std::optional<uint64_t>,
DIDT_ID_Count> DumpOffsets);
138 std::array<std::optional<uint64_t>,
DIDT_ID_Count> DumpOffsets;
139 dump(
OS, DumpOpts, DumpOffsets);
151 NormalUnits.
begin() +
242 return NormalUnits[index].get();
248 return DWOUnits[index].get();
273 if (Version > MaxVersion)
274 MaxVersion = Version;
391 template <
typename... Ts>
393 std::error_code EC,
char const *Fmt,
399 Stream <<
format(Fmt, Vals...)
400 <<
" has unsupported address size: " << AddressSize
401 <<
" (supported are ";
404 Stream << LS <<
Size;
406 return make_error<StringError>(Stream.
str(), EC);
412 return RecoverableErrorHandler;
419 static std::unique_ptr<DWARFContext>
423 std::function<
void(
Error)> RecoverableErrorHandler =
425 std::function<
void(
Error)> WarningHandler =
428 static std::unique_ptr<DWARFContext>
431 std::function<
void(
Error)> RecoverableErrorHandler =
433 std::function<
void(
Error)> WarningHandler =
469 std::unique_ptr<DWARFDebugMacro>
470 parseMacroOrMacinfo(MacroSecType SectionType);
473 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...
Stores all information relating to a compile unit, be it in its original instance in the object file ...
DIContextKind getKind() const
A format-neutral container for inlined code description.
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.
DIEsForAddress getDIEsForAddress(uint64_t Address)
Get the compilation unit, the function DIE and lexical block DIE for the given address where applicab...
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.
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)
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
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)
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.
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.
DataExtractor getLineStringExtractor() const
unit_iterator_range info_section_units()
Get units from .debug_info in this context.
DWARFTypeUnit * getTypeUnitForHash(uint16_t Version, uint64_t Hash, bool IsDWO)
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.
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.
unsigned getNumTypesUnits() const
Returns number of units from all .debug_types[.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.
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.
std::string & str()
Returns the string's reference.
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.