]>
git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/CodeGen/DIE.h
1 //===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Data structures for DWARF info entries.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
17 #include "llvm/ADT/FoldingSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Support/Dwarf.h"
29 //===--------------------------------------------------------------------===//
30 /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
31 /// Dwarf abbreviation.
33 /// Attribute - Dwarf attribute code.
35 dwarf::Attribute Attribute
;
37 /// Form - Dwarf form code.
42 DIEAbbrevData(dwarf::Attribute A
, dwarf::Form F
) : Attribute(A
), Form(F
) {}
45 dwarf::Attribute
getAttribute() const { return Attribute
; }
46 dwarf::Form
getForm() const { return Form
; }
48 /// Profile - Used to gather unique data for the abbreviation folding set.
50 void Profile(FoldingSetNodeID
&ID
) const;
53 //===--------------------------------------------------------------------===//
54 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
55 /// information object.
56 class DIEAbbrev
: public FoldingSetNode
{
57 /// Unique number for node.
61 /// Tag - Dwarf tag code.
65 /// Children - Whether or not this node has children.
67 // This cheats a bit in all of the uses since the values in the standard
68 // are 0 and 1 for no children and children respectively.
71 /// Data - Raw data bytes for abbreviation.
73 SmallVector
<DIEAbbrevData
, 12> Data
;
76 DIEAbbrev(dwarf::Tag T
, bool C
) : Tag(T
), Children(C
), Data() {}
79 dwarf::Tag
getTag() const { return Tag
; }
80 unsigned getNumber() const { return Number
; }
81 bool hasChildren() const { return Children
; }
82 const SmallVectorImpl
<DIEAbbrevData
> &getData() const { return Data
; }
83 void setChildrenFlag(bool hasChild
) { Children
= hasChild
; }
84 void setNumber(unsigned N
) { Number
= N
; }
86 /// AddAttribute - Adds another set of attribute information to the
88 void AddAttribute(dwarf::Attribute Attribute
, dwarf::Form Form
) {
89 Data
.push_back(DIEAbbrevData(Attribute
, Form
));
92 /// Profile - Used to gather unique data for the abbreviation folding set.
94 void Profile(FoldingSetNodeID
&ID
) const;
96 /// Emit - Print the abbreviation using the specified asm printer.
98 void Emit(AsmPrinter
*AP
) const;
101 void print(raw_ostream
&O
);
106 //===--------------------------------------------------------------------===//
107 /// DIE - A structured debug information entry. Has an abbreviation which
108 /// describes its organization.
113 /// Offset - Offset in debug info section.
117 /// Size - Size of instance + children.
121 /// Abbrev - Buffer for constructing abbreviation.
127 // This can't be a vector<DIE> because pointer validity is requirent for the
128 // Parent pointer and DIEEntry.
129 // It can't be a list<DIE> because some clients need pointer validity before
130 // the object has been added to any child list
131 // (eg: DwarfUnit::constructVariableDIE). These aren't insurmountable, but may
132 // be more convoluted than beneficial.
133 std::vector
<std::unique_ptr
<DIE
>> Children
;
137 /// Attribute values.
139 SmallVector
<DIEValue
*, 12> Values
;
143 : Offset(0), Size(0), Abbrev((dwarf::Tag
)0, dwarf::DW_CHILDREN_no
),
147 explicit DIE(dwarf::Tag Tag
)
148 : Offset(0), Size(0), Abbrev((dwarf::Tag
)Tag
, dwarf::DW_CHILDREN_no
),
152 DIEAbbrev
&getAbbrev() { return Abbrev
; }
153 const DIEAbbrev
&getAbbrev() const { return Abbrev
; }
154 unsigned getAbbrevNumber() const { return Abbrev
.getNumber(); }
155 dwarf::Tag
getTag() const { return Abbrev
.getTag(); }
156 unsigned getOffset() const { return Offset
; }
157 unsigned getSize() const { return Size
; }
158 const std::vector
<std::unique_ptr
<DIE
>> &getChildren() const {
161 const SmallVectorImpl
<DIEValue
*> &getValues() const { return Values
; }
162 DIE
*getParent() const { return Parent
; }
163 /// Climb up the parent chain to get the compile or type unit DIE this DIE
165 const DIE
*getUnit() const;
166 /// Similar to getUnit, returns null when DIE is not added to an
168 const DIE
*getUnitOrNull() const;
169 void setOffset(unsigned O
) { Offset
= O
; }
170 void setSize(unsigned S
) { Size
= S
; }
172 /// addValue - Add a value and attributes to a DIE.
174 void addValue(dwarf::Attribute Attribute
, dwarf::Form Form
, DIEValue
*Value
) {
175 Abbrev
.AddAttribute(Attribute
, Form
);
176 Values
.push_back(Value
);
179 /// addChild - Add a child to the DIE.
181 void addChild(std::unique_ptr
<DIE
> Child
) {
182 assert(!Child
->getParent());
183 Abbrev
.setChildrenFlag(dwarf::DW_CHILDREN_yes
);
184 Child
->Parent
= this;
185 Children
.push_back(std::move(Child
));
188 /// findAttribute - Find a value in the DIE with the attribute given,
189 /// returns NULL if no such attribute exists.
190 DIEValue
*findAttribute(dwarf::Attribute Attribute
) const;
193 void print(raw_ostream
&O
, unsigned IndentCount
= 0) const;
198 //===--------------------------------------------------------------------===//
199 /// DIEValue - A debug information entry value. Some of these roughly correlate
200 /// to DWARF attribute classes.
203 virtual void anchor();
220 /// Ty - Type of data stored in the value.
224 explicit DIEValue(Type T
) : Ty(T
) {}
225 virtual ~DIEValue() {}
229 Type
getType() const { return Ty
; }
231 /// EmitValue - Emit value via the Dwarf writer.
233 virtual void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const = 0;
235 /// SizeOf - Return the size of a value in bytes.
237 virtual unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const = 0;
240 virtual void print(raw_ostream
&O
) const = 0;
245 //===--------------------------------------------------------------------===//
246 /// DIEInteger - An integer value DIE.
248 class DIEInteger
: public DIEValue
{
252 explicit DIEInteger(uint64_t I
) : DIEValue(isInteger
), Integer(I
) {}
254 /// BestForm - Choose the best form for integer.
256 static dwarf::Form
BestForm(bool IsSigned
, uint64_t Int
) {
258 const int64_t SignedInt
= Int
;
259 if ((char)Int
== SignedInt
)
260 return dwarf::DW_FORM_data1
;
261 if ((short)Int
== SignedInt
)
262 return dwarf::DW_FORM_data2
;
263 if ((int)Int
== SignedInt
)
264 return dwarf::DW_FORM_data4
;
266 if ((unsigned char)Int
== Int
)
267 return dwarf::DW_FORM_data1
;
268 if ((unsigned short)Int
== Int
)
269 return dwarf::DW_FORM_data2
;
270 if ((unsigned int)Int
== Int
)
271 return dwarf::DW_FORM_data4
;
273 return dwarf::DW_FORM_data8
;
276 /// EmitValue - Emit integer of appropriate size.
278 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
280 uint64_t getValue() const { return Integer
; }
282 /// SizeOf - Determine size of integer value in bytes.
284 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
286 // Implement isa/cast/dyncast.
287 static bool classof(const DIEValue
*I
) { return I
->getType() == isInteger
; }
290 void print(raw_ostream
&O
) const override
;
294 //===--------------------------------------------------------------------===//
295 /// DIEExpr - An expression DIE.
297 class DIEExpr
: public DIEValue
{
301 explicit DIEExpr(const MCExpr
*E
) : DIEValue(isExpr
), Expr(E
) {}
303 /// EmitValue - Emit expression value.
305 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
307 /// getValue - Get MCExpr.
309 const MCExpr
*getValue() const { return Expr
; }
311 /// SizeOf - Determine size of expression value in bytes.
313 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
315 // Implement isa/cast/dyncast.
316 static bool classof(const DIEValue
*E
) { return E
->getType() == isExpr
; }
319 void print(raw_ostream
&O
) const override
;
323 //===--------------------------------------------------------------------===//
324 /// DIELabel - A label DIE.
326 class DIELabel
: public DIEValue
{
327 const MCSymbol
*Label
;
330 explicit DIELabel(const MCSymbol
*L
) : DIEValue(isLabel
), Label(L
) {}
332 /// EmitValue - Emit label value.
334 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
336 /// getValue - Get MCSymbol.
338 const MCSymbol
*getValue() const { return Label
; }
340 /// SizeOf - Determine size of label value in bytes.
342 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
344 // Implement isa/cast/dyncast.
345 static bool classof(const DIEValue
*L
) { return L
->getType() == isLabel
; }
348 void print(raw_ostream
&O
) const override
;
352 //===--------------------------------------------------------------------===//
353 /// DIEDelta - A simple label difference DIE.
355 class DIEDelta
: public DIEValue
{
356 const MCSymbol
*LabelHi
;
357 const MCSymbol
*LabelLo
;
360 DIEDelta(const MCSymbol
*Hi
, const MCSymbol
*Lo
)
361 : DIEValue(isDelta
), LabelHi(Hi
), LabelLo(Lo
) {}
363 /// EmitValue - Emit delta value.
365 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
367 /// SizeOf - Determine size of delta value in bytes.
369 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
371 // Implement isa/cast/dyncast.
372 static bool classof(const DIEValue
*D
) { return D
->getType() == isDelta
; }
375 void print(raw_ostream
&O
) const override
;
379 //===--------------------------------------------------------------------===//
380 /// DIEString - A container for string values.
382 class DIEString
: public DIEValue
{
383 const DIEValue
*Access
;
387 DIEString(const DIEValue
*Acc
, StringRef S
)
388 : DIEValue(isString
), Access(Acc
), Str(S
) {}
390 /// getString - Grab the string out of the object.
391 StringRef
getString() const { return Str
; }
393 /// EmitValue - Emit delta value.
395 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
397 /// SizeOf - Determine size of delta value in bytes.
399 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
401 // Implement isa/cast/dyncast.
402 static bool classof(const DIEValue
*D
) { return D
->getType() == isString
; }
405 void print(raw_ostream
&O
) const override
;
409 //===--------------------------------------------------------------------===//
410 /// DIEEntry - A pointer to another debug information entry. An instance of
411 /// this class can also be used as a proxy for a debug information entry not
412 /// yet defined (ie. types.)
413 class DIEEntry
: public DIEValue
{
417 explicit DIEEntry(DIE
&E
) : DIEValue(isEntry
), Entry(E
) {
420 DIE
&getEntry() const { return Entry
; }
422 /// EmitValue - Emit debug information entry offset.
424 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
426 /// SizeOf - Determine size of debug information entry in bytes.
428 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
{
429 return Form
== dwarf::DW_FORM_ref_addr
? getRefAddrSize(AP
)
433 /// Returns size of a ref_addr entry.
434 static unsigned getRefAddrSize(AsmPrinter
*AP
);
436 // Implement isa/cast/dyncast.
437 static bool classof(const DIEValue
*E
) { return E
->getType() == isEntry
; }
440 void print(raw_ostream
&O
) const override
;
444 //===--------------------------------------------------------------------===//
445 /// \brief A signature reference to a type unit.
446 class DIETypeSignature
: public DIEValue
{
447 const DwarfTypeUnit
&Unit
;
450 explicit DIETypeSignature(const DwarfTypeUnit
&Unit
)
451 : DIEValue(isTypeSignature
), Unit(Unit
) {}
453 /// \brief Emit type unit signature.
454 void EmitValue(AsmPrinter
*Asm
, dwarf::Form Form
) const override
;
456 /// Returns size of a ref_sig8 entry.
457 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
{
458 assert(Form
== dwarf::DW_FORM_ref_sig8
);
462 // \brief Implement isa/cast/dyncast.
463 static bool classof(const DIEValue
*E
) {
464 return E
->getType() == isTypeSignature
;
467 void print(raw_ostream
&O
) const override
;
472 //===--------------------------------------------------------------------===//
473 /// DIELoc - Represents an expression location.
475 class DIELoc
: public DIEValue
, public DIE
{
476 mutable unsigned Size
; // Size in bytes excluding size header.
478 DIELoc() : DIEValue(isLoc
), Size(0) {}
480 /// ComputeSize - Calculate the size of the location expression.
482 unsigned ComputeSize(AsmPrinter
*AP
) const;
484 /// BestForm - Choose the best form for data.
486 dwarf::Form
BestForm(unsigned DwarfVersion
) const {
487 if (DwarfVersion
> 3)
488 return dwarf::DW_FORM_exprloc
;
489 // Pre-DWARF4 location expressions were blocks and not exprloc.
490 if ((unsigned char)Size
== Size
)
491 return dwarf::DW_FORM_block1
;
492 if ((unsigned short)Size
== Size
)
493 return dwarf::DW_FORM_block2
;
494 if ((unsigned int)Size
== Size
)
495 return dwarf::DW_FORM_block4
;
496 return dwarf::DW_FORM_block
;
499 /// EmitValue - Emit location data.
501 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
503 /// SizeOf - Determine size of location data in bytes.
505 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
507 // Implement isa/cast/dyncast.
508 static bool classof(const DIEValue
*E
) { return E
->getType() == isLoc
; }
511 void print(raw_ostream
&O
) const override
;
515 //===--------------------------------------------------------------------===//
516 /// DIEBlock - Represents a block of values.
518 class DIEBlock
: public DIEValue
, public DIE
{
519 mutable unsigned Size
; // Size in bytes excluding size header.
521 DIEBlock() : DIEValue(isBlock
), Size(0) {}
523 /// ComputeSize - Calculate the size of the location expression.
525 unsigned ComputeSize(AsmPrinter
*AP
) const;
527 /// BestForm - Choose the best form for data.
529 dwarf::Form
BestForm() const {
530 if ((unsigned char)Size
== Size
)
531 return dwarf::DW_FORM_block1
;
532 if ((unsigned short)Size
== Size
)
533 return dwarf::DW_FORM_block2
;
534 if ((unsigned int)Size
== Size
)
535 return dwarf::DW_FORM_block4
;
536 return dwarf::DW_FORM_block
;
539 /// EmitValue - Emit location data.
541 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
543 /// SizeOf - Determine size of location data in bytes.
545 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
547 // Implement isa/cast/dyncast.
548 static bool classof(const DIEValue
*E
) { return E
->getType() == isBlock
; }
551 void print(raw_ostream
&O
) const override
;
555 //===--------------------------------------------------------------------===//
556 /// DIELocList - Represents a pointer to a location list in the debug_loc
559 class DIELocList
: public DIEValue
{
560 // Index into the .debug_loc vector.
564 DIELocList(size_t I
) : DIEValue(isLocList
), Index(I
) {}
566 /// getValue - Grab the current index out.
567 size_t getValue() const { return Index
; }
569 /// EmitValue - Emit location data.
571 void EmitValue(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
573 /// SizeOf - Determine size of location data in bytes.
575 unsigned SizeOf(AsmPrinter
*AP
, dwarf::Form Form
) const override
;
577 // Implement isa/cast/dyncast.
578 static bool classof(const DIEValue
*E
) { return E
->getType() == isLocList
; }
581 void print(raw_ostream
&O
) const override
;
585 } // end llvm namespace