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