David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- C++ -*--===// |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 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 | // This file contains support for writing dwarf compile unit. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 16 | |
Eric Christopher | 9e429ae | 2013-10-05 00:27:02 +0000 | [diff] [blame] | 17 | #include "DwarfDebug.h" |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseMap.h" |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/Optional.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringMap.h" |
Adrian Prantl | 702bf5a | 2014-03-18 02:34:52 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/AsmPrinter.h" |
Frederic Riss | e541e0b | 2015-01-05 21:29:41 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/DIE.h" |
Chandler Carruth | 12664a0 | 2014-03-06 00:22:06 +0000 | [diff] [blame] | 23 | #include "llvm/IR/DIBuilder.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 24 | #include "llvm/IR/DebugInfo.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCDwarf.h" |
David Blaikie | f3cd7c5 | 2013-06-28 20:05:04 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCExpr.h" |
David Blaikie | 7d73460 | 2013-12-06 22:33:05 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCSection.h" |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
| 30 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 31 | class MachineLocation; |
| 32 | class MachineOperand; |
| 33 | class ConstantInt; |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 34 | class ConstantFP; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 35 | class DbgVariable; |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 36 | class DwarfCompileUnit; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 37 | |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 38 | // Data structure to hold a range for range lists. |
| 39 | class RangeSpan { |
| 40 | public: |
| 41 | RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {} |
Eric Christopher | 270ba4a | 2013-12-04 19:06:58 +0000 | [diff] [blame] | 42 | const MCSymbol *getStart() const { return Start; } |
| 43 | const MCSymbol *getEnd() const { return End; } |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 44 | void setEnd(const MCSymbol *E) { End = E; } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | const MCSymbol *Start, *End; |
| 48 | }; |
| 49 | |
| 50 | class RangeSpanList { |
| 51 | private: |
| 52 | // Index for locating within the debug_range section this particular span. |
Eric Christopher | f879064 | 2013-12-04 22:04:50 +0000 | [diff] [blame] | 53 | MCSymbol *RangeSym; |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 54 | // List of ranges. |
| 55 | SmallVector<RangeSpan, 2> Ranges; |
| 56 | |
| 57 | public: |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 58 | RangeSpanList(MCSymbol *Sym, SmallVector<RangeSpan, 2> Ranges) |
| 59 | : RangeSym(Sym), Ranges(std::move(Ranges)) {} |
Eric Christopher | f879064 | 2013-12-04 22:04:50 +0000 | [diff] [blame] | 60 | MCSymbol *getSym() const { return RangeSym; } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 61 | const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; } |
| 62 | void addRange(RangeSpan Range) { Ranges.push_back(Range); } |
| 63 | }; |
| 64 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 66 | /// This dwarf writer support class manages information associated with a |
| 67 | /// source file. |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 68 | class DwarfUnit : public DIEUnit { |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 69 | protected: |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 70 | /// MDNode for the compile unit. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 71 | const DICompileUnit *CUNode; |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 72 | |
Duncan P. N. Exon Smith | 4fb1f9c | 2015-06-25 23:46:41 +0000 | [diff] [blame] | 73 | // All DIEValues are allocated through this allocator. |
| 74 | BumpPtrAllocator DIEValueAllocator; |
| 75 | |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 76 | /// Target of Dwarf emission. |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 77 | AsmPrinter *Asm; |
| 78 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 79 | // Holders for some common dwarf information. |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 80 | DwarfDebug *DD; |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 81 | DwarfFile *DU; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 82 | |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 83 | /// An anonymous type for index type. Owned by DIEUnit. |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 84 | DIE *IndexTyDie; |
| 85 | |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 86 | /// Tracks the mapping of unit level debug information variables to debug |
| 87 | /// information entries. |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 88 | DenseMap<const MDNode *, DIE *> MDNodeToDieMap; |
| 89 | |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 90 | /// A list of all the DIEBlocks in use. |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 91 | std::vector<DIEBlock *> DIEBlocks; |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 92 | |
| 93 | /// A list of all the DIELocs in use. |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 94 | std::vector<DIELoc *> DIELocs; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 95 | |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 96 | /// This map is used to keep track of subprogram DIEs that need |
| 97 | /// DW_AT_containing_type attribute. This attribute points to a DIE that |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 98 | /// corresponds to the MDNode mapped with the subprogram DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 99 | DenseMap<DIE *, const DINode *> ContainingTypeMap; |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 100 | |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 101 | DwarfUnit(dwarf::Tag, const DICompileUnit *CU, AsmPrinter *A, DwarfDebug *DW, |
| 102 | DwarfFile *DWU); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 103 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 104 | bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie); |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 105 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 106 | bool shareAcrossDWOCUs() const; |
| 107 | bool isShareableAcrossCUs(const DINode *D) const; |
| 108 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 109 | public: |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 110 | // Accessors. |
Adrian Prantl | 00dbc2a | 2015-01-12 22:19:26 +0000 | [diff] [blame] | 111 | AsmPrinter* getAsmPrinter() const { return Asm; } |
Duncan P. N. Exon Smith | 35ef22c | 2015-04-15 23:19:27 +0000 | [diff] [blame] | 112 | uint16_t getLanguage() const { return CUNode->getSourceLanguage(); } |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 113 | const DICompileUnit *getCUNode() const { return CUNode; } |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 114 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 115 | /// Return true if this compile unit has something to write out. |
David Blaikie | e40caae | 2016-12-01 21:59:09 +0000 | [diff] [blame] | 116 | bool hasContent() const { return getUnitDie().hasChildren(); } |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 117 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 118 | /// Get string containing language specific context for a global name. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 119 | /// |
| 120 | /// Walks the metadata parent chain in a language specific manner (using the |
| 121 | /// compile unit language) and returns it as a string. This is done at the |
| 122 | /// metadata level because DIEs may not currently have been added to the |
| 123 | /// parent context and walking the DIEs looking for names is more expensive |
| 124 | /// than walking the metadata. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 125 | std::string getParentContextString(const DIScope *Context) const; |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 126 | |
David Blaikie | 98cf172 | 2014-11-02 06:06:14 +0000 | [diff] [blame] | 127 | /// Add a new global name to the compile unit. |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 128 | virtual void addGlobalName(StringRef Name, const DIE &Die, |
| 129 | const DIScope *Context) = 0; |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 130 | |
David Blaikie | 98cf172 | 2014-11-02 06:06:14 +0000 | [diff] [blame] | 131 | /// Add a new global type to the compile unit. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 132 | virtual void addGlobalType(const DIType *Ty, const DIE &Die, |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 133 | const DIScope *Context) = 0; |
David Blaikie | 98cf172 | 2014-11-02 06:06:14 +0000 | [diff] [blame] | 134 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 135 | /// Returns the DIE map slot for the specified debug variable. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 136 | /// |
| 137 | /// We delegate the request to DwarfDebug when the MDNode can be part of the |
| 138 | /// type system, since DIEs for the type system can be shared across CUs and |
| 139 | /// the mappings are kept in DwarfDebug. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 140 | DIE *getDIE(const DINode *D) const; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 141 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 142 | /// Returns a fresh newly allocated DIELoc. |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 143 | DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc; } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 144 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 145 | /// Insert DIE into the map. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 146 | /// |
| 147 | /// We delegate the request to DwarfDebug when the MDNode can be part of the |
| 148 | /// type system, since DIEs for the type system can be shared across CUs and |
| 149 | /// the mappings are kept in DwarfDebug. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 150 | void insertDIE(const DINode *Desc, DIE *D); |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 151 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 152 | /// Add a flag that is true to the DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 153 | void addFlag(DIE &Die, dwarf::Attribute Attribute); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 154 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 155 | /// Add an unsigned integer attribute data and value. |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 156 | void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, |
| 157 | Optional<dwarf::Form> Form, uint64_t Integer); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 158 | |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 159 | void addUInt(DIEValueList &Block, dwarf::Form Form, uint64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 160 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 161 | /// Add an signed integer attribute data and value. |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 162 | void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, |
| 163 | Optional<dwarf::Form> Form, int64_t Integer); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 164 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 165 | void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 166 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 167 | /// Add a string attribute data and value. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 168 | /// |
| 169 | /// We always emit a reference to the string pool instead of immediate |
| 170 | /// strings so that DIEs have more predictable sizes. In the case of split |
| 171 | /// dwarf we emit an index into another table which gets us the static offset |
| 172 | /// into the string table. |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 173 | void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 174 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 175 | /// Add a Dwarf label attribute data and value. |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 176 | DIEValueList::value_iterator addLabel(DIEValueList &Die, |
| 177 | dwarf::Attribute Attribute, |
| 178 | dwarf::Form Form, |
| 179 | const MCSymbol *Label); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 180 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 181 | void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 182 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 183 | /// Add an offset into a section attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 184 | void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer); |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 185 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 186 | /// Add a dwarf op address data and value using the form given and an |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 187 | /// op of either DW_FORM_addr or DW_FORM_GNU_addr_index. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 188 | void addOpAddress(DIELoc &Die, const MCSymbol *Label); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 189 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 190 | /// Add a label delta attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 191 | void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 192 | const MCSymbol *Lo); |
| 193 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 194 | /// Add a DIE attribute data and value. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 195 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 196 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 197 | /// Add a DIE attribute data and value. |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 198 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry Entry); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 199 | |
Adrian Prantl | ee5feaf | 2015-07-15 17:01:41 +0000 | [diff] [blame] | 200 | /// Add a type's DW_AT_signature and set the declaration flag. |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 201 | void addDIETypeSignature(DIE &Die, uint64_t Signature); |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 202 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 203 | /// Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 204 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 205 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 206 | /// Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 207 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 208 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 209 | /// Add location information to specified debug information entry. |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 210 | void addSourceLine(DIE &Die, unsigned Line, const DIFile *File); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 211 | void addSourceLine(DIE &Die, const DILocalVariable *V); |
| 212 | void addSourceLine(DIE &Die, const DIGlobalVariable *G); |
| 213 | void addSourceLine(DIE &Die, const DISubprogram *SP); |
| 214 | void addSourceLine(DIE &Die, const DIType *Ty); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 215 | void addSourceLine(DIE &Die, const DIObjCProperty *Ty); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 216 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 217 | /// Add constant value entry in variable DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 218 | void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty); |
| 219 | void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty); |
| 220 | void addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 221 | void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned); |
David Blaikie | 60cae1b | 2014-05-11 16:08:41 +0000 | [diff] [blame] | 222 | void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 223 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 224 | /// Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 225 | void addConstantFPValue(DIE &Die, const MachineOperand &MO); |
| 226 | void addConstantFPValue(DIE &Die, const ConstantFP *CFP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 227 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 228 | /// Add a linkage name, if it isn't empty. |
Paul Robinson | 857b443 | 2015-03-10 22:44:45 +0000 | [diff] [blame] | 229 | void addLinkageName(DIE &Die, StringRef LinkageName); |
| 230 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 231 | /// Add template parameters in buffer. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 232 | void addTemplateParams(DIE &Buffer, DINodeArray TParams); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 233 | |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 234 | /// Add thrown types. |
| 235 | void addThrownTypes(DIE &Die, DINodeArray ThrownTypes); |
| 236 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 237 | // FIXME: Should be reformulated in terms of addComplexAddress. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 238 | /// Start with the address based on the location provided, and generate the |
| 239 | /// DWARF information necessary to find the actual Block variable (navigating |
| 240 | /// the Block struct) based on the starting location. Add the DWARF |
| 241 | /// information to the die. Obsolete, please use addComplexAddress instead. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 242 | void addBlockByrefAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 243 | dwarf::Attribute Attribute, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 244 | const MachineLocation &Location); |
| 245 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 246 | /// Add a new type attribute to the specified entity. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 247 | /// |
| 248 | /// This takes and attribute parameter because DW_AT_friend attributes are |
| 249 | /// also type references. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 250 | void addType(DIE &Entity, const DIType *Ty, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 251 | dwarf::Attribute Attribute = dwarf::DW_AT_type); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 252 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 253 | DIE *getOrCreateNameSpace(const DINamespace *NS); |
Adrian Prantl | 08a388b | 2015-06-30 02:13:04 +0000 | [diff] [blame] | 254 | DIE *getOrCreateModule(const DIModule *M); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 255 | DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 256 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 257 | void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, |
Dehao Chen | 1ce8d6c | 2017-01-19 00:44:11 +0000 | [diff] [blame] | 258 | bool SkipSPAttributes = false); |
David Blaikie | 7f91686 | 2014-05-27 18:37:38 +0000 | [diff] [blame] | 259 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 260 | /// Find existing DIE or create new DIE for the given type. |
David Blaikie | d51dea6 | 2015-07-01 18:07:16 +0000 | [diff] [blame] | 261 | DIE *getOrCreateTypeDIE(const MDNode *N); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 262 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 263 | /// Get context owner's DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 264 | DIE *getOrCreateContextDIE(const DIScope *Context); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 265 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 266 | /// Construct DIEs for types that contain vtables. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 267 | void constructContainingTypeDIEs(); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 268 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 269 | /// Construct function argument DIEs. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 270 | void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args); |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 271 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 272 | /// Create a DIE with the given Tag, add the DIE to its parent, and |
| 273 | /// call insertDIE if MD is not null. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 274 | DIE &createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N = nullptr); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 275 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame^] | 276 | bool useSegmentedStringOffsetsTable() const { |
| 277 | return DD->useSegmentedStringOffsetsTable(); |
| 278 | } |
| 279 | |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 280 | /// Compute the size of a header for this unit, not including the initial |
| 281 | /// length field. |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 282 | virtual unsigned getHeaderSize() const { |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 283 | return sizeof(int16_t) + // DWARF version number |
| 284 | sizeof(int32_t) + // Offset Into Abbrev. Section |
Paul Robinson | cddd604 | 2017-02-28 20:24:55 +0000 | [diff] [blame] | 285 | sizeof(int8_t) + // Pointer Size (in bytes) |
| 286 | (DD->getDwarfVersion() >= 5 ? sizeof(int8_t) |
| 287 | : 0); // DWARF v5 unit type |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /// Emit the header for this unit, not including the initial length field. |
Paul Robinson | cddd604 | 2017-02-28 20:24:55 +0000 | [diff] [blame] | 291 | virtual void emitHeader(bool UseOffsets) = 0; |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 292 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame^] | 293 | /// Add the DW_AT_str_offsets_base attribute to the unit DIE. |
| 294 | void addStringOffsetsStart(); |
| 295 | |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 296 | virtual DwarfCompileUnit &getCU() = 0; |
David Blaikie | d696fac | 2014-02-12 00:32:05 +0000 | [diff] [blame] | 297 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 298 | void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy); |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 299 | |
Wolfgang Pieb | e60147c | 2017-06-30 00:27:45 +0000 | [diff] [blame] | 300 | /// addSectionDelta - Add a label delta attribute data and value. |
| 301 | DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute, |
| 302 | const MCSymbol *Hi, const MCSymbol *Lo); |
| 303 | |
| 304 | /// Add a Dwarf section label attribute data and value. |
| 305 | DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute, |
| 306 | const MCSymbol *Label, |
| 307 | const MCSymbol *Sec); |
| 308 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 309 | protected: |
David Blaikie | c0bb21f | 2017-04-22 02:18:00 +0000 | [diff] [blame] | 310 | ~DwarfUnit(); |
| 311 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 312 | /// Create new static data member DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 313 | DIE *getOrCreateStaticMemberDIE(const DIDerivedType *DT); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 314 | |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 315 | /// Look up the source ID for the given file. If none currently exists, |
| 316 | /// create a new ID and insert it in the line table. |
| 317 | virtual unsigned getOrCreateSourceID(const DIFile *File) = 0; |
| 318 | |
| 319 | /// If the \p File has an MD5 checksum, return it as an MD5Result |
| 320 | /// allocated in the MCContext. |
| 321 | MD5::MD5Result *getMD5AsBytes(const DIFile *File); |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 322 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 323 | /// Look in the DwarfDebug map for the MDNode that corresponds to the |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 324 | /// reference. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 325 | template <typename T> T *resolve(TypedDINodeRef<T> Ref) const { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 326 | return Ref.resolve(); |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 327 | } |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 328 | |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 329 | /// If this is a named finished type then include it in the list of types for |
| 330 | /// the accelerator tables. |
| 331 | void updateAcceleratorTables(const DIScope *Context, const DIType *Ty, |
| 332 | const DIE &TyDIE); |
| 333 | |
Paul Robinson | cddd604 | 2017-02-28 20:24:55 +0000 | [diff] [blame] | 334 | /// Emit the common part of the header for this unit. |
| 335 | void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT); |
| 336 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 337 | private: |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 338 | void constructTypeDIE(DIE &Buffer, const DIBasicType *BTy); |
| 339 | void constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy); |
| 340 | void constructTypeDIE(DIE &Buffer, const DISubroutineType *DTy); |
| 341 | void constructSubrangeDIE(DIE &Buffer, const DISubrange *SR, DIE *IndexTy); |
| 342 | void constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy); |
| 343 | void constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy); |
| 344 | void constructMemberDIE(DIE &Buffer, const DIDerivedType *DT); |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 345 | void constructTemplateTypeParameterDIE(DIE &Buffer, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 346 | const DITemplateTypeParameter *TP); |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 347 | void constructTemplateValueParameterDIE(DIE &Buffer, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 348 | const DITemplateValueParameter *TVP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 349 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 350 | /// Return the default lower bound for an array. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 351 | /// |
| 352 | /// If the DWARF version doesn't handle the language, return -1. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 353 | int64_t getDefaultLowerBound() const; |
| 354 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 355 | /// Get an anonymous type for index type. |
David Blaikie | 871c2d9 | 2014-11-02 03:09:13 +0000 | [diff] [blame] | 356 | DIE *getIndexTyDie(); |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 357 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 358 | /// Set D as anonymous type for index which can be reused later. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 359 | void setIndexTyDie(DIE *D) { IndexTyDie = D; } |
| 360 | |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 361 | virtual bool isDwoUnit() const = 0; |
David Blaikie | 85366ac | 2017-04-22 07:53:44 +0000 | [diff] [blame] | 362 | const MCSymbol *getCrossSectionRelativeBaseAddress() const override; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 363 | }; |
| 364 | |
David Blaikie | c0bb21f | 2017-04-22 02:18:00 +0000 | [diff] [blame] | 365 | class DwarfTypeUnit final : public DwarfUnit { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 366 | uint64_t TypeSignature; |
| 367 | const DIE *Ty; |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 368 | DwarfCompileUnit &CU; |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 369 | MCDwarfDwoLineTable *SplitLineTable; |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 370 | |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 371 | unsigned getOrCreateSourceID(const DIFile *File) override; |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 372 | bool isDwoUnit() const override; |
| 373 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 374 | public: |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 375 | DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, |
| 376 | DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable = nullptr); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 377 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 378 | void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } |
| 379 | void setType(const DIE *Ty) { this->Ty = Ty; } |
| 380 | |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 381 | /// Get context owner's DIE. |
| 382 | DIE *createTypeDIE(const DICompositeType *Ty); |
| 383 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 384 | /// Emit the header for this unit, not including the initial length field. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 385 | void emitHeader(bool UseOffsets) override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 386 | unsigned getHeaderSize() const override { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 387 | return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature |
| 388 | sizeof(uint32_t); // Type DIE Offset |
| 389 | } |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 390 | void addGlobalName(StringRef Name, const DIE &Die, |
| 391 | const DIScope *Context) override; |
| 392 | void addGlobalType(const DIType *Ty, const DIE &Die, |
| 393 | const DIScope *Context) override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 394 | DwarfCompileUnit &getCU() override { return CU; } |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 395 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 396 | } // end llvm namespace |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 397 | #endif |