blob: 1738dce3c4c97edd53f82bd6272d5d8f55187ece [file] [log] [blame]
Bill Wendling2f921f82009-05-15 09:23:25 +00001//===-- 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 Lattnerb14490d2010-03-09 00:39:24 +000013
Bill Wendling2f921f82009-05-15 09:23:25 +000014#include "DwarfDebug.h"
David Blaikie37c52312014-10-04 15:49:50 +000015
16#include "ByteStreamer.h"
Adrian Prantl66f25952015-01-13 00:04:06 +000017#include "DwarfExpression.h"
David Blaikie37c52312014-10-04 15:49:50 +000018#include "DwarfCompileUnit.h"
Eric Christopher45731982013-08-08 23:45:55 +000019#include "DIEHash.h"
David Blaikie2c86a722013-12-02 19:33:15 +000020#include "DwarfUnit.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/Statistic.h"
23#include "llvm/ADT/StringExtras.h"
24#include "llvm/ADT/Triple.h"
Frederic Risse541e0b2015-01-05 21:29:41 +000025#include "llvm/CodeGen/DIE.h"
David Greene829b3e82009-08-19 21:52:55 +000026#include "llvm/CodeGen/MachineFunction.h"
Bill Wendling2f921f82009-05-15 09:23:25 +000027#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000028#include "llvm/IR/Constants.h"
Chandler Carruth12664a02014-03-06 00:22:06 +000029#include "llvm/IR/DIBuilder.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000030#include "llvm/IR/DataLayout.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000031#include "llvm/IR/DebugInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000032#include "llvm/IR/Instructions.h"
33#include "llvm/IR/Module.h"
Chandler Carruth4220e9c2014-03-04 11:17:44 +000034#include "llvm/IR/ValueHandle.h"
Chris Lattnere13c3722010-03-09 01:58:53 +000035#include "llvm/MC/MCAsmInfo.h"
Chris Lattner4d2c0f92009-07-31 18:48:30 +000036#include "llvm/MC/MCSection.h"
Chris Lattner4b7dadb2009-08-19 05:49:37 +000037#include "llvm/MC/MCStreamer.h"
Chris Lattnere13c3722010-03-09 01:58:53 +000038#include "llvm/MC/MCSymbol.h"
Devang Patel6c74a872010-04-27 19:46:33 +000039#include "llvm/Support/CommandLine.h"
Daniel Dunbarcdf01b52009-10-13 06:47:08 +000040#include "llvm/Support/Debug.h"
David Majnemered89b5c2013-08-21 06:13:34 +000041#include "llvm/Support/Dwarf.h"
Saleem Abdulrasool271ac582014-07-14 16:28:09 +000042#include "llvm/Support/Endian.h"
Daniel Dunbarcdf01b52009-10-13 06:47:08 +000043#include "llvm/Support/ErrorHandling.h"
Chris Lattnerf5c834f2010-01-22 22:09:00 +000044#include "llvm/Support/FormattedStream.h"
Logan Chien5b776b72014-02-22 14:00:39 +000045#include "llvm/Support/LEB128.h"
Eric Christopher67646432013-07-26 17:02:41 +000046#include "llvm/Support/MD5.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000047#include "llvm/Support/Path.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000048#include "llvm/Support/Timer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000049#include "llvm/Target/TargetFrameLowering.h"
50#include "llvm/Target/TargetLoweringObjectFile.h"
51#include "llvm/Target/TargetMachine.h"
52#include "llvm/Target/TargetOptions.h"
53#include "llvm/Target/TargetRegisterInfo.h"
Eric Christopherd9134482014-08-04 21:25:23 +000054#include "llvm/Target/TargetSubtargetInfo.h"
Bill Wendling2f921f82009-05-15 09:23:25 +000055using namespace llvm;
56
Chandler Carruth1b9dde02014-04-22 02:02:50 +000057#define DEBUG_TYPE "dwarfdebug"
58
Eric Christopher7f2b5512013-07-23 22:16:41 +000059static cl::opt<bool>
60DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
61 cl::desc("Disable debug info printing"));
Devang Patel6c74a872010-04-27 19:46:33 +000062
Eric Christopher7f2b5512013-07-23 22:16:41 +000063static cl::opt<bool> UnknownLocations(
64 "use-unknown-locations", cl::Hidden,
65 cl::desc("Make an absence of debug location information explicit."),
66 cl::init(false));
Dan Gohman7421ae42010-05-07 01:08:53 +000067
Eric Christopherdd1a0122013-09-13 00:35:05 +000068static cl::opt<bool>
69GenerateGnuPubSections("generate-gnu-dwarf-pub-sections", cl::Hidden,
70 cl::desc("Generate GNU-style pubnames and pubtypes"),
71 cl::init(false));
72
Eric Christopher02dbadb2014-02-14 01:26:55 +000073static cl::opt<bool> GenerateARangeSection("generate-arange-section",
74 cl::Hidden,
75 cl::desc("Generate dwarf aranges"),
76 cl::init(false));
77
Eric Christopher20b76a72012-08-23 22:36:40 +000078namespace {
Eric Christopherf07ee3a2014-01-27 23:50:03 +000079enum DefaultOnOff { Default, Enable, Disable };
Eric Christopher20b76a72012-08-23 22:36:40 +000080}
Eric Christopher4996c702011-11-07 09:24:32 +000081
Eric Christopher7f2b5512013-07-23 22:16:41 +000082static cl::opt<DefaultOnOff>
83DwarfAccelTables("dwarf-accel-tables", cl::Hidden,
84 cl::desc("Output prototype dwarf accelerator tables."),
85 cl::values(clEnumVal(Default, "Default for platform"),
86 clEnumVal(Enable, "Enabled"),
87 clEnumVal(Disable, "Disabled"), clEnumValEnd),
88 cl::init(Default));
Eric Christopher20b76a72012-08-23 22:36:40 +000089
Eric Christopher7f2b5512013-07-23 22:16:41 +000090static cl::opt<DefaultOnOff>
Eric Christopher7f2b5512013-07-23 22:16:41 +000091SplitDwarf("split-dwarf", cl::Hidden,
Eric Christopher5d008fe2013-12-04 23:24:28 +000092 cl::desc("Output DWARF5 split debug info."),
Eric Christopher7f2b5512013-07-23 22:16:41 +000093 cl::values(clEnumVal(Default, "Default for platform"),
94 clEnumVal(Enable, "Enabled"),
95 clEnumVal(Disable, "Disabled"), clEnumValEnd),
96 cl::init(Default));
Eric Christopher29424312012-11-12 22:22:20 +000097
Eric Christopher7da24882013-08-19 21:07:38 +000098static cl::opt<DefaultOnOff>
Eric Christopher4d36ca02013-08-26 23:24:35 +000099DwarfPubSections("generate-dwarf-pub-sections", cl::Hidden,
100 cl::desc("Generate DWARF pubnames and pubtypes sections"),
101 cl::values(clEnumVal(Default, "Default for platform"),
102 clEnumVal(Enable, "Enabled"),
103 clEnumVal(Disable, "Disabled"), clEnumValEnd),
104 cl::init(Default));
Eric Christopher7da24882013-08-19 21:07:38 +0000105
Benjamin Kramerb12cf012013-08-24 12:54:27 +0000106static const char *const DWARFGroupName = "DWARF Emission";
107static const char *const DbgTimerName = "DWARF Debug Writer";
Bill Wendlingfcc14142010-04-07 09:28:04 +0000108
Bill Wendling2f921f82009-05-15 09:23:25 +0000109//===----------------------------------------------------------------------===//
110
Manman Renbe5576f2013-10-08 19:07:44 +0000111/// resolve - Look in the DwarfDebug map for the MDNode that
112/// corresponds to the reference.
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000113template <typename T> T DbgVariable::resolve(DIRef<T> Ref) const {
Manman Renbe5576f2013-10-08 19:07:44 +0000114 return DD->resolve(Ref);
115}
116
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000117bool DbgVariable::isBlockByrefVariable() const {
118 assert(Var.isVariable() && "Invalid complex DbgVariable!");
119 return Var.isBlockByrefVariable(DD->getTypeIdentifierMap());
120}
121
Nick Lewycky019d2552011-07-29 03:49:23 +0000122DIType DbgVariable::getType() const {
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000123 DIType Ty = Var.getType().resolve(DD->getTypeIdentifierMap());
Devang Patelf20c4f72011-04-12 22:53:02 +0000124 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
125 // addresses instead.
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000126 if (Var.isBlockByrefVariable(DD->getTypeIdentifierMap())) {
Devang Patelf20c4f72011-04-12 22:53:02 +0000127 /* Byref variables, in Blocks, are declared by the programmer as
128 "SomeType VarName;", but the compiler creates a
129 __Block_byref_x_VarName struct, and gives the variable VarName
130 either the struct, or a pointer to the struct, as its type. This
131 is necessary for various behind-the-scenes things the compiler
132 needs to do with by-reference variables in blocks.
Eric Christopher6a841382012-11-19 22:42:10 +0000133
Devang Patelf20c4f72011-04-12 22:53:02 +0000134 However, as far as the original *programmer* is concerned, the
135 variable should still have type 'SomeType', as originally declared.
Eric Christopher6a841382012-11-19 22:42:10 +0000136
Devang Patelf20c4f72011-04-12 22:53:02 +0000137 The following function dives into the __Block_byref_x_VarName
138 struct to find the original type of the variable. This will be
139 passed back to the code generating the type for the Debug
140 Information Entry for the variable 'VarName'. 'VarName' will then
141 have the original type 'SomeType' in its debug information.
Eric Christopher6a841382012-11-19 22:42:10 +0000142
Devang Patelf20c4f72011-04-12 22:53:02 +0000143 The original type 'SomeType' will be the type of the field named
144 'VarName' inside the __Block_byref_x_VarName struct.
Eric Christopher6a841382012-11-19 22:42:10 +0000145
Devang Patelf20c4f72011-04-12 22:53:02 +0000146 NOTE: In order for this to not completely fail on the debugger
147 side, the Debug Information Entry for the variable VarName needs to
148 have a DW_AT_location that tells the debugger how to unwind through
149 the pointers and __Block_byref_x_VarName struct to find the actual
150 value of the variable. The function addBlockByrefType does this. */
151 DIType subType = Ty;
Eric Christopher31b05762013-08-08 01:41:00 +0000152 uint16_t tag = Ty.getTag();
Eric Christopher6a841382012-11-19 22:42:10 +0000153
Eric Christopher9adc55f2013-09-04 19:53:21 +0000154 if (tag == dwarf::DW_TAG_pointer_type)
Manman Renbe5576f2013-10-08 19:07:44 +0000155 subType = resolve(DIDerivedType(Ty).getTypeDerivedFrom());
Eric Christopher6a841382012-11-19 22:42:10 +0000156
Manman Renab8ffba2014-07-28 19:14:13 +0000157 DIArray Elements = DICompositeType(subType).getElements();
Devang Patelf20c4f72011-04-12 22:53:02 +0000158 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
David Blaikie5af2aca2013-11-18 23:57:26 +0000159 DIDerivedType DT(Elements.getElement(i));
Devang Patelf20c4f72011-04-12 22:53:02 +0000160 if (getName() == DT.getName())
Manman Renbe5576f2013-10-08 19:07:44 +0000161 return (resolve(DT.getTypeDerivedFrom()));
Devang Patel6d9f9fe2010-08-09 21:01:39 +0000162 }
Devang Patel6d9f9fe2010-08-09 21:01:39 +0000163 }
Devang Patelf20c4f72011-04-12 22:53:02 +0000164 return Ty;
165}
Bill Wendling2f921f82009-05-15 09:23:25 +0000166
David Blaikie18d33752014-04-24 01:23:49 +0000167static LLVM_CONSTEXPR DwarfAccelTable::Atom TypeAtoms[] = {
168 DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4),
169 DwarfAccelTable::Atom(dwarf::DW_ATOM_die_tag, dwarf::DW_FORM_data2),
170 DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)};
171
Chris Lattnerf0d6bd32010-04-05 05:11:15 +0000172DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
David Blaikie0dc623c2014-10-24 17:53:38 +0000173 : Asm(A), MMI(Asm->MMI), PrevLabel(nullptr), GlobalRangeCount(0),
David Blaikie2b22b1e2014-10-23 00:16:03 +0000174 InfoHolder(A, *this, "info_string", DIEValueAllocator),
Eric Christopher2037caf2014-01-28 00:49:26 +0000175 UsedNonDefaultText(false),
David Blaikie2b22b1e2014-10-23 00:16:03 +0000176 SkeletonHolder(A, *this, "skel_string", DIEValueAllocator),
David Blaikiee1c79742014-09-30 21:28:32 +0000177 IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()),
David Blaikie2406a0622014-04-23 23:37:35 +0000178 AccelNames(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
David Blaikie0ee82b92014-04-24 00:53:32 +0000179 dwarf::DW_FORM_data4)),
180 AccelObjC(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
David Blaikieecf04152014-04-24 01:02:42 +0000181 dwarf::DW_FORM_data4)),
182 AccelNamespace(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
David Blaikie18d33752014-04-24 01:23:49 +0000183 dwarf::DW_FORM_data4)),
184 AccelTypes(TypeAtoms) {
Jim Grosbacha8683bb2010-07-21 21:21:52 +0000185
Craig Topper353eda42014-04-24 06:44:33 +0000186 DwarfInfoSectionSym = DwarfAbbrevSectionSym = DwarfStrSectionSym = nullptr;
187 DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = nullptr;
188 DwarfLineSectionSym = nullptr;
189 DwarfAddrSectionSym = nullptr;
190 DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = nullptr;
191 FunctionBeginSym = FunctionEndSym = nullptr;
192 CurFn = nullptr;
193 CurMI = nullptr;
Eric Christopherad9fe892012-04-02 17:58:52 +0000194
Adrian Prantl5bf1d002013-10-15 20:26:37 +0000195 // Turn on accelerator tables for Darwin by default, pubnames by
196 // default for non-Darwin, and handle split dwarf.
Eric Christopher574b5c82013-08-19 21:41:38 +0000197 if (DwarfAccelTables == Default)
198 HasDwarfAccelTables = IsDarwin;
199 else
Eric Christopher5297df02013-08-26 20:58:35 +0000200 HasDwarfAccelTables = DwarfAccelTables == Enable;
Eric Christopher20b76a72012-08-23 22:36:40 +0000201
Eric Christophercdf218d2012-12-10 19:51:21 +0000202 if (SplitDwarf == Default)
203 HasSplitDwarf = false;
Eric Christopher29424312012-11-12 22:22:20 +0000204 else
Eric Christopher574b5c82013-08-19 21:41:38 +0000205 HasSplitDwarf = SplitDwarf == Enable;
Eric Christopher29424312012-11-12 22:22:20 +0000206
Eric Christopher4d36ca02013-08-26 23:24:35 +0000207 if (DwarfPubSections == Default)
208 HasDwarfPubSections = !IsDarwin;
Eric Christopher574b5c82013-08-19 21:41:38 +0000209 else
Eric Christopher4d36ca02013-08-26 23:24:35 +0000210 HasDwarfPubSections = DwarfPubSections == Enable;
Eric Christopher7da24882013-08-19 21:07:38 +0000211
Eric Christopher4c5bff32014-06-19 06:22:08 +0000212 unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
Eric Christopher793c7472014-04-28 20:42:22 +0000213 DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
214 : MMI->getModule()->getDwarfVersion();
Manman Renac8062b2013-07-02 23:40:10 +0000215
Oliver Stannardf7693f42014-06-19 15:39:33 +0000216 Asm->OutStreamer.getContext().setDwarfVersion(DwarfVersion);
217
Dan Gohman6e681a52010-06-18 15:56:31 +0000218 {
219 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
Eric Christopher58f41952012-11-19 22:42:15 +0000220 beginModule();
Torok Edwinf8dba242010-04-07 10:44:46 +0000221 }
Bill Wendling2f921f82009-05-15 09:23:25 +0000222}
Bill Wendling2f921f82009-05-15 09:23:25 +0000223
Reid Klecknerdd2647e2014-04-30 20:34:31 +0000224// Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
225DwarfDebug::~DwarfDebug() { }
226
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000227// Switch to the specified MCSection and emit an assembler
228// temporary label to it if SymbolStem is specified.
Eric Christopher7b30f2e42012-11-21 00:34:35 +0000229static MCSymbol *emitSectionSym(AsmPrinter *Asm, const MCSection *Section,
Craig Topper353eda42014-04-24 06:44:33 +0000230 const char *SymbolStem = nullptr) {
Eric Christophera7b61892011-11-07 09:18:38 +0000231 Asm->OutStreamer.SwitchSection(Section);
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000232 if (!SymbolStem)
Craig Topper353eda42014-04-24 06:44:33 +0000233 return nullptr;
Eric Christophera7b61892011-11-07 09:18:38 +0000234
235 MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
236 Asm->OutStreamer.EmitLabel(TmpSym);
237 return TmpSym;
238}
239
Eric Christopherd9843b32011-11-10 19:25:34 +0000240static bool isObjCClass(StringRef Name) {
241 return Name.startswith("+") || Name.startswith("-");
242}
243
244static bool hasObjCCategory(StringRef Name) {
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000245 if (!isObjCClass(Name))
246 return false;
Eric Christopherd9843b32011-11-10 19:25:34 +0000247
Benjamin Kramer260de742013-08-24 12:15:54 +0000248 return Name.find(") ") != StringRef::npos;
Eric Christopherd9843b32011-11-10 19:25:34 +0000249}
250
251static void getObjCClassCategory(StringRef In, StringRef &Class,
252 StringRef &Category) {
253 if (!hasObjCCategory(In)) {
254 Class = In.slice(In.find('[') + 1, In.find(' '));
255 Category = "";
256 return;
257 }
258
259 Class = In.slice(In.find('[') + 1, In.find('('));
260 Category = In.slice(In.find('[') + 1, In.find(' '));
261 return;
262}
263
264static StringRef getObjCMethodName(StringRef In) {
265 return In.slice(In.find(' ') + 1, In.find(']'));
266}
267
Richard Mittonc2508242013-10-03 22:07:08 +0000268// Helper for sorting sections into a stable output order.
269static bool SectionSort(const MCSection *A, const MCSection *B) {
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000270 std::string LA = (A ? A->getLabelBeginName() : "");
271 std::string LB = (B ? B->getLabelBeginName() : "");
272 return LA < LB;
Richard Mittonc2508242013-10-03 22:07:08 +0000273}
274
Eric Christopherd9843b32011-11-10 19:25:34 +0000275// Add the various names to the Dwarf accelerator table names.
Eric Christopher9cd26af2013-09-20 23:22:52 +0000276// TODO: Determine whether or not we should add names for programs
277// that do not have a DW_AT_name or DW_AT_linkage_name field - this
278// is only slightly different than the lookup of non-standard ObjC names.
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000279void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE &Die) {
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000280 if (!SP.isDefinition())
281 return;
David Blaikie2406a0622014-04-23 23:37:35 +0000282 addAccelName(SP.getName(), Die);
Eric Christopherd9843b32011-11-10 19:25:34 +0000283
284 // If the linkage name is different than the name, go ahead and output
285 // that as well into the name table.
286 if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName())
David Blaikie2406a0622014-04-23 23:37:35 +0000287 addAccelName(SP.getLinkageName(), Die);
Eric Christopherd9843b32011-11-10 19:25:34 +0000288
289 // If this is an Objective-C selector name add it to the ObjC accelerator
290 // too.
291 if (isObjCClass(SP.getName())) {
292 StringRef Class, Category;
293 getObjCClassCategory(SP.getName(), Class, Category);
David Blaikie0ee82b92014-04-24 00:53:32 +0000294 addAccelObjC(Class, Die);
Eric Christopherd9843b32011-11-10 19:25:34 +0000295 if (Category != "")
David Blaikie0ee82b92014-04-24 00:53:32 +0000296 addAccelObjC(Category, Die);
Eric Christopherd9843b32011-11-10 19:25:34 +0000297 // Also add the base method name to the name table.
David Blaikie2406a0622014-04-23 23:37:35 +0000298 addAccelName(getObjCMethodName(SP.getName()), Die);
Eric Christopherd9843b32011-11-10 19:25:34 +0000299 }
300}
301
Manman Ren3eb9dff2013-09-09 19:05:21 +0000302/// isSubprogramContext - Return true if Context is either a subprogram
303/// or another context nested inside a subprogram.
304bool DwarfDebug::isSubprogramContext(const MDNode *Context) {
305 if (!Context)
306 return false;
307 DIDescriptor D(Context);
308 if (D.isSubprogram())
309 return true;
310 if (D.isType())
Manman Ren116868e2013-09-09 19:47:11 +0000311 return isSubprogramContext(resolve(DIType(Context).getContext()));
Manman Ren3eb9dff2013-09-09 19:05:21 +0000312 return false;
313}
314
Manman Ren5b2f4b02013-09-11 19:40:28 +0000315/// Check whether we should create a DIE for the given Scope, return true
316/// if we don't create a DIE (the corresponding DIE is null).
Manman Ren2312ed32013-09-10 18:40:41 +0000317bool DwarfDebug::isLexicalScopeDIENull(LexicalScope *Scope) {
318 if (Scope->isAbstractScope())
319 return false;
320
Manman Ren5b2f4b02013-09-11 19:40:28 +0000321 // We don't create a DIE if there is no Range.
Manman Ren2312ed32013-09-10 18:40:41 +0000322 const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
323 if (Ranges.empty())
324 return true;
325
326 if (Ranges.size() > 1)
327 return false;
328
Manman Ren5b2f4b02013-09-11 19:40:28 +0000329 // We don't create a DIE if we have a single Range and the end label
330 // is null.
David Blaikiecd4b8a22014-08-31 02:14:26 +0000331 return !getLabelAfterInsn(Ranges.front().second);
Manman Ren2312ed32013-09-10 18:40:41 +0000332}
333
David Blaikie3a443c22014-11-04 22:12:25 +0000334template <typename Func> void forBothCUs(DwarfCompileUnit &CU, Func F) {
335 F(CU);
336 if (auto *SkelCU = CU.getSkeleton())
337 F(*SkelCU);
338}
339
David Blaikie73cc7052014-10-09 20:36:27 +0000340void DwarfDebug::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) {
David Blaikiee872a6e2014-04-29 15:58:35 +0000341 assert(Scope && Scope->getScopeNode());
342 assert(Scope->isAbstractScope());
343 assert(!Scope->getInlinedAt());
344
David Blaikie58410f22014-10-10 06:39:26 +0000345 const MDNode *SP = Scope->getScopeNode();
David Blaikiee872a6e2014-04-29 15:58:35 +0000346
David Blaikie9ab48842014-10-10 03:09:38 +0000347 ProcessedSPNodes.insert(SP);
348
David Blaikie1ea9db22014-05-21 23:14:12 +0000349 // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
350 // was inlined from another compile unit.
David Blaikie3a443c22014-11-04 22:12:25 +0000351 auto &CU = SPMap[SP];
352 forBothCUs(*CU, [&](DwarfCompileUnit &CU) {
353 CU.constructAbstractSubprogramScopeDIE(Scope);
354 });
David Blaikiee872a6e2014-04-29 15:58:35 +0000355}
356
David Blaikie65a74662014-04-25 18:26:14 +0000357void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE &D) const {
David Blaikie3c842622013-12-04 21:31:26 +0000358 if (!GenerateGnuPubSections)
359 return;
360
David Blaikief9b6a552014-04-22 22:39:41 +0000361 U.addFlag(D, dwarf::DW_AT_GNU_pubnames);
David Blaikie3c842622013-12-04 21:31:26 +0000362}
363
Eric Christopher4287a492013-12-09 23:57:44 +0000364// Create new DwarfCompileUnit for the given metadata node with tag
Eric Christopher48fef592012-12-20 21:58:40 +0000365// DW_TAG_compile_unit.
David Blaikief9b6a552014-04-22 22:39:41 +0000366DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
Devang Patel2d9caf92009-11-25 17:36:49 +0000367 StringRef FN = DIUnit.getFilename();
Nick Lewyckyd1ee7f82011-11-02 20:55:33 +0000368 CompilationDir = DIUnit.getDirectory();
Bill Wendling2b128d72009-05-20 23:19:06 +0000369
David Blaikief9b6a552014-04-22 22:39:41 +0000370 auto OwnedUnit = make_unique<DwarfCompileUnit>(
David Blaikiebd579052014-04-28 21:14:27 +0000371 InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
David Blaikief9b6a552014-04-22 22:39:41 +0000372 DwarfCompileUnit &NewCU = *OwnedUnit;
David Blaikie92a2f8a2014-04-28 21:04:29 +0000373 DIE &Die = NewCU.getUnitDie();
David Blaikief9b6a552014-04-22 22:39:41 +0000374 InfoHolder.addUnit(std::move(OwnedUnit));
David Blaikiecafd9622014-11-02 08:51:37 +0000375 if (useSplitDwarf())
376 NewCU.setSkeleton(constructSkeletonCU(NewCU));
David Blaikief9b6a552014-04-22 22:39:41 +0000377
David Blaikie7ac51492014-03-20 17:05:45 +0000378 // LTO with assembly output shares a single line table amongst multiple CUs.
379 // To avoid the compilation directory being ambiguous, let the line table
380 // explicitly describe the directory of all files, never relying on the
381 // compilation directory.
David Blaikie47f4b822014-03-19 00:11:28 +0000382 if (!Asm->OutStreamer.hasRawTextSupport() || SingleCU)
David Blaikiee05274d2014-03-18 00:11:48 +0000383 Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
David Blaikief9b6a552014-04-22 22:39:41 +0000384 NewCU.getUniqueID(), CompilationDir);
David Blaikie2666e242013-12-06 19:38:46 +0000385
David Blaikie92a2f8a2014-04-28 21:04:29 +0000386 NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
387 NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
David Blaikie637cac42014-04-22 23:09:36 +0000388 DIUnit.getLanguage());
David Blaikie92a2f8a2014-04-28 21:04:29 +0000389 NewCU.addString(Die, dwarf::DW_AT_name, FN);
Eric Christopher52ce7182013-04-09 19:23:15 +0000390
Eric Christopher52ce7182013-04-09 19:23:15 +0000391 if (!useSplitDwarf()) {
David Blaikief9b6a552014-04-22 22:39:41 +0000392 NewCU.initStmtList(DwarfLineSectionSym);
Eric Christophera51d3fc2013-09-27 22:50:48 +0000393
394 // If we're using split dwarf the compilation dir is going to be in the
395 // skeleton CU and so we don't need to duplicate it here.
396 if (!CompilationDir.empty())
David Blaikie92a2f8a2014-04-28 21:04:29 +0000397 NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
Eric Christophera51d3fc2013-09-27 22:50:48 +0000398
David Blaikie92a2f8a2014-04-28 21:04:29 +0000399 addGnuPubAttributes(NewCU, Die);
Eric Christopher52ce7182013-04-09 19:23:15 +0000400 }
Bill Wendling2b128d72009-05-20 23:19:06 +0000401
Bill Wendling2b128d72009-05-20 23:19:06 +0000402 if (DIUnit.isOptimized())
David Blaikie92a2f8a2014-04-28 21:04:29 +0000403 NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
Bill Wendling2b128d72009-05-20 23:19:06 +0000404
Devang Patel2d9caf92009-11-25 17:36:49 +0000405 StringRef Flags = DIUnit.getFlags();
406 if (!Flags.empty())
David Blaikie92a2f8a2014-04-28 21:04:29 +0000407 NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
Eric Christopher6a841382012-11-19 22:42:10 +0000408
Nick Lewycky479a8fe2011-10-17 23:27:36 +0000409 if (unsigned RVer = DIUnit.getRunTimeVersion())
David Blaikie92a2f8a2014-04-28 21:04:29 +0000410 NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
David Blaikie637cac42014-04-22 23:09:36 +0000411 dwarf::DW_FORM_data1, RVer);
Bill Wendling2b128d72009-05-20 23:19:06 +0000412
David Blaikiecafd9622014-11-02 08:51:37 +0000413 if (useSplitDwarf())
David Blaikief9b6a552014-04-22 22:39:41 +0000414 NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoDWOSection(),
David Blaikie637cac42014-04-22 23:09:36 +0000415 DwarfInfoDWOSectionSym);
David Blaikiecafd9622014-11-02 08:51:37 +0000416 else
David Blaikief9b6a552014-04-22 22:39:41 +0000417 NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
David Blaikie637cac42014-04-22 23:09:36 +0000418 DwarfInfoSectionSym);
Eric Christopherd039baa2013-12-30 03:40:32 +0000419
David Blaikief9b6a552014-04-22 22:39:41 +0000420 CUMap.insert(std::make_pair(DIUnit, &NewCU));
David Blaikie92a2f8a2014-04-28 21:04:29 +0000421 CUDieMap.insert(std::make_pair(&Die, &NewCU));
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000422 return NewCU;
Devang Patel1a0df9a2010-05-10 22:49:55 +0000423}
424
David Blaikie8912df12014-08-31 05:41:15 +0000425void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
426 const MDNode *N) {
David Blaikie1fd43652013-05-07 21:35:53 +0000427 DIImportedEntity Module(N);
David Blaikie5e390e42014-02-04 01:23:52 +0000428 assert(Module.Verify());
David Blaikief9b6a552014-04-22 22:39:41 +0000429 if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext()))
David Blaikiefebfafd2014-10-06 05:37:24 +0000430 D->addChild(TheCU.constructImportedEntityDIE(Module));
David Blaikief55abea2013-04-22 06:12:31 +0000431}
432
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000433// Emit all Dwarf sections that should come prior to the content. Create
434// global DIEs and emit initial debug info sections. This is invoked by
435// the target AsmPrinter.
Eric Christopher58f41952012-11-19 22:42:15 +0000436void DwarfDebug::beginModule() {
Devang Patel6c74a872010-04-27 19:46:33 +0000437 if (DisableDebugInfoPrinting)
438 return;
439
Eric Christopher58f41952012-11-19 22:42:15 +0000440 const Module *M = MMI->getModule();
441
David Blaikie2f040112014-07-25 16:10:16 +0000442 FunctionDIs = makeSubprogramMap(*M);
443
Devang Patele02e5852011-05-03 16:45:22 +0000444 NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
David Blaikiedc69ebb2013-03-11 23:39:23 +0000445 if (!CU_Nodes)
Devang Patel07bb9ee2011-08-15 23:47:24 +0000446 return;
Manman Ren60352032013-09-05 18:48:31 +0000447 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
Devang Patele02e5852011-05-03 16:45:22 +0000448
David Blaikiedc69ebb2013-03-11 23:39:23 +0000449 // Emit initial sections so we can reference labels later.
450 emitSectionLabels();
451
David Blaikie47f4b822014-03-19 00:11:28 +0000452 SingleCU = CU_Nodes->getNumOperands() == 1;
David Blaikiee05274d2014-03-18 00:11:48 +0000453
Duncan P. N. Exon Smithde36e802014-11-11 21:30:22 +0000454 for (MDNode *N : CU_Nodes->operands()) {
455 DICompileUnit CUNode(N);
David Blaikief9b6a552014-04-22 22:39:41 +0000456 DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
David Blaikie1fd43652013-05-07 21:35:53 +0000457 DIArray ImportedEntities = CUNode.getImportedEntities();
458 for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
David Blaikie684fc532013-05-06 23:33:07 +0000459 ScopesWithImportedEntities.push_back(std::make_pair(
David Blaikie1fd43652013-05-07 21:35:53 +0000460 DIImportedEntity(ImportedEntities.getElement(i)).getContext(),
461 ImportedEntities.getElement(i)));
David Blaikie684fc532013-05-06 23:33:07 +0000462 std::sort(ScopesWithImportedEntities.begin(),
Benjamin Kramerb12cf012013-08-24 12:54:27 +0000463 ScopesWithImportedEntities.end(), less_first());
David Blaikiedc69ebb2013-03-11 23:39:23 +0000464 DIArray GVs = CUNode.getGlobalVariables();
465 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
Frederic Riss9ba9eff2014-09-19 15:12:03 +0000466 CU.getOrCreateGlobalVariableDIE(DIGlobalVariable(GVs.getElement(i)));
David Blaikie6ba88e02014-08-29 22:10:52 +0000467 DIArray SPs = CUNode.getSubprograms();
468 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
469 SPMap.insert(std::make_pair(SPs.getElement(i), &CU));
David Blaikiedc69ebb2013-03-11 23:39:23 +0000470 DIArray EnumTypes = CUNode.getEnumTypes();
Manman Renbd1628a2014-07-28 23:04:20 +0000471 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) {
472 DIType Ty(EnumTypes.getElement(i));
473 // The enum types array by design contains pointers to
474 // MDNodes rather than DIRefs. Unique them here.
475 DIType UniqueTy(resolve(Ty.getRef()));
476 CU.getOrCreateTypeDIE(UniqueTy);
477 }
David Blaikiedc69ebb2013-03-11 23:39:23 +0000478 DIArray RetainedTypes = CUNode.getRetainedTypes();
Adrian Prantl0aa1aa22014-03-18 02:35:03 +0000479 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) {
480 DIType Ty(RetainedTypes.getElement(i));
481 // The retained types array by design contains pointers to
482 // MDNodes rather than DIRefs. Unique them here.
483 DIType UniqueTy(resolve(Ty.getRef()));
David Blaikief9b6a552014-04-22 22:39:41 +0000484 CU.getOrCreateTypeDIE(UniqueTy);
Adrian Prantl0aa1aa22014-03-18 02:35:03 +0000485 }
David Blaikief55abea2013-04-22 06:12:31 +0000486 // Emit imported_modules last so that the relevant context is already
487 // available.
David Blaikie1fd43652013-05-07 21:35:53 +0000488 for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
David Blaikie8912df12014-08-31 05:41:15 +0000489 constructAndAddImportedEntityDIE(CU, ImportedEntities.getElement(i));
David Blaikiedc69ebb2013-03-11 23:39:23 +0000490 }
Eric Christopher6a841382012-11-19 22:42:10 +0000491
Chris Lattner7cfa70e2010-04-05 02:19:28 +0000492 // Tell MMI that we have debug info.
493 MMI->setDebugInfoAvailability(true);
Eric Christopher6a841382012-11-19 22:42:10 +0000494
Bill Wendling2b128d72009-05-20 23:19:06 +0000495 // Prime section data.
Richard Mitton21101b32013-09-19 23:21:01 +0000496 SectionMap[Asm->getObjFileLowering().getTextSection()];
Bill Wendling2b128d72009-05-20 23:19:06 +0000497}
498
David Blaikieeb1a2722014-06-13 22:18:23 +0000499void DwarfDebug::finishVariableDefinitions() {
500 for (const auto &Var : ConcreteVariables) {
501 DIE *VariableDie = Var->getDIE();
David Blaikief73ae4f2014-08-12 00:00:31 +0000502 assert(VariableDie);
David Blaikieeb1a2722014-06-13 22:18:23 +0000503 // FIXME: Consider the time-space tradeoff of just storing the unit pointer
504 // in the ConcreteVariables list, rather than looking it up again here.
505 // DIE::getUnit isn't simple - it walks parent pointers, etc.
506 DwarfCompileUnit *Unit = lookupUnit(VariableDie->getUnit());
507 assert(Unit);
David Blaikiee847f132014-06-13 22:35:44 +0000508 DbgVariable *AbsVar = getExistingAbstractVariable(Var->getVariable());
David Blaikieeb1a2722014-06-13 22:18:23 +0000509 if (AbsVar && AbsVar->getDIE()) {
510 Unit->addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin,
511 *AbsVar->getDIE());
512 } else
513 Unit->applyVariableAttributes(*Var, *VariableDie);
514 }
515}
516
David Blaikief7221ad2014-05-27 18:37:43 +0000517void DwarfDebug::finishSubprogramDefinitions() {
David Blaikie7d6f29d2014-10-10 16:59:52 +0000518 for (const auto &P : SPMap)
David Blaikie3a443c22014-11-04 22:12:25 +0000519 forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
520 CU.finishSubprogramDefinition(DISubprogram(P.first));
521 });
David Blaikief7221ad2014-05-27 18:37:43 +0000522}
523
524
Eric Christopher960ac372012-11-22 00:59:49 +0000525// Collect info for variables that were optimized out.
526void DwarfDebug::collectDeadVariables() {
527 const Module *M = MMI->getModule();
Eric Christopher960ac372012-11-22 00:59:49 +0000528
529 if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
Duncan P. N. Exon Smithde36e802014-11-11 21:30:22 +0000530 for (MDNode *N : CU_Nodes->operands()) {
531 DICompileUnit TheCU(N);
David Blaikie9ba72542014-05-14 21:52:46 +0000532 // Construct subprogram DIE and add variables DIEs.
533 DwarfCompileUnit *SPCU =
534 static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
535 assert(SPCU && "Unable to find Compile Unit!");
Eric Christopher960ac372012-11-22 00:59:49 +0000536 DIArray Subprograms = TheCU.getSubprograms();
537 for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
Eric Christopher735401c2012-11-27 00:13:51 +0000538 DISubprogram SP(Subprograms.getElement(i));
Eric Christophera6c38a32013-10-15 23:31:38 +0000539 if (ProcessedSPNodes.count(SP) != 0)
540 continue;
David Blaikie1d96cc22014-10-31 22:30:30 +0000541 SPCU->collectDeadVariables(SP);
Eric Christopher960ac372012-11-22 00:59:49 +0000542 }
543 }
544 }
Eric Christopher960ac372012-11-22 00:59:49 +0000545}
546
547void DwarfDebug::finalizeModuleInfo() {
David Blaikie3c2fff32014-05-27 18:37:48 +0000548 finishSubprogramDefinitions();
549
David Blaikieeb1a2722014-06-13 22:18:23 +0000550 finishVariableDefinitions();
551
Eric Christopher960ac372012-11-22 00:59:49 +0000552 // Collect info for variables that were optimized out.
553 collectDeadVariables();
554
Eric Christopherad10cb52013-12-04 23:24:38 +0000555 // Handle anything that needs to be done on a per-unit basis after
556 // all other generation.
David Blaikie1998a2e2014-11-01 01:11:19 +0000557 for (const auto &P : CUMap) {
558 auto &TheCU = *P.second;
Eric Christopher60eb7692013-08-12 20:27:48 +0000559 // Emit DW_AT_containing_type attribute to connect types with their
560 // vtable holding type.
David Blaikie1998a2e2014-11-01 01:11:19 +0000561 TheCU.constructContainingTypeDIEs();
Eric Christopher60eb7692013-08-12 20:27:48 +0000562
Eric Christopher46e23432013-12-20 04:16:18 +0000563 // Add CU specific attributes if we need to add any.
David Blaikie1998a2e2014-11-01 01:11:19 +0000564 // If we're splitting the dwarf out now that we've got the entire
565 // CU then add the dwo id to it.
566 auto *SkCU = TheCU.getSkeleton();
567 if (useSplitDwarf()) {
568 // Emit a unique identifier for this CU.
569 uint64_t ID = DIEHash(Asm).computeCUSignature(TheCU.getUnitDie());
570 TheCU.addUInt(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
571 dwarf::DW_FORM_data8, ID);
572 SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
573 dwarf::DW_FORM_data8, ID);
David Blaikie3ffe4dd2014-03-25 05:34:24 +0000574
David Blaikie1998a2e2014-11-01 01:11:19 +0000575 // We don't keep track of which addresses are used in which CU so this
576 // is a bit pessimistic under LTO.
577 if (!AddrPool.isEmpty())
578 SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_addr_base,
579 DwarfAddrSectionSym, DwarfAddrSectionSym);
David Blaikie542616d2014-11-03 21:52:56 +0000580 if (!SkCU->getRangeLists().empty())
David Blaikie1998a2e2014-11-01 01:11:19 +0000581 SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_ranges_base,
582 DwarfDebugRangeSectionSym,
583 DwarfDebugRangeSectionSym);
584 }
Eric Christopherd8667202013-12-30 17:22:27 +0000585
David Blaikie1998a2e2014-11-01 01:11:19 +0000586 // If we have code split among multiple sections or non-contiguous
587 // ranges of code then emit a DW_AT_ranges attribute on the unit that will
588 // remain in the .o file, otherwise add a DW_AT_low_pc.
589 // FIXME: We should use ranges allow reordering of code ala
590 // .subsections_via_symbols in mach-o. This would mean turning on
591 // ranges for all subprogram DIEs for mach-o.
David Blaikiea8be0a72014-11-01 01:15:24 +0000592 DwarfCompileUnit &U = SkCU ? *SkCU : TheCU;
David Blaikie5b02a192014-11-03 23:10:59 +0000593 if (unsigned NumRanges = TheCU.getRanges().size()) {
594 if (NumRanges > 1)
David Blaikie1998a2e2014-11-01 01:11:19 +0000595 // A DW_AT_low_pc attribute may also be specified in combination with
596 // DW_AT_ranges to specify the default base address for use in
597 // location lists (see Section 2.6.2) and range lists (see Section
598 // 2.17.3).
599 U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
David Blaikie5b02a192014-11-03 23:10:59 +0000600 else
601 TheCU.setBaseAddress(TheCU.getRanges().front().getStart());
602 U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges());
Eric Christopher60eb7692013-08-12 20:27:48 +0000603 }
604 }
605
606 // Compute DIE offsets and sizes.
Eric Christopherc8a310e2012-12-10 23:34:43 +0000607 InfoHolder.computeSizeAndOffsets();
608 if (useSplitDwarf())
609 SkeletonHolder.computeSizeAndOffsets();
Eric Christopher960ac372012-11-22 00:59:49 +0000610}
611
612void DwarfDebug::endSections() {
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000613 // Filter labels by section.
Benjamin Kramer15596c72014-03-07 19:09:39 +0000614 for (const SymbolCU &SCU : ArangeLabels) {
Richard Mitton21101b32013-09-19 23:21:01 +0000615 if (SCU.Sym->isInSection()) {
616 // Make a note of this symbol and it's section.
617 const MCSection *Section = &SCU.Sym->getSection();
618 if (!Section->getKind().isMetadata())
619 SectionMap[Section].push_back(SCU);
620 } else {
621 // Some symbols (e.g. common/bss on mach-o) can have no section but still
622 // appear in the output. This sucks as we rely on sections to build
623 // arange spans. We can do it without, but it's icky.
Craig Topper353eda42014-04-24 06:44:33 +0000624 SectionMap[nullptr].push_back(SCU);
Richard Mitton21101b32013-09-19 23:21:01 +0000625 }
626 }
Bill Wendling2b128d72009-05-20 23:19:06 +0000627
Richard Mittonc2508242013-10-03 22:07:08 +0000628 // Build a list of sections used.
629 std::vector<const MCSection *> Sections;
Benjamin Kramer15596c72014-03-07 19:09:39 +0000630 for (const auto &it : SectionMap) {
631 const MCSection *Section = it.first;
Richard Mittonc2508242013-10-03 22:07:08 +0000632 Sections.push_back(Section);
633 }
634
635 // Sort the sections into order.
636 // This is only done to ensure consistent output order across different runs.
637 std::sort(Sections.begin(), Sections.end(), SectionSort);
638
639 // Add terminating symbols for each section.
Benjamin Kramer15596c72014-03-07 19:09:39 +0000640 for (unsigned ID = 0, E = Sections.size(); ID != E; ID++) {
Richard Mittonc2508242013-10-03 22:07:08 +0000641 const MCSection *Section = Sections[ID];
Craig Topper353eda42014-04-24 06:44:33 +0000642 MCSymbol *Sym = nullptr;
Richard Mitton21101b32013-09-19 23:21:01 +0000643
644 if (Section) {
Richard Mittonc2508242013-10-03 22:07:08 +0000645 // We can't call MCSection::getLabelEndName, as it's only safe to do so
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000646 // if we know the section name up-front. For user-created sections, the
Eric Christopher95531b62014-01-29 22:06:21 +0000647 // resulting label may not be valid to use as a label. (section names can
648 // use a greater set of characters on some systems)
Richard Mittonc2508242013-10-03 22:07:08 +0000649 Sym = Asm->GetTempSymbol("debug_end", ID);
Richard Mitton21101b32013-09-19 23:21:01 +0000650 Asm->OutStreamer.SwitchSection(Section);
651 Asm->OutStreamer.EmitLabel(Sym);
652 }
653
654 // Insert a final terminator.
Craig Topper353eda42014-04-24 06:44:33 +0000655 SectionMap[Section].push_back(SymbolCU(nullptr, Sym));
Bill Wendling2b128d72009-05-20 23:19:06 +0000656 }
Eric Christopher960ac372012-11-22 00:59:49 +0000657}
Bill Wendling2b128d72009-05-20 23:19:06 +0000658
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000659// Emit all Dwarf sections that should come after the content.
Eric Christopher960ac372012-11-22 00:59:49 +0000660void DwarfDebug::endModule() {
Craig Toppere73658d2014-04-28 04:05:08 +0000661 assert(CurFn == nullptr);
662 assert(CurMI == nullptr);
Eric Christopher960ac372012-11-22 00:59:49 +0000663
David Blaikie0dc623c2014-10-24 17:53:38 +0000664 // If we aren't actually generating debug info (check beginModule -
665 // conditionalized on !DisableDebugInfoPrinting and the presence of the
666 // llvm.dbg.cu metadata node)
667 if (!DwarfInfoSectionSym)
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000668 return;
Eric Christopher960ac372012-11-22 00:59:49 +0000669
670 // End any existing sections.
671 // TODO: Does this need to happen?
672 endSections();
673
674 // Finalize the debug info for the module.
675 finalizeModuleInfo();
Bill Wendling2b128d72009-05-20 23:19:06 +0000676
Eric Christopher9a8f5ed2013-11-19 09:04:50 +0000677 emitDebugStr();
Eric Christopher9cd26af2013-09-20 23:22:52 +0000678
Eric Christopher9a8f5ed2013-11-19 09:04:50 +0000679 // Emit all the DIEs into a debug info section.
680 emitDebugInfo();
Eric Christopher4c9b1192012-11-27 00:41:54 +0000681
Eric Christopher9a8f5ed2013-11-19 09:04:50 +0000682 // Corresponding abbreviations into a abbrev section.
683 emitAbbreviations();
Eric Christopher95198f502012-11-27 22:43:42 +0000684
Eric Christopher9a8f5ed2013-11-19 09:04:50 +0000685 // Emit info into a debug aranges section.
Eric Christopher02dbadb2014-02-14 01:26:55 +0000686 if (GenerateARangeSection)
687 emitDebugARanges();
Eric Christopher95198f502012-11-27 22:43:42 +0000688
Eric Christopher9a8f5ed2013-11-19 09:04:50 +0000689 // Emit info into a debug ranges section.
690 emitDebugRanges();
Eric Christopher95198f502012-11-27 22:43:42 +0000691
Eric Christopher9a8f5ed2013-11-19 09:04:50 +0000692 if (useSplitDwarf()) {
693 emitDebugStrDWO();
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000694 emitDebugInfoDWO();
Eric Christopher3c5a1912012-12-19 22:02:53 +0000695 emitDebugAbbrevDWO();
David Blaikie4a2f95f2014-03-18 01:17:26 +0000696 emitDebugLineDWO();
David Blaikiede8e12a2014-06-19 17:59:14 +0000697 emitDebugLocDWO();
Eric Christopher962c9082013-01-15 23:56:56 +0000698 // Emit DWO addresses.
David Blaikied75fb282014-04-23 21:20:10 +0000699 AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection());
David Blaikie94c1d7f2014-04-02 01:50:20 +0000700 } else
701 // Emit info into a debug loc section.
702 emitDebugLoc();
Bill Wendling2b128d72009-05-20 23:19:06 +0000703
Eric Christophera876b822012-08-23 07:32:06 +0000704 // Emit info into the dwarf accelerator table sections.
Eric Christopher20b76a72012-08-23 22:36:40 +0000705 if (useDwarfAccelTables()) {
Eric Christopher4996c702011-11-07 09:24:32 +0000706 emitAccelNames();
707 emitAccelObjC();
708 emitAccelNamespaces();
709 emitAccelTypes();
710 }
Eric Christopher6a841382012-11-19 22:42:10 +0000711
Eric Christopher4b358182013-08-30 00:40:17 +0000712 // Emit the pubnames and pubtypes sections if requested.
713 if (HasDwarfPubSections) {
David Blaikie70a33202013-09-19 17:33:35 +0000714 emitDebugPubNames(GenerateGnuPubSections);
715 emitDebugPubTypes(GenerateGnuPubSections);
Eric Christopher4b358182013-08-30 00:40:17 +0000716 }
Devang Patel04d2f2d2009-11-24 01:14:22 +0000717
Devang Pateld0701282010-08-02 17:32:15 +0000718 // clean up.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000719 SPMap.clear();
David Blaikie825bdd22014-05-21 22:41:17 +0000720 AbstractVariables.clear();
Bill Wendling2b128d72009-05-20 23:19:06 +0000721}
722
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000723// Find abstract variable, if any, associated with Var.
David Blaikiebe7c6772014-06-13 22:29:31 +0000724DbgVariable *DwarfDebug::getExistingAbstractVariable(const DIVariable &DV,
David Blaikie36408e72014-06-04 23:50:52 +0000725 DIVariable &Cleansed) {
Devang Patelbb23a4a2011-08-10 21:50:54 +0000726 LLVMContext &Ctx = DV->getContext();
727 // More then one inlined variable corresponds to one abstract variable.
David Blaikie36408e72014-06-04 23:50:52 +0000728 // FIXME: This duplication of variables when inlining should probably be
729 // removed. It's done to allow each DIVariable to describe its location
730 // because the DebugLoc on the dbg.value/declare isn't accurate. We should
731 // make it accurate then remove this duplication/cleansing stuff.
732 Cleansed = cleanseInlinedVariable(DV, Ctx);
733 auto I = AbstractVariables.find(Cleansed);
David Blaikie825bdd22014-05-21 22:41:17 +0000734 if (I != AbstractVariables.end())
735 return I->second.get();
David Blaikie36408e72014-06-04 23:50:52 +0000736 return nullptr;
737}
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000738
David Blaikiee847f132014-06-13 22:35:44 +0000739DbgVariable *DwarfDebug::getExistingAbstractVariable(const DIVariable &DV) {
740 DIVariable Cleansed;
741 return getExistingAbstractVariable(DV, Cleansed);
742}
743
David Blaikie6f9e8672014-06-13 23:52:55 +0000744void DwarfDebug::createAbstractVariable(const DIVariable &Var,
745 LexicalScope *Scope) {
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000746 auto AbsDbgVariable = make_unique<DbgVariable>(Var, DIExpression(), this);
David Blaikief4c504e2014-10-24 00:43:47 +0000747 InfoHolder.addScopeVariable(Scope, AbsDbgVariable.get());
David Blaikie6f9e8672014-06-13 23:52:55 +0000748 AbstractVariables[Var] = std::move(AbsDbgVariable);
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000749}
750
David Blaikie6f9e8672014-06-13 23:52:55 +0000751void DwarfDebug::ensureAbstractVariableIsCreated(const DIVariable &DV,
752 const MDNode *ScopeNode) {
David Blaikie36408e72014-06-04 23:50:52 +0000753 DIVariable Cleansed = DV;
David Blaikie6f9e8672014-06-13 23:52:55 +0000754 if (getExistingAbstractVariable(DV, Cleansed))
755 return;
David Blaikie36408e72014-06-04 23:50:52 +0000756
David Blaikie6f9e8672014-06-13 23:52:55 +0000757 createAbstractVariable(Cleansed, LScopes.getOrCreateAbstractScope(ScopeNode));
David Blaikie36408e72014-06-04 23:50:52 +0000758}
759
David Blaikie6f9e8672014-06-13 23:52:55 +0000760void
761DwarfDebug::ensureAbstractVariableIsCreatedIfScoped(const DIVariable &DV,
762 const MDNode *ScopeNode) {
David Blaikie36408e72014-06-04 23:50:52 +0000763 DIVariable Cleansed = DV;
David Blaikie6f9e8672014-06-13 23:52:55 +0000764 if (getExistingAbstractVariable(DV, Cleansed))
765 return;
David Blaikie36408e72014-06-04 23:50:52 +0000766
767 if (LexicalScope *Scope = LScopes.findAbstractScope(ScopeNode))
David Blaikie6f9e8672014-06-13 23:52:55 +0000768 createAbstractVariable(Cleansed, Scope);
David Blaikie36408e72014-06-04 23:50:52 +0000769}
770
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000771// Collect variable information from side table maintained by MMI.
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000772void DwarfDebug::collectVariableInfoFromMMITable(
Craig Topper71b7b682014-08-21 05:55:13 +0000773 SmallPtrSetImpl<const MDNode *> &Processed) {
Benjamin Kramer15596c72014-03-07 19:09:39 +0000774 for (const auto &VI : MMI->getVariableDbgInfo()) {
Benjamin Kramer2abfd6c72014-03-09 15:44:39 +0000775 if (!VI.Var)
Eric Christopherb4bef6d2013-11-19 09:04:36 +0000776 continue;
Benjamin Kramer2abfd6c72014-03-09 15:44:39 +0000777 Processed.insert(VI.Var);
Benjamin Kramer2abfd6c72014-03-09 15:44:39 +0000778 LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc);
Jim Grosbacha8683bb2010-07-21 21:21:52 +0000779
Devang Patelcdb7d442009-11-10 23:20:04 +0000780 // If variable scope is not found then skip this variable.
Craig Topper353eda42014-04-24 06:44:33 +0000781 if (!Scope)
Devang Patelcdb7d442009-11-10 23:20:04 +0000782 continue;
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000783
David Blaikieff468a52014-10-28 02:57:26 +0000784 DIVariable DV(VI.Var);
785 DIExpression Expr(VI.Expr);
David Blaikie6f9e8672014-06-13 23:52:55 +0000786 ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000787 ConcreteVariables.push_back(make_unique<DbgVariable>(DV, Expr, this));
David Blaikieeb1a2722014-06-13 22:18:23 +0000788 DbgVariable *RegVar = ConcreteVariables.back().get();
David Blaikieafd2c6b2014-04-22 05:41:06 +0000789 RegVar->setFrameIndex(VI.Slot);
David Blaikief4c504e2014-10-24 00:43:47 +0000790 InfoHolder.addScopeVariable(Scope, RegVar);
Devang Patel475d32a2009-10-06 01:26:37 +0000791 }
Devang Patel490c8ab2010-05-20 19:57:06 +0000792}
Devang Patela3e9c9c2010-03-15 18:33:46 +0000793
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000794// Get .debug_loc entry for the instruction range starting at MI.
Adrian Prantle19e5ef2014-04-27 18:25:40 +0000795static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) {
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000796 const MDNode *Expr = MI->getDebugExpression();
Adrian Prantl7f487772014-04-10 17:39:48 +0000797 const MDNode *Var = MI->getDebugVariable();
Devang Patel2442a892011-07-08 17:09:57 +0000798
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000799 assert(MI->getNumOperands() == 4);
Adrian Prantl418d1d12013-07-09 20:28:37 +0000800 if (MI->getOperand(0).isReg()) {
Devang Patel2442a892011-07-08 17:09:57 +0000801 MachineLocation MLoc;
Adrian Prantl418d1d12013-07-09 20:28:37 +0000802 // If the second operand is an immediate, this is a
803 // register-indirect address.
804 if (!MI->getOperand(1).isImm())
Adrian Prantld4c0dd42013-04-26 21:57:17 +0000805 MLoc.set(MI->getOperand(0).getReg());
806 else
807 MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000808 return DebugLocEntry::Value(Var, Expr, MLoc);
Devang Patel2442a892011-07-08 17:09:57 +0000809 }
810 if (MI->getOperand(0).isImm())
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000811 return DebugLocEntry::Value(Var, Expr, MI->getOperand(0).getImm());
Devang Patel2442a892011-07-08 17:09:57 +0000812 if (MI->getOperand(0).isFPImm())
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000813 return DebugLocEntry::Value(Var, Expr, MI->getOperand(0).getFPImm());
Devang Patel2442a892011-07-08 17:09:57 +0000814 if (MI->getOperand(0).isCImm())
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000815 return DebugLocEntry::Value(Var, Expr, MI->getOperand(0).getCImm());
Devang Patel2442a892011-07-08 17:09:57 +0000816
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000817 llvm_unreachable("Unexpected 4-operand DBG_VALUE instruction!");
Devang Patel2442a892011-07-08 17:09:57 +0000818}
819
Adrian Prantlb1416832014-08-01 22:11:58 +0000820/// Determine whether two variable pieces overlap.
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000821static bool piecesOverlap(DIExpression P1, DIExpression P2) {
Adrian Prantlb1416832014-08-01 22:11:58 +0000822 if (!P1.isVariablePiece() || !P2.isVariablePiece())
823 return true;
824 unsigned l1 = P1.getPieceOffset();
825 unsigned l2 = P2.getPieceOffset();
826 unsigned r1 = l1 + P1.getPieceSize();
827 unsigned r2 = l2 + P2.getPieceSize();
828 // True where [l1,r1[ and [r1,r2[ overlap.
829 return (l1 < r2) && (l2 < r1);
830}
831
832/// Build the location list for all DBG_VALUEs in the function that
833/// describe the same variable. If the ranges of several independent
834/// pieces of the same variable overlap partially, split them up and
835/// combine the ranges. The resulting DebugLocEntries are will have
836/// strict monotonically increasing begin addresses and will never
837/// overlap.
838//
839// Input:
840//
841// Ranges History [var, loc, piece ofs size]
842// 0 | [x, (reg0, piece 0, 32)]
843// 1 | | [x, (reg1, piece 32, 32)] <- IsPieceOfPrevEntry
844// 2 | | ...
845// 3 | [clobber reg0]
846// 4 [x, (mem, piece 0, 64)] <- overlapping with both previous pieces of x.
847//
848// Output:
849//
850// [0-1] [x, (reg0, piece 0, 32)]
851// [1-3] [x, (reg0, piece 0, 32), (reg1, piece 32, 32)]
852// [3-4] [x, (reg1, piece 32, 32)]
853// [4- ] [x, (mem, piece 0, 64)]
David Blaikiee1a26a62014-08-05 23:14:16 +0000854void
855DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
856 const DbgValueHistoryMap::InstrRanges &Ranges) {
Adrian Prantlcaaf0532014-08-11 21:05:57 +0000857 SmallVector<DebugLocEntry::Value, 4> OpenRanges;
Adrian Prantlb1416832014-08-01 22:11:58 +0000858
859 for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
860 const MachineInstr *Begin = I->first;
861 const MachineInstr *End = I->second;
862 assert(Begin->isDebugValue() && "Invalid History entry");
863
864 // Check if a variable is inaccessible in this range.
Adrian Prantl5e1fa852014-08-12 21:55:58 +0000865 if (Begin->getNumOperands() > 1 &&
866 Begin->getOperand(0).isReg() && !Begin->getOperand(0).getReg()) {
Adrian Prantlb1416832014-08-01 22:11:58 +0000867 OpenRanges.clear();
868 continue;
869 }
870
871 // If this piece overlaps with any open ranges, truncate them.
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000872 DIExpression DIExpr = Begin->getDebugExpression();
Adrian Prantlcaaf0532014-08-11 21:05:57 +0000873 auto Last = std::remove_if(OpenRanges.begin(), OpenRanges.end(),
Adrian Prantl76502d82014-08-11 23:22:59 +0000874 [&](DebugLocEntry::Value R) {
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000875 return piecesOverlap(DIExpr, R.getExpression());
876 });
Adrian Prantlb1416832014-08-01 22:11:58 +0000877 OpenRanges.erase(Last, OpenRanges.end());
878
879 const MCSymbol *StartLabel = getLabelBeforeInsn(Begin);
880 assert(StartLabel && "Forgot label before DBG_VALUE starting a range!");
881
882 const MCSymbol *EndLabel;
883 if (End != nullptr)
884 EndLabel = getLabelAfterInsn(End);
885 else if (std::next(I) == Ranges.end())
886 EndLabel = FunctionEndSym;
887 else
888 EndLabel = getLabelBeforeInsn(std::next(I)->first);
889 assert(EndLabel && "Forgot label after instruction ending a range!");
890
891 DEBUG(dbgs() << "DotDebugLoc: " << *Begin << "\n");
892
893 auto Value = getDebugLocValue(Begin);
David Blaikiee1a26a62014-08-05 23:14:16 +0000894 DebugLocEntry Loc(StartLabel, EndLabel, Value);
Adrian Prantle09ee3f2014-08-11 20:59:28 +0000895 bool couldMerge = false;
896
897 // If this is a piece, it may belong to the current DebugLocEntry.
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000898 if (DIExpr.isVariablePiece()) {
Adrian Prantle09ee3f2014-08-11 20:59:28 +0000899 // Add this value to the list of open ranges.
Adrian Prantlcaaf0532014-08-11 21:05:57 +0000900 OpenRanges.push_back(Value);
Adrian Prantle09ee3f2014-08-11 20:59:28 +0000901
902 // Attempt to add the piece to the last entry.
903 if (!DebugLoc.empty())
904 if (DebugLoc.back().MergeValues(Loc))
905 couldMerge = true;
906 }
907
908 if (!couldMerge) {
909 // Need to add a new DebugLocEntry. Add all values from still
910 // valid non-overlapping pieces.
Adrian Prantl1c6f2ec2014-08-11 21:06:00 +0000911 if (OpenRanges.size())
912 Loc.addValues(OpenRanges);
913
Adrian Prantlb1416832014-08-01 22:11:58 +0000914 DebugLoc.push_back(std::move(Loc));
915 }
Adrian Prantle09ee3f2014-08-11 20:59:28 +0000916
917 // Attempt to coalesce the ranges of two otherwise identical
918 // DebugLocEntries.
919 auto CurEntry = DebugLoc.rbegin();
920 auto PrevEntry = std::next(CurEntry);
921 if (PrevEntry != DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
922 DebugLoc.pop_back();
Adrian Prantlb1416832014-08-01 22:11:58 +0000923
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000924 DEBUG({
925 dbgs() << CurEntry->getValues().size() << " Values:\n";
926 for (auto Value : CurEntry->getValues()) {
927 Value.getVariable()->dump();
928 Value.getExpression()->dump();
929 }
930 dbgs() << "-----\n";
931 });
Adrian Prantlb1416832014-08-01 22:11:58 +0000932 }
933}
934
935
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000936// Find variables for each lexical scope.
Jim Grosbacha8683bb2010-07-21 21:21:52 +0000937void
David Blaikie263a0082014-10-23 00:06:27 +0000938DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
939 SmallPtrSetImpl<const MDNode *> &Processed) {
Eric Christopher270a12c2013-07-03 21:37:03 +0000940 // Grab the variable info that was squirreled away in the MMI side-table.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000941 collectVariableInfoFromMMITable(Processed);
Devang Patel490c8ab2010-05-20 19:57:06 +0000942
Alexey Samsonov0436caa2014-04-30 23:02:40 +0000943 for (const auto &I : DbgValues) {
944 DIVariable DV(I.first);
945 if (Processed.count(DV))
Devang Patel490c8ab2010-05-20 19:57:06 +0000946 continue;
947
Alexey Samsonovbb2990d2014-05-27 23:09:50 +0000948 // Instruction ranges, specifying where DV is accessible.
949 const auto &Ranges = I.second;
950 if (Ranges.empty())
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000951 continue;
Devang Patel9fc11702010-05-25 23:40:22 +0000952
Craig Topper353eda42014-04-24 06:44:33 +0000953 LexicalScope *Scope = nullptr;
David Blaikie09fdfab2014-08-07 22:22:49 +0000954 if (MDNode *IA = DV.getInlinedAt()) {
David Blaikie9b8c8cd2014-05-14 01:08:28 +0000955 DebugLoc DL = DebugLoc::getFromDILocation(IA);
956 Scope = LScopes.findInlinedScope(DebugLoc::get(
957 DL.getLine(), DL.getCol(), DV.getContext(), IA));
958 } else
959 Scope = LScopes.findLexicalScope(DV.getContext());
Devang Patel490c8ab2010-05-20 19:57:06 +0000960 // If variable scope is not found then skip this variable.
Devang Patelfbd6c452010-05-21 00:10:20 +0000961 if (!Scope)
Devang Patel490c8ab2010-05-20 19:57:06 +0000962 continue;
963
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000964 Processed.insert(DV);
Alexey Samsonovbb2990d2014-05-27 23:09:50 +0000965 const MachineInstr *MInsn = Ranges.front().first;
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000966 assert(MInsn->isDebugValue() && "History must begin with debug value");
David Blaikie6f9e8672014-06-13 23:52:55 +0000967 ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
968 ConcreteVariables.push_back(make_unique<DbgVariable>(MInsn, this));
David Blaikieeb1a2722014-06-13 22:18:23 +0000969 DbgVariable *RegVar = ConcreteVariables.back().get();
David Blaikief4c504e2014-10-24 00:43:47 +0000970 InfoHolder.addScopeVariable(Scope, RegVar);
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000971
Alexey Samsonovbb2990d2014-05-27 23:09:50 +0000972 // Check if the first DBG_VALUE is valid for the rest of the function.
Adrian Prantlc1197542014-05-30 21:10:13 +0000973 if (Ranges.size() == 1 && Ranges.front().second == nullptr)
Devang Patel9fc11702010-05-25 23:40:22 +0000974 continue;
Devang Patel9fc11702010-05-25 23:40:22 +0000975
Eric Christopher59cc0712013-01-28 17:33:26 +0000976 // Handle multiple DBG_VALUE instructions describing one variable.
David Blaikieafd2c6b2014-04-22 05:41:06 +0000977 RegVar->setDotDebugLocOffset(DotDebugLocEntries.size());
Jakob Stoklund Olesenec0ac3c2011-03-22 22:33:08 +0000978
David Blaikie0a456de2014-04-02 01:43:18 +0000979 DotDebugLocEntries.resize(DotDebugLocEntries.size() + 1);
980 DebugLocList &LocList = DotDebugLocEntries.back();
David Blaikie263a0082014-10-23 00:06:27 +0000981 LocList.CU = &TheCU;
David Blaikie0a456de2014-04-02 01:43:18 +0000982 LocList.Label =
983 Asm->GetTempSymbol("debug_loc", DotDebugLocEntries.size() - 1);
Jakob Stoklund Olesen9c057ee2011-03-22 00:21:41 +0000984
Adrian Prantlb1416832014-08-01 22:11:58 +0000985 // Build the location list for this variable.
David Blaikiee1a26a62014-08-05 23:14:16 +0000986 buildLocationList(LocList.List, Ranges);
Devang Patela3e9c9c2010-03-15 18:33:46 +0000987 }
Devang Patele0a94bf2010-05-14 21:01:35 +0000988
989 // Collect info for variables that were optimized out.
David Blaikie263a0082014-10-23 00:06:27 +0000990 DIArray Variables = SP.getVariables();
Devang Patel59e27c52011-08-19 23:28:12 +0000991 for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
992 DIVariable DV(Variables.getElement(i));
David Blaikie9ba72542014-05-14 21:52:46 +0000993 assert(DV.isVariable());
David Blaikie70573dc2014-11-19 07:49:26 +0000994 if (!Processed.insert(DV).second)
Devang Patel59e27c52011-08-19 23:28:12 +0000995 continue;
David Blaikiebb6a4e22014-06-05 00:51:35 +0000996 if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext())) {
David Blaikie6f9e8672014-06-13 23:52:55 +0000997 ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000998 DIExpression NoExpr;
999 ConcreteVariables.push_back(make_unique<DbgVariable>(DV, NoExpr, this));
David Blaikief4c504e2014-10-24 00:43:47 +00001000 InfoHolder.addScopeVariable(Scope, ConcreteVariables.back().get());
David Blaikiebb6a4e22014-06-05 00:51:35 +00001001 }
Devang Patele0a94bf2010-05-14 21:01:35 +00001002 }
Devang Patel9fc11702010-05-25 23:40:22 +00001003}
Devang Patele0a94bf2010-05-14 21:01:35 +00001004
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001005// Return Label preceding the instruction.
Eric Christopher962c9082013-01-15 23:56:56 +00001006MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001007 MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
1008 assert(Label && "Didn't insert label before instruction");
1009 return Label;
Devang Patel9fc11702010-05-25 23:40:22 +00001010}
1011
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001012// Return Label immediately following the instruction.
Eric Christopher962c9082013-01-15 23:56:56 +00001013MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001014 return LabelsAfterInsn.lookup(MI);
Devang Patel475d32a2009-10-06 01:26:37 +00001015}
1016
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001017// Process beginning of an instruction.
Devang Patelb5694e72010-10-26 17:49:02 +00001018void DwarfDebug::beginInstruction(const MachineInstr *MI) {
Craig Toppere73658d2014-04-28 04:05:08 +00001019 assert(CurMI == nullptr);
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001020 CurMI = MI;
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001021 // Check if source location changes, but ignore DBG_VALUE locations.
1022 if (!MI->isDebugValue()) {
1023 DebugLoc DL = MI->getDebugLoc();
1024 if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) {
Eric Christopheraec8a822012-04-05 20:39:05 +00001025 unsigned Flags = 0;
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001026 PrevInstLoc = DL;
Devang Patel34a66202011-05-11 19:22:19 +00001027 if (DL == PrologEndLoc) {
1028 Flags |= DWARF2_FLAG_PROLOGUE_END;
1029 PrologEndLoc = DebugLoc();
David Blaikieaeaa5bf2014-12-30 22:47:13 +00001030 Flags |= DWARF2_FLAG_IS_STMT;
Devang Patel34a66202011-05-11 19:22:19 +00001031 }
David Blaikieaeaa5bf2014-12-30 22:47:13 +00001032 if (DL.getLine() !=
1033 Asm->OutStreamer.getContext().getCurrentDwarfLoc().getLine())
Eric Christopheraec8a822012-04-05 20:39:05 +00001034 Flags |= DWARF2_FLAG_IS_STMT;
1035
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001036 if (!DL.isUnknown()) {
1037 const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext());
Devang Patel34a66202011-05-11 19:22:19 +00001038 recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001039 } else
Craig Topper353eda42014-04-24 06:44:33 +00001040 recordSourceLine(0, 0, nullptr, 0);
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001041 }
Devang Patel9fc11702010-05-25 23:40:22 +00001042 }
Devang Patel23b2ae62010-03-29 22:59:58 +00001043
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001044 // Insert labels where requested.
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001045 DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
1046 LabelsBeforeInsn.find(MI);
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001047
1048 // No label needed.
1049 if (I == LabelsBeforeInsn.end())
1050 return;
1051
1052 // Label already assigned.
1053 if (I->second)
Devang Patel002d54d2010-05-26 19:37:24 +00001054 return;
Devang Patelbd477be2010-03-29 17:20:31 +00001055
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001056 if (!PrevLabel) {
Devang Patelacc32a52010-05-26 21:23:46 +00001057 PrevLabel = MMI->getContext().CreateTempSymbol();
1058 Asm->OutStreamer.EmitLabel(PrevLabel);
Devang Patel002d54d2010-05-26 19:37:24 +00001059 }
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001060 I->second = PrevLabel;
Devang Patel8db360d2009-10-06 01:50:42 +00001061}
1062
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001063// Process end of an instruction.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001064void DwarfDebug::endInstruction() {
Craig Toppere73658d2014-04-28 04:05:08 +00001065 assert(CurMI != nullptr);
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001066 // Don't create a new label after DBG_VALUE instructions.
1067 // They don't generate code.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001068 if (!CurMI->isDebugValue())
Craig Topper353eda42014-04-24 06:44:33 +00001069 PrevLabel = nullptr;
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001070
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001071 DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001072 LabelsAfterInsn.find(CurMI);
Craig Topper353eda42014-04-24 06:44:33 +00001073 CurMI = nullptr;
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001074
1075 // No label needed.
1076 if (I == LabelsAfterInsn.end())
1077 return;
1078
1079 // Label already assigned.
1080 if (I->second)
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001081 return;
1082
1083 // We need a label after this instruction.
1084 if (!PrevLabel) {
1085 PrevLabel = MMI->getContext().CreateTempSymbol();
1086 Asm->OutStreamer.EmitLabel(PrevLabel);
Devang Patel3ebd8932010-04-08 16:50:29 +00001087 }
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001088 I->second = PrevLabel;
Devang Patelf6eeaeb2009-11-10 23:06:00 +00001089}
1090
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001091// Each LexicalScope has first instruction and last instruction to mark
1092// beginning and end of a scope respectively. Create an inverse map that list
1093// scopes starts (and ends) with an instruction. One instruction may start (or
1094// end) multiple scopes. Ignore scopes that are not reachable.
Devang Patel359b0132010-04-08 18:43:56 +00001095void DwarfDebug::identifyScopeMarkers() {
Devang Patel7e623022011-08-10 20:55:27 +00001096 SmallVector<LexicalScope *, 4> WorkList;
1097 WorkList.push_back(LScopes.getCurrentFunctionScope());
Devang Patel7771b7c2010-01-20 02:05:23 +00001098 while (!WorkList.empty()) {
Devang Patel7e623022011-08-10 20:55:27 +00001099 LexicalScope *S = WorkList.pop_back_val();
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001100
Craig Topper977e9cd2013-07-03 04:24:43 +00001101 const SmallVectorImpl<LexicalScope *> &Children = S->getChildren();
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001102 if (!Children.empty())
Benjamin Kramer15596c72014-03-07 19:09:39 +00001103 WorkList.append(Children.begin(), Children.end());
Devang Patel7771b7c2010-01-20 02:05:23 +00001104
Devang Patelf6eeaeb2009-11-10 23:06:00 +00001105 if (S->isAbstractScope())
1106 continue;
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001107
Benjamin Kramer15596c72014-03-07 19:09:39 +00001108 for (const InsnRange &R : S->getRanges()) {
1109 assert(R.first && "InsnRange does not have first instruction!");
1110 assert(R.second && "InsnRange does not have second instruction!");
1111 requestLabelBeforeInsn(R.first);
1112 requestLabelAfterInsn(R.second);
Devang Patel6c74a872010-04-27 19:46:33 +00001113 }
Devang Patel75cc16c2009-10-01 20:31:14 +00001114 }
Devang Patel75cc16c2009-10-01 20:31:14 +00001115}
1116
Alexey Samsonov8a86d6d2014-05-27 22:47:41 +00001117static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
1118 // First known non-DBG_VALUE and non-frame setup location marks
1119 // the beginning of the function body.
1120 for (const auto &MBB : *MF)
1121 for (const auto &MI : MBB)
1122 if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) &&
Adrian Prantlb9fa9452014-12-16 00:20:49 +00001123 !MI.getDebugLoc().isUnknown()) {
1124 // Did the target forget to set the FrameSetup flag for CFI insns?
1125 assert(!MI.isCFIInstruction() &&
1126 "First non-frame-setup instruction is a CFI instruction.");
Alexey Samsonov8a86d6d2014-05-27 22:47:41 +00001127 return MI.getDebugLoc();
Adrian Prantlb9fa9452014-12-16 00:20:49 +00001128 }
Alexey Samsonov8a86d6d2014-05-27 22:47:41 +00001129 return DebugLoc();
1130}
1131
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001132// Gather pre-function debug information. Assumes being called immediately
1133// after the function entry point has been emitted.
Chris Lattner76555b52010-01-26 23:18:02 +00001134void DwarfDebug::beginFunction(const MachineFunction *MF) {
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001135 CurFn = MF;
Eric Christopherfedfa442013-11-01 23:14:17 +00001136
1137 // If there's no debug info for the function we're not going to do anything.
1138 if (!MMI->hasDebugInfo())
1139 return;
1140
David Blaikie2f040112014-07-25 16:10:16 +00001141 auto DI = FunctionDIs.find(MF->getFunction());
1142 if (DI == FunctionDIs.end())
1143 return;
1144
Eric Christopherfedfa442013-11-01 23:14:17 +00001145 // Grab the lexical scopes for the function, if we don't have any of those
1146 // then we're not going to be able to do anything.
Devang Patel7e623022011-08-10 20:55:27 +00001147 LScopes.initialize(*MF);
Eric Christopher384f3fe2014-03-20 19:16:16 +00001148 if (LScopes.empty())
Eric Christopherfedfa442013-11-01 23:14:17 +00001149 return;
1150
Alexey Samsonov0436caa2014-04-30 23:02:40 +00001151 assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
Eric Christopherfedfa442013-11-01 23:14:17 +00001152
1153 // Make sure that each lexical scope will have a begin/end label.
Devang Patel7e623022011-08-10 20:55:27 +00001154 identifyScopeMarkers();
Devang Patel4598eb62009-10-06 18:37:31 +00001155
Eric Christopher4287a492013-12-09 23:57:44 +00001156 // Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
Eric Christopherfedfa442013-11-01 23:14:17 +00001157 // belongs to so that we add to the correct per-cu line table in the
1158 // non-asm case.
Manman Ren4e042a62013-02-05 21:52:47 +00001159 LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
David Blaikie2f040112014-07-25 16:10:16 +00001160 // FnScope->getScopeNode() and DI->second should represent the same function,
1161 // though they may not be the same MDNode due to inline functions merged in
1162 // LTO where the debug info metadata still differs (either due to distinct
1163 // written differences - two versions of a linkonce_odr function
1164 // written/copied into two separate files, or some sub-optimal metadata that
1165 // isn't structurally identical (see: file path/name info from clang, which
1166 // includes the directory of the cpp file being built, even when the file name
1167 // is absolute (such as an <> lookup header)))
Eric Christopher4287a492013-12-09 23:57:44 +00001168 DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
Manman Ren4e042a62013-02-05 21:52:47 +00001169 assert(TheCU && "Unable to find compile unit!");
Rafael Espindolab4eec1d2014-02-05 18:00:21 +00001170 if (Asm->OutStreamer.hasRawTextSupport())
1171 // Use a single line table if we are generating assembly.
Manman Ren9d4c7352013-05-21 00:57:22 +00001172 Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
1173 else
1174 Asm->OutStreamer.getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
Manman Ren4e042a62013-02-05 21:52:47 +00001175
Eric Christopherfedfa442013-11-01 23:14:17 +00001176 // Emit a label for the function so that we have a beginning address.
1177 FunctionBeginSym = Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber());
Bill Wendling2b128d72009-05-20 23:19:06 +00001178 // Assumes in correct section after the entry point.
Devang Patel6c74a872010-04-27 19:46:33 +00001179 Asm->OutStreamer.EmitLabel(FunctionBeginSym);
Bill Wendling2b128d72009-05-20 23:19:06 +00001180
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00001181 // Calculate history for local variables.
Eric Christopherd9134482014-08-04 21:25:23 +00001182 calculateDbgValueHistory(MF, Asm->TM.getSubtargetImpl()->getRegisterInfo(),
1183 DbgValues);
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00001184
1185 // Request labels for the full history.
Alexey Samsonovbb2990d2014-05-27 23:09:50 +00001186 for (const auto &I : DbgValues) {
1187 const auto &Ranges = I.second;
1188 if (Ranges.empty())
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001189 continue;
1190
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00001191 // The first mention of a function argument gets the FunctionBeginSym
1192 // label, so arguments are visible when breaking at function entry.
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001193 DIVariable DIVar(Ranges.front().first->getDebugVariable());
1194 if (DIVar.isVariable() && DIVar.getTag() == dwarf::DW_TAG_arg_variable &&
1195 getDISubprogram(DIVar.getContext()).describes(MF->getFunction())) {
1196 LabelsBeforeInsn[Ranges.front().first] = FunctionBeginSym;
1197 if (Ranges.front().first->getDebugExpression().isVariablePiece()) {
Adrian Prantlb1416832014-08-01 22:11:58 +00001198 // Mark all non-overlapping initial pieces.
1199 for (auto I = Ranges.begin(); I != Ranges.end(); ++I) {
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001200 DIExpression Piece = I->first->getDebugExpression();
Adrian Prantlb1416832014-08-01 22:11:58 +00001201 if (std::all_of(Ranges.begin(), I,
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001202 [&](DbgValueHistoryMap::InstrRange Pred) {
1203 return !piecesOverlap(Piece, Pred.first->getDebugExpression());
Adrian Prantlb1416832014-08-01 22:11:58 +00001204 }))
1205 LabelsBeforeInsn[I->first] = FunctionBeginSym;
1206 else
1207 break;
1208 }
1209 }
1210 }
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00001211
Alexey Samsonovbb2990d2014-05-27 23:09:50 +00001212 for (const auto &Range : Ranges) {
1213 requestLabelBeforeInsn(Range.first);
1214 if (Range.second)
1215 requestLabelAfterInsn(Range.second);
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001216 }
1217 }
Devang Patel002d54d2010-05-26 19:37:24 +00001218
Jakob Stoklund Olesen1886a4c2011-03-25 17:20:59 +00001219 PrevInstLoc = DebugLoc();
Devang Patel002d54d2010-05-26 19:37:24 +00001220 PrevLabel = FunctionBeginSym;
Devang Patel34a66202011-05-11 19:22:19 +00001221
1222 // Record beginning of function.
Alexey Samsonov8a86d6d2014-05-27 22:47:41 +00001223 PrologEndLoc = findPrologueEndLoc(MF);
Devang Patel34a66202011-05-11 19:22:19 +00001224 if (!PrologEndLoc.isUnknown()) {
Eric Christopherfedfa442013-11-01 23:14:17 +00001225 DebugLoc FnStartDL =
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +00001226 PrologEndLoc.getFnDebugLoc(MF->getFunction()->getContext());
Eric Christopherfedfa442013-11-01 23:14:17 +00001227 recordSourceLine(
1228 FnStartDL.getLine(), FnStartDL.getCol(),
1229 FnStartDL.getScope(MF->getFunction()->getContext()),
1230 // We'd like to list the prologue as "not statements" but GDB behaves
1231 // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
1232 DWARF2_FLAG_IS_STMT);
Devang Patel34a66202011-05-11 19:22:19 +00001233 }
Bill Wendling2b128d72009-05-20 23:19:06 +00001234}
1235
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001236// Gather and emit post-function debug information.
NAKAMURA Takumib9271612013-12-03 13:15:54 +00001237void DwarfDebug::endFunction(const MachineFunction *MF) {
David Blaikiee75f9632014-10-14 17:12:02 +00001238 assert(CurFn == MF &&
1239 "endFunction should be called with the same function as beginFunction");
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001240
David Blaikie2f040112014-07-25 16:10:16 +00001241 if (!MMI->hasDebugInfo() || LScopes.empty() ||
1242 !FunctionDIs.count(MF->getFunction())) {
Eric Christopher384f3fe2014-03-20 19:16:16 +00001243 // If we don't have a lexical scope for this function then there will
1244 // be a hole in the range information. Keep note of this by setting the
1245 // previously used section to nullptr.
Eric Christopher384f3fe2014-03-20 19:16:16 +00001246 PrevCU = nullptr;
Craig Topper353eda42014-04-24 06:44:33 +00001247 CurFn = nullptr;
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001248 return;
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +00001249 }
Devang Patel2904aa92009-11-12 19:02:56 +00001250
Devang Patel7e623022011-08-10 20:55:27 +00001251 // Define end label for subprogram.
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001252 FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());
Devang Patel7e623022011-08-10 20:55:27 +00001253 // Assumes in correct section after the entry point.
1254 Asm->OutStreamer.EmitLabel(FunctionEndSym);
Eric Christopher1a972152014-01-29 23:05:43 +00001255
Eric Christopher4287a492013-12-09 23:57:44 +00001256 // Set DwarfDwarfCompileUnitID in MCContext to default value.
Manman Ren4e042a62013-02-05 21:52:47 +00001257 Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
Eric Christopher6a841382012-11-19 22:42:10 +00001258
Devang Patel3acc70e2011-08-15 22:04:40 +00001259 LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
David Blaikie263a0082014-10-23 00:06:27 +00001260 DISubprogram SP(FnScope->getScopeNode());
1261 DwarfCompileUnit &TheCU = *SPMap.lookup(SP);
1262
1263 SmallPtrSet<const MDNode *, 16> ProcessedVars;
1264 collectVariableInfo(TheCU, SP, ProcessedVars);
Devang Patel3acc70e2011-08-15 22:04:40 +00001265
David Blaikie3a7ce252014-09-19 17:03:16 +00001266 // Add the range of this function to the list of ranges for the CU.
1267 TheCU.addRange(RangeSpan(FunctionBeginSym, FunctionEndSym));
1268
1269 // Under -gmlt, skip building the subprogram if there are no inlined
1270 // subroutines inside it.
1271 if (TheCU.getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly &&
David Blaikiee1c79742014-09-30 21:28:32 +00001272 LScopes.getAbstractScopesList().empty() && !IsDarwin) {
David Blaikie80e5b1e2014-10-24 17:57:34 +00001273 assert(InfoHolder.getScopeVariables().empty());
David Blaikie3a7ce252014-09-19 17:03:16 +00001274 assert(DbgValues.empty());
David Blaikie8b2fdb82014-10-09 18:24:28 +00001275 // FIXME: This wouldn't be true in LTO with a -g (with inlining) CU followed
1276 // by a -gmlt CU. Add a test and remove this assertion.
David Blaikie3a7ce252014-09-19 17:03:16 +00001277 assert(AbstractVariables.empty());
1278 LabelsBeforeInsn.clear();
1279 LabelsAfterInsn.clear();
1280 PrevLabel = nullptr;
1281 CurFn = nullptr;
1282 return;
1283 }
1284
Adrian Prantl049d21c2014-10-13 20:44:58 +00001285#ifndef NDEBUG
1286 size_t NumAbstractScopes = LScopes.getAbstractScopesList().size();
1287#endif
Devang Patel7e623022011-08-10 20:55:27 +00001288 // Construct abstract scopes.
Benjamin Kramer15596c72014-03-07 19:09:39 +00001289 for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
Devang Patel44403472011-08-12 18:10:19 +00001290 DISubprogram SP(AScope->getScopeNode());
David Blaikiedb5371b2014-07-18 22:26:59 +00001291 assert(SP.isSubprogram());
David Blaikie4abe19e2014-05-12 18:23:35 +00001292 // Collect info for variables that were optimized out.
1293 DIArray Variables = SP.getVariables();
1294 for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
1295 DIVariable DV(Variables.getElement(i));
1296 assert(DV && DV.isVariable());
David Blaikie70573dc2014-11-19 07:49:26 +00001297 if (!ProcessedVars.insert(DV).second)
David Blaikie4abe19e2014-05-12 18:23:35 +00001298 continue;
David Blaikie6f9e8672014-06-13 23:52:55 +00001299 ensureAbstractVariableIsCreated(DV, DV.getContext());
Adrian Prantl049d21c2014-10-13 20:44:58 +00001300 assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes
1301 && "ensureAbstractVariableIsCreated inserted abstract scopes");
Devang Patel5c0f85c2010-06-25 22:07:34 +00001302 }
David Blaikie73cc7052014-10-09 20:36:27 +00001303 constructAbstractSubprogramScopeDIE(AScope);
Bill Wendling2b128d72009-05-20 23:19:06 +00001304 }
Eric Christopher6a841382012-11-19 22:42:10 +00001305
David Blaikie1d072342014-10-09 20:21:36 +00001306 TheCU.constructSubprogramScopeDIE(FnScope);
David Blaikie3a443c22014-11-04 22:12:25 +00001307 if (auto *SkelCU = TheCU.getSkeleton())
1308 if (!LScopes.getAbstractScopesList().empty())
1309 SkelCU->constructSubprogramScopeDIE(FnScope);
Devang Patel3acc70e2011-08-15 22:04:40 +00001310
Bill Wendling2b128d72009-05-20 23:19:06 +00001311 // Clear debug info
David Blaikie825bdd22014-05-21 22:41:17 +00001312 // Ownership of DbgVariables is a bit subtle - ScopeVariables owns all the
1313 // DbgVariables except those that are also in AbstractVariables (since they
1314 // can be used cross-function)
David Blaikie80e5b1e2014-10-24 17:57:34 +00001315 InfoHolder.getScopeVariables().clear();
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +00001316 DbgValues.clear();
Devang Patel6c74a872010-04-27 19:46:33 +00001317 LabelsBeforeInsn.clear();
1318 LabelsAfterInsn.clear();
Craig Topper353eda42014-04-24 06:44:33 +00001319 PrevLabel = nullptr;
1320 CurFn = nullptr;
Bill Wendling2b128d72009-05-20 23:19:06 +00001321}
1322
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001323// Register a source line with debug info. Returns the unique label that was
1324// emitted and which provides correspondence to the source line list.
Devang Patel34a66202011-05-11 19:22:19 +00001325void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
1326 unsigned Flags) {
Devang Patel2d9caf92009-11-25 17:36:49 +00001327 StringRef Fn;
Devang Patele01b75c2011-03-24 20:30:50 +00001328 StringRef Dir;
Dan Gohman50849c62010-05-05 23:41:32 +00001329 unsigned Src = 1;
Diego Novillo282450d2014-03-03 18:53:17 +00001330 unsigned Discriminator = 0;
David Blaikie4c6d9872014-05-15 20:18:50 +00001331 if (DIScope Scope = DIScope(S)) {
1332 assert(Scope.isScope());
1333 Fn = Scope.getFilename();
1334 Dir = Scope.getDirectory();
David Blaikie2f3f76f2014-08-21 22:45:21 +00001335 if (Scope.isLexicalBlockFile())
1336 Discriminator = DILexicalBlockFile(S).getDiscriminator();
Dan Gohman50849c62010-05-05 23:41:32 +00001337
David Blaikie0e8d4012014-03-17 23:53:25 +00001338 unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
David Blaikiec33b3cd2014-04-22 21:27:37 +00001339 Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])
1340 .getOrCreateSourceID(Fn, Dir);
Dan Gohman50849c62010-05-05 23:41:32 +00001341 }
Diego Novillo282450d2014-03-03 18:53:17 +00001342 Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0,
1343 Discriminator, Fn);
Bill Wendling2b128d72009-05-20 23:19:06 +00001344}
1345
Bill Wendling806535f2009-05-20 23:22:40 +00001346//===----------------------------------------------------------------------===//
1347// Emit Methods
1348//===----------------------------------------------------------------------===//
1349
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001350// Emit initial Dwarf sections with a label at the start of each one.
Eric Christopher7b30f2e42012-11-21 00:34:35 +00001351void DwarfDebug::emitSectionLabels() {
Chris Lattner4b7dadb2009-08-19 05:49:37 +00001352 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
Daniel Dunbarc418d6b2009-09-19 20:40:05 +00001353
Bill Wendling480ff322009-05-20 23:21:38 +00001354 // Dwarf sections base addresses.
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001355 DwarfInfoSectionSym =
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001356 emitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
David Blaikie29459ae2014-07-25 17:11:58 +00001357 if (useSplitDwarf()) {
Eric Christopherd8667202013-12-30 17:22:27 +00001358 DwarfInfoDWOSectionSym =
1359 emitSectionSym(Asm, TLOF.getDwarfInfoDWOSection(), "section_info_dwo");
David Blaikie29459ae2014-07-25 17:11:58 +00001360 DwarfTypesDWOSectionSym =
1361 emitSectionSym(Asm, TLOF.getDwarfTypesDWOSection(), "section_types_dwo");
1362 }
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001363 DwarfAbbrevSectionSym =
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001364 emitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
Eric Christopher3c5a1912012-12-19 22:02:53 +00001365 if (useSplitDwarf())
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001366 DwarfAbbrevDWOSectionSym = emitSectionSym(
1367 Asm, TLOF.getDwarfAbbrevDWOSection(), "section_abbrev_dwo");
David Blaikie20474102014-02-25 22:46:44 +00001368 if (GenerateARangeSection)
1369 emitSectionSym(Asm, TLOF.getDwarfARangesSection());
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001370
Eric Christopher74804332013-02-07 21:19:50 +00001371 DwarfLineSectionSym =
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001372 emitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line");
Eric Christopher261d2342013-09-23 20:55:35 +00001373 if (GenerateGnuPubSections) {
Eric Christopher39eebfa2013-09-30 23:14:16 +00001374 DwarfGnuPubNamesSectionSym =
1375 emitSectionSym(Asm, TLOF.getDwarfGnuPubNamesSection());
1376 DwarfGnuPubTypesSectionSym =
1377 emitSectionSym(Asm, TLOF.getDwarfGnuPubTypesSection());
Eric Christopher261d2342013-09-23 20:55:35 +00001378 } else if (HasDwarfPubSections) {
1379 emitSectionSym(Asm, TLOF.getDwarfPubNamesSection());
1380 emitSectionSym(Asm, TLOF.getDwarfPubTypesSection());
Michael Gottesmanc89466f2013-09-04 04:39:38 +00001381 }
Eric Christopherdd1a0122013-09-13 00:35:05 +00001382
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001383 DwarfStrSectionSym =
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001384 emitSectionSym(Asm, TLOF.getDwarfStrSection(), "info_string");
Eric Christopher55863be2013-04-07 03:43:09 +00001385 if (useSplitDwarf()) {
Eric Christopher3bf29fd2012-12-27 02:14:01 +00001386 DwarfStrDWOSectionSym =
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001387 emitSectionSym(Asm, TLOF.getDwarfStrDWOSection(), "skel_string");
Eric Christopher55863be2013-04-07 03:43:09 +00001388 DwarfAddrSectionSym =
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001389 emitSectionSym(Asm, TLOF.getDwarfAddrSection(), "addr_sec");
David Blaikiee12ab122014-04-01 16:09:49 +00001390 DwarfDebugLocSectionSym =
David Blaikie9c550ac2014-03-25 01:44:02 +00001391 emitSectionSym(Asm, TLOF.getDwarfLocDWOSection(), "skel_loc");
1392 } else
1393 DwarfDebugLocSectionSym =
1394 emitSectionSym(Asm, TLOF.getDwarfLocSection(), "section_debug_loc");
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001395 DwarfDebugRangeSectionSym =
1396 emitSectionSym(Asm, TLOF.getDwarfRangesSection(), "debug_range");
Bill Wendling480ff322009-05-20 23:21:38 +00001397}
1398
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001399// Recursively emits a debug information entry.
David Blaikieb8184182014-04-14 22:45:02 +00001400void DwarfDebug::emitDIE(DIE &Die) {
Bill Wendling480ff322009-05-20 23:21:38 +00001401 // Get the abbreviation for this DIE.
David Blaikieb8184182014-04-14 22:45:02 +00001402 const DIEAbbrev &Abbrev = Die.getAbbrev();
Bill Wendling480ff322009-05-20 23:21:38 +00001403
Bill Wendling480ff322009-05-20 23:21:38 +00001404 // Emit the code (index) for the abbreviation.
Chris Lattner7bde8c02010-04-04 18:52:31 +00001405 if (Asm->isVerbose())
David Blaikieff3ab2c2013-12-05 01:01:41 +00001406 Asm->OutStreamer.AddComment("Abbrev [" + Twine(Abbrev.getNumber()) +
David Blaikieb8184182014-04-14 22:45:02 +00001407 "] 0x" + Twine::utohexstr(Die.getOffset()) +
1408 ":0x" + Twine::utohexstr(Die.getSize()) + " " +
David Blaikieff3ab2c2013-12-05 01:01:41 +00001409 dwarf::TagString(Abbrev.getTag()));
1410 Asm->EmitULEB128(Abbrev.getNumber());
Bill Wendling480ff322009-05-20 23:21:38 +00001411
David Blaikieb8184182014-04-14 22:45:02 +00001412 const SmallVectorImpl<DIEValue *> &Values = Die.getValues();
David Blaikieff3ab2c2013-12-05 01:01:41 +00001413 const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Bill Wendling480ff322009-05-20 23:21:38 +00001414
1415 // Emit the DIE attribute values.
1416 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
David Blaikief2443192013-10-21 17:28:37 +00001417 dwarf::Attribute Attr = AbbrevData[i].getAttribute();
1418 dwarf::Form Form = AbbrevData[i].getForm();
Bill Wendling480ff322009-05-20 23:21:38 +00001419 assert(Form && "Too many attributes for DIE (check abbreviation)");
1420
Eric Christopher13a1bb32014-03-06 00:00:49 +00001421 if (Asm->isVerbose()) {
Chris Lattner5adf9872010-01-24 18:54:17 +00001422 Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
Eric Christopher13a1bb32014-03-06 00:00:49 +00001423 if (Attr == dwarf::DW_AT_accessibility)
1424 Asm->OutStreamer.AddComment(dwarf::AccessibilityString(
1425 cast<DIEInteger>(Values[i])->getValue()));
1426 }
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001427
Eric Christopherdd508382014-03-06 00:00:56 +00001428 // Emit an attribute using the defined form.
1429 Values[i]->EmitValue(Asm, Form);
Bill Wendling480ff322009-05-20 23:21:38 +00001430 }
1431
1432 // Emit the DIE children if any.
Eric Christophere8f10722014-03-05 01:44:58 +00001433 if (Abbrev.hasChildren()) {
David Blaikieb8184182014-04-14 22:45:02 +00001434 for (auto &Child : Die.getChildren())
1435 emitDIE(*Child);
Bill Wendling480ff322009-05-20 23:21:38 +00001436
David Blaikie155f8812013-12-04 21:51:05 +00001437 Asm->OutStreamer.AddComment("End Of Children Mark");
Chris Lattner566cae92010-03-09 23:52:58 +00001438 Asm->EmitInt8(0);
Bill Wendling480ff322009-05-20 23:21:38 +00001439 }
1440}
1441
Eric Christopher9c2ecd92012-11-30 23:59:06 +00001442// Emit the debug info section.
1443void DwarfDebug::emitDebugInfo() {
Eric Christopherf8194852013-12-05 18:06:10 +00001444 DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
Eric Christophera2de8262012-12-15 00:04:07 +00001445
David Blaikie2b22b1e2014-10-23 00:16:03 +00001446 Holder.emitUnits(DwarfAbbrevSectionSym);
Eric Christopher9c2ecd92012-11-30 23:59:06 +00001447}
1448
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001449// Emit the abbreviation section.
Eric Christopher38371952012-11-20 23:30:11 +00001450void DwarfDebug::emitAbbreviations() {
Eric Christopherf8194852013-12-05 18:06:10 +00001451 DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
David Blaikie0504cda2013-12-05 07:43:55 +00001452
1453 Holder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
Eric Christopher3c5a1912012-12-19 22:02:53 +00001454}
Bill Wendling480ff322009-05-20 23:21:38 +00001455
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001456// Emit the last address of the section and the end of the line matrix.
Devang Patel930143b2009-11-21 02:48:08 +00001457void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
Bill Wendling480ff322009-05-20 23:21:38 +00001458 // Define last address of section.
Chris Lattner566cae92010-03-09 23:52:58 +00001459 Asm->OutStreamer.AddComment("Extended Op");
1460 Asm->EmitInt8(0);
Jim Grosbacha8683bb2010-07-21 21:21:52 +00001461
Chris Lattner566cae92010-03-09 23:52:58 +00001462 Asm->OutStreamer.AddComment("Op size");
Chandler Carruth5da3f052012-11-01 09:14:31 +00001463 Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1);
Chris Lattner566cae92010-03-09 23:52:58 +00001464 Asm->OutStreamer.AddComment("DW_LNE_set_address");
1465 Asm->EmitInt8(dwarf::DW_LNE_set_address);
1466
1467 Asm->OutStreamer.AddComment("Section end label");
Chris Lattnerb245dfb2010-03-10 01:17:49 +00001468
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001469 Asm->OutStreamer.EmitSymbolValue(
1470 Asm->GetTempSymbol("section_end", SectionEnd),
1471 Asm->getDataLayout().getPointerSize());
Bill Wendling480ff322009-05-20 23:21:38 +00001472
1473 // Mark end of matrix.
Chris Lattner566cae92010-03-09 23:52:58 +00001474 Asm->OutStreamer.AddComment("DW_LNE_end_sequence");
1475 Asm->EmitInt8(0);
Chris Lattnerf5c834f2010-01-22 22:09:00 +00001476 Asm->EmitInt8(1);
Chris Lattnerfa823552010-01-22 23:18:42 +00001477 Asm->EmitInt8(1);
Bill Wendling480ff322009-05-20 23:21:38 +00001478}
1479
David Blaikie6741bb02014-09-11 21:12:48 +00001480void DwarfDebug::emitAccel(DwarfAccelTable &Accel, const MCSection *Section,
1481 StringRef TableName, StringRef SymName) {
1482 Accel.FinalizeTable(Asm, TableName);
1483 Asm->OutStreamer.SwitchSection(Section);
1484 auto *SectionBegin = Asm->GetTempSymbol(SymName);
Eric Christopher4996c702011-11-07 09:24:32 +00001485 Asm->OutStreamer.EmitLabel(SectionBegin);
1486
1487 // Emit the full data.
Frederic Riss3a6b3542014-11-12 23:48:14 +00001488 Accel.Emit(Asm, SectionBegin, this, DwarfStrSectionSym);
David Blaikie6741bb02014-09-11 21:12:48 +00001489}
1490
1491// Emit visible names into a hashed accelerator table section.
1492void DwarfDebug::emitAccelNames() {
1493 emitAccel(AccelNames, Asm->getObjFileLowering().getDwarfAccelNamesSection(),
1494 "Names", "names_begin");
Eric Christopher4996c702011-11-07 09:24:32 +00001495}
1496
Eric Christopher48fef592012-12-20 21:58:40 +00001497// Emit objective C classes and categories into a hashed accelerator table
1498// section.
Eric Christopher4996c702011-11-07 09:24:32 +00001499void DwarfDebug::emitAccelObjC() {
David Blaikie6741bb02014-09-11 21:12:48 +00001500 emitAccel(AccelObjC, Asm->getObjFileLowering().getDwarfAccelObjCSection(),
1501 "ObjC", "objc_begin");
Eric Christopher4996c702011-11-07 09:24:32 +00001502}
1503
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001504// Emit namespace dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +00001505void DwarfDebug::emitAccelNamespaces() {
David Blaikie6741bb02014-09-11 21:12:48 +00001506 emitAccel(AccelNamespace,
1507 Asm->getObjFileLowering().getDwarfAccelNamespaceSection(),
1508 "namespac", "namespac_begin");
Eric Christopher4996c702011-11-07 09:24:32 +00001509}
1510
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001511// Emit type dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +00001512void DwarfDebug::emitAccelTypes() {
David Blaikie6741bb02014-09-11 21:12:48 +00001513 emitAccel(AccelTypes, Asm->getObjFileLowering().getDwarfAccelTypesSection(),
1514 "types", "types_begin");
Eric Christopher4996c702011-11-07 09:24:32 +00001515}
1516
Eric Christopherdd1a0122013-09-13 00:35:05 +00001517// Public name handling.
1518// The format for the various pubnames:
1519//
1520// dwarf pubnames - offset/name pairs where the offset is the offset into the CU
1521// for the DIE that is named.
1522//
1523// gnu pubnames - offset/index value/name tuples where the offset is the offset
1524// into the CU and the index value is computed according to the type of value
1525// for the DIE that is named.
1526//
1527// For type units the offset is the offset of the skeleton DIE. For split dwarf
1528// it's the offset within the debug_info/debug_types dwo section, however, the
1529// reference in the pubname header doesn't change.
1530
1531/// computeIndexValue - Compute the gdb index value for the DIE and CU.
Eric Christophera5a79422013-12-09 23:32:48 +00001532static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU,
Eric Christopher0fe676a2013-11-21 00:48:22 +00001533 const DIE *Die) {
Eric Christopherd2b497b2013-10-16 01:37:49 +00001534 dwarf::GDBIndexEntryLinkage Linkage = dwarf::GIEL_STATIC;
1535
1536 // We could have a specification DIE that has our most of our knowledge,
1537 // look for that now.
1538 DIEValue *SpecVal = Die->findAttribute(dwarf::DW_AT_specification);
1539 if (SpecVal) {
David Blaikie8dbcc3f2014-04-25 19:33:43 +00001540 DIE &SpecDIE = cast<DIEEntry>(SpecVal)->getEntry();
1541 if (SpecDIE.findAttribute(dwarf::DW_AT_external))
Eric Christopherd2b497b2013-10-16 01:37:49 +00001542 Linkage = dwarf::GIEL_EXTERNAL;
1543 } else if (Die->findAttribute(dwarf::DW_AT_external))
1544 Linkage = dwarf::GIEL_EXTERNAL;
Eric Christopherdd1a0122013-09-13 00:35:05 +00001545
1546 switch (Die->getTag()) {
1547 case dwarf::DW_TAG_class_type:
1548 case dwarf::DW_TAG_structure_type:
1549 case dwarf::DW_TAG_union_type:
1550 case dwarf::DW_TAG_enumeration_type:
Eric Christopher261d2342013-09-23 20:55:35 +00001551 return dwarf::PubIndexEntryDescriptor(
1552 dwarf::GIEK_TYPE, CU->getLanguage() != dwarf::DW_LANG_C_plus_plus
1553 ? dwarf::GIEL_STATIC
1554 : dwarf::GIEL_EXTERNAL);
Eric Christopherdd1a0122013-09-13 00:35:05 +00001555 case dwarf::DW_TAG_typedef:
1556 case dwarf::DW_TAG_base_type:
1557 case dwarf::DW_TAG_subrange_type:
David Blaikie8dec4072013-09-19 20:40:26 +00001558 return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE, dwarf::GIEL_STATIC);
Eric Christopherdd1a0122013-09-13 00:35:05 +00001559 case dwarf::DW_TAG_namespace:
David Blaikie8dec4072013-09-19 20:40:26 +00001560 return dwarf::GIEK_TYPE;
Eric Christopherdd1a0122013-09-13 00:35:05 +00001561 case dwarf::DW_TAG_subprogram:
Eric Christopherccac5c42013-09-23 22:59:14 +00001562 return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_FUNCTION, Linkage);
Eric Christopherdd1a0122013-09-13 00:35:05 +00001563 case dwarf::DW_TAG_constant:
1564 case dwarf::DW_TAG_variable:
Eric Christopherccac5c42013-09-23 22:59:14 +00001565 return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, Linkage);
Eric Christopherdd1a0122013-09-13 00:35:05 +00001566 case dwarf::DW_TAG_enumerator:
David Blaikie8dec4072013-09-19 20:40:26 +00001567 return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE,
1568 dwarf::GIEL_STATIC);
Eric Christopherdd1a0122013-09-13 00:35:05 +00001569 default:
David Blaikie8dec4072013-09-19 20:40:26 +00001570 return dwarf::GIEK_NONE;
Eric Christopherdd1a0122013-09-13 00:35:05 +00001571 }
Eric Christopherdd1a0122013-09-13 00:35:05 +00001572}
1573
Eric Christopher5f93bb92013-09-09 20:03:17 +00001574/// emitDebugPubNames - Emit visible names into a debug pubnames section.
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001575///
Eric Christopherdd1a0122013-09-13 00:35:05 +00001576void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
Eric Christopherdd1a0122013-09-13 00:35:05 +00001577 const MCSection *PSec =
1578 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
1579 : Asm->getObjFileLowering().getDwarfPubNamesSection();
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001580
David Blaikie192b45c2014-11-02 06:16:39 +00001581 emitDebugPubSection(GnuStyle, PSec, "Names",
1582 &DwarfCompileUnit::getGlobalNames);
David Blaikie0f55e832014-03-11 23:18:15 +00001583}
1584
1585void DwarfDebug::emitDebugPubSection(
1586 bool GnuStyle, const MCSection *PSec, StringRef Name,
David Blaikie192b45c2014-11-02 06:16:39 +00001587 const StringMap<const DIE *> &(DwarfCompileUnit::*Accessor)() const) {
David Blaikiec3d9e9e2014-03-06 01:42:00 +00001588 for (const auto &NU : CUMap) {
1589 DwarfCompileUnit *TheU = NU.second;
David Blaikie55bb8ac2014-03-11 23:23:39 +00001590
1591 const auto &Globals = (TheU->*Accessor)();
1592
David Blaikiece2f1cb2014-03-11 23:35:06 +00001593 if (Globals.empty())
1594 continue;
1595
David Blaikiebbad0bb2014-11-01 01:03:39 +00001596 if (auto *Skeleton = TheU->getSkeleton())
David Blaikiec3d9e9e2014-03-06 01:42:00 +00001597 TheU = Skeleton;
David Blaikie2a80e442013-12-02 22:09:48 +00001598 unsigned ID = TheU->getUniqueID();
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001599
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001600 // Start the dwarf pubnames section.
Eric Christopher13b99d22013-09-10 21:49:37 +00001601 Asm->OutStreamer.SwitchSection(PSec);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001602
Eric Christopherdd1a0122013-09-13 00:35:05 +00001603 // Emit the header.
David Blaikie0f55e832014-03-11 23:18:15 +00001604 Asm->OutStreamer.AddComment("Length of Public " + Name + " Info");
1605 MCSymbol *BeginLabel = Asm->GetTempSymbol("pub" + Name + "_begin", ID);
1606 MCSymbol *EndLabel = Asm->GetTempSymbol("pub" + Name + "_end", ID);
David Blaikieb7a1c4d2013-12-04 17:55:41 +00001607 Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001608
David Blaikieb7a1c4d2013-12-04 17:55:41 +00001609 Asm->OutStreamer.EmitLabel(BeginLabel);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001610
1611 Asm->OutStreamer.AddComment("DWARF Version");
David Majnemered89b5c2013-08-21 06:13:34 +00001612 Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001613
1614 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
David Blaikie7d734602013-12-06 22:33:05 +00001615 Asm->EmitSectionOffset(TheU->getLabelBegin(), TheU->getSectionSym());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001616
1617 Asm->OutStreamer.AddComment("Compilation Unit Length");
David Blaikie983bfea2014-11-01 23:07:14 +00001618 Asm->EmitInt32(TheU->getLength());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001619
Eric Christopherdd1a0122013-09-13 00:35:05 +00001620 // Emit the pubnames for this compilation unit.
David Blaikie55bb8ac2014-03-11 23:23:39 +00001621 for (const auto &GI : Globals) {
Benjamin Kramer15596c72014-03-07 19:09:39 +00001622 const char *Name = GI.getKeyData();
1623 const DIE *Entity = GI.second;
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001624
1625 Asm->OutStreamer.AddComment("DIE offset");
1626 Asm->EmitInt32(Entity->getOffset());
1627
Eric Christopherdd1a0122013-09-13 00:35:05 +00001628 if (GnuStyle) {
David Blaikie2a80e442013-12-02 22:09:48 +00001629 dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheU, Entity);
David Blaikied0a869d2013-09-19 22:19:37 +00001630 Asm->OutStreamer.AddComment(
David Blaikieefd0bcb2013-09-20 00:33:15 +00001631 Twine("Kind: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " +
David Blaikie404d3042013-09-19 23:01:29 +00001632 dwarf::GDBIndexEntryLinkageString(Desc.Linkage));
David Blaikied0a869d2013-09-19 22:19:37 +00001633 Asm->EmitInt8(Desc.toBits());
Eric Christopherdd1a0122013-09-13 00:35:05 +00001634 }
1635
David Blaikie155f8812013-12-04 21:51:05 +00001636 Asm->OutStreamer.AddComment("External Name");
Benjamin Kramer15596c72014-03-07 19:09:39 +00001637 Asm->OutStreamer.EmitBytes(StringRef(Name, GI.getKeyLength() + 1));
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001638 }
1639
1640 Asm->OutStreamer.AddComment("End Mark");
1641 Asm->EmitInt32(0);
David Blaikieb7a1c4d2013-12-04 17:55:41 +00001642 Asm->OutStreamer.EmitLabel(EndLabel);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +00001643 }
1644}
1645
Eric Christopherdd1a0122013-09-13 00:35:05 +00001646void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
Eric Christopher261d2342013-09-23 20:55:35 +00001647 const MCSection *PSec =
1648 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
1649 : Asm->getObjFileLowering().getDwarfPubTypesSection();
Eric Christopher8b3737f2013-09-13 00:34:58 +00001650
David Blaikie192b45c2014-11-02 06:16:39 +00001651 emitDebugPubSection(GnuStyle, PSec, "Types",
1652 &DwarfCompileUnit::getGlobalTypes);
Devang Patel04d2f2d2009-11-24 01:14:22 +00001653}
1654
Eric Christopher3bf29fd2012-12-27 02:14:01 +00001655// Emit visible names into a debug str section.
1656void DwarfDebug::emitDebugStr() {
Eric Christopherf8194852013-12-05 18:06:10 +00001657 DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
Eric Christopher3bf29fd2012-12-27 02:14:01 +00001658 Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection());
1659}
1660
Adrian Prantlb1416832014-08-01 22:11:58 +00001661/// Emits an optimal (=sorted) sequence of DW_OP_pieces.
1662void DwarfDebug::emitLocPieces(ByteStreamer &Streamer,
1663 const DITypeIdentifierMap &Map,
1664 ArrayRef<DebugLocEntry::Value> Values) {
Adrian Prantl293dd932014-08-11 21:05:55 +00001665 assert(std::all_of(Values.begin(), Values.end(), [](DebugLocEntry::Value P) {
Adrian Prantl76502d82014-08-11 23:22:59 +00001666 return P.isVariablePiece();
Adrian Prantlb1416832014-08-01 22:11:58 +00001667 }) && "all values are expected to be pieces");
Adrian Prantl293dd932014-08-11 21:05:55 +00001668 assert(std::is_sorted(Values.begin(), Values.end()) &&
1669 "pieces are expected to be sorted");
Adrian Prantlb1416832014-08-01 22:11:58 +00001670
1671 unsigned Offset = 0;
Adrian Prantl293dd932014-08-11 21:05:55 +00001672 for (auto Piece : Values) {
Adrian Prantl0a3bfdb2015-01-13 23:11:51 +00001673 const unsigned SizeOfByte = 8;
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001674 DIExpression Expr = Piece.getExpression();
1675 unsigned PieceOffset = Expr.getPieceOffset();
1676 unsigned PieceSize = Expr.getPieceSize();
Adrian Prantl293dd932014-08-11 21:05:55 +00001677 assert(Offset <= PieceOffset && "overlapping or duplicate pieces");
Adrian Prantlb1416832014-08-01 22:11:58 +00001678 if (Offset < PieceOffset) {
1679 // The DWARF spec seriously mandates pieces with no locations for gaps.
Adrian Prantl0a3bfdb2015-01-13 23:11:51 +00001680 Asm->EmitDwarfOpPiece(Streamer, (PieceOffset-Offset)*SizeOfByte);
Adrian Prantlb1416832014-08-01 22:11:58 +00001681 Offset += PieceOffset-Offset;
1682 }
Adrian Prantlb1416832014-08-01 22:11:58 +00001683 Offset += PieceSize;
1684
Adrian Prantlb458dc22014-10-01 18:10:54 +00001685#ifndef NDEBUG
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001686 DIVariable Var = Piece.getVariable();
1687 assert(!Var.isIndirect() && "indirect address for piece");
Adrian Prantlb1416832014-08-01 22:11:58 +00001688 unsigned VarSize = Var.getSizeInBits(Map);
1689 assert(PieceSize+PieceOffset <= VarSize/SizeOfByte
1690 && "piece is larger than or outside of variable");
1691 assert(PieceSize*SizeOfByte != VarSize
1692 && "piece covers entire variable");
1693#endif
1694 if (Piece.isLocation() && Piece.getLoc().isReg())
1695 Asm->EmitDwarfRegOpPiece(Streamer,
1696 Piece.getLoc(),
1697 PieceSize*SizeOfByte);
1698 else {
1699 emitDebugLocValue(Streamer, Piece);
1700 Asm->EmitDwarfOpPiece(Streamer, PieceSize*SizeOfByte);
1701 }
1702 }
1703}
1704
1705
Eric Christopher29e874d2014-03-07 22:40:37 +00001706void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
Eric Christopher05135fb2014-03-18 02:18:24 +00001707 const DebugLocEntry &Entry) {
Adrian Prantle19e5ef2014-04-27 18:25:40 +00001708 const DebugLocEntry::Value Value = Entry.getValues()[0];
Adrian Prantl76502d82014-08-11 23:22:59 +00001709 if (Value.isVariablePiece())
Adrian Prantlb1416832014-08-01 22:11:58 +00001710 // Emit all pieces that belong to the same variable and range.
1711 return emitLocPieces(Streamer, TypeIdentifierMap, Entry.getValues());
1712
1713 assert(Entry.getValues().size() == 1 && "only pieces may have >1 value");
1714 emitDebugLocValue(Streamer, Value);
1715}
1716
1717void DwarfDebug::emitDebugLocValue(ByteStreamer &Streamer,
1718 const DebugLocEntry::Value &Value) {
Adrian Prantl76502d82014-08-11 23:22:59 +00001719 DIVariable DV = Value.getVariable();
Adrian Prantl66f25952015-01-13 00:04:06 +00001720 DebugLocDwarfExpression Expr(*Asm, Streamer);
Adrian Prantlb1416832014-08-01 22:11:58 +00001721 // Regular entry.
Adrian Prantle19e5ef2014-04-27 18:25:40 +00001722 if (Value.isInt()) {
Adrian Prantl1a1647c2014-03-18 02:34:58 +00001723 DIBasicType BTy(resolve(DV.getType()));
Eric Christopher29e874d2014-03-07 22:40:37 +00001724 if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
Adrian Prantl66f25952015-01-13 00:04:06 +00001725 BTy.getEncoding() == dwarf::DW_ATE_signed_char))
1726 Expr.AddSignedConstant(Value.getInt());
1727 else
1728 Expr.AddUnsignedConstant(Value.getInt());
Adrian Prantle19e5ef2014-04-27 18:25:40 +00001729 } else if (Value.isLocation()) {
1730 MachineLocation Loc = Value.getLoc();
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001731 DIExpression Expr = Value.getExpression();
1732 if (!Expr)
Eric Christopher29e874d2014-03-07 22:40:37 +00001733 // Regular entry.
1734 Asm->EmitDwarfRegOp(Streamer, Loc, DV.isIndirect());
1735 else {
1736 // Complex address entry.
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001737 unsigned N = Expr.getNumElements();
Eric Christopher29e874d2014-03-07 22:40:37 +00001738 unsigned i = 0;
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001739 if (N >= 2 && Expr.getElement(0) == dwarf::DW_OP_plus) {
Eric Christopher29e874d2014-03-07 22:40:37 +00001740 if (Loc.getOffset()) {
1741 i = 2;
1742 Asm->EmitDwarfRegOp(Streamer, Loc, DV.isIndirect());
1743 Streamer.EmitInt8(dwarf::DW_OP_deref, "DW_OP_deref");
1744 Streamer.EmitInt8(dwarf::DW_OP_plus_uconst, "DW_OP_plus_uconst");
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001745 Streamer.EmitSLEB128(Expr.getElement(1));
Eric Christopher29e874d2014-03-07 22:40:37 +00001746 } else {
1747 // If first address element is OpPlus then emit
1748 // DW_OP_breg + Offset instead of DW_OP_reg + Offset.
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001749 MachineLocation TLoc(Loc.getReg(), Expr.getElement(1));
Eric Christopher29e874d2014-03-07 22:40:37 +00001750 Asm->EmitDwarfRegOp(Streamer, TLoc, DV.isIndirect());
1751 i = 2;
1752 }
1753 } else {
1754 Asm->EmitDwarfRegOp(Streamer, Loc, DV.isIndirect());
1755 }
1756
1757 // Emit remaining complex address elements.
1758 for (; i < N; ++i) {
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001759 uint64_t Element = Expr.getElement(i);
1760 if (Element == dwarf::DW_OP_plus) {
Eric Christopher29e874d2014-03-07 22:40:37 +00001761 Streamer.EmitInt8(dwarf::DW_OP_plus_uconst, "DW_OP_plus_uconst");
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001762 Streamer.EmitULEB128(Expr.getElement(++i));
1763 } else if (Element == dwarf::DW_OP_deref) {
Eric Christopher29e874d2014-03-07 22:40:37 +00001764 if (!Loc.isReg())
1765 Streamer.EmitInt8(dwarf::DW_OP_deref, "DW_OP_deref");
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001766 } else if (Element == dwarf::DW_OP_piece) {
Adrian Prantlb1416832014-08-01 22:11:58 +00001767 i += 3;
1768 // handled in emitDebugLocEntry.
Eric Christopher29e874d2014-03-07 22:40:37 +00001769 } else
1770 llvm_unreachable("unknown Opcode found in complex address");
1771 }
1772 }
1773 }
1774 // else ... ignore constant fp. There is not any good way to
1775 // to represent them here in dwarf.
1776 // FIXME: ^
1777}
1778
David Blaikie0e84adc2014-04-01 16:17:41 +00001779void DwarfDebug::emitDebugLocEntryLocation(const DebugLocEntry &Entry) {
1780 Asm->OutStreamer.AddComment("Loc expr size");
1781 MCSymbol *begin = Asm->OutStreamer.getContext().CreateTempSymbol();
1782 MCSymbol *end = Asm->OutStreamer.getContext().CreateTempSymbol();
1783 Asm->EmitLabelDifference(end, begin, 2);
1784 Asm->OutStreamer.EmitLabel(begin);
1785 // Emit the entry.
1786 APByteStreamer Streamer(*Asm);
1787 emitDebugLocEntry(Streamer, Entry);
1788 // Close the range.
1789 Asm->OutStreamer.EmitLabel(end);
1790}
1791
Eric Christopher9046f942013-07-02 21:36:07 +00001792// Emit locations into the debug loc section.
Devang Patel930143b2009-11-21 02:48:08 +00001793void DwarfDebug::emitDebugLoc() {
Daniel Dunbarfd95b012011-03-16 22:16:39 +00001794 // Start the dwarf loc section.
Chris Lattner4b7dadb2009-08-19 05:49:37 +00001795 Asm->OutStreamer.SwitchSection(
David Blaikie94c1d7f2014-04-02 01:50:20 +00001796 Asm->getObjFileLowering().getDwarfLocSection());
Chandler Carruth5da3f052012-11-01 09:14:31 +00001797 unsigned char Size = Asm->getDataLayout().getPointerSize();
David Blaikie84d8e182014-03-24 22:38:38 +00001798 for (const auto &DebugLoc : DotDebugLocEntries) {
David Blaikie0a456de2014-04-02 01:43:18 +00001799 Asm->OutStreamer.EmitLabel(DebugLoc.Label);
David Blaikiee1a26a62014-08-05 23:14:16 +00001800 const DwarfCompileUnit *CU = DebugLoc.CU;
David Blaikie0a456de2014-04-02 01:43:18 +00001801 for (const auto &Entry : DebugLoc.List) {
Eric Christopher384f3fe2014-03-20 19:16:16 +00001802 // Set up the range. This range is relative to the entry point of the
1803 // compile unit. This is a hard coded 0 for low_pc when we're emitting
1804 // ranges, or the DW_AT_low_pc on the compile unit otherwise.
David Blaikiece343492014-11-03 21:15:30 +00001805 if (auto *Base = CU->getBaseAddress()) {
Eric Christopher384f3fe2014-03-20 19:16:16 +00001806 Asm->EmitLabelDifference(Entry.getBeginSym(), Base, Size);
1807 Asm->EmitLabelDifference(Entry.getEndSym(), Base, Size);
1808 } else {
1809 Asm->OutStreamer.EmitSymbolValue(Entry.getBeginSym(), Size);
1810 Asm->OutStreamer.EmitSymbolValue(Entry.getEndSym(), Size);
1811 }
David Blaikie94c1d7f2014-04-02 01:50:20 +00001812
David Blaikie0e84adc2014-04-01 16:17:41 +00001813 emitDebugLocEntryLocation(Entry);
Devang Patel9fc11702010-05-25 23:40:22 +00001814 }
David Blaikie94c1d7f2014-04-02 01:50:20 +00001815 Asm->OutStreamer.EmitIntValue(0, Size);
1816 Asm->OutStreamer.EmitIntValue(0, Size);
1817 }
1818}
1819
1820void DwarfDebug::emitDebugLocDWO() {
1821 Asm->OutStreamer.SwitchSection(
1822 Asm->getObjFileLowering().getDwarfLocDWOSection());
1823 for (const auto &DebugLoc : DotDebugLocEntries) {
1824 Asm->OutStreamer.EmitLabel(DebugLoc.Label);
1825 for (const auto &Entry : DebugLoc.List) {
1826 // Just always use start_length for now - at least that's one address
1827 // rather than two. We could get fancier and try to, say, reuse an
1828 // address we know we've emitted elsewhere (the start of the function?
1829 // The start of the CU or CU subrange that encloses this range?)
1830 Asm->EmitInt8(dwarf::DW_LLE_start_length_entry);
David Blaikied75fb282014-04-23 21:20:10 +00001831 unsigned idx = AddrPool.getIndex(Entry.getBeginSym());
David Blaikie94c1d7f2014-04-02 01:50:20 +00001832 Asm->EmitULEB128(idx);
1833 Asm->EmitLabelDifference(Entry.getEndSym(), Entry.getBeginSym(), 4);
1834
1835 emitDebugLocEntryLocation(Entry);
David Blaikie9c550ac2014-03-25 01:44:02 +00001836 }
David Blaikie94c1d7f2014-04-02 01:50:20 +00001837 Asm->EmitInt8(dwarf::DW_LLE_end_of_list_entry);
Devang Patel9fc11702010-05-25 23:40:22 +00001838 }
Bill Wendling480ff322009-05-20 23:21:38 +00001839}
1840
Richard Mitton21101b32013-09-19 23:21:01 +00001841struct ArangeSpan {
1842 const MCSymbol *Start, *End;
1843};
1844
1845// Emit a debug aranges section, containing a CU lookup for any
1846// address we can tie back to a CU.
Eric Christopher7b30f2e42012-11-21 00:34:35 +00001847void DwarfDebug::emitDebugARanges() {
Bill Wendling480ff322009-05-20 23:21:38 +00001848 // Start the dwarf aranges section.
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001849 Asm->OutStreamer.SwitchSection(
1850 Asm->getObjFileLowering().getDwarfARangesSection());
Richard Mitton21101b32013-09-19 23:21:01 +00001851
Eric Christopher793c7472014-04-28 20:42:22 +00001852 typedef DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> SpansType;
Richard Mitton21101b32013-09-19 23:21:01 +00001853
1854 SpansType Spans;
1855
1856 // Build a list of sections used.
1857 std::vector<const MCSection *> Sections;
Benjamin Kramer15596c72014-03-07 19:09:39 +00001858 for (const auto &it : SectionMap) {
1859 const MCSection *Section = it.first;
Richard Mitton21101b32013-09-19 23:21:01 +00001860 Sections.push_back(Section);
1861 }
1862
1863 // Sort the sections into order.
1864 // This is only done to ensure consistent output order across different runs.
1865 std::sort(Sections.begin(), Sections.end(), SectionSort);
1866
1867 // Build a set of address spans, sorted by CU.
Benjamin Kramer15596c72014-03-07 19:09:39 +00001868 for (const MCSection *Section : Sections) {
David Blaikieafd2c6b2014-04-22 05:41:06 +00001869 SmallVector<SymbolCU, 8> &List = SectionMap[Section];
Richard Mitton21101b32013-09-19 23:21:01 +00001870 if (List.size() < 2)
1871 continue;
1872
1873 // Sort the symbols by offset within the section.
Benjamin Kramer571e2fe2014-03-07 19:41:22 +00001874 std::sort(List.begin(), List.end(),
1875 [&](const SymbolCU &A, const SymbolCU &B) {
1876 unsigned IA = A.Sym ? Asm->OutStreamer.GetSymbolOrder(A.Sym) : 0;
1877 unsigned IB = B.Sym ? Asm->OutStreamer.GetSymbolOrder(B.Sym) : 0;
1878
1879 // Symbols with no order assigned should be placed at the end.
1880 // (e.g. section end labels)
1881 if (IA == 0)
1882 return false;
1883 if (IB == 0)
1884 return true;
1885 return IA < IB;
1886 });
Richard Mitton21101b32013-09-19 23:21:01 +00001887
1888 // If we have no section (e.g. common), just write out
1889 // individual spans for each symbol.
Craig Topper353eda42014-04-24 06:44:33 +00001890 if (!Section) {
Benjamin Kramer15596c72014-03-07 19:09:39 +00001891 for (const SymbolCU &Cur : List) {
Richard Mitton21101b32013-09-19 23:21:01 +00001892 ArangeSpan Span;
1893 Span.Start = Cur.Sym;
Craig Topper353eda42014-04-24 06:44:33 +00001894 Span.End = nullptr;
Richard Mitton21101b32013-09-19 23:21:01 +00001895 if (Cur.CU)
1896 Spans[Cur.CU].push_back(Span);
1897 }
1898 } else {
1899 // Build spans between each label.
1900 const MCSymbol *StartSym = List[0].Sym;
Benjamin Kramer15596c72014-03-07 19:09:39 +00001901 for (size_t n = 1, e = List.size(); n < e; n++) {
Richard Mitton21101b32013-09-19 23:21:01 +00001902 const SymbolCU &Prev = List[n - 1];
1903 const SymbolCU &Cur = List[n];
1904
1905 // Try and build the longest span we can within the same CU.
1906 if (Cur.CU != Prev.CU) {
1907 ArangeSpan Span;
1908 Span.Start = StartSym;
1909 Span.End = Cur.Sym;
1910 Spans[Prev.CU].push_back(Span);
1911 StartSym = Cur.Sym;
1912 }
1913 }
1914 }
1915 }
1916
Richard Mitton21101b32013-09-19 23:21:01 +00001917 unsigned PtrSize = Asm->getDataLayout().getPointerSize();
1918
1919 // Build a list of CUs used.
Eric Christopher4287a492013-12-09 23:57:44 +00001920 std::vector<DwarfCompileUnit *> CUs;
Benjamin Kramer15596c72014-03-07 19:09:39 +00001921 for (const auto &it : Spans) {
1922 DwarfCompileUnit *CU = it.first;
Richard Mitton21101b32013-09-19 23:21:01 +00001923 CUs.push_back(CU);
1924 }
1925
1926 // Sort the CU list (again, to ensure consistent output order).
Benjamin Kramer571e2fe2014-03-07 19:41:22 +00001927 std::sort(CUs.begin(), CUs.end(), [](const DwarfUnit *A, const DwarfUnit *B) {
1928 return A->getUniqueID() < B->getUniqueID();
1929 });
Richard Mitton21101b32013-09-19 23:21:01 +00001930
1931 // Emit an arange table for each CU we used.
Benjamin Kramer15596c72014-03-07 19:09:39 +00001932 for (DwarfCompileUnit *CU : CUs) {
Richard Mitton21101b32013-09-19 23:21:01 +00001933 std::vector<ArangeSpan> &List = Spans[CU];
1934
David Blaikie27e35f22014-11-02 01:21:43 +00001935 // Describe the skeleton CU's offset and length, not the dwo file's.
1936 if (auto *Skel = CU->getSkeleton())
1937 CU = Skel;
1938
Richard Mitton21101b32013-09-19 23:21:01 +00001939 // Emit size of content not including length itself.
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001940 unsigned ContentSize =
1941 sizeof(int16_t) + // DWARF ARange version number
1942 sizeof(int32_t) + // Offset of CU in the .debug_info section
1943 sizeof(int8_t) + // Pointer Size (in bytes)
1944 sizeof(int8_t); // Segment Size (in bytes)
Richard Mitton21101b32013-09-19 23:21:01 +00001945
1946 unsigned TupleSize = PtrSize * 2;
1947
1948 // 7.20 in the Dwarf specs requires the table to be aligned to a tuple.
Benjamin Kramer8a68ab32014-01-07 19:28:14 +00001949 unsigned Padding =
1950 OffsetToAlignment(sizeof(int32_t) + ContentSize, TupleSize);
Richard Mitton21101b32013-09-19 23:21:01 +00001951
1952 ContentSize += Padding;
1953 ContentSize += (List.size() + 1) * TupleSize;
1954
1955 // For each compile unit, write the list of spans it covers.
1956 Asm->OutStreamer.AddComment("Length of ARange Set");
1957 Asm->EmitInt32(ContentSize);
1958 Asm->OutStreamer.AddComment("DWARF Arange version number");
1959 Asm->EmitInt16(dwarf::DW_ARANGES_VERSION);
1960 Asm->OutStreamer.AddComment("Offset Into Debug Info Section");
David Blaikie27e35f22014-11-02 01:21:43 +00001961 Asm->EmitSectionOffset(CU->getLabelBegin(), CU->getSectionSym());
Richard Mitton21101b32013-09-19 23:21:01 +00001962 Asm->OutStreamer.AddComment("Address Size (in bytes)");
1963 Asm->EmitInt8(PtrSize);
1964 Asm->OutStreamer.AddComment("Segment Size (in bytes)");
1965 Asm->EmitInt8(0);
1966
Benjamin Kramer8a68ab32014-01-07 19:28:14 +00001967 Asm->OutStreamer.EmitFill(Padding, 0xff);
Richard Mitton21101b32013-09-19 23:21:01 +00001968
Benjamin Kramer15596c72014-03-07 19:09:39 +00001969 for (const ArangeSpan &Span : List) {
Richard Mitton21101b32013-09-19 23:21:01 +00001970 Asm->EmitLabelReference(Span.Start, PtrSize);
1971
1972 // Calculate the size as being from the span start to it's end.
Richard Mitton089ed892013-09-23 17:56:20 +00001973 if (Span.End) {
Richard Mitton21101b32013-09-19 23:21:01 +00001974 Asm->EmitLabelDifference(Span.End, Span.Start, PtrSize);
Richard Mitton089ed892013-09-23 17:56:20 +00001975 } else {
1976 // For symbols without an end marker (e.g. common), we
1977 // write a single arange entry containing just that one symbol.
1978 uint64_t Size = SymSize[Span.Start];
1979 if (Size == 0)
1980 Size = 1;
1981
1982 Asm->OutStreamer.EmitIntValue(Size, PtrSize);
1983 }
Richard Mitton21101b32013-09-19 23:21:01 +00001984 }
1985
1986 Asm->OutStreamer.AddComment("ARange terminator");
1987 Asm->OutStreamer.EmitIntValue(0, PtrSize);
1988 Asm->OutStreamer.EmitIntValue(0, PtrSize);
1989 }
Bill Wendling480ff322009-05-20 23:21:38 +00001990}
1991
Eric Christopheracdcbdb2012-11-27 22:43:45 +00001992// Emit visible names into a debug ranges section.
Devang Patel930143b2009-11-21 02:48:08 +00001993void DwarfDebug::emitDebugRanges() {
Bill Wendling480ff322009-05-20 23:21:38 +00001994 // Start the dwarf ranges section.
Eric Christopherb4bef6d2013-11-19 09:04:36 +00001995 Asm->OutStreamer.SwitchSection(
1996 Asm->getObjFileLowering().getDwarfRangesSection());
Eric Christopher4751d702013-11-23 00:05:29 +00001997
Eric Christopher0f63d062013-12-03 00:45:45 +00001998 // Size for our labels.
1999 unsigned char Size = Asm->getDataLayout().getPointerSize();
2000
2001 // Grab the specific ranges for the compile units in the module.
Benjamin Kramer15596c72014-03-07 19:09:39 +00002002 for (const auto &I : CUMap) {
2003 DwarfCompileUnit *TheCU = I.second;
Eric Christopher0f63d062013-12-03 00:45:45 +00002004
David Blaikie3a443c22014-11-04 22:12:25 +00002005 if (auto *Skel = TheCU->getSkeleton())
2006 TheCU = Skel;
2007
Eric Christopher0f63d062013-12-03 00:45:45 +00002008 // Iterate over the misc ranges for the compile units in the module.
Benjamin Kramer15596c72014-03-07 19:09:39 +00002009 for (const RangeSpanList &List : TheCU->getRangeLists()) {
Eric Christopherf8790642013-12-04 22:04:50 +00002010 // Emit our symbol so we can find the beginning of the range.
2011 Asm->OutStreamer.EmitLabel(List.getSym());
Eric Christopher0f63d062013-12-03 00:45:45 +00002012
Benjamin Kramer15596c72014-03-07 19:09:39 +00002013 for (const RangeSpan &Range : List.getRanges()) {
Eric Christopher0f63d062013-12-03 00:45:45 +00002014 const MCSymbol *Begin = Range.getStart();
2015 const MCSymbol *End = Range.getEnd();
Eric Christopher565ab112013-12-20 04:34:22 +00002016 assert(Begin && "Range without a begin symbol?");
2017 assert(End && "Range without an end symbol?");
David Blaikiece343492014-11-03 21:15:30 +00002018 if (auto *Base = TheCU->getBaseAddress()) {
Eric Christopherece0e902014-04-25 22:23:54 +00002019 Asm->EmitLabelDifference(Begin, Base, Size);
2020 Asm->EmitLabelDifference(End, Base, Size);
2021 } else {
2022 Asm->OutStreamer.EmitSymbolValue(Begin, Size);
2023 Asm->OutStreamer.EmitSymbolValue(End, Size);
2024 }
Eric Christopher0f63d062013-12-03 00:45:45 +00002025 }
2026
2027 // And terminate the list with two 0 values.
Eric Christopherce0cfce2013-01-09 01:35:34 +00002028 Asm->OutStreamer.EmitIntValue(0, Size);
Eric Christopher0f63d062013-12-03 00:45:45 +00002029 Asm->OutStreamer.EmitIntValue(0, Size);
2030 }
Devang Patel12563b32010-04-16 23:33:45 +00002031 }
Bill Wendling480ff322009-05-20 23:21:38 +00002032}
2033
Eric Christopherd692c1d2012-12-11 19:42:09 +00002034// DWARF5 Experimental Separate Dwarf emitters.
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002035
David Blaikie65a74662014-04-25 18:26:14 +00002036void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
David Blaikief9b6a552014-04-22 22:39:41 +00002037 std::unique_ptr<DwarfUnit> NewU) {
David Blaikiecafd9622014-11-02 08:51:37 +00002038 NewU->addString(Die, dwarf::DW_AT_GNU_dwo_name,
David Blaikie4aa49b22014-11-02 08:52:37 +00002039 U.getCUNode().getSplitDebugFilename());
David Blaikie38fe6342014-01-09 04:28:46 +00002040
David Blaikie38fe6342014-01-09 04:28:46 +00002041 if (!CompilationDir.empty())
David Blaikiecafd9622014-11-02 08:51:37 +00002042 NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
David Blaikie38fe6342014-01-09 04:28:46 +00002043
David Blaikief9b6a552014-04-22 22:39:41 +00002044 addGnuPubAttributes(*NewU, Die);
David Blaikie38fe6342014-01-09 04:28:46 +00002045
David Blaikief9b6a552014-04-22 22:39:41 +00002046 SkeletonHolder.addUnit(std::move(NewU));
David Blaikie38fe6342014-01-09 04:28:46 +00002047}
2048
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002049// This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
2050// DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
David Blaikie96dea052014-03-24 21:31:35 +00002051// DW_AT_addr_base, DW_AT_ranges_base.
David Blaikief9b6a552014-04-22 22:39:41 +00002052DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) {
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002053
David Blaikief9b6a552014-04-22 22:39:41 +00002054 auto OwnedUnit = make_unique<DwarfCompileUnit>(
David Blaikiebd579052014-04-28 21:14:27 +00002055 CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder);
David Blaikief9b6a552014-04-22 22:39:41 +00002056 DwarfCompileUnit &NewCU = *OwnedUnit;
2057 NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
David Blaikie637cac42014-04-22 23:09:36 +00002058 DwarfInfoSectionSym);
Eric Christopher4c7765f2013-01-17 03:00:04 +00002059
David Blaikief9b6a552014-04-22 22:39:41 +00002060 NewCU.initStmtList(DwarfLineSectionSym);
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002061
David Blaikie92a2f8a2014-04-28 21:04:29 +00002062 initSkeletonUnit(CU, NewCU.getUnitDie(), std::move(OwnedUnit));
Eric Christopherc8a310e2012-12-10 23:34:43 +00002063
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002064 return NewCU;
2065}
2066
Eric Christopherd692c1d2012-12-11 19:42:09 +00002067// Emit the .debug_info.dwo section for separated dwarf. This contains the
2068// compile units that would normally be in debug_info.
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002069void DwarfDebug::emitDebugInfoDWO() {
Eric Christophercdf218d2012-12-10 19:51:21 +00002070 assert(useSplitDwarf() && "No split dwarf debug info?");
David Blaikie326e1fa2014-04-02 02:04:51 +00002071 // Don't pass an abbrev symbol, using a constant zero instead so as not to
2072 // emit relocations into the dwo file.
David Blaikie2b22b1e2014-10-23 00:16:03 +00002073 InfoHolder.emitUnits(/* AbbrevSymbol */ nullptr);
Eric Christopher3c5a1912012-12-19 22:02:53 +00002074}
2075
2076// Emit the .debug_abbrev.dwo section for separated dwarf. This contains the
2077// abbreviations for the .debug_info.dwo section.
2078void DwarfDebug::emitDebugAbbrevDWO() {
2079 assert(useSplitDwarf() && "No split dwarf?");
David Blaikie0504cda2013-12-05 07:43:55 +00002080 InfoHolder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection());
Eric Christopher9c2ecd92012-11-30 23:59:06 +00002081}
Eric Christopher3bf29fd2012-12-27 02:14:01 +00002082
David Blaikie4a2f95f2014-03-18 01:17:26 +00002083void DwarfDebug::emitDebugLineDWO() {
2084 assert(useSplitDwarf() && "No split dwarf?");
2085 Asm->OutStreamer.SwitchSection(
2086 Asm->getObjFileLowering().getDwarfLineDWOSection());
David Blaikie8287aff2014-03-18 02:13:23 +00002087 SplitTypeUnitFileTable.Emit(Asm->OutStreamer);
David Blaikie4a2f95f2014-03-18 01:17:26 +00002088}
2089
Eric Christopher3bf29fd2012-12-27 02:14:01 +00002090// Emit the .debug_str.dwo section for separated dwarf. This contains the
2091// string section and is identical in format to traditional .debug_str
2092// sections.
2093void DwarfDebug::emitDebugStrDWO() {
2094 assert(useSplitDwarf() && "No split dwarf?");
Eric Christopherb4bef6d2013-11-19 09:04:36 +00002095 const MCSection *OffSec =
2096 Asm->getObjFileLowering().getDwarfStrOffDWOSection();
Eric Christopher2cbd5762013-01-07 19:32:41 +00002097 InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
David Blaikie6741bb02014-09-11 21:12:48 +00002098 OffSec);
Eric Christopher3bf29fd2012-12-27 02:14:01 +00002099}
David Blaikie409dd9c2013-11-19 23:08:21 +00002100
David Blaikie47f4b822014-03-19 00:11:28 +00002101MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
2102 if (!useSplitDwarf())
2103 return nullptr;
2104 if (SingleCU)
2105 SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode().getDirectory());
2106 return &SplitTypeUnitFileTable;
2107}
2108
David Blaikief3de2ab2014-04-26 16:26:41 +00002109static uint64_t makeTypeSignature(StringRef Identifier) {
2110 MD5 Hash;
2111 Hash.update(Identifier);
2112 // ... take the least significant 8 bytes and return those. Our MD5
2113 // implementation always returns its results in little endian, swap bytes
2114 // appropriately.
2115 MD5::MD5Result Result;
2116 Hash.final(Result);
2117 return *reinterpret_cast<support::ulittle64_t *>(Result + 8);
2118}
2119
David Blaikie15632ae2014-02-12 00:31:30 +00002120void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
David Blaikie65a74662014-04-25 18:26:14 +00002121 StringRef Identifier, DIE &RefDie,
David Blaikief645f962014-01-09 03:23:41 +00002122 DICompositeType CTy) {
David Blaikiee12b49a2014-04-26 17:27:38 +00002123 // Fast path if we're building some type units and one has already used the
2124 // address pool we know we're going to throw away all this work anyway, so
2125 // don't bother building dependent types.
2126 if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
2127 return;
2128
David Blaikie47f615e2013-12-17 23:32:35 +00002129 const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy];
Chandler Carruthb587ab62014-01-20 08:07:07 +00002130 if (TU) {
David Blaikie15632ae2014-02-12 00:31:30 +00002131 CU.addDIETypeSignature(RefDie, *TU);
Chandler Carruthb587ab62014-01-20 08:07:07 +00002132 return;
David Blaikie409dd9c2013-11-19 23:08:21 +00002133 }
2134
David Blaikiee12b49a2014-04-26 17:27:38 +00002135 bool TopLevelType = TypeUnitsUnderConstruction.empty();
2136 AddrPool.resetUsedFlag();
2137
David Blaikie29459ae2014-07-25 17:11:58 +00002138 auto OwnedUnit = make_unique<DwarfTypeUnit>(
2139 InfoHolder.getUnits().size() + TypeUnitsUnderConstruction.size(), CU, Asm,
2140 this, &InfoHolder, getDwoLineTable(CU));
David Blaikief9b6a552014-04-22 22:39:41 +00002141 DwarfTypeUnit &NewTU = *OwnedUnit;
David Blaikie92a2f8a2014-04-28 21:04:29 +00002142 DIE &UnitDie = NewTU.getUnitDie();
David Blaikief9b6a552014-04-22 22:39:41 +00002143 TU = &NewTU;
Eric Christopher793c7472014-04-28 20:42:22 +00002144 TypeUnitsUnderConstruction.push_back(
2145 std::make_pair(std::move(OwnedUnit), CTy));
Chandler Carruthb587ab62014-01-20 08:07:07 +00002146
David Blaikie92a2f8a2014-04-28 21:04:29 +00002147 NewTU.addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
David Blaikie637cac42014-04-22 23:09:36 +00002148 CU.getLanguage());
Chandler Carruthb587ab62014-01-20 08:07:07 +00002149
David Blaikief3de2ab2014-04-26 16:26:41 +00002150 uint64_t Signature = makeTypeSignature(Identifier);
David Blaikief9b6a552014-04-22 22:39:41 +00002151 NewTU.setTypeSignature(Signature);
David Blaikief3de2ab2014-04-26 16:26:41 +00002152
David Blaikie29459ae2014-07-25 17:11:58 +00002153 if (useSplitDwarf())
David Blaikiea34568b2014-11-01 20:06:28 +00002154 NewTU.initSection(Asm->getObjFileLowering().getDwarfTypesDWOSection());
David Blaikie29459ae2014-07-25 17:11:58 +00002155 else {
David Blaikie92a2f8a2014-04-28 21:04:29 +00002156 CU.applyStmtList(UnitDie);
David Blaikie29459ae2014-07-25 17:11:58 +00002157 NewTU.initSection(
2158 Asm->getObjFileLowering().getDwarfTypesSection(Signature));
2159 }
Chandler Carruthb587ab62014-01-20 08:07:07 +00002160
David Blaikief3de2ab2014-04-26 16:26:41 +00002161 NewTU.setType(NewTU.createTypeDIE(CTy));
2162
David Blaikiee12b49a2014-04-26 17:27:38 +00002163 if (TopLevelType) {
2164 auto TypeUnitsToAdd = std::move(TypeUnitsUnderConstruction);
2165 TypeUnitsUnderConstruction.clear();
2166
2167 // Types referencing entries in the address table cannot be placed in type
2168 // units.
2169 if (AddrPool.hasBeenUsed()) {
2170
2171 // Remove all the types built while building this type.
2172 // This is pessimistic as some of these types might not be dependent on
2173 // the type that used an address.
2174 for (const auto &TU : TypeUnitsToAdd)
2175 DwarfTypeUnits.erase(TU.second);
2176
2177 // Construct this type in the CU directly.
2178 // This is inefficient because all the dependent types will be rebuilt
2179 // from scratch, including building them in type units, discovering that
2180 // they depend on addresses, throwing them out and rebuilding them.
2181 CU.constructTypeDIE(RefDie, CTy);
2182 return;
2183 }
2184
2185 // If the type wasn't dependent on fission addresses, finish adding the type
2186 // and all its dependent types.
David Blaikiec13bc972014-08-27 05:04:14 +00002187 for (auto &TU : TypeUnitsToAdd)
David Blaikiee12b49a2014-04-26 17:27:38 +00002188 InfoHolder.addUnit(std::move(TU.first));
David Blaikiee12b49a2014-04-26 17:27:38 +00002189 }
David Blaikief9b6a552014-04-22 22:39:41 +00002190 CU.addDIETypeSignature(RefDie, NewTU);
David Blaikie409dd9c2013-11-19 23:08:21 +00002191}
David Blaikie4bd13b72014-03-07 18:49:45 +00002192
David Blaikie2406a0622014-04-23 23:37:35 +00002193// Accelerator table mutators - add each name along with its companion
2194// DIE to the proper table while ensuring that the name that we're going
2195// to reference is in the string table. We do this since the names we
2196// add may not only be identical to the names in the DIE.
David Blaikieb0b3fcf2014-04-25 18:52:29 +00002197void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
David Blaikie2406a0622014-04-23 23:37:35 +00002198 if (!useDwarfAccelTables())
2199 return;
David Blaikie772ab8a2014-04-25 22:21:35 +00002200 AccelNames.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
2201 &Die);
David Blaikie2406a0622014-04-23 23:37:35 +00002202}
David Blaikie0ee82b92014-04-24 00:53:32 +00002203
David Blaikieb0b3fcf2014-04-25 18:52:29 +00002204void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
David Blaikie0ee82b92014-04-24 00:53:32 +00002205 if (!useDwarfAccelTables())
2206 return;
David Blaikie772ab8a2014-04-25 22:21:35 +00002207 AccelObjC.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
2208 &Die);
David Blaikie0ee82b92014-04-24 00:53:32 +00002209}
David Blaikieecf04152014-04-24 01:02:42 +00002210
David Blaikieb0b3fcf2014-04-25 18:52:29 +00002211void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
David Blaikieecf04152014-04-24 01:02:42 +00002212 if (!useDwarfAccelTables())
2213 return;
David Blaikie772ab8a2014-04-25 22:21:35 +00002214 AccelNamespace.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
2215 &Die);
David Blaikieecf04152014-04-24 01:02:42 +00002216}
David Blaikie18d33752014-04-24 01:23:49 +00002217
David Blaikieb0b3fcf2014-04-25 18:52:29 +00002218void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
David Blaikie18d33752014-04-24 01:23:49 +00002219 if (!useDwarfAccelTables())
2220 return;
David Blaikie772ab8a2014-04-25 22:21:35 +00002221 AccelTypes.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
2222 &Die);
David Blaikie18d33752014-04-24 01:23:49 +00002223}