Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit -----*- C++ -*-===// |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf compile unit. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |
| 16 | |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 17 | #include "DbgEntityHistoryCalculator.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 18 | #include "DwarfDebug.h" |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 19 | #include "DwarfUnit.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/ArrayRef.h" |
| 21 | #include "llvm/ADT/DenseMap.h" |
| 22 | #include "llvm/ADT/SmallVector.h" |
| 23 | #include "llvm/ADT/StringMap.h" |
| 24 | #include "llvm/ADT/StringRef.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 25 | #include "llvm/BinaryFormat/Dwarf.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/DIE.h" |
| 27 | #include "llvm/CodeGen/LexicalScopes.h" |
| 28 | #include "llvm/IR/DebugInfoMetadata.h" |
| 29 | #include "llvm/Support/Casting.h" |
| 30 | #include <algorithm> |
| 31 | #include <cassert> |
| 32 | #include <cstdint> |
| 33 | #include <memory> |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 34 | |
| 35 | namespace llvm { |
| 36 | |
| 37 | class AsmPrinter; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 38 | class DwarfFile; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 39 | class GlobalVariable; |
| 40 | class MCExpr; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 41 | class MCSymbol; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 42 | class MDNode; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 43 | |
David Blaikie | c0bb21f | 2017-04-22 02:18:00 +0000 | [diff] [blame] | 44 | class DwarfCompileUnit final : public DwarfUnit { |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 45 | /// A numeric ID unique among all CUs in the module |
| 46 | unsigned UniqueID; |
| 47 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 48 | /// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding |
| 49 | /// the need to search for it in applyStmtList. |
Duncan P. N. Exon Smith | 4fb1f9c | 2015-06-25 23:46:41 +0000 | [diff] [blame] | 50 | DIE::value_iterator StmtListValue; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 51 | |
David Blaikie | 7cbf58a | 2014-11-01 18:18:07 +0000 | [diff] [blame] | 52 | /// Skeleton unit associated with this unit. |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 53 | DwarfCompileUnit *Skeleton = nullptr; |
David Blaikie | 7cbf58a | 2014-11-01 18:18:07 +0000 | [diff] [blame] | 54 | |
David Blaikie | f4bdc31 | 2014-11-02 01:21:40 +0000 | [diff] [blame] | 55 | /// The start of the unit within its section. |
| 56 | MCSymbol *LabelBegin; |
| 57 | |
Amjad Aboud | 8bbce8a | 2016-02-01 14:09:41 +0000 | [diff] [blame] | 58 | /// The start of the unit macro info within macro section. |
| 59 | MCSymbol *MacroLabelBegin; |
| 60 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 61 | using ImportedEntityList = SmallVector<const MDNode *, 8>; |
| 62 | using ImportedEntityMap = DenseMap<const MDNode *, ImportedEntityList>; |
Ivan Krasin | 298639a | 2015-10-26 21:36:35 +0000 | [diff] [blame] | 63 | |
Amjad Aboud | 72da939 | 2016-04-30 01:44:07 +0000 | [diff] [blame] | 64 | ImportedEntityMap ImportedEntities; |
Ivan Krasin | 298639a | 2015-10-26 21:36:35 +0000 | [diff] [blame] | 65 | |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 66 | /// GlobalNames - A map of globally visible named entities for this unit. |
| 67 | StringMap<const DIE *> GlobalNames; |
| 68 | |
| 69 | /// GlobalTypes - A map of globally visible types for this unit. |
| 70 | StringMap<const DIE *> GlobalTypes; |
| 71 | |
David Blaikie | 89a26f0 | 2014-11-03 02:41:49 +0000 | [diff] [blame] | 72 | // List of range lists for a given compile unit, separate from the ranges for |
| 73 | // the CU itself. |
| 74 | SmallVector<RangeSpanList, 1> CURangeLists; |
| 75 | |
David Blaikie | bc532b4 | 2014-11-03 16:40:43 +0000 | [diff] [blame] | 76 | // List of ranges for a given compile unit. |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 77 | SmallVector<RangeSpan, 2> CURanges; |
David Blaikie | bc532b4 | 2014-11-03 16:40:43 +0000 | [diff] [blame] | 78 | |
David Blaikie | ce34349 | 2014-11-03 21:15:30 +0000 | [diff] [blame] | 79 | // The base address of this unit, if any. Used for relative references in |
| 80 | // ranges/locs. |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 81 | const MCSymbol *BaseAddress = nullptr; |
David Blaikie | ce34349 | 2014-11-03 21:15:30 +0000 | [diff] [blame] | 82 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 83 | DenseMap<const MDNode *, DIE *> AbstractSPDies; |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 84 | DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities; |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 85 | |
Paul Robinson | 543c0e1 | 2018-05-22 17:27:31 +0000 | [diff] [blame] | 86 | /// DWO ID for correlating skeleton and split units. |
| 87 | uint64_t DWOId = 0; |
| 88 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 89 | /// Construct a DIE for the given DbgVariable without initializing the |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 90 | /// DbgVariable's DIE reference. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 91 | DIE *constructVariableDIEImpl(const DbgVariable &DV, bool Abstract); |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 92 | |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 93 | bool isDwoUnit() const override; |
| 94 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 95 | DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { |
| 96 | if (isDwoUnit() && !DD->shareAcrossDWOCUs()) |
| 97 | return AbstractSPDies; |
| 98 | return DU->getAbstractSPDies(); |
| 99 | } |
| 100 | |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 101 | DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() { |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 102 | if (isDwoUnit() && !DD->shareAcrossDWOCUs()) |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 103 | return AbstractEntities; |
| 104 | return DU->getAbstractEntities(); |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 105 | } |
| 106 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 107 | public: |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 108 | DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 109 | DwarfDebug *DW, DwarfFile *DWU); |
| 110 | |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 111 | unsigned getUniqueID() const { return UniqueID; } |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 112 | |
David Blaikie | a33cd6a | 2014-11-01 00:50:34 +0000 | [diff] [blame] | 113 | DwarfCompileUnit *getSkeleton() const { |
David Blaikie | a5437b6 | 2014-11-01 19:26:05 +0000 | [diff] [blame] | 114 | return Skeleton; |
David Blaikie | a33cd6a | 2014-11-01 00:50:34 +0000 | [diff] [blame] | 115 | } |
| 116 | |
David Blaikie | b3cee2f | 2017-05-25 18:50:28 +0000 | [diff] [blame] | 117 | bool includeMinimalInlineScopes() const; |
| 118 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 119 | void initStmtList(); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 120 | |
| 121 | /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE. |
| 122 | void applyStmtList(DIE &D); |
| 123 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 124 | /// A pair of GlobalVariable and DIExpression. |
| 125 | struct GlobalExpr { |
| 126 | const GlobalVariable *Var; |
| 127 | const DIExpression *Expr; |
| 128 | }; |
| 129 | |
| 130 | /// Get or create global variable DIE. |
| 131 | DIE * |
| 132 | getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV, |
| 133 | ArrayRef<GlobalExpr> GlobalExprs); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 134 | |
| 135 | /// addLabelAddress - Add a dwarf label attribute data and value using |
| 136 | /// either DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 137 | void addLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
| 138 | const MCSymbol *Label); |
| 139 | |
| 140 | /// addLocalLabelAddress - Add a dwarf label attribute data and value using |
| 141 | /// DW_FORM_addr only. |
| 142 | void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
| 143 | const MCSymbol *Label); |
| 144 | |
| 145 | DwarfCompileUnit &getCU() override { return *this; } |
| 146 | |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 147 | unsigned getOrCreateSourceID(const DIFile *File) override; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 148 | |
Amjad Aboud | 72da939 | 2016-04-30 01:44:07 +0000 | [diff] [blame] | 149 | void addImportedEntity(const DIImportedEntity* IE) { |
| 150 | DIScope *Scope = IE->getScope(); |
Amjad Aboud | a5ba991 | 2016-04-21 16:58:49 +0000 | [diff] [blame] | 151 | assert(Scope && "Invalid Scope encoding!"); |
| 152 | if (!isa<DILocalScope>(Scope)) |
| 153 | // No need to add imported enities that are not local declaration. |
| 154 | return; |
| 155 | |
| 156 | auto *LocalScope = cast<DILocalScope>(Scope)->getNonLexicalBlockFileScope(); |
Amjad Aboud | 72da939 | 2016-04-30 01:44:07 +0000 | [diff] [blame] | 157 | ImportedEntities[LocalScope].push_back(IE); |
Ivan Krasin | 298639a | 2015-10-26 21:36:35 +0000 | [diff] [blame] | 158 | } |
| 159 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 160 | /// addRange - Add an address range to the list of ranges for this unit. |
| 161 | void addRange(RangeSpan Range); |
David Blaikie | 14499a7 | 2014-10-04 15:58:47 +0000 | [diff] [blame] | 162 | |
| 163 | void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 164 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 165 | /// Find DIE for the given subprogram and attach appropriate |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 166 | /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global |
| 167 | /// variables in this scope then create and insert DIEs for these |
| 168 | /// variables. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 169 | DIE &updateSubprogramScopeDIE(const DISubprogram *SP); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 170 | |
| 171 | void constructScopeDIE(LexicalScope *Scope, |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 172 | SmallVectorImpl<DIE *> &FinalChildren); |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 173 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 174 | /// A helper function to construct a RangeSpanList for a given |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 175 | /// lexical scope. |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 176 | void addScopeRangeList(DIE &ScopeDIE, SmallVector<RangeSpan, 2> Range); |
| 177 | |
| 178 | void attachRangesOrLowHighPC(DIE &D, SmallVector<RangeSpan, 2> Ranges); |
David Blaikie | de12375 | 2014-10-09 00:21:42 +0000 | [diff] [blame] | 179 | |
| 180 | void attachRangesOrLowHighPC(DIE &D, |
| 181 | const SmallVectorImpl<InsnRange> &Ranges); |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 182 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 183 | /// This scope represents inlined body of a function. Construct |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 184 | /// DIE to represent this concrete inlined copy of the function. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 185 | DIE *constructInlinedScopeDIE(LexicalScope *Scope); |
David Blaikie | 0fbf8bd | 2014-10-09 17:08:42 +0000 | [diff] [blame] | 186 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 187 | /// Construct new DW_TAG_lexical_block for this scope and |
David Blaikie | 0fbf8bd | 2014-10-09 17:08:42 +0000 | [diff] [blame] | 188 | /// attach DW_AT_low_pc/DW_AT_high_pc labels. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 189 | DIE *constructLexicalScopeDIE(LexicalScope *Scope); |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 190 | |
| 191 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 192 | DIE *constructVariableDIE(DbgVariable &DV, bool Abstract = false); |
David Blaikie | 4a1a44e | 2014-10-09 17:56:39 +0000 | [diff] [blame] | 193 | |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 194 | DIE *constructVariableDIE(DbgVariable &DV, const LexicalScope &Scope, |
| 195 | DIE *&ObjectPointer); |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 196 | |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 197 | /// Construct a DIE for the given DbgLabel. |
| 198 | DIE *constructLabelDIE(DbgLabel &DL, const LexicalScope &Scope); |
| 199 | |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 200 | /// A helper function to create children of a Scope DIE. |
| 201 | DIE *createScopeChildrenDIE(LexicalScope *Scope, |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 202 | SmallVectorImpl<DIE *> &Children, |
David Blaikie | 2195e13 | 2017-07-27 00:06:53 +0000 | [diff] [blame] | 203 | bool *HasNonScopeChildren = nullptr); |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 204 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 205 | /// Construct a DIE for this subprogram scope. |
David Blaikie | 3e3eb33 | 2016-12-15 23:17:52 +0000 | [diff] [blame] | 206 | void constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope); |
David Blaikie | 78b65b6 | 2014-10-09 20:26:15 +0000 | [diff] [blame] | 207 | |
| 208 | DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 209 | |
David Blaikie | 49be5b3 | 2014-10-31 21:57:02 +0000 | [diff] [blame] | 210 | void constructAbstractSubprogramScopeDIE(LexicalScope *Scope); |
David Blaikie | 4191cbc | 2014-10-10 06:39:29 +0000 | [diff] [blame] | 211 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 212 | /// Construct import_module DIE. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 213 | DIE *constructImportedEntityDIE(const DIImportedEntity *Module); |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 214 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 215 | void finishSubprogramDefinition(const DISubprogram *SP); |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 216 | void finishEntityDefinition(const DbgEntity *Entity); |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 217 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 218 | /// Find abstract variable associated with Var. |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 219 | using InlinedVariable = DbgValueHistoryMap::InlinedVariable; |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 220 | DbgEntity *getExistingAbstractEntity(const DINode *Node); |
| 221 | void createAbstractEntity(const DINode *Node, LexicalScope *Scope); |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 222 | |
David Blaikie | 7cbf58a | 2014-11-01 18:18:07 +0000 | [diff] [blame] | 223 | /// Set the skeleton unit associated with this unit. |
David Blaikie | a5437b6 | 2014-11-01 19:26:05 +0000 | [diff] [blame] | 224 | void setSkeleton(DwarfCompileUnit &Skel) { Skeleton = &Skel; } |
David Blaikie | a34568b | 2014-11-01 20:06:28 +0000 | [diff] [blame] | 225 | |
Paul Robinson | 543c0e1 | 2018-05-22 17:27:31 +0000 | [diff] [blame] | 226 | unsigned getHeaderSize() const override { |
| 227 | // DWARF v5 added the DWO ID to the header for split/skeleton units. |
| 228 | unsigned DWOIdSize = |
| 229 | DD->getDwarfVersion() >= 5 && DD->useSplitDwarf() ? sizeof(uint64_t) |
| 230 | : 0; |
| 231 | return DwarfUnit::getHeaderSize() + DWOIdSize; |
| 232 | } |
David Blaikie | 983bfea | 2014-11-01 23:07:14 +0000 | [diff] [blame] | 233 | unsigned getLength() { |
| 234 | return sizeof(uint32_t) + // Length field |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 235 | getHeaderSize() + getUnitDie().getSize(); |
David Blaikie | 983bfea | 2014-11-01 23:07:14 +0000 | [diff] [blame] | 236 | } |
David Blaikie | ae57e66 | 2014-11-01 23:59:23 +0000 | [diff] [blame] | 237 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 238 | void emitHeader(bool UseOffsets) override; |
David Blaikie | f4bdc31 | 2014-11-02 01:21:40 +0000 | [diff] [blame] | 239 | |
| 240 | MCSymbol *getLabelBegin() const { |
David Blaikie | e40caae | 2016-12-01 21:59:09 +0000 | [diff] [blame] | 241 | assert(getSection()); |
David Blaikie | f4bdc31 | 2014-11-02 01:21:40 +0000 | [diff] [blame] | 242 | return LabelBegin; |
| 243 | } |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 244 | |
Amjad Aboud | 8bbce8a | 2016-02-01 14:09:41 +0000 | [diff] [blame] | 245 | MCSymbol *getMacroLabelBegin() const { |
| 246 | return MacroLabelBegin; |
| 247 | } |
| 248 | |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 249 | /// Add a new global name to the compile unit. |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 250 | void addGlobalName(StringRef Name, const DIE &Die, |
| 251 | const DIScope *Context) override; |
| 252 | |
| 253 | /// Add a new global name present in a type unit to this compile unit. |
| 254 | void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context); |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 255 | |
| 256 | /// Add a new global type to the compile unit. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 257 | void addGlobalType(const DIType *Ty, const DIE &Die, |
| 258 | const DIScope *Context) override; |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 259 | |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 260 | /// Add a new global type present in a type unit to this compile unit. |
| 261 | void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context); |
| 262 | |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 263 | const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; } |
| 264 | const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; } |
David Blaikie | 7d48be2 | 2014-11-02 06:37:23 +0000 | [diff] [blame] | 265 | |
| 266 | /// Add DW_AT_location attribute for a DbgVariable based on provided |
| 267 | /// MachineLocation. |
| 268 | void addVariableAddress(const DbgVariable &DV, DIE &Die, |
| 269 | MachineLocation Location); |
David Blaikie | f7435ee | 2014-11-02 06:46:40 +0000 | [diff] [blame] | 270 | /// Add an address attribute to a die based on the location provided. |
| 271 | void addAddress(DIE &Die, dwarf::Attribute Attribute, |
Adrian Prantl | 5883af3 | 2015-01-19 17:57:29 +0000 | [diff] [blame] | 272 | const MachineLocation &Location); |
David Blaikie | 77895fb | 2014-11-02 06:58:44 +0000 | [diff] [blame] | 273 | |
| 274 | /// Start with the address based on the location provided, and generate the |
| 275 | /// DWARF information necessary to find the actual variable (navigating the |
| 276 | /// extra location information encoded in the type) based on the starting |
| 277 | /// location. Add the DWARF information to the die. |
| 278 | void addComplexAddress(const DbgVariable &DV, DIE &Die, |
| 279 | dwarf::Attribute Attribute, |
| 280 | const MachineLocation &Location); |
David Blaikie | 4bc0881 | 2014-11-02 07:03:19 +0000 | [diff] [blame] | 281 | |
| 282 | /// Add a Dwarf loclistptr attribute data and value. |
| 283 | void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index); |
David Blaikie | 02a6333 | 2014-11-02 07:06:51 +0000 | [diff] [blame] | 284 | void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie); |
David Blaikie | 9780208 | 2014-11-02 07:11:55 +0000 | [diff] [blame] | 285 | |
| 286 | /// Add a Dwarf expression attribute data and value. |
| 287 | void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr); |
David Blaikie | 3363a57 | 2014-11-02 08:09:09 +0000 | [diff] [blame] | 288 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 289 | void applySubprogramAttributesToDefinition(const DISubprogram *SP, |
Duncan P. N. Exon Smith | 2fbe135 | 2015-04-20 22:10:08 +0000 | [diff] [blame] | 290 | DIE &SPDie); |
David Blaikie | 89a26f0 | 2014-11-03 02:41:49 +0000 | [diff] [blame] | 291 | |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame^] | 292 | void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie); |
| 293 | |
David Blaikie | 89a26f0 | 2014-11-03 02:41:49 +0000 | [diff] [blame] | 294 | /// getRangeLists - Get the vector of range lists. |
| 295 | const SmallVectorImpl<RangeSpanList> &getRangeLists() const { |
David Blaikie | 542616d | 2014-11-03 21:52:56 +0000 | [diff] [blame] | 296 | return (Skeleton ? Skeleton : this)->CURangeLists; |
David Blaikie | 89a26f0 | 2014-11-03 02:41:49 +0000 | [diff] [blame] | 297 | } |
David Blaikie | bc532b4 | 2014-11-03 16:40:43 +0000 | [diff] [blame] | 298 | |
| 299 | /// getRanges - Get the list of ranges for this unit. |
| 300 | const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; } |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 301 | SmallVector<RangeSpan, 2> takeRanges() { return std::move(CURanges); } |
David Blaikie | ce34349 | 2014-11-03 21:15:30 +0000 | [diff] [blame] | 302 | |
| 303 | void setBaseAddress(const MCSymbol *Base) { BaseAddress = Base; } |
| 304 | const MCSymbol *getBaseAddress() const { return BaseAddress; } |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 305 | |
Paul Robinson | 543c0e1 | 2018-05-22 17:27:31 +0000 | [diff] [blame] | 306 | uint64_t getDWOId() const { return DWOId; } |
| 307 | void setDWOId(uint64_t DwoId) { DWOId = DwoId; } |
| 308 | |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 309 | bool hasDwarfPubSections() const; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 312 | } // end namespace llvm |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 313 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 314 | #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |