Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===// |
| 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 debug info into asm files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__ |
| 15 | #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__ |
| 16 | |
Timur Iskhodzhanov | 1cd1444 | 2013-12-03 15:10:23 +0000 | [diff] [blame] | 17 | #include "AsmPrinterHandler.h" |
Bill Wendling | e38859d | 2012-06-28 00:05:13 +0000 | [diff] [blame] | 18 | #include "DIE.h" |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 19 | #include "DebugLocEntry.h" |
David Blaikie | 0a456de | 2014-04-02 01:43:18 +0000 | [diff] [blame] | 20 | #include "DebugLocList.h" |
Devang Patel | 018b29b | 2010-01-19 06:19:05 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Eric Christopher | acbe42b | 2014-03-18 20:58:35 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/MapVector.h" |
| 23 | #include "llvm/ADT/SmallPtrSet.h" |
| 24 | #include "llvm/ADT/StringMap.h" |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/FoldingSet.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/LexicalScopes.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 27 | #include "llvm/IR/DebugInfo.h" |
Eric Christopher | acbe42b | 2014-03-18 20:58:35 +0000 | [diff] [blame] | 28 | #include "llvm/IR/DebugLoc.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MachineLocation.h" |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCDwarf.h" |
Chris Lattner | 3f3fb97 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Allocator.h" |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 32 | |
| 33 | namespace llvm { |
| 34 | |
Adrian Prantl | 702bf5a | 2014-03-18 02:34:52 +0000 | [diff] [blame] | 35 | class AsmPrinter; |
Eric Christopher | 29e874d | 2014-03-07 22:40:37 +0000 | [diff] [blame] | 36 | class ByteStreamer; |
Chris Lattner | 88fce10 | 2012-01-26 20:44:57 +0000 | [diff] [blame] | 37 | class ConstantInt; |
| 38 | class ConstantFP; |
Eric Christopher | ce4a944 | 2014-03-18 20:37:10 +0000 | [diff] [blame] | 39 | class DwarfCompileUnit; |
| 40 | class DwarfDebug; |
| 41 | class DwarfTypeUnit; |
| 42 | class DwarfUnit; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 43 | class MachineModuleInfo; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 44 | |
| 45 | //===----------------------------------------------------------------------===// |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 46 | /// \brief This class is used to record source line correspondence. |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 47 | class SrcLineInfo { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 48 | unsigned Line; // Source line number. |
| 49 | unsigned Column; // Source column. |
| 50 | unsigned SourceID; // Source ID number. |
| 51 | MCSymbol *Label; // Label in code ID number. |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 52 | public: |
Chris Lattner | b4666f4 | 2010-03-14 08:15:55 +0000 | [diff] [blame] | 53 | SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label) |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 54 | : Line(L), Column(C), SourceID(S), Label(label) {} |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 55 | |
| 56 | // Accessors |
| 57 | unsigned getLine() const { return Line; } |
| 58 | unsigned getColumn() const { return Column; } |
| 59 | unsigned getSourceID() const { return SourceID; } |
Chris Lattner | b4666f4 | 2010-03-14 08:15:55 +0000 | [diff] [blame] | 60 | MCSymbol *getLabel() const { return Label; } |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 63 | //===----------------------------------------------------------------------===// |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 64 | /// \brief This class is used to track local variable information. |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 65 | class DbgVariable { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 66 | DIVariable Var; // Variable Descriptor. |
| 67 | DIE *TheDIE; // Variable DIE. |
| 68 | unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries. |
| 69 | DbgVariable *AbsVar; // Corresponding Abstract variable, if any. |
| 70 | const MachineInstr *MInsn; // DBG_VALUE instruction of the variable. |
Devang Patel | 3e4a965 | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 71 | int FrameIndex; |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 72 | DwarfDebug *DD; |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 73 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 74 | public: |
| 75 | // AbsVar may be NULL. |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 76 | DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD) |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 77 | : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0), |
| 78 | FrameIndex(~0), DD(DD) {} |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 79 | |
| 80 | // Accessors. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 81 | DIVariable getVariable() const { return Var; } |
| 82 | void setDIE(DIE *D) { TheDIE = D; } |
| 83 | DIE *getDIE() const { return TheDIE; } |
| 84 | void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; } |
| 85 | unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; } |
| 86 | StringRef getName() const { return Var.getName(); } |
Devang Patel | 99819b5 | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 87 | DbgVariable *getAbstractVariable() const { return AbsVar; } |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 88 | const MachineInstr *getMInsn() const { return MInsn; } |
| 89 | void setMInsn(const MachineInstr *M) { MInsn = M; } |
| 90 | int getFrameIndex() const { return FrameIndex; } |
| 91 | void setFrameIndex(int FI) { FrameIndex = FI; } |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 92 | // Translate tag to proper Dwarf tag. |
David Blaikie | efc403b | 2014-04-12 02:24:04 +0000 | [diff] [blame] | 93 | dwarf::Tag getTag() const { |
Devang Patel | 6e4d2c9 | 2011-08-15 18:35:42 +0000 | [diff] [blame] | 94 | if (Var.getTag() == dwarf::DW_TAG_arg_variable) |
| 95 | return dwarf::DW_TAG_formal_parameter; |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 96 | |
Devang Patel | 6e4d2c9 | 2011-08-15 18:35:42 +0000 | [diff] [blame] | 97 | return dwarf::DW_TAG_variable; |
| 98 | } |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 99 | /// \brief Return true if DbgVariable is artificial. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 100 | bool isArtificial() const { |
Devang Patel | d7d80aa | 2011-08-15 18:40:16 +0000 | [diff] [blame] | 101 | if (Var.isArtificial()) |
| 102 | return true; |
Eric Christopher | c1c8a1b | 2012-09-21 22:18:52 +0000 | [diff] [blame] | 103 | if (getType().isArtificial()) |
Devang Patel | d7d80aa | 2011-08-15 18:40:16 +0000 | [diff] [blame] | 104 | return true; |
| 105 | return false; |
| 106 | } |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 107 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 108 | bool isObjectPointer() const { |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 109 | if (Var.isObjectPointer()) |
| 110 | return true; |
Eric Christopher | c1c8a1b | 2012-09-21 22:18:52 +0000 | [diff] [blame] | 111 | if (getType().isObjectPointer()) |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 112 | return true; |
| 113 | return false; |
| 114 | } |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 115 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 116 | bool variableHasComplexAddress() const { |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 117 | assert(Var.isVariable() && "Invalid complex DbgVariable!"); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 118 | return Var.hasComplexAddress(); |
| 119 | } |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 120 | bool isBlockByrefVariable() const; |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 121 | unsigned getNumAddrElements() const { |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 122 | assert(Var.isVariable() && "Invalid complex DbgVariable!"); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 123 | return Var.getNumAddrElements(); |
| 124 | } |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 125 | uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 126 | DIType getType() const; |
Manman Ren | be5576f | 2013-10-08 19:07:44 +0000 | [diff] [blame] | 127 | |
| 128 | private: |
| 129 | /// resolve - Look in the DwarfDebug map for the MDNode that |
| 130 | /// corresponds to the reference. |
| 131 | template <typename T> T resolve(DIRef<T> Ref) const; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 134 | /// \brief Collects and handles information specific to a particular |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 135 | /// collection of units. This collection represents all of the units |
| 136 | /// that will be ultimately output into a single object file. |
| 137 | class DwarfFile { |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 138 | // Target of Dwarf emission, used for sizing of abbreviations. |
| 139 | AsmPrinter *Asm; |
| 140 | |
| 141 | // Used to uniquely define abbreviations. |
David Blaikie | 0504cda | 2013-12-05 07:43:55 +0000 | [diff] [blame] | 142 | FoldingSet<DIEAbbrev> AbbreviationsSet; |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 143 | |
| 144 | // A list of all the unique abbreviations in use. |
David Blaikie | 0504cda | 2013-12-05 07:43:55 +0000 | [diff] [blame] | 145 | std::vector<DIEAbbrev *> Abbreviations; |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 146 | |
| 147 | // A pointer to all units in the section. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 148 | SmallVector<DwarfUnit *, 1> CUs; |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 149 | |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 150 | // Collection of strings for this unit and assorted symbols. |
Eric Christopher | 18cf061 | 2013-07-03 20:36:36 +0000 | [diff] [blame] | 151 | // A String->Symbol mapping of strings used by indirect |
| 152 | // references. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 153 | typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> |
| 154 | StrPool; |
Eric Christopher | 2761458 | 2013-01-08 22:22:06 +0000 | [diff] [blame] | 155 | StrPool StringPool; |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 156 | unsigned NextStringPoolNumber; |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 157 | std::string StringPref; |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 158 | |
David Blaikie | f1a6dea | 2014-02-15 19:34:03 +0000 | [diff] [blame] | 159 | struct AddressPoolEntry { |
| 160 | unsigned Number; |
| 161 | bool TLS; |
| 162 | AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {} |
| 163 | }; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 164 | // Collection of addresses for this unit and assorted labels. |
Eric Christopher | 18cf061 | 2013-07-03 20:36:36 +0000 | [diff] [blame] | 165 | // A Symbol->unsigned mapping of addresses used by indirect |
| 166 | // references. |
David Blaikie | f1a6dea | 2014-02-15 19:34:03 +0000 | [diff] [blame] | 167 | typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 168 | AddrPool AddressPool; |
| 169 | unsigned NextAddrPoolNumber; |
| 170 | |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 171 | public: |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 172 | DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA) |
David Blaikie | 0504cda | 2013-12-05 07:43:55 +0000 | [diff] [blame] | 173 | : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref), |
| 174 | AddressPool(), NextAddrPoolNumber(0) {} |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 175 | |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 176 | ~DwarfFile(); |
David Blaikie | 72f1a3e | 2013-11-23 01:17:34 +0000 | [diff] [blame] | 177 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 178 | const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; } |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 179 | |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 180 | /// \brief Compute the size and offset of a DIE given an incoming Offset. |
David Blaikie | b818418 | 2014-04-14 22:45:02 +0000 | [diff] [blame] | 181 | unsigned computeSizeAndOffset(DIE &Die, unsigned Offset); |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 182 | |
| 183 | /// \brief Compute the size and offset of all the DIEs. |
| 184 | void computeSizeAndOffsets(); |
| 185 | |
| 186 | /// \brief Define a unique number for the abbreviation. |
| 187 | void assignAbbrevNumber(DIEAbbrev &Abbrev); |
| 188 | |
| 189 | /// \brief Add a unit to the list of CUs. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 190 | void addUnit(DwarfUnit *CU) { CUs.push_back(CU); } |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 191 | |
| 192 | /// \brief Emit all of the units to the section listed with the given |
| 193 | /// abbreviation section. |
David Blaikie | f72ed5f | 2014-03-24 20:31:01 +0000 | [diff] [blame] | 194 | void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym); |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 195 | |
David Blaikie | 0504cda | 2013-12-05 07:43:55 +0000 | [diff] [blame] | 196 | /// \brief Emit a set of abbreviations to the specific section. |
| 197 | void emitAbbrevs(const MCSection *); |
| 198 | |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 199 | /// \brief Emit all of the strings to the section given. |
Eric Christopher | dd7b461 | 2013-07-03 21:23:59 +0000 | [diff] [blame] | 200 | void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection, |
| 201 | const MCSymbol *StrSecSym); |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 202 | |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 203 | /// \brief Emit all of the addresses to the section given. |
Eric Christopher | dd7b461 | 2013-07-03 21:23:59 +0000 | [diff] [blame] | 204 | void emitAddresses(const MCSection *AddrSection); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 205 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 206 | /// \brief Returns the entry into the start of the pool. |
| 207 | MCSymbol *getStringPoolSym(); |
| 208 | |
| 209 | /// \brief Returns an entry into the string pool with the given |
| 210 | /// string text. |
| 211 | MCSymbol *getStringPoolEntry(StringRef Str); |
| 212 | |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 213 | /// \brief Returns the index into the string pool with the given |
| 214 | /// string text. |
| 215 | unsigned getStringPoolIndex(StringRef Str); |
| 216 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 217 | /// \brief Returns the string pool. |
Eric Christopher | 2761458 | 2013-01-08 22:22:06 +0000 | [diff] [blame] | 218 | StrPool *getStringPool() { return &StringPool; } |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 219 | |
| 220 | /// \brief Returns the index into the address pool with the given |
| 221 | /// label/symbol. |
David Blaikie | f1a6dea | 2014-02-15 19:34:03 +0000 | [diff] [blame] | 222 | unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 223 | |
| 224 | /// \brief Returns the address pool. |
| 225 | AddrPool *getAddrPool() { return &AddressPool; } |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 226 | }; |
| 227 | |
Eric Christopher | 670ee0e | 2013-10-24 21:20:23 +0000 | [diff] [blame] | 228 | /// \brief Helper used to pair up a symbol and its DWARF compile unit. |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 229 | struct SymbolCU { |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 230 | SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {} |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 231 | const MCSymbol *Sym; |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 232 | DwarfCompileUnit *CU; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 235 | /// \brief Collects and handles dwarf debug information. |
Timur Iskhodzhanov | 1cd1444 | 2013-12-03 15:10:23 +0000 | [diff] [blame] | 236 | class DwarfDebug : public AsmPrinterHandler { |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 237 | // Target of Dwarf emission. |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 238 | AsmPrinter *Asm; |
Chris Lattner | acda87b | 2010-04-05 05:31:04 +0000 | [diff] [blame] | 239 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 240 | // Collected machine module information. |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 241 | MachineModuleInfo *MMI; |
| 242 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 243 | // All DIEValues are allocated through this allocator. |
Benjamin Kramer | 0748008 | 2012-06-09 10:34:15 +0000 | [diff] [blame] | 244 | BumpPtrAllocator DIEValueAllocator; |
| 245 | |
Eric Christopher | bfe7d29 | 2013-12-03 22:05:55 +0000 | [diff] [blame] | 246 | // Handle to the compile unit used for the inline extension handling, |
| 247 | // this is just so that the DIEValue allocator has a place to store |
| 248 | // the particular elements. |
| 249 | // FIXME: Store these off of DwarfDebug instead? |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 250 | DwarfCompileUnit *FirstCU; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 251 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 252 | // Maps MDNode with its corresponding DwarfCompileUnit. |
Eric Christopher | 179fba1 | 2014-01-29 22:06:23 +0000 | [diff] [blame] | 253 | MapVector<const MDNode *, DwarfCompileUnit *> CUMap; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 254 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 255 | // Maps subprogram MDNode with its corresponding DwarfCompileUnit. |
| 256 | DenseMap<const MDNode *, DwarfCompileUnit *> SPMap; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 257 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 258 | // Maps a CU DIE with its corresponding DwarfCompileUnit. |
| 259 | DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap; |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 260 | |
Eric Christopher | 47f2be8 | 2014-03-20 19:16:20 +0000 | [diff] [blame] | 261 | /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 262 | /// be shared across CUs, that is why we keep the map here instead |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 263 | /// of in DwarfCompileUnit. |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 264 | DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap; |
| 265 | |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 266 | // List of all labels used in aranges generation. |
| 267 | std::vector<SymbolCU> ArangeLabels; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 268 | |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 269 | // Size of each symbol emitted (for those symbols that have a specific size). |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 270 | DenseMap<const MCSymbol *, uint64_t> SymSize; |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 271 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 272 | // Provides a unique id per text section. |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 273 | typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType; |
| 274 | SectionMapType SectionMap; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 275 | |
Eric Christopher | aba20dd | 2013-07-08 21:16:18 +0000 | [diff] [blame] | 276 | // List of arguments for current function. |
David Blaikie | afd2c6b | 2014-04-22 05:41:06 +0000 | [diff] [blame^] | 277 | SmallVector<DbgVariable *, 8> CurrentFnArguments; |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 278 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 279 | LexicalScopes LScopes; |
Devang Patel | 95cd4b9 | 2010-03-25 15:09:44 +0000 | [diff] [blame] | 280 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 281 | // Collection of abstract subprogram DIEs. |
Devang Patel | a37a95e | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 282 | DenseMap<const MDNode *, DIE *> AbstractSPDies; |
| 283 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 284 | // Collection of dbg variables of a scope. |
David Blaikie | afd2c6b | 2014-04-22 05:41:06 +0000 | [diff] [blame^] | 285 | typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> > |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 286 | ScopeVariablesMap; |
Craig Topper | 2b4a201 | 2013-07-03 04:40:27 +0000 | [diff] [blame] | 287 | ScopeVariablesMap ScopeVariables; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 288 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 289 | // Collection of abstract variables. |
Devang Patel | 32cc43c | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 290 | DenseMap<const MDNode *, DbgVariable *> AbstractVariables; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 291 | |
David Blaikie | 0a456de | 2014-04-02 01:43:18 +0000 | [diff] [blame] | 292 | // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists |
| 293 | // can refer to them in spite of insertions into this list. |
| 294 | SmallVector<DebugLocList, 4> DotDebugLocEntries; |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 295 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 296 | // Collection of subprogram DIEs that are marked (at the end of the module) |
| 297 | // as DW_AT_inline. |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 298 | SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs; |
| 299 | |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 300 | // This is a collection of subprogram MDNodes that are processed to |
| 301 | // create DIEs. |
Devang Patel | f3b2db6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 302 | SmallPtrSet<const MDNode *, 16> ProcessedSPNodes; |
| 303 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 304 | // Maps instruction with label emitted before instruction. |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 305 | DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn; |
Devang Patel | 3ebd893 | 2010-04-08 16:50:29 +0000 | [diff] [blame] | 306 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 307 | // Maps instruction with label emitted after instruction. |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 308 | DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn; |
Devang Patel | 3ebd893 | 2010-04-08 16:50:29 +0000 | [diff] [blame] | 309 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 310 | // Every user variable mentioned by a DBG_VALUE instruction in order of |
| 311 | // appearance. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 312 | SmallVector<const MDNode *, 8> UserVariables; |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 313 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 314 | // For each user variable, keep a list of DBG_VALUE instructions in order. |
| 315 | // The list can also contain normal instructions that clobber the previous |
| 316 | // DBG_VALUE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 317 | typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> > |
| 318 | DbgValueHistoryMap; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 319 | DbgValueHistoryMap DbgValues; |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 320 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 321 | // Previous instruction's location information. This is used to determine |
| 322 | // label location to indicate scope boundries in dwarf debug info. |
Chris Lattner | 915c5f9 | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 323 | DebugLoc PrevInstLoc; |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 324 | MCSymbol *PrevLabel; |
Devang Patel | bd477be | 2010-03-29 17:20:31 +0000 | [diff] [blame] | 325 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 326 | // This location indicates end of function prologue and beginning of function |
| 327 | // body. |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 328 | DebugLoc PrologEndLoc; |
| 329 | |
Timur Iskhodzhanov | 1cd1444 | 2013-12-03 15:10:23 +0000 | [diff] [blame] | 330 | // If nonnull, stores the current machine function we're processing. |
| 331 | const MachineFunction *CurFn; |
| 332 | |
| 333 | // If nonnull, stores the current machine instruction we're processing. |
| 334 | const MachineInstr *CurMI; |
| 335 | |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 336 | // If nonnull, stores the section that the previous function was allocated to |
| 337 | // emitting. |
| 338 | const MCSection *PrevSection; |
| 339 | |
| 340 | // If nonnull, stores the CU in which the previous subprogram was contained. |
| 341 | const DwarfCompileUnit *PrevCU; |
| 342 | |
Chris Lattner | 6629ca9 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 343 | // Section Symbols: these are assembler temporary labels that are emitted at |
| 344 | // the beginning of each supported dwarf section. These are used to form |
| 345 | // section offsets and are created by EmitSectionLabels. |
Rafael Espindola | a716096 | 2011-05-06 14:56:22 +0000 | [diff] [blame] | 346 | MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym; |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 347 | MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym; |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 348 | MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym; |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 349 | MCSymbol *FunctionBeginSym, *FunctionEndSym; |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 350 | MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym; |
David Blaikie | e12ab12 | 2014-04-01 16:09:49 +0000 | [diff] [blame] | 351 | MCSymbol *DwarfStrDWOSectionSym; |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 352 | MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym; |
Devang Patel | 9c160e1 | 2010-07-08 20:10:35 +0000 | [diff] [blame] | 353 | |
Nick Lewycky | d1ee7f8 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 354 | // As an optimization, there is no need to emit an entry in the directory |
Eric Christopher | 808fd7b | 2013-07-03 01:57:23 +0000 | [diff] [blame] | 355 | // table for the same directory as DW_AT_comp_dir. |
Nick Lewycky | d1ee7f8 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 356 | StringRef CompilationDir; |
| 357 | |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 358 | // Counter for assigning globally unique IDs for ranges. |
| 359 | unsigned GlobalRangeCount; |
| 360 | |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 361 | // Holder for the file specific debug information. |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 362 | DwarfFile InfoHolder; |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 363 | |
Eric Christopher | 0aa4a67 | 2012-12-10 22:25:41 +0000 | [diff] [blame] | 364 | // Holders for the various debug information flags that we might need to |
| 365 | // have exposed. See accessor functions below for description. |
| 366 | |
Eric Christopher | 070bf16 | 2013-07-03 01:57:26 +0000 | [diff] [blame] | 367 | // Holder for imported entities. |
| 368 | typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32> |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 369 | ImportedEntityMap; |
Eric Christopher | 070bf16 | 2013-07-03 01:57:26 +0000 | [diff] [blame] | 370 | ImportedEntityMap ScopesWithImportedEntities; |
| 371 | |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 372 | // Map from MDNodes for user-defined types to the type units that describe |
| 373 | // them. |
| 374 | DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits; |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 375 | |
Eric Christopher | 4d36ca0 | 2013-08-26 23:24:35 +0000 | [diff] [blame] | 376 | // Whether to emit the pubnames/pubtypes sections. |
| 377 | bool HasDwarfPubSections; |
| 378 | |
Eric Christopher | 1ad8457 | 2014-01-15 00:04:29 +0000 | [diff] [blame] | 379 | // Whether or not to use AT_ranges for compilation units. |
| 380 | bool HasCURanges; |
| 381 | |
Eric Christopher | 2037caf | 2014-01-28 00:49:26 +0000 | [diff] [blame] | 382 | // Whether we emitted a function into a section other than the default |
| 383 | // text. |
| 384 | bool UsedNonDefaultText; |
| 385 | |
Eric Christopher | 4d36ca0 | 2013-08-26 23:24:35 +0000 | [diff] [blame] | 386 | // Version of dwarf we're emitting. |
| 387 | unsigned DwarfVersion; |
| 388 | |
Eric Christopher | 0a13eb3 | 2013-11-21 22:56:11 +0000 | [diff] [blame] | 389 | // Maps from a type identifier to the actual MDNode. |
| 390 | DITypeIdentifierMap TypeIdentifierMap; |
| 391 | |
Eric Christopher | 42e3994 | 2012-11-29 22:56:13 +0000 | [diff] [blame] | 392 | // DWARF5 Experimental Options |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 393 | bool HasDwarfAccelTables; |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 394 | bool HasSplitDwarf; |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 395 | |
Eric Christopher | d692c1d | 2012-12-11 19:42:09 +0000 | [diff] [blame] | 396 | // Separated Dwarf Variables |
Eric Christopher | d79f548 | 2012-12-10 19:51:13 +0000 | [diff] [blame] | 397 | // In general these will all be for bits that are left in the |
| 398 | // original object file, rather than things that are meant |
| 399 | // to be in the .dwo sections. |
| 400 | |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 401 | // Holder for the skeleton information. |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 402 | DwarfFile SkeletonHolder; |
Eric Christopher | d79f548 | 2012-12-10 19:51:13 +0000 | [diff] [blame] | 403 | |
David Blaikie | 47f4b82 | 2014-03-19 00:11:28 +0000 | [diff] [blame] | 404 | /// Store file names for type units under fission in a line table header that |
| 405 | /// will be emitted into debug_line.dwo. |
| 406 | // FIXME: replace this with a map from comp_dir to table so that we can emit |
| 407 | // multiple tables during LTO each of which uses directory 0, referencing the |
| 408 | // comp_dir of all the type units that use it. |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 409 | MCDwarfDwoLineTable SplitTypeUnitFileTable; |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 410 | |
David Blaikie | 47f4b82 | 2014-03-19 00:11:28 +0000 | [diff] [blame] | 411 | // True iff there are multiple CUs in this module. |
| 412 | bool SingleCU; |
| 413 | |
| 414 | MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &); |
| 415 | |
David Blaikie | afd2c6b | 2014-04-22 05:41:06 +0000 | [diff] [blame^] | 416 | void addScopeVariable(LexicalScope *LS, DbgVariable *Var); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 417 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 418 | const SmallVectorImpl<DwarfUnit *> &getUnits() { |
| 419 | return InfoHolder.getUnits(); |
| 420 | } |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 421 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 422 | /// \brief Find abstract variable associated with Var. |
Devang Patel | e1c53f2 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 423 | DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 424 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 425 | /// \brief Find DIE for the given subprogram and attach appropriate |
| 426 | /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global |
| 427 | /// variables in this scope then create and insert DIEs for these |
| 428 | /// variables. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 429 | DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 430 | |
Eric Christopher | 44e66c1 | 2013-12-03 00:45:56 +0000 | [diff] [blame] | 431 | /// \brief A helper function to check whether the DIE for a given Scope is |
| 432 | /// going to be null. |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 433 | bool isLexicalScopeDIENull(LexicalScope *Scope); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 434 | |
Eric Christopher | be2513e | 2013-12-03 00:45:59 +0000 | [diff] [blame] | 435 | /// \brief A helper function to construct a RangeSpanList for a given |
| 436 | /// lexical scope. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 437 | void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE, |
Eric Christopher | be2513e | 2013-12-03 00:45:59 +0000 | [diff] [blame] | 438 | const SmallVectorImpl<InsnRange> &Range); |
| 439 | |
Eric Christopher | 77913e039 | 2013-12-03 00:45:54 +0000 | [diff] [blame] | 440 | /// \brief Construct new DW_TAG_lexical_block for this scope and |
| 441 | /// attach DW_AT_low_pc/DW_AT_high_pc labels. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 442 | DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope); |
Eric Christopher | 77913e039 | 2013-12-03 00:45:54 +0000 | [diff] [blame] | 443 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 444 | /// \brief This scope represents inlined body of a function. Construct |
| 445 | /// DIE to represent this concrete inlined copy of the function. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 446 | DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope); |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 447 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 448 | /// \brief Construct a DIE for this scope. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 449 | DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope); |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 450 | /// A helper function to create children of a Scope DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 451 | DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 452 | SmallVectorImpl<DIE *> &Children); |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 453 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 454 | /// \brief Emit initial Dwarf sections with a label at the start of each one. |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 455 | void emitSectionLabels(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 456 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 457 | /// \brief Compute the size and offset of a DIE given an incoming Offset. |
Eric Christopher | 1f0cbb8 | 2012-11-20 22:14:13 +0000 | [diff] [blame] | 458 | unsigned computeSizeAndOffset(DIE *Die, unsigned Offset); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 459 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 460 | /// \brief Compute the size and offset of all the DIEs. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 461 | void computeSizeAndOffsets(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 462 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 463 | /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs. |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 464 | void computeInlinedDIEs(); |
| 465 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 466 | /// \brief Collect info for variables that were optimized out. |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 467 | void collectDeadVariables(); |
| 468 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 469 | /// \brief Finish off debug information after all functions have been |
| 470 | /// processed. |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 471 | void finalizeModuleInfo(); |
| 472 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 473 | /// \brief Emit labels to close any remaining sections that have been left |
| 474 | /// open. |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 475 | void endSections(); |
| 476 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 477 | /// \brief Emit the debug info section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 478 | void emitDebugInfo(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 479 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 480 | /// \brief Emit the abbreviation section. |
Eric Christopher | 3837195 | 2012-11-20 23:30:11 +0000 | [diff] [blame] | 481 | void emitAbbreviations(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 482 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 483 | /// \brief Emit the last address of the section and the end of |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 484 | /// the line matrix. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 485 | void emitEndOfLineMatrix(unsigned SectionEnd); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 486 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 487 | /// \brief Emit visible names into a hashed accelerator table section. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 488 | void emitAccelNames(); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 489 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 490 | /// \brief Emit objective C classes and categories into a hashed |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 491 | /// accelerator table section. |
| 492 | void emitAccelObjC(); |
| 493 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 494 | /// \brief Emit namespace dies into a hashed accelerator table. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 495 | void emitAccelNamespaces(); |
| 496 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 497 | /// \brief Emit type dies into a hashed accelerator table. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 498 | void emitAccelTypes(); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 499 | |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 500 | /// \brief Emit visible names into a debug pubnames section. |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 501 | /// \param GnuStyle determines whether or not we want to emit |
| 502 | /// additional information into the table ala newer gcc for gdb |
| 503 | /// index. |
| 504 | void emitDebugPubNames(bool GnuStyle = false); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 505 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 506 | /// \brief Emit visible types into a debug pubtypes section. |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 507 | /// \param GnuStyle determines whether or not we want to emit |
| 508 | /// additional information into the table ala newer gcc for gdb |
| 509 | /// index. |
| 510 | void emitDebugPubTypes(bool GnuStyle = false); |
Devang Patel | 04d2f2d | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 511 | |
David Blaikie | 0f55e83 | 2014-03-11 23:18:15 +0000 | [diff] [blame] | 512 | void |
| 513 | emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name, |
| 514 | const StringMap<const DIE *> &(DwarfUnit::*Accessor)() |
| 515 | const); |
| 516 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 517 | /// \brief Emit visible names into a debug str section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 518 | void emitDebugStr(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 519 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 520 | /// \brief Emit visible names into a debug loc section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 521 | void emitDebugLoc(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 522 | |
David Blaikie | 94c1d7f | 2014-04-02 01:50:20 +0000 | [diff] [blame] | 523 | /// \brief Emit visible names into a debug loc dwo section. |
| 524 | void emitDebugLocDWO(); |
| 525 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 526 | /// \brief Emit visible names into a debug aranges section. |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 527 | void emitDebugARanges(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 528 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 529 | /// \brief Emit visible names into a debug ranges section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 530 | void emitDebugRanges(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 531 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 532 | /// \brief Emit inline info using custom format. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 533 | void emitDebugInlineInfo(); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 534 | |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 535 | /// DWARF 5 Experimental Split Dwarf Emitters |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 536 | |
David Blaikie | 38fe634 | 2014-01-09 04:28:46 +0000 | [diff] [blame] | 537 | /// \brief Initialize common features of skeleton units. |
| 538 | void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU); |
| 539 | |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 540 | /// \brief Construct the split debug info compile unit for the debug info |
| 541 | /// section. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 542 | DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 543 | |
David Blaikie | 15ed5eb | 2014-01-10 01:38:41 +0000 | [diff] [blame] | 544 | /// \brief Construct the split debug info compile unit for the debug info |
| 545 | /// section. |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 546 | DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU); |
David Blaikie | 15ed5eb | 2014-01-10 01:38:41 +0000 | [diff] [blame] | 547 | |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 548 | /// \brief Emit the debug info dwo section. |
| 549 | void emitDebugInfoDWO(); |
| 550 | |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 551 | /// \brief Emit the debug abbrev dwo section. |
| 552 | void emitDebugAbbrevDWO(); |
| 553 | |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 554 | /// \brief Emit the debug line dwo section. |
| 555 | void emitDebugLineDWO(); |
| 556 | |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 557 | /// \brief Emit the debug str dwo section. |
| 558 | void emitDebugStrDWO(); |
| 559 | |
David Blaikie | 3c84262 | 2013-12-04 21:31:26 +0000 | [diff] [blame] | 560 | /// Flags to let the linker know we have emitted new style pubnames. Only |
| 561 | /// emit it here if we don't have a skeleton CU for split dwarf. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 562 | void addGnuPubAttributes(DwarfUnit *U, DIE *D) const; |
David Blaikie | 3c84262 | 2013-12-04 21:31:26 +0000 | [diff] [blame] | 563 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 564 | /// \brief Create new DwarfCompileUnit for the given metadata node with tag |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 565 | /// DW_TAG_compile_unit. |
David Blaikie | 47f4b82 | 2014-03-19 00:11:28 +0000 | [diff] [blame] | 566 | DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit); |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 567 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 568 | /// \brief Construct subprogram DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 569 | void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 570 | |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 571 | /// \brief Construct imported_module or imported_declaration DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 572 | void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 573 | |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 574 | /// \brief Construct import_module DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 575 | void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N, |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 576 | DIE *Context); |
| 577 | |
| 578 | /// \brief Construct import_module DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 579 | void constructImportedEntityDIE(DwarfCompileUnit *TheCU, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 580 | const DIImportedEntity &Module, DIE *Context); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 581 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 582 | /// \brief Register a source line with debug info. Returns the unique |
| 583 | /// label that was emitted and which provides correspondence to the |
| 584 | /// source line list. |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 585 | void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope, |
| 586 | unsigned Flags); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 587 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 588 | /// \brief Indentify instructions that are marking the beginning of or |
| 589 | /// ending of a scope. |
Devang Patel | 359b013 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 590 | void identifyScopeMarkers(); |
Devang Patel | f1d5a1e | 2010-04-08 15:37:09 +0000 | [diff] [blame] | 591 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 592 | /// \brief If Var is an current function argument that add it in |
| 593 | /// CurrentFnArguments list. |
David Blaikie | afd2c6b | 2014-04-22 05:41:06 +0000 | [diff] [blame^] | 594 | bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope); |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 595 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 596 | /// \brief Populate LexicalScope entries with variables' info. |
Timur Iskhodzhanov | 1cd1444 | 2013-12-03 15:10:23 +0000 | [diff] [blame] | 597 | void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 598 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 599 | /// \brief Collect variable information from the side table maintained |
| 600 | /// by MMI. |
Timur Iskhodzhanov | 1cd1444 | 2013-12-03 15:10:23 +0000 | [diff] [blame] | 601 | void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 602 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 603 | /// \brief Ensure that a label will be emitted before MI. |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 604 | void requestLabelBeforeInsn(const MachineInstr *MI) { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 605 | LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0)); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 608 | /// \brief Return Label preceding the instruction. |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 609 | MCSymbol *getLabelBeforeInsn(const MachineInstr *MI); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 610 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 611 | /// \brief Ensure that a label will be emitted after MI. |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 612 | void requestLabelAfterInsn(const MachineInstr *MI) { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 613 | LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0)); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 616 | /// \brief Return Label immediately following the instruction. |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 617 | MCSymbol *getLabelAfterInsn(const MachineInstr *MI); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 618 | |
David Blaikie | 4bd13b7 | 2014-03-07 18:49:45 +0000 | [diff] [blame] | 619 | void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin, |
| 620 | MCSymbol *End); |
| 621 | |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 622 | public: |
| 623 | //===--------------------------------------------------------------------===// |
| 624 | // Main entry points. |
| 625 | // |
Chris Lattner | f0d6bd3 | 2010-04-05 05:11:15 +0000 | [diff] [blame] | 626 | DwarfDebug(AsmPrinter *A, Module *M); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 627 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 628 | void insertDIE(const MDNode *TypeMD, DIE *Die) { |
| 629 | MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); |
| 630 | } |
| 631 | DIE *getDIE(const MDNode *TypeMD) { |
| 632 | return MDTypeNodeToDieMap.lookup(TypeMD); |
| 633 | } |
| 634 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 635 | /// \brief Emit all Dwarf sections that should come prior to the |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 636 | /// content. |
Eric Christopher | 58f4195 | 2012-11-19 22:42:15 +0000 | [diff] [blame] | 637 | void beginModule(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 638 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 639 | /// \brief Emit all Dwarf sections that should come after the content. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 640 | void endModule() override; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 641 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 642 | /// \brief Gather pre-function debug information. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 643 | void beginFunction(const MachineFunction *MF) override; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 644 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 645 | /// \brief Gather and emit post-function debug information. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 646 | void endFunction(const MachineFunction *MF) override; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 647 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 648 | /// \brief Process beginning of an instruction. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 649 | void beginInstruction(const MachineInstr *MI) override; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 650 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 651 | /// \brief Process end of an instruction. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 652 | void endInstruction() override; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 653 | |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 654 | /// \brief Add a DIE to the set of types that we're going to pull into |
| 655 | /// type units. |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 656 | void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 657 | DIE *Die, DICompositeType CTy); |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 658 | |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 659 | /// \brief Add a label so that arange data can be generated for it. |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 660 | void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); } |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 661 | |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 662 | /// \brief For symbols that have a size designated (e.g. common symbols), |
| 663 | /// this tracks that size. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 664 | void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 665 | SymSize[Sym] = Size; |
| 666 | } |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 667 | |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 668 | /// \brief Recursively Emits a debug information entry. |
David Blaikie | b818418 | 2014-04-14 22:45:02 +0000 | [diff] [blame] | 669 | void emitDIE(DIE &Die); |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 670 | |
Eric Christopher | 55c5181 | 2012-11-21 00:03:31 +0000 | [diff] [blame] | 671 | // Experimental DWARF5 features. |
| 672 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 673 | /// \brief Returns whether or not to emit tables that dwarf consumers can |
| 674 | /// use to accelerate lookup. |
Eric Christopher | 411bd59 | 2014-03-06 00:00:53 +0000 | [diff] [blame] | 675 | bool useDwarfAccelTables() const { return HasDwarfAccelTables; } |
Eric Christopher | 55c5181 | 2012-11-21 00:03:31 +0000 | [diff] [blame] | 676 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 677 | /// \brief Returns whether or not to change the current debug info for the |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 678 | /// split dwarf proposal support. |
Eric Christopher | 411bd59 | 2014-03-06 00:00:53 +0000 | [diff] [blame] | 679 | bool useSplitDwarf() const { return HasSplitDwarf; } |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 680 | |
| 681 | /// Returns the Dwarf Version. |
| 682 | unsigned getDwarfVersion() const { return DwarfVersion; } |
Manman Ren | 6035203 | 2013-09-05 18:48:31 +0000 | [diff] [blame] | 683 | |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 684 | /// Returns the section symbol for the .debug_loc section. |
| 685 | MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; } |
| 686 | |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 687 | /// Returns the previous section that was emitted into. |
| 688 | const MCSection *getPrevSection() const { return PrevSection; } |
| 689 | |
| 690 | /// Returns the previous CU that was being updated |
| 691 | const DwarfCompileUnit *getPrevCU() const { return PrevCU; } |
| 692 | |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 693 | /// Returns the entries for the .debug_loc section. |
David Blaikie | 0a456de | 2014-04-02 01:43:18 +0000 | [diff] [blame] | 694 | const SmallVectorImpl<DebugLocList> & |
David Blaikie | 84d8e18 | 2014-03-24 22:38:38 +0000 | [diff] [blame] | 695 | getDebugLocEntries() const { |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 696 | return DotDebugLocEntries; |
| 697 | } |
| 698 | |
| 699 | /// \brief Emit an entry for the debug loc section. This can be used to |
| 700 | /// handle an entry that's going to be emitted into the debug loc section. |
Eric Christopher | 05135fb | 2014-03-18 02:18:24 +0000 | [diff] [blame] | 701 | void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry); |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 702 | |
David Blaikie | 0e84adc | 2014-04-01 16:17:41 +0000 | [diff] [blame] | 703 | /// Emit the location for a debug loc entry, including the size header. |
| 704 | void emitDebugLocEntryLocation(const DebugLocEntry &Entry); |
| 705 | |
Eric Christopher | 87b9c49 | 2013-10-05 00:32:34 +0000 | [diff] [blame] | 706 | /// Find the MDNode for the given reference. |
| 707 | template <typename T> T resolve(DIRef<T> Ref) const { |
Manman Ren | 34b3dcc | 2013-09-10 18:30:07 +0000 | [diff] [blame] | 708 | return Ref.resolve(TypeIdentifierMap); |
| 709 | } |
Manman Ren | 6035203 | 2013-09-05 18:48:31 +0000 | [diff] [blame] | 710 | |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 711 | /// \brief Return the TypeIdentifierMap. |
Eric Christopher | c0bd5f8 | 2014-03-18 20:39:54 +0000 | [diff] [blame] | 712 | const DITypeIdentifierMap &getTypeIdentifierMap() const { |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 713 | return TypeIdentifierMap; |
| 714 | } |
| 715 | |
Eric Christopher | dd50838 | 2014-03-06 00:00:56 +0000 | [diff] [blame] | 716 | /// Find the DwarfCompileUnit for the given CU Die. |
| 717 | DwarfCompileUnit *lookupUnit(const DIE *CU) const { |
| 718 | return CUDieMap.lookup(CU); |
| 719 | } |
Manman Ren | 3eb9dff | 2013-09-09 19:05:21 +0000 | [diff] [blame] | 720 | /// isSubprogramContext - Return true if Context is either a subprogram |
| 721 | /// or another context nested inside a subprogram. |
| 722 | bool isSubprogramContext(const MDNode *Context); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 723 | }; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 724 | } // End of namespace llvm |
| 725 | |
| 726 | #endif |