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 | 832c7d9 | 2019-04-24 18:09:44 +0000 | [diff] [blame] | 103 | void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override; |
| 104 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 105 | public: |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 106 | DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 107 | DwarfDebug *DW, DwarfFile *DWU); |
| 108 | |
David Blaikie | c4af8bf | 2018-10-20 07:36:39 +0000 | [diff] [blame] | 109 | bool hasRangeLists() const { return HasRangeLists; } |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 110 | unsigned getUniqueID() const { return UniqueID; } |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 111 | |
David Blaikie | a33cd6a | 2014-11-01 00:50:34 +0000 | [diff] [blame] | 112 | DwarfCompileUnit *getSkeleton() const { |
David Blaikie | a5437b6 | 2014-11-01 19:26:05 +0000 | [diff] [blame] | 113 | return Skeleton; |
David Blaikie | a33cd6a | 2014-11-01 00:50:34 +0000 | [diff] [blame] | 114 | } |
| 115 | |
David Blaikie | b3cee2f | 2017-05-25 18:50:28 +0000 | [diff] [blame] | 116 | bool includeMinimalInlineScopes() const; |
| 117 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 118 | void initStmtList(); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 119 | |
| 120 | /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE. |
| 121 | void applyStmtList(DIE &D); |
| 122 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 123 | /// A pair of GlobalVariable and DIExpression. |
| 124 | struct GlobalExpr { |
| 125 | const GlobalVariable *Var; |
| 126 | const DIExpression *Expr; |
| 127 | }; |
| 128 | |
Markus Lavin | b86ce21 | 2019-03-19 13:16:28 +0000 | [diff] [blame] | 129 | struct BaseTypeRef { |
| 130 | BaseTypeRef(unsigned BitSize, dwarf::TypeKind Encoding) : |
| 131 | BitSize(BitSize), Encoding(Encoding) {} |
| 132 | unsigned BitSize; |
| 133 | dwarf::TypeKind Encoding; |
| 134 | DIE *Die = nullptr; |
| 135 | }; |
| 136 | |
| 137 | std::vector<BaseTypeRef> ExprRefedBaseTypes; |
| 138 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 139 | /// Get or create global variable DIE. |
| 140 | DIE * |
| 141 | getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV, |
| 142 | ArrayRef<GlobalExpr> GlobalExprs); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 143 | |
Adrian Prantl | 6ed5706 | 2019-04-08 19:13:55 +0000 | [diff] [blame] | 144 | DIE *getOrCreateCommonBlock(const DICommonBlock *CB, |
| 145 | ArrayRef<GlobalExpr> GlobalExprs); |
| 146 | |
| 147 | void addLocationAttribute(DIE *ToDIE, const DIGlobalVariable *GV, |
| 148 | ArrayRef<GlobalExpr> GlobalExprs); |
| 149 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 150 | /// addLabelAddress - Add a dwarf label attribute data and value using |
| 151 | /// either DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 152 | void addLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
| 153 | const MCSymbol *Label); |
| 154 | |
| 155 | /// addLocalLabelAddress - Add a dwarf label attribute data and value using |
| 156 | /// DW_FORM_addr only. |
| 157 | void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
| 158 | const MCSymbol *Label); |
| 159 | |
| 160 | DwarfCompileUnit &getCU() override { return *this; } |
| 161 | |
Paul Robinson | 612e89d | 2018-01-12 19:17:50 +0000 | [diff] [blame] | 162 | unsigned getOrCreateSourceID(const DIFile *File) override; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 163 | |
Amjad Aboud | 72da939 | 2016-04-30 01:44:07 +0000 | [diff] [blame] | 164 | void addImportedEntity(const DIImportedEntity* IE) { |
| 165 | DIScope *Scope = IE->getScope(); |
Amjad Aboud | a5ba991 | 2016-04-21 16:58:49 +0000 | [diff] [blame] | 166 | assert(Scope && "Invalid Scope encoding!"); |
| 167 | if (!isa<DILocalScope>(Scope)) |
| 168 | // No need to add imported enities that are not local declaration. |
| 169 | return; |
| 170 | |
| 171 | auto *LocalScope = cast<DILocalScope>(Scope)->getNonLexicalBlockFileScope(); |
Amjad Aboud | 72da939 | 2016-04-30 01:44:07 +0000 | [diff] [blame] | 172 | ImportedEntities[LocalScope].push_back(IE); |
Ivan Krasin | 298639a | 2015-10-26 21:36:35 +0000 | [diff] [blame] | 173 | } |
| 174 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 175 | /// addRange - Add an address range to the list of ranges for this unit. |
| 176 | void addRange(RangeSpan Range); |
David Blaikie | 14499a7 | 2014-10-04 15:58:47 +0000 | [diff] [blame] | 177 | |
| 178 | void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 179 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 180 | /// Find DIE for the given subprogram and attach appropriate |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 181 | /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global |
| 182 | /// variables in this scope then create and insert DIEs for these |
| 183 | /// variables. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 184 | DIE &updateSubprogramScopeDIE(const DISubprogram *SP); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 185 | |
| 186 | void constructScopeDIE(LexicalScope *Scope, |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 187 | SmallVectorImpl<DIE *> &FinalChildren); |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 188 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 189 | /// A helper function to construct a RangeSpanList for a given |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 190 | /// lexical scope. |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 191 | void addScopeRangeList(DIE &ScopeDIE, SmallVector<RangeSpan, 2> Range); |
| 192 | |
| 193 | void attachRangesOrLowHighPC(DIE &D, SmallVector<RangeSpan, 2> Ranges); |
David Blaikie | de12375 | 2014-10-09 00:21:42 +0000 | [diff] [blame] | 194 | |
| 195 | void attachRangesOrLowHighPC(DIE &D, |
| 196 | const SmallVectorImpl<InsnRange> &Ranges); |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 197 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 198 | /// This scope represents inlined body of a function. Construct |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 199 | /// 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] | 200 | DIE *constructInlinedScopeDIE(LexicalScope *Scope); |
David Blaikie | 0fbf8bd | 2014-10-09 17:08:42 +0000 | [diff] [blame] | 201 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 202 | /// Construct new DW_TAG_lexical_block for this scope and |
David Blaikie | 0fbf8bd | 2014-10-09 17:08:42 +0000 | [diff] [blame] | 203 | /// 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] | 204 | DIE *constructLexicalScopeDIE(LexicalScope *Scope); |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 205 | |
| 206 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 207 | DIE *constructVariableDIE(DbgVariable &DV, bool Abstract = false); |
David Blaikie | 4a1a44e | 2014-10-09 17:56:39 +0000 | [diff] [blame] | 208 | |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 209 | DIE *constructVariableDIE(DbgVariable &DV, const LexicalScope &Scope, |
| 210 | DIE *&ObjectPointer); |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 211 | |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame] | 212 | /// Construct a DIE for the given DbgLabel. |
| 213 | DIE *constructLabelDIE(DbgLabel &DL, const LexicalScope &Scope); |
| 214 | |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 215 | /// A helper function to create children of a Scope DIE. |
| 216 | DIE *createScopeChildrenDIE(LexicalScope *Scope, |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 217 | SmallVectorImpl<DIE *> &Children, |
David Blaikie | 2195e13 | 2017-07-27 00:06:53 +0000 | [diff] [blame] | 218 | bool *HasNonScopeChildren = nullptr); |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 219 | |
Markus Lavin | b86ce21 | 2019-03-19 13:16:28 +0000 | [diff] [blame] | 220 | void createBaseTypeDIEs(); |
| 221 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 222 | /// Construct a DIE for this subprogram scope. |
Vedant Kumar | 5931b4e | 2018-10-05 20:37:17 +0000 | [diff] [blame] | 223 | DIE &constructSubprogramScopeDIE(const DISubprogram *Sub, |
| 224 | LexicalScope *Scope); |
David Blaikie | 78b65b6 | 2014-10-09 20:26:15 +0000 | [diff] [blame] | 225 | |
| 226 | DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 227 | |
David Blaikie | 49be5b3 | 2014-10-31 21:57:02 +0000 | [diff] [blame] | 228 | void constructAbstractSubprogramScopeDIE(LexicalScope *Scope); |
David Blaikie | 4191cbc | 2014-10-10 06:39:29 +0000 | [diff] [blame] | 229 | |
Vedant Kumar | 58a0714 | 2019-08-26 20:53:34 +0000 | [diff] [blame] | 230 | /// This takes a DWARF 5 tag and returns it or a GNU analog. |
| 231 | dwarf::Tag getDwarf5OrGNUTag(dwarf::Tag Tag) const; |
| 232 | |
| 233 | /// This takes a DWARF 5 attribute and returns it or a GNU analog. |
| 234 | dwarf::Attribute getDwarf5OrGNUAttr(dwarf::Attribute Attr) const; |
Djordje Todorovic | b9973f8 | 2019-07-31 16:51:28 +0000 | [diff] [blame] | 235 | |
Vedant Kumar | 533dd02 | 2019-08-26 20:53:12 +0000 | [diff] [blame] | 236 | /// This takes a DWARF 5 location atom and either returns it or a GNU analog. |
| 237 | dwarf::LocationAtom getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const; |
| 238 | |
Vedant Kumar | 5931b4e | 2018-10-05 20:37:17 +0000 | [diff] [blame] | 239 | /// Construct a call site entry DIE describing a call within \p Scope to a |
Djordje Todorovic | b9973f8 | 2019-07-31 16:51:28 +0000 | [diff] [blame] | 240 | /// callee described by \p CalleeSP. |
| 241 | /// \p IsTail specifies whether the call is a tail call. |
| 242 | /// \p PCAddr (used for GDB + DWARF 4 tuning) points to the PC value after |
| 243 | /// the call instruction. |
| 244 | /// \p PCOffset (used for cases other than GDB + DWARF 4 tuning) must be |
| 245 | /// non-zero for non-tail calls (in the case of non-gdb tuning, since for |
| 246 | /// GDB + DWARF 5 tuning we still generate PC info for tail calls) or be the |
Djordje Todorovic | 0739ccd | 2019-07-12 09:45:12 +0000 | [diff] [blame] | 247 | /// function-local offset to PC value after the call instruction. |
Djordje Todorovic | b9973f8 | 2019-07-31 16:51:28 +0000 | [diff] [blame] | 248 | /// \p CallReg is a register location for an indirect call. For direct calls |
| 249 | /// the \p CallReg is set to 0. |
| 250 | DIE &constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram *CalleeSP, |
| 251 | bool IsTail, const MCSymbol *PCAddr, |
| 252 | const MCExpr *PCOffset, unsigned CallReg); |
| 253 | /// Construct call site parameter DIEs for the \p CallSiteDIE. The \p Params |
| 254 | /// were collected by the \ref collectCallSiteParameters. |
| 255 | /// Note: The order of parameters does not matter, since debuggers recognize |
| 256 | /// call site parameters by the DW_AT_location attribute. |
| 257 | void constructCallSiteParmEntryDIEs(DIE &CallSiteDIE, |
| 258 | SmallVector<DbgCallSiteParam, 4> &Params); |
Vedant Kumar | 5931b4e | 2018-10-05 20:37:17 +0000 | [diff] [blame] | 259 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 260 | /// Construct import_module DIE. |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 261 | DIE *constructImportedEntityDIE(const DIImportedEntity *Module); |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 262 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 263 | void finishSubprogramDefinition(const DISubprogram *SP); |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame] | 264 | void finishEntityDefinition(const DbgEntity *Entity); |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 265 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 266 | /// Find abstract variable associated with Var. |
Hsiangkai Wang | 760c1ab | 2018-09-06 02:22:06 +0000 | [diff] [blame] | 267 | using InlinedEntity = DbgValueHistoryMap::InlinedEntity; |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame] | 268 | DbgEntity *getExistingAbstractEntity(const DINode *Node); |
| 269 | void createAbstractEntity(const DINode *Node, LexicalScope *Scope); |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 270 | |
David Blaikie | 7cbf58a | 2014-11-01 18:18:07 +0000 | [diff] [blame] | 271 | /// Set the skeleton unit associated with this unit. |
David Blaikie | a5437b6 | 2014-11-01 19:26:05 +0000 | [diff] [blame] | 272 | void setSkeleton(DwarfCompileUnit &Skel) { Skeleton = &Skel; } |
David Blaikie | a34568b | 2014-11-01 20:06:28 +0000 | [diff] [blame] | 273 | |
Paul Robinson | 543c0e1 | 2018-05-22 17:27:31 +0000 | [diff] [blame] | 274 | unsigned getHeaderSize() const override { |
| 275 | // DWARF v5 added the DWO ID to the header for split/skeleton units. |
| 276 | unsigned DWOIdSize = |
| 277 | DD->getDwarfVersion() >= 5 && DD->useSplitDwarf() ? sizeof(uint64_t) |
| 278 | : 0; |
| 279 | return DwarfUnit::getHeaderSize() + DWOIdSize; |
| 280 | } |
David Blaikie | 983bfea | 2014-11-01 23:07:14 +0000 | [diff] [blame] | 281 | unsigned getLength() { |
| 282 | return sizeof(uint32_t) + // Length field |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 283 | getHeaderSize() + getUnitDie().getSize(); |
David Blaikie | 983bfea | 2014-11-01 23:07:14 +0000 | [diff] [blame] | 284 | } |
David Blaikie | ae57e66 | 2014-11-01 23:59:23 +0000 | [diff] [blame] | 285 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 286 | void emitHeader(bool UseOffsets) override; |
David Blaikie | f4bdc31 | 2014-11-02 01:21:40 +0000 | [diff] [blame] | 287 | |
David Blaikie | 61c127c | 2018-12-14 22:34:03 +0000 | [diff] [blame] | 288 | /// Add the DW_AT_addr_base attribute to the unit DIE. |
| 289 | void addAddrTableBase(); |
| 290 | |
David Blaikie | f4bdc31 | 2014-11-02 01:21:40 +0000 | [diff] [blame] | 291 | MCSymbol *getLabelBegin() const { |
David Blaikie | e40caae | 2016-12-01 21:59:09 +0000 | [diff] [blame] | 292 | assert(getSection()); |
David Blaikie | f4bdc31 | 2014-11-02 01:21:40 +0000 | [diff] [blame] | 293 | return LabelBegin; |
| 294 | } |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 295 | |
Amjad Aboud | 8bbce8a | 2016-02-01 14:09:41 +0000 | [diff] [blame] | 296 | MCSymbol *getMacroLabelBegin() const { |
| 297 | return MacroLabelBegin; |
| 298 | } |
| 299 | |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 300 | /// Add a new global name to the compile unit. |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 301 | void addGlobalName(StringRef Name, const DIE &Die, |
| 302 | const DIScope *Context) override; |
| 303 | |
| 304 | /// Add a new global name present in a type unit to this compile unit. |
| 305 | void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context); |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 306 | |
| 307 | /// Add a new global type to the compile unit. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 308 | void addGlobalType(const DIType *Ty, const DIE &Die, |
| 309 | const DIScope *Context) override; |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 310 | |
David Blaikie | a0e3c75 | 2017-02-03 00:44:18 +0000 | [diff] [blame] | 311 | /// Add a new global type present in a type unit to this compile unit. |
| 312 | void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context); |
| 313 | |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 314 | const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; } |
| 315 | const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; } |
David Blaikie | 7d48be2 | 2014-11-02 06:37:23 +0000 | [diff] [blame] | 316 | |
| 317 | /// Add DW_AT_location attribute for a DbgVariable based on provided |
| 318 | /// MachineLocation. |
| 319 | void addVariableAddress(const DbgVariable &DV, DIE &Die, |
| 320 | MachineLocation Location); |
David Blaikie | f7435ee | 2014-11-02 06:46:40 +0000 | [diff] [blame] | 321 | /// Add an address attribute to a die based on the location provided. |
| 322 | void addAddress(DIE &Die, dwarf::Attribute Attribute, |
Adrian Prantl | 5883af3 | 2015-01-19 17:57:29 +0000 | [diff] [blame] | 323 | const MachineLocation &Location); |
David Blaikie | 77895fb | 2014-11-02 06:58:44 +0000 | [diff] [blame] | 324 | |
| 325 | /// Start with the address based on the location provided, and generate the |
| 326 | /// DWARF information necessary to find the actual variable (navigating the |
| 327 | /// extra location information encoded in the type) based on the starting |
| 328 | /// location. Add the DWARF information to the die. |
| 329 | void addComplexAddress(const DbgVariable &DV, DIE &Die, |
| 330 | dwarf::Attribute Attribute, |
| 331 | const MachineLocation &Location); |
David Blaikie | 4bc0881 | 2014-11-02 07:03:19 +0000 | [diff] [blame] | 332 | |
| 333 | /// Add a Dwarf loclistptr attribute data and value. |
| 334 | void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index); |
David Blaikie | 02a6333 | 2014-11-02 07:06:51 +0000 | [diff] [blame] | 335 | void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie); |
David Blaikie | 9780208 | 2014-11-02 07:11:55 +0000 | [diff] [blame] | 336 | |
| 337 | /// Add a Dwarf expression attribute data and value. |
| 338 | void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr); |
David Blaikie | 3363a57 | 2014-11-02 08:09:09 +0000 | [diff] [blame] | 339 | |
Vedant Kumar | 74533bd | 2018-10-22 21:44:21 +0000 | [diff] [blame] | 340 | /// Add an attribute containing an address expression to \p Die. |
| 341 | void addAddressExpr(DIE &Die, dwarf::Attribute Attribute, const MCExpr *Expr); |
| 342 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 343 | void applySubprogramAttributesToDefinition(const DISubprogram *SP, |
Duncan P. N. Exon Smith | 2fbe135 | 2015-04-20 22:10:08 +0000 | [diff] [blame] | 344 | DIE &SPDie); |
David Blaikie | 89a26f0 | 2014-11-03 02:41:49 +0000 | [diff] [blame] | 345 | |
Hsiangkai Wang | 2532ac8 | 2018-08-17 15:22:04 +0000 | [diff] [blame] | 346 | void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie); |
| 347 | |
David Blaikie | bc532b4 | 2014-11-03 16:40:43 +0000 | [diff] [blame] | 348 | /// getRanges - Get the list of ranges for this unit. |
| 349 | const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; } |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 350 | SmallVector<RangeSpan, 2> takeRanges() { return std::move(CURanges); } |
David Blaikie | ce34349 | 2014-11-03 21:15:30 +0000 | [diff] [blame] | 351 | |
| 352 | void setBaseAddress(const MCSymbol *Base) { BaseAddress = Base; } |
| 353 | const MCSymbol *getBaseAddress() const { return BaseAddress; } |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 354 | |
Paul Robinson | 543c0e1 | 2018-05-22 17:27:31 +0000 | [diff] [blame] | 355 | uint64_t getDWOId() const { return DWOId; } |
| 356 | void setDWOId(uint64_t DwoId) { DWOId = DwoId; } |
| 357 | |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 358 | bool hasDwarfPubSections() const; |
Markus Lavin | b86ce21 | 2019-03-19 13:16:28 +0000 | [diff] [blame] | 359 | |
| 360 | void addBaseTypeRef(DIEValueList &Die, int64_t Idx); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 361 | }; |
| 362 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 363 | } // end namespace llvm |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 364 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 365 | #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |