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