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