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