llvm.org GIT mirror llvm / 0c36e97
Make DIE.h a public CodeGen header. dsymutil would like to use all the AsmPrinter/MCStreamer infrastructure to stream out the DWARF. In order to do so, it will reuse the DIE object and so this header needs to be public. The interface exposed here has some corners that cannot be used without a DwarfDebug object, but clients that want to stream Dwarf can just avoid these. Differential Revision: http://reviews.llvm.org/D6695 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225208 91177308-0d34-0410-b5e6-96231b3b80d8 Frederic Riss 5 years ago
11 changed file(s) with 596 addition(s) and 596 deletion(s). Raw diff Collapse all Expand all
0 //===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Data structures for DWARF info entries.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
15
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/Dwarf.h"
19 #include
20
21 namespace llvm {
22 class AsmPrinter;
23 class MCExpr;
24 class MCSymbol;
25 class raw_ostream;
26 class DwarfTypeUnit;
27
28 //===--------------------------------------------------------------------===//
29 /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
30 /// Dwarf abbreviation.
31 class DIEAbbrevData {
32 /// Attribute - Dwarf attribute code.
33 ///
34 dwarf::Attribute Attribute;
35
36 /// Form - Dwarf form code.
37 ///
38 dwarf::Form Form;
39
40 public:
41 DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {}
42
43 // Accessors.
44 dwarf::Attribute getAttribute() const { return Attribute; }
45 dwarf::Form getForm() const { return Form; }
46
47 /// Profile - Used to gather unique data for the abbreviation folding set.
48 ///
49 void Profile(FoldingSetNodeID &ID) const;
50 };
51
52 //===--------------------------------------------------------------------===//
53 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
54 /// information object.
55 class DIEAbbrev : public FoldingSetNode {
56 /// Unique number for node.
57 ///
58 unsigned Number;
59
60 /// Tag - Dwarf tag code.
61 ///
62 dwarf::Tag Tag;
63
64 /// Children - Whether or not this node has children.
65 ///
66 // This cheats a bit in all of the uses since the values in the standard
67 // are 0 and 1 for no children and children respectively.
68 bool Children;
69
70 /// Data - Raw data bytes for abbreviation.
71 ///
72 SmallVector Data;
73
74 public:
75 DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C), Data() {}
76
77 // Accessors.
78 dwarf::Tag getTag() const { return Tag; }
79 unsigned getNumber() const { return Number; }
80 bool hasChildren() const { return Children; }
81 const SmallVectorImpl &getData() const { return Data; }
82 void setChildrenFlag(bool hasChild) { Children = hasChild; }
83 void setNumber(unsigned N) { Number = N; }
84
85 /// AddAttribute - Adds another set of attribute information to the
86 /// abbreviation.
87 void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
88 Data.push_back(DIEAbbrevData(Attribute, Form));
89 }
90
91 /// Profile - Used to gather unique data for the abbreviation folding set.
92 ///
93 void Profile(FoldingSetNodeID &ID) const;
94
95 /// Emit - Print the abbreviation using the specified asm printer.
96 ///
97 void Emit(AsmPrinter *AP) const;
98
99 #ifndef NDEBUG
100 void print(raw_ostream &O);
101 void dump();
102 #endif
103 };
104
105 //===--------------------------------------------------------------------===//
106 /// DIE - A structured debug information entry. Has an abbreviation which
107 /// describes its organization.
108 class DIEValue;
109
110 class DIE {
111 protected:
112 /// Offset - Offset in debug info section.
113 ///
114 unsigned Offset;
115
116 /// Size - Size of instance + children.
117 ///
118 unsigned Size;
119
120 /// Abbrev - Buffer for constructing abbreviation.
121 ///
122 DIEAbbrev Abbrev;
123
124 /// Children DIEs.
125 ///
126 // This can't be a vector because pointer validity is requirent for the
127 // Parent pointer and DIEEntry.
128 // It can't be a list because some clients need pointer validity before
129 // the object has been added to any child list
130 // (eg: DwarfUnit::constructVariableDIE). These aren't insurmountable, but may
131 // be more convoluted than beneficial.
132 std::vector> Children;
133
134 DIE *Parent;
135
136 /// Attribute values.
137 ///
138 SmallVector Values;
139
140 protected:
141 DIE()
142 : Offset(0), Size(0), Abbrev((dwarf::Tag)0, dwarf::DW_CHILDREN_no),
143 Parent(nullptr) {}
144
145 public:
146 explicit DIE(dwarf::Tag Tag)
147 : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
148 Parent(nullptr) {}
149
150 // Accessors.
151 DIEAbbrev &getAbbrev() { return Abbrev; }
152 const DIEAbbrev &getAbbrev() const { return Abbrev; }
153 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
154 dwarf::Tag getTag() const { return Abbrev.getTag(); }
155 unsigned getOffset() const { return Offset; }
156 unsigned getSize() const { return Size; }
157 const std::vector> &getChildren() const {
158 return Children;
159 }
160 const SmallVectorImpl &getValues() const { return Values; }
161 DIE *getParent() const { return Parent; }
162 /// Climb up the parent chain to get the compile or type unit DIE this DIE
163 /// belongs to.
164 const DIE *getUnit() const;
165 /// Similar to getUnit, returns null when DIE is not added to an
166 /// owner yet.
167 const DIE *getUnitOrNull() const;
168 void setOffset(unsigned O) { Offset = O; }
169 void setSize(unsigned S) { Size = S; }
170
171 /// addValue - Add a value and attributes to a DIE.
172 ///
173 void addValue(dwarf::Attribute Attribute, dwarf::Form Form, DIEValue *Value) {
174 Abbrev.AddAttribute(Attribute, Form);
175 Values.push_back(Value);
176 }
177
178 /// addChild - Add a child to the DIE.
179 ///
180 void addChild(std::unique_ptr Child) {
181 assert(!Child->getParent());
182 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
183 Child->Parent = this;
184 Children.push_back(std::move(Child));
185 }
186
187 /// findAttribute - Find a value in the DIE with the attribute given,
188 /// returns NULL if no such attribute exists.
189 DIEValue *findAttribute(dwarf::Attribute Attribute) const;
190
191 #ifndef NDEBUG
192 void print(raw_ostream &O, unsigned IndentCount = 0) const;
193 void dump();
194 #endif
195 };
196
197 //===--------------------------------------------------------------------===//
198 /// DIEValue - A debug information entry value. Some of these roughly correlate
199 /// to DWARF attribute classes.
200 ///
201 class DIEValue {
202 virtual void anchor();
203
204 public:
205 enum Type {
206 isInteger,
207 isString,
208 isExpr,
209 isLabel,
210 isDelta,
211 isEntry,
212 isTypeSignature,
213 isBlock,
214 isLoc,
215 isLocList,
216 };
217
218 protected:
219 /// Ty - Type of data stored in the value.
220 ///
221 Type Ty;
222
223 explicit DIEValue(Type T) : Ty(T) {}
224 virtual ~DIEValue() {}
225
226 public:
227 // Accessors
228 Type getType() const { return Ty; }
229
230 /// EmitValue - Emit value via the Dwarf writer.
231 ///
232 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0;
233
234 /// SizeOf - Return the size of a value in bytes.
235 ///
236 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0;
237
238 #ifndef NDEBUG
239 virtual void print(raw_ostream &O) const = 0;
240 void dump() const;
241 #endif
242 };
243
244 //===--------------------------------------------------------------------===//
245 /// DIEInteger - An integer value DIE.
246 ///
247 class DIEInteger : public DIEValue {
248 uint64_t Integer;
249
250 public:
251 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
252
253 /// BestForm - Choose the best form for integer.
254 ///
255 static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
256 if (IsSigned) {
257 const int64_t SignedInt = Int;
258 if ((char)Int == SignedInt)
259 return dwarf::DW_FORM_data1;
260 if ((short)Int == SignedInt)
261 return dwarf::DW_FORM_data2;
262 if ((int)Int == SignedInt)
263 return dwarf::DW_FORM_data4;
264 } else {
265 if ((unsigned char)Int == Int)
266 return dwarf::DW_FORM_data1;
267 if ((unsigned short)Int == Int)
268 return dwarf::DW_FORM_data2;
269 if ((unsigned int)Int == Int)
270 return dwarf::DW_FORM_data4;
271 }
272 return dwarf::DW_FORM_data8;
273 }
274
275 /// EmitValue - Emit integer of appropriate size.
276 ///
277 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
278
279 uint64_t getValue() const { return Integer; }
280
281 /// SizeOf - Determine size of integer value in bytes.
282 ///
283 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
284
285 // Implement isa/cast/dyncast.
286 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
287
288 #ifndef NDEBUG
289 void print(raw_ostream &O) const override;
290 #endif
291 };
292
293 //===--------------------------------------------------------------------===//
294 /// DIEExpr - An expression DIE.
295 //
296 class DIEExpr : public DIEValue {
297 const MCExpr *Expr;
298
299 public:
300 explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
301
302 /// EmitValue - Emit expression value.
303 ///
304 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
305
306 /// getValue - Get MCExpr.
307 ///
308 const MCExpr *getValue() const { return Expr; }
309
310 /// SizeOf - Determine size of expression value in bytes.
311 ///
312 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
313
314 // Implement isa/cast/dyncast.
315 static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
316
317 #ifndef NDEBUG
318 void print(raw_ostream &O) const override;
319 #endif
320 };
321
322 //===--------------------------------------------------------------------===//
323 /// DIELabel - A label DIE.
324 //
325 class DIELabel : public DIEValue {
326 const MCSymbol *Label;
327
328 public:
329 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
330
331 /// EmitValue - Emit label value.
332 ///
333 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
334
335 /// getValue - Get MCSymbol.
336 ///
337 const MCSymbol *getValue() const { return Label; }
338
339 /// SizeOf - Determine size of label value in bytes.
340 ///
341 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
342
343 // Implement isa/cast/dyncast.
344 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
345
346 #ifndef NDEBUG
347 void print(raw_ostream &O) const override;
348 #endif
349 };
350
351 //===--------------------------------------------------------------------===//
352 /// DIEDelta - A simple label difference DIE.
353 ///
354 class DIEDelta : public DIEValue {
355 const MCSymbol *LabelHi;
356 const MCSymbol *LabelLo;
357
358 public:
359 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
360 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
361
362 /// EmitValue - Emit delta value.
363 ///
364 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
365
366 /// SizeOf - Determine size of delta value in bytes.
367 ///
368 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
369
370 // Implement isa/cast/dyncast.
371 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
372
373 #ifndef NDEBUG
374 void print(raw_ostream &O) const override;
375 #endif
376 };
377
378 //===--------------------------------------------------------------------===//
379 /// DIEString - A container for string values.
380 ///
381 class DIEString : public DIEValue {
382 const DIEValue *Access;
383 StringRef Str;
384
385 public:
386 DIEString(const DIEValue *Acc, StringRef S)
387 : DIEValue(isString), Access(Acc), Str(S) {}
388
389 /// getString - Grab the string out of the object.
390 StringRef getString() const { return Str; }
391
392 /// EmitValue - Emit delta value.
393 ///
394 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
395
396 /// SizeOf - Determine size of delta value in bytes.
397 ///
398 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
399
400 // Implement isa/cast/dyncast.
401 static bool classof(const DIEValue *D) { return D->getType() == isString; }
402
403 #ifndef NDEBUG
404 void print(raw_ostream &O) const override;
405 #endif
406 };
407
408 //===--------------------------------------------------------------------===//
409 /// DIEEntry - A pointer to another debug information entry. An instance of
410 /// this class can also be used as a proxy for a debug information entry not
411 /// yet defined (ie. types.)
412 class DIEEntry : public DIEValue {
413 DIE &Entry;
414
415 public:
416 explicit DIEEntry(DIE &E) : DIEValue(isEntry), Entry(E) {
417 }
418
419 DIE &getEntry() const { return Entry; }
420
421 /// EmitValue - Emit debug information entry offset.
422 ///
423 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
424
425 /// SizeOf - Determine size of debug information entry in bytes.
426 ///
427 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override {
428 return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
429 : sizeof(int32_t);
430 }
431
432 /// Returns size of a ref_addr entry.
433 static unsigned getRefAddrSize(AsmPrinter *AP);
434
435 // Implement isa/cast/dyncast.
436 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
437
438 #ifndef NDEBUG
439 void print(raw_ostream &O) const override;
440 #endif
441 };
442
443 //===--------------------------------------------------------------------===//
444 /// \brief A signature reference to a type unit.
445 class DIETypeSignature : public DIEValue {
446 const DwarfTypeUnit &Unit;
447
448 public:
449 explicit DIETypeSignature(const DwarfTypeUnit &Unit)
450 : DIEValue(isTypeSignature), Unit(Unit) {}
451
452 /// \brief Emit type unit signature.
453 void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const override;
454
455 /// Returns size of a ref_sig8 entry.
456 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override {
457 assert(Form == dwarf::DW_FORM_ref_sig8);
458 return 8;
459 }
460
461 // \brief Implement isa/cast/dyncast.
462 static bool classof(const DIEValue *E) {
463 return E->getType() == isTypeSignature;
464 }
465 #ifndef NDEBUG
466 void print(raw_ostream &O) const override;
467 void dump() const;
468 #endif
469 };
470
471 //===--------------------------------------------------------------------===//
472 /// DIELoc - Represents an expression location.
473 //
474 class DIELoc : public DIEValue, public DIE {
475 mutable unsigned Size; // Size in bytes excluding size header.
476 public:
477 DIELoc() : DIEValue(isLoc), Size(0) {}
478
479 /// ComputeSize - Calculate the size of the location expression.
480 ///
481 unsigned ComputeSize(AsmPrinter *AP) const;
482
483 /// BestForm - Choose the best form for data.
484 ///
485 dwarf::Form BestForm(unsigned DwarfVersion) const {
486 if (DwarfVersion > 3)
487 return dwarf::DW_FORM_exprloc;
488 // Pre-DWARF4 location expressions were blocks and not exprloc.
489 if ((unsigned char)Size == Size)
490 return dwarf::DW_FORM_block1;
491 if ((unsigned short)Size == Size)
492 return dwarf::DW_FORM_block2;
493 if ((unsigned int)Size == Size)
494 return dwarf::DW_FORM_block4;
495 return dwarf::DW_FORM_block;
496 }
497
498 /// EmitValue - Emit location data.
499 ///
500 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
501
502 /// SizeOf - Determine size of location data in bytes.
503 ///
504 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
505
506 // Implement isa/cast/dyncast.
507 static bool classof(const DIEValue *E) { return E->getType() == isLoc; }
508
509 #ifndef NDEBUG
510 void print(raw_ostream &O) const override;
511 #endif
512 };
513
514 //===--------------------------------------------------------------------===//
515 /// DIEBlock - Represents a block of values.
516 //
517 class DIEBlock : public DIEValue, public DIE {
518 mutable unsigned Size; // Size in bytes excluding size header.
519 public:
520 DIEBlock() : DIEValue(isBlock), Size(0) {}
521
522 /// ComputeSize - Calculate the size of the location expression.
523 ///
524 unsigned ComputeSize(AsmPrinter *AP) const;
525
526 /// BestForm - Choose the best form for data.
527 ///
528 dwarf::Form BestForm() const {
529 if ((unsigned char)Size == Size)
530 return dwarf::DW_FORM_block1;
531 if ((unsigned short)Size == Size)
532 return dwarf::DW_FORM_block2;
533 if ((unsigned int)Size == Size)
534 return dwarf::DW_FORM_block4;
535 return dwarf::DW_FORM_block;
536 }
537
538 /// EmitValue - Emit location data.
539 ///
540 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
541
542 /// SizeOf - Determine size of location data in bytes.
543 ///
544 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
545
546 // Implement isa/cast/dyncast.
547 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
548
549 #ifndef NDEBUG
550 void print(raw_ostream &O) const override;
551 #endif
552 };
553
554 //===--------------------------------------------------------------------===//
555 /// DIELocList - Represents a pointer to a location list in the debug_loc
556 /// section.
557 //
558 class DIELocList : public DIEValue {
559 // Index into the .debug_loc vector.
560 size_t Index;
561
562 public:
563 DIELocList(size_t I) : DIEValue(isLocList), Index(I) {}
564
565 /// getValue - Grab the current index out.
566 size_t getValue() const { return Index; }
567
568 /// EmitValue - Emit location data.
569 ///
570 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
571
572 /// SizeOf - Determine size of location data in bytes.
573 ///
574 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
575
576 // Implement isa/cast/dyncast.
577 static bool classof(const DIEValue *E) { return E->getType() == isLocList; }
578
579 #ifndef NDEBUG
580 void print(raw_ostream &O) const override;
581 #endif
582 };
583
584 } // end llvm namespace
585
586 #endif
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "DIE.h"
13 #include "llvm/CodeGen/DIE.h"
1414
1515 #include "DwarfCompileUnit.h"
1616 #include "DwarfDebug.h"
+0
-587
lib/CodeGen/AsmPrinter/DIE.h less more
None //===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Data structures for DWARF info entries.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
15
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/Dwarf.h"
19 #include
20
21 namespace llvm {
22 class AsmPrinter;
23 class MCExpr;
24 class MCSymbol;
25 class raw_ostream;
26 class DwarfTypeUnit;
27
28 //===--------------------------------------------------------------------===//
29 /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
30 /// Dwarf abbreviation.
31 class DIEAbbrevData {
32 /// Attribute - Dwarf attribute code.
33 ///
34 dwarf::Attribute Attribute;
35
36 /// Form - Dwarf form code.
37 ///
38 dwarf::Form Form;
39
40 public:
41 DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {}
42
43 // Accessors.
44 dwarf::Attribute getAttribute() const { return Attribute; }
45 dwarf::Form getForm() const { return Form; }
46
47 /// Profile - Used to gather unique data for the abbreviation folding set.
48 ///
49 void Profile(FoldingSetNodeID &ID) const;
50 };
51
52 //===--------------------------------------------------------------------===//
53 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
54 /// information object.
55 class DIEAbbrev : public FoldingSetNode {
56 /// Unique number for node.
57 ///
58 unsigned Number;
59
60 /// Tag - Dwarf tag code.
61 ///
62 dwarf::Tag Tag;
63
64 /// Children - Whether or not this node has children.
65 ///
66 // This cheats a bit in all of the uses since the values in the standard
67 // are 0 and 1 for no children and children respectively.
68 bool Children;
69
70 /// Data - Raw data bytes for abbreviation.
71 ///
72 SmallVector Data;
73
74 public:
75 DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C), Data() {}
76
77 // Accessors.
78 dwarf::Tag getTag() const { return Tag; }
79 unsigned getNumber() const { return Number; }
80 bool hasChildren() const { return Children; }
81 const SmallVectorImpl &getData() const { return Data; }
82 void setChildrenFlag(bool hasChild) { Children = hasChild; }
83 void setNumber(unsigned N) { Number = N; }
84
85 /// AddAttribute - Adds another set of attribute information to the
86 /// abbreviation.
87 void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
88 Data.push_back(DIEAbbrevData(Attribute, Form));
89 }
90
91 /// Profile - Used to gather unique data for the abbreviation folding set.
92 ///
93 void Profile(FoldingSetNodeID &ID) const;
94
95 /// Emit - Print the abbreviation using the specified asm printer.
96 ///
97 void Emit(AsmPrinter *AP) const;
98
99 #ifndef NDEBUG
100 void print(raw_ostream &O);
101 void dump();
102 #endif
103 };
104
105 //===--------------------------------------------------------------------===//
106 /// DIE - A structured debug information entry. Has an abbreviation which
107 /// describes its organization.
108 class DIEValue;
109
110 class DIE {
111 protected:
112 /// Offset - Offset in debug info section.
113 ///
114 unsigned Offset;
115
116 /// Size - Size of instance + children.
117 ///
118 unsigned Size;
119
120 /// Abbrev - Buffer for constructing abbreviation.
121 ///
122 DIEAbbrev Abbrev;
123
124 /// Children DIEs.
125 ///
126 // This can't be a vector because pointer validity is requirent for the
127 // Parent pointer and DIEEntry.
128 // It can't be a list because some clients need pointer validity before
129 // the object has been added to any child list
130 // (eg: DwarfUnit::constructVariableDIE). These aren't insurmountable, but may
131 // be more convoluted than beneficial.
132 std::vector> Children;
133
134 DIE *Parent;
135
136 /// Attribute values.
137 ///
138 SmallVector Values;
139
140 protected:
141 DIE()
142 : Offset(0), Size(0), Abbrev((dwarf::Tag)0, dwarf::DW_CHILDREN_no),
143 Parent(nullptr) {}
144
145 public:
146 explicit DIE(dwarf::Tag Tag)
147 : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
148 Parent(nullptr) {}
149
150 // Accessors.
151 DIEAbbrev &getAbbrev() { return Abbrev; }
152 const DIEAbbrev &getAbbrev() const { return Abbrev; }
153 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
154 dwarf::Tag getTag() const { return Abbrev.getTag(); }
155 unsigned getOffset() const { return Offset; }
156 unsigned getSize() const { return Size; }
157 const std::vector> &getChildren() const {
158 return Children;
159 }
160 const SmallVectorImpl &getValues() const { return Values; }
161 DIE *getParent() const { return Parent; }
162 /// Climb up the parent chain to get the compile or type unit DIE this DIE
163 /// belongs to.
164 const DIE *getUnit() const;
165 /// Similar to getUnit, returns null when DIE is not added to an
166 /// owner yet.
167 const DIE *getUnitOrNull() const;
168 void setOffset(unsigned O) { Offset = O; }
169 void setSize(unsigned S) { Size = S; }
170
171 /// addValue - Add a value and attributes to a DIE.
172 ///
173 void addValue(dwarf::Attribute Attribute, dwarf::Form Form, DIEValue *Value) {
174 Abbrev.AddAttribute(Attribute, Form);
175 Values.push_back(Value);
176 }
177
178 /// addChild - Add a child to the DIE.
179 ///
180 void addChild(std::unique_ptr Child) {
181 assert(!Child->getParent());
182 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
183 Child->Parent = this;
184 Children.push_back(std::move(Child));
185 }
186
187 /// findAttribute - Find a value in the DIE with the attribute given,
188 /// returns NULL if no such attribute exists.
189 DIEValue *findAttribute(dwarf::Attribute Attribute) const;
190
191 #ifndef NDEBUG
192 void print(raw_ostream &O, unsigned IndentCount = 0) const;
193 void dump();
194 #endif
195 };
196
197 //===--------------------------------------------------------------------===//
198 /// DIEValue - A debug information entry value. Some of these roughly correlate
199 /// to DWARF attribute classes.
200 ///
201 class DIEValue {
202 virtual void anchor();
203
204 public:
205 enum Type {
206 isInteger,
207 isString,
208 isExpr,
209 isLabel,
210 isDelta,
211 isEntry,
212 isTypeSignature,
213 isBlock,
214 isLoc,
215 isLocList,
216 };
217
218 protected:
219 /// Ty - Type of data stored in the value.
220 ///
221 Type Ty;
222
223 explicit DIEValue(Type T) : Ty(T) {}
224 virtual ~DIEValue() {}
225
226 public:
227 // Accessors
228 Type getType() const { return Ty; }
229
230 /// EmitValue - Emit value via the Dwarf writer.
231 ///
232 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0;
233
234 /// SizeOf - Return the size of a value in bytes.
235 ///
236 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0;
237
238 #ifndef NDEBUG
239 virtual void print(raw_ostream &O) const = 0;
240 void dump() const;
241 #endif
242 };
243
244 //===--------------------------------------------------------------------===//
245 /// DIEInteger - An integer value DIE.
246 ///
247 class DIEInteger : public DIEValue {
248 uint64_t Integer;
249
250 public:
251 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
252
253 /// BestForm - Choose the best form for integer.
254 ///
255 static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
256 if (IsSigned) {
257 const int64_t SignedInt = Int;
258 if ((char)Int == SignedInt)
259 return dwarf::DW_FORM_data1;
260 if ((short)Int == SignedInt)
261 return dwarf::DW_FORM_data2;
262 if ((int)Int == SignedInt)
263 return dwarf::DW_FORM_data4;
264 } else {
265 if ((unsigned char)Int == Int)
266 return dwarf::DW_FORM_data1;
267 if ((unsigned short)Int == Int)
268 return dwarf::DW_FORM_data2;
269 if ((unsigned int)Int == Int)
270 return dwarf::DW_FORM_data4;
271 }
272 return dwarf::DW_FORM_data8;
273 }
274
275 /// EmitValue - Emit integer of appropriate size.
276 ///
277 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
278
279 uint64_t getValue() const { return Integer; }
280
281 /// SizeOf - Determine size of integer value in bytes.
282 ///
283 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
284
285 // Implement isa/cast/dyncast.
286 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
287
288 #ifndef NDEBUG
289 void print(raw_ostream &O) const override;
290 #endif
291 };
292
293 //===--------------------------------------------------------------------===//
294 /// DIEExpr - An expression DIE.
295 //
296 class DIEExpr : public DIEValue {
297 const MCExpr *Expr;
298
299 public:
300 explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
301
302 /// EmitValue - Emit expression value.
303 ///
304 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
305
306 /// getValue - Get MCExpr.
307 ///
308 const MCExpr *getValue() const { return Expr; }
309
310 /// SizeOf - Determine size of expression value in bytes.
311 ///
312 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
313
314 // Implement isa/cast/dyncast.
315 static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
316
317 #ifndef NDEBUG
318 void print(raw_ostream &O) const override;
319 #endif
320 };
321
322 //===--------------------------------------------------------------------===//
323 /// DIELabel - A label DIE.
324 //
325 class DIELabel : public DIEValue {
326 const MCSymbol *Label;
327
328 public:
329 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
330
331 /// EmitValue - Emit label value.
332 ///
333 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
334
335 /// getValue - Get MCSymbol.
336 ///
337 const MCSymbol *getValue() const { return Label; }
338
339 /// SizeOf - Determine size of label value in bytes.
340 ///
341 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
342
343 // Implement isa/cast/dyncast.
344 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
345
346 #ifndef NDEBUG
347 void print(raw_ostream &O) const override;
348 #endif
349 };
350
351 //===--------------------------------------------------------------------===//
352 /// DIEDelta - A simple label difference DIE.
353 ///
354 class DIEDelta : public DIEValue {
355 const MCSymbol *LabelHi;
356 const MCSymbol *LabelLo;
357
358 public:
359 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
360 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
361
362 /// EmitValue - Emit delta value.
363 ///
364 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
365
366 /// SizeOf - Determine size of delta value in bytes.
367 ///
368 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
369
370 // Implement isa/cast/dyncast.
371 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
372
373 #ifndef NDEBUG
374 void print(raw_ostream &O) const override;
375 #endif
376 };
377
378 //===--------------------------------------------------------------------===//
379 /// DIEString - A container for string values.
380 ///
381 class DIEString : public DIEValue {
382 const DIEValue *Access;
383 StringRef Str;
384
385 public:
386 DIEString(const DIEValue *Acc, StringRef S)
387 : DIEValue(isString), Access(Acc), Str(S) {}
388
389 /// getString - Grab the string out of the object.
390 StringRef getString() const { return Str; }
391
392 /// EmitValue - Emit delta value.
393 ///
394 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
395
396 /// SizeOf - Determine size of delta value in bytes.
397 ///
398 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
399
400 // Implement isa/cast/dyncast.
401 static bool classof(const DIEValue *D) { return D->getType() == isString; }
402
403 #ifndef NDEBUG
404 void print(raw_ostream &O) const override;
405 #endif
406 };
407
408 //===--------------------------------------------------------------------===//
409 /// DIEEntry - A pointer to another debug information entry. An instance of
410 /// this class can also be used as a proxy for a debug information entry not
411 /// yet defined (ie. types.)
412 class DIEEntry : public DIEValue {
413 DIE &Entry;
414
415 public:
416 explicit DIEEntry(DIE &E) : DIEValue(isEntry), Entry(E) {
417 }
418
419 DIE &getEntry() const { return Entry; }
420
421 /// EmitValue - Emit debug information entry offset.
422 ///
423 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
424
425 /// SizeOf - Determine size of debug information entry in bytes.
426 ///
427 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override {
428 return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
429 : sizeof(int32_t);
430 }
431
432 /// Returns size of a ref_addr entry.
433 static unsigned getRefAddrSize(AsmPrinter *AP);
434
435 // Implement isa/cast/dyncast.
436 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
437
438 #ifndef NDEBUG
439 void print(raw_ostream &O) const override;
440 #endif
441 };
442
443 //===--------------------------------------------------------------------===//
444 /// \brief A signature reference to a type unit.
445 class DIETypeSignature : public DIEValue {
446 const DwarfTypeUnit &Unit;
447
448 public:
449 explicit DIETypeSignature(const DwarfTypeUnit &Unit)
450 : DIEValue(isTypeSignature), Unit(Unit) {}
451
452 /// \brief Emit type unit signature.
453 void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const override;
454
455 /// Returns size of a ref_sig8 entry.
456 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override {
457 assert(Form == dwarf::DW_FORM_ref_sig8);
458 return 8;
459 }
460
461 // \brief Implement isa/cast/dyncast.
462 static bool classof(const DIEValue *E) {
463 return E->getType() == isTypeSignature;
464 }
465 #ifndef NDEBUG
466 void print(raw_ostream &O) const override;
467 void dump() const;
468 #endif
469 };
470
471 //===--------------------------------------------------------------------===//
472 /// DIELoc - Represents an expression location.
473 //
474 class DIELoc : public DIEValue, public DIE {
475 mutable unsigned Size; // Size in bytes excluding size header.
476 public:
477 DIELoc() : DIEValue(isLoc), Size(0) {}
478
479 /// ComputeSize - Calculate the size of the location expression.
480 ///
481 unsigned ComputeSize(AsmPrinter *AP) const;
482
483 /// BestForm - Choose the best form for data.
484 ///
485 dwarf::Form BestForm(unsigned DwarfVersion) const {
486 if (DwarfVersion > 3)
487 return dwarf::DW_FORM_exprloc;
488 // Pre-DWARF4 location expressions were blocks and not exprloc.
489 if ((unsigned char)Size == Size)
490 return dwarf::DW_FORM_block1;
491 if ((unsigned short)Size == Size)
492 return dwarf::DW_FORM_block2;
493 if ((unsigned int)Size == Size)
494 return dwarf::DW_FORM_block4;
495 return dwarf::DW_FORM_block;
496 }
497
498 /// EmitValue - Emit location data.
499 ///
500 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
501
502 /// SizeOf - Determine size of location data in bytes.
503 ///
504 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
505
506 // Implement isa/cast/dyncast.
507 static bool classof(const DIEValue *E) { return E->getType() == isLoc; }
508
509 #ifndef NDEBUG
510 void print(raw_ostream &O) const override;
511 #endif
512 };
513
514 //===--------------------------------------------------------------------===//
515 /// DIEBlock - Represents a block of values.
516 //
517 class DIEBlock : public DIEValue, public DIE {
518 mutable unsigned Size; // Size in bytes excluding size header.
519 public:
520 DIEBlock() : DIEValue(isBlock), Size(0) {}
521
522 /// ComputeSize - Calculate the size of the location expression.
523 ///
524 unsigned ComputeSize(AsmPrinter *AP) const;
525
526 /// BestForm - Choose the best form for data.
527 ///
528 dwarf::Form BestForm() const {
529 if ((unsigned char)Size == Size)
530 return dwarf::DW_FORM_block1;
531 if ((unsigned short)Size == Size)
532 return dwarf::DW_FORM_block2;
533 if ((unsigned int)Size == Size)
534 return dwarf::DW_FORM_block4;
535 return dwarf::DW_FORM_block;
536 }
537
538 /// EmitValue - Emit location data.
539 ///
540 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
541
542 /// SizeOf - Determine size of location data in bytes.
543 ///
544 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
545
546 // Implement isa/cast/dyncast.
547 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
548
549 #ifndef NDEBUG
550 void print(raw_ostream &O) const override;
551 #endif
552 };
553
554 //===--------------------------------------------------------------------===//
555 /// DIELocList - Represents a pointer to a location list in the debug_loc
556 /// section.
557 //
558 class DIELocList : public DIEValue {
559 // Index into the .debug_loc vector.
560 size_t Index;
561
562 public:
563 DIELocList(size_t I) : DIEValue(isLocList), Index(I) {}
564
565 /// getValue - Grab the current index out.
566 size_t getValue() const { return Index; }
567
568 /// EmitValue - Emit location data.
569 ///
570 void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
571
572 /// SizeOf - Determine size of location data in bytes.
573 ///
574 unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
575
576 // Implement isa/cast/dyncast.
577 static bool classof(const DIEValue *E) { return E->getType() == isLocList; }
578
579 #ifndef NDEBUG
580 void print(raw_ostream &O) const override;
581 #endif
582 };
583
584 } // end llvm namespace
585
586 #endif
1212
1313 #include "ByteStreamer.h"
1414 #include "DIEHash.h"
15 #include "DIE.h"
1615 #include "DwarfDebug.h"
1716 #include "llvm/ADT/ArrayRef.h"
1817 #include "llvm/ADT/StringRef.h"
1918 #include "llvm/CodeGen/AsmPrinter.h"
19 #include "llvm/CodeGen/DIE.h"
2020 #include "llvm/Support/Debug.h"
2121 #include "llvm/Support/Dwarf.h"
2222 #include "llvm/Support/Endian.h"
1313 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
1414 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIEHASH_H
1515
16 #include "DIE.h"
16 #include "llvm/CodeGen/DIE.h"
1717 #include "llvm/ADT/DenseMap.h"
1818 #include "llvm/Support/MD5.h"
1919
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "DwarfAccelTable.h"
14 #include "DIE.h"
1514 #include "DwarfCompileUnit.h"
1615 #include "DwarfDebug.h"
1716 #include "llvm/ADT/STLExtras.h"
1817 #include "llvm/ADT/Twine.h"
1918 #include "llvm/CodeGen/AsmPrinter.h"
19 #include "llvm/CodeGen/DIE.h"
2020 #include "llvm/MC/MCExpr.h"
2121 #include "llvm/MC/MCStreamer.h"
2222 #include "llvm/MC/MCSymbol.h"
1313 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFACCELTABLE_H
1414 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFACCELTABLE_H
1515
16 #include "DIE.h"
1716 #include "llvm/ADT/ArrayRef.h"
1817 #include "llvm/ADT/StringMap.h"
18 #include "llvm/CodeGen/DIE.h"
1919 #include "llvm/MC/MCSymbol.h"
2020 #include "llvm/Support/Compiler.h"
2121 #include "llvm/Support/DataTypes.h"
1414
1515 #include "ByteStreamer.h"
1616 #include "DwarfCompileUnit.h"
17 #include "DIE.h"
1817 #include "DIEHash.h"
1918 #include "DwarfUnit.h"
2019 #include "llvm/ADT/STLExtras.h"
2120 #include "llvm/ADT/Statistic.h"
2221 #include "llvm/ADT/StringExtras.h"
2322 #include "llvm/ADT/Triple.h"
23 #include "llvm/CodeGen/DIE.h"
2424 #include "llvm/CodeGen/MachineFunction.h"
2525 #include "llvm/CodeGen/MachineModuleInfo.h"
2626 #include "llvm/IR/Constants.h"
1515
1616 #include "DwarfFile.h"
1717 #include "AsmPrinterHandler.h"
18 #include "DIE.h"
1918 #include "DbgValueHistoryCalculator.h"
2019 #include "DebugLocEntry.h"
2120 #include "DebugLocList.h"
2524 #include "llvm/ADT/SmallPtrSet.h"
2625 #include "llvm/ADT/StringMap.h"
2726 #include "llvm/ADT/FoldingSet.h"
27 #include "llvm/CodeGen/DIE.h"
2828 #include "llvm/CodeGen/LexicalScopes.h"
2929 #include "llvm/CodeGen/MachineInstr.h"
3030 #include "llvm/IR/DebugInfo.h"
1313 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H
1414 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H
1515
16 #include "DIE.h"
1716 #include "DwarfDebug.h"
1817 #include "llvm/ADT/DenseMap.h"
1918 #include "llvm/ADT/Optional.h"
2019 #include "llvm/ADT/StringMap.h"
2120 #include "llvm/CodeGen/AsmPrinter.h"
21 #include "llvm/CodeGen/DIE.h"
2222 #include "llvm/IR/DIBuilder.h"
2323 #include "llvm/IR/DebugInfo.h"
2424 #include "llvm/MC/MCExpr.h"
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "../lib/CodeGen/AsmPrinter/DIE.h"
9 #include "llvm/CodeGen/DIE.h"
1010 #include "../lib/CodeGen/AsmPrinter/DIEHash.h"
1111 #include "llvm/Support/Debug.h"
1212 #include "llvm/Support/Dwarf.h"