#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAddr.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
#include "llvm/DebugInfo/DWARF/DWARFListTable.h"
#include "llvm/DebugInfo/DWARF/DWARFLocationExpression.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
#include "llvm/DebugInfo/DWARF/DWARFVerifier.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/Decompressor.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/RelocationResolver.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstdint>
#include <deque>
#include <map>
#include <string>
#include <utility>
#include <vector>
usingnamespacellvm;
usingnamespacedwarf;
usingnamespaceobject;
#define DEBUG_TYPE …
DWARFLineTable;
FileLineInfoKind;
FunctionNameKind;
void fixupIndexV4(DWARFContext &C, DWARFUnitIndex &Index) { … }
void fixupIndexV5(DWARFContext &C, DWARFUnitIndex &Index) { … }
void fixupIndex(DWARFContext &C, DWARFUnitIndex &Index) { … }
template <typename T>
static T &getAccelTable(std::unique_ptr<T> &Cache, const DWARFObject &Obj,
const DWARFSection &Section, StringRef StringSection,
bool IsLittleEndian) { … }
std::unique_ptr<DWARFDebugMacro>
DWARFContext::DWARFContextState::parseMacroOrMacinfo(MacroSecType SectionType) { … }
namespace {
class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState { … };
class ThreadSafeState : public ThreadUnsafeDWARFContextState { … };
}
DWARFContext::DWARFContext(std::unique_ptr<const DWARFObject> DObj,
std::string DWPName,
std::function<void(Error)> RecoverableErrorHandler,
std::function<void(Error)> WarningHandler,
bool ThreadSafe)
: … { … }
DWARFContext::~DWARFContext() = default;
static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) { … }
ContributionCollection;
static ContributionCollection
collectContributionData(DWARFContext::unit_iterator_range Units) { … }
static void dumpStringOffsetsSection(raw_ostream &OS, DIDumpOptions DumpOpts,
StringRef SectionName,
const DWARFObject &Obj,
const DWARFSection &StringOffsetsSection,
StringRef StringSection,
DWARFContext::unit_iterator_range Units,
bool LittleEndian) { … }
static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData,
DIDumpOptions DumpOpts, uint16_t Version,
uint8_t AddrSize) { … }
static void dumpRnglistsSection(
raw_ostream &OS, DWARFDataExtractor &rnglistData,
llvm::function_ref<std::optional<object::SectionedAddress>(uint32_t)>
LookupPooledAddress,
DIDumpOptions DumpOpts) { … }
static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts,
DWARFDataExtractor Data, const DWARFObject &Obj,
std::optional<uint64_t> DumpOffset) { … }
static void dumpPubTableSection(raw_ostream &OS, DIDumpOptions DumpOpts,
DWARFDataExtractor Data, bool GnuStyle) { … }
void DWARFContext::dump(
raw_ostream &OS, DIDumpOptions DumpOpts,
std::array<std::optional<uint64_t>, DIDT_ID_Count> DumpOffsets) { … }
DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version, uint64_t Hash,
bool IsDWO) { … }
DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) { … }
DWARFDie DWARFContext::getDIEForOffset(uint64_t Offset) { … }
bool DWARFContext::verify(raw_ostream &OS, DIDumpOptions DumpOpts) { … }
const DWARFUnitIndex &DWARFContext::getCUIndex() { … }
const DWARFUnitIndex &DWARFContext::getTUIndex() { … }
DWARFGdbIndex &DWARFContext::getGdbIndex() { … }
const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() { … }
const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() { … }
const DWARFDebugLoc *DWARFContext::getDebugLoc() { … }
const DWARFDebugAranges *DWARFContext::getDebugAranges() { … }
Expected<const DWARFDebugFrame *> DWARFContext::getDebugFrame() { … }
Expected<const DWARFDebugFrame *> DWARFContext::getEHFrame() { … }
const DWARFDebugMacro *DWARFContext::getDebugMacro() { … }
const DWARFDebugMacro *DWARFContext::getDebugMacroDWO() { … }
const DWARFDebugMacro *DWARFContext::getDebugMacinfo() { … }
const DWARFDebugMacro *DWARFContext::getDebugMacinfoDWO() { … }
const DWARFDebugNames &DWARFContext::getDebugNames() { … }
const AppleAcceleratorTable &DWARFContext::getAppleNames() { … }
const AppleAcceleratorTable &DWARFContext::getAppleTypes() { … }
const AppleAcceleratorTable &DWARFContext::getAppleNamespaces() { … }
const AppleAcceleratorTable &DWARFContext::getAppleObjC() { … }
const DWARFDebugLine::LineTable *
DWARFContext::getLineTableForUnit(DWARFUnit *U) { … }
Expected<const DWARFDebugLine::LineTable *> DWARFContext::getLineTableForUnit(
DWARFUnit *U, function_ref<void(Error)> RecoverableErrorHandler) { … }
void DWARFContext::clearLineTableForUnit(DWARFUnit *U) { … }
DWARFUnitVector &DWARFContext::getDWOUnits(bool Lazy) { … }
DWARFUnit *DWARFContext::getUnitForOffset(uint64_t Offset) { … }
DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint64_t Offset) { … }
DWARFCompileUnit *DWARFContext::getCompileUnitForCodeAddress(uint64_t Address) { … }
DWARFCompileUnit *DWARFContext::getCompileUnitForDataAddress(uint64_t Address) { … }
DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address,
bool CheckDWO) { … }
static bool getFunctionNameAndStartLineForAddress(
DWARFCompileUnit *CU, uint64_t Address, FunctionNameKind Kind,
DILineInfoSpecifier::FileLineInfoKind FileNameKind,
std::string &FunctionName, std::string &StartFile, uint32_t &StartLine,
std::optional<uint64_t> &StartAddress) { … }
static std::optional<int64_t>
getExpressionFrameOffset(ArrayRef<uint8_t> Expr,
std::optional<unsigned> FrameBaseReg) { … }
void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
DWARFDie Die, std::vector<DILocal> &Result) { … }
std::vector<DILocal>
DWARFContext::getLocalsForAddress(object::SectionedAddress Address) { … }
DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Spec) { … }
DILineInfo
DWARFContext::getLineInfoForDataAddress(object::SectionedAddress Address) { … }
DILineInfoTable DWARFContext::getLineInfoForAddressRange(
object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Spec) { … }
DIInliningInfo
DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Spec) { … }
std::shared_ptr<DWARFContext>
DWARFContext::getDWOContext(StringRef AbsolutePath) { … }
static Error createError(const Twine &Reason, llvm::Error E) { … }
struct SymInfo { … };
static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj,
const RelocationRef &Reloc,
const LoadedObjectInfo *L,
std::map<SymbolRef, SymInfo> &Cache) { … }
static bool isRelocScattered(const object::ObjectFile &Obj,
const RelocationRef &Reloc) { … }
namespace {
struct DWARFSectionMap final : public DWARFSection { … };
class DWARFObjInMemory final : public DWARFObject { … };
}
std::unique_ptr<DWARFContext>
DWARFContext::create(const object::ObjectFile &Obj,
ProcessDebugRelocations RelocAction,
const LoadedObjectInfo *L, std::string DWPName,
std::function<void(Error)> RecoverableErrorHandler,
std::function<void(Error)> WarningHandler,
bool ThreadSafe) { … }
std::unique_ptr<DWARFContext>
DWARFContext::create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
uint8_t AddrSize, bool isLittleEndian,
std::function<void(Error)> RecoverableErrorHandler,
std::function<void(Error)> WarningHandler,
bool ThreadSafe) { … }
uint8_t DWARFContext::getCUAddrSize() { … }