Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf debug info into asm files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | b14490d | 2010-03-09 00:39:24 +0000 | [diff] [blame] | 13 | |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "dwarfdebug" |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 15 | #include "DwarfDebug.h" |
Chris Lattner | 3f3fb97 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 16 | #include "DIE.h" |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 17 | #include "DIEHash.h" |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 18 | #include "DwarfAccelTable.h" |
Devang Patel | 5eb4319 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 19 | #include "DwarfCompileUnit.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
| 21 | #include "llvm/ADT/Statistic.h" |
| 22 | #include "llvm/ADT/StringExtras.h" |
| 23 | #include "llvm/ADT/Triple.h" |
David Greene | 829b3e8 | 2009-08-19 21:52:55 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/DIBuilder.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 28 | #include "llvm/IR/Constants.h" |
| 29 | #include "llvm/IR/DataLayout.h" |
| 30 | #include "llvm/IR/Instructions.h" |
| 31 | #include "llvm/IR/Module.h" |
Chris Lattner | e13c372 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 32 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | 4d2c0f9 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 4b7dadb | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | e13c372 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCSymbol.h" |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 36 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | cdf01b5 | 2009-10-13 06:47:08 +0000 | [diff] [blame] | 37 | #include "llvm/Support/Debug.h" |
David Majnemer | ed89b5c | 2013-08-21 06:13:34 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Dwarf.h" |
Daniel Dunbar | cdf01b5 | 2009-10-13 06:47:08 +0000 | [diff] [blame] | 39 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | f5c834f | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 40 | #include "llvm/Support/FormattedStream.h" |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 41 | #include "llvm/Support/MD5.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 42 | #include "llvm/Support/Path.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Timer.h" |
| 44 | #include "llvm/Support/ValueHandle.h" |
| 45 | #include "llvm/Target/TargetFrameLowering.h" |
| 46 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 47 | #include "llvm/Target/TargetMachine.h" |
| 48 | #include "llvm/Target/TargetOptions.h" |
| 49 | #include "llvm/Target/TargetRegisterInfo.h" |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 52 | static cl::opt<bool> |
| 53 | DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden, |
| 54 | cl::desc("Disable debug info printing")); |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 55 | |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 56 | static cl::opt<bool> UnknownLocations( |
| 57 | "use-unknown-locations", cl::Hidden, |
| 58 | cl::desc("Make an absence of debug location information explicit."), |
| 59 | cl::init(false)); |
Dan Gohman | 7421ae4 | 2010-05-07 01:08:53 +0000 | [diff] [blame] | 60 | |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 61 | static cl::opt<bool> |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 62 | GenerateODRHash("generate-odr-hash", cl::Hidden, |
| 63 | cl::desc("Add an ODR hash to external type DIEs."), |
| 64 | cl::init(false)); |
| 65 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 66 | static cl::opt<bool> GenerateCUHash("generate-cu-hash", cl::Hidden, |
| 67 | cl::desc("Add the CU hash as the dwo_id."), |
| 68 | cl::init(false)); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 69 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 70 | static cl::opt<bool> |
| 71 | GenerateGnuPubSections("generate-gnu-dwarf-pub-sections", cl::Hidden, |
| 72 | cl::desc("Generate GNU-style pubnames and pubtypes"), |
| 73 | cl::init(false)); |
| 74 | |
Eric Christopher | 20b76a7 | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 75 | namespace { |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 76 | enum DefaultOnOff { |
| 77 | Default, |
| 78 | Enable, |
| 79 | Disable |
| 80 | }; |
Eric Christopher | 20b76a7 | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 81 | } |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 82 | |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 83 | static cl::opt<DefaultOnOff> |
| 84 | DwarfAccelTables("dwarf-accel-tables", cl::Hidden, |
| 85 | cl::desc("Output prototype dwarf accelerator tables."), |
| 86 | cl::values(clEnumVal(Default, "Default for platform"), |
| 87 | clEnumVal(Enable, "Enabled"), |
| 88 | clEnumVal(Disable, "Disabled"), clEnumValEnd), |
| 89 | cl::init(Default)); |
Eric Christopher | 20b76a7 | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 90 | |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 91 | static cl::opt<DefaultOnOff> |
Eric Christopher | 7f2b551 | 2013-07-23 22:16:41 +0000 | [diff] [blame] | 92 | SplitDwarf("split-dwarf", cl::Hidden, |
| 93 | cl::desc("Output prototype dwarf split debug info."), |
| 94 | cl::values(clEnumVal(Default, "Default for platform"), |
| 95 | clEnumVal(Enable, "Enabled"), |
| 96 | clEnumVal(Disable, "Disabled"), clEnumValEnd), |
| 97 | cl::init(Default)); |
Eric Christopher | 2942431 | 2012-11-12 22:22:20 +0000 | [diff] [blame] | 98 | |
Eric Christopher | 7da2488 | 2013-08-19 21:07:38 +0000 | [diff] [blame] | 99 | static cl::opt<DefaultOnOff> |
Eric Christopher | 4d36ca0 | 2013-08-26 23:24:35 +0000 | [diff] [blame] | 100 | DwarfPubSections("generate-dwarf-pub-sections", cl::Hidden, |
| 101 | cl::desc("Generate DWARF pubnames and pubtypes sections"), |
| 102 | cl::values(clEnumVal(Default, "Default for platform"), |
| 103 | clEnumVal(Enable, "Enabled"), |
| 104 | clEnumVal(Disable, "Disabled"), clEnumValEnd), |
| 105 | cl::init(Default)); |
Eric Christopher | 7da2488 | 2013-08-19 21:07:38 +0000 | [diff] [blame] | 106 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 107 | static cl::opt<unsigned> |
| 108 | DwarfVersionNumber("dwarf-version", cl::Hidden, |
| 109 | cl::desc("Generate DWARF for dwarf version."), |
| 110 | cl::init(0)); |
| 111 | |
Benjamin Kramer | b12cf01 | 2013-08-24 12:54:27 +0000 | [diff] [blame] | 112 | static const char *const DWARFGroupName = "DWARF Emission"; |
| 113 | static const char *const DbgTimerName = "DWARF Debug Writer"; |
Bill Wendling | fcc1414 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 114 | |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 115 | //===----------------------------------------------------------------------===// |
| 116 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 117 | // Configuration values for initial hash set sizes (log2). |
| 118 | // |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 119 | static const unsigned InitAbbreviationsSetSize = 9; // log2(512) |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 120 | |
| 121 | namespace llvm { |
| 122 | |
Manman Ren | be5576f | 2013-10-08 19:07:44 +0000 | [diff] [blame] | 123 | /// resolve - Look in the DwarfDebug map for the MDNode that |
| 124 | /// corresponds to the reference. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 125 | template <typename T> T DbgVariable::resolve(DIRef<T> Ref) const { |
Manman Ren | be5576f | 2013-10-08 19:07:44 +0000 | [diff] [blame] | 126 | return DD->resolve(Ref); |
| 127 | } |
| 128 | |
Nick Lewycky | 019d255 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 129 | DIType DbgVariable::getType() const { |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 130 | DIType Ty = Var.getType(); |
| 131 | // FIXME: isBlockByrefVariable should be reformulated in terms of complex |
| 132 | // addresses instead. |
| 133 | if (Var.isBlockByrefVariable()) { |
| 134 | /* Byref variables, in Blocks, are declared by the programmer as |
| 135 | "SomeType VarName;", but the compiler creates a |
| 136 | __Block_byref_x_VarName struct, and gives the variable VarName |
| 137 | either the struct, or a pointer to the struct, as its type. This |
| 138 | is necessary for various behind-the-scenes things the compiler |
| 139 | needs to do with by-reference variables in blocks. |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 140 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 141 | However, as far as the original *programmer* is concerned, the |
| 142 | variable should still have type 'SomeType', as originally declared. |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 143 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 144 | The following function dives into the __Block_byref_x_VarName |
| 145 | struct to find the original type of the variable. This will be |
| 146 | passed back to the code generating the type for the Debug |
| 147 | Information Entry for the variable 'VarName'. 'VarName' will then |
| 148 | have the original type 'SomeType' in its debug information. |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 149 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 150 | The original type 'SomeType' will be the type of the field named |
| 151 | 'VarName' inside the __Block_byref_x_VarName struct. |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 152 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 153 | NOTE: In order for this to not completely fail on the debugger |
| 154 | side, the Debug Information Entry for the variable VarName needs to |
| 155 | have a DW_AT_location that tells the debugger how to unwind through |
| 156 | the pointers and __Block_byref_x_VarName struct to find the actual |
| 157 | value of the variable. The function addBlockByrefType does this. */ |
| 158 | DIType subType = Ty; |
Eric Christopher | 31b0576 | 2013-08-08 01:41:00 +0000 | [diff] [blame] | 159 | uint16_t tag = Ty.getTag(); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 160 | |
Eric Christopher | 9adc55f | 2013-09-04 19:53:21 +0000 | [diff] [blame] | 161 | if (tag == dwarf::DW_TAG_pointer_type) |
Manman Ren | be5576f | 2013-10-08 19:07:44 +0000 | [diff] [blame] | 162 | subType = resolve(DIDerivedType(Ty).getTypeDerivedFrom()); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 163 | |
Eric Christopher | 9adc55f | 2013-09-04 19:53:21 +0000 | [diff] [blame] | 164 | DIArray Elements = DICompositeType(subType).getTypeArray(); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 165 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
David Blaikie | 5af2aca | 2013-11-18 23:57:26 +0000 | [diff] [blame] | 166 | DIDerivedType DT(Elements.getElement(i)); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 167 | if (getName() == DT.getName()) |
Manman Ren | be5576f | 2013-10-08 19:07:44 +0000 | [diff] [blame] | 168 | return (resolve(DT.getTypeDerivedFrom())); |
Devang Patel | 6d9f9fe | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 169 | } |
Devang Patel | 6d9f9fe | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 170 | } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 171 | return Ty; |
| 172 | } |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 173 | |
Chris Lattner | f5d0636 | 2010-04-05 04:09:20 +0000 | [diff] [blame] | 174 | } // end llvm namespace |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 175 | |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 176 | /// Return Dwarf Version by checking module flags. |
| 177 | static unsigned getDwarfVersionFromModule(const Module *M) { |
Manman Ren | 8bfde89 | 2013-07-16 23:21:16 +0000 | [diff] [blame] | 178 | Value *Val = M->getModuleFlag("Dwarf Version"); |
| 179 | if (!Val) |
Eric Christopher | e31e072 | 2013-09-04 22:21:24 +0000 | [diff] [blame] | 180 | return dwarf::DWARF_VERSION; |
Manman Ren | 8bfde89 | 2013-07-16 23:21:16 +0000 | [diff] [blame] | 181 | return cast<ConstantInt>(Val)->getZExtValue(); |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Chris Lattner | f0d6bd3 | 2010-04-05 05:11:15 +0000 | [diff] [blame] | 184 | DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 185 | : Asm(A), MMI(Asm->MMI), FirstCU(0), |
| 186 | AbbreviationsSet(InitAbbreviationsSetSize), |
| 187 | SourceIdMap(DIEValueAllocator), PrevLabel(NULL), GlobalCUIndexCount(0), |
| 188 | InfoHolder(A, &AbbreviationsSet, Abbreviations, "info_string", |
| 189 | DIEValueAllocator), |
| 190 | SkeletonAbbrevSet(InitAbbreviationsSetSize), |
| 191 | SkeletonHolder(A, &SkeletonAbbrevSet, SkeletonAbbrevs, "skel_string", |
| 192 | DIEValueAllocator) { |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 193 | |
Rafael Espindola | a716096 | 2011-05-06 14:56:22 +0000 | [diff] [blame] | 194 | DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0; |
Chris Lattner | e58b547 | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 195 | DwarfStrSectionSym = TextSectionSym = 0; |
Eric Christopher | 7480433 | 2013-02-07 21:19:50 +0000 | [diff] [blame] | 196 | DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = DwarfLineSectionSym = 0; |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 197 | DwarfAddrSectionSym = 0; |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 198 | DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = 0; |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 199 | FunctionBeginSym = FunctionEndSym = 0; |
Eric Christopher | ad9fe89 | 2012-04-02 17:58:52 +0000 | [diff] [blame] | 200 | |
Adrian Prantl | 5bf1d00 | 2013-10-15 20:26:37 +0000 | [diff] [blame] | 201 | // Turn on accelerator tables for Darwin by default, pubnames by |
| 202 | // default for non-Darwin, and handle split dwarf. |
Eric Christopher | 203e12b | 2013-04-27 01:07:52 +0000 | [diff] [blame] | 203 | bool IsDarwin = Triple(A->getTargetTriple()).isOSDarwin(); |
Eric Christopher | 4977f21 | 2012-08-23 22:36:36 +0000 | [diff] [blame] | 204 | |
Eric Christopher | 574b5c8 | 2013-08-19 21:41:38 +0000 | [diff] [blame] | 205 | if (DwarfAccelTables == Default) |
| 206 | HasDwarfAccelTables = IsDarwin; |
| 207 | else |
Eric Christopher | 5297df0 | 2013-08-26 20:58:35 +0000 | [diff] [blame] | 208 | HasDwarfAccelTables = DwarfAccelTables == Enable; |
Eric Christopher | 20b76a7 | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 209 | |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 210 | if (SplitDwarf == Default) |
| 211 | HasSplitDwarf = false; |
Eric Christopher | 2942431 | 2012-11-12 22:22:20 +0000 | [diff] [blame] | 212 | else |
Eric Christopher | 574b5c8 | 2013-08-19 21:41:38 +0000 | [diff] [blame] | 213 | HasSplitDwarf = SplitDwarf == Enable; |
Eric Christopher | 2942431 | 2012-11-12 22:22:20 +0000 | [diff] [blame] | 214 | |
Eric Christopher | 4d36ca0 | 2013-08-26 23:24:35 +0000 | [diff] [blame] | 215 | if (DwarfPubSections == Default) |
| 216 | HasDwarfPubSections = !IsDarwin; |
Eric Christopher | 574b5c8 | 2013-08-19 21:41:38 +0000 | [diff] [blame] | 217 | else |
Eric Christopher | 4d36ca0 | 2013-08-26 23:24:35 +0000 | [diff] [blame] | 218 | HasDwarfPubSections = DwarfPubSections == Enable; |
Eric Christopher | 7da2488 | 2013-08-19 21:07:38 +0000 | [diff] [blame] | 219 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 220 | DwarfVersion = DwarfVersionNumber |
| 221 | ? DwarfVersionNumber |
| 222 | : getDwarfVersionFromModule(MMI->getModule()); |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 223 | |
Dan Gohman | 6e681a5 | 2010-06-18 15:56:31 +0000 | [diff] [blame] | 224 | { |
| 225 | NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled); |
Eric Christopher | 58f4195 | 2012-11-19 22:42:15 +0000 | [diff] [blame] | 226 | beginModule(); |
Torok Edwin | f8dba24 | 2010-04-07 10:44:46 +0000 | [diff] [blame] | 227 | } |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 228 | } |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 229 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 230 | // Switch to the specified MCSection and emit an assembler |
| 231 | // temporary label to it if SymbolStem is specified. |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 232 | static MCSymbol *emitSectionSym(AsmPrinter *Asm, const MCSection *Section, |
Eric Christopher | a7b6189 | 2011-11-07 09:18:38 +0000 | [diff] [blame] | 233 | const char *SymbolStem = 0) { |
| 234 | Asm->OutStreamer.SwitchSection(Section); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 235 | if (!SymbolStem) |
| 236 | return 0; |
Eric Christopher | a7b6189 | 2011-11-07 09:18:38 +0000 | [diff] [blame] | 237 | |
| 238 | MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem); |
| 239 | Asm->OutStreamer.EmitLabel(TmpSym); |
| 240 | return TmpSym; |
| 241 | } |
| 242 | |
David Blaikie | 72f1a3e | 2013-11-23 01:17:34 +0000 | [diff] [blame] | 243 | DwarfUnits::~DwarfUnits() { |
| 244 | for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(), E = CUs.end(); |
| 245 | I != E; ++I) |
| 246 | delete *I; |
| 247 | } |
| 248 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 249 | MCSymbol *DwarfUnits::getStringPoolSym() { |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 250 | return Asm->GetTempSymbol(StringPref); |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 253 | MCSymbol *DwarfUnits::getStringPoolEntry(StringRef Str) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 254 | std::pair<MCSymbol *, unsigned> &Entry = |
| 255 | StringPool.GetOrCreateValue(Str).getValue(); |
| 256 | if (Entry.first) |
| 257 | return Entry.first; |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 258 | |
| 259 | Entry.second = NextStringPoolNumber++; |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 260 | return Entry.first = Asm->GetTempSymbol(StringPref, Entry.second); |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 263 | unsigned DwarfUnits::getStringPoolIndex(StringRef Str) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 264 | std::pair<MCSymbol *, unsigned> &Entry = |
| 265 | StringPool.GetOrCreateValue(Str).getValue(); |
| 266 | if (Entry.first) |
| 267 | return Entry.second; |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 268 | |
| 269 | Entry.second = NextStringPoolNumber++; |
| 270 | Entry.first = Asm->GetTempSymbol(StringPref, Entry.second); |
| 271 | return Entry.second; |
| 272 | } |
| 273 | |
David Blaikie | dea547b | 2013-06-28 18:47:14 +0000 | [diff] [blame] | 274 | unsigned DwarfUnits::getAddrPoolIndex(const MCSymbol *Sym) { |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 275 | return getAddrPoolIndex(MCSymbolRefExpr::Create(Sym, Asm->OutContext)); |
| 276 | } |
| 277 | |
Ulrich Weigand | 8b3d226 | 2013-07-02 18:46:46 +0000 | [diff] [blame] | 278 | unsigned DwarfUnits::getAddrPoolIndex(const MCExpr *Sym) { |
| 279 | std::pair<DenseMap<const MCExpr *, unsigned>::iterator, bool> P = |
David Blaikie | b8ef785 | 2013-06-28 18:47:19 +0000 | [diff] [blame] | 280 | AddressPool.insert(std::make_pair(Sym, NextAddrPoolNumber)); |
David Blaikie | a67de2b | 2013-06-28 18:55:13 +0000 | [diff] [blame] | 281 | if (P.second) |
| 282 | ++NextAddrPoolNumber; |
David Blaikie | b8ef785 | 2013-06-28 18:47:19 +0000 | [diff] [blame] | 283 | return P.first->second; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 286 | // Define a unique number for the abbreviation. |
| 287 | // |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 288 | void DwarfUnits::assignAbbrevNumber(DIEAbbrev &Abbrev) { |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 289 | // Check the set for priors. |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 290 | DIEAbbrev *InSet = AbbreviationsSet->GetOrInsertNode(&Abbrev); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 291 | |
| 292 | // If it's newly added. |
| 293 | if (InSet == &Abbrev) { |
| 294 | // Add to abbreviation list. |
David Blaikie | 2d4e112 | 2013-10-30 17:14:24 +0000 | [diff] [blame] | 295 | Abbreviations.push_back(&Abbrev); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 296 | |
| 297 | // Assign the vector position + 1 as its number. |
David Blaikie | 2d4e112 | 2013-10-30 17:14:24 +0000 | [diff] [blame] | 298 | Abbrev.setNumber(Abbreviations.size()); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 299 | } else { |
| 300 | // Assign existing abbreviation number. |
| 301 | Abbrev.setNumber(InSet->getNumber()); |
| 302 | } |
| 303 | } |
| 304 | |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 305 | static bool isObjCClass(StringRef Name) { |
| 306 | return Name.startswith("+") || Name.startswith("-"); |
| 307 | } |
| 308 | |
| 309 | static bool hasObjCCategory(StringRef Name) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 310 | if (!isObjCClass(Name)) |
| 311 | return false; |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 312 | |
Benjamin Kramer | 260de74 | 2013-08-24 12:15:54 +0000 | [diff] [blame] | 313 | return Name.find(") ") != StringRef::npos; |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static void getObjCClassCategory(StringRef In, StringRef &Class, |
| 317 | StringRef &Category) { |
| 318 | if (!hasObjCCategory(In)) { |
| 319 | Class = In.slice(In.find('[') + 1, In.find(' ')); |
| 320 | Category = ""; |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | Class = In.slice(In.find('[') + 1, In.find('(')); |
| 325 | Category = In.slice(In.find('[') + 1, In.find(' ')); |
| 326 | return; |
| 327 | } |
| 328 | |
| 329 | static StringRef getObjCMethodName(StringRef In) { |
| 330 | return In.slice(In.find(' ') + 1, In.find(']')); |
| 331 | } |
| 332 | |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 333 | // Helper for sorting sections into a stable output order. |
| 334 | static bool SectionSort(const MCSection *A, const MCSection *B) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 335 | std::string LA = (A ? A->getLabelBeginName() : ""); |
| 336 | std::string LB = (B ? B->getLabelBeginName() : ""); |
| 337 | return LA < LB; |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 340 | // Add the various names to the Dwarf accelerator table names. |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 341 | // TODO: Determine whether or not we should add names for programs |
| 342 | // that do not have a DW_AT_name or DW_AT_linkage_name field - this |
| 343 | // is only slightly different than the lookup of non-standard ObjC names. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 344 | static void addSubprogramNames(CompileUnit *TheCU, DISubprogram SP, DIE *Die) { |
| 345 | if (!SP.isDefinition()) |
| 346 | return; |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 347 | TheCU->addAccelName(SP.getName(), Die); |
| 348 | |
| 349 | // If the linkage name is different than the name, go ahead and output |
| 350 | // that as well into the name table. |
| 351 | if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName()) |
| 352 | TheCU->addAccelName(SP.getLinkageName(), Die); |
| 353 | |
| 354 | // If this is an Objective-C selector name add it to the ObjC accelerator |
| 355 | // too. |
| 356 | if (isObjCClass(SP.getName())) { |
| 357 | StringRef Class, Category; |
| 358 | getObjCClassCategory(SP.getName(), Class, Category); |
| 359 | TheCU->addAccelObjC(Class, Die); |
| 360 | if (Category != "") |
| 361 | TheCU->addAccelObjC(Category, Die); |
| 362 | // Also add the base method name to the name table. |
| 363 | TheCU->addAccelName(getObjCMethodName(SP.getName()), Die); |
| 364 | } |
| 365 | } |
| 366 | |
Manman Ren | 3eb9dff | 2013-09-09 19:05:21 +0000 | [diff] [blame] | 367 | /// isSubprogramContext - Return true if Context is either a subprogram |
| 368 | /// or another context nested inside a subprogram. |
| 369 | bool DwarfDebug::isSubprogramContext(const MDNode *Context) { |
| 370 | if (!Context) |
| 371 | return false; |
| 372 | DIDescriptor D(Context); |
| 373 | if (D.isSubprogram()) |
| 374 | return true; |
| 375 | if (D.isType()) |
Manman Ren | 116868e | 2013-09-09 19:47:11 +0000 | [diff] [blame] | 376 | return isSubprogramContext(resolve(DIType(Context).getContext())); |
Manman Ren | 3eb9dff | 2013-09-09 19:05:21 +0000 | [diff] [blame] | 377 | return false; |
| 378 | } |
| 379 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 380 | // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc |
| 381 | // and DW_AT_high_pc attributes. If there are global variables in this |
| 382 | // scope then create and insert DIEs for these variables. |
David Blaikie | 25bc719 | 2013-11-15 23:13:08 +0000 | [diff] [blame] | 383 | DIE *DwarfDebug::updateSubprogramScopeDIE(CompileUnit *SPCU, DISubprogram SP) { |
| 384 | DIE *SPDie = SPCU->getDIE(SP); |
Devang Patel | a37a95e | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 385 | |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 386 | assert(SPDie && "Unable to find subprogram DIE!"); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 387 | |
Bill Wendling | f720bf6 | 2012-11-07 05:19:04 +0000 | [diff] [blame] | 388 | // If we're updating an abstract DIE, then we will be adding the children and |
| 389 | // object pointer later on. But what we don't want to do is process the |
| 390 | // concrete DIE twice. |
David Blaikie | 25bc719 | 2013-11-15 23:13:08 +0000 | [diff] [blame] | 391 | if (DIE *AbsSPDIE = AbstractSPDies.lookup(SP)) { |
Bill Wendling | f720bf6 | 2012-11-07 05:19:04 +0000 | [diff] [blame] | 392 | // Pick up abstract subprogram DIE. |
Manman Ren | 4a841a8 | 2013-10-29 01:03:01 +0000 | [diff] [blame] | 393 | SPDie = SPCU->createAndAddDIE(dwarf::DW_TAG_subprogram, *SPCU->getCUDie()); |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 394 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, AbsSPDIE); |
Bill Wendling | d9bb9b6 | 2012-11-07 04:42:18 +0000 | [diff] [blame] | 395 | } else { |
| 396 | DISubprogram SPDecl = SP.getFunctionDeclaration(); |
| 397 | if (!SPDecl.isSubprogram()) { |
| 398 | // There is not any need to generate specification DIE for a function |
| 399 | // defined at compile unit level. If a function is defined inside another |
| 400 | // function then gdb prefers the definition at top level and but does not |
| 401 | // expect specification DIE in parent function. So avoid creating |
| 402 | // specification DIE for a function defined inside a function. |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 403 | DIScope SPContext = resolve(SP.getContext()); |
| 404 | if (SP.isDefinition() && !SPContext.isCompileUnit() && |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 405 | !SPContext.isFile() && !isSubprogramContext(SPContext)) { |
Bill Wendling | d9bb9b6 | 2012-11-07 04:42:18 +0000 | [diff] [blame] | 406 | SPCU->addFlag(SPDie, dwarf::DW_AT_declaration); |
| 407 | |
| 408 | // Add arguments. |
| 409 | DICompositeType SPTy = SP.getType(); |
| 410 | DIArray Args = SPTy.getTypeArray(); |
Eric Christopher | 31b0576 | 2013-08-08 01:41:00 +0000 | [diff] [blame] | 411 | uint16_t SPTag = SPTy.getTag(); |
Bill Wendling | d9bb9b6 | 2012-11-07 04:42:18 +0000 | [diff] [blame] | 412 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 413 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
Manman Ren | 4a841a8 | 2013-10-29 01:03:01 +0000 | [diff] [blame] | 414 | DIE *Arg = |
| 415 | SPCU->createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie); |
David Blaikie | 5af2aca | 2013-11-18 23:57:26 +0000 | [diff] [blame] | 416 | DIType ATy(Args.getElement(i)); |
Bill Wendling | d9bb9b6 | 2012-11-07 04:42:18 +0000 | [diff] [blame] | 417 | SPCU->addType(Arg, ATy); |
| 418 | if (ATy.isArtificial()) |
| 419 | SPCU->addFlag(Arg, dwarf::DW_AT_artificial); |
| 420 | if (ATy.isObjectPointer()) |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 421 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, Arg); |
Bill Wendling | d9bb9b6 | 2012-11-07 04:42:18 +0000 | [diff] [blame] | 422 | } |
| 423 | DIE *SPDeclDie = SPDie; |
Manman Ren | 4a841a8 | 2013-10-29 01:03:01 +0000 | [diff] [blame] | 424 | SPDie = |
| 425 | SPCU->createAndAddDIE(dwarf::DW_TAG_subprogram, *SPCU->getCUDie()); |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 426 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, SPDeclDie); |
Bill Wendling | d9bb9b6 | 2012-11-07 04:42:18 +0000 | [diff] [blame] | 427 | } |
| 428 | } |
Devang Patel | a37a95e | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 431 | SPCU->addLabelAddress( |
| 432 | SPDie, dwarf::DW_AT_low_pc, |
| 433 | Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber())); |
| 434 | SPCU->addLabelAddress( |
| 435 | SPDie, dwarf::DW_AT_high_pc, |
| 436 | Asm->GetTempSymbol("func_end", Asm->getFunctionNumber())); |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 437 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 438 | MachineLocation Location(RI->getFrameRegister(*Asm->MF)); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 439 | SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location); |
Devang Patel | 6efc8e5 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 440 | |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 441 | // Add name to the name table, we do this here because we're guaranteed |
| 442 | // to have concrete versions of our DW_TAG_subprogram nodes. |
| 443 | addSubprogramNames(SPCU, SP, SPDie); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 444 | |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 445 | return SPDie; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 448 | /// Check whether we should create a DIE for the given Scope, return true |
| 449 | /// if we don't create a DIE (the corresponding DIE is null). |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 450 | bool DwarfDebug::isLexicalScopeDIENull(LexicalScope *Scope) { |
| 451 | if (Scope->isAbstractScope()) |
| 452 | return false; |
| 453 | |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 454 | // We don't create a DIE if there is no Range. |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 455 | const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges(); |
| 456 | if (Ranges.empty()) |
| 457 | return true; |
| 458 | |
| 459 | if (Ranges.size() > 1) |
| 460 | return false; |
| 461 | |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 462 | // We don't create a DIE if we have a single Range and the end label |
| 463 | // is null. |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 464 | SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(); |
| 465 | MCSymbol *End = getLabelAfterInsn(RI->second); |
| 466 | return !End; |
| 467 | } |
| 468 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 469 | // Construct new DW_TAG_lexical_block for this scope and attach |
| 470 | // DW_AT_low_pc/DW_AT_high_pc labels. |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 471 | DIE *DwarfDebug::constructLexicalScopeDIE(CompileUnit *TheCU, |
Devang Patel | d2dfc5e | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 472 | LexicalScope *Scope) { |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 473 | if (isLexicalScopeDIENull(Scope)) |
| 474 | return 0; |
| 475 | |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 476 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block); |
| 477 | if (Scope->isAbstractScope()) |
| 478 | return ScopeDIE; |
| 479 | |
Craig Topper | 977e9cd | 2013-07-03 04:24:43 +0000 | [diff] [blame] | 480 | const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges(); |
Eric Christopher | dc42ea8 | 2013-07-03 01:57:28 +0000 | [diff] [blame] | 481 | // If we have multiple ranges, emit them into the range section. |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 482 | if (Ranges.size() > 1) { |
| 483 | // .debug_range section has not been laid out yet. Emit offset in |
Eric Christopher | 4751d70 | 2013-11-23 00:05:29 +0000 | [diff] [blame] | 484 | // .debug_range as a relocatable label. emitDIE will handle |
| 485 | // emitting it appropriately. |
| 486 | unsigned Offset = DebugRangeSymbols.size(); |
| 487 | TheCU->addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, |
| 488 | Asm->GetTempSymbol("debug_ranges", Offset)); |
Craig Topper | d8e4365 | 2013-07-03 04:17:25 +0000 | [diff] [blame] | 489 | for (SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 490 | RE = Ranges.end(); |
| 491 | RI != RE; ++RI) { |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 492 | DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); |
| 493 | DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second)); |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 494 | } |
Eric Christopher | c111083 | 2013-07-03 01:22:29 +0000 | [diff] [blame] | 495 | |
| 496 | // Terminate the range list. |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 497 | DebugRangeSymbols.push_back(NULL); |
| 498 | DebugRangeSymbols.push_back(NULL); |
| 499 | return ScopeDIE; |
| 500 | } |
| 501 | |
Eric Christopher | dc42ea8 | 2013-07-03 01:57:28 +0000 | [diff] [blame] | 502 | // Construct the address range for this DIE. |
Craig Topper | d8e4365 | 2013-07-03 04:17:25 +0000 | [diff] [blame] | 503 | SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 504 | MCSymbol *Start = getLabelBeforeInsn(RI->first); |
| 505 | MCSymbol *End = getLabelAfterInsn(RI->second); |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 506 | assert(End && "End label should not be null!"); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 507 | |
Chris Lattner | e13c372 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 508 | assert(Start->isDefined() && "Invalid starting label for an inlined scope!"); |
| 509 | assert(End->isDefined() && "Invalid end label for an inlined scope!"); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 510 | |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 511 | TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_low_pc, Start); |
| 512 | TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_high_pc, End); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 513 | |
| 514 | return ScopeDIE; |
| 515 | } |
| 516 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 517 | // This scope represents inlined body of a function. Construct DIE to |
| 518 | // represent this concrete inlined copy of the function. |
Devang Patel | d2dfc5e | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 519 | DIE *DwarfDebug::constructInlinedScopeDIE(CompileUnit *TheCU, |
| 520 | LexicalScope *Scope) { |
Craig Topper | 977e9cd | 2013-07-03 04:24:43 +0000 | [diff] [blame] | 521 | const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges(); |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 522 | assert(Ranges.empty() == false && |
| 523 | "LexicalScope does not have instruction markers!"); |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 524 | |
Devang Patel | f098ce2 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 525 | if (!Scope->getScopeNode()) |
| 526 | return NULL; |
| 527 | DIScope DS(Scope->getScopeNode()); |
| 528 | DISubprogram InlinedSP = getDISubprogram(DS); |
Eric Christopher | e595bae | 2013-10-04 17:08:38 +0000 | [diff] [blame] | 529 | DIE *OriginDIE = TheCU->getDIE(InlinedSP); |
Devang Patel | f098ce2 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 530 | if (!OriginDIE) { |
Bill Wendling | 10e0e2e | 2012-10-30 17:51:02 +0000 | [diff] [blame] | 531 | DEBUG(dbgs() << "Unable to find original DIE for an inlined subprogram."); |
Devang Patel | f098ce2 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 532 | return NULL; |
| 533 | } |
| 534 | |
Devang Patel | 73bc172 | 2011-05-05 17:54:26 +0000 | [diff] [blame] | 535 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine); |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 536 | TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 537 | |
Devang Patel | f098ce2 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 538 | if (Ranges.size() > 1) { |
| 539 | // .debug_range section has not been laid out yet. Emit offset in |
Eric Christopher | 4751d70 | 2013-11-23 00:05:29 +0000 | [diff] [blame] | 540 | // .debug_range as a relocatable label. emitDIE will handle |
| 541 | // emitting it appropriately. |
| 542 | unsigned Offset = DebugRangeSymbols.size(); |
| 543 | TheCU->addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, |
| 544 | Asm->GetTempSymbol("debug_ranges", Offset)); |
Craig Topper | d8e4365 | 2013-07-03 04:17:25 +0000 | [diff] [blame] | 545 | for (SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 546 | RE = Ranges.end(); |
| 547 | RI != RE; ++RI) { |
Devang Patel | f098ce2 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 548 | DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); |
| 549 | DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second)); |
| 550 | } |
| 551 | DebugRangeSymbols.push_back(NULL); |
| 552 | DebugRangeSymbols.push_back(NULL); |
| 553 | } else { |
Craig Topper | d8e4365 | 2013-07-03 04:17:25 +0000 | [diff] [blame] | 554 | SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(); |
Eric Christopher | f94eb2b | 2013-07-03 02:23:53 +0000 | [diff] [blame] | 555 | MCSymbol *StartLabel = getLabelBeforeInsn(RI->first); |
| 556 | MCSymbol *EndLabel = getLabelAfterInsn(RI->second); |
| 557 | |
| 558 | if (StartLabel == 0 || EndLabel == 0) |
| 559 | llvm_unreachable("Unexpected Start and End labels for an inlined scope!"); |
| 560 | |
| 561 | assert(StartLabel->isDefined() && |
| 562 | "Invalid starting label for an inlined scope!"); |
| 563 | assert(EndLabel->isDefined() && "Invalid end label for an inlined scope!"); |
| 564 | |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 565 | TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_low_pc, StartLabel); |
| 566 | TheCU->addLabelAddress(ScopeDIE, dwarf::DW_AT_high_pc, EndLabel); |
Devang Patel | f098ce2 | 2011-07-27 00:34:13 +0000 | [diff] [blame] | 567 | } |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 568 | |
| 569 | InlinedSubprogramDIEs.insert(OriginDIE); |
| 570 | |
Eric Christopher | f94eb2b | 2013-07-03 02:23:53 +0000 | [diff] [blame] | 571 | // Add the call site information to the DIE. |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 572 | DILocation DL(Scope->getInlinedAt()); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 573 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_file, None, |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 574 | getOrCreateSourceID(DL.getFilename(), DL.getDirectory(), |
| 575 | TheCU->getUniqueID())); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 576 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_line, None, DL.getLineNumber()); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 577 | |
Eric Christopher | 8dda5d0 | 2011-12-04 06:02:38 +0000 | [diff] [blame] | 578 | // Add name to the name table, we do this here because we're guaranteed |
| 579 | // to have concrete versions of our DW_TAG_inlined_subprogram nodes. |
| 580 | addSubprogramNames(TheCU, InlinedSP, ScopeDIE); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 581 | |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 582 | return ScopeDIE; |
| 583 | } |
| 584 | |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 585 | DIE *DwarfDebug::createScopeChildrenDIE(CompileUnit *TheCU, LexicalScope *Scope, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 586 | SmallVectorImpl<DIE *> &Children) { |
| 587 | DIE *ObjectPointer = NULL; |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 588 | |
| 589 | // Collect arguments for current function. |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 590 | if (LScopes.isCurrentFunctionScope(Scope)) |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 591 | for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i) |
| 592 | if (DbgVariable *ArgDV = CurrentFnArguments[i]) |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 593 | if (DIE *Arg = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 594 | TheCU->constructVariableDIE(*ArgDV, Scope->isAbstractScope())) { |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 595 | Children.push_back(Arg); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 596 | if (ArgDV->isObjectPointer()) |
| 597 | ObjectPointer = Arg; |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 598 | } |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 599 | |
Eric Christopher | f84354b | 2011-10-03 15:49:16 +0000 | [diff] [blame] | 600 | // Collect lexical scope children first. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 601 | const SmallVectorImpl<DbgVariable *> &Variables = |
| 602 | ScopeVariables.lookup(Scope); |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 603 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 604 | if (DIE *Variable = TheCU->constructVariableDIE(*Variables[i], |
| 605 | Scope->isAbstractScope())) { |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 606 | Children.push_back(Variable); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 607 | if (Variables[i]->isObjectPointer()) |
| 608 | ObjectPointer = Variable; |
Eric Christopher | c1c8a1b | 2012-09-21 22:18:52 +0000 | [diff] [blame] | 609 | } |
Craig Topper | 977e9cd | 2013-07-03 04:24:43 +0000 | [diff] [blame] | 610 | const SmallVectorImpl<LexicalScope *> &Scopes = Scope->getChildren(); |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 611 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 612 | if (DIE *Nested = constructScopeDIE(TheCU, Scopes[j])) |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 613 | Children.push_back(Nested); |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 614 | return ObjectPointer; |
| 615 | } |
| 616 | |
| 617 | // Construct a DIE for this scope. |
| 618 | DIE *DwarfDebug::constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope) { |
| 619 | if (!Scope || !Scope->getScopeNode()) |
| 620 | return NULL; |
| 621 | |
| 622 | DIScope DS(Scope->getScopeNode()); |
| 623 | |
| 624 | SmallVector<DIE *, 8> Children; |
| 625 | DIE *ObjectPointer = NULL; |
| 626 | bool ChildrenCreated = false; |
| 627 | |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 628 | // We try to create the scope DIE first, then the children DIEs. This will |
| 629 | // avoid creating un-used children then removing them later when we find out |
| 630 | // the scope DIE is null. |
Devang Patel | 3b548aa | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 631 | DIE *ScopeDIE = NULL; |
| 632 | if (Scope->getInlinedAt()) |
Devang Patel | d2dfc5e | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 633 | ScopeDIE = constructInlinedScopeDIE(TheCU, Scope); |
Devang Patel | 3b548aa | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 634 | else if (DS.isSubprogram()) { |
Devang Patel | d10b2af | 2010-06-28 20:53:04 +0000 | [diff] [blame] | 635 | ProcessedSPNodes.insert(DS); |
Devang Patel | a37a95e | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 636 | if (Scope->isAbstractScope()) { |
Eric Christopher | e595bae | 2013-10-04 17:08:38 +0000 | [diff] [blame] | 637 | ScopeDIE = TheCU->getDIE(DS); |
Devang Patel | a37a95e | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 638 | // Note down abstract DIE. |
| 639 | if (ScopeDIE) |
| 640 | AbstractSPDies.insert(std::make_pair(DS, ScopeDIE)); |
David Blaikie | e26a377 | 2013-11-18 23:59:04 +0000 | [diff] [blame] | 641 | } else |
David Blaikie | 25bc719 | 2013-11-15 23:13:08 +0000 | [diff] [blame] | 642 | ScopeDIE = updateSubprogramScopeDIE(TheCU, DISubprogram(DS)); |
David Blaikie | e26a377 | 2013-11-18 23:59:04 +0000 | [diff] [blame] | 643 | } else { |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 644 | // Early exit when we know the scope DIE is going to be null. |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 645 | if (isLexicalScopeDIENull(Scope)) |
| 646 | return NULL; |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 647 | |
| 648 | // We create children here when we know the scope DIE is not going to be |
| 649 | // null and the children will be added to the scope DIE. |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 650 | ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children); |
| 651 | ChildrenCreated = true; |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 652 | |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 653 | // There is no need to emit empty lexical block DIE. |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 654 | std::pair<ImportedEntityMap::const_iterator, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 655 | ImportedEntityMap::const_iterator> Range = |
| 656 | std::equal_range( |
| 657 | ScopesWithImportedEntities.begin(), |
| 658 | ScopesWithImportedEntities.end(), |
| 659 | std::pair<const MDNode *, const MDNode *>(DS, (const MDNode *)0), |
| 660 | less_first()); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 661 | if (Children.empty() && Range.first == Range.second) |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 662 | return NULL; |
Devang Patel | d2dfc5e | 2011-08-15 22:24:32 +0000 | [diff] [blame] | 663 | ScopeDIE = constructLexicalScopeDIE(TheCU, Scope); |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 664 | assert(ScopeDIE && "Scope DIE should not be null."); |
Eric Christopher | 5fdd68e | 2013-06-24 23:20:02 +0000 | [diff] [blame] | 665 | for (ImportedEntityMap::const_iterator i = Range.first; i != Range.second; |
| 666 | ++i) |
David Blaikie | 4dd2de7 | 2013-05-08 06:01:38 +0000 | [diff] [blame] | 667 | constructImportedEntityDIE(TheCU, i->second, ScopeDIE); |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 668 | } |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 669 | |
Benjamin Kramer | 892daba | 2013-08-24 11:55:49 +0000 | [diff] [blame] | 670 | if (!ScopeDIE) { |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 671 | assert(Children.empty() && |
| 672 | "We create children only when the scope DIE is not null."); |
Benjamin Kramer | 892daba | 2013-08-24 11:55:49 +0000 | [diff] [blame] | 673 | return NULL; |
| 674 | } |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 675 | if (!ChildrenCreated) |
Manman Ren | 5b2f4b0 | 2013-09-11 19:40:28 +0000 | [diff] [blame] | 676 | // We create children when the scope DIE is not null. |
Manman Ren | 2312ed3 | 2013-09-10 18:40:41 +0000 | [diff] [blame] | 677 | ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 678 | |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 679 | // Add children |
Craig Topper | d8e4365 | 2013-07-03 04:17:25 +0000 | [diff] [blame] | 680 | for (SmallVectorImpl<DIE *>::iterator I = Children.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 681 | E = Children.end(); |
| 682 | I != E; ++I) |
Devang Patel | 5f1b4cd | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 683 | ScopeDIE->addChild(*I); |
Devang Patel | 04d2f2d | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 684 | |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 685 | if (DS.isSubprogram() && ObjectPointer != NULL) |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 686 | TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, ObjectPointer); |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 687 | |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 688 | return ScopeDIE; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 691 | // Look up the source id with the given directory and source file names. |
| 692 | // If none currently exists, create a new id and insert it in the |
| 693 | // SourceIds map. This can update DirectoryNames and SourceFileNames maps |
| 694 | // as well. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 695 | unsigned DwarfDebug::getOrCreateSourceID(StringRef FileName, StringRef DirName, |
| 696 | unsigned CUID) { |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 697 | // If we use .loc in assembly, we can't separate .file entries according to |
| 698 | // compile units. Thus all files will belong to the default compile unit. |
Rafael Espindola | ac4ad25 | 2013-10-05 16:42:21 +0000 | [diff] [blame] | 699 | |
| 700 | // FIXME: add a better feature test than hasRawTextSupport. Even better, |
| 701 | // extend .file to support this. |
| 702 | if (Asm->TM.hasMCUseLoc() && Asm->OutStreamer.hasRawTextSupport()) |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 703 | CUID = 0; |
| 704 | |
Devang Patel | 871d0b1 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 705 | // If FE did not provide a file name, then assume stdin. |
| 706 | if (FileName.empty()) |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 707 | return getOrCreateSourceID("<stdin>", StringRef(), CUID); |
Devang Patel | e01b75c | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 708 | |
Nick Lewycky | d1ee7f8 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 709 | // TODO: this might not belong here. See if we can factor this better. |
| 710 | if (DirName == CompilationDir) |
| 711 | DirName = ""; |
| 712 | |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 713 | // FileIDCUMap stores the current ID for the given compile unit. |
| 714 | unsigned SrcId = FileIDCUMap[CUID] + 1; |
Devang Patel | 871d0b1 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 715 | |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 716 | // We look up the CUID/file/dir by concatenating them with a zero byte. |
Benjamin Kramer | 71b1973 | 2012-03-11 14:56:26 +0000 | [diff] [blame] | 717 | SmallString<128> NamePair; |
Manman Ren | 5b22f9f | 2013-04-06 01:02:38 +0000 | [diff] [blame] | 718 | NamePair += utostr(CUID); |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 719 | NamePair += '\0'; |
Benjamin Kramer | 71b1973 | 2012-03-11 14:56:26 +0000 | [diff] [blame] | 720 | NamePair += DirName; |
| 721 | NamePair += '\0'; // Zero bytes are not allowed in paths. |
| 722 | NamePair += FileName; |
| 723 | |
| 724 | StringMapEntry<unsigned> &Ent = SourceIdMap.GetOrCreateValue(NamePair, SrcId); |
| 725 | if (Ent.getValue() != SrcId) |
| 726 | return Ent.getValue(); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 727 | |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 728 | FileIDCUMap[CUID] = SrcId; |
Rafael Espindola | 67c6ab8 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 729 | // Print out a .file directive to specify files for .loc directives. |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 730 | Asm->OutStreamer.EmitDwarfFileDirective(SrcId, DirName, FileName, CUID); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 731 | |
| 732 | return SrcId; |
| 733 | } |
| 734 | |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 735 | // Create new CompileUnit for the given metadata node with tag |
| 736 | // DW_TAG_compile_unit. |
David Blaikie | 5a15240 | 2013-11-15 23:52:02 +0000 | [diff] [blame] | 737 | CompileUnit *DwarfDebug::constructCompileUnit(DICompileUnit DIUnit) { |
Devang Patel | 2d9caf9 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 738 | StringRef FN = DIUnit.getFilename(); |
Nick Lewycky | d1ee7f8 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 739 | CompilationDir = DIUnit.getDirectory(); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 740 | |
| 741 | DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); |
David Blaikie | 5a15240 | 2013-11-15 23:52:02 +0000 | [diff] [blame] | 742 | CompileUnit *NewCU = new CompileUnit(GlobalCUIndexCount++, Die, DIUnit, Asm, |
| 743 | this, &InfoHolder); |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 744 | |
| 745 | FileIDCUMap[NewCU->getUniqueID()] = 0; |
| 746 | // Call this to emit a .file directive if it wasn't emitted for the source |
| 747 | // file this CU comes from yet. |
| 748 | getOrCreateSourceID(FN, CompilationDir, NewCU->getUniqueID()); |
| 749 | |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 750 | NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer()); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 751 | NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2, |
| 752 | DIUnit.getLanguage()); |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 753 | NewCU->addString(Die, dwarf::DW_AT_name, FN); |
Eric Christopher | 52ce718 | 2013-04-09 19:23:15 +0000 | [diff] [blame] | 754 | |
Eric Christopher | b1b9451 | 2012-08-01 18:19:01 +0000 | [diff] [blame] | 755 | // 2.17.1 requires that we use DW_AT_low_pc for a single entry point |
Eric Christopher | 52ce718 | 2013-04-09 19:23:15 +0000 | [diff] [blame] | 756 | // into an entity. We're using 0 (or a NULL label) for this. For |
| 757 | // split dwarf it's in the skeleton CU so omit it here. |
| 758 | if (!useSplitDwarf()) |
| 759 | NewCU->addLabelAddress(Die, dwarf::DW_AT_low_pc, NULL); |
Manman Ren | 4e042a6 | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 760 | |
| 761 | // Define start line table label for each Compile Unit. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 762 | MCSymbol *LineTableStartSym = |
| 763 | Asm->GetTempSymbol("line_table_start", NewCU->getUniqueID()); |
Manman Ren | 4e042a6 | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 764 | Asm->OutStreamer.getContext().setMCLineTableSymbol(LineTableStartSym, |
| 765 | NewCU->getUniqueID()); |
| 766 | |
Manman Ren | 9d4c735 | 2013-05-21 00:57:22 +0000 | [diff] [blame] | 767 | // Use a single line table if we are using .loc and generating assembly. |
| 768 | bool UseTheFirstCU = |
Rafael Espindola | ac4ad25 | 2013-10-05 16:42:21 +0000 | [diff] [blame] | 769 | (Asm->TM.hasMCUseLoc() && Asm->OutStreamer.hasRawTextSupport()) || |
| 770 | (NewCU->getUniqueID() == 0); |
Manman Ren | 9d4c735 | 2013-05-21 00:57:22 +0000 | [diff] [blame] | 771 | |
Eric Christopher | 52ce718 | 2013-04-09 19:23:15 +0000 | [diff] [blame] | 772 | if (!useSplitDwarf()) { |
Eric Christopher | a51d3fc | 2013-09-27 22:50:48 +0000 | [diff] [blame] | 773 | // DW_AT_stmt_list is a offset of line number information for this |
| 774 | // compile unit in debug_line section. For split dwarf this is |
| 775 | // left in the skeleton CU and so not included. |
| 776 | // The line table entries are not always emitted in assembly, so it |
| 777 | // is not okay to use line_table_start here. |
Eric Christopher | 52ce718 | 2013-04-09 19:23:15 +0000 | [diff] [blame] | 778 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 779 | NewCU->addSectionLabel( |
| 780 | Die, dwarf::DW_AT_stmt_list, |
| 781 | UseTheFirstCU ? Asm->GetTempSymbol("section_line") |
| 782 | : LineTableStartSym); |
Manman Ren | 9d4c735 | 2013-05-21 00:57:22 +0000 | [diff] [blame] | 783 | else if (UseTheFirstCU) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 784 | NewCU->addSectionOffset(Die, dwarf::DW_AT_stmt_list, 0); |
Eric Christopher | 52ce718 | 2013-04-09 19:23:15 +0000 | [diff] [blame] | 785 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 786 | NewCU->addSectionDelta(Die, dwarf::DW_AT_stmt_list, |
| 787 | LineTableStartSym, DwarfLineSectionSym); |
Eric Christopher | a51d3fc | 2013-09-27 22:50:48 +0000 | [diff] [blame] | 788 | |
| 789 | // If we're using split dwarf the compilation dir is going to be in the |
| 790 | // skeleton CU and so we don't need to duplicate it here. |
| 791 | if (!CompilationDir.empty()) |
| 792 | NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir); |
| 793 | |
Eric Christopher | 1d06eb5 | 2013-10-01 00:43:31 +0000 | [diff] [blame] | 794 | // Flags to let the linker know we have emitted new style pubnames. Only |
Eric Christopher | a51d3fc | 2013-09-27 22:50:48 +0000 | [diff] [blame] | 795 | // emit it here if we don't have a skeleton CU for split dwarf. |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 796 | if (GenerateGnuPubSections) { |
| 797 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 798 | NewCU->addSectionLabel( |
| 799 | Die, dwarf::DW_AT_GNU_pubnames, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 800 | Asm->GetTempSymbol("gnu_pubnames", NewCU->getUniqueID())); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 801 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 802 | NewCU->addSectionDelta( |
| 803 | Die, dwarf::DW_AT_GNU_pubnames, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 804 | Asm->GetTempSymbol("gnu_pubnames", NewCU->getUniqueID()), |
| 805 | DwarfGnuPubNamesSectionSym); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 806 | |
| 807 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 808 | NewCU->addSectionLabel( |
| 809 | Die, dwarf::DW_AT_GNU_pubtypes, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 810 | Asm->GetTempSymbol("gnu_pubtypes", NewCU->getUniqueID())); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 811 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 812 | NewCU->addSectionDelta( |
| 813 | Die, dwarf::DW_AT_GNU_pubtypes, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 814 | Asm->GetTempSymbol("gnu_pubtypes", NewCU->getUniqueID()), |
| 815 | DwarfGnuPubTypesSectionSym); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 816 | } |
Eric Christopher | 52ce718 | 2013-04-09 19:23:15 +0000 | [diff] [blame] | 817 | } |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 818 | |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 819 | if (DIUnit.isOptimized()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 820 | NewCU->addFlag(Die, dwarf::DW_AT_APPLE_optimized); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 821 | |
Devang Patel | 2d9caf9 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 822 | StringRef Flags = DIUnit.getFlags(); |
| 823 | if (!Flags.empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 824 | NewCU->addString(Die, dwarf::DW_AT_APPLE_flags, Flags); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 825 | |
Nick Lewycky | 479a8fe | 2011-10-17 23:27:36 +0000 | [diff] [blame] | 826 | if (unsigned RVer = DIUnit.getRunTimeVersion()) |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 827 | NewCU->addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers, |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 828 | dwarf::DW_FORM_data1, RVer); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 829 | |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 830 | if (!FirstCU) |
| 831 | FirstCU = NewCU; |
Eric Christopher | 7a2cdf7 | 2013-02-05 07:31:55 +0000 | [diff] [blame] | 832 | |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 833 | InfoHolder.addUnit(NewCU); |
| 834 | |
David Blaikie | 5a15240 | 2013-11-15 23:52:02 +0000 | [diff] [blame] | 835 | CUMap.insert(std::make_pair(DIUnit, NewCU)); |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 836 | CUDieMap.insert(std::make_pair(Die, NewCU)); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 837 | return NewCU; |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 840 | // Construct subprogram DIE. |
Eric Christopher | a6c38a3 | 2013-10-15 23:31:38 +0000 | [diff] [blame] | 841 | void DwarfDebug::constructSubprogramDIE(CompileUnit *TheCU, const MDNode *N) { |
Eric Christopher | ffbc4de | 2013-10-18 01:57:30 +0000 | [diff] [blame] | 842 | // FIXME: We should only call this routine once, however, during LTO if a |
| 843 | // program is defined in multiple CUs we could end up calling it out of |
| 844 | // beginModule as we walk the CUs. |
| 845 | |
| 846 | CompileUnit *&CURef = SPMap[N]; |
| 847 | if (CURef) |
| 848 | return; |
| 849 | CURef = TheCU; |
Rafael Espindola | 6cf4e83 | 2011-11-04 19:00:29 +0000 | [diff] [blame] | 850 | |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 851 | DISubprogram SP(N); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 852 | if (!SP.isDefinition()) |
| 853 | // This is a method declaration which will be handled while constructing |
| 854 | // class type. |
Devang Patel | 0751a28 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 855 | return; |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 856 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 857 | DIE *SubprogramDie = TheCU->getOrCreateSubprogramDIE(SP); |
Stuart Hastings | 4bd3dd9 | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 858 | |
Eric Christopher | ba506db | 2013-09-09 20:03:20 +0000 | [diff] [blame] | 859 | // Expose as a global name. |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 860 | TheCU->addGlobalName(SP.getName(), SubprogramDie, resolve(SP.getContext())); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 861 | } |
| 862 | |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 863 | void DwarfDebug::constructImportedEntityDIE(CompileUnit *TheCU, |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 864 | const MDNode *N) { |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 865 | DIImportedEntity Module(N); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 866 | if (!Module.Verify()) |
| 867 | return; |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 868 | if (DIE *D = TheCU->getOrCreateContextDIE(Module.getContext())) |
David Blaikie | 4dd2de7 | 2013-05-08 06:01:38 +0000 | [diff] [blame] | 869 | constructImportedEntityDIE(TheCU, Module, D); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 870 | } |
| 871 | |
David Blaikie | 4dd2de7 | 2013-05-08 06:01:38 +0000 | [diff] [blame] | 872 | void DwarfDebug::constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N, |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 873 | DIE *Context) { |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 874 | DIImportedEntity Module(N); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 875 | if (!Module.Verify()) |
| 876 | return; |
David Blaikie | 4dd2de7 | 2013-05-08 06:01:38 +0000 | [diff] [blame] | 877 | return constructImportedEntityDIE(TheCU, Module, Context); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 878 | } |
| 879 | |
David Blaikie | 4dd2de7 | 2013-05-08 06:01:38 +0000 | [diff] [blame] | 880 | void DwarfDebug::constructImportedEntityDIE(CompileUnit *TheCU, |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 881 | const DIImportedEntity &Module, |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 882 | DIE *Context) { |
| 883 | assert(Module.Verify() && |
| 884 | "Use one of the MDNode * overloads to handle invalid metadata"); |
| 885 | assert(Context && "Should always have a context for an imported_module"); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 886 | DIE *IMDie = new DIE(Module.getTag()); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 887 | TheCU->insertDIE(Module, IMDie); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 888 | DIE *EntityDie; |
| 889 | DIDescriptor Entity = Module.getEntity(); |
| 890 | if (Entity.isNameSpace()) |
| 891 | EntityDie = TheCU->getOrCreateNameSpace(DINameSpace(Entity)); |
| 892 | else if (Entity.isSubprogram()) |
| 893 | EntityDie = TheCU->getOrCreateSubprogramDIE(DISubprogram(Entity)); |
David Blaikie | 3b6038b | 2013-05-08 06:01:41 +0000 | [diff] [blame] | 894 | else if (Entity.isType()) |
| 895 | EntityDie = TheCU->getOrCreateTypeDIE(DIType(Entity)); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 896 | else |
David Blaikie | 3b6038b | 2013-05-08 06:01:41 +0000 | [diff] [blame] | 897 | EntityDie = TheCU->getDIE(Entity); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 898 | unsigned FileID = getOrCreateSourceID(Module.getContext().getFilename(), |
| 899 | Module.getContext().getDirectory(), |
| 900 | TheCU->getUniqueID()); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 901 | TheCU->addUInt(IMDie, dwarf::DW_AT_decl_file, None, FileID); |
| 902 | TheCU->addUInt(IMDie, dwarf::DW_AT_decl_line, None, Module.getLineNumber()); |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 903 | TheCU->addDIEEntry(IMDie, dwarf::DW_AT_import, EntityDie); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 904 | StringRef Name = Module.getName(); |
| 905 | if (!Name.empty()) |
| 906 | TheCU->addString(IMDie, dwarf::DW_AT_name, Name); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 907 | Context->addChild(IMDie); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 910 | // Emit all Dwarf sections that should come prior to the content. Create |
| 911 | // global DIEs and emit initial debug info sections. This is invoked by |
| 912 | // the target AsmPrinter. |
Eric Christopher | 58f4195 | 2012-11-19 22:42:15 +0000 | [diff] [blame] | 913 | void DwarfDebug::beginModule() { |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 914 | if (DisableDebugInfoPrinting) |
| 915 | return; |
| 916 | |
Eric Christopher | 58f4195 | 2012-11-19 22:42:15 +0000 | [diff] [blame] | 917 | const Module *M = MMI->getModule(); |
| 918 | |
Nick Lewycky | 019d255 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 919 | // If module has named metadata anchors then use them, otherwise scan the |
| 920 | // module using debug info finder to collect debug info. |
Devang Patel | e02e585 | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 921 | NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu"); |
David Blaikie | dc69ebb | 2013-03-11 23:39:23 +0000 | [diff] [blame] | 922 | if (!CU_Nodes) |
Devang Patel | 07bb9ee | 2011-08-15 23:47:24 +0000 | [diff] [blame] | 923 | return; |
Manman Ren | 6035203 | 2013-09-05 18:48:31 +0000 | [diff] [blame] | 924 | TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); |
Devang Patel | e02e585 | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 925 | |
David Blaikie | dc69ebb | 2013-03-11 23:39:23 +0000 | [diff] [blame] | 926 | // Emit initial sections so we can reference labels later. |
| 927 | emitSectionLabels(); |
| 928 | |
| 929 | for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { |
| 930 | DICompileUnit CUNode(CU_Nodes->getOperand(i)); |
| 931 | CompileUnit *CU = constructCompileUnit(CUNode); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 932 | DIArray ImportedEntities = CUNode.getImportedEntities(); |
| 933 | for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i) |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 934 | ScopesWithImportedEntities.push_back(std::make_pair( |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 935 | DIImportedEntity(ImportedEntities.getElement(i)).getContext(), |
| 936 | ImportedEntities.getElement(i))); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 937 | std::sort(ScopesWithImportedEntities.begin(), |
Benjamin Kramer | b12cf01 | 2013-08-24 12:54:27 +0000 | [diff] [blame] | 938 | ScopesWithImportedEntities.end(), less_first()); |
David Blaikie | dc69ebb | 2013-03-11 23:39:23 +0000 | [diff] [blame] | 939 | DIArray GVs = CUNode.getGlobalVariables(); |
| 940 | for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) |
David Blaikie | a781b25b | 2013-11-17 21:55:13 +0000 | [diff] [blame] | 941 | CU->createGlobalVariableDIE(DIGlobalVariable(GVs.getElement(i))); |
David Blaikie | dc69ebb | 2013-03-11 23:39:23 +0000 | [diff] [blame] | 942 | DIArray SPs = CUNode.getSubprograms(); |
| 943 | for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) |
| 944 | constructSubprogramDIE(CU, SPs.getElement(i)); |
| 945 | DIArray EnumTypes = CUNode.getEnumTypes(); |
| 946 | for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) |
| 947 | CU->getOrCreateTypeDIE(EnumTypes.getElement(i)); |
| 948 | DIArray RetainedTypes = CUNode.getRetainedTypes(); |
| 949 | for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) |
| 950 | CU->getOrCreateTypeDIE(RetainedTypes.getElement(i)); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 951 | // Emit imported_modules last so that the relevant context is already |
| 952 | // available. |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 953 | for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i) |
| 954 | constructImportedEntityDIE(CU, ImportedEntities.getElement(i)); |
David Blaikie | dc69ebb | 2013-03-11 23:39:23 +0000 | [diff] [blame] | 955 | } |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 956 | |
Chris Lattner | 7cfa70e | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 957 | // Tell MMI that we have debug info. |
| 958 | MMI->setDebugInfoAvailability(true); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 959 | |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 960 | // Prime section data. |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 961 | SectionMap[Asm->getObjFileLowering().getTextSection()]; |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 964 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 965 | void DwarfDebug::computeInlinedDIEs() { |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 966 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 967 | for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 968 | AE = InlinedSubprogramDIEs.end(); |
| 969 | AI != AE; ++AI) { |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 970 | DIE *ISP = *AI; |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 971 | FirstCU->addUInt(ISP, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 972 | } |
Rafael Espindola | e7cc8bf | 2011-11-12 01:57:54 +0000 | [diff] [blame] | 973 | for (DenseMap<const MDNode *, DIE *>::iterator AI = AbstractSPDies.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 974 | AE = AbstractSPDies.end(); |
| 975 | AI != AE; ++AI) { |
Rafael Espindola | e7cc8bf | 2011-11-12 01:57:54 +0000 | [diff] [blame] | 976 | DIE *ISP = AI->second; |
| 977 | if (InlinedSubprogramDIEs.count(ISP)) |
| 978 | continue; |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 979 | FirstCU->addUInt(ISP, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined); |
Rafael Espindola | e7cc8bf | 2011-11-12 01:57:54 +0000 | [diff] [blame] | 980 | } |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | // Collect info for variables that were optimized out. |
| 984 | void DwarfDebug::collectDeadVariables() { |
| 985 | const Module *M = MMI->getModule(); |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 986 | |
| 987 | if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) { |
| 988 | for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { |
| 989 | DICompileUnit TheCU(CU_Nodes->getOperand(i)); |
| 990 | DIArray Subprograms = TheCU.getSubprograms(); |
| 991 | for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) { |
Eric Christopher | 735401c | 2012-11-27 00:13:51 +0000 | [diff] [blame] | 992 | DISubprogram SP(Subprograms.getElement(i)); |
Eric Christopher | a6c38a3 | 2013-10-15 23:31:38 +0000 | [diff] [blame] | 993 | if (ProcessedSPNodes.count(SP) != 0) |
| 994 | continue; |
| 995 | if (!SP.isSubprogram()) |
| 996 | continue; |
| 997 | if (!SP.isDefinition()) |
| 998 | continue; |
Eric Christopher | 735401c | 2012-11-27 00:13:51 +0000 | [diff] [blame] | 999 | DIArray Variables = SP.getVariables(); |
Eric Christopher | a6c38a3 | 2013-10-15 23:31:38 +0000 | [diff] [blame] | 1000 | if (Variables.getNumElements() == 0) |
| 1001 | continue; |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1002 | |
Eric Christopher | 735401c | 2012-11-27 00:13:51 +0000 | [diff] [blame] | 1003 | // Construct subprogram DIE and add variables DIEs. |
| 1004 | CompileUnit *SPCU = CUMap.lookup(TheCU); |
| 1005 | assert(SPCU && "Unable to find Compile Unit!"); |
Eric Christopher | c798d8a | 2013-10-22 00:22:39 +0000 | [diff] [blame] | 1006 | // FIXME: See the comment in constructSubprogramDIE about duplicate |
| 1007 | // subprogram DIEs. |
| 1008 | constructSubprogramDIE(SPCU, SP); |
| 1009 | DIE *SPDIE = SPCU->getDIE(SP); |
Eric Christopher | 735401c | 2012-11-27 00:13:51 +0000 | [diff] [blame] | 1010 | for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) { |
| 1011 | DIVariable DV(Variables.getElement(vi)); |
Eric Christopher | a6c38a3 | 2013-10-15 23:31:38 +0000 | [diff] [blame] | 1012 | if (!DV.isVariable()) |
| 1013 | continue; |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1014 | DbgVariable NewVar(DV, NULL, this); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1015 | if (DIE *VariableDIE = SPCU->constructVariableDIE(NewVar, false)) |
Eric Christopher | a6c38a3 | 2013-10-15 23:31:38 +0000 | [diff] [blame] | 1016 | SPDIE->addChild(VariableDIE); |
Eric Christopher | 735401c | 2012-11-27 00:13:51 +0000 | [diff] [blame] | 1017 | } |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | } |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 1023 | // Type Signature [7.27] and ODR Hash code. |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 1024 | |
| 1025 | /// \brief Grabs the string in whichever attribute is passed in and returns |
Eric Christopher | 8552e22 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 1026 | /// a reference to it. Returns "" if the attribute doesn't exist. |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 1027 | static StringRef getDIEStringAttr(DIE *Die, unsigned Attr) { |
Eric Christopher | 8552e22 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 1028 | DIEValue *V = Die->findAttribute(Attr); |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 1029 | |
Eric Christopher | 8552e22 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 1030 | if (DIEString *S = dyn_cast_or_null<DIEString>(V)) |
| 1031 | return S->getString(); |
| 1032 | |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 1033 | return StringRef(""); |
| 1034 | } |
| 1035 | |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 1036 | /// Return true if the current DIE is contained within an anonymous namespace. |
| 1037 | static bool isContainedInAnonNamespace(DIE *Die) { |
| 1038 | DIE *Parent = Die->getParent(); |
| 1039 | |
| 1040 | while (Parent) { |
Eric Christopher | e414ece | 2013-07-29 23:53:08 +0000 | [diff] [blame] | 1041 | if (Parent->getTag() == dwarf::DW_TAG_namespace && |
| 1042 | getDIEStringAttr(Parent, dwarf::DW_AT_name) == "") |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 1043 | return true; |
| 1044 | Parent = Parent->getParent(); |
| 1045 | } |
| 1046 | |
| 1047 | return false; |
| 1048 | } |
| 1049 | |
Eric Christopher | af15f8d | 2013-08-07 01:18:24 +0000 | [diff] [blame] | 1050 | /// Test if the current CU language is C++ and that we have |
| 1051 | /// a named type that is not contained in an anonymous namespace. |
| 1052 | static bool shouldAddODRHash(CompileUnit *CU, DIE *Die) { |
Eric Christopher | 341770d | 2013-08-07 08:35:10 +0000 | [diff] [blame] | 1053 | return CU->getLanguage() == dwarf::DW_LANG_C_plus_plus && |
| 1054 | getDIEStringAttr(Die, dwarf::DW_AT_name) != "" && |
| 1055 | !isContainedInAnonNamespace(Die); |
Eric Christopher | 4573198 | 2013-08-08 23:45:55 +0000 | [diff] [blame] | 1056 | } |
Eric Christopher | af15f8d | 2013-08-07 01:18:24 +0000 | [diff] [blame] | 1057 | |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1058 | void DwarfDebug::finalizeModuleInfo() { |
| 1059 | // Collect info for variables that were optimized out. |
| 1060 | collectDeadVariables(); |
| 1061 | |
| 1062 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 1063 | computeInlinedDIEs(); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1064 | |
Eric Christopher | 60eb769 | 2013-08-12 20:27:48 +0000 | [diff] [blame] | 1065 | // Handle anything that needs to be done on a per-cu basis. |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 1066 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 1067 | E = getUnits().end(); |
| 1068 | I != E; ++I) { |
| 1069 | CompileUnit *TheCU = *I; |
Eric Christopher | 60eb769 | 2013-08-12 20:27:48 +0000 | [diff] [blame] | 1070 | // Emit DW_AT_containing_type attribute to connect types with their |
| 1071 | // vtable holding type. |
| 1072 | TheCU->constructContainingTypeDIEs(); |
| 1073 | |
| 1074 | // If we're splitting the dwarf out now that we've got the entire |
| 1075 | // CU then construct a skeleton CU based upon it. |
| 1076 | if (useSplitDwarf()) { |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 1077 | uint64_t ID = 0; |
| 1078 | if (GenerateCUHash) { |
| 1079 | DIEHash CUHash; |
David Blaikie | 2aee7be | 2013-10-24 18:29:03 +0000 | [diff] [blame] | 1080 | ID = CUHash.computeCUSignature(*TheCU->getCUDie()); |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 1081 | } |
Eric Christopher | 60eb769 | 2013-08-12 20:27:48 +0000 | [diff] [blame] | 1082 | // This should be a unique identifier when we want to build .dwp files. |
| 1083 | TheCU->addUInt(TheCU->getCUDie(), dwarf::DW_AT_GNU_dwo_id, |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 1084 | dwarf::DW_FORM_data8, ID); |
Eric Christopher | 60eb769 | 2013-08-12 20:27:48 +0000 | [diff] [blame] | 1085 | // Now construct the skeleton CU associated. |
Eric Christopher | 6fdf324 | 2013-08-26 23:50:43 +0000 | [diff] [blame] | 1086 | CompileUnit *SkCU = constructSkeletonCU(TheCU); |
Eric Christopher | 60eb769 | 2013-08-12 20:27:48 +0000 | [diff] [blame] | 1087 | // This should be a unique identifier when we want to build .dwp files. |
| 1088 | SkCU->addUInt(SkCU->getCUDie(), dwarf::DW_AT_GNU_dwo_id, |
Eric Christopher | d29614f | 2013-08-13 01:21:55 +0000 | [diff] [blame] | 1089 | dwarf::DW_FORM_data8, ID); |
Eric Christopher | 60eb769 | 2013-08-12 20:27:48 +0000 | [diff] [blame] | 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | // Compute DIE offsets and sizes. |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 1094 | InfoHolder.computeSizeAndOffsets(); |
| 1095 | if (useSplitDwarf()) |
| 1096 | SkeletonHolder.computeSizeAndOffsets(); |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | void DwarfDebug::endSections() { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1100 | // Filter labels by section. |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 1101 | for (size_t n = 0; n < ArangeLabels.size(); n++) { |
| 1102 | const SymbolCU &SCU = ArangeLabels[n]; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 1103 | if (SCU.Sym->isInSection()) { |
| 1104 | // Make a note of this symbol and it's section. |
| 1105 | const MCSection *Section = &SCU.Sym->getSection(); |
| 1106 | if (!Section->getKind().isMetadata()) |
| 1107 | SectionMap[Section].push_back(SCU); |
| 1108 | } else { |
| 1109 | // Some symbols (e.g. common/bss on mach-o) can have no section but still |
| 1110 | // appear in the output. This sucks as we rely on sections to build |
| 1111 | // arange spans. We can do it without, but it's icky. |
| 1112 | SectionMap[NULL].push_back(SCU); |
| 1113 | } |
| 1114 | } |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1115 | |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 1116 | // Build a list of sections used. |
| 1117 | std::vector<const MCSection *> Sections; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 1118 | for (SectionMapType::iterator it = SectionMap.begin(); it != SectionMap.end(); |
| 1119 | it++) { |
| 1120 | const MCSection *Section = it->first; |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 1121 | Sections.push_back(Section); |
| 1122 | } |
| 1123 | |
| 1124 | // Sort the sections into order. |
| 1125 | // This is only done to ensure consistent output order across different runs. |
| 1126 | std::sort(Sections.begin(), Sections.end(), SectionSort); |
| 1127 | |
| 1128 | // Add terminating symbols for each section. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1129 | for (unsigned ID = 0; ID < Sections.size(); ID++) { |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 1130 | const MCSection *Section = Sections[ID]; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 1131 | MCSymbol *Sym = NULL; |
| 1132 | |
| 1133 | if (Section) { |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 1134 | // We can't call MCSection::getLabelEndName, as it's only safe to do so |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1135 | // if we know the section name up-front. For user-created sections, the |
| 1136 | // resulting |
| 1137 | // label may not be valid to use as a label. (section names can use a |
| 1138 | // greater |
Richard Mitton | c250824 | 2013-10-03 22:07:08 +0000 | [diff] [blame] | 1139 | // set of characters on some systems) |
| 1140 | Sym = Asm->GetTempSymbol("debug_end", ID); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 1141 | Asm->OutStreamer.SwitchSection(Section); |
| 1142 | Asm->OutStreamer.EmitLabel(Sym); |
| 1143 | } |
| 1144 | |
| 1145 | // Insert a final terminator. |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 1146 | SectionMap[Section].push_back(SymbolCU(NULL, Sym)); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1147 | } |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1148 | } |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1149 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1150 | // Emit all Dwarf sections that should come after the content. |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1151 | void DwarfDebug::endModule() { |
| 1152 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1153 | if (!FirstCU) |
| 1154 | return; |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 1155 | |
| 1156 | // End any existing sections. |
| 1157 | // TODO: Does this need to happen? |
| 1158 | endSections(); |
| 1159 | |
| 1160 | // Finalize the debug info for the module. |
| 1161 | finalizeModuleInfo(); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1162 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1163 | emitDebugStr(); |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1164 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1165 | // Emit all the DIEs into a debug info section. |
| 1166 | emitDebugInfo(); |
Eric Christopher | 4c9b119 | 2012-11-27 00:41:54 +0000 | [diff] [blame] | 1167 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1168 | // Corresponding abbreviations into a abbrev section. |
| 1169 | emitAbbreviations(); |
Eric Christopher | 95198f50 | 2012-11-27 22:43:42 +0000 | [diff] [blame] | 1170 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1171 | // Emit info into a debug loc section. |
| 1172 | emitDebugLoc(); |
Eric Christopher | 95198f50 | 2012-11-27 22:43:42 +0000 | [diff] [blame] | 1173 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1174 | // Emit info into a debug aranges section. |
| 1175 | emitDebugARanges(); |
Eric Christopher | 95198f50 | 2012-11-27 22:43:42 +0000 | [diff] [blame] | 1176 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1177 | // Emit info into a debug ranges section. |
| 1178 | emitDebugRanges(); |
Eric Christopher | 95198f50 | 2012-11-27 22:43:42 +0000 | [diff] [blame] | 1179 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1180 | // Emit info into a debug macinfo section. |
| 1181 | emitDebugMacInfo(); |
Eric Christopher | 95198f50 | 2012-11-27 22:43:42 +0000 | [diff] [blame] | 1182 | |
Eric Christopher | 9a8f5ed | 2013-11-19 09:04:50 +0000 | [diff] [blame] | 1183 | if (useSplitDwarf()) { |
| 1184 | emitDebugStrDWO(); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 1185 | emitDebugInfoDWO(); |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 1186 | emitDebugAbbrevDWO(); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 1187 | // Emit DWO addresses. |
| 1188 | InfoHolder.emitAddresses(Asm->getObjFileLowering().getDwarfAddrSection()); |
Eric Christopher | 95198f50 | 2012-11-27 22:43:42 +0000 | [diff] [blame] | 1189 | } |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1190 | |
Eric Christopher | a876b82 | 2012-08-23 07:32:06 +0000 | [diff] [blame] | 1191 | // Emit info into the dwarf accelerator table sections. |
Eric Christopher | 20b76a7 | 2012-08-23 22:36:40 +0000 | [diff] [blame] | 1192 | if (useDwarfAccelTables()) { |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1193 | emitAccelNames(); |
| 1194 | emitAccelObjC(); |
| 1195 | emitAccelNamespaces(); |
| 1196 | emitAccelTypes(); |
| 1197 | } |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1198 | |
Eric Christopher | 4b35818 | 2013-08-30 00:40:17 +0000 | [diff] [blame] | 1199 | // Emit the pubnames and pubtypes sections if requested. |
| 1200 | if (HasDwarfPubSections) { |
David Blaikie | 70a3320 | 2013-09-19 17:33:35 +0000 | [diff] [blame] | 1201 | emitDebugPubNames(GenerateGnuPubSections); |
| 1202 | emitDebugPubTypes(GenerateGnuPubSections); |
Eric Christopher | 4b35818 | 2013-08-30 00:40:17 +0000 | [diff] [blame] | 1203 | } |
Devang Patel | 04d2f2d | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1204 | |
Devang Patel | d070128 | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 1205 | // clean up. |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1206 | SPMap.clear(); |
Eric Christopher | 8afd7b6 | 2012-12-10 19:51:18 +0000 | [diff] [blame] | 1207 | |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 1208 | // Reset these for the next Module if we have one. |
| 1209 | FirstCU = NULL; |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1212 | // Find abstract variable, if any, associated with Var. |
Devang Patel | bb23a4a | 2011-08-10 21:50:54 +0000 | [diff] [blame] | 1213 | DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV, |
Chris Lattner | 915c5f9 | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1214 | DebugLoc ScopeLoc) { |
Devang Patel | bb23a4a | 2011-08-10 21:50:54 +0000 | [diff] [blame] | 1215 | LLVMContext &Ctx = DV->getContext(); |
| 1216 | // More then one inlined variable corresponds to one abstract variable. |
| 1217 | DIVariable Var = cleanseInlinedVariable(DV, Ctx); |
Devang Patel | cfa8e9d | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1218 | DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1219 | if (AbsDbgVariable) |
| 1220 | return AbsDbgVariable; |
| 1221 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1222 | LexicalScope *Scope = LScopes.findAbstractScope(ScopeLoc.getScope(Ctx)); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1223 | if (!Scope) |
| 1224 | return NULL; |
| 1225 | |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1226 | AbsDbgVariable = new DbgVariable(Var, NULL, this); |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1227 | addScopeVariable(Scope, AbsDbgVariable); |
Devang Patel | cfa8e9d | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1228 | AbstractVariables[Var] = AbsDbgVariable; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1229 | return AbsDbgVariable; |
| 1230 | } |
| 1231 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1232 | // If Var is a current function argument then add it to CurrentFnArguments list. |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1233 | bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF, |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1234 | DbgVariable *Var, LexicalScope *Scope) { |
| 1235 | if (!LScopes.isCurrentFunctionScope(Scope)) |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1236 | return false; |
| 1237 | DIVariable DV = Var->getVariable(); |
| 1238 | if (DV.getTag() != dwarf::DW_TAG_arg_variable) |
| 1239 | return false; |
| 1240 | unsigned ArgNo = DV.getArgNumber(); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1241 | if (ArgNo == 0) |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1242 | return false; |
| 1243 | |
Devang Patel | 4ab660b | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 1244 | size_t Size = CurrentFnArguments.size(); |
| 1245 | if (Size == 0) |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1246 | CurrentFnArguments.resize(MF->getFunction()->arg_size()); |
Devang Patel | 63b3e76 | 2011-03-03 21:49:41 +0000 | [diff] [blame] | 1247 | // llvm::Function argument size is not good indicator of how many |
Devang Patel | 34a7ab4 | 2011-03-03 20:08:10 +0000 | [diff] [blame] | 1248 | // arguments does the function have at source level. |
| 1249 | if (ArgNo > Size) |
Devang Patel | 4ab660b | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 1250 | CurrentFnArguments.resize(ArgNo * 2); |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1251 | CurrentFnArguments[ArgNo - 1] = Var; |
| 1252 | return true; |
| 1253 | } |
| 1254 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1255 | // Collect variable information from side table maintained by MMI. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1256 | void DwarfDebug::collectVariableInfoFromMMITable( |
| 1257 | const MachineFunction *MF, SmallPtrSet<const MDNode *, 16> &Processed) { |
Devang Patel | 475d32a | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1258 | MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo(); |
| 1259 | for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1260 | VE = VMap.end(); |
| 1261 | VI != VE; ++VI) { |
Devang Patel | 32cc43c | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1262 | const MDNode *Var = VI->first; |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1263 | if (!Var) |
| 1264 | continue; |
Devang Patel | e0a94bf | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1265 | Processed.insert(Var); |
Chris Lattner | 915c5f9 | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1266 | DIVariable DV(Var); |
| 1267 | const std::pair<unsigned, DebugLoc> &VP = VI->second; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1268 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1269 | LexicalScope *Scope = LScopes.findLexicalScope(VP.second); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1270 | |
Devang Patel | cdb7d44 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 1271 | // If variable scope is not found then skip this variable. |
Chris Lattner | 915c5f9 | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1272 | if (Scope == 0) |
Devang Patel | cdb7d44 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 1273 | continue; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1274 | |
Devang Patel | e1c53f2 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1275 | DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second); |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1276 | DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this); |
Devang Patel | 3e4a965 | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 1277 | RegVar->setFrameIndex(VP.first); |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1278 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1279 | addScopeVariable(Scope, RegVar); |
Devang Patel | 99819b5 | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 1280 | if (AbsDbgVariable) |
Devang Patel | 3e4a965 | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 1281 | AbsDbgVariable->setFrameIndex(VP.first); |
Devang Patel | 475d32a | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1282 | } |
Devang Patel | 490c8ab | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1283 | } |
Devang Patel | a3e9c9c | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 1284 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1285 | // Return true if debug value, encoded by DBG_VALUE instruction, is in a |
| 1286 | // defined reg. |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1287 | static bool isDbgValueInDefinedReg(const MachineInstr *MI) { |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1288 | assert(MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!"); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1289 | return MI->getNumOperands() == 3 && MI->getOperand(0).isReg() && |
| 1290 | MI->getOperand(0).getReg() && |
Adrian Prantl | 418d1d1 | 2013-07-09 20:28:37 +0000 | [diff] [blame] | 1291 | (MI->getOperand(1).isImm() || |
| 1292 | (MI->getOperand(1).isReg() && MI->getOperand(1).getReg() == 0U)); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1295 | // Get .debug_loc entry for the instruction range starting at MI. |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1296 | static DotDebugLocEntry getDebugLocEntry(AsmPrinter *Asm, |
| 1297 | const MCSymbol *FLabel, |
Devang Patel | 2442a89 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 1298 | const MCSymbol *SLabel, |
| 1299 | const MachineInstr *MI) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1300 | const MDNode *Var = MI->getOperand(MI->getNumOperands() - 1).getMetadata(); |
Devang Patel | 2442a89 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 1301 | |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1302 | assert(MI->getNumOperands() == 3); |
Adrian Prantl | 418d1d1 | 2013-07-09 20:28:37 +0000 | [diff] [blame] | 1303 | if (MI->getOperand(0).isReg()) { |
Devang Patel | 2442a89 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 1304 | MachineLocation MLoc; |
Adrian Prantl | 418d1d1 | 2013-07-09 20:28:37 +0000 | [diff] [blame] | 1305 | // If the second operand is an immediate, this is a |
| 1306 | // register-indirect address. |
| 1307 | if (!MI->getOperand(1).isImm()) |
Adrian Prantl | d4c0dd4 | 2013-04-26 21:57:17 +0000 | [diff] [blame] | 1308 | MLoc.set(MI->getOperand(0).getReg()); |
| 1309 | else |
| 1310 | MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm()); |
Devang Patel | 2442a89 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 1311 | return DotDebugLocEntry(FLabel, SLabel, MLoc, Var); |
| 1312 | } |
| 1313 | if (MI->getOperand(0).isImm()) |
| 1314 | return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getImm()); |
| 1315 | if (MI->getOperand(0).isFPImm()) |
| 1316 | return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getFPImm()); |
| 1317 | if (MI->getOperand(0).isCImm()) |
| 1318 | return DotDebugLocEntry(FLabel, SLabel, MI->getOperand(0).getCImm()); |
| 1319 | |
Craig Topper | ee4dab5 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 1320 | llvm_unreachable("Unexpected 3 operand DBG_VALUE instruction!"); |
Devang Patel | 2442a89 | 2011-07-08 17:09:57 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1323 | // Find variables for each lexical scope. |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1324 | void |
Devang Patel | 5c0f85c | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 1325 | DwarfDebug::collectVariableInfo(const MachineFunction *MF, |
| 1326 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1327 | |
Eric Christopher | 270a12c | 2013-07-03 21:37:03 +0000 | [diff] [blame] | 1328 | // Grab the variable info that was squirreled away in the MMI side-table. |
Devang Patel | 490c8ab | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1329 | collectVariableInfoFromMMITable(MF, Processed); |
| 1330 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1331 | for (SmallVectorImpl<const MDNode *>::const_iterator |
| 1332 | UVI = UserVariables.begin(), |
| 1333 | UVE = UserVariables.end(); |
| 1334 | UVI != UVE; ++UVI) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1335 | const MDNode *Var = *UVI; |
| 1336 | if (Processed.count(Var)) |
Devang Patel | 490c8ab | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1337 | continue; |
| 1338 | |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1339 | // History contains relevant DBG_VALUE instructions for Var and instructions |
| 1340 | // clobbering it. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1341 | SmallVectorImpl<const MachineInstr *> &History = DbgValues[Var]; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1342 | if (History.empty()) |
| 1343 | continue; |
| 1344 | const MachineInstr *MInsn = History.front(); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1345 | |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1346 | DIVariable DV(Var); |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1347 | LexicalScope *Scope = NULL; |
Devang Patel | 7a9dedf | 2010-05-27 20:25:04 +0000 | [diff] [blame] | 1348 | if (DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 1349 | DISubprogram(DV.getContext()).describes(MF->getFunction())) |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1350 | Scope = LScopes.getCurrentFunctionScope(); |
David Blaikie | dc69ebb | 2013-03-11 23:39:23 +0000 | [diff] [blame] | 1351 | else if (MDNode *IA = DV.getInlinedAt()) |
| 1352 | Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA)); |
| 1353 | else |
| 1354 | Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1))); |
Devang Patel | 490c8ab | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1355 | // If variable scope is not found then skip this variable. |
Devang Patel | fbd6c45 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 1356 | if (!Scope) |
Devang Patel | 490c8ab | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1357 | continue; |
| 1358 | |
| 1359 | Processed.insert(DV); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1360 | assert(MInsn->isDebugValue() && "History must begin with debug value"); |
Devang Patel | 99819b5 | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 1361 | DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc()); |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1362 | DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this); |
Devang Patel | 6c622ef | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1363 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1364 | addScopeVariable(Scope, RegVar); |
Devang Patel | 99819b5 | 2011-08-15 19:01:20 +0000 | [diff] [blame] | 1365 | if (AbsVar) |
Devang Patel | 3e4a965 | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 1366 | AbsVar->setMInsn(MInsn); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1367 | |
Eric Christopher | cc10d20 | 2012-10-08 20:48:54 +0000 | [diff] [blame] | 1368 | // Simplify ranges that are fully coalesced. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1369 | if (History.size() <= 1 || |
| 1370 | (History.size() == 2 && MInsn->isIdenticalTo(History.back()))) { |
Devang Patel | 3e4a965 | 2011-08-15 21:24:36 +0000 | [diff] [blame] | 1371 | RegVar->setMInsn(MInsn); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1372 | continue; |
| 1373 | } |
| 1374 | |
Eric Christopher | 59cc071 | 2013-01-28 17:33:26 +0000 | [diff] [blame] | 1375 | // Handle multiple DBG_VALUE instructions describing one variable. |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1376 | RegVar->setDotDebugLocOffset(DotDebugLocEntries.size()); |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1377 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1378 | for (SmallVectorImpl<const MachineInstr *>::const_iterator |
| 1379 | HI = History.begin(), |
| 1380 | HE = History.end(); |
| 1381 | HI != HE; ++HI) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1382 | const MachineInstr *Begin = *HI; |
| 1383 | assert(Begin->isDebugValue() && "Invalid History entry"); |
Jakob Stoklund Olesen | 9c057ee | 2011-03-22 00:21:41 +0000 | [diff] [blame] | 1384 | |
Devang Patel | e7181b5 | 2011-06-01 23:00:17 +0000 | [diff] [blame] | 1385 | // Check if DBG_VALUE is truncating a range. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1386 | if (Begin->getNumOperands() > 1 && Begin->getOperand(0).isReg() && |
| 1387 | !Begin->getOperand(0).getReg()) |
Devang Patel | e7181b5 | 2011-06-01 23:00:17 +0000 | [diff] [blame] | 1388 | continue; |
| 1389 | |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1390 | // Compute the range for a register location. |
| 1391 | const MCSymbol *FLabel = getLabelBeforeInsn(Begin); |
| 1392 | const MCSymbol *SLabel = 0; |
| 1393 | |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1394 | if (HI + 1 == HE) |
| 1395 | // If Begin is the last instruction in History then its value is valid |
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1396 | // until the end of the function. |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1397 | SLabel = FunctionEndSym; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1398 | else { |
| 1399 | const MachineInstr *End = HI[1]; |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1400 | DEBUG(dbgs() << "DotDebugLoc Pair:\n" |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1401 | << "\t" << *Begin << "\t" << *End << "\n"); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1402 | if (End->isDebugValue()) |
| 1403 | SLabel = getLabelBeforeInsn(End); |
| 1404 | else { |
| 1405 | // End is a normal instruction clobbering the range. |
| 1406 | SLabel = getLabelAfterInsn(End); |
| 1407 | assert(SLabel && "Forgot label after clobber instruction"); |
| 1408 | ++HI; |
| 1409 | } |
| 1410 | } |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1411 | |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1412 | // The value is valid until the next DBG_VALUE or clobber. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1413 | DotDebugLocEntries.push_back( |
| 1414 | getDebugLocEntry(Asm, FLabel, SLabel, Begin)); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1415 | } |
| 1416 | DotDebugLocEntries.push_back(DotDebugLocEntry()); |
Devang Patel | a3e9c9c | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 1417 | } |
Devang Patel | e0a94bf | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1418 | |
| 1419 | // Collect info for variables that were optimized out. |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1420 | LexicalScope *FnScope = LScopes.getCurrentFunctionScope(); |
| 1421 | DIArray Variables = DISubprogram(FnScope->getScopeNode()).getVariables(); |
| 1422 | for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) { |
| 1423 | DIVariable DV(Variables.getElement(i)); |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 1424 | if (!DV || !DV.isVariable() || !Processed.insert(DV)) |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1425 | continue; |
| 1426 | if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext())) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1427 | addScopeVariable(Scope, new DbgVariable(DV, NULL, this)); |
Devang Patel | e0a94bf | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1428 | } |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1429 | } |
Devang Patel | e0a94bf | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1430 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1431 | // Return Label preceding the instruction. |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 1432 | MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1433 | MCSymbol *Label = LabelsBeforeInsn.lookup(MI); |
| 1434 | assert(Label && "Didn't insert label before instruction"); |
| 1435 | return Label; |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1438 | // Return Label immediately following the instruction. |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 1439 | MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1440 | return LabelsAfterInsn.lookup(MI); |
Devang Patel | 475d32a | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1443 | // Process beginning of an instruction. |
Devang Patel | b5694e7 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 1444 | void DwarfDebug::beginInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1445 | // Check if source location changes, but ignore DBG_VALUE locations. |
| 1446 | if (!MI->isDebugValue()) { |
| 1447 | DebugLoc DL = MI->getDebugLoc(); |
| 1448 | if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) { |
Eric Christopher | aec8a82 | 2012-04-05 20:39:05 +0000 | [diff] [blame] | 1449 | unsigned Flags = 0; |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1450 | PrevInstLoc = DL; |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1451 | if (DL == PrologEndLoc) { |
| 1452 | Flags |= DWARF2_FLAG_PROLOGUE_END; |
| 1453 | PrologEndLoc = DebugLoc(); |
| 1454 | } |
Eric Christopher | aec8a82 | 2012-04-05 20:39:05 +0000 | [diff] [blame] | 1455 | if (PrologEndLoc.isUnknown()) |
| 1456 | Flags |= DWARF2_FLAG_IS_STMT; |
| 1457 | |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1458 | if (!DL.isUnknown()) { |
| 1459 | const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1460 | recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags); |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1461 | } else |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1462 | recordSourceLine(0, 0, 0, 0); |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1463 | } |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1464 | } |
Devang Patel | 23b2ae6 | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 1465 | |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1466 | // Insert labels where requested. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1467 | DenseMap<const MachineInstr *, MCSymbol *>::iterator I = |
| 1468 | LabelsBeforeInsn.find(MI); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1469 | |
| 1470 | // No label needed. |
| 1471 | if (I == LabelsBeforeInsn.end()) |
| 1472 | return; |
| 1473 | |
| 1474 | // Label already assigned. |
| 1475 | if (I->second) |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1476 | return; |
Devang Patel | bd477be | 2010-03-29 17:20:31 +0000 | [diff] [blame] | 1477 | |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1478 | if (!PrevLabel) { |
Devang Patel | acc32a5 | 2010-05-26 21:23:46 +0000 | [diff] [blame] | 1479 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 1480 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1481 | } |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1482 | I->second = PrevLabel; |
Devang Patel | 8db360d | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1485 | // Process end of an instruction. |
Devang Patel | b5694e7 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 1486 | void DwarfDebug::endInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1487 | // Don't create a new label after DBG_VALUE instructions. |
| 1488 | // They don't generate code. |
| 1489 | if (!MI->isDebugValue()) |
| 1490 | PrevLabel = 0; |
| 1491 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1492 | DenseMap<const MachineInstr *, MCSymbol *>::iterator I = |
| 1493 | LabelsAfterInsn.find(MI); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1494 | |
| 1495 | // No label needed. |
| 1496 | if (I == LabelsAfterInsn.end()) |
| 1497 | return; |
| 1498 | |
| 1499 | // Label already assigned. |
| 1500 | if (I->second) |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1501 | return; |
| 1502 | |
| 1503 | // We need a label after this instruction. |
| 1504 | if (!PrevLabel) { |
| 1505 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 1506 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | 3ebd893 | 2010-04-08 16:50:29 +0000 | [diff] [blame] | 1507 | } |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1508 | I->second = PrevLabel; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1511 | // Each LexicalScope has first instruction and last instruction to mark |
| 1512 | // beginning and end of a scope respectively. Create an inverse map that list |
| 1513 | // scopes starts (and ends) with an instruction. One instruction may start (or |
| 1514 | // end) multiple scopes. Ignore scopes that are not reachable. |
Devang Patel | 359b013 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 1515 | void DwarfDebug::identifyScopeMarkers() { |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1516 | SmallVector<LexicalScope *, 4> WorkList; |
| 1517 | WorkList.push_back(LScopes.getCurrentFunctionScope()); |
Devang Patel | 7771b7c | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 1518 | while (!WorkList.empty()) { |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1519 | LexicalScope *S = WorkList.pop_back_val(); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1520 | |
Craig Topper | 977e9cd | 2013-07-03 04:24:43 +0000 | [diff] [blame] | 1521 | const SmallVectorImpl<LexicalScope *> &Children = S->getChildren(); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1522 | if (!Children.empty()) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1523 | for (SmallVectorImpl<LexicalScope *>::const_iterator |
| 1524 | SI = Children.begin(), |
| 1525 | SE = Children.end(); |
| 1526 | SI != SE; ++SI) |
Devang Patel | 7771b7c | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 1527 | WorkList.push_back(*SI); |
| 1528 | |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1529 | if (S->isAbstractScope()) |
| 1530 | continue; |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1531 | |
Craig Topper | 977e9cd | 2013-07-03 04:24:43 +0000 | [diff] [blame] | 1532 | const SmallVectorImpl<InsnRange> &Ranges = S->getRanges(); |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1533 | if (Ranges.empty()) |
| 1534 | continue; |
Craig Topper | d8e4365 | 2013-07-03 04:17:25 +0000 | [diff] [blame] | 1535 | for (SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(), |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1536 | RE = Ranges.end(); |
| 1537 | RI != RE; ++RI) { |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1538 | assert(RI->first && "InsnRange does not have first instruction!"); |
| 1539 | assert(RI->second && "InsnRange does not have second instruction!"); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1540 | requestLabelBeforeInsn(RI->first); |
| 1541 | requestLabelAfterInsn(RI->second); |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1542 | } |
Devang Patel | 75cc16c | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1543 | } |
Devang Patel | 75cc16c | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1546 | // Get MDNode for DebugLoc's scope. |
Devang Patel | 589845d | 2011-05-09 22:14:49 +0000 | [diff] [blame] | 1547 | static MDNode *getScopeNode(DebugLoc DL, const LLVMContext &Ctx) { |
| 1548 | if (MDNode *InlinedAt = DL.getInlinedAt(Ctx)) |
| 1549 | return getScopeNode(DebugLoc::getFromDILocation(InlinedAt), Ctx); |
| 1550 | return DL.getScope(Ctx); |
| 1551 | } |
| 1552 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1553 | // Walk up the scope chain of given debug loc and find line number info |
| 1554 | // for the function. |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1555 | static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) { |
| 1556 | const MDNode *Scope = getScopeNode(DL, Ctx); |
| 1557 | DISubprogram SP = getDISubprogram(Scope); |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 1558 | if (SP.isSubprogram()) { |
Eric Christopher | 3416419 | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1559 | // Check for number of operands since the compatibility is |
| 1560 | // cheap here. |
Eric Christopher | b81e2b4 | 2012-04-03 17:55:42 +0000 | [diff] [blame] | 1561 | if (SP->getNumOperands() > 19) |
Eric Christopher | 3416419 | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1562 | return DebugLoc::get(SP.getScopeLineNumber(), 0, SP); |
| 1563 | else |
| 1564 | return DebugLoc::get(SP.getLineNumber(), 0, SP); |
| 1565 | } |
| 1566 | |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1567 | return DebugLoc(); |
| 1568 | } |
| 1569 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1570 | // Gather pre-function debug information. Assumes being called immediately |
| 1571 | // after the function entry point has been emitted. |
Chris Lattner | 76555b5 | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 1572 | void DwarfDebug::beginFunction(const MachineFunction *MF) { |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1573 | |
| 1574 | // If there's no debug info for the function we're not going to do anything. |
| 1575 | if (!MMI->hasDebugInfo()) |
| 1576 | return; |
| 1577 | |
| 1578 | // Grab the lexical scopes for the function, if we don't have any of those |
| 1579 | // then we're not going to be able to do anything. |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1580 | LScopes.initialize(*MF); |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1581 | if (LScopes.empty()) |
| 1582 | return; |
| 1583 | |
| 1584 | assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned"); |
| 1585 | |
| 1586 | // Make sure that each lexical scope will have a begin/end label. |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1587 | identifyScopeMarkers(); |
Devang Patel | 4598eb6 | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1588 | |
Manman Ren | 4e042a6 | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 1589 | // Set DwarfCompileUnitID in MCContext to the Compile Unit this function |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1590 | // belongs to so that we add to the correct per-cu line table in the |
| 1591 | // non-asm case. |
Manman Ren | 4e042a6 | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 1592 | LexicalScope *FnScope = LScopes.getCurrentFunctionScope(); |
| 1593 | CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode()); |
| 1594 | assert(TheCU && "Unable to find compile unit!"); |
Rafael Espindola | ac4ad25 | 2013-10-05 16:42:21 +0000 | [diff] [blame] | 1595 | if (Asm->TM.hasMCUseLoc() && Asm->OutStreamer.hasRawTextSupport()) |
Manman Ren | 9d4c735 | 2013-05-21 00:57:22 +0000 | [diff] [blame] | 1596 | // Use a single line table if we are using .loc and generating assembly. |
| 1597 | Asm->OutStreamer.getContext().setDwarfCompileUnitID(0); |
| 1598 | else |
| 1599 | Asm->OutStreamer.getContext().setDwarfCompileUnitID(TheCU->getUniqueID()); |
Manman Ren | 4e042a6 | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 1600 | |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1601 | // Emit a label for the function so that we have a beginning address. |
| 1602 | FunctionBeginSym = Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber()); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1603 | // Assumes in correct section after the entry point. |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1604 | Asm->OutStreamer.EmitLabel(FunctionBeginSym); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1605 | |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1606 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1607 | // LiveUserVar - Map physreg numbers to the MDNode they contain. |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1608 | std::vector<const MDNode *> LiveUserVar(TRI->getNumRegs()); |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1609 | |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1610 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E; |
| 1611 | ++I) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1612 | bool AtBlockEntry = true; |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1613 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1614 | II != IE; ++II) { |
| 1615 | const MachineInstr *MI = II; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1616 | |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1617 | if (MI->isDebugValue()) { |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1618 | assert(MI->getNumOperands() > 1 && "Invalid machine instruction!"); |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1619 | |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1620 | // Keep track of user variables. |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1621 | const MDNode *Var = |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1622 | MI->getOperand(MI->getNumOperands() - 1).getMetadata(); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1623 | |
| 1624 | // Variable is in a register, we need to check for clobbers. |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1625 | if (isDbgValueInDefinedReg(MI)) |
| 1626 | LiveUserVar[MI->getOperand(0).getReg()] = Var; |
| 1627 | |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1628 | // Check the history of this variable. |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1629 | SmallVectorImpl<const MachineInstr *> &History = DbgValues[Var]; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1630 | if (History.empty()) { |
| 1631 | UserVariables.push_back(Var); |
| 1632 | // The first mention of a function argument gets the FunctionBeginSym |
| 1633 | // label, so arguments are visible when breaking at function entry. |
| 1634 | DIVariable DV(Var); |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 1635 | if (DV.isVariable() && DV.getTag() == dwarf::DW_TAG_arg_variable && |
David Blaikie | 5af2aca | 2013-11-18 23:57:26 +0000 | [diff] [blame] | 1636 | getDISubprogram(DV.getContext()).describes(MF->getFunction())) |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1637 | LabelsBeforeInsn[MI] = FunctionBeginSym; |
| 1638 | } else { |
| 1639 | // We have seen this variable before. Try to coalesce DBG_VALUEs. |
| 1640 | const MachineInstr *Prev = History.back(); |
| 1641 | if (Prev->isDebugValue()) { |
| 1642 | // Coalesce identical entries at the end of History. |
| 1643 | if (History.size() >= 2 && |
Devang Patel | b7a328e | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1644 | Prev->isIdenticalTo(History[History.size() - 2])) { |
Eric Christopher | 85a495e | 2012-10-08 20:48:49 +0000 | [diff] [blame] | 1645 | DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n" |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1646 | << "\t" << *Prev << "\t" |
| 1647 | << *History[History.size() - 2] << "\n"); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1648 | History.pop_back(); |
Devang Patel | b7a328e | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1649 | } |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1650 | |
| 1651 | // Terminate old register assignments that don't reach MI; |
| 1652 | MachineFunction::const_iterator PrevMBB = Prev->getParent(); |
| 1653 | if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) && |
| 1654 | isDbgValueInDefinedReg(Prev)) { |
| 1655 | // Previous register assignment needs to terminate at the end of |
| 1656 | // its basic block. |
| 1657 | MachineBasicBlock::const_iterator LastMI = |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1658 | PrevMBB->getLastNonDebugInstr(); |
Devang Patel | b7a328e | 2011-07-07 00:14:27 +0000 | [diff] [blame] | 1659 | if (LastMI == PrevMBB->end()) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1660 | // Drop DBG_VALUE for empty range. |
Eric Christopher | 85a495e | 2012-10-08 20:48:49 +0000 | [diff] [blame] | 1661 | DEBUG(dbgs() << "Dropping DBG_VALUE for empty range:\n" |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1662 | << "\t" << *Prev << "\n"); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1663 | History.pop_back(); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 1664 | } else if (llvm::next(PrevMBB) != PrevMBB->getParent()->end()) |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1665 | // Terminate after LastMI. |
| 1666 | History.push_back(LastMI); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | History.push_back(MI); |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1671 | } else { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1672 | // Not a DBG_VALUE instruction. |
| 1673 | if (!MI->isLabel()) |
| 1674 | AtBlockEntry = false; |
| 1675 | |
Eric Christopher | 13319578 | 2012-10-04 20:46:14 +0000 | [diff] [blame] | 1676 | // First known non-DBG_VALUE and non-frame setup location marks |
| 1677 | // the beginning of the function body. |
| 1678 | if (!MI->getFlag(MachineInstr::FrameSetup) && |
| 1679 | (PrologEndLoc.isUnknown() && !MI->getDebugLoc().isUnknown())) |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1680 | PrologEndLoc = MI->getDebugLoc(); |
| 1681 | |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1682 | // Check if the instruction clobbers any registers with debug vars. |
| 1683 | for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(), |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1684 | MOE = MI->operands_end(); |
| 1685 | MOI != MOE; ++MOI) { |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1686 | if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg()) |
| 1687 | continue; |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1688 | for (MCRegAliasIterator AI(MOI->getReg(), TRI, true); AI.isValid(); |
| 1689 | ++AI) { |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 1690 | unsigned Reg = *AI; |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1691 | const MDNode *Var = LiveUserVar[Reg]; |
| 1692 | if (!Var) |
| 1693 | continue; |
| 1694 | // Reg is now clobbered. |
| 1695 | LiveUserVar[Reg] = 0; |
| 1696 | |
| 1697 | // Was MD last defined by a DBG_VALUE referring to Reg? |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1698 | DbgValueHistoryMap::iterator HistI = DbgValues.find(Var); |
| 1699 | if (HistI == DbgValues.end()) |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1700 | continue; |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1701 | SmallVectorImpl<const MachineInstr *> &History = HistI->second; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1702 | if (History.empty()) |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1703 | continue; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1704 | const MachineInstr *Prev = History.back(); |
| 1705 | // Sanity-check: Register assignments are terminated at the end of |
| 1706 | // their block. |
| 1707 | if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent()) |
| 1708 | continue; |
| 1709 | // Is the variable still in Reg? |
| 1710 | if (!isDbgValueInDefinedReg(Prev) || |
| 1711 | Prev->getOperand(0).getReg() != Reg) |
| 1712 | continue; |
| 1713 | // Var is clobbered. Make sure the next instruction gets a label. |
| 1714 | History.push_back(MI); |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1715 | } |
| 1716 | } |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1717 | } |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1718 | } |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end(); |
| 1722 | I != E; ++I) { |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1723 | SmallVectorImpl<const MachineInstr *> &History = I->second; |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1724 | if (History.empty()) |
| 1725 | continue; |
| 1726 | |
| 1727 | // Make sure the final register assignments are terminated. |
| 1728 | const MachineInstr *Prev = History.back(); |
| 1729 | if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) { |
| 1730 | const MachineBasicBlock *PrevMBB = Prev->getParent(); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1731 | MachineBasicBlock::const_iterator LastMI = |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1732 | PrevMBB->getLastNonDebugInstr(); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1733 | if (LastMI == PrevMBB->end()) |
| 1734 | // Drop DBG_VALUE for empty range. |
| 1735 | History.pop_back(); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 1736 | else if (PrevMBB != &PrevMBB->getParent()->back()) { |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1737 | // Terminate after LastMI. |
| 1738 | History.push_back(LastMI); |
| 1739 | } |
| 1740 | } |
| 1741 | // Request labels for the full history. |
| 1742 | for (unsigned i = 0, e = History.size(); i != e; ++i) { |
| 1743 | const MachineInstr *MI = History[i]; |
| 1744 | if (MI->isDebugValue()) |
| 1745 | requestLabelBeforeInsn(MI); |
| 1746 | else |
| 1747 | requestLabelAfterInsn(MI); |
| 1748 | } |
| 1749 | } |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1750 | |
Jakob Stoklund Olesen | 1886a4c | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1751 | PrevInstLoc = DebugLoc(); |
Devang Patel | 002d54d | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1752 | PrevLabel = FunctionBeginSym; |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1753 | |
| 1754 | // Record beginning of function. |
| 1755 | if (!PrologEndLoc.isUnknown()) { |
Eric Christopher | fedfa44 | 2013-11-01 23:14:17 +0000 | [diff] [blame] | 1756 | DebugLoc FnStartDL = |
| 1757 | getFnDebugLoc(PrologEndLoc, MF->getFunction()->getContext()); |
| 1758 | recordSourceLine( |
| 1759 | FnStartDL.getLine(), FnStartDL.getCol(), |
| 1760 | FnStartDL.getScope(MF->getFunction()->getContext()), |
| 1761 | // We'd like to list the prologue as "not statements" but GDB behaves |
| 1762 | // poorly if we do that. Revisit this with caution/GDB (7.5+) testing. |
| 1763 | DWARF2_FLAG_IS_STMT); |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1764 | } |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1767 | void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) { |
David Blaikie | 6f1a806 | 2013-06-05 05:39:59 +0000 | [diff] [blame] | 1768 | SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS]; |
| 1769 | DIVariable DV = Var->getVariable(); |
David Blaikie | 36d5d2f | 2013-06-06 21:04:51 +0000 | [diff] [blame] | 1770 | // Variables with positive arg numbers are parameters. |
| 1771 | if (unsigned ArgNum = DV.getArgNumber()) { |
| 1772 | // Keep all parameters in order at the start of the variable list to ensure |
| 1773 | // function types are correct (no out-of-order parameters) |
| 1774 | // |
| 1775 | // This could be improved by only doing it for optimized builds (unoptimized |
| 1776 | // builds have the right order to begin with), searching from the back (this |
| 1777 | // would catch the unoptimized case quickly), or doing a binary search |
| 1778 | // rather than linear search. |
| 1779 | SmallVectorImpl<DbgVariable *>::iterator I = Vars.begin(); |
| 1780 | while (I != Vars.end()) { |
| 1781 | unsigned CurNum = (*I)->getVariable().getArgNumber(); |
| 1782 | // A local (non-parameter) variable has been found, insert immediately |
| 1783 | // before it. |
| 1784 | if (CurNum == 0) |
| 1785 | break; |
| 1786 | // A later indexed parameter has been found, insert immediately before it. |
David Blaikie | b272a75 | 2013-06-06 22:28:26 +0000 | [diff] [blame] | 1787 | if (CurNum > ArgNum) |
David Blaikie | 36d5d2f | 2013-06-06 21:04:51 +0000 | [diff] [blame] | 1788 | break; |
David Blaikie | b272a75 | 2013-06-06 22:28:26 +0000 | [diff] [blame] | 1789 | ++I; |
David Blaikie | 6f1a806 | 2013-06-05 05:39:59 +0000 | [diff] [blame] | 1790 | } |
David Blaikie | 36d5d2f | 2013-06-06 21:04:51 +0000 | [diff] [blame] | 1791 | Vars.insert(I, Var); |
| 1792 | return; |
David Blaikie | 6f1a806 | 2013-06-05 05:39:59 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | Vars.push_back(Var); |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1798 | // Gather and emit post-function debug information. |
Chris Lattner | 76555b5 | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 1799 | void DwarfDebug::endFunction(const MachineFunction *MF) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1800 | if (!MMI->hasDebugInfo() || LScopes.empty()) |
| 1801 | return; |
Devang Patel | 2904aa9 | 2009-11-12 19:02:56 +0000 | [diff] [blame] | 1802 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1803 | // Define end label for subprogram. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1804 | FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber()); |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1805 | // Assumes in correct section after the entry point. |
| 1806 | Asm->OutStreamer.EmitLabel(FunctionEndSym); |
Manman Ren | 4e042a6 | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 1807 | // Set DwarfCompileUnitID in MCContext to default value. |
| 1808 | Asm->OutStreamer.getContext().setDwarfCompileUnitID(0); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1809 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1810 | SmallPtrSet<const MDNode *, 16> ProcessedVars; |
| 1811 | collectVariableInfo(MF, ProcessedVars); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1812 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1813 | LexicalScope *FnScope = LScopes.getCurrentFunctionScope(); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1814 | CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode()); |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1815 | assert(TheCU && "Unable to find compile unit!"); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1816 | |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1817 | // Construct abstract scopes. |
Devang Patel | 4440347 | 2011-08-12 18:10:19 +0000 | [diff] [blame] | 1818 | ArrayRef<LexicalScope *> AList = LScopes.getAbstractScopesList(); |
| 1819 | for (unsigned i = 0, e = AList.size(); i != e; ++i) { |
| 1820 | LexicalScope *AScope = AList[i]; |
| 1821 | DISubprogram SP(AScope->getScopeNode()); |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 1822 | if (SP.isSubprogram()) { |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1823 | // Collect info for variables that were optimized out. |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1824 | DIArray Variables = SP.getVariables(); |
| 1825 | for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) { |
| 1826 | DIVariable DV(Variables.getElement(i)); |
Manman Ren | 7504ed4 | 2013-07-08 18:33:29 +0000 | [diff] [blame] | 1827 | if (!DV || !DV.isVariable() || !ProcessedVars.insert(DV)) |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1828 | continue; |
Alexey Samsonov | 3960278 | 2012-07-06 08:45:08 +0000 | [diff] [blame] | 1829 | // Check that DbgVariable for DV wasn't created earlier, when |
| 1830 | // findAbstractVariable() was called for inlined instance of DV. |
| 1831 | LLVMContext &Ctx = DV->getContext(); |
| 1832 | DIVariable CleanDV = cleanseInlinedVariable(DV, Ctx); |
| 1833 | if (AbstractVariables.lookup(CleanDV)) |
| 1834 | continue; |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1835 | if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext())) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1836 | addScopeVariable(Scope, new DbgVariable(DV, NULL, this)); |
Devang Patel | 5c0f85c | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 1837 | } |
| 1838 | } |
Devang Patel | 4440347 | 2011-08-12 18:10:19 +0000 | [diff] [blame] | 1839 | if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0) |
Manman Ren | 4213c39 | 2013-05-29 17:16:59 +0000 | [diff] [blame] | 1840 | constructScopeDIE(TheCU, AScope); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1841 | } |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1842 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1843 | DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 1844 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1845 | if (!MF->getTarget().Options.DisableFramePointerElim(*MF)) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1846 | TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1847 | |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1848 | // Clear debug info |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1849 | for (ScopeVariablesMap::iterator I = ScopeVariables.begin(), |
| 1850 | E = ScopeVariables.end(); |
| 1851 | I != E; ++I) |
Devang Patel | 7e62302 | 2011-08-10 20:55:27 +0000 | [diff] [blame] | 1852 | DeleteContainerPointers(I->second); |
| 1853 | ScopeVariables.clear(); |
Devang Patel | ad45d91 | 2011-04-22 18:09:57 +0000 | [diff] [blame] | 1854 | DeleteContainerPointers(CurrentFnArguments); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1855 | UserVariables.clear(); |
| 1856 | DbgValues.clear(); |
Jeffrey Yasskin | 35b4e4f | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 1857 | AbstractVariables.clear(); |
Devang Patel | 6c74a87 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1858 | LabelsBeforeInsn.clear(); |
| 1859 | LabelsAfterInsn.clear(); |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 1860 | PrevLabel = NULL; |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1863 | // Register a source line with debug info. Returns the unique label that was |
| 1864 | // emitted and which provides correspondence to the source line list. |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1865 | void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S, |
| 1866 | unsigned Flags) { |
Devang Patel | 2d9caf9 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1867 | StringRef Fn; |
Devang Patel | e01b75c | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1868 | StringRef Dir; |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1869 | unsigned Src = 1; |
| 1870 | if (S) { |
| 1871 | DIDescriptor Scope(S); |
Devang Patel | 2089d16 | 2009-10-05 18:03:19 +0000 | [diff] [blame] | 1872 | |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1873 | if (Scope.isCompileUnit()) { |
| 1874 | DICompileUnit CU(S); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1875 | Fn = CU.getFilename(); |
Devang Patel | e01b75c | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1876 | Dir = CU.getDirectory(); |
Devang Patel | c4b6905 | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 1877 | } else if (Scope.isFile()) { |
| 1878 | DIFile F(S); |
Devang Patel | c4b6905 | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 1879 | Fn = F.getFilename(); |
Devang Patel | e01b75c | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1880 | Dir = F.getDirectory(); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1881 | } else if (Scope.isSubprogram()) { |
| 1882 | DISubprogram SP(S); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1883 | Fn = SP.getFilename(); |
Devang Patel | e01b75c | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1884 | Dir = SP.getDirectory(); |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1885 | } else if (Scope.isLexicalBlockFile()) { |
| 1886 | DILexicalBlockFile DBF(S); |
| 1887 | Fn = DBF.getFilename(); |
| 1888 | Dir = DBF.getDirectory(); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1889 | } else if (Scope.isLexicalBlock()) { |
| 1890 | DILexicalBlock DB(S); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1891 | Fn = DB.getFilename(); |
Devang Patel | e01b75c | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1892 | Dir = DB.getDirectory(); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1893 | } else |
Craig Topper | ee4dab5 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 1894 | llvm_unreachable("Unexpected scope info"); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1895 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1896 | Src = getOrCreateSourceID( |
| 1897 | Fn, Dir, Asm->OutStreamer.getContext().getDwarfCompileUnitID()); |
Dan Gohman | 50849c6 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 1898 | } |
Nick Lewycky | 019d255 | 2011-07-29 03:49:23 +0000 | [diff] [blame] | 1899 | Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0, 0, Fn); |
Bill Wendling | 2b128d7 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
Bill Wendling | 806535f | 2009-05-20 23:22:40 +0000 | [diff] [blame] | 1902 | //===----------------------------------------------------------------------===// |
| 1903 | // Emit Methods |
| 1904 | //===----------------------------------------------------------------------===// |
| 1905 | |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 1906 | // Compute the size and offset of a DIE. The offset is relative to start of the |
| 1907 | // CU. It returns the offset after laying out the DIE. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1908 | unsigned DwarfUnits::computeSizeAndOffset(DIE *Die, unsigned Offset) { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1909 | // Get the children. |
| 1910 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 1911 | |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1912 | // Record the abbreviation. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1913 | assignAbbrevNumber(Die->getAbbrev()); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1914 | |
| 1915 | // Get the abbreviation for this DIE. |
| 1916 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
David Blaikie | 2d4e112 | 2013-10-30 17:14:24 +0000 | [diff] [blame] | 1917 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1918 | |
| 1919 | // Set DIE offset |
| 1920 | Die->setOffset(Offset); |
| 1921 | |
| 1922 | // Start the size with the size of abbreviation code. |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 1923 | Offset += MCAsmInfo::getULEB128Size(AbbrevNumber); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1924 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1925 | const SmallVectorImpl<DIEValue *> &Values = Die->getValues(); |
Eric Christopher | 4887c8f | 2013-03-29 23:34:06 +0000 | [diff] [blame] | 1926 | const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev->getData(); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1927 | |
| 1928 | // Size the DIE attribute values. |
| 1929 | for (unsigned i = 0, N = Values.size(); i < N; ++i) |
| 1930 | // Size attribute value. |
Chris Lattner | 5a00dea | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 1931 | Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm()); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1932 | |
| 1933 | // Size the DIE children if any. |
| 1934 | if (!Children.empty()) { |
| 1935 | assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes && |
| 1936 | "Children flag not set"); |
| 1937 | |
| 1938 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Eric Christopher | 1f0cbb8 | 2012-11-20 22:14:13 +0000 | [diff] [blame] | 1939 | Offset = computeSizeAndOffset(Children[j], Offset); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1940 | |
| 1941 | // End of children marker. |
| 1942 | Offset += sizeof(int8_t); |
| 1943 | } |
| 1944 | |
| 1945 | Die->setSize(Offset - Die->getOffset()); |
| 1946 | return Offset; |
| 1947 | } |
| 1948 | |
Eric Christopher | b088d2d | 2013-10-24 21:05:08 +0000 | [diff] [blame] | 1949 | // Compute the size and offset for each DIE. |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 1950 | void DwarfUnits::computeSizeAndOffsets() { |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 1951 | // Offset from the first CU in the debug info section is 0 initially. |
| 1952 | unsigned SecOffset = 0; |
| 1953 | |
Eric Christopher | b088d2d | 2013-10-24 21:05:08 +0000 | [diff] [blame] | 1954 | // Iterate over each compile unit and set the size and offsets for each |
| 1955 | // DIE within each compile unit. All offsets are CU relative. |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 1956 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = CUs.begin(), |
| 1957 | E = CUs.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1958 | I != E; ++I) { |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 1959 | (*I)->setDebugInfoOffset(SecOffset); |
| 1960 | |
| 1961 | // CU-relative offset is reset to 0 here. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1962 | unsigned Offset = sizeof(int32_t) + // Length of Unit Info |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 1963 | (*I)->getHeaderSize(); // Unit-specific headers |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 1964 | |
| 1965 | // EndOffset here is CU-relative, after laying out |
| 1966 | // all of the CU DIE. |
| 1967 | unsigned EndOffset = computeSizeAndOffset((*I)->getCUDie(), Offset); |
| 1968 | SecOffset += EndOffset; |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1969 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 1972 | // Emit initial Dwarf sections with a label at the start of each one. |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 1973 | void DwarfDebug::emitSectionLabels() { |
Chris Lattner | 4b7dadb | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1974 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Daniel Dunbar | c418d6b | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 1975 | |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1976 | // Dwarf sections base addresses. |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1977 | DwarfInfoSectionSym = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1978 | emitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info"); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1979 | DwarfAbbrevSectionSym = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1980 | emitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev"); |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 1981 | if (useSplitDwarf()) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1982 | DwarfAbbrevDWOSectionSym = emitSectionSym( |
| 1983 | Asm, TLOF.getDwarfAbbrevDWOSection(), "section_abbrev_dwo"); |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 1984 | emitSectionSym(Asm, TLOF.getDwarfARangesSection()); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1985 | |
Chris Lattner | 6629ca9 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 1986 | if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection()) |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 1987 | emitSectionSym(Asm, MacroInfo); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 1988 | |
Eric Christopher | 7480433 | 2013-02-07 21:19:50 +0000 | [diff] [blame] | 1989 | DwarfLineSectionSym = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 1990 | emitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line"); |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 1991 | emitSectionSym(Asm, TLOF.getDwarfLocSection()); |
Eric Christopher | 261d234 | 2013-09-23 20:55:35 +0000 | [diff] [blame] | 1992 | if (GenerateGnuPubSections) { |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 1993 | DwarfGnuPubNamesSectionSym = |
| 1994 | emitSectionSym(Asm, TLOF.getDwarfGnuPubNamesSection()); |
| 1995 | DwarfGnuPubTypesSectionSym = |
| 1996 | emitSectionSym(Asm, TLOF.getDwarfGnuPubTypesSection()); |
Eric Christopher | 261d234 | 2013-09-23 20:55:35 +0000 | [diff] [blame] | 1997 | } else if (HasDwarfPubSections) { |
| 1998 | emitSectionSym(Asm, TLOF.getDwarfPubNamesSection()); |
| 1999 | emitSectionSym(Asm, TLOF.getDwarfPubTypesSection()); |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 2000 | } |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2001 | |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2002 | DwarfStrSectionSym = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2003 | emitSectionSym(Asm, TLOF.getDwarfStrSection(), "info_string"); |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 2004 | if (useSplitDwarf()) { |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 2005 | DwarfStrDWOSectionSym = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2006 | emitSectionSym(Asm, TLOF.getDwarfStrDWOSection(), "skel_string"); |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 2007 | DwarfAddrSectionSym = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2008 | emitSectionSym(Asm, TLOF.getDwarfAddrSection(), "addr_sec"); |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 2009 | } |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2010 | DwarfDebugRangeSectionSym = |
| 2011 | emitSectionSym(Asm, TLOF.getDwarfRangesSection(), "debug_range"); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2012 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2013 | DwarfDebugLocSectionSym = |
| 2014 | emitSectionSym(Asm, TLOF.getDwarfLocSection(), "section_debug_loc"); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2015 | |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 2016 | TextSectionSym = emitSectionSym(Asm, TLOF.getTextSection(), "text_begin"); |
| 2017 | emitSectionSym(Asm, TLOF.getDataSection()); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2020 | // Recursively emits a debug information entry. |
David Blaikie | 2d4e112 | 2013-10-30 17:14:24 +0000 | [diff] [blame] | 2021 | void DwarfDebug::emitDIE(DIE *Die, ArrayRef<DIEAbbrev *> Abbrevs) { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2022 | // Get the abbreviation for this DIE. |
| 2023 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
David Blaikie | 2d4e112 | 2013-10-30 17:14:24 +0000 | [diff] [blame] | 2024 | const DIEAbbrev *Abbrev = Abbrevs[AbbrevNumber - 1]; |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2025 | |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2026 | // Emit the code (index) for the abbreviation. |
Chris Lattner | 7bde8c0 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2027 | if (Asm->isVerbose()) |
Chris Lattner | fa82355 | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 2028 | Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" + |
| 2029 | Twine::utohexstr(Die->getOffset()) + ":0x" + |
| 2030 | Twine::utohexstr(Die->getSize()) + " " + |
| 2031 | dwarf::TagString(Abbrev->getTag())); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2032 | Asm->EmitULEB128(AbbrevNumber); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2033 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2034 | const SmallVectorImpl<DIEValue *> &Values = Die->getValues(); |
Eric Christopher | 4887c8f | 2013-03-29 23:34:06 +0000 | [diff] [blame] | 2035 | const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev->getData(); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2036 | |
| 2037 | // Emit the DIE attribute values. |
| 2038 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 2039 | dwarf::Attribute Attr = AbbrevData[i].getAttribute(); |
| 2040 | dwarf::Form Form = AbbrevData[i].getForm(); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2041 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
| 2042 | |
Chris Lattner | 7bde8c0 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2043 | if (Asm->isVerbose()) |
Chris Lattner | 5adf987 | 2010-01-24 18:54:17 +0000 | [diff] [blame] | 2044 | Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr)); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2045 | |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2046 | switch (Attr) { |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 2047 | case dwarf::DW_AT_abstract_origin: |
| 2048 | case dwarf::DW_AT_type: |
| 2049 | case dwarf::DW_AT_friend: |
| 2050 | case dwarf::DW_AT_specification: |
| 2051 | case dwarf::DW_AT_import: |
| 2052 | case dwarf::DW_AT_containing_type: { |
| 2053 | DIEEntry *E = cast<DIEEntry>(Values[i]); |
| 2054 | DIE *Origin = E->getEntry(); |
| 2055 | unsigned Addr = Origin->getOffset(); |
| 2056 | if (Form == dwarf::DW_FORM_ref_addr) { |
| 2057 | assert(!useSplitDwarf() && "TODO: dwo files can't have relocations."); |
| 2058 | // For DW_FORM_ref_addr, output the offset from beginning of debug info |
| 2059 | // section. Origin->getOffset() returns the offset from start of the |
| 2060 | // compile unit. |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 2061 | CompileUnit *CU = CUDieMap.lookup(Origin->getUnit()); |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 2062 | assert(CU && "CUDie should belong to a CU."); |
| 2063 | Addr += CU->getDebugInfoOffset(); |
| 2064 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
| 2065 | Asm->EmitLabelPlusOffset(DwarfInfoSectionSym, Addr, |
| 2066 | DIEEntry::getRefAddrSize(Asm)); |
| 2067 | else |
Manman Ren | 251a1bd | 2013-10-29 23:14:15 +0000 | [diff] [blame] | 2068 | Asm->EmitLabelOffsetDifference(DwarfInfoSectionSym, Addr, |
| 2069 | DwarfInfoSectionSym, |
| 2070 | DIEEntry::getRefAddrSize(Asm)); |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 2071 | } else { |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 2072 | // Make sure Origin belong to the same CU. |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 2073 | assert(Die->getUnit() == Origin->getUnit() && |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 2074 | "The referenced DIE should belong to the same CU in ref4"); |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 2075 | Asm->EmitInt32(Addr); |
| 2076 | } |
| 2077 | break; |
| 2078 | } |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2079 | case dwarf::DW_AT_ranges: { |
| 2080 | // DW_AT_range Value encodes offset in debug_range section. |
Eric Christopher | 4751d70 | 2013-11-23 00:05:29 +0000 | [diff] [blame] | 2081 | DIELabel *V = cast<DIELabel>(Values[i]); |
Devang Patel | da3ef85 | 2010-09-02 16:43:44 +0000 | [diff] [blame] | 2082 | |
Eric Christopher | 4751d70 | 2013-11-23 00:05:29 +0000 | [diff] [blame] | 2083 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
| 2084 | Asm->EmitSectionOffset(V->getValue(), DwarfDebugRangeSectionSym); |
| 2085 | else |
| 2086 | Asm->EmitLabelDifference(V->getValue(), DwarfDebugRangeSectionSym, 4); |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2087 | break; |
| 2088 | } |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2089 | case dwarf::DW_AT_location: { |
Nick Lewycky | 33da336 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 2090 | if (DIELabel *L = dyn_cast<DIELabel>(Values[i])) { |
| 2091 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | d0b82ae | 2013-11-16 00:18:40 +0000 | [diff] [blame] | 2092 | Asm->EmitSectionOffset(L->getValue(), DwarfDebugLocSectionSym); |
Nick Lewycky | 33da336 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 2093 | else |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 2094 | Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4); |
Nick Lewycky | 33da336 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 2095 | } else { |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2096 | Values[i]->EmitValue(Asm, Form); |
Nick Lewycky | 33da336 | 2012-06-22 01:25:12 +0000 | [diff] [blame] | 2097 | } |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2098 | break; |
| 2099 | } |
Devang Patel | a1bd5a1 | 2010-09-29 19:08:08 +0000 | [diff] [blame] | 2100 | case dwarf::DW_AT_accessibility: { |
| 2101 | if (Asm->isVerbose()) { |
| 2102 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
| 2103 | Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue())); |
| 2104 | } |
| 2105 | Values[i]->EmitValue(Asm, Form); |
| 2106 | break; |
| 2107 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2108 | default: |
| 2109 | // Emit an attribute using the defined form. |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2110 | Values[i]->EmitValue(Asm, Form); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2111 | break; |
| 2112 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | // Emit the DIE children if any. |
| 2116 | if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) { |
| 2117 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2118 | |
| 2119 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2120 | emitDIE(Children[j], Abbrevs); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2121 | |
Chris Lattner | 7bde8c0 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2122 | if (Asm->isVerbose()) |
Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2123 | Asm->OutStreamer.AddComment("End Of Children Mark"); |
| 2124 | Asm->EmitInt8(0); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 2128 | // Emit the various dwarf units to the unit section USection with |
| 2129 | // the abbreviations going into ASection. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2130 | void DwarfUnits::emitUnits(DwarfDebug *DD, const MCSection *USection, |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 2131 | const MCSection *ASection, |
| 2132 | const MCSymbol *ASectionSym) { |
| 2133 | Asm->OutStreamer.SwitchSection(USection); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2134 | for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(), E = CUs.end(); |
| 2135 | I != E; ++I) { |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 2136 | CompileUnit *TheCU = *I; |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2137 | DIE *Die = TheCU->getCUDie(); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2138 | |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2139 | // Emit the compile units header. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2140 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol(USection->getLabelBeginName(), |
| 2141 | TheCU->getUniqueID())); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2142 | |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2143 | // Emit size of content not including length itself |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 2144 | Asm->OutStreamer.AddComment("Length of Unit"); |
| 2145 | Asm->EmitInt32(TheCU->getHeaderSize() + Die->getSize()); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2146 | |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 2147 | TheCU->emitHeader(ASection, ASectionSym); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2148 | |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2149 | DD->emitDIE(Die, Abbreviations); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2150 | Asm->OutStreamer.EmitLabel( |
| 2151 | Asm->GetTempSymbol(USection->getLabelEndName(), TheCU->getUniqueID())); |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2152 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2155 | // Emit the debug info section. |
| 2156 | void DwarfDebug::emitDebugInfo() { |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 2157 | DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder; |
| 2158 | |
| 2159 | Holder.emitUnits(this, Asm->getObjFileLowering().getDwarfInfoSection(), |
| 2160 | Asm->getObjFileLowering().getDwarfAbbrevSection(), |
| 2161 | DwarfAbbrevSectionSym); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2164 | // Emit the abbreviation section. |
Eric Christopher | 3837195 | 2012-11-20 23:30:11 +0000 | [diff] [blame] | 2165 | void DwarfDebug::emitAbbreviations() { |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2166 | if (!useSplitDwarf()) |
| 2167 | emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection(), |
| 2168 | &Abbreviations); |
| 2169 | else |
| 2170 | emitSkeletonAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection()); |
| 2171 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2172 | |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2173 | void DwarfDebug::emitAbbrevs(const MCSection *Section, |
| 2174 | std::vector<DIEAbbrev *> *Abbrevs) { |
| 2175 | // Check to see if it is worth the effort. |
| 2176 | if (!Abbrevs->empty()) { |
| 2177 | // Start the debug abbrev section. |
| 2178 | Asm->OutStreamer.SwitchSection(Section); |
| 2179 | |
| 2180 | MCSymbol *Begin = Asm->GetTempSymbol(Section->getLabelBeginName()); |
Eric Christopher | 996b2b7 | 2012-12-13 03:00:38 +0000 | [diff] [blame] | 2181 | Asm->OutStreamer.EmitLabel(Begin); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2182 | |
| 2183 | // For each abbrevation. |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2184 | for (unsigned i = 0, N = Abbrevs->size(); i < N; ++i) { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2185 | // Get abbreviation data |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2186 | const DIEAbbrev *Abbrev = Abbrevs->at(i); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2187 | |
| 2188 | // Emit the abbrevations code (base 1 index.) |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2189 | Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code"); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2190 | |
| 2191 | // Emit the abbreviations data. |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2192 | Abbrev->Emit(Asm); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | // Mark end of abbreviations. |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2196 | Asm->EmitULEB128(0, "EOM(3)"); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2197 | |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 2198 | MCSymbol *End = Asm->GetTempSymbol(Section->getLabelEndName()); |
Eric Christopher | 996b2b7 | 2012-12-13 03:00:38 +0000 | [diff] [blame] | 2199 | Asm->OutStreamer.EmitLabel(End); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2200 | } |
| 2201 | } |
| 2202 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2203 | // Emit the last address of the section and the end of the line matrix. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2204 | void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2205 | // Define last address of section. |
Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2206 | Asm->OutStreamer.AddComment("Extended Op"); |
| 2207 | Asm->EmitInt8(0); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2208 | |
Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2209 | Asm->OutStreamer.AddComment("Op size"); |
Chandler Carruth | 5da3f05 | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2210 | Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1); |
Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2211 | Asm->OutStreamer.AddComment("DW_LNE_set_address"); |
| 2212 | Asm->EmitInt8(dwarf::DW_LNE_set_address); |
| 2213 | |
| 2214 | Asm->OutStreamer.AddComment("Section end label"); |
Chris Lattner | b245dfb | 2010-03-10 01:17:49 +0000 | [diff] [blame] | 2215 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2216 | Asm->OutStreamer.EmitSymbolValue( |
| 2217 | Asm->GetTempSymbol("section_end", SectionEnd), |
| 2218 | Asm->getDataLayout().getPointerSize()); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2219 | |
| 2220 | // Mark end of matrix. |
Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2221 | Asm->OutStreamer.AddComment("DW_LNE_end_sequence"); |
| 2222 | Asm->EmitInt8(0); |
Chris Lattner | f5c834f | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 2223 | Asm->EmitInt8(1); |
Chris Lattner | fa82355 | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 2224 | Asm->EmitInt8(1); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2227 | // Emit visible names into a hashed accelerator table section. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2228 | void DwarfDebug::emitAccelNames() { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2229 | DwarfAccelTable AT( |
| 2230 | DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2231 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 2232 | E = getUnits().end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2233 | I != E; ++I) { |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2234 | CompileUnit *TheCU = *I; |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2235 | const StringMap<std::vector<const DIE *> > &Names = TheCU->getAccelNames(); |
| 2236 | for (StringMap<std::vector<const DIE *> >::const_iterator |
| 2237 | GI = Names.begin(), |
| 2238 | GE = Names.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2239 | GI != GE; ++GI) { |
Benjamin Kramer | 63e39eb | 2013-05-11 18:24:28 +0000 | [diff] [blame] | 2240 | StringRef Name = GI->getKey(); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2241 | const std::vector<const DIE *> &Entities = GI->second; |
| 2242 | for (std::vector<const DIE *>::const_iterator DI = Entities.begin(), |
| 2243 | DE = Entities.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2244 | DI != DE; ++DI) |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2245 | AT.AddName(Name, *DI); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | AT.FinalizeTable(Asm, "Names"); |
| 2250 | Asm->OutStreamer.SwitchSection( |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2251 | Asm->getObjFileLowering().getDwarfAccelNamesSection()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2252 | MCSymbol *SectionBegin = Asm->GetTempSymbol("names_begin"); |
| 2253 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 2254 | |
| 2255 | // Emit the full data. |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 2256 | AT.Emit(Asm, SectionBegin, &InfoHolder); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 2259 | // Emit objective C classes and categories into a hashed accelerator table |
| 2260 | // section. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2261 | void DwarfDebug::emitAccelObjC() { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2262 | DwarfAccelTable AT( |
| 2263 | DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2264 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 2265 | E = getUnits().end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2266 | I != E; ++I) { |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2267 | CompileUnit *TheCU = *I; |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2268 | const StringMap<std::vector<const DIE *> > &Names = TheCU->getAccelObjC(); |
| 2269 | for (StringMap<std::vector<const DIE *> >::const_iterator |
| 2270 | GI = Names.begin(), |
| 2271 | GE = Names.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2272 | GI != GE; ++GI) { |
Benjamin Kramer | 63e39eb | 2013-05-11 18:24:28 +0000 | [diff] [blame] | 2273 | StringRef Name = GI->getKey(); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2274 | const std::vector<const DIE *> &Entities = GI->second; |
| 2275 | for (std::vector<const DIE *>::const_iterator DI = Entities.begin(), |
| 2276 | DE = Entities.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2277 | DI != DE; ++DI) |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2278 | AT.AddName(Name, *DI); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | AT.FinalizeTable(Asm, "ObjC"); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2283 | Asm->OutStreamer.SwitchSection( |
| 2284 | Asm->getObjFileLowering().getDwarfAccelObjCSection()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2285 | MCSymbol *SectionBegin = Asm->GetTempSymbol("objc_begin"); |
| 2286 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 2287 | |
| 2288 | // Emit the full data. |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 2289 | AT.Emit(Asm, SectionBegin, &InfoHolder); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2292 | // Emit namespace dies into a hashed accelerator table. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2293 | void DwarfDebug::emitAccelNamespaces() { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2294 | DwarfAccelTable AT( |
| 2295 | DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2296 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 2297 | E = getUnits().end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2298 | I != E; ++I) { |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2299 | CompileUnit *TheCU = *I; |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2300 | const StringMap<std::vector<const DIE *> > &Names = |
| 2301 | TheCU->getAccelNamespace(); |
| 2302 | for (StringMap<std::vector<const DIE *> >::const_iterator |
| 2303 | GI = Names.begin(), |
| 2304 | GE = Names.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2305 | GI != GE; ++GI) { |
Benjamin Kramer | 63e39eb | 2013-05-11 18:24:28 +0000 | [diff] [blame] | 2306 | StringRef Name = GI->getKey(); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2307 | const std::vector<const DIE *> &Entities = GI->second; |
| 2308 | for (std::vector<const DIE *>::const_iterator DI = Entities.begin(), |
| 2309 | DE = Entities.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2310 | DI != DE; ++DI) |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2311 | AT.AddName(Name, *DI); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | AT.FinalizeTable(Asm, "namespac"); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2316 | Asm->OutStreamer.SwitchSection( |
| 2317 | Asm->getObjFileLowering().getDwarfAccelNamespaceSection()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2318 | MCSymbol *SectionBegin = Asm->GetTempSymbol("namespac_begin"); |
| 2319 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 2320 | |
| 2321 | // Emit the full data. |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 2322 | AT.Emit(Asm, SectionBegin, &InfoHolder); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2325 | // Emit type dies into a hashed accelerator table. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2326 | void DwarfDebug::emitAccelTypes() { |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 2327 | std::vector<DwarfAccelTable::Atom> Atoms; |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2328 | Atoms.push_back( |
| 2329 | DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); |
| 2330 | Atoms.push_back( |
| 2331 | DwarfAccelTable::Atom(dwarf::DW_ATOM_die_tag, dwarf::DW_FORM_data2)); |
| 2332 | Atoms.push_back( |
| 2333 | DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)); |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 2334 | DwarfAccelTable AT(Atoms); |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2335 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 2336 | E = getUnits().end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2337 | I != E; ++I) { |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2338 | CompileUnit *TheCU = *I; |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2339 | const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &Names = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2340 | TheCU->getAccelTypes(); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2341 | for (StringMap< |
| 2342 | std::vector<std::pair<const DIE *, unsigned> > >::const_iterator |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2343 | GI = Names.begin(), |
| 2344 | GE = Names.end(); |
| 2345 | GI != GE; ++GI) { |
Benjamin Kramer | 63e39eb | 2013-05-11 18:24:28 +0000 | [diff] [blame] | 2346 | StringRef Name = GI->getKey(); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2347 | const std::vector<std::pair<const DIE *, unsigned> > &Entities = |
| 2348 | GI->second; |
| 2349 | for (std::vector<std::pair<const DIE *, unsigned> >::const_iterator |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2350 | DI = Entities.begin(), |
| 2351 | DE = Entities.end(); |
| 2352 | DI != DE; ++DI) |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 2353 | AT.AddName(Name, DI->first, DI->second); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | AT.FinalizeTable(Asm, "types"); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2358 | Asm->OutStreamer.SwitchSection( |
| 2359 | Asm->getObjFileLowering().getDwarfAccelTypesSection()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2360 | MCSymbol *SectionBegin = Asm->GetTempSymbol("types_begin"); |
| 2361 | Asm->OutStreamer.EmitLabel(SectionBegin); |
| 2362 | |
| 2363 | // Emit the full data. |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 2364 | AT.Emit(Asm, SectionBegin, &InfoHolder); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2367 | // Public name handling. |
| 2368 | // The format for the various pubnames: |
| 2369 | // |
| 2370 | // dwarf pubnames - offset/name pairs where the offset is the offset into the CU |
| 2371 | // for the DIE that is named. |
| 2372 | // |
| 2373 | // gnu pubnames - offset/index value/name tuples where the offset is the offset |
| 2374 | // into the CU and the index value is computed according to the type of value |
| 2375 | // for the DIE that is named. |
| 2376 | // |
| 2377 | // For type units the offset is the offset of the skeleton DIE. For split dwarf |
| 2378 | // it's the offset within the debug_info/debug_types dwo section, however, the |
| 2379 | // reference in the pubname header doesn't change. |
| 2380 | |
| 2381 | /// computeIndexValue - Compute the gdb index value for the DIE and CU. |
David Blaikie | 8dec407 | 2013-09-19 20:40:26 +0000 | [diff] [blame] | 2382 | static dwarf::PubIndexEntryDescriptor computeIndexValue(CompileUnit *CU, |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 2383 | const DIE *Die) { |
Eric Christopher | d2b497b | 2013-10-16 01:37:49 +0000 | [diff] [blame] | 2384 | dwarf::GDBIndexEntryLinkage Linkage = dwarf::GIEL_STATIC; |
| 2385 | |
| 2386 | // We could have a specification DIE that has our most of our knowledge, |
| 2387 | // look for that now. |
| 2388 | DIEValue *SpecVal = Die->findAttribute(dwarf::DW_AT_specification); |
| 2389 | if (SpecVal) { |
| 2390 | DIE *SpecDIE = cast<DIEEntry>(SpecVal)->getEntry(); |
| 2391 | if (SpecDIE->findAttribute(dwarf::DW_AT_external)) |
| 2392 | Linkage = dwarf::GIEL_EXTERNAL; |
| 2393 | } else if (Die->findAttribute(dwarf::DW_AT_external)) |
| 2394 | Linkage = dwarf::GIEL_EXTERNAL; |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2395 | |
| 2396 | switch (Die->getTag()) { |
| 2397 | case dwarf::DW_TAG_class_type: |
| 2398 | case dwarf::DW_TAG_structure_type: |
| 2399 | case dwarf::DW_TAG_union_type: |
| 2400 | case dwarf::DW_TAG_enumeration_type: |
Eric Christopher | 261d234 | 2013-09-23 20:55:35 +0000 | [diff] [blame] | 2401 | return dwarf::PubIndexEntryDescriptor( |
| 2402 | dwarf::GIEK_TYPE, CU->getLanguage() != dwarf::DW_LANG_C_plus_plus |
| 2403 | ? dwarf::GIEL_STATIC |
| 2404 | : dwarf::GIEL_EXTERNAL); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2405 | case dwarf::DW_TAG_typedef: |
| 2406 | case dwarf::DW_TAG_base_type: |
| 2407 | case dwarf::DW_TAG_subrange_type: |
David Blaikie | 8dec407 | 2013-09-19 20:40:26 +0000 | [diff] [blame] | 2408 | return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE, dwarf::GIEL_STATIC); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2409 | case dwarf::DW_TAG_namespace: |
David Blaikie | 8dec407 | 2013-09-19 20:40:26 +0000 | [diff] [blame] | 2410 | return dwarf::GIEK_TYPE; |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2411 | case dwarf::DW_TAG_subprogram: |
Eric Christopher | ccac5c4 | 2013-09-23 22:59:14 +0000 | [diff] [blame] | 2412 | return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_FUNCTION, Linkage); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2413 | case dwarf::DW_TAG_constant: |
| 2414 | case dwarf::DW_TAG_variable: |
Eric Christopher | ccac5c4 | 2013-09-23 22:59:14 +0000 | [diff] [blame] | 2415 | return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, Linkage); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2416 | case dwarf::DW_TAG_enumerator: |
David Blaikie | 8dec407 | 2013-09-19 20:40:26 +0000 | [diff] [blame] | 2417 | return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, |
| 2418 | dwarf::GIEL_STATIC); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2419 | default: |
David Blaikie | 8dec407 | 2013-09-19 20:40:26 +0000 | [diff] [blame] | 2420 | return dwarf::GIEK_NONE; |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2421 | } |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
Eric Christopher | 5f93bb9 | 2013-09-09 20:03:17 +0000 | [diff] [blame] | 2424 | /// emitDebugPubNames - Emit visible names into a debug pubnames section. |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2425 | /// |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2426 | void DwarfDebug::emitDebugPubNames(bool GnuStyle) { |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2427 | const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection(); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2428 | const MCSection *PSec = |
| 2429 | GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection() |
| 2430 | : Asm->getObjFileLowering().getDwarfPubNamesSection(); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2431 | |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2432 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 2433 | E = getUnits().end(); |
| 2434 | I != E; ++I) { |
| 2435 | CompileUnit *TheCU = *I; |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2436 | unsigned ID = TheCU->getUniqueID(); |
| 2437 | |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2438 | // Start the dwarf pubnames section. |
Eric Christopher | 13b99d2 | 2013-09-10 21:49:37 +0000 | [diff] [blame] | 2439 | Asm->OutStreamer.SwitchSection(PSec); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2440 | |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2441 | // Emit a label so we can reference the beginning of this pubname section. |
| 2442 | if (GnuStyle) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2443 | Asm->OutStreamer.EmitLabel( |
| 2444 | Asm->GetTempSymbol("gnu_pubnames", TheCU->getUniqueID())); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2445 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2446 | // Emit the header. |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2447 | Asm->OutStreamer.AddComment("Length of Public Names Info"); |
| 2448 | Asm->EmitLabelDifference(Asm->GetTempSymbol("pubnames_end", ID), |
| 2449 | Asm->GetTempSymbol("pubnames_begin", ID), 4); |
| 2450 | |
| 2451 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin", ID)); |
| 2452 | |
| 2453 | Asm->OutStreamer.AddComment("DWARF Version"); |
David Majnemer | ed89b5c | 2013-08-21 06:13:34 +0000 | [diff] [blame] | 2454 | Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2455 | |
| 2456 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
| 2457 | Asm->EmitSectionOffset(Asm->GetTempSymbol(ISec->getLabelBeginName(), ID), |
| 2458 | DwarfInfoSectionSym); |
| 2459 | |
| 2460 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
| 2461 | Asm->EmitLabelDifference(Asm->GetTempSymbol(ISec->getLabelEndName(), ID), |
| 2462 | Asm->GetTempSymbol(ISec->getLabelBeginName(), ID), |
| 2463 | 4); |
| 2464 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2465 | // Emit the pubnames for this compilation unit. |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 2466 | const StringMap<const DIE *> &Globals = TheCU->getGlobalNames(); |
| 2467 | for (StringMap<const DIE *>::const_iterator GI = Globals.begin(), |
| 2468 | GE = Globals.end(); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2469 | GI != GE; ++GI) { |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2470 | const char *Name = GI->getKeyData(); |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 2471 | const DIE *Entity = GI->second; |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2472 | |
| 2473 | Asm->OutStreamer.AddComment("DIE offset"); |
| 2474 | Asm->EmitInt32(Entity->getOffset()); |
| 2475 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2476 | if (GnuStyle) { |
David Blaikie | d0a869d | 2013-09-19 22:19:37 +0000 | [diff] [blame] | 2477 | dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheCU, Entity); |
| 2478 | Asm->OutStreamer.AddComment( |
David Blaikie | efd0bcb | 2013-09-20 00:33:15 +0000 | [diff] [blame] | 2479 | Twine("Kind: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " + |
David Blaikie | 404d304 | 2013-09-19 23:01:29 +0000 | [diff] [blame] | 2480 | dwarf::GDBIndexEntryLinkageString(Desc.Linkage)); |
David Blaikie | d0a869d | 2013-09-19 22:19:37 +0000 | [diff] [blame] | 2481 | Asm->EmitInt8(Desc.toBits()); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2484 | if (Asm->isVerbose()) |
| 2485 | Asm->OutStreamer.AddComment("External Name"); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2486 | Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength() + 1)); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | Asm->OutStreamer.AddComment("End Mark"); |
| 2490 | Asm->EmitInt32(0); |
| 2491 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end", ID)); |
| 2492 | } |
| 2493 | } |
| 2494 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2495 | void DwarfDebug::emitDebugPubTypes(bool GnuStyle) { |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2496 | const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection(); |
Eric Christopher | 261d234 | 2013-09-23 20:55:35 +0000 | [diff] [blame] | 2497 | const MCSection *PSec = |
| 2498 | GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection() |
| 2499 | : Asm->getObjFileLowering().getDwarfPubTypesSection(); |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2500 | |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2501 | for (SmallVectorImpl<CompileUnit *>::const_iterator I = getUnits().begin(), |
| 2502 | E = getUnits().end(); |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2503 | I != E; ++I) { |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 2504 | CompileUnit *TheCU = *I; |
Eric Christopher | 6abc9c5 | 2011-11-07 09:18:35 +0000 | [diff] [blame] | 2505 | // Start the dwarf pubtypes section. |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2506 | Asm->OutStreamer.SwitchSection(PSec); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2507 | |
| 2508 | // Emit a label so we can reference the beginning of this pubtype section. |
| 2509 | if (GnuStyle) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2510 | Asm->OutStreamer.EmitLabel( |
| 2511 | Asm->GetTempSymbol("gnu_pubtypes", TheCU->getUniqueID())); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2512 | |
| 2513 | // Emit the header. |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2514 | Asm->OutStreamer.AddComment("Length of Public Types Info"); |
| 2515 | Asm->EmitLabelDifference( |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2516 | Asm->GetTempSymbol("pubtypes_end", TheCU->getUniqueID()), |
| 2517 | Asm->GetTempSymbol("pubtypes_begin", TheCU->getUniqueID()), 4); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2518 | |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2519 | Asm->OutStreamer.EmitLabel( |
| 2520 | Asm->GetTempSymbol("pubtypes_begin", TheCU->getUniqueID())); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2521 | |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2522 | if (Asm->isVerbose()) |
| 2523 | Asm->OutStreamer.AddComment("DWARF Version"); |
David Majnemer | ed89b5c | 2013-08-21 06:13:34 +0000 | [diff] [blame] | 2524 | Asm->EmitInt16(dwarf::DW_PUBTYPES_VERSION); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2525 | |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2526 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2527 | Asm->EmitSectionOffset( |
| 2528 | Asm->GetTempSymbol(ISec->getLabelBeginName(), TheCU->getUniqueID()), |
| 2529 | DwarfInfoSectionSym); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2530 | |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2531 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2532 | Asm->EmitLabelDifference( |
| 2533 | Asm->GetTempSymbol(ISec->getLabelEndName(), TheCU->getUniqueID()), |
| 2534 | Asm->GetTempSymbol(ISec->getLabelBeginName(), TheCU->getUniqueID()), 4); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2535 | |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2536 | // Emit the pubtypes. |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 2537 | const StringMap<const DIE *> &Globals = TheCU->getGlobalTypes(); |
| 2538 | for (StringMap<const DIE *>::const_iterator GI = Globals.begin(), |
| 2539 | GE = Globals.end(); |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2540 | GI != GE; ++GI) { |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2541 | const char *Name = GI->getKeyData(); |
Eric Christopher | 0fe676a | 2013-11-21 00:48:22 +0000 | [diff] [blame] | 2542 | const DIE *Entity = GI->second; |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2543 | |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2544 | if (Asm->isVerbose()) |
| 2545 | Asm->OutStreamer.AddComment("DIE offset"); |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2546 | Asm->EmitInt32(Entity->getOffset()); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2547 | |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2548 | if (GnuStyle) { |
David Blaikie | d0a869d | 2013-09-19 22:19:37 +0000 | [diff] [blame] | 2549 | dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheCU, Entity); |
| 2550 | Asm->OutStreamer.AddComment( |
David Blaikie | efd0bcb | 2013-09-20 00:33:15 +0000 | [diff] [blame] | 2551 | Twine("Kind: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " + |
David Blaikie | 404d304 | 2013-09-19 23:01:29 +0000 | [diff] [blame] | 2552 | dwarf::GDBIndexEntryLinkageString(Desc.Linkage)); |
David Blaikie | d0a869d | 2013-09-19 22:19:37 +0000 | [diff] [blame] | 2553 | Asm->EmitInt8(Desc.toBits()); |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2556 | if (Asm->isVerbose()) |
| 2557 | Asm->OutStreamer.AddComment("External Name"); |
| 2558 | |
Benjamin Kramer | 966ed1b | 2011-11-09 18:16:11 +0000 | [diff] [blame] | 2559 | // Emit the name with a terminating null byte. |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2560 | Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength() + 1)); |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2561 | } |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2562 | |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2563 | Asm->OutStreamer.AddComment("End Mark"); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2564 | Asm->EmitInt32(0); |
Eric Christopher | 8b3737f | 2013-09-13 00:34:58 +0000 | [diff] [blame] | 2565 | Asm->OutStreamer.EmitLabel( |
| 2566 | Asm->GetTempSymbol("pubtypes_end", TheCU->getUniqueID())); |
Devang Patel | 04d2f2d | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2567 | } |
Devang Patel | 04d2f2d | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 2570 | // Emit strings into a string section. |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 2571 | void DwarfUnits::emitStrings(const MCSection *StrSection, |
| 2572 | const MCSection *OffsetSection = NULL, |
| 2573 | const MCSymbol *StrSecSym = NULL) { |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 2574 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2575 | if (StringPool.empty()) |
| 2576 | return; |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2577 | |
Chris Lattner | 3d72a67 | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2578 | // Start the dwarf str section. |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 2579 | Asm->OutStreamer.SwitchSection(StrSection); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2580 | |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2581 | // Get all of the string pool entries and put them in an array by their ID so |
| 2582 | // we can sort them. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2583 | SmallVector< |
| 2584 | std::pair<unsigned, StringMapEntry<std::pair<MCSymbol *, unsigned> > *>, |
| 2585 | 64> Entries; |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2586 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2587 | for (StringMap<std::pair<MCSymbol *, unsigned> >::iterator |
| 2588 | I = StringPool.begin(), |
| 2589 | E = StringPool.end(); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 2590 | I != E; ++I) |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2591 | Entries.push_back(std::make_pair(I->second.second, &*I)); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2592 | |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2593 | array_pod_sort(Entries.begin(), Entries.end()); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2594 | |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2595 | for (unsigned i = 0, e = Entries.size(); i != e; ++i) { |
Chris Lattner | 3d72a67 | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2596 | // Emit a label for reference from debug information entries. |
Chris Lattner | b7aa952 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2597 | Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first); |
Jim Grosbach | a8683bb | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2598 | |
Benjamin Kramer | 966ed1b | 2011-11-09 18:16:11 +0000 | [diff] [blame] | 2599 | // Emit the string itself with a terminating null byte. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2600 | Asm->OutStreamer.EmitBytes( |
| 2601 | StringRef(Entries[i].second->getKeyData(), |
| 2602 | Entries[i].second->getKeyLength() + 1)); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2603 | } |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 2604 | |
| 2605 | // If we've got an offset section go ahead and emit that now as well. |
| 2606 | if (OffsetSection) { |
| 2607 | Asm->OutStreamer.SwitchSection(OffsetSection); |
| 2608 | unsigned offset = 0; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2609 | unsigned size = 4; // FIXME: DWARF64 is 8. |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 2610 | for (unsigned i = 0, e = Entries.size(); i != e; ++i) { |
Eric Christopher | bf7bc49 | 2013-01-09 03:52:05 +0000 | [diff] [blame] | 2611 | Asm->OutStreamer.EmitIntValue(offset, size); |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 2612 | offset += Entries[i].second->getKeyLength() + 1; |
| 2613 | } |
| 2614 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
Eric Christopher | 65132a8 | 2013-11-19 09:11:26 +0000 | [diff] [blame] | 2617 | |
| 2618 | // Emit addresses into the section given. |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2619 | void DwarfUnits::emitAddresses(const MCSection *AddrSection) { |
| 2620 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2621 | if (AddressPool.empty()) |
| 2622 | return; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2623 | |
| 2624 | // Start the dwarf addr section. |
| 2625 | Asm->OutStreamer.SwitchSection(AddrSection); |
| 2626 | |
David Blaikie | ce1960f | 2013-07-08 17:51:28 +0000 | [diff] [blame] | 2627 | // Order the address pool entries by ID |
David Blaikie | ac569a6 | 2013-07-08 17:33:10 +0000 | [diff] [blame] | 2628 | SmallVector<const MCExpr *, 64> Entries(AddressPool.size()); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2629 | |
David Blaikie | ce1960f | 2013-07-08 17:51:28 +0000 | [diff] [blame] | 2630 | for (DenseMap<const MCExpr *, unsigned>::iterator I = AddressPool.begin(), |
| 2631 | E = AddressPool.end(); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2632 | I != E; ++I) |
David Blaikie | ac569a6 | 2013-07-08 17:33:10 +0000 | [diff] [blame] | 2633 | Entries[I->second] = I->first; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2634 | |
| 2635 | for (unsigned i = 0, e = Entries.size(); i != e; ++i) { |
Ulrich Weigand | 8b3d226 | 2013-07-02 18:46:46 +0000 | [diff] [blame] | 2636 | // Emit an expression for reference from debug information entries. |
David Blaikie | ac569a6 | 2013-07-08 17:33:10 +0000 | [diff] [blame] | 2637 | if (const MCExpr *Expr = Entries[i]) |
Ulrich Weigand | 8b3d226 | 2013-07-02 18:46:46 +0000 | [diff] [blame] | 2638 | Asm->OutStreamer.EmitValue(Expr, Asm->getDataLayout().getPointerSize()); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2639 | else |
| 2640 | Asm->OutStreamer.EmitIntValue(0, Asm->getDataLayout().getPointerSize()); |
| 2641 | } |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 2644 | // Emit visible names into a debug str section. |
| 2645 | void DwarfDebug::emitDebugStr() { |
| 2646 | DwarfUnits &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder; |
| 2647 | Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection()); |
| 2648 | } |
| 2649 | |
Eric Christopher | 9046f94 | 2013-07-02 21:36:07 +0000 | [diff] [blame] | 2650 | // Emit locations into the debug loc section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2651 | void DwarfDebug::emitDebugLoc() { |
Devang Patel | 6b9a9fe | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2652 | if (DotDebugLocEntries.empty()) |
| 2653 | return; |
| 2654 | |
Eric Christopher | 4887c8f | 2013-03-29 23:34:06 +0000 | [diff] [blame] | 2655 | for (SmallVectorImpl<DotDebugLocEntry>::iterator |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2656 | I = DotDebugLocEntries.begin(), |
| 2657 | E = DotDebugLocEntries.end(); |
Devang Patel | 116a9d7 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2658 | I != E; ++I) { |
| 2659 | DotDebugLocEntry &Entry = *I; |
| 2660 | if (I + 1 != DotDebugLocEntries.end()) |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2661 | Entry.Merge(I + 1); |
Devang Patel | 116a9d7 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Daniel Dunbar | fd95b01 | 2011-03-16 22:16:39 +0000 | [diff] [blame] | 2664 | // Start the dwarf loc section. |
Chris Lattner | 4b7dadb | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2665 | Asm->OutStreamer.SwitchSection( |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2666 | Asm->getObjFileLowering().getDwarfLocSection()); |
Chandler Carruth | 5da3f05 | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2667 | unsigned char Size = Asm->getDataLayout().getPointerSize(); |
Devang Patel | 6b9a9fe | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2668 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0)); |
| 2669 | unsigned index = 1; |
Eric Christopher | 4887c8f | 2013-03-29 23:34:06 +0000 | [diff] [blame] | 2670 | for (SmallVectorImpl<DotDebugLocEntry>::iterator |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2671 | I = DotDebugLocEntries.begin(), |
| 2672 | E = DotDebugLocEntries.end(); |
Devang Patel | 30265c4 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 2673 | I != E; ++I, ++index) { |
Devang Patel | 116a9d7 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2674 | DotDebugLocEntry &Entry = *I; |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2675 | if (Entry.isMerged()) |
| 2676 | continue; |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2677 | if (Entry.isEmpty()) { |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 2678 | Asm->OutStreamer.EmitIntValue(0, Size); |
| 2679 | Asm->OutStreamer.EmitIntValue(0, Size); |
Devang Patel | 6b9a9fe | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2680 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index)); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2681 | } else { |
Eric Christopher | 25f0642 | 2013-07-03 22:40:18 +0000 | [diff] [blame] | 2682 | Asm->OutStreamer.EmitSymbolValue(Entry.getBeginSym(), Size); |
| 2683 | Asm->OutStreamer.EmitSymbolValue(Entry.getEndSym(), Size); |
| 2684 | DIVariable DV(Entry.getVariable()); |
Rafael Espindola | d23bfb8 | 2011-05-27 22:05:41 +0000 | [diff] [blame] | 2685 | Asm->OutStreamer.AddComment("Loc expr size"); |
| 2686 | MCSymbol *begin = Asm->OutStreamer.getContext().CreateTempSymbol(); |
| 2687 | MCSymbol *end = Asm->OutStreamer.getContext().CreateTempSymbol(); |
| 2688 | Asm->EmitLabelDifference(end, begin, 2); |
| 2689 | Asm->OutStreamer.EmitLabel(begin); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2690 | if (Entry.isInt()) { |
Devang Patel | 324f843 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2691 | DIBasicType BTy(DV.getType()); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2692 | if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed || |
| 2693 | BTy.getEncoding() == dwarf::DW_ATE_signed_char)) { |
Devang Patel | 324f843 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2694 | Asm->OutStreamer.AddComment("DW_OP_consts"); |
| 2695 | Asm->EmitInt8(dwarf::DW_OP_consts); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2696 | Asm->EmitSLEB128(Entry.getInt()); |
Devang Patel | 324f843 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2697 | } else { |
| 2698 | Asm->OutStreamer.AddComment("DW_OP_constu"); |
| 2699 | Asm->EmitInt8(dwarf::DW_OP_constu); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2700 | Asm->EmitULEB128(Entry.getInt()); |
Devang Patel | 324f843 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2701 | } |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2702 | } else if (Entry.isLocation()) { |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2703 | MachineLocation Loc = Entry.getLoc(); |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 2704 | if (!DV.hasComplexAddress()) |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2705 | // Regular entry. |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2706 | Asm->EmitDwarfRegOp(Loc, DV.isIndirect()); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2707 | else { |
| 2708 | // Complex address entry. |
| 2709 | unsigned N = DV.getNumAddrElements(); |
| 2710 | unsigned i = 0; |
| 2711 | if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) { |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2712 | if (Loc.getOffset()) { |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2713 | i = 2; |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2714 | Asm->EmitDwarfRegOp(Loc, DV.isIndirect()); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2715 | Asm->OutStreamer.AddComment("DW_OP_deref"); |
| 2716 | Asm->EmitInt8(dwarf::DW_OP_deref); |
| 2717 | Asm->OutStreamer.AddComment("DW_OP_plus_uconst"); |
| 2718 | Asm->EmitInt8(dwarf::DW_OP_plus_uconst); |
| 2719 | Asm->EmitSLEB128(DV.getAddrElement(1)); |
| 2720 | } else { |
| 2721 | // If first address element is OpPlus then emit |
| 2722 | // DW_OP_breg + Offset instead of DW_OP_reg + Offset. |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2723 | MachineLocation TLoc(Loc.getReg(), DV.getAddrElement(1)); |
| 2724 | Asm->EmitDwarfRegOp(TLoc, DV.isIndirect()); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2725 | i = 2; |
| 2726 | } |
| 2727 | } else { |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2728 | Asm->EmitDwarfRegOp(Loc, DV.isIndirect()); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2729 | } |
Eric Christopher | 6a84138 | 2012-11-19 22:42:10 +0000 | [diff] [blame] | 2730 | |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2731 | // Emit remaining complex address elements. |
| 2732 | for (; i < N; ++i) { |
| 2733 | uint64_t Element = DV.getAddrElement(i); |
| 2734 | if (Element == DIBuilder::OpPlus) { |
| 2735 | Asm->EmitInt8(dwarf::DW_OP_plus_uconst); |
| 2736 | Asm->EmitULEB128(DV.getAddrElement(++i)); |
Eric Christopher | 4d25052 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 2737 | } else if (Element == DIBuilder::OpDeref) { |
Eric Christopher | 614a89f | 2013-07-03 22:40:21 +0000 | [diff] [blame] | 2738 | if (!Loc.isReg()) |
Eric Christopher | 4d25052 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 2739 | Asm->EmitInt8(dwarf::DW_OP_deref); |
| 2740 | } else |
| 2741 | llvm_unreachable("unknown Opcode found in complex address"); |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2742 | } |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2743 | } |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2744 | } |
Devang Patel | ed9fd45 | 2011-07-08 16:49:43 +0000 | [diff] [blame] | 2745 | // else ... ignore constant fp. There is not any good way to |
| 2746 | // to represent them here in dwarf. |
Rafael Espindola | d23bfb8 | 2011-05-27 22:05:41 +0000 | [diff] [blame] | 2747 | Asm->OutStreamer.EmitLabel(end); |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2748 | } |
| 2749 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2752 | struct SymbolCUSorter { |
| 2753 | SymbolCUSorter(const MCStreamer &s) : Streamer(s) {} |
| 2754 | const MCStreamer &Streamer; |
| 2755 | |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2756 | bool operator()(const SymbolCU &A, const SymbolCU &B) { |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2757 | unsigned IA = A.Sym ? Streamer.GetSymbolOrder(A.Sym) : 0; |
| 2758 | unsigned IB = B.Sym ? Streamer.GetSymbolOrder(B.Sym) : 0; |
| 2759 | |
| 2760 | // Symbols with no order assigned should be placed at the end. |
| 2761 | // (e.g. section end labels) |
| 2762 | if (IA == 0) |
| 2763 | IA = (unsigned)(-1); |
| 2764 | if (IB == 0) |
| 2765 | IB = (unsigned)(-1); |
| 2766 | return IA < IB; |
| 2767 | } |
| 2768 | }; |
| 2769 | |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2770 | static bool CUSort(const CompileUnit *A, const CompileUnit *B) { |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2771 | return (A->getUniqueID() < B->getUniqueID()); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | struct ArangeSpan { |
| 2775 | const MCSymbol *Start, *End; |
| 2776 | }; |
| 2777 | |
| 2778 | // Emit a debug aranges section, containing a CU lookup for any |
| 2779 | // address we can tie back to a CU. |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 2780 | void DwarfDebug::emitDebugARanges() { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2781 | // Start the dwarf aranges section. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2782 | Asm->OutStreamer.SwitchSection( |
| 2783 | Asm->getObjFileLowering().getDwarfARangesSection()); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2784 | |
| 2785 | typedef DenseMap<CompileUnit *, std::vector<ArangeSpan> > SpansType; |
| 2786 | |
| 2787 | SpansType Spans; |
| 2788 | |
| 2789 | // Build a list of sections used. |
| 2790 | std::vector<const MCSection *> Sections; |
| 2791 | for (SectionMapType::iterator it = SectionMap.begin(); it != SectionMap.end(); |
| 2792 | it++) { |
| 2793 | const MCSection *Section = it->first; |
| 2794 | Sections.push_back(Section); |
| 2795 | } |
| 2796 | |
| 2797 | // Sort the sections into order. |
| 2798 | // This is only done to ensure consistent output order across different runs. |
| 2799 | std::sort(Sections.begin(), Sections.end(), SectionSort); |
| 2800 | |
| 2801 | // Build a set of address spans, sorted by CU. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2802 | for (size_t SecIdx = 0; SecIdx < Sections.size(); SecIdx++) { |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2803 | const MCSection *Section = Sections[SecIdx]; |
| 2804 | SmallVector<SymbolCU, 8> &List = SectionMap[Section]; |
| 2805 | if (List.size() < 2) |
| 2806 | continue; |
| 2807 | |
| 2808 | // Sort the symbols by offset within the section. |
| 2809 | SymbolCUSorter sorter(Asm->OutStreamer); |
| 2810 | std::sort(List.begin(), List.end(), sorter); |
| 2811 | |
| 2812 | // If we have no section (e.g. common), just write out |
| 2813 | // individual spans for each symbol. |
| 2814 | if (Section == NULL) { |
| 2815 | for (size_t n = 0; n < List.size(); n++) { |
| 2816 | const SymbolCU &Cur = List[n]; |
| 2817 | |
| 2818 | ArangeSpan Span; |
| 2819 | Span.Start = Cur.Sym; |
| 2820 | Span.End = NULL; |
| 2821 | if (Cur.CU) |
| 2822 | Spans[Cur.CU].push_back(Span); |
| 2823 | } |
| 2824 | } else { |
| 2825 | // Build spans between each label. |
| 2826 | const MCSymbol *StartSym = List[0].Sym; |
| 2827 | for (size_t n = 1; n < List.size(); n++) { |
| 2828 | const SymbolCU &Prev = List[n - 1]; |
| 2829 | const SymbolCU &Cur = List[n]; |
| 2830 | |
| 2831 | // Try and build the longest span we can within the same CU. |
| 2832 | if (Cur.CU != Prev.CU) { |
| 2833 | ArangeSpan Span; |
| 2834 | Span.Start = StartSym; |
| 2835 | Span.End = Cur.Sym; |
| 2836 | Spans[Prev.CU].push_back(Span); |
| 2837 | StartSym = Cur.Sym; |
| 2838 | } |
| 2839 | } |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection(); |
| 2844 | unsigned PtrSize = Asm->getDataLayout().getPointerSize(); |
| 2845 | |
| 2846 | // Build a list of CUs used. |
| 2847 | std::vector<CompileUnit *> CUs; |
| 2848 | for (SpansType::iterator it = Spans.begin(); it != Spans.end(); it++) { |
| 2849 | CompileUnit *CU = it->first; |
| 2850 | CUs.push_back(CU); |
| 2851 | } |
| 2852 | |
| 2853 | // Sort the CU list (again, to ensure consistent output order). |
| 2854 | std::sort(CUs.begin(), CUs.end(), CUSort); |
| 2855 | |
| 2856 | // Emit an arange table for each CU we used. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2857 | for (size_t CUIdx = 0; CUIdx < CUs.size(); CUIdx++) { |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2858 | CompileUnit *CU = CUs[CUIdx]; |
| 2859 | std::vector<ArangeSpan> &List = Spans[CU]; |
| 2860 | |
| 2861 | // Emit size of content not including length itself. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2862 | unsigned ContentSize = |
| 2863 | sizeof(int16_t) + // DWARF ARange version number |
| 2864 | sizeof(int32_t) + // Offset of CU in the .debug_info section |
| 2865 | sizeof(int8_t) + // Pointer Size (in bytes) |
| 2866 | sizeof(int8_t); // Segment Size (in bytes) |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2867 | |
| 2868 | unsigned TupleSize = PtrSize * 2; |
| 2869 | |
| 2870 | // 7.20 in the Dwarf specs requires the table to be aligned to a tuple. |
| 2871 | unsigned Padding = 0; |
| 2872 | while (((sizeof(int32_t) + ContentSize + Padding) % TupleSize) != 0) |
| 2873 | Padding++; |
| 2874 | |
| 2875 | ContentSize += Padding; |
| 2876 | ContentSize += (List.size() + 1) * TupleSize; |
| 2877 | |
| 2878 | // For each compile unit, write the list of spans it covers. |
| 2879 | Asm->OutStreamer.AddComment("Length of ARange Set"); |
| 2880 | Asm->EmitInt32(ContentSize); |
| 2881 | Asm->OutStreamer.AddComment("DWARF Arange version number"); |
| 2882 | Asm->EmitInt16(dwarf::DW_ARANGES_VERSION); |
| 2883 | Asm->OutStreamer.AddComment("Offset Into Debug Info Section"); |
| 2884 | Asm->EmitSectionOffset( |
| 2885 | Asm->GetTempSymbol(ISec->getLabelBeginName(), CU->getUniqueID()), |
| 2886 | DwarfInfoSectionSym); |
| 2887 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
| 2888 | Asm->EmitInt8(PtrSize); |
| 2889 | Asm->OutStreamer.AddComment("Segment Size (in bytes)"); |
| 2890 | Asm->EmitInt8(0); |
| 2891 | |
| 2892 | for (unsigned n = 0; n < Padding; n++) |
| 2893 | Asm->EmitInt8(0xff); |
| 2894 | |
| 2895 | for (unsigned n = 0; n < List.size(); n++) { |
| 2896 | const ArangeSpan &Span = List[n]; |
| 2897 | Asm->EmitLabelReference(Span.Start, PtrSize); |
| 2898 | |
| 2899 | // Calculate the size as being from the span start to it's end. |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 2900 | if (Span.End) { |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2901 | Asm->EmitLabelDifference(Span.End, Span.Start, PtrSize); |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 2902 | } else { |
| 2903 | // For symbols without an end marker (e.g. common), we |
| 2904 | // write a single arange entry containing just that one symbol. |
| 2905 | uint64_t Size = SymSize[Span.Start]; |
| 2906 | if (Size == 0) |
| 2907 | Size = 1; |
| 2908 | |
| 2909 | Asm->OutStreamer.EmitIntValue(Size, PtrSize); |
| 2910 | } |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | Asm->OutStreamer.AddComment("ARange terminator"); |
| 2914 | Asm->OutStreamer.EmitIntValue(0, PtrSize); |
| 2915 | Asm->OutStreamer.EmitIntValue(0, PtrSize); |
| 2916 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2919 | // Emit visible names into a debug ranges section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2920 | void DwarfDebug::emitDebugRanges() { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2921 | // Start the dwarf ranges section. |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2922 | Asm->OutStreamer.SwitchSection( |
| 2923 | Asm->getObjFileLowering().getDwarfRangesSection()); |
Chandler Carruth | 5da3f05 | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 2924 | unsigned char Size = Asm->getDataLayout().getPointerSize(); |
Eric Christopher | 4751d70 | 2013-11-23 00:05:29 +0000 | [diff] [blame] | 2925 | for (uint32_t i = 0, e = DebugRangeSymbols.size(); i < e; ++i) { |
| 2926 | // Only emit a symbol for every range pair for now. |
| 2927 | // FIXME: Make this per range list. |
| 2928 | if ((i % 2) == 0) |
| 2929 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_ranges", i)); |
| 2930 | |
| 2931 | const MCSymbol *I = DebugRangeSymbols[i]; |
| 2932 | if (I) |
| 2933 | Asm->OutStreamer.EmitSymbolValue(I, Size); |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2934 | else |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 2935 | Asm->OutStreamer.EmitIntValue(0, Size); |
Devang Patel | 12563b3 | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2936 | } |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 2939 | // Emit visible names into a debug macinfo section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2940 | void DwarfDebug::emitDebugMacInfo() { |
Daniel Dunbar | c418d6b | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 2941 | if (const MCSection *LineInfo = |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 2942 | Asm->getObjFileLowering().getDwarfMacroInfoSection()) { |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2943 | // Start the dwarf macinfo section. |
Chris Lattner | 4b7dadb | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2944 | Asm->OutStreamer.SwitchSection(LineInfo); |
Bill Wendling | 480ff32 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2945 | } |
| 2946 | } |
| 2947 | |
Eric Christopher | d692c1d | 2012-12-11 19:42:09 +0000 | [diff] [blame] | 2948 | // DWARF5 Experimental Separate Dwarf emitters. |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2949 | |
| 2950 | // This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list, |
| 2951 | // DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id, |
Eric Christopher | 9a08f9e | 2013-10-01 00:43:36 +0000 | [diff] [blame] | 2952 | // DW_AT_ranges_base, DW_AT_addr_base. |
Eric Christopher | 6fdf324 | 2013-08-26 23:50:43 +0000 | [diff] [blame] | 2953 | CompileUnit *DwarfDebug::constructSkeletonCU(const CompileUnit *CU) { |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2954 | |
| 2955 | DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); |
David Blaikie | b01f13e | 2013-11-15 23:54:45 +0000 | [diff] [blame] | 2956 | CompileUnit *NewCU = new CompileUnit(CU->getUniqueID(), Die, CU->getNode(), |
| 2957 | Asm, this, &SkeletonHolder); |
Eric Christopher | 4c7765f | 2013-01-17 03:00:04 +0000 | [diff] [blame] | 2958 | |
Eric Christopher | dae389b | 2013-02-22 23:50:08 +0000 | [diff] [blame] | 2959 | NewCU->addLocalString(Die, dwarf::DW_AT_GNU_dwo_name, |
David Blaikie | b01f13e | 2013-11-15 23:54:45 +0000 | [diff] [blame] | 2960 | CU->getNode().getSplitDebugFilename()); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2961 | |
Eric Christopher | 44c6aa6 | 2013-04-22 07:51:08 +0000 | [diff] [blame] | 2962 | // Relocate to the beginning of the addr_base section, else 0 for the |
| 2963 | // beginning of the one for this compile unit. |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 2964 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2965 | NewCU->addSectionLabel(Die, dwarf::DW_AT_GNU_addr_base, |
| 2966 | DwarfAddrSectionSym); |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 2967 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2968 | NewCU->addSectionOffset(Die, dwarf::DW_AT_GNU_addr_base, 0); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2969 | |
| 2970 | // 2.17.1 requires that we use DW_AT_low_pc for a single entry point |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2971 | // into an entity. We're using 0, or a NULL label for this. |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2972 | NewCU->addUInt(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 2973 | |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2974 | // DW_AT_stmt_list is a offset of line number information for this |
| 2975 | // compile unit in debug_line section. |
Eric Christopher | 55863be | 2013-04-07 03:43:09 +0000 | [diff] [blame] | 2976 | // FIXME: Should handle multiple compile units. |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2977 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2978 | NewCU->addSectionLabel(Die, dwarf::DW_AT_stmt_list, |
| 2979 | DwarfLineSectionSym); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2980 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2981 | NewCU->addSectionOffset(Die, dwarf::DW_AT_stmt_list, 0); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2982 | |
| 2983 | if (!CompilationDir.empty()) |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 2984 | NewCU->addLocalString(Die, dwarf::DW_AT_comp_dir, CompilationDir); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 2985 | |
Eric Christopher | 1d06eb5 | 2013-10-01 00:43:31 +0000 | [diff] [blame] | 2986 | // Flags to let the linker know we have emitted new style pubnames. |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2987 | if (GenerateGnuPubSections) { |
| 2988 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2989 | NewCU->addSectionLabel( |
| 2990 | Die, dwarf::DW_AT_GNU_pubnames, |
| 2991 | Asm->GetTempSymbol("gnu_pubnames", NewCU->getUniqueID())); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2992 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2993 | NewCU->addSectionDelta( |
| 2994 | Die, dwarf::DW_AT_GNU_pubnames, |
| 2995 | Asm->GetTempSymbol("gnu_pubnames", NewCU->getUniqueID()), |
| 2996 | DwarfGnuPubNamesSectionSym); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 2997 | |
| 2998 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 2999 | NewCU->addSectionLabel( |
| 3000 | Die, dwarf::DW_AT_GNU_pubtypes, |
| 3001 | Asm->GetTempSymbol("gnu_pubtypes", NewCU->getUniqueID())); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 3002 | else |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 3003 | NewCU->addSectionDelta( |
| 3004 | Die, dwarf::DW_AT_GNU_pubtypes, |
| 3005 | Asm->GetTempSymbol("gnu_pubtypes", NewCU->getUniqueID()), |
| 3006 | DwarfGnuPubTypesSectionSym); |
Eric Christopher | 39eebfa | 2013-09-30 23:14:16 +0000 | [diff] [blame] | 3007 | } |
Eric Christopher | dd1a012 | 2013-09-13 00:35:05 +0000 | [diff] [blame] | 3008 | |
Eric Christopher | 9a08f9e | 2013-10-01 00:43:36 +0000 | [diff] [blame] | 3009 | // Flag if we've emitted any ranges and their location for the compile unit. |
| 3010 | if (DebugRangeSymbols.size()) { |
| 3011 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 3012 | NewCU->addSectionLabel(Die, dwarf::DW_AT_GNU_ranges_base, |
| 3013 | DwarfDebugRangeSectionSym); |
Eric Christopher | 9a08f9e | 2013-10-01 00:43:36 +0000 | [diff] [blame] | 3014 | else |
| 3015 | NewCU->addUInt(Die, dwarf::DW_AT_GNU_ranges_base, dwarf::DW_FORM_data4, |
| 3016 | 0); |
| 3017 | } |
| 3018 | |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 3019 | SkeletonHolder.addUnit(NewCU); |
| 3020 | |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 3021 | return NewCU; |
| 3022 | } |
| 3023 | |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 3024 | void DwarfDebug::emitSkeletonAbbrevs(const MCSection *Section) { |
| 3025 | assert(useSplitDwarf() && "No split dwarf debug info?"); |
| 3026 | emitAbbrevs(Section, &SkeletonAbbrevs); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
Eric Christopher | d692c1d | 2012-12-11 19:42:09 +0000 | [diff] [blame] | 3029 | // Emit the .debug_info.dwo section for separated dwarf. This contains the |
| 3030 | // compile units that would normally be in debug_info. |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 3031 | void DwarfDebug::emitDebugInfoDWO() { |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 3032 | assert(useSplitDwarf() && "No split dwarf debug info?"); |
Eric Christopher | a2de826 | 2012-12-15 00:04:07 +0000 | [diff] [blame] | 3033 | InfoHolder.emitUnits(this, Asm->getObjFileLowering().getDwarfInfoDWOSection(), |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 3034 | Asm->getObjFileLowering().getDwarfAbbrevDWOSection(), |
| 3035 | DwarfAbbrevDWOSectionSym); |
| 3036 | } |
| 3037 | |
| 3038 | // Emit the .debug_abbrev.dwo section for separated dwarf. This contains the |
| 3039 | // abbreviations for the .debug_info.dwo section. |
| 3040 | void DwarfDebug::emitDebugAbbrevDWO() { |
| 3041 | assert(useSplitDwarf() && "No split dwarf?"); |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 3042 | emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection(), |
| 3043 | &Abbreviations); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 3044 | } |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 3045 | |
| 3046 | // Emit the .debug_str.dwo section for separated dwarf. This contains the |
| 3047 | // string section and is identical in format to traditional .debug_str |
| 3048 | // sections. |
| 3049 | void DwarfDebug::emitDebugStrDWO() { |
| 3050 | assert(useSplitDwarf() && "No split dwarf?"); |
Eric Christopher | b4bef6d | 2013-11-19 09:04:36 +0000 | [diff] [blame] | 3051 | const MCSection *OffSec = |
| 3052 | Asm->getObjFileLowering().getDwarfStrOffDWOSection(); |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 3053 | const MCSymbol *StrSym = DwarfStrSectionSym; |
| 3054 | InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(), |
| 3055 | OffSec, StrSym); |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 3056 | } |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 3057 | |
David Blaikie | 3c1d332 | 2013-12-02 18:44:29 +0000 | [diff] [blame^] | 3058 | void DwarfDebug::addTypeUnitType(uint16_t Language, DIE *RefDie, |
| 3059 | DICompositeType CTy) { |
Eric Christopher | f52eddf | 2013-11-26 22:23:27 +0000 | [diff] [blame] | 3060 | DenseMap<const MDNode *, |
| 3061 | std::pair<uint64_t, SmallVectorImpl<DIE *> *> >::iterator I = |
| 3062 | TypeUnits.find(CTy); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 3063 | SmallVector<DIE *, 8> References; |
| 3064 | References.push_back(RefDie); |
| 3065 | if (I != TypeUnits.end()) { |
| 3066 | if (I->second.second) { |
| 3067 | I->second.second->push_back(RefDie); |
| 3068 | return; |
| 3069 | } |
| 3070 | } else { |
| 3071 | DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit); |
David Blaikie | 3c1d332 | 2013-12-02 18:44:29 +0000 | [diff] [blame^] | 3072 | CompileUnit *NewCU = new CompileUnit(GlobalCUIndexCount++, UnitDie, |
| 3073 | Language, Asm, this, &InfoHolder); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 3074 | CUDieMap.insert(std::make_pair(UnitDie, NewCU)); |
| 3075 | NewCU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2, |
David Blaikie | 3c1d332 | 2013-12-02 18:44:29 +0000 | [diff] [blame^] | 3076 | Language); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 3077 | |
| 3078 | // Register the type in the TypeUnits map with a vector of references to be |
| 3079 | // populated whenever a reference is required. |
| 3080 | I = TypeUnits.insert(std::make_pair(CTy, std::make_pair(0, &References))) |
| 3081 | .first; |
| 3082 | |
| 3083 | // Construct the type, this may, recursively, require more type units that |
| 3084 | // may in turn require this type again - in which case they will add DIEs to |
| 3085 | // the References vector. |
| 3086 | DIE *Die = NewCU->createTypeDIE(CTy); |
| 3087 | |
| 3088 | if (GenerateODRHash && shouldAddODRHash(NewCU, Die)) |
| 3089 | NewCU->addUInt(UnitDie, dwarf::DW_AT_GNU_odr_signature, |
| 3090 | dwarf::DW_FORM_data8, |
| 3091 | DIEHash().computeDIEODRSignature(*Die)); |
| 3092 | // FIXME: This won't handle circularly referential structures, as the DIE |
| 3093 | // may have references to other DIEs still under construction and missing |
| 3094 | // their signature. Hashing should walk through the signatures to their |
| 3095 | // referenced type, or possibly walk the precomputed hashes of related types |
| 3096 | // at the end. |
| 3097 | uint64_t Signature = DIEHash().computeTypeSignature(*Die); |
| 3098 | |
| 3099 | // Remove the References vector and add the type hash. |
| 3100 | I->second.first = Signature; |
| 3101 | I->second.second = NULL; |
| 3102 | |
| 3103 | |
| 3104 | InfoHolder.addUnit(NewCU); |
| 3105 | } |
| 3106 | |
| 3107 | // Populate all the signatures. |
| 3108 | for (unsigned i = 0, e = References.size(); i != e; ++i) { |
| 3109 | CUMap.begin()->second->addUInt(References[i], dwarf::DW_AT_signature, |
| 3110 | dwarf::DW_FORM_ref_sig8, I->second.first); |
| 3111 | } |
| 3112 | } |