summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h208
-rw-r--r--llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h13
-rw-r--r--llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h75
-rw-r--r--llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h3
-rw-r--r--llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h9
5 files changed, 113 insertions, 195 deletions
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index ee2e805050c..18908ae24fe 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -26,6 +26,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
+#include "llvm/DebugInfo/DWARF/DWARFObject.h"
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
@@ -45,10 +46,14 @@ class DataExtractor;
class MemoryBuffer;
class raw_ostream;
+/// Used as a return value for a error callback passed to DWARF context.
+/// Callback should return Halt if client application wants to stop
+/// object parsing, or should return Continue otherwise.
+enum class ErrorPolicy { Halt, Continue };
+
/// DWARFContext
/// This data structure is the top level entity that deals with dwarf debug
-/// information parsing. The actual data is supplied through pure virtual
-/// methods that a concrete implementation provides.
+/// information parsing. The actual data is supplied through DWARFObj.
class DWARFContext : public DIContext {
DWARFUnitSection<DWARFCompileUnit> CUs;
std::deque<DWARFUnitSection<DWARFTypeUnit>> TUs;
@@ -95,11 +100,17 @@ class DWARFContext : public DIContext {
/// and store them in DWOTUs.
void parseDWOTypeUnits();
+protected:
+ std::unique_ptr<const DWARFObject> DObj;
+
public:
- DWARFContext() : DIContext(CK_DWARF) {}
+ DWARFContext(std::unique_ptr<const DWARFObject> DObj)
+ : DIContext(CK_DWARF), DObj(std::move(DObj)) {}
DWARFContext(DWARFContext &) = delete;
DWARFContext &operator=(DWARFContext &) = delete;
+ const DWARFObject &getDWARFObj() const { return *DObj; }
+
static bool classof(const DIContext *DICtx) {
return DICtx->getKind() == CK_DWARF;
}
@@ -222,55 +233,24 @@ public:
DIInliningInfo getInliningInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
- virtual StringRef getFileName() const = 0;
- virtual bool isLittleEndian() const = 0;
- virtual uint8_t getAddressSize() const = 0;
- virtual const DWARFSection &getInfoSection() = 0;
- virtual void forEachTypesSections(function_ref<void(DWARFSection &)> F) = 0;
- virtual StringRef getAbbrevSection() = 0;
- virtual const DWARFSection &getLocSection() = 0;
- virtual StringRef getARangeSection() = 0;
- virtual StringRef getDebugFrameSection() = 0;
- virtual StringRef getEHFrameSection() = 0;
- virtual const DWARFSection &getLineSection() = 0;
- virtual StringRef getStringSection() = 0;
- virtual const DWARFSection& getRangeSection() = 0;
- virtual StringRef getMacinfoSection() = 0;
- virtual StringRef getPubNamesSection() = 0;
- virtual StringRef getPubTypesSection() = 0;
- virtual StringRef getGnuPubNamesSection() = 0;
- virtual StringRef getGnuPubTypesSection() = 0;
-
- /// DWARF v5
- /// @{
- virtual const DWARFSection &getStringOffsetSection() = 0;
- /// @}
-
- // Sections for DWARF5 split dwarf proposal.
- virtual const DWARFSection &getInfoDWOSection() = 0;
- virtual void
- forEachTypesDWOSections(function_ref<void(DWARFSection &)> F) = 0;
- virtual StringRef getAbbrevDWOSection() = 0;
- virtual const DWARFSection &getLineDWOSection() = 0;
- virtual const DWARFSection &getLocDWOSection() = 0;
- virtual StringRef getStringDWOSection() = 0;
- virtual const DWARFSection &getStringOffsetDWOSection() = 0;
- virtual const DWARFSection &getRangeDWOSection() = 0;
- virtual const DWARFSection &getAddrSection() = 0;
- virtual const DWARFSection& getAppleNamesSection() = 0;
- virtual const DWARFSection& getAppleTypesSection() = 0;
- virtual const DWARFSection& getAppleNamespacesSection() = 0;
- virtual const DWARFSection& getAppleObjCSection() = 0;
- virtual StringRef getCUIndexSection() = 0;
- virtual StringRef getGdbIndexSection() = 0;
- virtual StringRef getTUIndexSection() = 0;
-
+ bool isLittleEndian() const { return DObj->isLittleEndian(); }
static bool isSupportedVersion(unsigned version) {
return version == 2 || version == 3 || version == 4 || version == 5;
}
std::shared_ptr<DWARFContext> getDWOContext(StringRef AbsolutePath);
+ /// Function used to handle default error reporting policy. Prints a error
+ /// message and returns Continue, so DWARF context ignores the error.
+ static ErrorPolicy defaultErrorHandler(Error E);
+ static std::unique_ptr<DWARFContext>
+ create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
+ function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler);
+
+ static std::unique_ptr<DWARFContext>
+ create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
+ uint8_t AddrSize, bool isLittleEndian = sys::IsLittleEndianHost);
+
private:
/// Return the compile unit that includes an offset (relative to .debug_info).
DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
@@ -280,142 +260,6 @@ private:
DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
};
-/// Used as a return value for a error callback passed to DWARF context.
-/// Callback should return Halt if client application wants to stop
-/// object parsing, or should return Continue otherwise.
-enum class ErrorPolicy { Halt, Continue };
-
-/// DWARFContextInMemory is the simplest possible implementation of a
-/// DWARFContext. It assumes all content is available in memory and stores
-/// pointers to it.
-class DWARFContextInMemory : public DWARFContext {
- virtual void anchor();
-
- using TypeSectionMap = MapVector<object::SectionRef, DWARFSection,
- std::map<object::SectionRef, unsigned>>;
-
- StringRef FileName;
- bool IsLittleEndian;
- uint8_t AddressSize;
- DWARFSection InfoSection;
- TypeSectionMap TypesSections;
- StringRef AbbrevSection;
- DWARFSection LocSection;
- StringRef ARangeSection;
- StringRef DebugFrameSection;
- StringRef EHFrameSection;
- DWARFSection LineSection;
- StringRef StringSection;
- DWARFSection RangeSection;
- StringRef MacinfoSection;
- StringRef PubNamesSection;
- StringRef PubTypesSection;
- StringRef GnuPubNamesSection;
- StringRef GnuPubTypesSection;
-
- /// DWARF v5
- /// @{
- DWARFSection StringOffsetSection;
- /// @}
-
- // Sections for DWARF5 split dwarf proposal.
- DWARFSection InfoDWOSection;
- TypeSectionMap TypesDWOSections;
- StringRef AbbrevDWOSection;
- DWARFSection LineDWOSection;
- DWARFSection LocDWOSection;
- StringRef StringDWOSection;
- DWARFSection StringOffsetDWOSection;
- DWARFSection RangeDWOSection;
- DWARFSection AddrSection;
- DWARFSection AppleNamesSection;
- DWARFSection AppleTypesSection;
- DWARFSection AppleNamespacesSection;
- DWARFSection AppleObjCSection;
- StringRef CUIndexSection;
- StringRef GdbIndexSection;
- StringRef TUIndexSection;
-
- SmallVector<SmallString<32>, 4> UncompressedSections;
-
- DWARFSection *mapNameToDWARFSection(StringRef Name);
- StringRef *mapSectionToMember(StringRef Name);
-
- /// If Sec is compressed section, decompresses and updates its contents
- /// provided by Data. Otherwise leaves it unchanged.
- Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
- StringRef &Data);
-
- /// Function used to handle default error reporting policy. Prints a error
- /// message and returns Continue, so DWARF context ignores the error.
- static ErrorPolicy defaultErrorHandler(Error E);
-
-public:
- DWARFContextInMemory(
- const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
- function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler);
-
- DWARFContextInMemory(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
- uint8_t AddrSize,
- bool isLittleEndian = sys::IsLittleEndianHost);
-
- StringRef getFileName() const override { return FileName; }
- bool isLittleEndian() const override { return IsLittleEndian; }
- uint8_t getAddressSize() const override { return AddressSize; }
- const DWARFSection &getInfoSection() override { return InfoSection; }
- void forEachTypesSections(function_ref<void(DWARFSection &)> F) override {
- for (auto &P : TypesSections)
- F(P.second);
- }
- StringRef getAbbrevSection() override { return AbbrevSection; }
- const DWARFSection &getLocSection() override { return LocSection; }
- StringRef getARangeSection() override { return ARangeSection; }
- StringRef getDebugFrameSection() override { return DebugFrameSection; }
- StringRef getEHFrameSection() override { return EHFrameSection; }
- const DWARFSection &getLineSection() override { return LineSection; }
- StringRef getStringSection() override { return StringSection; }
- const DWARFSection &getRangeSection() override { return RangeSection; }
- StringRef getMacinfoSection() override { return MacinfoSection; }
- StringRef getPubNamesSection() override { return PubNamesSection; }
- StringRef getPubTypesSection() override { return PubTypesSection; }
- StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; }
- StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; }
- const DWARFSection& getAppleNamesSection() override { return AppleNamesSection; }
- const DWARFSection& getAppleTypesSection() override { return AppleTypesSection; }
- const DWARFSection& getAppleNamespacesSection() override { return AppleNamespacesSection; }
- const DWARFSection& getAppleObjCSection() override { return AppleObjCSection; }
-
- // DWARF v5
- const DWARFSection &getStringOffsetSection() override {
- return StringOffsetSection;
- }
-
- // Sections for DWARF5 split dwarf proposal.
- const DWARFSection &getInfoDWOSection() override { return InfoDWOSection; }
-
- void forEachTypesDWOSections(function_ref<void(DWARFSection &)> F) override {
- for (auto &P : TypesDWOSections)
- F(P.second);
- }
-
- StringRef getAbbrevDWOSection() override { return AbbrevDWOSection; }
- const DWARFSection &getLineDWOSection() override { return LineDWOSection; }
- const DWARFSection &getLocDWOSection() override { return LocDWOSection; }
- StringRef getStringDWOSection() override { return StringDWOSection; }
-
- const DWARFSection &getStringOffsetDWOSection() override {
- return StringOffsetDWOSection;
- }
-
- const DWARFSection &getRangeDWOSection() override { return RangeDWOSection; }
-
- const DWARFSection &getAddrSection() override { return AddrSection; }
-
- StringRef getCUIndexSection() override { return CUIndexSection; }
- StringRef getGdbIndexSection() override { return GdbIndexSection; }
- StringRef getTUIndexSection() override { return TUIndexSection; }
-};
-
} // end namespace llvm
#endif // LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
index ef4360f6662..a379d9c85b3 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
@@ -14,18 +14,21 @@
#include "llvm/Support/DataExtractor.h"
namespace llvm {
+class DWARFObject;
/// A DataExtractor (typically for an in-memory copy of an object-file section)
/// plus a relocation map for that section, if there is one.
class DWARFDataExtractor : public DataExtractor {
- const RelocAddrMap *RelocMap = nullptr;
+ const DWARFObject *Obj = nullptr;
+ const DWARFSection *Section = nullptr;
+
public:
/// Constructor for the normal case of extracting data from a DWARF section.
/// The DWARFSection's lifetime must be at least as long as the extractor's.
- DWARFDataExtractor(const DWARFSection &Section, bool IsLittleEndian,
- uint8_t AddressSize)
- : DataExtractor(Section.Data, IsLittleEndian, AddressSize),
- RelocMap(&Section.Relocs) {}
+ DWARFDataExtractor(const DWARFObject &Obj, const DWARFSection &Section,
+ bool IsLittleEndian, uint8_t AddressSize)
+ : DataExtractor(Section.Data, IsLittleEndian, AddressSize), Obj(&Obj),
+ Section(&Section) {}
/// Constructor for cases when there are no relocations.
DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
new file mode 100644
index 00000000000..5e43d8c0d4f
--- /dev/null
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
@@ -0,0 +1,75 @@
+//===- DWARFObject.h --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-----------------------------------------------------------------------===/
+
+#ifndef LLVM_DEBUGINFO_DWARF_DWARFOBJECT_H
+#define LLVM_DEBUGINFO_DWARF_DWARFOBJECT_H
+
+#include "llvm/DebugInfo/DWARF/DWARFSection.h"
+
+namespace llvm {
+// This is responsible for low level access to the object file. It
+// knows how to find the required sections and compute relocated
+// values.
+// The default implementations of the get<Section> methods return dummy values.
+// This is to allow clients that only need some of those to implement just the
+// ones they need. We can't use unreachable for as many cases because the parser
+// implementation is eager and will call some of these methods even if the
+// result is not used.
+class DWARFObject {
+ DWARFSection Dummy;
+
+public:
+ virtual ~DWARFObject() = default;
+ virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
+ virtual bool isLittleEndian() const = 0;
+ virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
+ virtual const DWARFSection &getInfoSection() const { return Dummy; }
+ virtual void
+ forEachTypesSections(function_ref<void(const DWARFSection &)> F) const {}
+ virtual StringRef getAbbrevSection() const { return ""; }
+ virtual const DWARFSection &getLocSection() const { return Dummy; }
+ virtual StringRef getARangeSection() const { return ""; }
+ virtual StringRef getDebugFrameSection() const { return ""; }
+ virtual StringRef getEHFrameSection() const { return ""; }
+ virtual const DWARFSection &getLineSection() const { return Dummy; }
+ virtual StringRef getStringSection() const { return ""; }
+ virtual const DWARFSection &getRangeSection() const { return Dummy; }
+ virtual StringRef getMacinfoSection() const { return ""; }
+ virtual StringRef getPubNamesSection() const { return ""; }
+ virtual StringRef getPubTypesSection() const { return ""; }
+ virtual StringRef getGnuPubNamesSection() const { return ""; }
+ virtual StringRef getGnuPubTypesSection() const { return ""; }
+ virtual const DWARFSection &getStringOffsetSection() const { return Dummy; }
+ virtual const DWARFSection &getInfoDWOSection() const { return Dummy; }
+ virtual void
+ forEachTypesDWOSections(function_ref<void(const DWARFSection &)> F) const {}
+ virtual StringRef getAbbrevDWOSection() const { return ""; }
+ virtual const DWARFSection &getLineDWOSection() const { return Dummy; }
+ virtual const DWARFSection &getLocDWOSection() const { return Dummy; }
+ virtual StringRef getStringDWOSection() const { return ""; }
+ virtual const DWARFSection &getStringOffsetDWOSection() const {
+ return Dummy;
+ }
+ virtual const DWARFSection &getRangeDWOSection() const { return Dummy; }
+ virtual const DWARFSection &getAddrSection() const { return Dummy; }
+ virtual const DWARFSection &getAppleNamesSection() const { return Dummy; }
+ virtual const DWARFSection &getAppleTypesSection() const { return Dummy; }
+ virtual const DWARFSection &getAppleNamespacesSection() const {
+ return Dummy;
+ }
+ virtual const DWARFSection &getAppleObjCSection() const { return Dummy; }
+ virtual StringRef getCUIndexSection() const { return ""; }
+ virtual StringRef getGdbIndexSection() const { return ""; }
+ virtual StringRef getTUIndexSection() const { return ""; }
+ virtual Optional<RelocAddrEntry> find(const DWARFSection &Sec,
+ uint64_t Pos) const = 0;
+};
+
+} // namespace llvm
+#endif
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
index 2b8a53a4c93..43df3b36809 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
@@ -17,6 +17,9 @@ namespace llvm {
struct DWARFSection {
StringRef Data;
+};
+
+struct DWARFSectionMap final : public DWARFSection {
RelocAddrMap Relocs;
};
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
index 056c1b77c65..b4e3f008f31 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -197,19 +197,12 @@ public:
bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
- DWARFDataExtractor getDebugInfoExtractor() const {
- return DWARFDataExtractor(InfoSection, isLittleEndian,
- getAddressByteSize());
- }
+ DWARFDataExtractor getDebugInfoExtractor() const;
DataExtractor getStringExtractor() const {
return DataExtractor(StringSection, false, 0);
}
- const RelocAddrMap *getRelocMap() const { return &InfoSection.Relocs; }
- const RelocAddrMap &getStringOffsetsRelocMap() const {
- return StringOffsetSection.Relocs;
- }
bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
OpenPOWER on IntegriCloud