David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===// |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +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 | // |
Eric Christopher | 160522c | 2012-08-14 05:13:29 +0000 | [diff] [blame] | 10 | // This file contains support for constructing a dwarf compile unit. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
David Blaikie | 2c86a72 | 2013-12-02 19:33:15 +0000 | [diff] [blame] | 14 | #include "DwarfUnit.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "DwarfAccelTable.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 16 | #include "DwarfDebug.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/APFloat.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Constants.h" |
Chandler Carruth | 12664a0 | 2014-03-06 00:22:06 +0000 | [diff] [blame] | 19 | #include "llvm/IR/DIBuilder.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/DataLayout.h" |
| 21 | #include "llvm/IR/GlobalVariable.h" |
| 22 | #include "llvm/IR/Instructions.h" |
Rafael Espindola | 894843c | 2014-01-07 21:19:40 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Mangler.h" |
Eric Christopher | 8458862 | 2013-12-28 01:39:17 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCAsmInfo.h" |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCContext.h" |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSection.h" |
| 27 | #include "llvm/MC/MCStreamer.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 28 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetFrameLowering.h" |
David Blaikie | f269497 | 2013-06-28 20:05:11 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetMachine.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetRegisterInfo.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 33 | |
| 34 | using namespace llvm; |
| 35 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 36 | #define DEBUG_TYPE "dwarfdebug" |
| 37 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 38 | static cl::opt<bool> |
| 39 | GenerateDwarfTypeUnits("generate-type-units", cl::Hidden, |
| 40 | cl::desc("Generate DWARF4 type units."), |
| 41 | cl::init(false)); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 42 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 43 | /// Unit - Unit constructor. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 44 | DwarfUnit::DwarfUnit(unsigned UID, dwarf::Tag UnitTag, DICompileUnit Node, |
David Blaikie | 92a2f8a | 2014-04-28 21:04:29 +0000 | [diff] [blame] | 45 | AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU) |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 46 | : UniqueID(UID), CUNode(Node), UnitDie(UnitTag), DebugInfoOffset(0), Asm(A), |
| 47 | DD(DW), DU(DWU), IndexTyDie(nullptr), Section(nullptr), |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 48 | Skeleton(nullptr) { |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 49 | assert(UnitTag == dwarf::DW_TAG_compile_unit || |
| 50 | UnitTag == dwarf::DW_TAG_type_unit); |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 51 | DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1); |
| 52 | } |
| 53 | |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 54 | DwarfCompileUnit::DwarfCompileUnit(unsigned UID, DICompileUnit Node, |
| 55 | AsmPrinter *A, DwarfDebug *DW, |
| 56 | DwarfFile *DWU) |
| 57 | : DwarfUnit(UID, dwarf::DW_TAG_compile_unit, Node, A, DW, DWU) { |
David Blaikie | 92a2f8a | 2014-04-28 21:04:29 +0000 | [diff] [blame] | 58 | insertDIE(Node, &getUnitDie()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 59 | } |
| 60 | |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 61 | DwarfTypeUnit::DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A, |
David Blaikie | 92a2f8a | 2014-04-28 21:04:29 +0000 | [diff] [blame] | 62 | DwarfDebug *DW, DwarfFile *DWU, |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 63 | MCDwarfDwoLineTable *SplitLineTable) |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 64 | : DwarfUnit(UID, dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU), |
| 65 | CU(CU), SplitLineTable(SplitLineTable) { |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 66 | if (SplitLineTable) |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 67 | addSectionOffset(UnitDie, dwarf::DW_AT_stmt_list, 0); |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 68 | } |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 69 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 70 | /// ~Unit - Destructor for compile unit. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 71 | DwarfUnit::~DwarfUnit() { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 72 | for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j) |
| 73 | DIEBlocks[j]->~DIEBlock(); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 74 | for (unsigned j = 0, M = DIELocs.size(); j < M; ++j) |
| 75 | DIELocs[j]->~DIELoc(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
| 79 | /// information entry. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 80 | DIEEntry *DwarfUnit::createDIEEntry(DIE &Entry) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 81 | DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry); |
| 82 | return Value; |
| 83 | } |
| 84 | |
Bill Wendling | 3495f9b | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 85 | /// getDefaultLowerBound - Return the default lower bound for an array. If the |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 86 | /// DWARF version doesn't handle the language, return -1. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 87 | int64_t DwarfUnit::getDefaultLowerBound() const { |
David Blaikie | cb8e435 | 2013-11-15 23:50:53 +0000 | [diff] [blame] | 88 | switch (getLanguage()) { |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 89 | default: |
| 90 | break; |
| 91 | |
| 92 | case dwarf::DW_LANG_C89: |
| 93 | case dwarf::DW_LANG_C99: |
| 94 | case dwarf::DW_LANG_C: |
| 95 | case dwarf::DW_LANG_C_plus_plus: |
| 96 | case dwarf::DW_LANG_ObjC: |
| 97 | case dwarf::DW_LANG_ObjC_plus_plus: |
| 98 | return 0; |
| 99 | |
| 100 | case dwarf::DW_LANG_Fortran77: |
| 101 | case dwarf::DW_LANG_Fortran90: |
| 102 | case dwarf::DW_LANG_Fortran95: |
| 103 | return 1; |
| 104 | |
| 105 | // The languages below have valid values only if the DWARF version >= 4. |
| 106 | case dwarf::DW_LANG_Java: |
| 107 | case dwarf::DW_LANG_Python: |
| 108 | case dwarf::DW_LANG_UPC: |
| 109 | case dwarf::DW_LANG_D: |
| 110 | if (dwarf::DWARF_VERSION >= 4) |
| 111 | return 0; |
| 112 | break; |
| 113 | |
| 114 | case dwarf::DW_LANG_Ada83: |
| 115 | case dwarf::DW_LANG_Ada95: |
| 116 | case dwarf::DW_LANG_Cobol74: |
| 117 | case dwarf::DW_LANG_Cobol85: |
| 118 | case dwarf::DW_LANG_Modula2: |
| 119 | case dwarf::DW_LANG_Pascal83: |
| 120 | case dwarf::DW_LANG_PLI: |
| 121 | if (dwarf::DWARF_VERSION >= 4) |
| 122 | return 1; |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | return -1; |
| 127 | } |
| 128 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 129 | /// Check whether the DIE for this MDNode can be shared across CUs. |
David Blaikie | 4201ddf | 2013-11-15 22:59:36 +0000 | [diff] [blame] | 130 | static bool isShareableAcrossCUs(DIDescriptor D) { |
David Blaikie | bcb418e | 2013-11-20 18:40:16 +0000 | [diff] [blame] | 131 | // When the MDNode can be part of the type system, the DIE can be shared |
| 132 | // across CUs. |
| 133 | // Combining type units and cross-CU DIE sharing is lower value (since |
| 134 | // cross-CU DIE sharing is used in LTO and removes type redundancy at that |
| 135 | // level already) but may be implementable for some value in projects |
| 136 | // building multiple independent libraries with LTO and then linking those |
| 137 | // together. |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 138 | return (D.isType() || |
| 139 | (D.isSubprogram() && !DISubprogram(D).isDefinition())) && |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 140 | !GenerateDwarfTypeUnits; |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /// getDIE - Returns the debug information entry map slot for the |
| 144 | /// specified debug variable. We delegate the request to DwarfDebug |
| 145 | /// when the DIE for this MDNode can be shared across CUs. The mappings |
| 146 | /// will be kept in DwarfDebug for shareable DIEs. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 147 | DIE *DwarfUnit::getDIE(DIDescriptor D) const { |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 148 | if (isShareableAcrossCUs(D)) |
| 149 | return DD->getDIE(D); |
| 150 | return MDNodeToDieMap.lookup(D); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug |
| 154 | /// when the DIE for this MDNode can be shared across CUs. The mappings |
| 155 | /// will be kept in DwarfDebug for shareable DIEs. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 156 | void DwarfUnit::insertDIE(DIDescriptor Desc, DIE *D) { |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 157 | if (isShareableAcrossCUs(Desc)) { |
| 158 | DD->insertDIE(Desc, D); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 159 | return; |
| 160 | } |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 161 | MDNodeToDieMap.insert(std::make_pair(Desc, D)); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 164 | /// addFlag - Add a flag that is true. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 165 | void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) { |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 166 | if (DD->getDwarfVersion() >= 4) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 167 | Die.addValue(Attribute, dwarf::DW_FORM_flag_present, DIEIntegerOne); |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 168 | else |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 169 | Die.addValue(Attribute, dwarf::DW_FORM_flag, DIEIntegerOne); |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 172 | /// addUInt - Add an unsigned integer attribute data and value. |
| 173 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 174 | void DwarfUnit::addUInt(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 175 | Optional<dwarf::Form> Form, uint64_t Integer) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 176 | if (!Form) |
| 177 | Form = DIEInteger::BestForm(false, Integer); |
| 178 | DIEValue *Value = Integer == 1 ? DIEIntegerOne : new (DIEValueAllocator) |
| 179 | DIEInteger(Integer); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 180 | Die.addValue(Attribute, *Form, Value); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 181 | } |
| 182 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 183 | void DwarfUnit::addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 184 | addUInt(Block, (dwarf::Attribute)0, Form, Integer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /// addSInt - Add an signed integer attribute data and value. |
| 188 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 189 | void DwarfUnit::addSInt(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 190 | Optional<dwarf::Form> Form, int64_t Integer) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 191 | if (!Form) |
| 192 | Form = DIEInteger::BestForm(true, Integer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 193 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 194 | Die.addValue(Attribute, *Form, Value); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 195 | } |
| 196 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 197 | void DwarfUnit::addSInt(DIELoc &Die, Optional<dwarf::Form> Form, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 198 | int64_t Integer) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 199 | addSInt(Die, (dwarf::Attribute)0, Form, Integer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 202 | /// addString - Add a string attribute data and value. We always emit a |
| 203 | /// reference to the string pool instead of immediate strings so that DIEs have |
Eric Christopher | fba2260 | 2013-01-07 19:32:45 +0000 | [diff] [blame] | 204 | /// more predictable sizes. In the case of split dwarf we emit an index |
| 205 | /// into another table which gets us the static offset into the string |
| 206 | /// table. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 207 | void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 208 | StringRef String) { |
Eric Christopher | 05893f4 | 2013-12-30 18:32:31 +0000 | [diff] [blame] | 209 | |
| 210 | if (!DD->useSplitDwarf()) |
| 211 | return addLocalString(Die, Attribute, String); |
| 212 | |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 213 | unsigned idx = DU->getStringPool().getIndex(*Asm, String); |
Eric Christopher | 05893f4 | 2013-12-30 18:32:31 +0000 | [diff] [blame] | 214 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx); |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 215 | DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 216 | Die.addValue(Attribute, dwarf::DW_FORM_GNU_str_index, Str); |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /// addLocalString - Add a string attribute data and value. This is guaranteed |
| 220 | /// to be in the local string pool instead of indirected. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 221 | void DwarfUnit::addLocalString(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 222 | StringRef String) { |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 223 | MCSymbol *Symb = DU->getStringPool().getSymbol(*Asm, String); |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 224 | DIEValue *Value; |
Eric Christopher | 8458862 | 2013-12-28 01:39:17 +0000 | [diff] [blame] | 225 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 226 | Value = new (DIEValueAllocator) DIELabel(Symb); |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 227 | else { |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 228 | MCSymbol *StringPool = DU->getStringPool().getSectionSymbol(); |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 229 | Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool); |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 230 | } |
Eric Christopher | 05893f4 | 2013-12-30 18:32:31 +0000 | [diff] [blame] | 231 | DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 232 | Die.addValue(Attribute, dwarf::DW_FORM_strp, Str); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 235 | /// addExpr - Add a Dwarf expression attribute data and value. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 236 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 237 | void DwarfUnit::addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr) { |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 238 | DIEValue *Value = new (DIEValueAllocator) DIEExpr(Expr); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 239 | Die.addValue((dwarf::Attribute)0, Form, Value); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 242 | /// addLocationList - Add a Dwarf loclistptr attribute data and value. |
| 243 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 244 | void DwarfUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 245 | unsigned Index) { |
| 246 | DIEValue *Value = new (DIEValueAllocator) DIELocList(Index); |
| 247 | dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset |
| 248 | : dwarf::DW_FORM_data4; |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 249 | Die.addValue(Attribute, Form, Value); |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 252 | /// addLabel - Add a Dwarf label attribute data and value. |
| 253 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 254 | void DwarfUnit::addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 255 | const MCSymbol *Label) { |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 256 | DIEValue *Value = new (DIEValueAllocator) DIELabel(Label); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 257 | Die.addValue(Attribute, Form, Value); |
David Blaikie | f3cd7c5 | 2013-06-28 20:05:04 +0000 | [diff] [blame] | 258 | } |
| 259 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 260 | void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 261 | addLabel(Die, (dwarf::Attribute)0, Form, Label); |
| 262 | } |
| 263 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 264 | /// addSectionLabel - Add a Dwarf section label attribute data and value. |
| 265 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 266 | void DwarfUnit::addSectionLabel(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 267 | const MCSymbol *Label) { |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 268 | if (DD->getDwarfVersion() >= 4) |
| 269 | addLabel(Die, Attribute, dwarf::DW_FORM_sec_offset, Label); |
| 270 | else |
| 271 | addLabel(Die, Attribute, dwarf::DW_FORM_data4, Label); |
| 272 | } |
| 273 | |
| 274 | /// addSectionOffset - Add an offset into a section attribute data and value. |
| 275 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 276 | void DwarfUnit::addSectionOffset(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 277 | uint64_t Integer) { |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 278 | if (DD->getDwarfVersion() >= 4) |
| 279 | addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer); |
| 280 | else |
| 281 | addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer); |
| 282 | } |
| 283 | |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 284 | /// addLabelAddress - Add a dwarf label attribute data and value using |
| 285 | /// DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 286 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 287 | void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 288 | const MCSymbol *Label) { |
| 289 | |
| 290 | if (!DD->useSplitDwarf()) |
| 291 | return addLocalLabelAddress(Die, Attribute, Label); |
| 292 | |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 293 | if (Label) |
| 294 | DD->addArangeLabel(SymbolCU(this, Label)); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 295 | |
David Blaikie | d75fb28 | 2014-04-23 21:20:10 +0000 | [diff] [blame] | 296 | unsigned idx = DD->getAddressPool().getIndex(Label); |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 297 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 298 | Die.addValue(Attribute, dwarf::DW_FORM_GNU_addr_index, Value); |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 299 | } |
| 300 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 301 | void DwarfCompileUnit::addLocalLabelAddress(DIE &Die, |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 302 | dwarf::Attribute Attribute, |
| 303 | const MCSymbol *Label) { |
| 304 | if (Label) |
| 305 | DD->addArangeLabel(SymbolCU(this, Label)); |
| 306 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 307 | Die.addValue(Attribute, dwarf::DW_FORM_addr, |
| 308 | Label ? (DIEValue *)new (DIEValueAllocator) DIELabel(Label) |
| 309 | : new (DIEValueAllocator) DIEInteger(0)); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 310 | } |
| 311 | |
David Blaikie | 0e8d401 | 2014-03-17 23:53:25 +0000 | [diff] [blame] | 312 | unsigned DwarfCompileUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) { |
| 313 | // If we print assembly, we can't separate .file entries according to |
| 314 | // compile units. Thus all files will belong to the default compile unit. |
| 315 | |
| 316 | // FIXME: add a better feature test than hasRawTextSupport. Even better, |
| 317 | // extend .file to support this. |
| 318 | return Asm->OutStreamer.EmitDwarfFileDirective( |
| 319 | 0, DirName, FileName, |
| 320 | Asm->OutStreamer.hasRawTextSupport() ? 0 : getUniqueID()); |
| 321 | } |
| 322 | |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 323 | unsigned DwarfTypeUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) { |
| 324 | return SplitLineTable ? SplitLineTable->getFile(DirName, FileName) |
| 325 | : getCU().getOrCreateSourceID(FileName, DirName); |
| 326 | } |
| 327 | |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 328 | /// addOpAddress - Add a dwarf op address data and value using the |
| 329 | /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 330 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 331 | void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) { |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 332 | if (!DD->useSplitDwarf()) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 333 | addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 334 | addLabel(Die, dwarf::DW_FORM_udata, Sym); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 335 | } else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 336 | addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index); |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 337 | addUInt(Die, dwarf::DW_FORM_GNU_addr_index, |
David Blaikie | d75fb28 | 2014-04-23 21:20:10 +0000 | [diff] [blame] | 338 | DD->getAddressPool().getIndex(Sym)); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 342 | /// addSectionDelta - Add a section label delta attribute data and value. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 343 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 344 | void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 345 | const MCSymbol *Hi, const MCSymbol *Lo) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 346 | DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 347 | Die.addValue(Attribute, DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset |
| 348 | : dwarf::DW_FORM_data4, |
| 349 | Value); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 350 | } |
| 351 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 352 | void DwarfUnit::addLabelDelta(DIE &Die, dwarf::Attribute Attribute, |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 353 | const MCSymbol *Hi, const MCSymbol *Lo) { |
| 354 | DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 355 | Die.addValue(Attribute, dwarf::DW_FORM_data4, Value); |
David Blaikie | 48b1bdc | 2014-03-07 01:30:55 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 358 | /// addDIEEntry - Add a DIE attribute data and value. |
| 359 | /// |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 360 | void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry) { |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 361 | addDIEEntry(Die, Attribute, createDIEEntry(Entry)); |
| 362 | } |
| 363 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 364 | void DwarfUnit::addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type) { |
David Blaikie | f3de2ab | 2014-04-26 16:26:41 +0000 | [diff] [blame] | 365 | // Flag the type unit reference as a declaration so that if it contains |
| 366 | // members (implicit special members, static data member definitions, member |
| 367 | // declarations for definitions in this CU, etc) consumers don't get confused |
| 368 | // and think this is a full definition. |
| 369 | addFlag(Die, dwarf::DW_AT_declaration); |
| 370 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 371 | Die.addValue(dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8, |
| 372 | new (DIEValueAllocator) DIETypeSignature(Type)); |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 373 | } |
| 374 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 375 | void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 376 | DIEEntry *Entry) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 377 | const DIE *DieCU = Die.getUnitOrNull(); |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 378 | const DIE *EntryCU = Entry->getEntry().getUnitOrNull(); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 379 | if (!DieCU) |
| 380 | // We assume that Die belongs to this CU, if it is not linked to any CU yet. |
David Blaikie | adcde36 | 2014-04-25 18:35:57 +0000 | [diff] [blame] | 381 | DieCU = &getUnitDie(); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 382 | if (!EntryCU) |
David Blaikie | adcde36 | 2014-04-25 18:35:57 +0000 | [diff] [blame] | 383 | EntryCU = &getUnitDie(); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 384 | Die.addValue(Attribute, |
| 385 | EntryCU == DieCU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr, |
| 386 | Entry); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 389 | /// Create a DIE with the given Tag, add the DIE to its parent, and |
| 390 | /// call insertDIE if MD is not null. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 391 | DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) { |
David Blaikie | efc403b | 2014-04-12 02:24:04 +0000 | [diff] [blame] | 392 | assert(Tag != dwarf::DW_TAG_auto_variable && |
| 393 | Tag != dwarf::DW_TAG_arg_variable); |
David Blaikie | 914046e | 2014-04-25 20:00:34 +0000 | [diff] [blame] | 394 | Parent.addChild(make_unique<DIE>((dwarf::Tag)Tag)); |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 395 | DIE &Die = *Parent.getChildren().back(); |
David Blaikie | 52c5020 | 2013-11-16 00:29:01 +0000 | [diff] [blame] | 396 | if (N) |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 397 | insertDIE(N, &Die); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 398 | return Die; |
| 399 | } |
| 400 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 401 | /// addBlock - Add block data. |
| 402 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 403 | void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) { |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 404 | Loc->ComputeSize(Asm); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 405 | DIELocs.push_back(Loc); // Memoize so we can call the destructor later on. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 406 | Die.addValue(Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 407 | } |
| 408 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 409 | void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 410 | DIEBlock *Block) { |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 411 | Block->ComputeSize(Asm); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 412 | DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 413 | Die.addValue(Attribute, Block->BestForm(), Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /// addSourceLine - Add location information to specified debug information |
| 417 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 418 | void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, StringRef File, |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 419 | StringRef Directory) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 420 | if (Line == 0) |
| 421 | return; |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 422 | |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 423 | unsigned FileID = getOrCreateSourceID(File, Directory); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 424 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 425 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 426 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /// addSourceLine - Add location information to specified debug information |
| 430 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 431 | void DwarfUnit::addSourceLine(DIE &Die, DIVariable V) { |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 432 | assert(V.isVariable()); |
| 433 | |
Eric Christopher | 89a575c | 2014-02-12 22:38:04 +0000 | [diff] [blame] | 434 | addSourceLine(Die, V.getLineNumber(), V.getContext().getFilename(), |
| 435 | V.getContext().getDirectory()); |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /// addSourceLine - Add location information to specified debug information |
| 439 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 440 | void DwarfUnit::addSourceLine(DIE &Die, DIGlobalVariable G) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame] | 441 | assert(G.isGlobalVariable()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 442 | |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 443 | addSourceLine(Die, G.getLineNumber(), G.getFilename(), G.getDirectory()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /// addSourceLine - Add location information to specified debug information |
| 447 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 448 | void DwarfUnit::addSourceLine(DIE &Die, DISubprogram SP) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame] | 449 | assert(SP.isSubprogram()); |
Eric Christopher | 7734ca2 | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 450 | |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 451 | addSourceLine(Die, SP.getLineNumber(), SP.getFilename(), SP.getDirectory()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /// addSourceLine - Add location information to specified debug information |
| 455 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 456 | void DwarfUnit::addSourceLine(DIE &Die, DIType Ty) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame] | 457 | assert(Ty.isType()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 458 | |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 459 | addSourceLine(Die, Ty.getLineNumber(), Ty.getFilename(), Ty.getDirectory()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /// addSourceLine - Add location information to specified debug information |
| 463 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 464 | void DwarfUnit::addSourceLine(DIE &Die, DIObjCProperty Ty) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame] | 465 | assert(Ty.isObjCProperty()); |
Eric Christopher | 70e1bd8 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 466 | |
Eric Christopher | 70e1bd8 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 467 | DIFile File = Ty.getFile(); |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 468 | addSourceLine(Die, Ty.getLineNumber(), File.getFilename(), |
| 469 | File.getDirectory()); |
Eric Christopher | 70e1bd8 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /// addSourceLine - Add location information to specified debug information |
| 473 | /// entry. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 474 | void DwarfUnit::addSourceLine(DIE &Die, DINameSpace NS) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame] | 475 | assert(NS.Verify()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 476 | |
David Blaikie | 101613e | 2014-02-12 00:11:25 +0000 | [diff] [blame] | 477 | addSourceLine(Die, NS.getLineNumber(), NS.getFilename(), NS.getDirectory()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 480 | /// addVariableAddress - Add DW_AT_location attribute for a |
Devang Patel | 77dc541 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 481 | /// DbgVariable based on provided MachineLocation. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 482 | void DwarfUnit::addVariableAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 483 | MachineLocation Location) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 484 | if (DV.variableHasComplexAddress()) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 485 | addComplexAddress(DV, Die, dwarf::DW_AT_location, Location); |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 486 | else if (DV.isBlockByrefVariable()) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 487 | addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 488 | else |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 489 | addAddress(Die, dwarf::DW_AT_location, Location, |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 490 | DV.getVariable().isIndirect()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 493 | /// addRegisterOp - Add register operand. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 494 | void DwarfUnit::addRegisterOp(DIELoc &TheDie, unsigned Reg) { |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 495 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 496 | int DWReg = RI->getDwarfRegNum(Reg, false); |
| 497 | bool isSubRegister = DWReg < 0; |
| 498 | |
| 499 | unsigned Idx = 0; |
| 500 | |
| 501 | // Go up the super-register chain until we hit a valid dwarf register number. |
| 502 | for (MCSuperRegIterator SR(Reg, RI); SR.isValid() && DWReg < 0; ++SR) { |
| 503 | DWReg = RI->getDwarfRegNum(*SR, false); |
| 504 | if (DWReg >= 0) |
| 505 | Idx = RI->getSubRegIndex(*SR, Reg); |
| 506 | } |
| 507 | |
| 508 | if (DWReg < 0) { |
Eric Christopher | a13839f | 2014-02-26 23:27:16 +0000 | [diff] [blame] | 509 | DEBUG(dbgs() << "Invalid Dwarf register number.\n"); |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 510 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_nop); |
| 511 | return; |
| 512 | } |
| 513 | |
| 514 | // Emit register |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 515 | if (DWReg < 32) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 516 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 517 | else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 518 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
| 519 | addUInt(TheDie, dwarf::DW_FORM_udata, DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 520 | } |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 521 | |
| 522 | // Emit Mask |
| 523 | if (isSubRegister) { |
| 524 | unsigned Size = RI->getSubRegIdxSize(Idx); |
| 525 | unsigned Offset = RI->getSubRegIdxOffset(Idx); |
| 526 | if (Offset > 0) { |
| 527 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bit_piece); |
| 528 | addUInt(TheDie, dwarf::DW_FORM_data1, Size); |
| 529 | addUInt(TheDie, dwarf::DW_FORM_data1, Offset); |
| 530 | } else { |
Adrian Prantl | 7199fd5 | 2014-02-12 19:34:44 +0000 | [diff] [blame] | 531 | unsigned ByteSize = Size / 8; // Assuming 8 bits per byte. |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 532 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_piece); |
Adrian Prantl | 7199fd5 | 2014-02-12 19:34:44 +0000 | [diff] [blame] | 533 | addUInt(TheDie, dwarf::DW_FORM_data1, ByteSize); |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 534 | } |
| 535 | } |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /// addRegisterOffset - Add register offset. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 539 | void DwarfUnit::addRegisterOffset(DIELoc &TheDie, unsigned Reg, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 540 | int64_t Offset) { |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 541 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 542 | unsigned DWReg = RI->getDwarfRegNum(Reg, false); |
| 543 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 544 | if (Reg == TRI->getFrameRegister(*Asm->MF)) |
| 545 | // If variable offset is based in frame register then use fbreg. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 546 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 547 | else if (DWReg < 32) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 548 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 549 | else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 550 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 551 | addUInt(TheDie, dwarf::DW_FORM_udata, DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 552 | } |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 553 | addSInt(TheDie, dwarf::DW_FORM_sdata, Offset); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /// addAddress - Add an address attribute to a die based on the location |
| 557 | /// provided. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 558 | void DwarfUnit::addAddress(DIE &Die, dwarf::Attribute Attribute, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 559 | const MachineLocation &Location, bool Indirect) { |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 560 | DIELoc *Loc = new (DIEValueAllocator) DIELoc(); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 561 | |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 562 | if (Location.isReg() && !Indirect) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 563 | addRegisterOp(*Loc, Location.getReg()); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 564 | else { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 565 | addRegisterOffset(*Loc, Location.getReg(), Location.getOffset()); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 566 | if (Indirect && !Location.isReg()) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 567 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 570 | |
| 571 | // Now attach the location information to the DIE. |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 572 | addBlock(Die, Attribute, Loc); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 575 | /// addComplexAddress - Start with the address based on the location provided, |
| 576 | /// and generate the DWARF information necessary to find the actual variable |
Eric Christopher | 1c70b67 | 2013-12-05 00:13:15 +0000 | [diff] [blame] | 577 | /// given the extra address information encoded in the DbgVariable, starting |
| 578 | /// from the starting location. Add the DWARF information to the die. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 579 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 580 | void DwarfUnit::addComplexAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 581 | dwarf::Attribute Attribute, |
| 582 | const MachineLocation &Location) { |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 583 | DIELoc *Loc = new (DIEValueAllocator) DIELoc(); |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 584 | unsigned N = DV.getNumAddrElements(); |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 585 | unsigned i = 0; |
| 586 | if (Location.isReg()) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 587 | if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) { |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 588 | // If first address element is OpPlus then emit |
| 589 | // DW_OP_breg + Offset instead of DW_OP_reg + Offset. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 590 | addRegisterOffset(*Loc, Location.getReg(), DV.getAddrElement(1)); |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 591 | i = 2; |
| 592 | } else |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 593 | addRegisterOp(*Loc, Location.getReg()); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 594 | } else |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 595 | addRegisterOffset(*Loc, Location.getReg(), Location.getOffset()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 596 | |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 597 | for (; i < N; ++i) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 598 | uint64_t Element = DV.getAddrElement(i); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 599 | if (Element == DIBuilder::OpPlus) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 600 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 601 | addUInt(*Loc, dwarf::DW_FORM_udata, DV.getAddrElement(++i)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 602 | } else if (Element == DIBuilder::OpDeref) { |
Eric Christopher | 4d25052 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 603 | if (!Location.isReg()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 604 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 605 | } else |
| 606 | llvm_unreachable("unknown DIBuilder Opcode"); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // Now attach the location information to the DIE. |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 610 | addBlock(Die, Attribute, Loc); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* Byref variables, in Blocks, are declared by the programmer as "SomeType |
| 614 | VarName;", but the compiler creates a __Block_byref_x_VarName struct, and |
| 615 | gives the variable VarName either the struct, or a pointer to the struct, as |
| 616 | its type. This is necessary for various behind-the-scenes things the |
| 617 | compiler needs to do with by-reference variables in Blocks. |
| 618 | |
| 619 | However, as far as the original *programmer* is concerned, the variable |
| 620 | should still have type 'SomeType', as originally declared. |
| 621 | |
| 622 | The function getBlockByrefType dives into the __Block_byref_x_VarName |
| 623 | struct to find the original type of the variable, which is then assigned to |
| 624 | the variable's Debug Information Entry as its real type. So far, so good. |
| 625 | However now the debugger will expect the variable VarName to have the type |
| 626 | SomeType. So we need the location attribute for the variable to be an |
| 627 | expression that explains to the debugger how to navigate through the |
| 628 | pointers and struct to find the actual variable of type SomeType. |
| 629 | |
| 630 | The following function does just that. We start by getting |
| 631 | the "normal" location for the variable. This will be the location |
| 632 | of either the struct __Block_byref_x_VarName or the pointer to the |
| 633 | struct __Block_byref_x_VarName. |
| 634 | |
| 635 | The struct will look something like: |
| 636 | |
| 637 | struct __Block_byref_x_VarName { |
| 638 | ... <various fields> |
| 639 | struct __Block_byref_x_VarName *forwarding; |
| 640 | ... <various other fields> |
| 641 | SomeType VarName; |
| 642 | ... <maybe more fields> |
| 643 | }; |
| 644 | |
| 645 | If we are given the struct directly (as our starting point) we |
| 646 | need to tell the debugger to: |
| 647 | |
| 648 | 1). Add the offset of the forwarding field. |
| 649 | |
| 650 | 2). Follow that pointer to get the real __Block_byref_x_VarName |
| 651 | struct to use (the real one may have been copied onto the heap). |
| 652 | |
| 653 | 3). Add the offset for the field VarName, to find the actual variable. |
| 654 | |
| 655 | If we started with a pointer to the struct, then we need to |
| 656 | dereference that pointer first, before the other steps. |
| 657 | Translating this into DWARF ops, we will need to append the following |
| 658 | to the current location description for the variable: |
| 659 | |
| 660 | DW_OP_deref -- optional, if we start with a pointer |
| 661 | DW_OP_plus_uconst <forward_fld_offset> |
| 662 | DW_OP_deref |
| 663 | DW_OP_plus_uconst <varName_fld_offset> |
| 664 | |
| 665 | That is what this function does. */ |
| 666 | |
| 667 | /// addBlockByrefAddress - Start with the address based on the location |
| 668 | /// provided, and generate the DWARF information necessary to find the |
| 669 | /// actual Block variable (navigating the Block struct) based on the |
| 670 | /// starting location. Add the DWARF information to the die. For |
| 671 | /// more information, read large comment just above here. |
| 672 | /// |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 673 | void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 674 | dwarf::Attribute Attribute, |
| 675 | const MachineLocation &Location) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 676 | DIType Ty = DV.getType(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 677 | DIType TmpTy = Ty; |
Eric Christopher | 31b0576 | 2013-08-08 01:41:00 +0000 | [diff] [blame] | 678 | uint16_t Tag = Ty.getTag(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 679 | bool isPointer = false; |
| 680 | |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 681 | StringRef varName = DV.getName(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 682 | |
| 683 | if (Tag == dwarf::DW_TAG_pointer_type) { |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 684 | DIDerivedType DTy(Ty); |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 685 | TmpTy = resolve(DTy.getTypeDerivedFrom()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 686 | isPointer = true; |
| 687 | } |
| 688 | |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 689 | DICompositeType blockStruct(TmpTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 690 | |
| 691 | // Find the __forwarding field and the variable field in the __Block_byref |
| 692 | // struct. |
| 693 | DIArray Fields = blockStruct.getTypeArray(); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 694 | DIDerivedType varField; |
| 695 | DIDerivedType forwardingField; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 696 | |
| 697 | for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) { |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 698 | DIDerivedType DT(Fields.getElement(i)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 699 | StringRef fieldName = DT.getName(); |
| 700 | if (fieldName == "__forwarding") |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 701 | forwardingField = DT; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 702 | else if (fieldName == varName) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 703 | varField = DT; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | // Get the offsets for the forwarding field and the variable field. |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 707 | unsigned forwardingFieldOffset = forwardingField.getOffsetInBits() >> 3; |
| 708 | unsigned varFieldOffset = varField.getOffsetInBits() >> 2; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 709 | |
| 710 | // Decode the original location, and use that as the start of the byref |
| 711 | // variable's location. |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 712 | DIELoc *Loc = new (DIEValueAllocator) DIELoc(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 713 | |
Eric Christopher | ef9d710 | 2012-07-04 02:02:18 +0000 | [diff] [blame] | 714 | if (Location.isReg()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 715 | addRegisterOp(*Loc, Location.getReg()); |
Eric Christopher | ef9d710 | 2012-07-04 02:02:18 +0000 | [diff] [blame] | 716 | else |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 717 | addRegisterOffset(*Loc, Location.getReg(), Location.getOffset()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 718 | |
| 719 | // If we started with a pointer to the __Block_byref... struct, then |
| 720 | // the first thing we need to do is dereference the pointer (DW_OP_deref). |
| 721 | if (isPointer) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 722 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 723 | |
| 724 | // Next add the offset for the '__forwarding' field: |
| 725 | // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in |
| 726 | // adding the offset if it's 0. |
| 727 | if (forwardingFieldOffset > 0) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 728 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 729 | addUInt(*Loc, dwarf::DW_FORM_udata, forwardingFieldOffset); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | // Now dereference the __forwarding field to get to the real __Block_byref |
| 733 | // struct: DW_OP_deref. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 734 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 735 | |
| 736 | // Now that we've got the real __Block_byref... struct, add the offset |
| 737 | // for the variable's field to get to the location of the actual variable: |
| 738 | // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0. |
| 739 | if (varFieldOffset > 0) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 740 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 741 | addUInt(*Loc, dwarf::DW_FORM_udata, varFieldOffset); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | // Now attach the location information to the DIE. |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 745 | addBlock(Die, Attribute, Loc); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 748 | /// isTypeSigned - Return true if the type is signed. |
David Blaikie | 958647c | 2014-05-11 15:06:20 +0000 | [diff] [blame] | 749 | static bool isTypeSigned(DwarfDebug *DD, DIType Ty) { |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 750 | if (Ty.isDerivedType()) |
David Blaikie | 958647c | 2014-05-11 15:06:20 +0000 | [diff] [blame] | 751 | return isTypeSigned(DD, |
| 752 | DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom())); |
| 753 | |
| 754 | return Ty.isBasicType() && |
| 755 | (DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed || |
| 756 | DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char); |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 759 | /// Return true if type encoding is unsigned. |
| 760 | static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) { |
| 761 | DIDerivedType DTy(Ty); |
| 762 | if (DTy.isDerivedType()) |
| 763 | return isUnsignedDIType(DD, DD->resolve(DTy.getTypeDerivedFrom())); |
| 764 | |
| 765 | DIBasicType BTy(Ty); |
| 766 | if (BTy.isBasicType()) { |
| 767 | unsigned Encoding = BTy.getEncoding(); |
| 768 | if (Encoding == dwarf::DW_ATE_unsigned || |
| 769 | Encoding == dwarf::DW_ATE_unsigned_char || |
| 770 | Encoding == dwarf::DW_ATE_boolean) |
| 771 | return true; |
| 772 | } |
| 773 | return false; |
| 774 | } |
| 775 | |
| 776 | /// If this type is derived from a base type then return base type size. |
Manman Ren | bda410f | 2013-10-08 18:46:58 +0000 | [diff] [blame] | 777 | static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) { |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 778 | unsigned Tag = Ty.getTag(); |
| 779 | |
| 780 | if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef && |
| 781 | Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type && |
| 782 | Tag != dwarf::DW_TAG_restrict_type) |
| 783 | return Ty.getSizeInBits(); |
| 784 | |
| 785 | DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom()); |
| 786 | |
Eric Christopher | 8cc04fc | 2014-03-12 18:18:05 +0000 | [diff] [blame] | 787 | // If this type is not derived from any type or the type is a declaration then |
| 788 | // take conservative approach. |
| 789 | if (!BaseType.isValid() || BaseType.isForwardDecl()) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 790 | return Ty.getSizeInBits(); |
| 791 | |
| 792 | // If this is a derived type, go ahead and get the base type, unless it's a |
| 793 | // reference then it's just the size of the field. Pointer types have no need |
| 794 | // of this since they're a different type of qualification on the type. |
| 795 | if (BaseType.getTag() == dwarf::DW_TAG_reference_type || |
| 796 | BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type) |
| 797 | return Ty.getSizeInBits(); |
| 798 | |
| 799 | if (BaseType.isDerivedType()) |
Manman Ren | bda410f | 2013-10-08 18:46:58 +0000 | [diff] [blame] | 800 | return getBaseTypeSize(DD, DIDerivedType(BaseType)); |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 801 | |
| 802 | return BaseType.getSizeInBits(); |
| 803 | } |
| 804 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 805 | /// addConstantFPValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 806 | void DwarfUnit::addConstantFPValue(DIE &Die, const MachineOperand &MO) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 807 | assert(MO.isFPImm() && "Invalid machine operand!"); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 808 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 809 | APFloat FPImm = MO.getFPImm()->getValueAPF(); |
| 810 | |
| 811 | // Get the raw data form of the floating point. |
| 812 | const APInt FltVal = FPImm.bitcastToAPInt(); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 813 | const char *FltPtr = (const char *)FltVal.getRawData(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 814 | |
| 815 | int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte. |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 816 | bool LittleEndian = Asm->getDataLayout().isLittleEndian(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 817 | int Incr = (LittleEndian ? 1 : -1); |
| 818 | int Start = (LittleEndian ? 0 : NumBytes - 1); |
| 819 | int Stop = (LittleEndian ? NumBytes : -1); |
| 820 | |
| 821 | // Output the constant to DWARF one byte at a time. |
| 822 | for (; Start != Stop; Start += Incr) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 823 | addUInt(*Block, dwarf::DW_FORM_data1, (unsigned char)0xFF & FltPtr[Start]); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 824 | |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 825 | addBlock(Die, dwarf::DW_AT_const_value, Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 826 | } |
| 827 | |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 828 | /// addConstantFPValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 829 | void DwarfUnit::addConstantFPValue(DIE &Die, const ConstantFP *CFP) { |
Eric Christopher | 9d1daa8 | 2013-08-27 23:49:04 +0000 | [diff] [blame] | 830 | // Pass this down to addConstantValue as an unsigned bag of bits. |
| 831 | addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true); |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 834 | /// addConstantValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 835 | void DwarfUnit::addConstantValue(DIE &Die, const ConstantInt *CI, |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 836 | bool Unsigned) { |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 837 | addConstantValue(Die, CI->getValue(), Unsigned); |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 838 | } |
| 839 | |
David Blaikie | c05c8f4 | 2014-05-11 15:47:39 +0000 | [diff] [blame^] | 840 | /// addConstantValue - Add constant value entry in variable DIE. |
| 841 | void DwarfUnit::addConstantValue(DIE &Die, const MachineOperand &MO, |
| 842 | DIType Ty) { |
| 843 | assert(MO.isImm() && "Invalid machine operand!"); |
| 844 | |
| 845 | addConstantValue(Die, isTypeSigned(DD, Ty), MO.getImm()); |
| 846 | } |
| 847 | |
| 848 | void DwarfUnit::addConstantValue(DIE &Die, bool Signed, uint64_t Val) { |
| 849 | // FIXME: This is a bit conservative/simple - it emits negative values always |
| 850 | // sign extended to 64 bits rather than minimizing the number of bytes. |
| 851 | addUInt(Die, dwarf::DW_AT_const_value, |
| 852 | Signed ? dwarf::DW_FORM_sdata : dwarf::DW_FORM_udata, Val); |
| 853 | } |
| 854 | |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 855 | // addConstantValue - Add constant value entry in variable DIE. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 856 | void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) { |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 857 | unsigned CIBitWidth = Val.getBitWidth(); |
Devang Patel | 8816bbc | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 858 | if (CIBitWidth <= 64) { |
David Blaikie | c05c8f4 | 2014-05-11 15:47:39 +0000 | [diff] [blame^] | 859 | addConstantValue(Die, !Unsigned, Unsigned ? Val.getZExtValue() : Val.getSExtValue()); |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 860 | return; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 864 | |
| 865 | // Get the raw data form of the large APInt. |
NAKAMURA Takumi | 29ccdd8 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 866 | const uint64_t *Ptr64 = Val.getRawData(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 867 | |
| 868 | int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte. |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 869 | bool LittleEndian = Asm->getDataLayout().isLittleEndian(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 870 | |
| 871 | // Output the constant to DWARF one byte at a time. |
NAKAMURA Takumi | 29ccdd8 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 872 | for (int i = 0; i < NumBytes; i++) { |
| 873 | uint8_t c; |
| 874 | if (LittleEndian) |
| 875 | c = Ptr64[i / 8] >> (8 * (i & 7)); |
| 876 | else |
| 877 | c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7)); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 878 | addUInt(*Block, dwarf::DW_FORM_data1, c); |
NAKAMURA Takumi | 29ccdd8 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 879 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 880 | |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 881 | addBlock(Die, dwarf::DW_AT_const_value, Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Eric Christopher | 25e3509 | 2013-04-22 07:47:40 +0000 | [diff] [blame] | 884 | /// addTemplateParams - Add template parameters into buffer. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 885 | void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 886 | // Add template parameters. |
| 887 | for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) { |
| 888 | DIDescriptor Element = TParams.getElement(i); |
| 889 | if (Element.isTemplateTypeParameter()) |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 890 | constructTemplateTypeParameterDIE(Buffer, |
| 891 | DITemplateTypeParameter(Element)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 892 | else if (Element.isTemplateValueParameter()) |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 893 | constructTemplateValueParameterDIE(Buffer, |
| 894 | DITemplateValueParameter(Element)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 895 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 896 | } |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 897 | |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 898 | /// getOrCreateContextDIE - Get context owner's DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 899 | DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) { |
David Blaikie | bd700e4 | 2013-11-14 21:24:34 +0000 | [diff] [blame] | 900 | if (!Context || Context.isFile()) |
David Blaikie | adcde36 | 2014-04-25 18:35:57 +0000 | [diff] [blame] | 901 | return &getUnitDie(); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 902 | if (Context.isType()) |
| 903 | return getOrCreateTypeDIE(DIType(Context)); |
David Blaikie | 1dbca70 | 2013-11-14 19:37:56 +0000 | [diff] [blame] | 904 | if (Context.isNameSpace()) |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 905 | return getOrCreateNameSpace(DINameSpace(Context)); |
David Blaikie | 1dbca70 | 2013-11-14 19:37:56 +0000 | [diff] [blame] | 906 | if (Context.isSubprogram()) |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 907 | return getOrCreateSubprogramDIE(DISubprogram(Context)); |
Adrian Prantl | 7d828bb | 2013-11-15 21:05:09 +0000 | [diff] [blame] | 908 | return getDIE(Context); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 911 | DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) { |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 912 | DIScope Context = resolve(Ty.getContext()); |
| 913 | DIE *ContextDIE = getOrCreateContextDIE(Context); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 914 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 915 | if (DIE *TyDIE = getDIE(Ty)) |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 916 | return TyDIE; |
| 917 | |
| 918 | // Create new type. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 919 | DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 920 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 921 | constructTypeDIE(TyDIE, Ty); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 922 | |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 923 | updateAcceleratorTables(Context, Ty, TyDIE); |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 924 | return &TyDIE; |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 927 | /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the |
| 928 | /// given DIType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 929 | DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { |
David Blaikie | 3288755 | 2013-11-14 22:25:02 +0000 | [diff] [blame] | 930 | if (!TyNode) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 931 | return nullptr; |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 932 | |
David Blaikie | 3288755 | 2013-11-14 22:25:02 +0000 | [diff] [blame] | 933 | DIType Ty(TyNode); |
| 934 | assert(Ty.isType()); |
Adrian Prantl | c95ec91 | 2014-03-24 21:33:01 +0000 | [diff] [blame] | 935 | assert(Ty == resolve(Ty.getRef()) && |
Adrian Prantl | 0aa1aa2 | 2014-03-18 02:35:03 +0000 | [diff] [blame] | 936 | "type was not uniqued, possible ODR violation."); |
David Blaikie | 3288755 | 2013-11-14 22:25:02 +0000 | [diff] [blame] | 937 | |
David Blaikie | ee11f22 | 2014-04-12 05:35:59 +0000 | [diff] [blame] | 938 | // DW_TAG_restrict_type is not supported in DWARF2 |
| 939 | if (Ty.getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2) |
| 940 | return getOrCreateTypeDIE(resolve(DIDerivedType(Ty).getTypeDerivedFrom())); |
| 941 | |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 942 | // Construct the context before querying for the existence of the DIE in case |
| 943 | // such construction creates the DIE. |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 944 | DIScope Context = resolve(Ty.getContext()); |
| 945 | DIE *ContextDIE = getOrCreateContextDIE(Context); |
Adrian Prantl | 4583f7d | 2013-11-15 23:21:39 +0000 | [diff] [blame] | 946 | assert(ContextDIE); |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 947 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 948 | if (DIE *TyDIE = getDIE(Ty)) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 949 | return TyDIE; |
| 950 | |
| 951 | // Create new type. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 952 | DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 953 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 954 | updateAcceleratorTables(Context, Ty, TyDIE); |
David Blaikie | c3d9e9e | 2014-03-06 01:42:00 +0000 | [diff] [blame] | 955 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 956 | if (Ty.isBasicType()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 957 | constructTypeDIE(TyDIE, DIBasicType(Ty)); |
David Blaikie | 8a263cb | 2013-11-26 00:22:37 +0000 | [diff] [blame] | 958 | else if (Ty.isCompositeType()) { |
| 959 | DICompositeType CTy(Ty); |
David Blaikie | cfb2115 | 2014-01-03 18:59:42 +0000 | [diff] [blame] | 960 | if (GenerateDwarfTypeUnits && !Ty.isForwardDecl()) |
| 961 | if (MDString *TypeId = CTy.getIdentifier()) { |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 962 | DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy); |
Adrian Prantl | e2da17f | 2014-03-14 23:08:17 +0000 | [diff] [blame] | 963 | // Skip updating the accelerator tables since this is not the full type. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 964 | return &TyDIE; |
David Blaikie | cfb2115 | 2014-01-03 18:59:42 +0000 | [diff] [blame] | 965 | } |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 966 | constructTypeDIE(TyDIE, CTy); |
David Blaikie | 8a263cb | 2013-11-26 00:22:37 +0000 | [diff] [blame] | 967 | } else { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 968 | assert(Ty.isDerivedType() && "Unknown kind of DIType"); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 969 | constructTypeDIE(TyDIE, DIDerivedType(Ty)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 970 | } |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 971 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 972 | return &TyDIE; |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 975 | void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty, |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 976 | const DIE &TyDIE) { |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 977 | if (!Ty.getName().empty() && !Ty.isForwardDecl()) { |
| 978 | bool IsImplementation = 0; |
| 979 | if (Ty.isCompositeType()) { |
| 980 | DICompositeType CT(Ty); |
Eric Christopher | 8ea8e4f | 2012-01-06 23:03:37 +0000 | [diff] [blame] | 981 | // A runtime language of 0 actually means C/C++ and that any |
| 982 | // non-negative value is some version of Objective-C/C++. |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 983 | IsImplementation = (CT.getRunTimeLang() == 0) || CT.isObjcClassComplete(); |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 984 | } |
Eric Christopher | cf7289f | 2013-09-05 18:20:16 +0000 | [diff] [blame] | 985 | unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0; |
David Blaikie | 18d3375 | 2014-04-24 01:23:49 +0000 | [diff] [blame] | 986 | DD->addAccelType(Ty.getName(), TyDIE, Flags); |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 987 | |
David Blaikie | adbea1e | 2014-03-12 03:34:38 +0000 | [diff] [blame] | 988 | if ((!Context || Context.isCompileUnit() || Context.isFile() || |
| 989 | Context.isNameSpace()) && |
| 990 | getCUNode().getEmissionKind() != DIBuilder::LineTablesOnly) |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 991 | GlobalTypes[getParentContextString(Context) + Ty.getName().str()] = |
| 992 | &TyDIE; |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 993 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /// addType - Add a new type attribute to the specified entity. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 997 | void DwarfUnit::addType(DIE &Entity, DIType Ty, dwarf::Attribute Attribute) { |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 998 | assert(Ty && "Trying to add a type that doesn't exist?"); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 999 | |
| 1000 | // Check for pre-existence. |
| 1001 | DIEEntry *Entry = getDIEEntry(Ty); |
| 1002 | // If it exists then use the existing value. |
| 1003 | if (Entry) { |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 1004 | addDIEEntry(Entity, Attribute, Entry); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1005 | return; |
| 1006 | } |
| 1007 | |
| 1008 | // Construct type. |
| 1009 | DIE *Buffer = getOrCreateTypeDIE(Ty); |
| 1010 | |
| 1011 | // Set up proxy. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1012 | Entry = createDIEEntry(*Buffer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1013 | insertDIEEntry(Ty, Entry); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 1014 | addDIEEntry(Entity, Attribute, Entry); |
Devang Patel | 1cb8ab4 | 2011-05-31 23:30:30 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Eric Christopher | 9c58f31 | 2013-09-20 22:20:55 +0000 | [diff] [blame] | 1017 | /// addGlobalName - Add a new global name to the compile unit. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1018 | void DwarfUnit::addGlobalName(StringRef Name, DIE &Die, DIScope Context) { |
David Blaikie | adbea1e | 2014-03-12 03:34:38 +0000 | [diff] [blame] | 1019 | if (getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly) |
| 1020 | return; |
Eric Christopher | 8dba0d5 | 2013-10-19 01:04:42 +0000 | [diff] [blame] | 1021 | std::string FullName = getParentContextString(Context) + Name.str(); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1022 | GlobalNames[FullName] = &Die; |
Eric Christopher | 9c58f31 | 2013-09-20 22:20:55 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1025 | /// getParentContextString - Walks the metadata parent chain in a language |
| 1026 | /// specific manner (using the compile unit language) and returns |
| 1027 | /// it as a string. This is done at the metadata level because DIEs may |
| 1028 | /// not currently have been added to the parent context and walking the |
| 1029 | /// DIEs looking for names is more expensive than walking the metadata. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1030 | std::string DwarfUnit::getParentContextString(DIScope Context) const { |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1031 | if (!Context) |
| 1032 | return ""; |
| 1033 | |
| 1034 | // FIXME: Decide whether to implement this for non-C++ languages. |
| 1035 | if (getLanguage() != dwarf::DW_LANG_C_plus_plus) |
| 1036 | return ""; |
| 1037 | |
Eric Christopher | 8dba0d5 | 2013-10-19 01:04:42 +0000 | [diff] [blame] | 1038 | std::string CS; |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1039 | SmallVector<DIScope, 1> Parents; |
| 1040 | while (!Context.isCompileUnit()) { |
| 1041 | Parents.push_back(Context); |
| 1042 | if (Context.getContext()) |
| 1043 | Context = resolve(Context.getContext()); |
| 1044 | else |
| 1045 | // Structure, etc types will have a NULL context if they're at the top |
| 1046 | // level. |
| 1047 | break; |
| 1048 | } |
| 1049 | |
| 1050 | // Reverse iterate over our list to go from the outermost construct to the |
| 1051 | // innermost. |
| 1052 | for (SmallVectorImpl<DIScope>::reverse_iterator I = Parents.rbegin(), |
| 1053 | E = Parents.rend(); |
| 1054 | I != E; ++I) { |
| 1055 | DIScope Ctx = *I; |
| 1056 | StringRef Name = Ctx.getName(); |
Eric Christopher | 8dba0d5 | 2013-10-19 01:04:42 +0000 | [diff] [blame] | 1057 | if (!Name.empty()) { |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1058 | CS += Name; |
| 1059 | CS += "::"; |
| 1060 | } |
| 1061 | } |
| 1062 | return CS; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1066 | void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1067 | // Get core information. |
| 1068 | StringRef Name = BTy.getName(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1069 | // Add name if not anonymous or intermediate type. |
| 1070 | if (!Name.empty()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1071 | addString(Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1072 | |
David Blaikie | fac5612 | 2013-10-04 23:21:16 +0000 | [diff] [blame] | 1073 | // An unspecified type only has a name attribute. |
| 1074 | if (BTy.getTag() == dwarf::DW_TAG_unspecified_type) |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1075 | return; |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1076 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1077 | addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1078 | BTy.getEncoding()); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1079 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1080 | uint64_t Size = BTy.getSizeInBits() >> 3; |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1081 | addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1085 | void DwarfUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1086 | // Get core information. |
| 1087 | StringRef Name = DTy.getName(); |
| 1088 | uint64_t Size = DTy.getSizeInBits() >> 3; |
David Blaikie | fac5612 | 2013-10-04 23:21:16 +0000 | [diff] [blame] | 1089 | uint16_t Tag = Buffer.getTag(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1090 | |
| 1091 | // Map to main type, void will not have a type. |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1092 | DIType FromTy = resolve(DTy.getTypeDerivedFrom()); |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1093 | if (FromTy) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1094 | addType(Buffer, FromTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1095 | |
| 1096 | // Add name if not anonymous or intermediate type. |
| 1097 | if (!Name.empty()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1098 | addString(Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1099 | |
| 1100 | // Add size if non-zero (derived types might be zero-sized.) |
Eric Christopher | 8575790 | 2012-02-21 22:25:53 +0000 | [diff] [blame] | 1101 | if (Size && Tag != dwarf::DW_TAG_pointer_type) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1102 | addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1103 | |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 1104 | if (Tag == dwarf::DW_TAG_ptr_to_member_type) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1105 | addDIEEntry(Buffer, dwarf::DW_AT_containing_type, |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1106 | *getOrCreateTypeDIE(resolve(DTy.getClassType()))); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1107 | // Add source line info if available and TyDesc is not a forward declaration. |
| 1108 | if (!DTy.isForwardDecl()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1109 | addSourceLine(Buffer, DTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Adrian Prantl | 3f49c89 | 2014-02-25 19:57:42 +0000 | [diff] [blame] | 1112 | /// constructSubprogramArguments - Construct function argument DIEs. |
David Blaikie | 899ae61 | 2014-04-30 22:58:19 +0000 | [diff] [blame] | 1113 | void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DIArray Args) { |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 1114 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 1115 | DIDescriptor Ty = Args.getElement(i); |
| 1116 | if (Ty.isUnspecifiedParameter()) { |
| 1117 | assert(i == N-1 && "Unspecified parameter must be the last argument"); |
| 1118 | createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer); |
| 1119 | } else { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1120 | DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer); |
| 1121 | addType(Arg, DIType(Ty)); |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 1122 | if (DIType(Ty).isArtificial()) |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1123 | addFlag(Arg, dwarf::DW_AT_artificial); |
Adrian Prantl | 3f49c89 | 2014-02-25 19:57:42 +0000 | [diff] [blame] | 1124 | } |
Adrian Prantl | 69140d2 | 2014-02-25 22:27:14 +0000 | [diff] [blame] | 1125 | } |
Adrian Prantl | 3f49c89 | 2014-02-25 19:57:42 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1128 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1129 | void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 1130 | // Add name if not anonymous or intermediate type. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1131 | StringRef Name = CTy.getName(); |
| 1132 | |
| 1133 | uint64_t Size = CTy.getSizeInBits() >> 3; |
David Blaikie | fac5612 | 2013-10-04 23:21:16 +0000 | [diff] [blame] | 1134 | uint16_t Tag = Buffer.getTag(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1135 | |
| 1136 | switch (Tag) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1137 | case dwarf::DW_TAG_array_type: |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1138 | constructArrayTypeDIE(Buffer, CTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1139 | break; |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1140 | case dwarf::DW_TAG_enumeration_type: |
| 1141 | constructEnumTypeDIE(Buffer, CTy); |
| 1142 | break; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1143 | case dwarf::DW_TAG_subroutine_type: { |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1144 | // Add return type. A void return won't have a type. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1145 | DIArray Elements = CTy.getTypeArray(); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1146 | DIType RTy(Elements.getElement(0)); |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1147 | if (RTy) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1148 | addType(Buffer, RTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1149 | |
| 1150 | bool isPrototyped = true; |
Adrian Prantl | 3f49c89 | 2014-02-25 19:57:42 +0000 | [diff] [blame] | 1151 | if (Elements.getNumElements() == 2 && |
| 1152 | Elements.getElement(1).isUnspecifiedParameter()) |
| 1153 | isPrototyped = false; |
| 1154 | |
| 1155 | constructSubprogramArguments(Buffer, Elements); |
| 1156 | |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1157 | // Add prototype flag if we're dealing with a C language and the |
| 1158 | // function has been prototyped. |
David Blaikie | cb8e435 | 2013-11-15 23:50:53 +0000 | [diff] [blame] | 1159 | uint16_t Language = getLanguage(); |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1160 | if (isPrototyped && |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1161 | (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 || |
Eric Christopher | d42b92f | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1162 | Language == dwarf::DW_LANG_ObjC)) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1163 | addFlag(Buffer, dwarf::DW_AT_prototyped); |
Adrian Prantl | 99c7af2 | 2013-12-18 21:48:19 +0000 | [diff] [blame] | 1164 | |
| 1165 | if (CTy.isLValueReference()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1166 | addFlag(Buffer, dwarf::DW_AT_reference); |
Adrian Prantl | 99c7af2 | 2013-12-18 21:48:19 +0000 | [diff] [blame] | 1167 | |
| 1168 | if (CTy.isRValueReference()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1169 | addFlag(Buffer, dwarf::DW_AT_rvalue_reference); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1170 | } break; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1171 | case dwarf::DW_TAG_structure_type: |
| 1172 | case dwarf::DW_TAG_union_type: |
| 1173 | case dwarf::DW_TAG_class_type: { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1174 | // Add elements to structure type. |
David Blaikie | a1ae0e6 | 2013-08-01 20:30:22 +0000 | [diff] [blame] | 1175 | DIArray Elements = CTy.getTypeArray(); |
| 1176 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1177 | DIDescriptor Element = Elements.getElement(i); |
Adrian Prantl | ef129fb | 2014-01-18 02:12:00 +0000 | [diff] [blame] | 1178 | if (Element.isSubprogram()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1179 | getOrCreateSubprogramDIE(DISubprogram(Element)); |
Adrian Prantl | ef129fb | 2014-01-18 02:12:00 +0000 | [diff] [blame] | 1180 | else if (Element.isDerivedType()) { |
Eric Christopher | d42b92f | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1181 | DIDerivedType DDTy(Element); |
| 1182 | if (DDTy.getTag() == dwarf::DW_TAG_friend) { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1183 | DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer); |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1184 | addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()), |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1185 | dwarf::DW_AT_friend); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1186 | } else if (DDTy.isStaticMember()) { |
Manman Ren | 57e6ff7 | 2013-10-23 22:57:12 +0000 | [diff] [blame] | 1187 | getOrCreateStaticMemberDIE(DDTy); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1188 | } else { |
Manman Ren | 230ec86 | 2013-10-23 23:00:44 +0000 | [diff] [blame] | 1189 | constructMemberDIE(Buffer, DDTy); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1190 | } |
Eric Christopher | 7285c7d | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 1191 | } else if (Element.isObjCProperty()) { |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1192 | DIObjCProperty Property(Element); |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1193 | DIE &ElemDie = createAndAddDIE(Property.getTag(), Buffer); |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1194 | StringRef PropertyName = Property.getObjCPropertyName(); |
| 1195 | addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName); |
Eric Christopher | 4c96056 | 2014-01-23 19:16:28 +0000 | [diff] [blame] | 1196 | if (Property.getType()) |
| 1197 | addType(ElemDie, Property.getType()); |
Eric Christopher | d42b92f | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1198 | addSourceLine(ElemDie, Property); |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1199 | StringRef GetterName = Property.getObjCPropertyGetterName(); |
| 1200 | if (!GetterName.empty()) |
| 1201 | addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName); |
| 1202 | StringRef SetterName = Property.getObjCPropertySetterName(); |
| 1203 | if (!SetterName.empty()) |
| 1204 | addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName); |
| 1205 | unsigned PropertyAttributes = 0; |
Devang Patel | 403e819 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 1206 | if (Property.isReadOnlyObjCProperty()) |
| 1207 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readonly; |
| 1208 | if (Property.isReadWriteObjCProperty()) |
| 1209 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readwrite; |
| 1210 | if (Property.isAssignObjCProperty()) |
| 1211 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_assign; |
| 1212 | if (Property.isRetainObjCProperty()) |
| 1213 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_retain; |
| 1214 | if (Property.isCopyObjCProperty()) |
| 1215 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_copy; |
| 1216 | if (Property.isNonAtomicObjCProperty()) |
| 1217 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_nonatomic; |
| 1218 | if (PropertyAttributes) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1219 | addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, None, |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1220 | PropertyAttributes); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1221 | |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1222 | DIEEntry *Entry = getDIEEntry(Element); |
| 1223 | if (!Entry) { |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1224 | Entry = createDIEEntry(ElemDie); |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1225 | insertDIEEntry(Element, Entry); |
| 1226 | } |
Devang Patel | 403e819 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 1227 | } else |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1228 | continue; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | if (CTy.isAppleBlockExtension()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1232 | addFlag(Buffer, dwarf::DW_AT_APPLE_block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1233 | |
Eric Christopher | 9e429ae | 2013-10-05 00:27:02 +0000 | [diff] [blame] | 1234 | DICompositeType ContainingType(resolve(CTy.getContainingType())); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1235 | if (ContainingType) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1236 | addDIEEntry(Buffer, dwarf::DW_AT_containing_type, |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1237 | *getOrCreateTypeDIE(ContainingType)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1238 | |
Devang Patel | 12419ae | 2011-05-12 21:29:42 +0000 | [diff] [blame] | 1239 | if (CTy.isObjcClassComplete()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1240 | addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type); |
Devang Patel | 2409e78 | 2011-05-12 19:06:16 +0000 | [diff] [blame] | 1241 | |
Eric Christopher | da011dd | 2011-12-16 23:42:42 +0000 | [diff] [blame] | 1242 | // Add template parameters to a class, structure or union types. |
| 1243 | // FIXME: The support isn't in the metadata for this yet. |
| 1244 | if (Tag == dwarf::DW_TAG_class_type || |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1245 | Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1246 | addTemplateParams(Buffer, CTy.getTemplateParams()); |
| 1247 | |
| 1248 | break; |
| 1249 | } |
| 1250 | default: |
| 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | // Add name if not anonymous or intermediate type. |
| 1255 | if (!Name.empty()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1256 | addString(Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1257 | |
Eric Christopher | 775cbd2 | 2012-05-22 18:45:18 +0000 | [diff] [blame] | 1258 | if (Tag == dwarf::DW_TAG_enumeration_type || |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1259 | Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type || |
Eric Christopher | 775cbd2 | 2012-05-22 18:45:18 +0000 | [diff] [blame] | 1260 | Tag == dwarf::DW_TAG_union_type) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1261 | // Add size if non-zero (derived types might be zero-sized.) |
Eric Christopher | 1cf3338 | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1262 | // TODO: Do we care about size for enum forward declarations? |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1263 | if (Size) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1264 | addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size); |
Eric Christopher | 1cf3338 | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1265 | else if (!CTy.isForwardDecl()) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1266 | // Add zero size if it is not a forward declaration. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1267 | addUInt(Buffer, dwarf::DW_AT_byte_size, None, 0); |
Eric Christopher | 1cf3338 | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1268 | |
| 1269 | // If we're a forward decl, say so. |
| 1270 | if (CTy.isForwardDecl()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1271 | addFlag(Buffer, dwarf::DW_AT_declaration); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1272 | |
| 1273 | // Add source line info if available. |
| 1274 | if (!CTy.isForwardDecl()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1275 | addSourceLine(Buffer, CTy); |
Eric Christopher | 54cf8ff | 2012-03-07 00:15:19 +0000 | [diff] [blame] | 1276 | |
| 1277 | // No harm in adding the runtime language to the declaration. |
| 1278 | unsigned RLang = CTy.getRunTimeLang(); |
| 1279 | if (RLang) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1280 | addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1, |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1281 | RLang); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 1285 | /// constructTemplateTypeParameterDIE - Construct new DIE for the given |
| 1286 | /// DITemplateTypeParameter. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1287 | void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer, |
| 1288 | DITemplateTypeParameter TP) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1289 | DIE &ParamDIE = |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1290 | createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer); |
Eric Christopher | 056b647 | 2013-08-08 08:09:43 +0000 | [diff] [blame] | 1291 | // Add the type if it exists, it could be void and therefore no type. |
| 1292 | if (TP.getType()) |
Manman Ren | 88b0f94 | 2013-10-09 19:46:28 +0000 | [diff] [blame] | 1293 | addType(ParamDIE, resolve(TP.getType())); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 1294 | if (!TP.getName().empty()) |
| 1295 | addString(ParamDIE, dwarf::DW_AT_name, TP.getName()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 1298 | /// constructTemplateValueParameterDIE - Construct new DIE for the given |
| 1299 | /// DITemplateValueParameter. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1300 | void |
| 1301 | DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer, |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 1302 | DITemplateValueParameter VP) { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1303 | DIE &ParamDIE = createAndAddDIE(VP.getTag(), Buffer); |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1304 | |
| 1305 | // Add the type if there is one, template template and template parameter |
| 1306 | // packs will not have a type. |
Eric Christopher | 691281b | 2013-10-21 17:48:51 +0000 | [diff] [blame] | 1307 | if (VP.getTag() == dwarf::DW_TAG_template_value_parameter) |
Manman Ren | 88b0f94 | 2013-10-09 19:46:28 +0000 | [diff] [blame] | 1308 | addType(ParamDIE, resolve(VP.getType())); |
Eric Christopher | afb2c41 | 2013-08-08 07:40:31 +0000 | [diff] [blame] | 1309 | if (!VP.getName().empty()) |
| 1310 | addString(ParamDIE, dwarf::DW_AT_name, VP.getName()); |
| 1311 | if (Value *Val = VP.getValue()) { |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1312 | if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) |
Manman Ren | 88b0f94 | 2013-10-09 19:46:28 +0000 | [diff] [blame] | 1313 | addConstantValue(ParamDIE, CI, |
| 1314 | isUnsignedDIType(DD, resolve(VP.getType()))); |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1315 | else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) { |
| 1316 | // For declaration non-type template parameters (such as global values and |
| 1317 | // functions) |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1318 | DIELoc *Loc = new (DIEValueAllocator) DIELoc(); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1319 | addOpAddress(*Loc, Asm->getSymbol(GV)); |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1320 | // Emit DW_OP_stack_value to use the address as the immediate value of the |
| 1321 | // parameter, rather than a pointer to it. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1322 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1323 | addBlock(ParamDIE, dwarf::DW_AT_location, Loc); |
Eric Christopher | afb2c41 | 2013-08-08 07:40:31 +0000 | [diff] [blame] | 1324 | } else if (VP.getTag() == dwarf::DW_TAG_GNU_template_template_param) { |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 1325 | assert(isa<MDString>(Val)); |
| 1326 | addString(ParamDIE, dwarf::DW_AT_GNU_template_name, |
| 1327 | cast<MDString>(Val)->getString()); |
Eric Christopher | afb2c41 | 2013-08-08 07:40:31 +0000 | [diff] [blame] | 1328 | } else if (VP.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) { |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 1329 | assert(isa<MDNode>(Val)); |
| 1330 | DIArray A(cast<MDNode>(Val)); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1331 | addTemplateParams(ParamDIE, A); |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1332 | } |
| 1333 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1336 | /// getOrCreateNameSpace - Create a DIE for DINameSpace. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1337 | DIE *DwarfUnit::getOrCreateNameSpace(DINameSpace NS) { |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1338 | // Construct the context before querying for the existence of the DIE in case |
| 1339 | // such construction creates the DIE. |
| 1340 | DIE *ContextDIE = getOrCreateContextDIE(NS.getContext()); |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1341 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1342 | if (DIE *NDie = getDIE(NS)) |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1343 | return NDie; |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1344 | DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1345 | |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1346 | if (!NS.getName().empty()) { |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1347 | addString(NDie, dwarf::DW_AT_name, NS.getName()); |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1348 | DD->addAccelNamespace(NS.getName(), NDie); |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1349 | addGlobalName(NS.getName(), NDie, NS.getContext()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1350 | } else |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1351 | DD->addAccelNamespace("(anonymous namespace)", NDie); |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1352 | addSourceLine(NDie, NS); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1353 | return &NDie; |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1356 | /// getOrCreateSubprogramDIE - Create new DIE using SP. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1357 | DIE *DwarfUnit::getOrCreateSubprogramDIE(DISubprogram SP) { |
David Blaikie | 309ffe4 | 2013-10-04 01:39:59 +0000 | [diff] [blame] | 1358 | // Construct the context before querying for the existence of the DIE in case |
| 1359 | // such construction creates the DIE (as is the case for member function |
| 1360 | // declarations). |
Adrian Prantl | d1e6a4e | 2014-03-14 23:08:25 +0000 | [diff] [blame] | 1361 | DIScope Context = resolve(SP.getContext()); |
| 1362 | DIE *ContextDIE = getOrCreateContextDIE(Context); |
Adrian Prantl | d486b34 | 2014-03-18 17:41:15 +0000 | [diff] [blame] | 1363 | |
Adrian Prantl | d1e6a4e | 2014-03-14 23:08:25 +0000 | [diff] [blame] | 1364 | // Unique declarations based on the ODR, where applicable. |
Adrian Prantl | d486b34 | 2014-03-18 17:41:15 +0000 | [diff] [blame] | 1365 | SP = DISubprogram(DD->resolve(SP.getRef())); |
| 1366 | assert(SP.Verify()); |
David Blaikie | 309ffe4 | 2013-10-04 01:39:59 +0000 | [diff] [blame] | 1367 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1368 | if (DIE *SPDie = getDIE(SP)) |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1369 | return SPDie; |
| 1370 | |
Manman Ren | 73d697c | 2013-10-29 00:58:04 +0000 | [diff] [blame] | 1371 | DISubprogram SPDecl = SP.getFunctionDeclaration(); |
| 1372 | if (SPDecl.isSubprogram()) |
| 1373 | // Add subprogram definitions to the CU die directly. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 1374 | ContextDIE = &getUnitDie(); |
Peter Collingbourne | 4d358b5 | 2012-05-27 18:36:44 +0000 | [diff] [blame] | 1375 | |
| 1376 | // DW_TAG_inlined_subroutine may refer to this DIE. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1377 | DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP); |
Peter Collingbourne | 4d358b5 | 2012-05-27 18:36:44 +0000 | [diff] [blame] | 1378 | |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1379 | DIE *DeclDie = nullptr; |
Manman Ren | b9512a7 | 2013-10-23 22:12:26 +0000 | [diff] [blame] | 1380 | if (SPDecl.isSubprogram()) |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1381 | DeclDie = getOrCreateSubprogramDIE(SPDecl); |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1382 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1383 | // Add function template parameters. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1384 | addTemplateParams(SPDie, SP.getTemplateParams()); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1385 | |
Adrian Prantl | 8714aaf | 2014-04-14 21:16:04 +0000 | [diff] [blame] | 1386 | if (DeclDie) |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1387 | // Refer function declaration directly. |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1388 | addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie); |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1389 | |
Adrian Prantl | 8714aaf | 2014-04-14 21:16:04 +0000 | [diff] [blame] | 1390 | // Add the linkage name if we have one and it isn't in the Decl. |
| 1391 | StringRef LinkageName = SP.getLinkageName(); |
| 1392 | if (!LinkageName.empty()) { |
| 1393 | if (SPDecl.isSubprogram() && !SPDecl.getLinkageName().empty()) |
| 1394 | assert(SPDecl.getLinkageName() == SP.getLinkageName() && |
| 1395 | "decl has a linkage name and it is different"); |
| 1396 | else |
| 1397 | addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, |
| 1398 | GlobalValue::getRealLinkageName(LinkageName)); |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1399 | } |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1400 | |
Adrian Prantl | 8714aaf | 2014-04-14 21:16:04 +0000 | [diff] [blame] | 1401 | // If this DIE is going to refer declaration info using AT_specification |
| 1402 | // then there is no need to add other attributes. |
| 1403 | if (DeclDie) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1404 | return &SPDie; |
Eric Christopher | acb7115 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1405 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1406 | // Constructors and operators for anonymous aggregates do not have names. |
| 1407 | if (!SP.getName().empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1408 | addString(SPDie, dwarf::DW_AT_name, SP.getName()); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1409 | |
| 1410 | addSourceLine(SPDie, SP); |
| 1411 | |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1412 | // Add the prototype if we have a prototype and we have a C like |
| 1413 | // language. |
David Blaikie | cb8e435 | 2013-11-15 23:50:53 +0000 | [diff] [blame] | 1414 | uint16_t Language = getLanguage(); |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1415 | if (SP.isPrototyped() && |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1416 | (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 || |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1417 | Language == dwarf::DW_LANG_ObjC)) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1418 | addFlag(SPDie, dwarf::DW_AT_prototyped); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1419 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1420 | DICompositeType SPTy = SP.getType(); |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1421 | assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type && |
| 1422 | "the type of a subprogram should be a subroutine"); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1423 | |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1424 | DIArray Args = SPTy.getTypeArray(); |
Eric Christopher | 691281b | 2013-10-21 17:48:51 +0000 | [diff] [blame] | 1425 | // Add a return type. If this is a type like a C/C++ void type we don't add a |
| 1426 | // return type. |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1427 | if (Args.getElement(0)) |
| 1428 | addType(SPDie, DIType(Args.getElement(0))); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1429 | |
| 1430 | unsigned VK = SP.getVirtuality(); |
| 1431 | if (VK) { |
Nick Lewycky | cfde1a2 | 2011-12-14 00:56:07 +0000 | [diff] [blame] | 1432 | addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1433 | DIELoc *Block = getDIELoc(); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1434 | addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1435 | addUInt(*Block, dwarf::DW_FORM_udata, SP.getVirtualIndex()); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1436 | addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block); |
Eric Christopher | 98b7f17 | 2013-11-11 18:52:36 +0000 | [diff] [blame] | 1437 | ContainingTypeMap.insert( |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1438 | std::make_pair(&SPDie, resolve(SP.getContainingType()))); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | if (!SP.isDefinition()) { |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1442 | addFlag(SPDie, dwarf::DW_AT_declaration); |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1443 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1444 | // Add arguments. Do not add arguments for subprogram definition. They will |
| 1445 | // be handled while processing variables. |
David Blaikie | 899ae61 | 2014-04-30 22:58:19 +0000 | [diff] [blame] | 1446 | constructSubprogramArguments(SPDie, Args); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | if (SP.isArtificial()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1450 | addFlag(SPDie, dwarf::DW_AT_artificial); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1451 | |
| 1452 | if (!SP.isLocalToUnit()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1453 | addFlag(SPDie, dwarf::DW_AT_external); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1454 | |
| 1455 | if (SP.isOptimized()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1456 | addFlag(SPDie, dwarf::DW_AT_APPLE_optimized); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1457 | |
| 1458 | if (unsigned isa = Asm->getISAEncoding()) { |
| 1459 | addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa); |
| 1460 | } |
| 1461 | |
Adrian Prantl | 99c7af2 | 2013-12-18 21:48:19 +0000 | [diff] [blame] | 1462 | if (SP.isLValueReference()) |
| 1463 | addFlag(SPDie, dwarf::DW_AT_reference); |
| 1464 | |
| 1465 | if (SP.isRValueReference()) |
| 1466 | addFlag(SPDie, dwarf::DW_AT_rvalue_reference); |
| 1467 | |
Adrian Prantl | ef129fb | 2014-01-18 02:12:00 +0000 | [diff] [blame] | 1468 | if (SP.isProtected()) |
| 1469 | addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1470 | dwarf::DW_ACCESS_protected); |
| 1471 | else if (SP.isPrivate()) |
| 1472 | addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1473 | dwarf::DW_ACCESS_private); |
| 1474 | else |
| 1475 | addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1476 | dwarf::DW_ACCESS_public); |
| 1477 | |
| 1478 | if (SP.isExplicit()) |
| 1479 | addFlag(SPDie, dwarf::DW_AT_explicit); |
| 1480 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1481 | return &SPDie; |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1484 | // Return const expression if value is a GEP to access merged global |
| 1485 | // constant. e.g. |
| 1486 | // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0) |
| 1487 | static const ConstantExpr *getMergedGlobalExpr(const Value *V) { |
| 1488 | const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V); |
| 1489 | if (!CE || CE->getNumOperands() != 3 || |
| 1490 | CE->getOpcode() != Instruction::GetElementPtr) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1491 | return nullptr; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1492 | |
| 1493 | // First operand points to a global struct. |
| 1494 | Value *Ptr = CE->getOperand(0); |
| 1495 | if (!isa<GlobalValue>(Ptr) || |
| 1496 | !isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType())) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1497 | return nullptr; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1498 | |
| 1499 | // Second operand is zero. |
| 1500 | const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CE->getOperand(1)); |
| 1501 | if (!CI || !CI->isZero()) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1502 | return nullptr; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1503 | |
| 1504 | // Third operand is offset. |
| 1505 | if (!isa<ConstantInt>(CE->getOperand(2))) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1506 | return nullptr; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1507 | |
| 1508 | return CE; |
| 1509 | } |
| 1510 | |
| 1511 | /// createGlobalVariableDIE - create global variable DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 1512 | void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1513 | // Check for pre-existence. |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 1514 | if (getDIE(GV)) |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1515 | return; |
| 1516 | |
David Blaikie | 5e390e4 | 2014-02-04 01:23:52 +0000 | [diff] [blame] | 1517 | assert(GV.isGlobalVariable()); |
Devang Patel | 0ecbcbd | 2011-08-18 23:17:55 +0000 | [diff] [blame] | 1518 | |
Eric Christopher | 08f7c8f | 2013-10-04 23:49:26 +0000 | [diff] [blame] | 1519 | DIScope GVContext = GV.getContext(); |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 1520 | DIType GTy = DD->resolve(GV.getType()); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1521 | |
| 1522 | // If this is a static data member definition, some attributes belong |
| 1523 | // to the declaration DIE. |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1524 | DIE *VariableDIE = nullptr; |
Manman Ren | e697d3c | 2013-02-01 23:54:37 +0000 | [diff] [blame] | 1525 | bool IsStaticMember = false; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1526 | DIDerivedType SDMDecl = GV.getStaticDataMemberDeclaration(); |
| 1527 | if (SDMDecl.Verify()) { |
| 1528 | assert(SDMDecl.isStaticMember() && "Expected static member decl"); |
| 1529 | // We need the declaration DIE that is in the static member's class. |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1530 | VariableDIE = getOrCreateStaticMemberDIE(SDMDecl); |
Manman Ren | e697d3c | 2013-02-01 23:54:37 +0000 | [diff] [blame] | 1531 | IsStaticMember = true; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | // If this is not a static data member definition, create the variable |
| 1535 | // DIE and add the initial set of attributes to it. |
| 1536 | if (!VariableDIE) { |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1537 | // Construct the context before querying for the existence of the DIE in |
| 1538 | // case such construction creates the DIE. |
| 1539 | DIE *ContextDIE = getOrCreateContextDIE(GVContext); |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1540 | |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1541 | // Add to map. |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1542 | VariableDIE = &createAndAddDIE(GV.getTag(), *ContextDIE, GV); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1543 | |
| 1544 | // Add name and type. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1545 | addString(*VariableDIE, dwarf::DW_AT_name, GV.getDisplayName()); |
| 1546 | addType(*VariableDIE, GTy); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1547 | |
| 1548 | // Add scoping info. |
Eric Christopher | d2b497b | 2013-10-16 01:37:49 +0000 | [diff] [blame] | 1549 | if (!GV.isLocalToUnit()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1550 | addFlag(*VariableDIE, dwarf::DW_AT_external); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1551 | |
| 1552 | // Add line number info. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1553 | addSourceLine(*VariableDIE, GV); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1556 | // Add location. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1557 | bool addToAccelTable = false; |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1558 | DIE *VariableSpecDIE = nullptr; |
| 1559 | bool isGlobalVariable = GV.getGlobal() != nullptr; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1560 | if (isGlobalVariable) { |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1561 | addToAccelTable = true; |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1562 | DIELoc *Loc = new (DIEValueAllocator) DIELoc(); |
Rafael Espindola | 79858aa | 2013-10-29 17:07:16 +0000 | [diff] [blame] | 1563 | const MCSymbol *Sym = Asm->getSymbol(GV.getGlobal()); |
David Blaikie | f269497 | 2013-06-28 20:05:11 +0000 | [diff] [blame] | 1564 | if (GV.getGlobal()->isThreadLocal()) { |
| 1565 | // FIXME: Make this work with -gsplit-dwarf. |
| 1566 | unsigned PointerSize = Asm->getDataLayout().getPointerSize(); |
| 1567 | assert((PointerSize == 4 || PointerSize == 8) && |
| 1568 | "Add support for other sizes if necessary"); |
| 1569 | // Based on GCC's support for TLS: |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1570 | if (!DD->useSplitDwarf()) { |
| 1571 | // 1) Start with a constNu of the appropriate pointer size |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1572 | addUInt(*Loc, dwarf::DW_FORM_data1, |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1573 | PointerSize == 4 ? dwarf::DW_OP_const4u : dwarf::DW_OP_const8u); |
Richard Mitton | 0aafb58 | 2013-10-07 18:39:18 +0000 | [diff] [blame] | 1574 | // 2) containing the (relocated) offset of the TLS variable |
| 1575 | // within the module's TLS block. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1576 | addExpr(*Loc, dwarf::DW_FORM_udata, |
David Blaikie | f1a6dea | 2014-02-15 19:34:03 +0000 | [diff] [blame] | 1577 | Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym)); |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1578 | } else { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1579 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index); |
| 1580 | addUInt(*Loc, dwarf::DW_FORM_udata, |
David Blaikie | d75fb28 | 2014-04-23 21:20:10 +0000 | [diff] [blame] | 1581 | DD->getAddressPool().getIndex(Sym, /* TLS */ true)); |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1582 | } |
Richard Mitton | 0aafb58 | 2013-10-07 18:39:18 +0000 | [diff] [blame] | 1583 | // 3) followed by a custom OP to make the debugger do a TLS lookup. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1584 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_push_tls_address); |
David Blaikie | bc7e0d4 | 2013-11-27 23:53:52 +0000 | [diff] [blame] | 1585 | } else { |
| 1586 | DD->addArangeLabel(SymbolCU(this, Sym)); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1587 | addOpAddress(*Loc, Sym); |
David Blaikie | bc7e0d4 | 2013-11-27 23:53:52 +0000 | [diff] [blame] | 1588 | } |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1589 | // Do not create specification DIE if context is either compile unit |
| 1590 | // or a subprogram. |
Devang Patel | 5e6b65c | 2011-09-21 23:41:11 +0000 | [diff] [blame] | 1591 | if (GVContext && GV.isDefinition() && !GVContext.isCompileUnit() && |
Manman Ren | 3eb9dff | 2013-09-09 19:05:21 +0000 | [diff] [blame] | 1592 | !GVContext.isFile() && !DD->isSubprogramContext(GVContext)) { |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1593 | // Create specification DIE. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 1594 | VariableSpecDIE = &createAndAddDIE(dwarf::DW_TAG_variable, UnitDie); |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1595 | addDIEEntry(*VariableSpecDIE, dwarf::DW_AT_specification, *VariableDIE); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1596 | addBlock(*VariableSpecDIE, dwarf::DW_AT_location, Loc); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1597 | // A static member's declaration is already flagged as such. |
| 1598 | if (!SDMDecl.Verify()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1599 | addFlag(*VariableDIE, dwarf::DW_AT_declaration); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1600 | } else { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1601 | addBlock(*VariableDIE, dwarf::DW_AT_location, Loc); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1602 | } |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 1603 | // Add the linkage name. |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1604 | StringRef LinkageName = GV.getLinkageName(); |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 1605 | if (!LinkageName.empty()) |
Eric Christopher | 3f79b8c | 2013-02-27 23:49:47 +0000 | [diff] [blame] | 1606 | // From DWARF4: DIEs to which DW_AT_linkage_name may apply include: |
| 1607 | // TAG_common_block, TAG_constant, TAG_entry_point, TAG_subprogram and |
| 1608 | // TAG_variable. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1609 | addString(IsStaticMember && VariableSpecDIE ? *VariableSpecDIE |
| 1610 | : *VariableDIE, |
Eric Christopher | af7eca2 | 2014-03-13 23:26:25 +0000 | [diff] [blame] | 1611 | DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name |
| 1612 | : dwarf::DW_AT_MIPS_linkage_name, |
Benjamin Kramer | 7c27564 | 2013-06-01 17:51:14 +0000 | [diff] [blame] | 1613 | GlobalValue::getRealLinkageName(LinkageName)); |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1614 | } else if (const ConstantInt *CI = |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1615 | dyn_cast_or_null<ConstantInt>(GV.getConstant())) { |
Adrian Prantl | 322f41d | 2013-04-04 22:56:49 +0000 | [diff] [blame] | 1616 | // AT_const_value was added when the static member was created. To avoid |
Manman Ren | e697d3c | 2013-02-01 23:54:37 +0000 | [diff] [blame] | 1617 | // emitting AT_const_value multiple times, we only add AT_const_value when |
| 1618 | // it is not a static member. |
| 1619 | if (!IsStaticMember) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1620 | addConstantValue(*VariableDIE, CI, isUnsignedDIType(DD, GTy)); |
David Blaikie | a781b25b | 2013-11-17 21:55:13 +0000 | [diff] [blame] | 1621 | } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getOperand(11))) { |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1622 | addToAccelTable = true; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1623 | // GV is a merged global. |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1624 | DIELoc *Loc = new (DIEValueAllocator) DIELoc(); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1625 | Value *Ptr = CE->getOperand(0); |
David Blaikie | bc7e0d4 | 2013-11-27 23:53:52 +0000 | [diff] [blame] | 1626 | MCSymbol *Sym = Asm->getSymbol(cast<GlobalValue>(Ptr)); |
| 1627 | DD->addArangeLabel(SymbolCU(this, Sym)); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1628 | addOpAddress(*Loc, Sym); |
| 1629 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1630 | SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end()); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1631 | addUInt(*Loc, dwarf::DW_FORM_udata, |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1632 | Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx)); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1633 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 1634 | addBlock(*VariableDIE, dwarf::DW_AT_location, Loc); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Eric Christopher | c12c211 | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1637 | if (addToAccelTable) { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1638 | DIE &AddrDIE = VariableSpecDIE ? *VariableSpecDIE : *VariableDIE; |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 1639 | DD->addAccelName(GV.getName(), AddrDIE); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1640 | |
Eric Christopher | c12c211 | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1641 | // If the linkage name is different than the name, go ahead and output |
| 1642 | // that as well into the name table. |
| 1643 | if (GV.getLinkageName() != "" && GV.getName() != GV.getLinkageName()) |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 1644 | DD->addAccelName(GV.getLinkageName(), AddrDIE); |
Eric Christopher | c12c211 | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1645 | } |
Eric Christopher | d2b497b | 2013-10-16 01:37:49 +0000 | [diff] [blame] | 1646 | |
| 1647 | if (!GV.isLocalToUnit()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1648 | addGlobalName(GV.getName(), |
| 1649 | VariableSpecDIE ? *VariableSpecDIE : *VariableDIE, |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1650 | GV.getContext()); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1653 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1654 | void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1655 | DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer); |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1656 | addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1657 | |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1658 | // The LowerBound value defines the lower bounds which is typically zero for |
| 1659 | // C/C++. The Count value is the number of elements. Values are 64 bit. If |
| 1660 | // Count == -1 then the array is unbounded and we do not emit |
| 1661 | // DW_AT_lower_bound and DW_AT_upper_bound attributes. If LowerBound == 0 and |
| 1662 | // Count == 0, then the array has zero elements in which case we do not emit |
| 1663 | // an upper bound. |
| 1664 | int64_t LowerBound = SR.getLo(); |
Bill Wendling | 3495f9b | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 1665 | int64_t DefaultLowerBound = getDefaultLowerBound(); |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1666 | int64_t Count = SR.getCount(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1667 | |
Bill Wendling | 3495f9b | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 1668 | if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1669 | addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound); |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1670 | |
| 1671 | if (Count != -1 && Count != 0) |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1672 | // FIXME: An unbounded array should reference the expression that defines |
| 1673 | // the array. |
Eric Christopher | 98b7f17 | 2013-11-11 18:52:36 +0000 | [diff] [blame] | 1674 | addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, None, |
| 1675 | LowerBound + Count - 1); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1679 | void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) { |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1680 | if (CTy.isVector()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1681 | addFlag(Buffer, dwarf::DW_AT_GNU_vector); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1682 | |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1683 | // Emit the element type. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1684 | addType(Buffer, resolve(CTy.getTypeDerivedFrom())); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1685 | |
| 1686 | // Get an anonymous type for index type. |
Eric Christopher | cad9b53 | 2013-01-04 21:51:53 +0000 | [diff] [blame] | 1687 | // FIXME: This type should be passed down from the front end |
| 1688 | // as different languages may have different sizes for indexes. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1689 | DIE *IdxTy = getIndexTyDie(); |
| 1690 | if (!IdxTy) { |
David Blaikie | 12e00fc | 2014-04-03 06:28:20 +0000 | [diff] [blame] | 1691 | // Construct an integer type to use for indexes. |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 1692 | IdxTy = &createAndAddDIE(dwarf::DW_TAG_base_type, UnitDie); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1693 | addString(*IdxTy, dwarf::DW_AT_name, "sizetype"); |
| 1694 | addUInt(*IdxTy, dwarf::DW_AT_byte_size, None, sizeof(int64_t)); |
| 1695 | addUInt(*IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
David Blaikie | 12e00fc | 2014-04-03 06:28:20 +0000 | [diff] [blame] | 1696 | dwarf::DW_ATE_unsigned); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1697 | setIndexTyDie(IdxTy); |
| 1698 | } |
| 1699 | |
| 1700 | // Add subranges to array type. |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1701 | DIArray Elements = CTy.getTypeArray(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1702 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 1703 | DIDescriptor Element = Elements.getElement(i); |
| 1704 | if (Element.getTag() == dwarf::DW_TAG_subrange_type) |
| 1705 | constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy); |
| 1706 | } |
| 1707 | } |
| 1708 | |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1709 | /// constructEnumTypeDIE - Construct an enum type DIE from DICompositeType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1710 | void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) { |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1711 | DIArray Elements = CTy.getTypeArray(); |
| 1712 | |
| 1713 | // Add enumerators to enumeration type. |
| 1714 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1715 | DIEnumerator Enum(Elements.getElement(i)); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1716 | if (Enum.isEnumerator()) { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1717 | DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1718 | StringRef Name = Enum.getName(); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1719 | addString(Enumerator, dwarf::DW_AT_name, Name); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1720 | int64_t Value = Enum.getEnumValue(); |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 1721 | addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, |
| 1722 | Value); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1723 | } |
| 1724 | } |
| 1725 | DIType DTy = resolve(CTy.getTypeDerivedFrom()); |
| 1726 | if (DTy) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1727 | addType(Buffer, DTy); |
| 1728 | addFlag(Buffer, dwarf::DW_AT_enum_class); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1729 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1732 | /// constructContainingTypeDIEs - Construct DIEs for types that contain |
| 1733 | /// vtables. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1734 | void DwarfUnit::constructContainingTypeDIEs() { |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1735 | for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(), |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1736 | CE = ContainingTypeMap.end(); |
| 1737 | CI != CE; ++CI) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1738 | DIE &SPDie = *CI->first; |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 1739 | DIDescriptor D(CI->second); |
| 1740 | if (!D) |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1741 | continue; |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 1742 | DIE *NDie = getDIE(D); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1743 | if (!NDie) |
| 1744 | continue; |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1745 | addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1749 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
David Blaikie | 914046e | 2014-04-25 20:00:34 +0000 | [diff] [blame] | 1750 | std::unique_ptr<DIE> DwarfUnit::constructVariableDIE(DbgVariable &DV, |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 1751 | AbstractOrInlined AbsIn) { |
| 1752 | auto D = constructVariableDIEImpl(DV, AbsIn); |
David Blaikie | e071fc8 | 2014-04-25 17:32:19 +0000 | [diff] [blame] | 1753 | DV.setDIE(*D); |
| 1754 | return D; |
| 1755 | } |
| 1756 | |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 1757 | std::unique_ptr<DIE> |
| 1758 | DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV, |
| 1759 | AbstractOrInlined AbsIn) { |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1760 | StringRef Name = DV.getName(); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1761 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1762 | // Define variable debug information entry. |
David Blaikie | 914046e | 2014-04-25 20:00:34 +0000 | [diff] [blame] | 1763 | auto VariableDie = make_unique<DIE>(DV.getTag()); |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1764 | DbgVariable *AbsVar = DV.getAbstractVariable(); |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1765 | DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : nullptr; |
Manman Ren | 4213c39 | 2013-05-29 17:16:59 +0000 | [diff] [blame] | 1766 | if (AbsDIE) |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 1767 | addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin, *AbsDIE); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1768 | else { |
David Blaikie | 715528b | 2013-08-19 03:34:03 +0000 | [diff] [blame] | 1769 | if (!Name.empty()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1770 | addString(*VariableDie, dwarf::DW_AT_name, Name); |
| 1771 | addSourceLine(*VariableDie, DV.getVariable()); |
| 1772 | addType(*VariableDie, DV.getType()); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 1775 | if (AbsIn != AOI_Inlined && DV.isArtificial()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1776 | addFlag(*VariableDie, dwarf::DW_AT_artificial); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1777 | |
David Blaikie | 44078b3 | 2014-04-30 22:41:33 +0000 | [diff] [blame] | 1778 | if (AbsIn == AOI_Abstract) |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1779 | return VariableDie; |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1780 | |
| 1781 | // Add variable address. |
| 1782 | |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1783 | unsigned Offset = DV.getDotDebugLocOffset(); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1784 | if (Offset != ~0U) { |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1785 | addLocationList(*VariableDie, dwarf::DW_AT_location, Offset); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1786 | return VariableDie; |
| 1787 | } |
| 1788 | |
Eric Christopher | cead033 | 2011-10-03 15:49:20 +0000 | [diff] [blame] | 1789 | // Check if variable is described by a DBG_VALUE instruction. |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1790 | if (const MachineInstr *DVInsn = DV.getMInsn()) { |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1791 | assert(DVInsn->getNumOperands() == 3); |
| 1792 | if (DVInsn->getOperand(0).isReg()) { |
| 1793 | const MachineOperand RegOp = DVInsn->getOperand(0); |
Adrian Prantl | 1994288 | 2013-07-09 21:44:06 +0000 | [diff] [blame] | 1794 | // If the second operand is an immediate, this is an indirect value. |
Adrian Prantl | 418d1d1 | 2013-07-09 20:28:37 +0000 | [diff] [blame] | 1795 | if (DVInsn->getOperand(1).isImm()) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1796 | MachineLocation Location(RegOp.getReg(), |
| 1797 | DVInsn->getOperand(1).getImm()); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1798 | addVariableAddress(DV, *VariableDie, Location); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1799 | } else if (RegOp.getReg()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1800 | addVariableAddress(DV, *VariableDie, MachineLocation(RegOp.getReg())); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1801 | } else if (DVInsn->getOperand(0).isImm()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1802 | addConstantValue(*VariableDie, DVInsn->getOperand(0), DV.getType()); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1803 | else if (DVInsn->getOperand(0).isFPImm()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1804 | addConstantFPValue(*VariableDie, DVInsn->getOperand(0)); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1805 | else if (DVInsn->getOperand(0).isCImm()) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1806 | addConstantValue(*VariableDie, DVInsn->getOperand(0).getCImm(), |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1807 | isUnsignedDIType(DD, DV.getType())); |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 1808 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1809 | return VariableDie; |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
David Blaikie | e071fc8 | 2014-04-25 17:32:19 +0000 | [diff] [blame] | 1812 | // .. else use frame index. |
| 1813 | int FI = DV.getFrameIndex(); |
| 1814 | if (FI != ~0) { |
| 1815 | unsigned FrameReg = 0; |
| 1816 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
| 1817 | int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); |
| 1818 | MachineLocation Location(FrameReg, Offset); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1819 | addVariableAddress(DV, *VariableDie, Location); |
David Blaikie | e071fc8 | 2014-04-25 17:32:19 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1822 | return VariableDie; |
| 1823 | } |
| 1824 | |
Manman Ren | 230ec86 | 2013-10-23 23:00:44 +0000 | [diff] [blame] | 1825 | /// constructMemberDIE - Construct member DIE from DIDerivedType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1826 | void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) { |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1827 | DIE &MemberDie = createAndAddDIE(DT.getTag(), Buffer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1828 | StringRef Name = DT.getName(); |
| 1829 | if (!Name.empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1830 | addString(MemberDie, dwarf::DW_AT_name, Name); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1831 | |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1832 | addType(MemberDie, resolve(DT.getTypeDerivedFrom())); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1833 | |
| 1834 | addSourceLine(MemberDie, DT); |
| 1835 | |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1836 | if (DT.getTag() == dwarf::DW_TAG_inheritance && DT.isVirtual()) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1837 | |
| 1838 | // For C++, virtual base classes are not at fixed offset. Use following |
| 1839 | // expression to extract appropriate offset from vtable. |
| 1840 | // BaseAddr = ObAddr + *((*ObAddr) - Offset) |
| 1841 | |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1842 | DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc(); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1843 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup); |
| 1844 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1845 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1846 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT.getOffsetInBits()); |
| 1847 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus); |
| 1848 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1849 | addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1850 | |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1851 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie); |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1852 | } else { |
| 1853 | uint64_t Size = DT.getSizeInBits(); |
| 1854 | uint64_t FieldSize = getBaseTypeSize(DD, DT); |
| 1855 | uint64_t OffsetInBytes; |
| 1856 | |
| 1857 | if (Size != FieldSize) { |
Eric Christopher | 1acdbb8 | 2014-03-12 17:14:46 +0000 | [diff] [blame] | 1858 | // Handle bitfield, assume bytes are 8 bits. |
| 1859 | addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8); |
| 1860 | addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size); |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1861 | |
| 1862 | uint64_t Offset = DT.getOffsetInBits(); |
| 1863 | uint64_t AlignMask = ~(DT.getAlignInBits() - 1); |
| 1864 | uint64_t HiMark = (Offset + FieldSize) & AlignMask; |
| 1865 | uint64_t FieldOffset = (HiMark - FieldSize); |
| 1866 | Offset -= FieldOffset; |
| 1867 | |
| 1868 | // Maybe we need to work from the other end. |
| 1869 | if (Asm->getDataLayout().isLittleEndian()) |
| 1870 | Offset = FieldSize - (Offset + Size); |
| 1871 | addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset); |
| 1872 | |
Adrian Prantl | c67655a | 2014-01-28 18:13:47 +0000 | [diff] [blame] | 1873 | // Here DW_AT_data_member_location points to the anonymous |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1874 | // field that includes this bit field. |
| 1875 | OffsetInBytes = FieldOffset >> 3; |
| 1876 | } else |
| 1877 | // This is not a bitfield. |
| 1878 | OffsetInBytes = DT.getOffsetInBits() >> 3; |
David Blaikie | 2ada116 | 2014-01-03 00:48:38 +0000 | [diff] [blame] | 1879 | |
David Blaikie | 22b29a5 | 2014-01-03 01:30:05 +0000 | [diff] [blame] | 1880 | if (DD->getDwarfVersion() <= 2) { |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 1881 | DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc(); |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1882 | addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 1883 | addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes); |
David Blaikie | 22b29a5 | 2014-01-03 01:30:05 +0000 | [diff] [blame] | 1884 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie); |
| 1885 | } else |
| 1886 | addUInt(MemberDie, dwarf::DW_AT_data_member_location, None, |
| 1887 | OffsetInBytes); |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1888 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1889 | |
| 1890 | if (DT.isProtected()) |
Nick Lewycky | cb91849 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1891 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1892 | dwarf::DW_ACCESS_protected); |
| 1893 | else if (DT.isPrivate()) |
Nick Lewycky | cb91849 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1894 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1895 | dwarf::DW_ACCESS_private); |
| 1896 | // Otherwise C++ member and base classes are considered public. |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1897 | else |
Nick Lewycky | cb91849 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1898 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1899 | dwarf::DW_ACCESS_public); |
| 1900 | if (DT.isVirtual()) |
Nick Lewycky | cfde1a2 | 2011-12-14 00:56:07 +0000 | [diff] [blame] | 1901 | addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1902 | dwarf::DW_VIRTUALITY_virtual); |
Devang Patel | 514b400 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1903 | |
| 1904 | // Objective-C properties. |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1905 | if (MDNode *PNode = DT.getObjCProperty()) |
| 1906 | if (DIEEntry *PropertyDie = getDIEEntry(PNode)) |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1907 | MemberDie.addValue(dwarf::DW_AT_APPLE_property, dwarf::DW_FORM_ref4, |
| 1908 | PropertyDie); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1909 | |
David Blaikie | 37fefc3 | 2012-12-13 22:43:07 +0000 | [diff] [blame] | 1910 | if (DT.isArtificial()) |
| 1911 | addFlag(MemberDie, dwarf::DW_AT_artificial); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1912 | } |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1913 | |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1914 | /// getOrCreateStaticMemberDIE - Create new DIE for C++ static member. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1915 | DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) { |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1916 | if (!DT.Verify()) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1917 | return nullptr; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1918 | |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1919 | // Construct the context before querying for the existence of the DIE in case |
| 1920 | // such construction creates the DIE. |
| 1921 | DIE *ContextDIE = getOrCreateContextDIE(resolve(DT.getContext())); |
David Blaikie | bd700e4 | 2013-11-14 21:24:34 +0000 | [diff] [blame] | 1922 | assert(dwarf::isType(ContextDIE->getTag()) && |
| 1923 | "Static member should belong to a type."); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1924 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1925 | if (DIE *StaticMemberDIE = getDIE(DT)) |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1926 | return StaticMemberDIE; |
| 1927 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 1928 | DIE &StaticMemberDIE = createAndAddDIE(DT.getTag(), *ContextDIE, DT); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1929 | |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1930 | DIType Ty = resolve(DT.getTypeDerivedFrom()); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1931 | |
| 1932 | addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName()); |
| 1933 | addType(StaticMemberDIE, Ty); |
| 1934 | addSourceLine(StaticMemberDIE, DT); |
| 1935 | addFlag(StaticMemberDIE, dwarf::DW_AT_external); |
| 1936 | addFlag(StaticMemberDIE, dwarf::DW_AT_declaration); |
| 1937 | |
| 1938 | // FIXME: We could omit private if the parent is a class_type, and |
| 1939 | // public if the parent is something else. |
| 1940 | if (DT.isProtected()) |
| 1941 | addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1942 | dwarf::DW_ACCESS_protected); |
| 1943 | else if (DT.isPrivate()) |
| 1944 | addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1945 | dwarf::DW_ACCESS_private); |
| 1946 | else |
| 1947 | addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1948 | dwarf::DW_ACCESS_public); |
| 1949 | |
| 1950 | if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT.getConstant())) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1951 | addConstantValue(StaticMemberDIE, CI, isUnsignedDIType(DD, Ty)); |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 1952 | if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT.getConstant())) |
| 1953 | addConstantFPValue(StaticMemberDIE, CFP); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1954 | |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 1955 | return &StaticMemberDIE; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1956 | } |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 1957 | |
David Blaikie | d82b237 | 2014-03-24 20:28:10 +0000 | [diff] [blame] | 1958 | void DwarfUnit::emitHeader(const MCSymbol *ASectionSym) const { |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 1959 | Asm->OutStreamer.AddComment("DWARF version number"); |
| 1960 | Asm->EmitInt16(DD->getDwarfVersion()); |
| 1961 | Asm->OutStreamer.AddComment("Offset Into Abbrev. Section"); |
David Blaikie | 6896e19 | 2013-12-04 23:39:02 +0000 | [diff] [blame] | 1962 | // We share one abbreviations table across all units so it's always at the |
| 1963 | // start of the section. Use a relocatable offset where needed to ensure |
| 1964 | // linking doesn't invalidate that offset. |
David Blaikie | 3c9a3cc | 2014-03-24 20:53:02 +0000 | [diff] [blame] | 1965 | if (ASectionSym) |
| 1966 | Asm->EmitSectionOffset(ASectionSym, ASectionSym); |
| 1967 | else |
David Blaikie | 326e1fa | 2014-04-02 02:04:51 +0000 | [diff] [blame] | 1968 | // Use a constant value when no symbol is provided. |
David Blaikie | 3c9a3cc | 2014-03-24 20:53:02 +0000 | [diff] [blame] | 1969 | Asm->EmitInt32(0); |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 1970 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
| 1971 | Asm->EmitInt8(Asm->getDataLayout().getPointerSize()); |
| 1972 | } |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 1973 | |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 1974 | void DwarfUnit::addRange(RangeSpan Range) { |
| 1975 | // Only add a range for this unit if we're emitting full debug. |
| 1976 | if (getCUNode().getEmissionKind() == DIBuilder::FullDebug) { |
| 1977 | // If we have no current ranges just add the range and return, otherwise, |
| 1978 | // check the current section and CU against the previous section and CU we |
| 1979 | // emitted into and the subprogram was contained within. If these are the |
| 1980 | // same then extend our current range, otherwise add this as a new range. |
| 1981 | if (CURanges.size() == 0 || |
| 1982 | this != DD->getPrevCU() || |
| 1983 | Asm->getCurrentSection() != DD->getPrevSection()) { |
| 1984 | CURanges.push_back(Range); |
| 1985 | return; |
| 1986 | } |
| 1987 | |
| 1988 | assert(&(CURanges.back().getEnd()->getSection()) == |
| 1989 | &(Range.getEnd()->getSection()) && |
| 1990 | "We can only append to a range in the same section!"); |
| 1991 | CURanges.back().setEnd(Range.getEnd()); |
| 1992 | } |
| 1993 | } |
| 1994 | |
David Blaikie | 2494fdb | 2014-02-14 22:41:51 +0000 | [diff] [blame] | 1995 | void DwarfCompileUnit::initStmtList(MCSymbol *DwarfLineSectionSym) { |
| 1996 | // Define start line table label for each Compile Unit. |
| 1997 | MCSymbol *LineTableStartSym = |
David Blaikie | 3464161 | 2014-04-01 08:07:52 +0000 | [diff] [blame] | 1998 | Asm->OutStreamer.getDwarfLineTableSymbol(getUniqueID()); |
David Blaikie | 2494fdb | 2014-02-14 22:41:51 +0000 | [diff] [blame] | 1999 | |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 2000 | stmtListIndex = UnitDie.getValues().size(); |
David Blaikie | 60e6386 | 2014-02-14 23:58:13 +0000 | [diff] [blame] | 2001 | |
David Blaikie | 2494fdb | 2014-02-14 22:41:51 +0000 | [diff] [blame] | 2002 | // DW_AT_stmt_list is a offset of line number information for this |
| 2003 | // compile unit in debug_line section. For split dwarf this is |
| 2004 | // left in the skeleton CU and so not included. |
| 2005 | // The line table entries are not always emitted in assembly, so it |
| 2006 | // is not okay to use line_table_start here. |
| 2007 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 2008 | addSectionLabel(UnitDie, dwarf::DW_AT_stmt_list, LineTableStartSym); |
David Blaikie | 2494fdb | 2014-02-14 22:41:51 +0000 | [diff] [blame] | 2009 | else |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 2010 | addSectionDelta(UnitDie, dwarf::DW_AT_stmt_list, LineTableStartSym, |
David Blaikie | 2494fdb | 2014-02-14 22:41:51 +0000 | [diff] [blame] | 2011 | DwarfLineSectionSym); |
| 2012 | } |
| 2013 | |
David Blaikie | 60e6386 | 2014-02-14 23:58:13 +0000 | [diff] [blame] | 2014 | void DwarfCompileUnit::applyStmtList(DIE &D) { |
| 2015 | D.addValue(dwarf::DW_AT_stmt_list, |
David Blaikie | bd57905 | 2014-04-28 21:14:27 +0000 | [diff] [blame] | 2016 | UnitDie.getAbbrev().getData()[stmtListIndex].getForm(), |
| 2017 | UnitDie.getValues()[stmtListIndex]); |
David Blaikie | 60e6386 | 2014-02-14 23:58:13 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
David Blaikie | d82b237 | 2014-03-24 20:28:10 +0000 | [diff] [blame] | 2020 | void DwarfTypeUnit::emitHeader(const MCSymbol *ASectionSym) const { |
| 2021 | DwarfUnit::emitHeader(ASectionSym); |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 2022 | Asm->OutStreamer.AddComment("Type Signature"); |
| 2023 | Asm->OutStreamer.EmitIntValue(TypeSignature, sizeof(TypeSignature)); |
| 2024 | Asm->OutStreamer.AddComment("Type DIE Offset"); |
David Blaikie | 15ed5eb | 2014-01-10 01:38:41 +0000 | [diff] [blame] | 2025 | // In a skeleton type unit there is no type DIE so emit a zero offset. |
| 2026 | Asm->OutStreamer.EmitIntValue(Ty ? Ty->getOffset() : 0, |
| 2027 | sizeof(Ty->getOffset())); |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | void DwarfTypeUnit::initSection(const MCSection *Section) { |
| 2031 | assert(!this->Section); |
| 2032 | this->Section = Section; |
| 2033 | // Since each type unit is contained in its own COMDAT section, the begin |
| 2034 | // label and the section label are the same. Using the begin label emission in |
| 2035 | // DwarfDebug to emit the section label as well is slightly subtle/sneaky, but |
| 2036 | // the only other alternative of lazily constructing start-of-section labels |
| 2037 | // and storing a mapping in DwarfDebug (or AsmPrinter). |
| 2038 | this->SectionSym = this->LabelBegin = |
| 2039 | Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID()); |
| 2040 | this->LabelEnd = |
| 2041 | Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID()); |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 2042 | } |