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 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 130 | /// Add a flag that is true to the DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 131 | void addFlag(DIE &Die, dwarf::Attribute Attribute); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 132 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 133 | /// Add an unsigned integer attribute data and value. |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 134 | void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, |
| 135 | Optional<dwarf::Form> Form, uint64_t Integer); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 136 | |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 137 | void addUInt(DIEValueList &Block, dwarf::Form Form, uint64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 138 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 139 | /// Add an signed integer attribute data and value. |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 140 | void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, |
| 141 | Optional<dwarf::Form> Form, int64_t Integer); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 142 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 143 | void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 144 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 145 | /// Add a string attribute data and value. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 146 | /// |
| 147 | /// We always emit a reference to the string pool instead of immediate |
| 148 | /// strings so that DIEs have more predictable sizes. In the case of split |
| 149 | /// dwarf we emit an index into another table which gets us the static offset |
| 150 | /// into the string table. |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 151 | void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 152 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 153 | /// Add a Dwarf label attribute data and value. |
Duncan P. N. Exon Smith | 55a868a | 2015-08-02 20:44:46 +0000 | [diff] [blame] | 154 | DIEValueList::value_iterator addLabel(DIEValueList &Die, |
| 155 | dwarf::Attribute Attribute, |
| 156 | dwarf::Form Form, |
| 157 | const MCSymbol *Label); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 158 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 159 | void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 160 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 161 | /// Add an offset into a section attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 162 | void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer); |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 163 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 164 | /// 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] | 165 | /// op of either DW_FORM_addr or DW_FORM_GNU_addr_index. |
Fangrui Song | cb0bab8 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 166 | void addOpAddress(DIELoc &Die, const MCSymbol *Sym); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 167 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 168 | /// Add a label delta attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 169 | void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 170 | const MCSymbol *Lo); |
| 171 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 172 | /// Add a DIE attribute data and value. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 173 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 174 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 175 | /// Add a DIE attribute data and value. |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 176 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry Entry); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 177 | |
Adrian Prantl | ee5feaf | 2015-07-15 17:01:41 +0000 | [diff] [blame] | 178 | /// Add a type's DW_AT_signature and set the declaration flag. |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 179 | void addDIETypeSignature(DIE &Die, uint64_t Signature); |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 180 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 181 | /// Add block data. |
Fangrui Song | cb0bab8 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 182 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 183 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 184 | /// Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 185 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 186 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 187 | /// Add location information to specified debug information entry. |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 188 | void addSourceLine(DIE &Die, unsigned Line, const DIFile *File); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 189 | void addSourceLine(DIE &Die, const DILocalVariable *V); |
| 190 | void addSourceLine(DIE &Die, const DIGlobalVariable *G); |
| 191 | void addSourceLine(DIE &Die, const DISubprogram *SP); |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame] | 192 | void addSourceLine(DIE &Die, const DILabel *L); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 193 | void addSourceLine(DIE &Die, const DIType *Ty); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 194 | void addSourceLine(DIE &Die, const DIObjCProperty *Ty); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 195 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 196 | /// Add constant value entry in variable DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 197 | void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty); |
| 198 | void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty); |
| 199 | void addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 200 | void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned); |
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 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 216 | // FIXME: Should be reformulated in terms of addComplexAddress. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 217 | /// Start with the address based on the location provided, and generate the |
| 218 | /// DWARF information necessary to find the actual Block variable (navigating |
| 219 | /// the Block struct) based on the starting location. Add the DWARF |
| 220 | /// information to the die. Obsolete, please use addComplexAddress instead. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 221 | void addBlockByrefAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 222 | dwarf::Attribute Attribute, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 223 | const MachineLocation &Location); |
| 224 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 225 | /// Add a new type attribute to the specified entity. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 226 | /// |
| 227 | /// This takes and attribute parameter because DW_AT_friend attributes are |
| 228 | /// also type references. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 229 | void addType(DIE &Entity, const DIType *Ty, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 230 | dwarf::Attribute Attribute = dwarf::DW_AT_type); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 231 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 232 | DIE *getOrCreateNameSpace(const DINamespace *NS); |
Adrian Prantl | 08a388b | 2015-06-30 02:13:04 +0000 | [diff] [blame] | 233 | DIE *getOrCreateModule(const DIModule *M); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 234 | DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 235 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 236 | void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, |
Dehao Chen | 1ce8d6c | 2017-01-19 00:44:11 +0000 | [diff] [blame] | 237 | bool SkipSPAttributes = false); |
David Blaikie | 7f91686 | 2014-05-27 18:37:38 +0000 | [diff] [blame] | 238 | |
Eugene Leviant | daea28a | 2019-03-04 07:15:36 +0000 | [diff] [blame] | 239 | /// Creates type DIE with specific context. |
| 240 | DIE *createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty); |
| 241 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 242 | /// Find existing DIE or create new DIE for the given type. |
Fangrui Song | cb0bab8 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 243 | DIE *getOrCreateTypeDIE(const MDNode *TyNode); |
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 | /// Get context owner's DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 246 | DIE *getOrCreateContextDIE(const DIScope *Context); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 247 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 248 | /// Construct DIEs for types that contain vtables. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 249 | void constructContainingTypeDIEs(); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 250 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 251 | /// Construct function argument DIEs. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 252 | void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args); |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 253 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 254 | /// Create a DIE with the given Tag, add the DIE to its parent, and |
| 255 | /// call insertDIE if MD is not null. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 256 | DIE &createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N = nullptr); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 257 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 258 | bool useSegmentedStringOffsetsTable() const { |
| 259 | return DD->useSegmentedStringOffsetsTable(); |
| 260 | } |
| 261 | |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 262 | /// Compute the size of a header for this unit, not including the initial |
| 263 | /// length field. |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 264 | virtual unsigned getHeaderSize() const { |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 265 | return sizeof(int16_t) + // DWARF version number |
| 266 | sizeof(int32_t) + // Offset Into Abbrev. Section |
Paul Robinson | cddd604 | 2017-02-28 20:24:55 +0000 | [diff] [blame] | 267 | sizeof(int8_t) + // Pointer Size (in bytes) |
| 268 | (DD->getDwarfVersion() >= 5 ? sizeof(int8_t) |
| 269 | : 0); // DWARF v5 unit type |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /// Emit the header for this unit, not including the initial length field. |
Paul Robinson | cddd604 | 2017-02-28 20:24:55 +0000 | [diff] [blame] | 273 | virtual void emitHeader(bool UseOffsets) = 0; |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 274 | |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 275 | /// Add the DW_AT_str_offsets_base attribute to the unit DIE. |
| 276 | void addStringOffsetsStart(); |
| 277 | |
Wolfgang Pieb | fcf3810 | 2018-07-12 18:18:21 +0000 | [diff] [blame] | 278 | /// Add the DW_AT_rnglists_base attribute to the unit DIE. |
| 279 | void addRnglistsBase(); |
| 280 | |
George Rimar | 088d96b | 2018-10-26 11:25:12 +0000 | [diff] [blame] | 281 | /// Add the DW_AT_loclists_base attribute to the unit DIE. |
| 282 | void addLoclistsBase(); |
| 283 | |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 284 | virtual DwarfCompileUnit &getCU() = 0; |
David Blaikie | d696fac | 2014-02-12 00:32:05 +0000 | [diff] [blame] | 285 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 286 | void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy); |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 287 | |
Wolfgang Pieb | e60147c | 2017-06-30 00:27:45 +0000 | [diff] [blame] | 288 | /// addSectionDelta - Add a label delta attribute data and value. |
| 289 | DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute, |
| 290 | const MCSymbol *Hi, const MCSymbol *Lo); |
| 291 | |
| 292 | /// Add a Dwarf section label attribute data and value. |
| 293 | DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute, |
| 294 | const MCSymbol *Label, |
| 295 | const MCSymbol *Sec); |
| 296 | |
Paul Robinson | b271f31 | 2018-03-29 17:16:41 +0000 | [diff] [blame] | 297 | /// If the \p File has an MD5 checksum, return it as an MD5Result |
| 298 | /// allocated in the MCContext. |
Eric Christopher | 798e83b | 2019-04-04 23:34:38 +0000 | [diff] [blame] | 299 | Optional<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const; |
Paul Robinson | b271f31 | 2018-03-29 17:16:41 +0000 | [diff] [blame] | 300 | |
David Blaikie | 832c7d9 | 2019-04-24 18:09:44 +0000 | [diff] [blame] | 301 | /// Get context owner's DIE. |
| 302 | DIE *createTypeDIE(const DICompositeType *Ty); |
| 303 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 304 | protected: |
David Blaikie | c0bb21f | 2017-04-22 02:18:00 +0000 | [diff] [blame] | 305 | ~DwarfUnit(); |
| 306 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 307 | /// Create new static data member DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 308 | DIE *getOrCreateStaticMemberDIE(const DIDerivedType *DT); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 309 | |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 310 | /// Look up the source ID for the given file. If none currently exists, |
| 311 | /// create a new ID and insert it in the line table. |
| 312 | virtual unsigned getOrCreateSourceID(const DIFile *File) = 0; |
| 313 | |
Paul Robinson | cddd604 | 2017-02-28 20:24:55 +0000 | [diff] [blame] | 314 | /// Emit the common part of the header for this unit. |
| 315 | void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT); |
| 316 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 317 | private: |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 318 | void constructTypeDIE(DIE &Buffer, const DIBasicType *BTy); |
| 319 | void constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy); |
Fangrui Song | cb0bab8 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 320 | void constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 321 | void constructSubrangeDIE(DIE &Buffer, const DISubrange *SR, DIE *IndexTy); |
| 322 | void constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy); |
| 323 | void constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy); |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 324 | DIE &constructMemberDIE(DIE &Buffer, const DIDerivedType *DT); |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 325 | void constructTemplateTypeParameterDIE(DIE &Buffer, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 326 | const DITemplateTypeParameter *TP); |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 327 | void constructTemplateValueParameterDIE(DIE &Buffer, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 328 | const DITemplateValueParameter *TVP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 329 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 330 | /// Return the default lower bound for an array. |
Duncan P. N. Exon Smith | d89ef16 | 2015-04-20 20:29:51 +0000 | [diff] [blame] | 331 | /// |
| 332 | /// If the DWARF version doesn't handle the language, return -1. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 333 | int64_t getDefaultLowerBound() const; |
| 334 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 335 | /// Get an anonymous type for index type. |
David Blaikie | 871c2d9 | 2014-11-02 03:09:13 +0000 | [diff] [blame] | 336 | DIE *getIndexTyDie(); |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 337 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 338 | /// Set D as anonymous type for index which can be reused later. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 339 | void setIndexTyDie(DIE *D) { IndexTyDie = D; } |
| 340 | |
David Blaikie | 832c7d9 | 2019-04-24 18:09:44 +0000 | [diff] [blame] | 341 | virtual void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) = 0; |
| 342 | |
| 343 | /// If this is a named finished type then include it in the list of types for |
| 344 | /// the accelerator tables. |
| 345 | void updateAcceleratorTables(const DIScope *Context, const DIType *Ty, |
| 346 | const DIE &TyDIE); |
| 347 | |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 348 | virtual bool isDwoUnit() const = 0; |
David Blaikie | 85366ac | 2017-04-22 07:53:44 +0000 | [diff] [blame] | 349 | const MCSymbol *getCrossSectionRelativeBaseAddress() const override; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 350 | }; |
| 351 | |
David Blaikie | c0bb21f | 2017-04-22 02:18:00 +0000 | [diff] [blame] | 352 | class DwarfTypeUnit final : public DwarfUnit { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 353 | uint64_t TypeSignature; |
| 354 | const DIE *Ty; |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 355 | DwarfCompileUnit &CU; |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 356 | MCDwarfDwoLineTable *SplitLineTable; |
Paul Robinson | 7cb26ad | 2018-03-27 21:28:59 +0000 | [diff] [blame] | 357 | bool UsedLineTable = false; |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 358 | |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 359 | unsigned getOrCreateSourceID(const DIFile *File) override; |
David Blaikie | 832c7d9 | 2019-04-24 18:09:44 +0000 | [diff] [blame] | 360 | void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override; |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 361 | bool isDwoUnit() const override; |
| 362 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 363 | public: |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 364 | DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, |
| 365 | DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable = nullptr); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 366 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 367 | void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } |
| 368 | void setType(const DIE *Ty) { this->Ty = Ty; } |
| 369 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 370 | /// Emit the header for this unit, not including the initial length field. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 371 | void emitHeader(bool UseOffsets) override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 372 | unsigned getHeaderSize() const override { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 373 | return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature |
| 374 | sizeof(uint32_t); // Type DIE Offset |
| 375 | } |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 376 | void addGlobalName(StringRef Name, const DIE &Die, |
| 377 | const DIScope *Context) override; |
| 378 | void addGlobalType(const DIType *Ty, const DIE &Die, |
| 379 | const DIScope *Context) override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 380 | DwarfCompileUnit &getCU() override { return CU; } |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 381 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 382 | } // end llvm namespace |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 383 | #endif |