David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- C++ -*--===// |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf compile unit. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |
| 15 | #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |
| 16 | |
| 17 | #include "DIE.h" |
Eric Christopher | 9e429ae | 2013-10-05 00:27:02 +0000 | [diff] [blame] | 18 | #include "DwarfDebug.h" |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Optional.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringMap.h" |
Adrian Prantl | 702bf5a | 2014-03-18 02:34:52 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/AsmPrinter.h" |
Chandler Carruth | 12664a0 | 2014-03-06 00:22:06 +0000 | [diff] [blame] | 23 | #include "llvm/IR/DIBuilder.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 24 | #include "llvm/IR/DebugInfo.h" |
David Blaikie | f3cd7c5 | 2013-06-28 20:05:04 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCExpr.h" |
David Blaikie | 7d73460 | 2013-12-06 22:33:05 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSection.h" |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCDwarf.h" |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
| 30 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 31 | class MachineLocation; |
| 32 | class MachineOperand; |
| 33 | class ConstantInt; |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 34 | class ConstantFP; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 35 | class DbgVariable; |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 36 | class DwarfCompileUnit; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 37 | |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 38 | // Data structure to hold a range for range lists. |
| 39 | class RangeSpan { |
| 40 | public: |
| 41 | RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {} |
Eric Christopher | 270ba4a | 2013-12-04 19:06:58 +0000 | [diff] [blame] | 42 | const MCSymbol *getStart() const { return Start; } |
| 43 | const MCSymbol *getEnd() const { return End; } |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 44 | void setEnd(const MCSymbol *E) { End = E; } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | const MCSymbol *Start, *End; |
| 48 | }; |
| 49 | |
| 50 | class RangeSpanList { |
| 51 | private: |
| 52 | // Index for locating within the debug_range section this particular span. |
Eric Christopher | f879064 | 2013-12-04 22:04:50 +0000 | [diff] [blame] | 53 | MCSymbol *RangeSym; |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 54 | // List of ranges. |
| 55 | SmallVector<RangeSpan, 2> Ranges; |
| 56 | |
| 57 | public: |
Eric Christopher | f879064 | 2013-12-04 22:04:50 +0000 | [diff] [blame] | 58 | RangeSpanList(MCSymbol *Sym) : RangeSym(Sym) {} |
| 59 | MCSymbol *getSym() const { return RangeSym; } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 60 | const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; } |
| 61 | void addRange(RangeSpan Range) { Ranges.push_back(Range); } |
| 62 | }; |
| 63 | |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 64 | enum AbstractOrInlined { AOI_None, AOI_Inlined, AOI_Abstract }; |
| 65 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 66 | //===----------------------------------------------------------------------===// |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 67 | /// Unit - This dwarf writer support class manages information associated |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 68 | /// with a source file. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 69 | class DwarfUnit { |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 70 | protected: |
Eli Bendersky | b42d146 | 2012-12-03 18:45:45 +0000 | [diff] [blame] | 71 | /// UniqueID - a numeric ID unique among all CUs in the module |
Eli Bendersky | b42d146 | 2012-12-03 18:45:45 +0000 | [diff] [blame] | 72 | unsigned UniqueID; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 73 | |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 74 | /// Node - MDNode for the compile unit. |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 75 | DICompileUnit CUNode; |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 76 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 77 | /// Unit debug information entry. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 78 | DIE UnitDie; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 79 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 80 | /// Offset of the UnitDie from beginning of debug info section. |
Eric Christopher | a16725b | 2013-11-21 01:29:16 +0000 | [diff] [blame] | 81 | unsigned DebugInfoOffset; |
| 82 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 83 | /// Asm - Target of Dwarf emission. |
| 84 | AsmPrinter *Asm; |
| 85 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 86 | // Holders for some common dwarf information. |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 87 | DwarfDebug *DD; |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 88 | DwarfFile *DU; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 89 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 90 | /// IndexTyDie - An anonymous type for index type. Owned by UnitDie. |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 91 | DIE *IndexTyDie; |
| 92 | |
Eric Christopher | 6156011 | 2013-05-08 00:11:10 +0000 | [diff] [blame] | 93 | /// MDNodeToDieMap - Tracks the mapping of unit level debug information |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 94 | /// variables to debug information entries. |
| 95 | DenseMap<const MDNode *, DIE *> MDNodeToDieMap; |
| 96 | |
Eric Christopher | 6156011 | 2013-05-08 00:11:10 +0000 | [diff] [blame] | 97 | /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 98 | /// descriptors to debug information entries using a DIEEntry proxy. |
| 99 | DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap; |
| 100 | |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 101 | /// GlobalNames - A map of globally visible named entities for this unit. |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 102 | StringMap<const DIE *> GlobalNames; |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 103 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 104 | /// GlobalTypes - A map of globally visible types for this unit. |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 105 | StringMap<const DIE *> GlobalTypes; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 106 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 107 | /// DIEBlocks - A list of all the DIEBlocks in use. |
| 108 | std::vector<DIEBlock *> DIEBlocks; |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 109 | |
| 110 | /// DIELocs - A list of all the DIELocs in use. |
| 111 | std::vector<DIELoc *> DIELocs; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 112 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 113 | /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that |
| 114 | /// need DW_AT_containing_type attribute. This attribute points to a DIE that |
| 115 | /// corresponds to the MDNode mapped with the subprogram DIE. |
| 116 | DenseMap<DIE *, const MDNode *> ContainingTypeMap; |
| 117 | |
Eric Christopher | 46e2343 | 2013-12-20 04:16:18 +0000 | [diff] [blame] | 118 | // List of ranges for a given compile unit. |
| 119 | SmallVector<RangeSpan, 1> CURanges; |
| 120 | |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 121 | // List of range lists for a given compile unit, separate from the ranges for |
| 122 | // the CU itself. |
Eric Christopher | 270ba4a | 2013-12-04 19:06:58 +0000 | [diff] [blame] | 123 | SmallVector<RangeSpanList, 1> CURangeLists; |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 124 | |
Eric Christopher | 3264a48 | 2013-10-05 00:39:55 +0000 | [diff] [blame] | 125 | // DIEValueAllocator - All DIEValues are allocated through this allocator. |
| 126 | BumpPtrAllocator DIEValueAllocator; |
| 127 | |
| 128 | // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently. |
| 129 | DIEInteger *DIEIntegerOne; |
| 130 | |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 131 | /// The section this unit will be emitted in. |
| 132 | const MCSection *Section; |
| 133 | |
| 134 | /// A label at the start of the non-dwo section related to this unit. |
| 135 | MCSymbol *SectionSym; |
| 136 | |
David Blaikie | 7d73460 | 2013-12-06 22:33:05 +0000 | [diff] [blame] | 137 | /// The start of the unit within its section. |
| 138 | MCSymbol *LabelBegin; |
| 139 | |
| 140 | /// The end of the unit within its section. |
| 141 | MCSymbol *LabelEnd; |
| 142 | |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 143 | /// Skeleton unit associated with this unit. |
| 144 | DwarfUnit *Skeleton; |
| 145 | |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 146 | DwarfUnit(unsigned UID, dwarf::Tag, DICompileUnit CU, AsmPrinter *A, |
| 147 | DwarfDebug *DW, DwarfFile *DWU); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 148 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 149 | public: |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 150 | virtual ~DwarfUnit(); |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 151 | |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 152 | /// Set the skeleton unit associated with this unit. |
David Blaikie | f9b6a55 | 2014-04-22 22:39:41 +0000 | [diff] [blame] | 153 | void setSkeleton(DwarfUnit &Skel) { Skeleton = &Skel; } |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 154 | |
| 155 | /// Get the skeleton unit associated with this unit. |
| 156 | DwarfUnit *getSkeleton() const { return Skeleton; } |
| 157 | |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 158 | /// Pass in the SectionSym even though we could recreate it in every compile |
| 159 | /// unit (type units will have actually distinct symbols once they're in |
| 160 | /// comdat sections). |
| 161 | void initSection(const MCSection *Section, MCSymbol *SectionSym) { |
| 162 | assert(!this->Section); |
| 163 | this->Section = Section; |
| 164 | this->SectionSym = SectionSym; |
David Blaikie | 7d73460 | 2013-12-06 22:33:05 +0000 | [diff] [blame] | 165 | this->LabelBegin = |
| 166 | Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID()); |
| 167 | this->LabelEnd = |
| 168 | Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID()); |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 169 | } |
David Blaikie | 1ab7c2d | 2013-12-09 17:51:30 +0000 | [diff] [blame] | 170 | |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 171 | const MCSection *getSection() const { |
| 172 | assert(Section); |
| 173 | return Section; |
| 174 | } |
| 175 | |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 176 | /// If there's a skeleton then return the section symbol for the skeleton |
| 177 | /// unit, otherwise return the section symbol for this unit. |
| 178 | MCSymbol *getLocalSectionSym() const { |
| 179 | if (Skeleton) |
| 180 | return Skeleton->getSectionSym(); |
Eric Christopher | d4368fd | 2014-01-02 21:03:28 +0000 | [diff] [blame] | 181 | return getSectionSym(); |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 182 | } |
| 183 | |
David Blaikie | 7d73460 | 2013-12-06 22:33:05 +0000 | [diff] [blame] | 184 | MCSymbol *getSectionSym() const { |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 185 | assert(Section); |
| 186 | return SectionSym; |
| 187 | } |
| 188 | |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 189 | /// If there's a skeleton then return the begin label for the skeleton unit, |
| 190 | /// otherwise return the local label for this unit. |
| 191 | MCSymbol *getLocalLabelBegin() const { |
| 192 | if (Skeleton) |
| 193 | return Skeleton->getLabelBegin(); |
Eric Christopher | d4368fd | 2014-01-02 21:03:28 +0000 | [diff] [blame] | 194 | return getLabelBegin(); |
Eric Christopher | d866720 | 2013-12-30 17:22:27 +0000 | [diff] [blame] | 195 | } |
| 196 | |
David Blaikie | 7d73460 | 2013-12-06 22:33:05 +0000 | [diff] [blame] | 197 | MCSymbol *getLabelBegin() const { |
| 198 | assert(Section); |
| 199 | return LabelBegin; |
| 200 | } |
| 201 | |
| 202 | MCSymbol *getLabelEnd() const { |
| 203 | assert(Section); |
| 204 | return LabelEnd; |
| 205 | } |
| 206 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 207 | // Accessors. |
Eric Christopher | ca68bbf | 2013-08-26 23:58:22 +0000 | [diff] [blame] | 208 | unsigned getUniqueID() const { return UniqueID; } |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 209 | uint16_t getLanguage() const { return CUNode.getLanguage(); } |
| 210 | DICompileUnit getCUNode() const { return CUNode; } |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 211 | DIE &getUnitDie() { return UnitDie; } |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 212 | const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; } |
| 213 | const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; } |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 214 | |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 215 | unsigned getDebugInfoOffset() const { return DebugInfoOffset; } |
| 216 | void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; } |
| 217 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 218 | /// hasContent - Return true if this compile unit has something to write out. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 219 | bool hasContent() const { return !UnitDie.getChildren().empty(); } |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 220 | |
Eric Christopher | 46e2343 | 2013-12-20 04:16:18 +0000 | [diff] [blame] | 221 | /// addRange - Add an address range to the list of ranges for this unit. |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 222 | void addRange(RangeSpan Range); |
Eric Christopher | 46e2343 | 2013-12-20 04:16:18 +0000 | [diff] [blame] | 223 | |
| 224 | /// getRanges - Get the list of ranges for this unit. |
| 225 | const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; } |
| 226 | SmallVectorImpl<RangeSpan> &getRanges() { return CURanges; } |
| 227 | |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 228 | /// addRangeList - Add an address range list to the list of range lists. |
Eric Christopher | 270ba4a | 2013-12-04 19:06:58 +0000 | [diff] [blame] | 229 | void addRangeList(RangeSpanList Ranges) { CURangeLists.push_back(Ranges); } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 230 | |
| 231 | /// getRangeLists - Get the vector of range lists. |
Eric Christopher | 270ba4a | 2013-12-04 19:06:58 +0000 | [diff] [blame] | 232 | const SmallVectorImpl<RangeSpanList> &getRangeLists() const { |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 233 | return CURangeLists; |
| 234 | } |
Eric Christopher | 270ba4a | 2013-12-04 19:06:58 +0000 | [diff] [blame] | 235 | SmallVectorImpl<RangeSpanList> &getRangeLists() { return CURangeLists; } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 236 | |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 237 | /// getParentContextString - Get a string containing the language specific |
| 238 | /// context for a global name. |
| 239 | std::string getParentContextString(DIScope Context) const; |
| 240 | |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 241 | /// addGlobalName - Add a new global entity to the compile unit. |
| 242 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 243 | void addGlobalName(StringRef Name, DIE &Die, DIScope Context); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 244 | |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 245 | /// addAccelNamespace - Add a new name to the namespace accelerator table. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 246 | void addAccelNamespace(StringRef Name, const DIE &Die); |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 247 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 248 | /// getDIE - Returns the debug information entry map slot for the |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 249 | /// specified debug variable. We delegate the request to DwarfDebug |
| 250 | /// when the MDNode can be part of the type system, since DIEs for |
| 251 | /// the type system can be shared across CUs and the mappings are |
| 252 | /// kept in DwarfDebug. |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 253 | DIE *getDIE(DIDescriptor D) const; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 254 | |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 255 | /// getDIELoc - Returns a fresh newly allocated DIELoc. |
| 256 | DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc(); } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 257 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 258 | /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug |
| 259 | /// when the MDNode can be part of the type system, since DIEs for |
| 260 | /// the type system can be shared across CUs and the mappings are |
| 261 | /// kept in DwarfDebug. |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 262 | void insertDIE(DIDescriptor Desc, DIE *D); |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 263 | |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 264 | /// addFlag - Add a flag that is true to the DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 265 | void addFlag(DIE &Die, dwarf::Attribute Attribute); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 266 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 267 | /// addUInt - Add an unsigned integer attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 268 | void addUInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form, |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 269 | uint64_t Integer); |
| 270 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 271 | void addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 272 | |
| 273 | /// addSInt - Add an signed integer attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 274 | void addSInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form, |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 275 | int64_t Integer); |
| 276 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 277 | void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 278 | |
| 279 | /// addString - Add a string attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 280 | void addString(DIE &Die, dwarf::Attribute Attribute, const StringRef Str); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 281 | |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 282 | /// addLocalString - Add a string attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 283 | void addLocalString(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 284 | const StringRef Str); |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 285 | |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 286 | /// addExpr - Add a Dwarf expression attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 287 | void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr); |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 288 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 289 | /// addLabel - Add a Dwarf label attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 290 | void addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 291 | const MCSymbol *Label); |
| 292 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 293 | void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 294 | |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 295 | /// addLocationList - Add a Dwarf loclistptr attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 296 | void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index); |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 297 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 298 | /// addSectionLabel - Add a Dwarf section label attribute data and value. |
| 299 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 300 | void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | f52eddf | 2013-11-26 22:23:27 +0000 | [diff] [blame] | 301 | const MCSymbol *Label); |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 302 | |
| 303 | /// addSectionOffset - Add an offset into a section attribute data and value. |
| 304 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 305 | void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer); |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 306 | |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 307 | /// addOpAddress - Add a dwarf op address data and value using the |
| 308 | /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 309 | void addOpAddress(DIELoc &Die, const MCSymbol *Label); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 310 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 311 | /// addSectionDelta - Add a label delta attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 312 | void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 313 | const MCSymbol *Lo); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 314 | |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 315 | /// addLabelDelta - Add a label delta attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 316 | void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 317 | const MCSymbol *Lo); |
| 318 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 319 | /// addDIEEntry - Add a DIE attribute data and value. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 320 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 321 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 322 | /// addDIEEntry - Add a DIE attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 323 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry *Entry); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 324 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 325 | void addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type); |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 326 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 327 | /// addBlock - Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 328 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 329 | |
| 330 | /// addBlock - Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 331 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 332 | |
| 333 | /// addSourceLine - Add location information to specified debug information |
| 334 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 335 | void addSourceLine(DIE &Die, unsigned Line, StringRef File, |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 336 | StringRef Directory); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 337 | void addSourceLine(DIE &Die, DIVariable V); |
| 338 | void addSourceLine(DIE &Die, DIGlobalVariable G); |
| 339 | void addSourceLine(DIE &Die, DISubprogram SP); |
| 340 | void addSourceLine(DIE &Die, DIType Ty); |
| 341 | void addSourceLine(DIE &Die, DINameSpace NS); |
| 342 | void addSourceLine(DIE &Die, DIObjCProperty Ty); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 343 | |
| 344 | /// addAddress - Add an address attribute to a die based on the location |
| 345 | /// provided. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 346 | void addAddress(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 347 | const MachineLocation &Location, bool Indirect = false); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 348 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 349 | /// addConstantValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 350 | void addConstantValue(DIE &Die, const MachineOperand &MO, DIType Ty); |
David Blaikie | c0a2841 | 2014-05-11 15:56:59 +0000 | [diff] [blame] | 351 | void addConstantValue(DIE &Die, const ConstantInt *CI, DIType Ty); |
| 352 | void addConstantValue(DIE &Die, const APInt &Val, DIType Ty); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 353 | void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned); |
David Blaikie | 60cae1b | 2014-05-11 16:08:41 +0000 | [diff] [blame] | 354 | void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 355 | |
| 356 | /// addConstantFPValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 357 | void addConstantFPValue(DIE &Die, const MachineOperand &MO); |
| 358 | void addConstantFPValue(DIE &Die, const ConstantFP *CFP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 359 | |
| 360 | /// addTemplateParams - Add template parameters in buffer. |
| 361 | void addTemplateParams(DIE &Buffer, DIArray TParams); |
| 362 | |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 363 | /// addRegisterOp - Add register operand. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 364 | void addRegisterOp(DIELoc &TheDie, unsigned Reg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 365 | |
| 366 | /// addRegisterOffset - Add register offset. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 367 | void addRegisterOffset(DIELoc &TheDie, unsigned Reg, int64_t Offset); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 368 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 369 | /// addComplexAddress - Start with the address based on the location provided, |
| 370 | /// and generate the DWARF information necessary to find the actual variable |
| 371 | /// (navigating the extra location information encoded in the type) based on |
| 372 | /// the starting location. Add the DWARF information to the die. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 373 | void addComplexAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 374 | dwarf::Attribute Attribute, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 375 | const MachineLocation &Location); |
| 376 | |
| 377 | // FIXME: Should be reformulated in terms of addComplexAddress. |
| 378 | /// addBlockByrefAddress - Start with the address based on the location |
| 379 | /// provided, and generate the DWARF information necessary to find the |
| 380 | /// actual Block variable (navigating the Block struct) based on the |
| 381 | /// starting location. Add the DWARF information to the die. Obsolete, |
| 382 | /// please use addComplexAddress instead. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 383 | void addBlockByrefAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 384 | dwarf::Attribute Attribute, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 385 | const MachineLocation &Location); |
| 386 | |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 387 | /// addVariableAddress - Add DW_AT_location attribute for a |
Devang Patel | 77dc541 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 388 | /// DbgVariable based on provided MachineLocation. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 389 | void addVariableAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 390 | MachineLocation Location); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 391 | |
Eric Christopher | 7285c7d | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 392 | /// addType - Add a new type attribute to the specified entity. This takes |
| 393 | /// and attribute parameter because DW_AT_friend attributes are also |
| 394 | /// type references. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 395 | void addType(DIE &Entity, DIType Ty, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 396 | dwarf::Attribute Attribute = dwarf::DW_AT_type); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 397 | |
| 398 | /// getOrCreateNameSpace - Create a DIE for DINameSpace. |
| 399 | DIE *getOrCreateNameSpace(DINameSpace NS); |
| 400 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 401 | /// getOrCreateSubprogramDIE - Create new DIE using SP. |
| 402 | DIE *getOrCreateSubprogramDIE(DISubprogram SP); |
| 403 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 404 | /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the |
| 405 | /// given DIType. |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 406 | DIE *getOrCreateTypeDIE(const MDNode *N); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 407 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 408 | /// getOrCreateContextDIE - Get context owner's DIE. |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 409 | DIE *createTypeDIE(DICompositeType Ty); |
| 410 | |
| 411 | /// getOrCreateContextDIE - Get context owner's DIE. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 412 | DIE *getOrCreateContextDIE(DIScope Context); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 413 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 414 | /// constructContainingTypeDIEs - Construct DIEs for types that contain |
| 415 | /// vtables. |
| 416 | void constructContainingTypeDIEs(); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 417 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 418 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
David Blaikie | 914046e | 2014-04-25 20:00:34 +0000 | [diff] [blame] | 419 | std::unique_ptr<DIE> constructVariableDIE(DbgVariable &DV, |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 420 | AbstractOrInlined AbsIn = AOI_None); |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 421 | |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 422 | /// constructSubprogramArguments - Construct function argument DIEs. |
David Blaikie | 899ae61 | 2014-04-30 22:58:19 +0000 | [diff] [blame] | 423 | void constructSubprogramArguments(DIE &Buffer, DIArray Args); |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 424 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 425 | /// Create a DIE with the given Tag, add the DIE to its parent, and |
| 426 | /// call insertDIE if MD is not null. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 427 | DIE &createAndAddDIE(unsigned Tag, DIE &Parent, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 428 | DIDescriptor N = DIDescriptor()); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 429 | |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 430 | /// Compute the size of a header for this unit, not including the initial |
| 431 | /// length field. |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 432 | virtual unsigned getHeaderSize() const { |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 433 | return sizeof(int16_t) + // DWARF version number |
| 434 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 435 | sizeof(int8_t); // Pointer Size (in bytes) |
| 436 | } |
| 437 | |
| 438 | /// Emit the header for this unit, not including the initial length field. |
David Blaikie | d82b237 | 2014-03-24 20:28:10 +0000 | [diff] [blame] | 439 | virtual void emitHeader(const MCSymbol *ASectionSym) const; |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 440 | |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 441 | virtual DwarfCompileUnit &getCU() = 0; |
David Blaikie | d696fac | 2014-02-12 00:32:05 +0000 | [diff] [blame] | 442 | |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 443 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
| 444 | void constructTypeDIE(DIE &Buffer, DICompositeType CTy); |
| 445 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 446 | protected: |
| 447 | /// getOrCreateStaticMemberDIE - Create new static data member DIE. |
| 448 | DIE *getOrCreateStaticMemberDIE(DIDerivedType DT); |
| 449 | |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 450 | /// Look up the source ID with the given directory and source file names. If |
| 451 | /// none currently exists, create a new ID and insert it in the line table. |
| 452 | virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0; |
| 453 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 454 | private: |
David Blaikie | e071fc8 | 2014-04-25 17:32:19 +0000 | [diff] [blame] | 455 | /// \brief Construct a DIE for the given DbgVariable without initializing the |
| 456 | /// DbgVariable's DIE reference. |
David Blaikie | 914046e | 2014-04-25 20:00:34 +0000 | [diff] [blame] | 457 | std::unique_ptr<DIE> constructVariableDIEImpl(const DbgVariable &DV, |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 458 | AbstractOrInlined AbsIn); |
David Blaikie | e071fc8 | 2014-04-25 17:32:19 +0000 | [diff] [blame] | 459 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 460 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
Eric Christopher | f0388b7 | 2013-10-04 23:49:29 +0000 | [diff] [blame] | 461 | void constructTypeDIE(DIE &Buffer, DIBasicType BTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 462 | |
| 463 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
Eric Christopher | f0388b7 | 2013-10-04 23:49:29 +0000 | [diff] [blame] | 464 | void constructTypeDIE(DIE &Buffer, DIDerivedType DTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 465 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 466 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
| 467 | void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy); |
| 468 | |
| 469 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 470 | void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 471 | |
| 472 | /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 473 | void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 474 | |
Manman Ren | 230ec86 | 2013-10-23 23:00:44 +0000 | [diff] [blame] | 475 | /// constructMemberDIE - Construct member DIE from DIDerivedType. |
| 476 | void constructMemberDIE(DIE &Buffer, DIDerivedType DT); |
Manman Ren | 7cc6270 | 2013-10-18 21:14:19 +0000 | [diff] [blame] | 477 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 478 | /// constructTemplateTypeParameterDIE - Construct new DIE for the given |
| 479 | /// DITemplateTypeParameter. |
| 480 | void constructTemplateTypeParameterDIE(DIE &Buffer, |
| 481 | DITemplateTypeParameter TP); |
Manman Ren | 7cc6270 | 2013-10-18 21:14:19 +0000 | [diff] [blame] | 482 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 483 | /// constructTemplateValueParameterDIE - Construct new DIE for the given |
| 484 | /// DITemplateValueParameter. |
| 485 | void constructTemplateValueParameterDIE(DIE &Buffer, |
| 486 | DITemplateValueParameter TVP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 487 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 488 | /// getLowerBoundDefault - Return the default lower bound for an array. If the |
| 489 | /// DWARF version doesn't handle the language, return -1. |
| 490 | int64_t getDefaultLowerBound() const; |
| 491 | |
| 492 | /// getDIEEntry - Returns the debug information entry for the specified |
| 493 | /// debug variable. |
| 494 | DIEEntry *getDIEEntry(const MDNode *N) const { |
| 495 | return MDNodeToDIEEntryMap.lookup(N); |
| 496 | } |
| 497 | |
| 498 | /// insertDIEEntry - Insert debug information entry into the map. |
| 499 | void insertDIEEntry(const MDNode *N, DIEEntry *E) { |
| 500 | MDNodeToDIEEntryMap.insert(std::make_pair(N, E)); |
| 501 | } |
| 502 | |
| 503 | // getIndexTyDie - Get an anonymous type for index type. |
| 504 | DIE *getIndexTyDie() { return IndexTyDie; } |
| 505 | |
| 506 | // setIndexTyDie - Set D as anonymous type for index which can be reused |
| 507 | // later. |
| 508 | void setIndexTyDie(DIE *D) { IndexTyDie = D; } |
| 509 | |
| 510 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
| 511 | /// information entry. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 512 | DIEEntry *createDIEEntry(DIE &Entry); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 513 | |
Eric Christopher | 9e429ae | 2013-10-05 00:27:02 +0000 | [diff] [blame] | 514 | /// resolve - Look in the DwarfDebug map for the MDNode that |
Eric Christopher | 87b9c49 | 2013-10-05 00:32:34 +0000 | [diff] [blame] | 515 | /// corresponds to the reference. |
Eric Christopher | 9e429ae | 2013-10-05 00:27:02 +0000 | [diff] [blame] | 516 | template <typename T> T resolve(DIRef<T> Ref) const { |
| 517 | return DD->resolve(Ref); |
| 518 | } |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 519 | |
| 520 | /// If this is a named finished type then include it in the list of types for |
| 521 | /// the accelerator tables. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 522 | void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE &TyDIE); |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 523 | }; |
| 524 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 525 | class DwarfCompileUnit : public DwarfUnit { |
David Blaikie | 60e6386 | 2014-02-14 23:58:13 +0000 | [diff] [blame] | 526 | /// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding |
| 527 | /// the need to search for it in applyStmtList. |
| 528 | unsigned stmtListIndex; |
| 529 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 530 | public: |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 531 | DwarfCompileUnit(unsigned UID, DICompileUnit Node, AsmPrinter *A, |
| 532 | DwarfDebug *DW, DwarfFile *DWU); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 533 | |
David Blaikie | 2494fdb | 2014-02-14 22:41:51 +0000 | [diff] [blame] | 534 | void initStmtList(MCSymbol *DwarfLineSectionSym); |
| 535 | |
David Blaikie | 60e6386 | 2014-02-14 23:58:13 +0000 | [diff] [blame] | 536 | /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE. |
| 537 | void applyStmtList(DIE &D); |
| 538 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 539 | /// createGlobalVariableDIE - create global variable DIE. |
| 540 | void createGlobalVariableDIE(DIGlobalVariable GV); |
| 541 | |
| 542 | /// addLabelAddress - Add a dwarf label attribute data and value using |
| 543 | /// either DW_FORM_addr or DW_FORM_GNU_addr_index. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 544 | void addLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 545 | const MCSymbol *Label); |
| 546 | |
| 547 | /// addLocalLabelAddress - Add a dwarf label attribute data and value using |
| 548 | /// DW_FORM_addr only. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 549 | void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 550 | const MCSymbol *Label); |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 551 | |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 552 | DwarfCompileUnit &getCU() override { return *this; } |
David Blaikie | 0e8d401 | 2014-03-17 23:53:25 +0000 | [diff] [blame] | 553 | |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 554 | unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override; |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 555 | }; |
| 556 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 557 | class DwarfTypeUnit : public DwarfUnit { |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 558 | private: |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 559 | uint64_t TypeSignature; |
| 560 | const DIE *Ty; |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 561 | DwarfCompileUnit &CU; |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 562 | MCDwarfDwoLineTable *SplitLineTable; |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 563 | |
| 564 | public: |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 565 | DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A, |
| 566 | DwarfDebug *DW, DwarfFile *DWU, |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 567 | MCDwarfDwoLineTable *SplitLineTable = nullptr); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 568 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 569 | void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 570 | uint64_t getTypeSignature() const { return TypeSignature; } |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 571 | void setType(const DIE *Ty) { this->Ty = Ty; } |
| 572 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 573 | /// Emit the header for this unit, not including the initial length field. |
David Blaikie | d82b237 | 2014-03-24 20:28:10 +0000 | [diff] [blame] | 574 | void emitHeader(const MCSymbol *ASectionSym) const override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 575 | unsigned getHeaderSize() const override { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 576 | return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature |
| 577 | sizeof(uint32_t); // Type DIE Offset |
| 578 | } |
| 579 | void initSection(const MCSection *Section); |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 580 | DwarfCompileUnit &getCU() override { return CU; } |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 581 | |
| 582 | protected: |
| 583 | unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override; |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 584 | }; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 585 | } // end llvm namespace |
| 586 | #endif |