blob: cda4475482dd1668530a764e481c53517bcbe152 [file] [log] [blame]
Benjamin Krameraa2f78f2011-09-13 19:42:23 +00001//===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===/
9
10#ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11#define LLVM_DEBUGINFO_DWARFCONTEXT_H
12
13#include "DWARFCompileUnit.h"
Benjamin Kramera6002fd2011-09-14 01:09:52 +000014#include "DWARFDebugAranges.h"
Eli Benderskyfd08bc12013-02-05 23:30:58 +000015#include "DWARFDebugFrame.h"
Benjamin Kramer5acab502011-09-15 02:12:05 +000016#include "DWARFDebugLine.h"
David Blaikie18e73502013-06-19 21:37:13 +000017#include "DWARFDebugLoc.h"
Alexey Samsonov034e57a2012-08-27 07:17:47 +000018#include "DWARFDebugRangeList.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000019#include "llvm/ADT/OwningPtr.h"
20#include "llvm/ADT/SmallVector.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000021#include "llvm/DebugInfo/DIContext.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000022
23namespace llvm {
24
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000025/// DWARFContext
26/// This data structure is the top level entity that deals with dwarf debug
27/// information parsing. The actual data is supplied through pure virtual
28/// methods that a concrete implementation provides.
29class DWARFContext : public DIContext {
Alexey Samsonova9debbf2013-08-23 06:56:01 +000030 SmallVector<DWARFCompileUnit *, 1> CUs;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000031 OwningPtr<DWARFDebugAbbrev> Abbrev;
David Blaikie18e73502013-06-19 21:37:13 +000032 OwningPtr<DWARFDebugLoc> Loc;
Benjamin Kramera6002fd2011-09-14 01:09:52 +000033 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramer5acab502011-09-15 02:12:05 +000034 OwningPtr<DWARFDebugLine> Line;
Eli Benderskyfd08bc12013-02-05 23:30:58 +000035 OwningPtr<DWARFDebugFrame> DebugFrame;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000036
Alexey Samsonova9debbf2013-08-23 06:56:01 +000037 SmallVector<DWARFCompileUnit *, 1> DWOCUs;
Eric Christopherda4b2192013-01-02 23:52:13 +000038 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
39
Craig Topperb1d83e82012-09-18 02:01:41 +000040 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
41 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000042
43 /// Read compile units from the debug_info section and store them in CUs.
44 void parseCompileUnits();
Eric Christopher7370b552012-11-12 21:40:38 +000045
Eric Christopherda4b2192013-01-02 23:52:13 +000046 /// Read compile units from the debug_info.dwo section and store them in
47 /// DWOCUs.
48 void parseDWOCompileUnits();
49
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000050public:
David Blaikie1b5ee5d2013-09-23 17:42:01 +000051 struct Section {
52 StringRef Data;
53 RelocAddrMap Relocs;
54 };
55
Alexey Samsonovc2e00872013-08-06 10:32:39 +000056 DWARFContext() : DIContext(CK_DWARF) {}
Alexey Samsonova9debbf2013-08-23 06:56:01 +000057 virtual ~DWARFContext();
Alexey Samsonovc2e00872013-08-06 10:32:39 +000058
59 static bool classof(const DIContext *DICtx) {
60 return DICtx->getKind() == CK_DWARF;
61 }
62
Eli Bendersky7a94daa2013-01-25 20:26:43 +000063 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
Eric Christopher7c678de2012-11-07 23:22:07 +000064
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000065 /// Get the number of compile units in this context.
66 unsigned getNumCompileUnits() {
67 if (CUs.empty())
68 parseCompileUnits();
69 return CUs.size();
70 }
Eric Christopherda4b2192013-01-02 23:52:13 +000071
72 /// Get the number of compile units in the DWO context.
73 unsigned getNumDWOCompileUnits() {
74 if (DWOCUs.empty())
75 parseDWOCompileUnits();
76 return DWOCUs.size();
77 }
78
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000079 /// Get the compile unit at the specified index for this compile unit.
80 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
81 if (CUs.empty())
82 parseCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +000083 return CUs[index];
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000084 }
85
Eric Christopherda4b2192013-01-02 23:52:13 +000086 /// Get the compile unit at the specified index for the DWO compile units.
87 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
88 if (DWOCUs.empty())
89 parseDWOCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +000090 return DWOCUs[index];
Eric Christopherda4b2192013-01-02 23:52:13 +000091 }
92
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000093 /// Get a pointer to the parsed DebugAbbrev object.
94 const DWARFDebugAbbrev *getDebugAbbrev();
95
David Blaikie18e73502013-06-19 21:37:13 +000096 /// Get a pointer to the parsed DebugLoc object.
97 const DWARFDebugLoc *getDebugLoc();
98
Eric Christopherda4b2192013-01-02 23:52:13 +000099 /// Get a pointer to the parsed dwo abbreviations object.
100 const DWARFDebugAbbrev *getDebugAbbrevDWO();
101
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000102 /// Get a pointer to the parsed DebugAranges object.
103 const DWARFDebugAranges *getDebugAranges();
104
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000105 /// Get a pointer to the parsed frame information object.
106 const DWARFDebugFrame *getDebugFrame();
107
Benjamin Kramer679e1752011-09-15 20:43:18 +0000108 /// Get a pointer to a parsed line table corresponding to a compile unit.
109 const DWARFDebugLine::LineTable *
110 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000111
Alexey Samsonov45be7932012-08-30 07:49:50 +0000112 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
113 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000114 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
115 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000116 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
117 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000118
Eric Christopher7370b552012-11-12 21:40:38 +0000119 virtual bool isLittleEndian() const = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000120 virtual uint8_t getAddressSize() const = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000121 virtual const Section &getInfoSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000122 virtual StringRef getAbbrevSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000123 virtual const Section &getLocSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000124 virtual StringRef getARangeSection() = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000125 virtual StringRef getDebugFrameSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000126 virtual const Section &getLineSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000127 virtual StringRef getStringSection() = 0;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000128 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000129 virtual StringRef getPubNamesSection() = 0;
David Blaikie404d3042013-09-19 23:01:29 +0000130 virtual StringRef getGnuPubNamesSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000131
Eric Christopherda4b2192013-01-02 23:52:13 +0000132 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000133 virtual const Section &getInfoDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000134 virtual StringRef getAbbrevDWOSection() = 0;
135 virtual StringRef getStringDWOSection() = 0;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000136 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000137 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher962c9082013-01-15 23:56:56 +0000138 virtual StringRef getAddrSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000139
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000140 static bool isSupportedVersion(unsigned version) {
Eric Christopherf7d848d2013-08-06 01:38:27 +0000141 return version == 2 || version == 3 || version == 4;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000142 }
Alexey Samsonov45be7932012-08-30 07:49:50 +0000143private:
144 /// Return the compile unit that includes an offset (relative to .debug_info).
145 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000146
Alexey Samsonov45be7932012-08-30 07:49:50 +0000147 /// Return the compile unit which contains instruction with provided
148 /// address.
149 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000150};
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000151
152/// DWARFContextInMemory is the simplest possible implementation of a
153/// DWARFContext. It assumes all content is available in memory and stores
154/// pointers to it.
155class DWARFContextInMemory : public DWARFContext {
David Blaikiea379b1812011-12-20 02:50:00 +0000156 virtual void anchor();
Eric Christopher7370b552012-11-12 21:40:38 +0000157 bool IsLittleEndian;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000158 uint8_t AddressSize;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000159 Section InfoSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000160 StringRef AbbrevSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000161 Section LocSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000162 StringRef ARangeSection;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000163 StringRef DebugFrameSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000164 Section LineSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000165 StringRef StringSection;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000166 StringRef RangeSection;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000167 StringRef PubNamesSection;
David Blaikie404d3042013-09-19 23:01:29 +0000168 StringRef GnuPubNamesSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000169
170 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000171 Section InfoDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000172 StringRef AbbrevDWOSection;
173 StringRef StringDWOSection;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000174 StringRef StringOffsetDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000175 StringRef RangeDWOSection;
Eric Christopher962c9082013-01-15 23:56:56 +0000176 StringRef AddrSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000177
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000178 SmallVector<MemoryBuffer*, 4> UncompressedSections;
179
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000180public:
Eric Christopher7370b552012-11-12 21:40:38 +0000181 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000182 ~DWARFContextInMemory();
Eric Christopher7370b552012-11-12 21:40:38 +0000183 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000184 virtual uint8_t getAddressSize() const { return AddressSize; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000185 virtual const Section &getInfoSection() { return InfoSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000186 virtual StringRef getAbbrevSection() { return AbbrevSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000187 virtual const Section &getLocSection() { return LocSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000188 virtual StringRef getARangeSection() { return ARangeSection; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000189 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000190 virtual const Section &getLineSection() { return LineSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000191 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000192 virtual StringRef getRangeSection() { return RangeSection; }
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000193 virtual StringRef getPubNamesSection() { return PubNamesSection; }
David Blaikie404d3042013-09-19 23:01:29 +0000194 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000195
196 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000197 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000198 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
199 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopher2cbd5762013-01-07 19:32:41 +0000200 virtual StringRef getStringOffsetDWOSection() {
201 return StringOffsetDWOSection;
202 }
Eric Christopherda4b2192013-01-02 23:52:13 +0000203 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher962c9082013-01-15 23:56:56 +0000204 virtual StringRef getAddrSection() {
205 return AddrSection;
206 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000207};
208
209}
210
211#endif