blob: a9e52e674a430ff193509a3cc3280d19349f7436 [file] [log] [blame]
David Blaikie319a05f2013-12-02 19:33:10 +00001//===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
Devang Patel5eb43192011-04-12 17:40:32 +00002//
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// This file contains support for writing dwarf compile unit.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15#define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
16
17#include "DIE.h"
Eric Christopher9e429ae2013-10-05 00:27:02 +000018#include "DwarfDebug.h"
Devang Patel5eb43192011-04-12 17:40:32 +000019#include "llvm/ADT/DenseMap.h"
David Blaikief2443192013-10-21 17:28:37 +000020#include "llvm/ADT/Optional.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000021#include "llvm/ADT/StringMap.h"
Adrian Prantl702bf5a2014-03-18 02:34:52 +000022#include "llvm/CodeGen/AsmPrinter.h"
Chandler Carruth12664a02014-03-06 00:22:06 +000023#include "llvm/IR/DIBuilder.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000024#include "llvm/IR/DebugInfo.h"
David Blaikief3cd7c52013-06-28 20:05:04 +000025#include "llvm/MC/MCExpr.h"
David Blaikie7d734602013-12-06 22:33:05 +000026#include "llvm/MC/MCSection.h"
David Blaikie4a2f95f2014-03-18 01:17:26 +000027#include "llvm/MC/MCDwarf.h"
Devang Patel5eb43192011-04-12 17:40:32 +000028
29namespace llvm {
30
Devang Patelf20c4f72011-04-12 22:53:02 +000031class MachineLocation;
32class MachineOperand;
33class ConstantInt;
David Blaikiea39a76e2013-01-20 01:18:01 +000034class ConstantFP;
Devang Patelf20c4f72011-04-12 22:53:02 +000035class DbgVariable;
David Blaikie15632ae2014-02-12 00:31:30 +000036class DwarfCompileUnit;
Devang Patelf20c4f72011-04-12 22:53:02 +000037
Eric Christopher0f63d062013-12-03 00:45:45 +000038// Data structure to hold a range for range lists.
39class RangeSpan {
40public:
41 RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
Eric Christopher270ba4a2013-12-04 19:06:58 +000042 const MCSymbol *getStart() const { return Start; }
43 const MCSymbol *getEnd() const { return End; }
Eric Christopher384f3fe2014-03-20 19:16:16 +000044 void setEnd(const MCSymbol *E) { End = E; }
Eric Christopher0f63d062013-12-03 00:45:45 +000045
46private:
47 const MCSymbol *Start, *End;
48};
49
50class RangeSpanList {
51private:
52 // Index for locating within the debug_range section this particular span.
Eric Christopherf8790642013-12-04 22:04:50 +000053 MCSymbol *RangeSym;
Eric Christopher0f63d062013-12-03 00:45:45 +000054 // List of ranges.
55 SmallVector<RangeSpan, 2> Ranges;
56
57public:
Eric Christopherf8790642013-12-04 22:04:50 +000058 RangeSpanList(MCSymbol *Sym) : RangeSym(Sym) {}
59 MCSymbol *getSym() const { return RangeSym; }
Eric Christopher0f63d062013-12-03 00:45:45 +000060 const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
61 void addRange(RangeSpan Range) { Ranges.push_back(Range); }
62};
63
Devang Patel5eb43192011-04-12 17:40:32 +000064//===----------------------------------------------------------------------===//
David Blaikie319a05f2013-12-02 19:33:10 +000065/// Unit - This dwarf writer support class manages information associated
Devang Patel5eb43192011-04-12 17:40:32 +000066/// with a source file.
Eric Christophera5a79422013-12-09 23:32:48 +000067class DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +000068protected:
Eli Benderskyb42d1462012-12-03 18:45:45 +000069 /// UniqueID - a numeric ID unique among all CUs in the module
Eli Benderskyb42d1462012-12-03 18:45:45 +000070 unsigned UniqueID;
Devang Patel5eb43192011-04-12 17:40:32 +000071
David Blaikie7480ae62014-01-09 03:03:27 +000072 /// Node - MDNode for the compile unit.
David Blaikief645f962014-01-09 03:23:41 +000073 DICompileUnit CUNode;
David Blaikie7480ae62014-01-09 03:03:27 +000074
David Blaikie2a80e442013-12-02 22:09:48 +000075 /// Unit debug information entry.
Ahmed Charles56440fd2014-03-06 05:51:42 +000076 const std::unique_ptr<DIE> UnitDie;
Devang Patel5eb43192011-04-12 17:40:32 +000077
David Blaikie2a80e442013-12-02 22:09:48 +000078 /// Offset of the UnitDie from beginning of debug info section.
Eric Christophera16725b2013-11-21 01:29:16 +000079 unsigned DebugInfoOffset;
80
Devang Patelf20c4f72011-04-12 22:53:02 +000081 /// Asm - Target of Dwarf emission.
82 AsmPrinter *Asm;
83
Eric Christophere698f532012-12-20 21:58:36 +000084 // Holders for some common dwarf information.
Devang Patelf20c4f72011-04-12 22:53:02 +000085 DwarfDebug *DD;
Eric Christopherf8194852013-12-05 18:06:10 +000086 DwarfFile *DU;
Devang Patelf20c4f72011-04-12 22:53:02 +000087
David Blaikie2a80e442013-12-02 22:09:48 +000088 /// IndexTyDie - An anonymous type for index type. Owned by UnitDie.
Devang Patel5eb43192011-04-12 17:40:32 +000089 DIE *IndexTyDie;
90
Eric Christopher61560112013-05-08 00:11:10 +000091 /// MDNodeToDieMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000092 /// variables to debug information entries.
93 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
94
Eric Christopher61560112013-05-08 00:11:10 +000095 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information
Devang Patel5eb43192011-04-12 17:40:32 +000096 /// descriptors to debug information entries using a DIEEntry proxy.
97 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
98
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +000099 /// GlobalNames - A map of globally visible named entities for this unit.
Eric Christopher0fe676a2013-11-21 00:48:22 +0000100 StringMap<const DIE *> GlobalNames;
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000101
Devang Patel5eb43192011-04-12 17:40:32 +0000102 /// GlobalTypes - A map of globally visible types for this unit.
Eric Christopher0fe676a2013-11-21 00:48:22 +0000103 StringMap<const DIE *> GlobalTypes;
Devang Patel5eb43192011-04-12 17:40:32 +0000104
Eric Christopher4996c702011-11-07 09:24:32 +0000105 /// AccelNames - A map of names for the name accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000106 StringMap<std::vector<const DIE *> > AccelNames;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000107
108 /// AccelObjC - A map of objc spec for the objc accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000109 StringMap<std::vector<const DIE *> > AccelObjC;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000110
111 /// AccelNamespace - A map of names for the namespace accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000112 StringMap<std::vector<const DIE *> > AccelNamespace;
Eric Christopher4affe8c2013-11-21 01:29:13 +0000113
114 /// AccelTypes - A map of names for the type accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000115 StringMap<std::vector<std::pair<const DIE *, unsigned> > > AccelTypes;
Eric Christopher4996c702011-11-07 09:24:32 +0000116
Devang Patelf20c4f72011-04-12 22:53:02 +0000117 /// DIEBlocks - A list of all the DIEBlocks in use.
118 std::vector<DIEBlock *> DIEBlocks;
Eric Christopher4a741042014-02-16 08:46:55 +0000119
120 /// DIELocs - A list of all the DIELocs in use.
121 std::vector<DIELoc *> DIELocs;
Devang Patelf20c4f72011-04-12 22:53:02 +0000122
Devang Patel89543712011-08-15 17:24:54 +0000123 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
124 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
125 /// corresponds to the MDNode mapped with the subprogram DIE.
126 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
127
Eric Christopher46e23432013-12-20 04:16:18 +0000128 // List of ranges for a given compile unit.
129 SmallVector<RangeSpan, 1> CURanges;
130
Eric Christopher0f63d062013-12-03 00:45:45 +0000131 // List of range lists for a given compile unit, separate from the ranges for
132 // the CU itself.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000133 SmallVector<RangeSpanList, 1> CURangeLists;
Eric Christopher0f63d062013-12-03 00:45:45 +0000134
Eric Christopher3264a482013-10-05 00:39:55 +0000135 // DIEValueAllocator - All DIEValues are allocated through this allocator.
136 BumpPtrAllocator DIEValueAllocator;
137
138 // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
139 DIEInteger *DIEIntegerOne;
140
David Blaikie03073f72013-12-06 22:14:48 +0000141 /// The section this unit will be emitted in.
142 const MCSection *Section;
143
144 /// A label at the start of the non-dwo section related to this unit.
145 MCSymbol *SectionSym;
146
David Blaikie7d734602013-12-06 22:33:05 +0000147 /// The start of the unit within its section.
148 MCSymbol *LabelBegin;
149
150 /// The end of the unit within its section.
151 MCSymbol *LabelEnd;
152
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000153 /// The label for the start of the range sets for the elements of this unit.
154 MCSymbol *LabelRange;
155
Eric Christopherd8667202013-12-30 17:22:27 +0000156 /// Skeleton unit associated with this unit.
157 DwarfUnit *Skeleton;
158
David Blaikie7480ae62014-01-09 03:03:27 +0000159 DwarfUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,
160 DwarfDebug *DW, DwarfFile *DWU);
David Blaikie319a05f2013-12-02 19:33:10 +0000161
Devang Patel5eb43192011-04-12 17:40:32 +0000162public:
Eric Christophera5a79422013-12-09 23:32:48 +0000163 virtual ~DwarfUnit();
Devang Patel5eb43192011-04-12 17:40:32 +0000164
Eric Christopherd8667202013-12-30 17:22:27 +0000165 /// Set the skeleton unit associated with this unit.
166 void setSkeleton(DwarfUnit *Skel) { Skeleton = Skel; }
167
168 /// Get the skeleton unit associated with this unit.
169 DwarfUnit *getSkeleton() const { return Skeleton; }
170
David Blaikie03073f72013-12-06 22:14:48 +0000171 /// Pass in the SectionSym even though we could recreate it in every compile
172 /// unit (type units will have actually distinct symbols once they're in
173 /// comdat sections).
174 void initSection(const MCSection *Section, MCSymbol *SectionSym) {
175 assert(!this->Section);
176 this->Section = Section;
177 this->SectionSym = SectionSym;
David Blaikie7d734602013-12-06 22:33:05 +0000178 this->LabelBegin =
179 Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
180 this->LabelEnd =
181 Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000182 this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID());
David Blaikie03073f72013-12-06 22:14:48 +0000183 }
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000184
David Blaikie03073f72013-12-06 22:14:48 +0000185 const MCSection *getSection() const {
186 assert(Section);
187 return Section;
188 }
189
Eric Christopherd8667202013-12-30 17:22:27 +0000190 /// If there's a skeleton then return the section symbol for the skeleton
191 /// unit, otherwise return the section symbol for this unit.
192 MCSymbol *getLocalSectionSym() const {
193 if (Skeleton)
194 return Skeleton->getSectionSym();
Eric Christopherd4368fd2014-01-02 21:03:28 +0000195 return getSectionSym();
Eric Christopherd8667202013-12-30 17:22:27 +0000196 }
197
David Blaikie7d734602013-12-06 22:33:05 +0000198 MCSymbol *getSectionSym() const {
David Blaikie03073f72013-12-06 22:14:48 +0000199 assert(Section);
200 return SectionSym;
201 }
202
Eric Christopherd8667202013-12-30 17:22:27 +0000203 /// If there's a skeleton then return the begin label for the skeleton unit,
204 /// otherwise return the local label for this unit.
205 MCSymbol *getLocalLabelBegin() const {
206 if (Skeleton)
207 return Skeleton->getLabelBegin();
Eric Christopherd4368fd2014-01-02 21:03:28 +0000208 return getLabelBegin();
Eric Christopherd8667202013-12-30 17:22:27 +0000209 }
210
David Blaikie7d734602013-12-06 22:33:05 +0000211 MCSymbol *getLabelBegin() const {
212 assert(Section);
213 return LabelBegin;
214 }
215
216 MCSymbol *getLabelEnd() const {
217 assert(Section);
218 return LabelEnd;
219 }
220
David Blaikie1ab7c2d2013-12-09 17:51:30 +0000221 MCSymbol *getLabelRange() const {
222 assert(Section);
223 return LabelRange;
224 }
225
Devang Patel5eb43192011-04-12 17:40:32 +0000226 // Accessors.
Eric Christopherca68bbf2013-08-26 23:58:22 +0000227 unsigned getUniqueID() const { return UniqueID; }
David Blaikief645f962014-01-09 03:23:41 +0000228 uint16_t getLanguage() const { return CUNode.getLanguage(); }
229 DICompileUnit getCUNode() const { return CUNode; }
David Blaikie2a80e442013-12-02 22:09:48 +0000230 DIE *getUnitDie() const { return UnitDie.get(); }
Eric Christopher0fe676a2013-11-21 00:48:22 +0000231 const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
232 const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
Devang Patel5eb43192011-04-12 17:40:32 +0000233
David Blaikie2ea848b2013-11-19 22:51:04 +0000234 const StringMap<std::vector<const DIE *> > &getAccelNames() const {
Eric Christopherd9843b32011-11-10 19:25:34 +0000235 return AccelNames;
236 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000237 const StringMap<std::vector<const DIE *> > &getAccelObjC() const {
Eric Christopher4996c702011-11-07 09:24:32 +0000238 return AccelObjC;
239 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000240 const StringMap<std::vector<const DIE *> > &getAccelNamespace() const {
Eric Christopher66b37db2011-11-10 21:47:55 +0000241 return AccelNamespace;
242 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000243 const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &
Eric Christopherca68bbf2013-08-26 23:58:22 +0000244 getAccelTypes() const {
Eric Christopher66b37db2011-11-10 21:47:55 +0000245 return AccelTypes;
246 }
Eric Christopher48fef592012-12-20 21:58:40 +0000247
Manman Rence20d462013-10-29 22:57:10 +0000248 unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
249 void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
250
Devang Patel5eb43192011-04-12 17:40:32 +0000251 /// hasContent - Return true if this compile unit has something to write out.
David Blaikie2a80e442013-12-02 22:09:48 +0000252 bool hasContent() const { return !UnitDie->getChildren().empty(); }
Devang Patel5eb43192011-04-12 17:40:32 +0000253
Eric Christopher46e23432013-12-20 04:16:18 +0000254 /// addRange - Add an address range to the list of ranges for this unit.
Eric Christopher384f3fe2014-03-20 19:16:16 +0000255 void addRange(RangeSpan Range);
Eric Christopher46e23432013-12-20 04:16:18 +0000256
257 /// getRanges - Get the list of ranges for this unit.
258 const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
259 SmallVectorImpl<RangeSpan> &getRanges() { return CURanges; }
260
Eric Christopher0f63d062013-12-03 00:45:45 +0000261 /// addRangeList - Add an address range list to the list of range lists.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000262 void addRangeList(RangeSpanList Ranges) { CURangeLists.push_back(Ranges); }
Eric Christopher0f63d062013-12-03 00:45:45 +0000263
264 /// getRangeLists - Get the vector of range lists.
Eric Christopher270ba4a2013-12-04 19:06:58 +0000265 const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
Eric Christopher0f63d062013-12-03 00:45:45 +0000266 return CURangeLists;
267 }
Eric Christopher270ba4a2013-12-04 19:06:58 +0000268 SmallVectorImpl<RangeSpanList> &getRangeLists() { return CURangeLists; }
Eric Christopher0f63d062013-12-03 00:45:45 +0000269
Eric Christopher2c8b7902013-10-17 02:06:06 +0000270 /// getParentContextString - Get a string containing the language specific
271 /// context for a global name.
272 std::string getParentContextString(DIScope Context) const;
273
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000274 /// addGlobalName - Add a new global entity to the compile unit.
275 ///
Eric Christopher2c8b7902013-10-17 02:06:06 +0000276 void addGlobalName(StringRef Name, DIE *Die, DIScope Context);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000277
Eric Christopher4996c702011-11-07 09:24:32 +0000278 /// addAccelName - Add a new name to the name accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000279 void addAccelName(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000280
281 /// addAccelObjC - Add a new name to the ObjC accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000282 void addAccelObjC(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000283
284 /// addAccelNamespace - Add a new name to the namespace accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000285 void addAccelNamespace(StringRef Name, const DIE *Die);
Eric Christopher9cd26af2013-09-20 23:22:52 +0000286
287 /// addAccelType - Add a new type to the type accelerator table.
David Blaikie2ea848b2013-11-19 22:51:04 +0000288 void addAccelType(StringRef Name, std::pair<const DIE *, unsigned> Die);
Eric Christopher48fef592012-12-20 21:58:40 +0000289
Devang Patel5eb43192011-04-12 17:40:32 +0000290 /// getDIE - Returns the debug information entry map slot for the
Manman Ren4dbdc902013-10-31 17:54:35 +0000291 /// specified debug variable. We delegate the request to DwarfDebug
292 /// when the MDNode can be part of the type system, since DIEs for
293 /// the type system can be shared across CUs and the mappings are
294 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000295 DIE *getDIE(DIDescriptor D) const;
Devang Patel5eb43192011-04-12 17:40:32 +0000296
Eric Christopher4a741042014-02-16 08:46:55 +0000297 /// getDIELoc - Returns a fresh newly allocated DIELoc.
298 DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc(); }
Devang Patelf20c4f72011-04-12 22:53:02 +0000299
Manman Ren4dbdc902013-10-31 17:54:35 +0000300 /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
301 /// when the MDNode can be part of the type system, since DIEs for
302 /// the type system can be shared across CUs and the mappings are
303 /// kept in DwarfDebug.
David Blaikie2ad00162013-11-15 23:09:13 +0000304 void insertDIE(DIDescriptor Desc, DIE *D);
Devang Patel5eb43192011-04-12 17:40:32 +0000305
Devang Patel5eb43192011-04-12 17:40:32 +0000306 /// addDie - Adds or interns the DIE to the compile unit.
307 ///
David Blaikie2a80e442013-12-02 22:09:48 +0000308 void addDie(DIE *Buffer) { UnitDie->addChild(Buffer); }
Devang Patel5eb43192011-04-12 17:40:32 +0000309
Eric Christopherbb69a272012-08-24 01:14:27 +0000310 /// addFlag - Add a flag that is true to the DIE.
David Blaikief2443192013-10-21 17:28:37 +0000311 void addFlag(DIE *Die, dwarf::Attribute Attribute);
Eric Christopher48fef592012-12-20 21:58:40 +0000312
Devang Patelf20c4f72011-04-12 22:53:02 +0000313 /// addUInt - Add an unsigned integer attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000314 void addUInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
315 uint64_t Integer);
316
Eric Christopher4a741042014-02-16 08:46:55 +0000317 void addUInt(DIE *Block, dwarf::Form Form, uint64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000318
319 /// addSInt - Add an signed integer attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000320 void addSInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
321 int64_t Integer);
322
Eric Christopher4a741042014-02-16 08:46:55 +0000323 void addSInt(DIELoc *Die, Optional<dwarf::Form> Form, int64_t Integer);
Devang Patelf20c4f72011-04-12 22:53:02 +0000324
325 /// addString - Add a string attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000326 void addString(DIE *Die, dwarf::Attribute Attribute, const StringRef Str);
Devang Patelf20c4f72011-04-12 22:53:02 +0000327
Eric Christopher2cbd5762013-01-07 19:32:41 +0000328 /// addLocalString - Add a string attribute data and value.
Eric Christophera07e4f52013-11-19 09:28:34 +0000329 void addLocalString(DIE *Die, dwarf::Attribute Attribute,
330 const StringRef Str);
Eric Christopher2cbd5762013-01-07 19:32:41 +0000331
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000332 /// addExpr - Add a Dwarf expression attribute data and value.
Eric Christopher4a741042014-02-16 08:46:55 +0000333 void addExpr(DIELoc *Die, dwarf::Form Form, const MCExpr *Expr);
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000334
Devang Patelf20c4f72011-04-12 22:53:02 +0000335 /// addLabel - Add a Dwarf label attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000336 void addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
Devang Patelf20c4f72011-04-12 22:53:02 +0000337 const MCSymbol *Label);
338
Eric Christopher4a741042014-02-16 08:46:55 +0000339 void addLabel(DIELoc *Die, dwarf::Form Form, const MCSymbol *Label);
David Blaikief2443192013-10-21 17:28:37 +0000340
Eric Christophera27220f2014-03-05 22:41:20 +0000341 /// addLocationList - Add a Dwarf loclistptr attribute data and value.
342 void addLocationList(DIE *Die, dwarf::Attribute Attribute, unsigned Index);
343
Eric Christopher33ff6972013-11-21 23:46:41 +0000344 /// addSectionLabel - Add a Dwarf section label attribute data and value.
345 ///
Eric Christopherf52eddf2013-11-26 22:23:27 +0000346 void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
347 const MCSymbol *Label);
Eric Christopher33ff6972013-11-21 23:46:41 +0000348
349 /// addSectionOffset - Add an offset into a section attribute data and value.
350 ///
351 void addSectionOffset(DIE *Die, dwarf::Attribute Attribute, uint64_t Integer);
352
Eric Christophere9ec2452013-01-18 22:11:33 +0000353 /// addOpAddress - Add a dwarf op address data and value using the
354 /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
Eric Christopher4a741042014-02-16 08:46:55 +0000355 void addOpAddress(DIELoc *Die, const MCSymbol *Label);
Eric Christophere9ec2452013-01-18 22:11:33 +0000356
Eric Christopher33ff6972013-11-21 23:46:41 +0000357 /// addSectionDelta - Add a label delta attribute data and value.
358 void addSectionDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
359 const MCSymbol *Lo);
Devang Patelf20c4f72011-04-12 22:53:02 +0000360
David Blaikie48b1bdc2014-03-07 01:30:55 +0000361 /// addLabelDelta - Add a label delta attribute data and value.
362 void addLabelDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
363 const MCSymbol *Lo);
364
Devang Patelf20c4f72011-04-12 22:53:02 +0000365 /// addDIEEntry - Add a DIE attribute data and value.
David Blaikief2443192013-10-21 17:28:37 +0000366 void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry);
Eric Christopher48fef592012-12-20 21:58:40 +0000367
Manman Ren4dbdc902013-10-31 17:54:35 +0000368 /// addDIEEntry - Add a DIE attribute data and value.
Manman Ren4dbdc902013-10-31 17:54:35 +0000369 void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIEEntry *Entry);
370
David Blaikie47f615e2013-12-17 23:32:35 +0000371 void addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type);
372
Devang Patelf20c4f72011-04-12 22:53:02 +0000373 /// addBlock - Add block data.
Eric Christopher4a741042014-02-16 08:46:55 +0000374 void addBlock(DIE *Die, dwarf::Attribute Attribute, DIELoc *Block);
375
376 /// addBlock - Add block data.
David Blaikief2443192013-10-21 17:28:37 +0000377 void addBlock(DIE *Die, dwarf::Attribute Attribute, DIEBlock *Block);
Devang Patelf20c4f72011-04-12 22:53:02 +0000378
379 /// addSourceLine - Add location information to specified debug information
380 /// entry.
David Blaikie101613e2014-02-12 00:11:25 +0000381 void addSourceLine(DIE *Die, unsigned Line, StringRef File,
382 StringRef Directory);
Devang Patelf20c4f72011-04-12 22:53:02 +0000383 void addSourceLine(DIE *Die, DIVariable V);
384 void addSourceLine(DIE *Die, DIGlobalVariable G);
385 void addSourceLine(DIE *Die, DISubprogram SP);
386 void addSourceLine(DIE *Die, DIType Ty);
387 void addSourceLine(DIE *Die, DINameSpace NS);
Eric Christopher70e1bd82012-03-29 08:42:56 +0000388 void addSourceLine(DIE *Die, DIObjCProperty Ty);
Devang Patelf20c4f72011-04-12 22:53:02 +0000389
390 /// addAddress - Add an address attribute to a die based on the location
391 /// provided.
Eric Christophera07e4f52013-11-19 09:28:34 +0000392 void addAddress(DIE *Die, dwarf::Attribute Attribute,
393 const MachineLocation &Location, bool Indirect = false);
Devang Patelf20c4f72011-04-12 22:53:02 +0000394
Devang Patelf20c4f72011-04-12 22:53:02 +0000395 /// addConstantValue - Add constant value entry in variable DIE.
Eric Christopher78fcf4902013-07-03 01:08:30 +0000396 void addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
397 void addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
398 void addConstantValue(DIE *Die, const APInt &Val, bool Unsigned);
Devang Patelf20c4f72011-04-12 22:53:02 +0000399
400 /// addConstantFPValue - Add constant value entry in variable DIE.
Eric Christopher78fcf4902013-07-03 01:08:30 +0000401 void addConstantFPValue(DIE *Die, const MachineOperand &MO);
402 void addConstantFPValue(DIE *Die, const ConstantFP *CFP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000403
404 /// addTemplateParams - Add template parameters in buffer.
405 void addTemplateParams(DIE &Buffer, DIArray TParams);
406
Devang Patelba5fbf12011-04-26 19:06:18 +0000407 /// addRegisterOp - Add register operand.
Eric Christopher4a741042014-02-16 08:46:55 +0000408 void addRegisterOp(DIELoc *TheDie, unsigned Reg);
Devang Patelba5fbf12011-04-26 19:06:18 +0000409
410 /// addRegisterOffset - Add register offset.
Eric Christopher4a741042014-02-16 08:46:55 +0000411 void addRegisterOffset(DIELoc *TheDie, unsigned Reg, int64_t Offset);
Devang Patelba5fbf12011-04-26 19:06:18 +0000412
Devang Patelf20c4f72011-04-12 22:53:02 +0000413 /// addComplexAddress - Start with the address based on the location provided,
414 /// and generate the DWARF information necessary to find the actual variable
415 /// (navigating the extra location information encoded in the type) based on
416 /// the starting location. Add the DWARF information to the die.
Eric Christophera07e4f52013-11-19 09:28:34 +0000417 void addComplexAddress(const DbgVariable &DV, DIE *Die,
418 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000419 const MachineLocation &Location);
420
421 // FIXME: Should be reformulated in terms of addComplexAddress.
422 /// addBlockByrefAddress - Start with the address based on the location
423 /// provided, and generate the DWARF information necessary to find the
424 /// actual Block variable (navigating the Block struct) based on the
425 /// starting location. Add the DWARF information to the die. Obsolete,
426 /// please use addComplexAddress instead.
Eric Christophera07e4f52013-11-19 09:28:34 +0000427 void addBlockByrefAddress(const DbgVariable &DV, DIE *Die,
428 dwarf::Attribute Attribute,
Devang Patelf20c4f72011-04-12 22:53:02 +0000429 const MachineLocation &Location);
430
Eric Christopher48fef592012-12-20 21:58:40 +0000431 /// addVariableAddress - Add DW_AT_location attribute for a
Devang Patel77dc5412011-04-27 22:45:24 +0000432 /// DbgVariable based on provided MachineLocation.
Eric Christopherbf2d23c2013-06-24 21:07:27 +0000433 void addVariableAddress(const DbgVariable &DV, DIE *Die,
434 MachineLocation Location);
Devang Patelf20c4f72011-04-12 22:53:02 +0000435
Eric Christopher7285c7d2012-03-28 07:34:31 +0000436 /// addType - Add a new type attribute to the specified entity. This takes
437 /// and attribute parameter because DW_AT_friend attributes are also
438 /// type references.
Eric Christophera07e4f52013-11-19 09:28:34 +0000439 void addType(DIE *Entity, DIType Ty,
440 dwarf::Attribute Attribute = dwarf::DW_AT_type);
Devang Patelf20c4f72011-04-12 22:53:02 +0000441
442 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
443 DIE *getOrCreateNameSpace(DINameSpace NS);
444
Devang Patel89543712011-08-15 17:24:54 +0000445 /// getOrCreateSubprogramDIE - Create new DIE using SP.
446 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
447
Devang Patelf20c4f72011-04-12 22:53:02 +0000448 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
449 /// given DIType.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000450 DIE *getOrCreateTypeDIE(const MDNode *N);
Devang Patelf20c4f72011-04-12 22:53:02 +0000451
Eric Christopherfa205ca2013-10-05 00:05:51 +0000452 /// getOrCreateContextDIE - Get context owner's DIE.
David Blaikie409dd9c2013-11-19 23:08:21 +0000453 DIE *createTypeDIE(DICompositeType Ty);
454
455 /// getOrCreateContextDIE - Get context owner's DIE.
Eric Christopherfa205ca2013-10-05 00:05:51 +0000456 DIE *getOrCreateContextDIE(DIScope Context);
Devang Patelf20c4f72011-04-12 22:53:02 +0000457
Eric Christopherfa205ca2013-10-05 00:05:51 +0000458 /// constructContainingTypeDIEs - Construct DIEs for types that contain
459 /// vtables.
460 void constructContainingTypeDIEs();
Devang Patelf20c4f72011-04-12 22:53:02 +0000461
Eric Christopherfa205ca2013-10-05 00:05:51 +0000462 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
Eric Christopher34a2c872013-11-15 01:43:19 +0000463 DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
Eric Christopherfa205ca2013-10-05 00:05:51 +0000464
Adrian Prantl69140d22014-02-25 22:27:14 +0000465 /// constructSubprogramArguments - Construct function argument DIEs.
466 void constructSubprogramArguments(DIE &Buffer, DIArray Args);
467
Manman Renb987e512013-10-29 00:53:03 +0000468 /// Create a DIE with the given Tag, add the DIE to its parent, and
469 /// call insertDIE if MD is not null.
Eric Christophera07e4f52013-11-19 09:28:34 +0000470 DIE *createAndAddDIE(unsigned Tag, DIE &Parent,
471 DIDescriptor N = DIDescriptor());
Manman Renb987e512013-10-29 00:53:03 +0000472
David Blaikie6b288cf2013-10-30 20:42:41 +0000473 /// Compute the size of a header for this unit, not including the initial
474 /// length field.
David Blaikiebc563272013-12-13 21:33:40 +0000475 virtual unsigned getHeaderSize() const {
David Blaikie6b288cf2013-10-30 20:42:41 +0000476 return sizeof(int16_t) + // DWARF version number
477 sizeof(int32_t) + // Offset Into Abbrev. Section
478 sizeof(int8_t); // Pointer Size (in bytes)
479 }
480
481 /// Emit the header for this unit, not including the initial length field.
David Blaikiebc563272013-12-13 21:33:40 +0000482 virtual void emitHeader(const MCSection *ASection,
483 const MCSymbol *ASectionSym) const;
David Blaikie6b288cf2013-10-30 20:42:41 +0000484
David Blaikie15632ae2014-02-12 00:31:30 +0000485 virtual DwarfCompileUnit &getCU() = 0;
David Blaikied696fac2014-02-12 00:32:05 +0000486
David Blaikie319a05f2013-12-02 19:33:10 +0000487protected:
488 /// getOrCreateStaticMemberDIE - Create new static data member DIE.
489 DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
490
David Blaikie4a2f95f2014-03-18 01:17:26 +0000491 /// Look up the source ID with the given directory and source file names. If
492 /// none currently exists, create a new ID and insert it in the line table.
493 virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0;
494
Eric Christopherfa205ca2013-10-05 00:05:51 +0000495private:
Devang Patelf20c4f72011-04-12 22:53:02 +0000496 /// constructTypeDIE - Construct basic type die from DIBasicType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000497 void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000498
499 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000500 void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000501
502 /// constructTypeDIE - Construct type DIE from DICompositeType.
Eric Christopherf0388b72013-10-04 23:49:29 +0000503 void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000504
505 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
506 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
507
508 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Eric Christopherdf9955d2013-11-11 18:52:31 +0000509 void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000510
511 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Eric Christopheraeb105f2013-11-11 18:52:39 +0000512 void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
Devang Patelf20c4f72011-04-12 22:53:02 +0000513
Manman Ren230ec862013-10-23 23:00:44 +0000514 /// constructMemberDIE - Construct member DIE from DIDerivedType.
515 void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
Manman Ren7cc62702013-10-18 21:14:19 +0000516
Manman Renffc9a712013-10-23 23:05:28 +0000517 /// constructTemplateTypeParameterDIE - Construct new DIE for the given
518 /// DITemplateTypeParameter.
519 void constructTemplateTypeParameterDIE(DIE &Buffer,
520 DITemplateTypeParameter TP);
Manman Ren7cc62702013-10-18 21:14:19 +0000521
Manman Renffc9a712013-10-23 23:05:28 +0000522 /// constructTemplateValueParameterDIE - Construct new DIE for the given
523 /// DITemplateValueParameter.
524 void constructTemplateValueParameterDIE(DIE &Buffer,
525 DITemplateValueParameter TVP);
Devang Patelf20c4f72011-04-12 22:53:02 +0000526
Eric Christopherfa205ca2013-10-05 00:05:51 +0000527 /// getLowerBoundDefault - Return the default lower bound for an array. If the
528 /// DWARF version doesn't handle the language, return -1.
529 int64_t getDefaultLowerBound() const;
530
531 /// getDIEEntry - Returns the debug information entry for the specified
532 /// debug variable.
533 DIEEntry *getDIEEntry(const MDNode *N) const {
534 return MDNodeToDIEEntryMap.lookup(N);
535 }
536
537 /// insertDIEEntry - Insert debug information entry into the map.
538 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
539 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
540 }
541
542 // getIndexTyDie - Get an anonymous type for index type.
543 DIE *getIndexTyDie() { return IndexTyDie; }
544
545 // setIndexTyDie - Set D as anonymous type for index which can be reused
546 // later.
547 void setIndexTyDie(DIE *D) { IndexTyDie = D; }
548
549 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
550 /// information entry.
551 DIEEntry *createDIEEntry(DIE *Entry);
David Blaikie684fc532013-05-06 23:33:07 +0000552
Eric Christopher9e429ae2013-10-05 00:27:02 +0000553 /// resolve - Look in the DwarfDebug map for the MDNode that
Eric Christopher87b9c492013-10-05 00:32:34 +0000554 /// corresponds to the reference.
Eric Christopher9e429ae2013-10-05 00:27:02 +0000555 template <typename T> T resolve(DIRef<T> Ref) const {
556 return DD->resolve(Ref);
557 }
David Blaikie2ea848b2013-11-19 22:51:04 +0000558
559 /// If this is a named finished type then include it in the list of types for
560 /// the accelerator tables.
David Blaikie9d861be2013-11-26 00:15:27 +0000561 void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE);
Devang Patel5eb43192011-04-12 17:40:32 +0000562};
563
Eric Christopher4287a492013-12-09 23:57:44 +0000564class DwarfCompileUnit : public DwarfUnit {
David Blaikie60e63862014-02-14 23:58:13 +0000565 /// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding
566 /// the need to search for it in applyStmtList.
567 unsigned stmtListIndex;
568
David Blaikie319a05f2013-12-02 19:33:10 +0000569public:
Eric Christopher4287a492013-12-09 23:57:44 +0000570 DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
571 DwarfDebug *DW, DwarfFile *DWU);
David Blaikie319a05f2013-12-02 19:33:10 +0000572
David Blaikie2494fdb2014-02-14 22:41:51 +0000573 void initStmtList(MCSymbol *DwarfLineSectionSym);
574
David Blaikie60e63862014-02-14 23:58:13 +0000575 /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
576 void applyStmtList(DIE &D);
577
David Blaikie319a05f2013-12-02 19:33:10 +0000578 /// createGlobalVariableDIE - create global variable DIE.
579 void createGlobalVariableDIE(DIGlobalVariable GV);
580
581 /// addLabelAddress - Add a dwarf label attribute data and value using
582 /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
Eric Christopher384f3fe2014-03-20 19:16:16 +0000583 void addLabelAddress(DIE *Die, dwarf::Attribute Attribute,
584 const MCSymbol *Label);
585
586 /// addLocalLabelAddress - Add a dwarf label attribute data and value using
587 /// DW_FORM_addr only.
588 void addLocalLabelAddress(DIE *Die, dwarf::Attribute Attribute,
589 const MCSymbol *Label);
David Blaikie15632ae2014-02-12 00:31:30 +0000590
Craig Topper73156022014-03-02 09:09:27 +0000591 DwarfCompileUnit &getCU() override { return *this; }
David Blaikie0e8d4012014-03-17 23:53:25 +0000592
David Blaikie4a2f95f2014-03-18 01:17:26 +0000593 unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override;
David Blaikie319a05f2013-12-02 19:33:10 +0000594};
595
Eric Christopher4287a492013-12-09 23:57:44 +0000596class DwarfTypeUnit : public DwarfUnit {
David Blaikie319a05f2013-12-02 19:33:10 +0000597private:
David Blaikiebc563272013-12-13 21:33:40 +0000598 uint64_t TypeSignature;
599 const DIE *Ty;
David Blaikie15632ae2014-02-12 00:31:30 +0000600 DwarfCompileUnit &CU;
David Blaikie8287aff2014-03-18 02:13:23 +0000601 MCDwarfDwoLineTable *SplitLineTable;
David Blaikie319a05f2013-12-02 19:33:10 +0000602
603public:
David Blaikie15632ae2014-02-12 00:31:30 +0000604 DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, AsmPrinter *A,
David Blaikie4a2f95f2014-03-18 01:17:26 +0000605 DwarfDebug *DW, DwarfFile *DWU,
David Blaikie8287aff2014-03-18 02:13:23 +0000606 MCDwarfDwoLineTable *SplitLineTable = nullptr);
David Blaikie319a05f2013-12-02 19:33:10 +0000607
David Blaikiebc563272013-12-13 21:33:40 +0000608 void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
David Blaikie47f615e2013-12-17 23:32:35 +0000609 uint64_t getTypeSignature() const { return TypeSignature; }
David Blaikiebc563272013-12-13 21:33:40 +0000610 void setType(const DIE *Ty) { this->Ty = Ty; }
611
David Blaikiebc563272013-12-13 21:33:40 +0000612 /// Emit the header for this unit, not including the initial length field.
613 void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym) const
Craig Topper73156022014-03-02 09:09:27 +0000614 override;
615 unsigned getHeaderSize() const override {
David Blaikiebc563272013-12-13 21:33:40 +0000616 return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
617 sizeof(uint32_t); // Type DIE Offset
618 }
619 void initSection(const MCSection *Section);
Craig Topper73156022014-03-02 09:09:27 +0000620 DwarfCompileUnit &getCU() override { return CU; }
David Blaikie4a2f95f2014-03-18 01:17:26 +0000621
622protected:
623 unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override;
David Blaikie319a05f2013-12-02 19:33:10 +0000624};
Devang Patel5eb43192011-04-12 17:40:32 +0000625} // end llvm namespace
626#endif