blob: 27c17fcc163b5ec3cf2ff98af0822c7117cc46b7 [file] [log] [blame]
Bill Wendling88423ee2009-05-15 00:11:17 +00001//===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- 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// Data structures for DWARF info entries.
Eric Christopherff348452013-01-07 22:40:45 +000011//
Bill Wendling88423ee2009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
Bill Wendling0310d762009-05-15 09:23:25 +000014#ifndef CODEGEN_ASMPRINTER_DIE_H__
15#define CODEGEN_ASMPRINTER_DIE_H__
Bill Wendling88423ee2009-05-15 00:11:17 +000016
Bill Wendling88423ee2009-05-15 00:11:17 +000017#include "llvm/ADT/FoldingSet.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/Support/Compiler.h"
20#include "llvm/Support/Dwarf.h"
Chris Lattnerb01acfa2009-08-23 01:01:17 +000021#include <vector>
Bill Wendling88423ee2009-05-15 00:11:17 +000022
23namespace llvm {
24 class AsmPrinter;
Chris Lattner858431d2010-01-16 18:50:28 +000025 class MCSymbol;
Chris Lattnerb98b1bf2010-03-08 22:23:36 +000026 class raw_ostream;
Bill Wendling88423ee2009-05-15 00:11:17 +000027
28 //===--------------------------------------------------------------------===//
29 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
30 /// Dwarf abbreviation.
Nick Lewycky381afae2009-11-17 09:17:08 +000031 class DIEAbbrevData {
Bill Wendling88423ee2009-05-15 00:11:17 +000032 /// Attribute - Dwarf attribute code.
33 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000034 uint16_t Attribute;
Bill Wendling88423ee2009-05-15 00:11:17 +000035
36 /// Form - Dwarf form code.
37 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000038 uint16_t Form;
Bill Wendling88423ee2009-05-15 00:11:17 +000039 public:
Benjamin Kramere697b4f2012-01-24 12:08:28 +000040 DIEAbbrevData(uint16_t A, uint16_t F) : Attribute(A), Form(F) {}
Bill Wendling88423ee2009-05-15 00:11:17 +000041
42 // Accessors.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000043 uint16_t getAttribute() const { return Attribute; }
44 uint16_t getForm() const { return Form; }
Bill Wendling88423ee2009-05-15 00:11:17 +000045
46 /// Profile - Used to gather unique data for the abbreviation folding set.
47 ///
48 void Profile(FoldingSetNodeID &ID) const;
49 };
50
51 //===--------------------------------------------------------------------===//
52 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
53 /// information object.
Nick Lewycky381afae2009-11-17 09:17:08 +000054 class DIEAbbrev : public FoldingSetNode {
Bill Wendling88423ee2009-05-15 00:11:17 +000055 /// Tag - Dwarf tag code.
56 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000057 uint16_t Tag;
58
59 /// ChildrenFlag - Dwarf children flag.
60 ///
61 uint16_t ChildrenFlag;
Bill Wendling88423ee2009-05-15 00:11:17 +000062
63 /// Unique number for node.
64 ///
65 unsigned Number;
66
Bill Wendling88423ee2009-05-15 00:11:17 +000067 /// Data - Raw data bytes for abbreviation.
68 ///
Eric Christopher2df938a2013-03-29 20:23:06 +000069 SmallVector<DIEAbbrevData, 12> Data;
Devang Patel6404e4e2009-12-15 19:16:48 +000070
Bill Wendling88423ee2009-05-15 00:11:17 +000071 public:
Benjamin Kramere697b4f2012-01-24 12:08:28 +000072 DIEAbbrev(uint16_t T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {}
Bill Wendling88423ee2009-05-15 00:11:17 +000073
74 // Accessors.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000075 uint16_t getTag() const { return Tag; }
Bill Wendling88423ee2009-05-15 00:11:17 +000076 unsigned getNumber() const { return Number; }
Benjamin Kramere697b4f2012-01-24 12:08:28 +000077 uint16_t getChildrenFlag() const { return ChildrenFlag; }
Eric Christopherf7cef702013-03-29 23:34:06 +000078 const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
Benjamin Kramere697b4f2012-01-24 12:08:28 +000079 void setTag(uint16_t T) { Tag = T; }
80 void setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; }
Bill Wendling88423ee2009-05-15 00:11:17 +000081 void setNumber(unsigned N) { Number = N; }
82
83 /// AddAttribute - Adds another set of attribute information to the
84 /// abbreviation.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000085 void AddAttribute(uint16_t Attribute, uint16_t Form) {
Bill Wendling88423ee2009-05-15 00:11:17 +000086 Data.push_back(DIEAbbrevData(Attribute, Form));
87 }
88
89 /// AddFirstAttribute - Adds a set of attribute information to the front
90 /// of the abbreviation.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000091 void AddFirstAttribute(uint16_t Attribute, uint16_t Form) {
Bill Wendling88423ee2009-05-15 00:11:17 +000092 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
93 }
94
95 /// Profile - Used to gather unique data for the abbreviation folding set.
96 ///
97 void Profile(FoldingSetNodeID &ID) const;
98
99 /// Emit - Print the abbreviation using the specified asm printer.
100 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000101 void Emit(AsmPrinter *AP) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000102
103#ifndef NDEBUG
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000104 void print(raw_ostream &O);
Bill Wendling88423ee2009-05-15 00:11:17 +0000105 void dump();
106#endif
107 };
108
109 //===--------------------------------------------------------------------===//
110 /// DIE - A structured debug information entry. Has an abbreviation which
Eric Christopher0c5cdc52013-04-03 05:29:58 +0000111 /// describes its organization.
Bill Wendling88423ee2009-05-15 00:11:17 +0000112 class DIEValue;
113
Devang Patel6f01d9c2009-11-21 00:31:03 +0000114 class DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000115 protected:
Bill Wendling88423ee2009-05-15 00:11:17 +0000116 /// Offset - Offset in debug info section.
117 ///
118 unsigned Offset;
119
120 /// Size - Size of instance + children.
121 ///
122 unsigned Size;
123
Benjamin Kramere697b4f2012-01-24 12:08:28 +0000124 /// Abbrev - Buffer for constructing abbreviation.
125 ///
126 DIEAbbrev Abbrev;
127
Bill Wendling88423ee2009-05-15 00:11:17 +0000128 /// Children DIEs.
129 ///
130 std::vector<DIE *> Children;
131
Devang Patel6404e4e2009-12-15 19:16:48 +0000132 DIE *Parent;
133
Bill Wendling034b94b2012-12-19 07:18:57 +0000134 /// Attribute values.
Bill Wendling88423ee2009-05-15 00:11:17 +0000135 ///
Eric Christopher2df938a2013-03-29 20:23:06 +0000136 SmallVector<DIEValue*, 12> Values;
Bill Wendling88423ee2009-05-15 00:11:17 +0000137
Eric Christopherd32d7a52013-06-10 20:58:53 +0000138#ifndef NDEBUG
Owen Andersond5509f22009-06-24 23:13:56 +0000139 // Private data for print()
140 mutable unsigned IndentCount;
Eric Christopherd32d7a52013-06-10 20:58:53 +0000141#endif
Bill Wendling88423ee2009-05-15 00:11:17 +0000142 public:
143 explicit DIE(unsigned Tag)
Eric Christopher30cb8362013-05-06 17:50:50 +0000144 : Offset(0), Size(0), Abbrev(Tag, dwarf::DW_CHILDREN_no), Parent(0) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000145 virtual ~DIE();
146
147 // Accessors.
148 DIEAbbrev &getAbbrev() { return Abbrev; }
149 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
150 unsigned getTag() const { return Abbrev.getTag(); }
151 unsigned getOffset() const { return Offset; }
152 unsigned getSize() const { return Size; }
153 const std::vector<DIE *> &getChildren() const { return Children; }
Eric Christopherf7cef702013-03-29 23:34:06 +0000154 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
Devang Patel6404e4e2009-12-15 19:16:48 +0000155 DIE *getParent() const { return Parent; }
Manman Renbc3e96f2013-03-12 18:27:15 +0000156 /// Climb up the parent chain to get the compile unit DIE this DIE belongs
157 /// to.
Eric Christopher4d7f2ce2013-05-14 21:33:10 +0000158 DIE *getCompileUnit();
Bill Wendling88423ee2009-05-15 00:11:17 +0000159 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
160 void setOffset(unsigned O) { Offset = O; }
161 void setSize(unsigned S) { Size = S; }
Eric Christopherff348452013-01-07 22:40:45 +0000162
Devang Patel2c4ceb12009-11-21 02:48:08 +0000163 /// addValue - Add a value and attributes to a DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000164 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000165 void addValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000166 Abbrev.AddAttribute(Attribute, Form);
167 Values.push_back(Value);
168 }
169
Devang Patel2c4ceb12009-11-21 02:48:08 +0000170 /// addChild - Add a child to the DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000171 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000172 void addChild(DIE *Child) {
Devang Patel6404e4e2009-12-15 19:16:48 +0000173 if (Child->getParent()) {
174 assert (Child->getParent() == this && "Unexpected DIE Parent!");
175 return;
176 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000177 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
178 Children.push_back(Child);
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000179 Child->Parent = this;
Bill Wendling88423ee2009-05-15 00:11:17 +0000180 }
181
Bill Wendling88423ee2009-05-15 00:11:17 +0000182#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000183 void print(raw_ostream &O, unsigned IndentCount = 0) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000184 void dump();
185#endif
186 };
187
188 //===--------------------------------------------------------------------===//
189 /// DIEValue - A debug information entry value.
190 ///
Devang Patel6f01d9c2009-11-21 00:31:03 +0000191 class DIEValue {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000192 virtual void anchor();
Bill Wendling88423ee2009-05-15 00:11:17 +0000193 public:
194 enum {
195 isInteger,
196 isString,
197 isLabel,
Bill Wendling88423ee2009-05-15 00:11:17 +0000198 isDelta,
199 isEntry,
200 isBlock
201 };
202 protected:
203 /// Type - Type of data stored in the value.
204 ///
205 unsigned Type;
206 public:
207 explicit DIEValue(unsigned T) : Type(T) {}
208 virtual ~DIEValue() {}
209
210 // Accessors
211 unsigned getType() const { return Type; }
212
213 /// EmitValue - Emit value via the Dwarf writer.
214 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000215 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000216
217 /// SizeOf - Return the size of a value in bytes.
218 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000219 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000220
Bill Wendling88423ee2009-05-15 00:11:17 +0000221#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000222 virtual void print(raw_ostream &O) const = 0;
223 void dump() const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000224#endif
225 };
226
227 //===--------------------------------------------------------------------===//
228 /// DIEInteger - An integer value DIE.
229 ///
Nick Lewycky381afae2009-11-17 09:17:08 +0000230 class DIEInteger : public DIEValue {
Bill Wendling88423ee2009-05-15 00:11:17 +0000231 uint64_t Integer;
232 public:
233 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
234
235 /// BestForm - Choose the best form for integer.
236 ///
237 static unsigned BestForm(bool IsSigned, uint64_t Int) {
238 if (IsSigned) {
Hans Wennborga12c6742013-03-18 17:03:05 +0000239 const int64_t SignedInt = Int;
240 if ((char)Int == SignedInt) return dwarf::DW_FORM_data1;
241 if ((short)Int == SignedInt) return dwarf::DW_FORM_data2;
242 if ((int)Int == SignedInt) return dwarf::DW_FORM_data4;
Bill Wendling88423ee2009-05-15 00:11:17 +0000243 } else {
244 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
245 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
246 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
247 }
248 return dwarf::DW_FORM_data8;
249 }
250
251 /// EmitValue - Emit integer of appropriate size.
252 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000253 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000254
Devang Patelf2548ca2010-04-16 23:33:45 +0000255 uint64_t getValue() const { return Integer; }
256
Bill Wendling88423ee2009-05-15 00:11:17 +0000257 /// SizeOf - Determine size of integer value in bytes.
258 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000259 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000260
Bill Wendling88423ee2009-05-15 00:11:17 +0000261 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000262 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
263
264#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000265 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000266#endif
267 };
268
269 //===--------------------------------------------------------------------===//
Chris Lattner4faf59a2010-03-08 22:31:46 +0000270 /// DIELabel - A label expression DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000271 //
Chris Lattner4faf59a2010-03-08 22:31:46 +0000272 class DIELabel : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000273 const MCSymbol *Label;
Bill Wendling88423ee2009-05-15 00:11:17 +0000274 public:
Chris Lattner4faf59a2010-03-08 22:31:46 +0000275 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000276
277 /// EmitValue - Emit label value.
278 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000279 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000280
Devang Patelc3f5f782010-05-25 23:40:22 +0000281 /// getValue - Get MCSymbol.
282 ///
283 const MCSymbol *getValue() const { return Label; }
284
Bill Wendling88423ee2009-05-15 00:11:17 +0000285 /// SizeOf - Determine size of label value in bytes.
286 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000287 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000288
Bill Wendling88423ee2009-05-15 00:11:17 +0000289 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000290 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
291
292#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000293 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000294#endif
295 };
296
297 //===--------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000298 /// DIEDelta - A simple label difference DIE.
299 ///
Nick Lewycky381afae2009-11-17 09:17:08 +0000300 class DIEDelta : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000301 const MCSymbol *LabelHi;
302 const MCSymbol *LabelLo;
Bill Wendling88423ee2009-05-15 00:11:17 +0000303 public:
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000304 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Bill Wendling88423ee2009-05-15 00:11:17 +0000305 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
306
307 /// EmitValue - Emit delta value.
308 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000309 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000310
311 /// SizeOf - Determine size of delta value in bytes.
312 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000313 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000314
Bill Wendling88423ee2009-05-15 00:11:17 +0000315 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000316 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
317
318#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000319 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000320#endif
321 };
322
323 //===--------------------------------------------------------------------===//
Nick Lewycky024170f2011-10-18 22:39:43 +0000324 /// DIEEntry - A pointer to another debug information entry. An instance of
Bill Wendling88423ee2009-05-15 00:11:17 +0000325 /// this class can also be used as a proxy for a debug information entry not
326 /// yet defined (ie. types.)
Nick Lewycky381afae2009-11-17 09:17:08 +0000327 class DIEEntry : public DIEValue {
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000328 DIE *const Entry;
Bill Wendling88423ee2009-05-15 00:11:17 +0000329 public:
David Blaikie17a692e2013-05-14 00:35:19 +0000330 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
331 assert(E && "Cannot construct a DIEEntry with a null DIE");
332 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000333
334 DIE *getEntry() const { return Entry; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000335
336 /// EmitValue - Emit debug information entry offset.
337 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000338 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000339
340 /// SizeOf - Determine size of debug information entry in bytes.
341 ///
Manman Ren624a93e2013-04-04 23:13:11 +0000342 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const {
343 return sizeof(int32_t);
344 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000345
Bill Wendling88423ee2009-05-15 00:11:17 +0000346 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000347 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
348
349#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000350 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000351#endif
352 };
353
354 //===--------------------------------------------------------------------===//
355 /// DIEBlock - A block of values. Primarily used for location expressions.
356 //
Nick Lewycky381afae2009-11-17 09:17:08 +0000357 class DIEBlock : public DIEValue, public DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000358 unsigned Size; // Size in bytes excluding size header.
359 public:
360 DIEBlock()
361 : DIEValue(isBlock), DIE(0), Size(0) {}
362 virtual ~DIEBlock() {}
363
364 /// ComputeSize - calculate the size of the block.
365 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000366 unsigned ComputeSize(AsmPrinter *AP);
Bill Wendling88423ee2009-05-15 00:11:17 +0000367
368 /// BestForm - Choose the best form for data.
369 ///
370 unsigned BestForm() const {
371 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
372 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
373 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
374 return dwarf::DW_FORM_block;
375 }
376
377 /// EmitValue - Emit block data.
378 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000379 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000380
381 /// SizeOf - Determine size of block data in bytes.
382 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000383 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000384
Bill Wendling88423ee2009-05-15 00:11:17 +0000385 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000386 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
387
388#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000389 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000390#endif
391 };
392
393} // end llvm namespace
394
395#endif