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