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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 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: |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 58 | RangeSpanList(MCSymbol *Sym, SmallVector<RangeSpan, 2> Ranges) |
| 59 | : RangeSym(Sym), Ranges(std::move(Ranges)) {} |
Eric Christopher | f879064 | 2013-12-04 22:04:50 +0000 | [diff] [blame] | 60 | MCSymbol *getSym() const { return RangeSym; } |
Eric Christopher | 0f63d06 | 2013-12-03 00:45:45 +0000 | [diff] [blame] | 61 | const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; } |
| 62 | void addRange(RangeSpan Range) { Ranges.push_back(Range); } |
| 63 | }; |
| 64 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 66 | /// Unit - This dwarf writer support class manages information associated |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 67 | /// with a source file. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 68 | class DwarfUnit { |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 69 | protected: |
Eli Bendersky | b42d146 | 2012-12-03 18:45:45 +0000 | [diff] [blame] | 70 | /// UniqueID - a numeric ID unique among all CUs in the module |
Eli Bendersky | b42d146 | 2012-12-03 18:45:45 +0000 | [diff] [blame] | 71 | unsigned UniqueID; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 72 | |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 73 | /// Node - MDNode for the compile unit. |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 74 | DICompileUnit CUNode; |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 75 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 76 | /// Unit debug information entry. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 77 | DIE UnitDie; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 78 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 79 | /// Offset of the UnitDie from beginning of debug info section. |
Eric Christopher | a16725b | 2013-11-21 01:29:16 +0000 | [diff] [blame] | 80 | unsigned DebugInfoOffset; |
| 81 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 82 | /// Asm - Target of Dwarf emission. |
| 83 | AsmPrinter *Asm; |
| 84 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 85 | // Holders for some common dwarf information. |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 86 | DwarfDebug *DD; |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 87 | DwarfFile *DU; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 88 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 89 | /// IndexTyDie - An anonymous type for index type. Owned by UnitDie. |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 90 | DIE *IndexTyDie; |
| 91 | |
Eric Christopher | 6156011 | 2013-05-08 00:11:10 +0000 | [diff] [blame] | 92 | /// MDNodeToDieMap - Tracks the mapping of unit level debug information |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 93 | /// variables to debug information entries. |
| 94 | DenseMap<const MDNode *, DIE *> MDNodeToDieMap; |
| 95 | |
Eric Christopher | 6156011 | 2013-05-08 00:11:10 +0000 | [diff] [blame] | 96 | /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 97 | /// descriptors to debug information entries using a DIEEntry proxy. |
| 98 | DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap; |
| 99 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 100 | /// DIEBlocks - A list of all the DIEBlocks in use. |
| 101 | std::vector<DIEBlock *> DIEBlocks; |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 102 | |
| 103 | /// DIELocs - A list of all the DIELocs in use. |
| 104 | std::vector<DIELoc *> DIELocs; |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 105 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 106 | /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that |
| 107 | /// need DW_AT_containing_type attribute. This attribute points to a DIE that |
| 108 | /// corresponds to the MDNode mapped with the subprogram DIE. |
| 109 | DenseMap<DIE *, const MDNode *> ContainingTypeMap; |
| 110 | |
Eric Christopher | 3264a48 | 2013-10-05 00:39:55 +0000 | [diff] [blame] | 111 | // DIEValueAllocator - All DIEValues are allocated through this allocator. |
| 112 | BumpPtrAllocator DIEValueAllocator; |
| 113 | |
| 114 | // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently. |
| 115 | DIEInteger *DIEIntegerOne; |
| 116 | |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 117 | /// The section this unit will be emitted in. |
| 118 | const MCSection *Section; |
| 119 | |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 120 | DwarfUnit(unsigned UID, dwarf::Tag, DICompileUnit CU, AsmPrinter *A, |
| 121 | DwarfDebug *DW, DwarfFile *DWU); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 122 | |
David Blaikie | a34568b | 2014-11-01 20:06:28 +0000 | [diff] [blame] | 123 | void initSection(const MCSection *Section); |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 124 | |
| 125 | /// Add a string attribute data and value. |
| 126 | void addLocalString(DIE &Die, dwarf::Attribute Attribute, StringRef Str); |
| 127 | |
| 128 | void addIndexedString(DIE &Die, dwarf::Attribute Attribute, StringRef Str); |
| 129 | |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame^] | 130 | bool applySubprogramDefinitionAttributes(DISubprogram SP, DIE &SPDie); |
| 131 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 132 | public: |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 133 | virtual ~DwarfUnit(); |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 134 | |
David Blaikie | 03073f7 | 2013-12-06 22:14:48 +0000 | [diff] [blame] | 135 | const MCSection *getSection() const { |
| 136 | assert(Section); |
| 137 | return Section; |
| 138 | } |
| 139 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 140 | // Accessors. |
Eric Christopher | ca68bbf | 2013-08-26 23:58:22 +0000 | [diff] [blame] | 141 | unsigned getUniqueID() const { return UniqueID; } |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 142 | uint16_t getLanguage() const { return CUNode.getLanguage(); } |
| 143 | DICompileUnit getCUNode() const { return CUNode; } |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 144 | DIE &getUnitDie() { return UnitDie; } |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 145 | |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 146 | unsigned getDebugInfoOffset() const { return DebugInfoOffset; } |
| 147 | void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; } |
| 148 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 149 | /// hasContent - Return true if this compile unit has something to write out. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 150 | bool hasContent() const { return !UnitDie.getChildren().empty(); } |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 151 | |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 152 | /// getParentContextString - Get a string containing the language specific |
| 153 | /// context for a global name. |
| 154 | std::string getParentContextString(DIScope Context) const; |
| 155 | |
David Blaikie | 98cf172 | 2014-11-02 06:06:14 +0000 | [diff] [blame] | 156 | /// Add a new global name to the compile unit. |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 157 | virtual void addGlobalName(StringRef Name, DIE &Die, DIScope Context) {} |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 158 | |
David Blaikie | 98cf172 | 2014-11-02 06:06:14 +0000 | [diff] [blame] | 159 | /// Add a new global type to the compile unit. |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 160 | virtual void addGlobalType(DIType Ty, const DIE &Die, DIScope Context) {} |
David Blaikie | 98cf172 | 2014-11-02 06:06:14 +0000 | [diff] [blame] | 161 | |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 162 | /// addAccelNamespace - Add a new name to the namespace accelerator table. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 163 | void addAccelNamespace(StringRef Name, const DIE &Die); |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 164 | |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 165 | /// getDIE - Returns the debug information entry map slot for the |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 166 | /// specified debug variable. We delegate the request to DwarfDebug |
| 167 | /// when the MDNode can be part of the type system, since DIEs for |
| 168 | /// the type system can be shared across CUs and the mappings are |
| 169 | /// kept in DwarfDebug. |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 170 | DIE *getDIE(DIDescriptor D) const; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 171 | |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 172 | /// getDIELoc - Returns a fresh newly allocated DIELoc. |
| 173 | DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc(); } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 174 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 175 | /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug |
| 176 | /// when the MDNode can be part of the type system, since DIEs for |
| 177 | /// the type system can be shared across CUs and the mappings are |
| 178 | /// kept in DwarfDebug. |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 179 | void insertDIE(DIDescriptor Desc, DIE *D); |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 180 | |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 181 | /// addFlag - Add a flag that is true to the DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 182 | void addFlag(DIE &Die, dwarf::Attribute Attribute); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 183 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 184 | /// addUInt - Add an unsigned integer attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 185 | void addUInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form, |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 186 | uint64_t Integer); |
| 187 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 188 | void addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 189 | |
| 190 | /// addSInt - Add an signed integer attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 191 | void addSInt(DIE &Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form, |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 192 | int64_t Integer); |
| 193 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 194 | void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 195 | |
| 196 | /// addString - Add a string attribute data and value. |
Craig Topper | 6dc4a8bc | 2014-08-30 16:48:02 +0000 | [diff] [blame] | 197 | void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 198 | |
| 199 | /// addLabel - Add a Dwarf label attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 200 | void addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 201 | const MCSymbol *Label); |
| 202 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 203 | void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 204 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 205 | /// addSectionOffset - Add an offset into a section attribute data and value. |
| 206 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 207 | void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer); |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 208 | |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 209 | /// addOpAddress - Add a dwarf op address data and value using the |
| 210 | /// 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] | 211 | void addOpAddress(DIELoc &Die, const MCSymbol *Label); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 212 | |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 213 | /// addLabelDelta - Add a label delta attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 214 | void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 215 | const MCSymbol *Lo); |
| 216 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 217 | /// addDIEEntry - Add a DIE attribute data and value. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 218 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 219 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 220 | /// addDIEEntry - Add a DIE attribute data and value. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 221 | void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry *Entry); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 222 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 223 | void addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type); |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 224 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 225 | /// addBlock - Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 226 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 227 | |
| 228 | /// addBlock - Add block data. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 229 | void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 230 | |
| 231 | /// addSourceLine - Add location information to specified debug information |
| 232 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 233 | void addSourceLine(DIE &Die, unsigned Line, StringRef File, |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 234 | StringRef Directory); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 235 | void addSourceLine(DIE &Die, DIVariable V); |
| 236 | void addSourceLine(DIE &Die, DIGlobalVariable G); |
| 237 | void addSourceLine(DIE &Die, DISubprogram SP); |
| 238 | void addSourceLine(DIE &Die, DIType Ty); |
| 239 | void addSourceLine(DIE &Die, DINameSpace NS); |
| 240 | void addSourceLine(DIE &Die, DIObjCProperty Ty); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 241 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 242 | /// addConstantValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 243 | void addConstantValue(DIE &Die, const MachineOperand &MO, DIType Ty); |
David Blaikie | c0a2841 | 2014-05-11 15:56:59 +0000 | [diff] [blame] | 244 | void addConstantValue(DIE &Die, const ConstantInt *CI, DIType Ty); |
| 245 | void addConstantValue(DIE &Die, const APInt &Val, DIType Ty); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 246 | void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned); |
David Blaikie | 60cae1b | 2014-05-11 16:08:41 +0000 | [diff] [blame] | 247 | void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 248 | |
| 249 | /// addConstantFPValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 250 | void addConstantFPValue(DIE &Die, const MachineOperand &MO); |
| 251 | void addConstantFPValue(DIE &Die, const ConstantFP *CFP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 252 | |
| 253 | /// addTemplateParams - Add template parameters in buffer. |
| 254 | void addTemplateParams(DIE &Buffer, DIArray TParams); |
| 255 | |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 256 | /// addRegisterOp - Add register operand. |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame] | 257 | void addRegisterOpPiece(DIELoc &TheDie, unsigned Reg, |
| 258 | unsigned SizeInBits = 0, unsigned OffsetInBits = 0); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 259 | |
| 260 | /// addRegisterOffset - Add register offset. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 261 | void addRegisterOffset(DIELoc &TheDie, unsigned Reg, int64_t Offset); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 262 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 263 | // FIXME: Should be reformulated in terms of addComplexAddress. |
| 264 | /// addBlockByrefAddress - Start with the address based on the location |
| 265 | /// provided, and generate the DWARF information necessary to find the |
| 266 | /// actual Block variable (navigating the Block struct) based on the |
| 267 | /// starting location. Add the DWARF information to the die. Obsolete, |
| 268 | /// please use addComplexAddress instead. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 269 | void addBlockByrefAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 270 | dwarf::Attribute Attribute, |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 271 | const MachineLocation &Location); |
| 272 | |
Eric Christopher | 7285c7d | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 273 | /// addType - Add a new type attribute to the specified entity. This takes |
| 274 | /// and attribute parameter because DW_AT_friend attributes are also |
| 275 | /// type references. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 276 | void addType(DIE &Entity, DIType Ty, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 277 | dwarf::Attribute Attribute = dwarf::DW_AT_type); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 278 | |
| 279 | /// getOrCreateNameSpace - Create a DIE for DINameSpace. |
| 280 | DIE *getOrCreateNameSpace(DINameSpace NS); |
| 281 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 282 | /// getOrCreateSubprogramDIE - Create new DIE using SP. |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame^] | 283 | DIE *getOrCreateSubprogramDIE(DISubprogram SP, bool Minimal = false); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 284 | |
David Blaikie | 279c451 | 2014-11-02 08:18:06 +0000 | [diff] [blame] | 285 | void applySubprogramAttributes(DISubprogram SP, DIE &SPDie, |
| 286 | bool Minimal = false); |
David Blaikie | 7f91686 | 2014-05-27 18:37:38 +0000 | [diff] [blame] | 287 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 288 | /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the |
| 289 | /// given DIType. |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 290 | DIE *getOrCreateTypeDIE(const MDNode *N); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 291 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 292 | /// getOrCreateContextDIE - Get context owner's DIE. |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 293 | DIE *createTypeDIE(DICompositeType Ty); |
| 294 | |
| 295 | /// getOrCreateContextDIE - Get context owner's DIE. |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 296 | DIE *getOrCreateContextDIE(DIScope Context); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 297 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 298 | /// constructContainingTypeDIEs - Construct DIEs for types that contain |
| 299 | /// vtables. |
| 300 | void constructContainingTypeDIEs(); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 301 | |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 302 | /// constructSubprogramArguments - Construct function argument DIEs. |
Manman Ren | f8a1967 | 2014-07-28 22:24:06 +0000 | [diff] [blame] | 303 | void constructSubprogramArguments(DIE &Buffer, DITypeArray Args); |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 304 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 305 | /// Create a DIE with the given Tag, add the DIE to its parent, and |
| 306 | /// call insertDIE if MD is not null. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 307 | DIE &createAndAddDIE(unsigned Tag, DIE &Parent, |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 308 | DIDescriptor N = DIDescriptor()); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 309 | |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 310 | /// Compute the size of a header for this unit, not including the initial |
| 311 | /// length field. |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 312 | virtual unsigned getHeaderSize() const { |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 313 | return sizeof(int16_t) + // DWARF version number |
| 314 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 315 | sizeof(int8_t); // Pointer Size (in bytes) |
| 316 | } |
| 317 | |
| 318 | /// Emit the header for this unit, not including the initial length field. |
David Blaikie | d82b237 | 2014-03-24 20:28:10 +0000 | [diff] [blame] | 319 | virtual void emitHeader(const MCSymbol *ASectionSym) const; |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 320 | |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 321 | virtual DwarfCompileUnit &getCU() = 0; |
David Blaikie | d696fac | 2014-02-12 00:32:05 +0000 | [diff] [blame] | 322 | |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 323 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
| 324 | void constructTypeDIE(DIE &Buffer, DICompositeType CTy); |
| 325 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 326 | protected: |
| 327 | /// getOrCreateStaticMemberDIE - Create new static data member DIE. |
| 328 | DIE *getOrCreateStaticMemberDIE(DIDerivedType DT); |
| 329 | |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 330 | /// Look up the source ID with the given directory and source file names. If |
| 331 | /// none currently exists, create a new ID and insert it in the line table. |
| 332 | virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0; |
| 333 | |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 334 | /// resolve - Look in the DwarfDebug map for the MDNode that |
| 335 | /// corresponds to the reference. |
| 336 | template <typename T> T resolve(DIRef<T> Ref) const { |
| 337 | return DD->resolve(Ref); |
| 338 | } |
| 339 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 340 | private: |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 341 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
Eric Christopher | f0388b7 | 2013-10-04 23:49:29 +0000 | [diff] [blame] | 342 | void constructTypeDIE(DIE &Buffer, DIBasicType BTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 343 | |
| 344 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
Eric Christopher | f0388b7 | 2013-10-04 23:49:29 +0000 | [diff] [blame] | 345 | void constructTypeDIE(DIE &Buffer, DIDerivedType DTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 346 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 347 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
| 348 | void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy); |
| 349 | |
| 350 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 351 | void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 352 | |
| 353 | /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 354 | void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 355 | |
Manman Ren | 230ec86 | 2013-10-23 23:00:44 +0000 | [diff] [blame] | 356 | /// constructMemberDIE - Construct member DIE from DIDerivedType. |
| 357 | void constructMemberDIE(DIE &Buffer, DIDerivedType DT); |
Manman Ren | 7cc6270 | 2013-10-18 21:14:19 +0000 | [diff] [blame] | 358 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 359 | /// constructTemplateTypeParameterDIE - Construct new DIE for the given |
| 360 | /// DITemplateTypeParameter. |
| 361 | void constructTemplateTypeParameterDIE(DIE &Buffer, |
| 362 | DITemplateTypeParameter TP); |
Manman Ren | 7cc6270 | 2013-10-18 21:14:19 +0000 | [diff] [blame] | 363 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 364 | /// constructTemplateValueParameterDIE - Construct new DIE for the given |
| 365 | /// DITemplateValueParameter. |
| 366 | void constructTemplateValueParameterDIE(DIE &Buffer, |
| 367 | DITemplateValueParameter TVP); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 368 | |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 369 | /// getLowerBoundDefault - Return the default lower bound for an array. If the |
| 370 | /// DWARF version doesn't handle the language, return -1. |
| 371 | int64_t getDefaultLowerBound() const; |
| 372 | |
| 373 | /// getDIEEntry - Returns the debug information entry for the specified |
| 374 | /// debug variable. |
| 375 | DIEEntry *getDIEEntry(const MDNode *N) const { |
| 376 | return MDNodeToDIEEntryMap.lookup(N); |
| 377 | } |
| 378 | |
| 379 | /// insertDIEEntry - Insert debug information entry into the map. |
| 380 | void insertDIEEntry(const MDNode *N, DIEEntry *E) { |
| 381 | MDNodeToDIEEntryMap.insert(std::make_pair(N, E)); |
| 382 | } |
| 383 | |
| 384 | // getIndexTyDie - Get an anonymous type for index type. |
David Blaikie | 871c2d9 | 2014-11-02 03:09:13 +0000 | [diff] [blame] | 385 | DIE *getIndexTyDie(); |
Eric Christopher | fa205ca | 2013-10-05 00:05:51 +0000 | [diff] [blame] | 386 | |
| 387 | // setIndexTyDie - Set D as anonymous type for index which can be reused |
| 388 | // later. |
| 389 | void setIndexTyDie(DIE *D) { IndexTyDie = D; } |
| 390 | |
| 391 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
| 392 | /// information entry. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 393 | DIEEntry *createDIEEntry(DIE &Entry); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 394 | |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 395 | /// If this is a named finished type then include it in the list of types for |
| 396 | /// the accelerator tables. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 397 | void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE &TyDIE); |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 398 | |
| 399 | virtual bool isDwoUnit() const = 0; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 400 | }; |
| 401 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 402 | class DwarfTypeUnit : public DwarfUnit { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 403 | uint64_t TypeSignature; |
| 404 | const DIE *Ty; |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 405 | DwarfCompileUnit &CU; |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 406 | MCDwarfDwoLineTable *SplitLineTable; |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 407 | |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 408 | unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override; |
| 409 | bool isDwoUnit() const override; |
| 410 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 411 | public: |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 412 | DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A, |
| 413 | DwarfDebug *DW, DwarfFile *DWU, |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 414 | MCDwarfDwoLineTable *SplitLineTable = nullptr); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 415 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 416 | void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 417 | uint64_t getTypeSignature() const { return TypeSignature; } |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 418 | void setType(const DIE *Ty) { this->Ty = Ty; } |
| 419 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 420 | /// Emit the header for this unit, not including the initial length field. |
David Blaikie | d82b237 | 2014-03-24 20:28:10 +0000 | [diff] [blame] | 421 | void emitHeader(const MCSymbol *ASectionSym) const override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 422 | unsigned getHeaderSize() const override { |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 423 | return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature |
| 424 | sizeof(uint32_t); // Type DIE Offset |
| 425 | } |
David Blaikie | 29459ae | 2014-07-25 17:11:58 +0000 | [diff] [blame] | 426 | using DwarfUnit::initSection; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 427 | DwarfCompileUnit &getCU() override { return CU; } |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 428 | }; |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 429 | } // end llvm namespace |
| 430 | #endif |