1 //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===/
10 #ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11 #define LLVM_DEBUGINFO_DWARFCONTEXT_H
13 #include "DWARFCompileUnit.h"
14 #include "DWARFDebugAranges.h"
15 #include "DWARFDebugLine.h"
16 #include "DWARFDebugRangeList.h"
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/DebugInfo/DIContext.h"
24 /// This data structure is the top level entity that deals with dwarf debug
25 /// information parsing. The actual data is supplied through pure virtual
26 /// methods that a concrete implementation provides.
27 class DWARFContext : public DIContext {
28 SmallVector<DWARFCompileUnit, 1> CUs;
29 OwningPtr<DWARFDebugAbbrev> Abbrev;
30 OwningPtr<DWARFDebugAranges> Aranges;
31 OwningPtr<DWARFDebugLine> Line;
33 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
34 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
36 /// Read compile units from the debug_info section and store them in CUs.
37 void parseCompileUnits();
41 virtual void dump(raw_ostream &OS);
43 /// Get the number of compile units in this context.
44 unsigned getNumCompileUnits() {
49 /// Get the compile unit at the specified index for this compile unit.
50 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
56 /// Get a pointer to the parsed DebugAbbrev object.
57 const DWARFDebugAbbrev *getDebugAbbrev();
59 /// Get a pointer to the parsed DebugAranges object.
60 const DWARFDebugAranges *getDebugAranges();
62 /// Get a pointer to a parsed line table corresponding to a compile unit.
63 const DWARFDebugLine::LineTable *
64 getLineTableForCompileUnit(DWARFCompileUnit *cu);
66 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
67 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
68 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
69 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
71 virtual bool isLittleEndian() const = 0;
72 virtual const RelocAddrMap &relocMap() const = 0;
73 virtual StringRef getInfoSection() = 0;
74 virtual StringRef getAbbrevSection() = 0;
75 virtual StringRef getARangeSection() = 0;
76 virtual StringRef getLineSection() = 0;
77 virtual StringRef getStringSection() = 0;
78 virtual StringRef getRangeSection() = 0;
80 static bool isSupportedVersion(unsigned version) {
81 return version == 2 || version == 3;
84 /// Return the compile unit that includes an offset (relative to .debug_info).
85 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
87 /// Return the compile unit which contains instruction with provided
89 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
92 /// DWARFContextInMemory is the simplest possible implementation of a
93 /// DWARFContext. It assumes all content is available in memory and stores
95 class DWARFContextInMemory : public DWARFContext {
96 virtual void anchor();
98 RelocAddrMap RelocMap;
99 StringRef InfoSection;
100 StringRef AbbrevSection;
101 StringRef ARangeSection;
102 StringRef LineSection;
103 StringRef StringSection;
104 StringRef RangeSection;
106 DWARFContextInMemory(object::ObjectFile *);
107 virtual bool isLittleEndian() const { return IsLittleEndian; }
108 virtual const RelocAddrMap &relocMap() const { return RelocMap; }
109 virtual StringRef getInfoSection() { return InfoSection; }
110 virtual StringRef getAbbrevSection() { return AbbrevSection; }
111 virtual StringRef getARangeSection() { return ARangeSection; }
112 virtual StringRef getLineSection() { return LineSection; }
113 virtual StringRef getStringSection() { return StringSection; }
114 virtual StringRef getRangeSection() { return RangeSection; }