blob: 57bb8d0229d3da2bb4a444b32b5e71a1941d80ad [file] [log] [blame]
Bill Wendling2f921f82009-05-15 09:23:25 +00001//===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
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//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
15#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
Bill Wendling2f921f82009-05-15 09:23:25 +000016
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +000017#include "AsmPrinterHandler.h"
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000018#include "DbgValueHistoryCalculator.h"
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +000019#include "DebugLocStream.h"
David Blaikie2406a0622014-04-23 23:37:35 +000020#include "DwarfAccelTable.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000021#include "DwarfFile.h"
Devang Patel018b29b2010-01-19 06:19:05 +000022#include "llvm/ADT/DenseMap.h"
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000023#include "llvm/ADT/DenseSet.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000024#include "llvm/ADT/FoldingSet.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000025#include "llvm/ADT/MapVector.h"
26#include "llvm/ADT/SmallPtrSet.h"
27#include "llvm/ADT/StringMap.h"
Frederic Risse541e0b2015-01-05 21:29:41 +000028#include "llvm/CodeGen/DIE.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000029#include "llvm/CodeGen/LexicalScopes.h"
Adrian Prantlc1197542014-05-30 21:10:13 +000030#include "llvm/CodeGen/MachineInstr.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000031#include "llvm/IR/DebugInfo.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000032#include "llvm/IR/DebugLoc.h"
David Blaikie4a2f95f2014-03-18 01:17:26 +000033#include "llvm/MC/MCDwarf.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000034#include "llvm/MC/MachineLocation.h"
Chris Lattner3f3fb972010-04-05 05:24:55 +000035#include "llvm/Support/Allocator.h"
David Blaikief9b6a552014-04-22 22:39:41 +000036#include <memory>
37
Bill Wendling2f921f82009-05-15 09:23:25 +000038namespace llvm {
39
Adrian Prantl702bf5a2014-03-18 02:34:52 +000040class AsmPrinter;
Eric Christopher29e874d2014-03-07 22:40:37 +000041class ByteStreamer;
Chris Lattner88fce102012-01-26 20:44:57 +000042class ConstantInt;
43class ConstantFP;
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +000044class DebugLocEntry;
Eric Christopherce4a9442014-03-18 20:37:10 +000045class DwarfCompileUnit;
46class DwarfDebug;
47class DwarfTypeUnit;
48class DwarfUnit;
Bill Wendling2f921f82009-05-15 09:23:25 +000049class MachineModuleInfo;
Bill Wendling2f921f82009-05-15 09:23:25 +000050
51//===----------------------------------------------------------------------===//
Adrian Prantl857237e2015-07-13 18:25:29 +000052/// This class is used to record source line correspondence.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000053class SrcLineInfo {
Eric Christophera5a79422013-12-09 23:32:48 +000054 unsigned Line; // Source line number.
55 unsigned Column; // Source column.
56 unsigned SourceID; // Source ID number.
57 MCSymbol *Label; // Label in code ID number.
Bill Wendling2f921f82009-05-15 09:23:25 +000058public:
Chris Lattnerb4666f42010-03-14 08:15:55 +000059 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
Eric Christophera5a79422013-12-09 23:32:48 +000060 : Line(L), Column(C), SourceID(S), Label(label) {}
Bill Wendling2f921f82009-05-15 09:23:25 +000061
62 // Accessors
63 unsigned getLine() const { return Line; }
64 unsigned getColumn() const { return Column; }
65 unsigned getSourceID() const { return SourceID; }
Chris Lattnerb4666f42010-03-14 08:15:55 +000066 MCSymbol *getLabel() const { return Label; }
Bill Wendling2f921f82009-05-15 09:23:25 +000067};
68
Devang Patelf20c4f72011-04-12 22:53:02 +000069//===----------------------------------------------------------------------===//
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000070/// This class is used to track local variable information.
Adrian Prantlca7e4702015-02-10 23:18:28 +000071///
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000072/// Variables can be created from allocas, in which case they're generated from
73/// the MMI table. Such variables can have multiple expressions and frame
74/// indices. The \a Expr and \a FrameIndices array must match.
Adrian Prantlca7e4702015-02-10 23:18:28 +000075///
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000076/// Variables can be created from \c DBG_VALUE instructions. Those whose
77/// location changes over time use \a DebugLocListIndex, while those with a
78/// single instruction use \a MInsn and (optionally) a single entry of \a Expr.
79///
80/// Variables that have been optimized out use none of these fields.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000081class DbgVariable {
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000082 const DILocalVariable *Var; /// Variable Descriptor.
83 const DILocation *IA; /// Inlined at location.
84 SmallVector<const DIExpression *, 1> Expr; /// Complex address.
85 DIE *TheDIE = nullptr; /// Variable DIE.
86 unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs.
87 const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction.
88 SmallVector<int, 1> FrameIndex; /// Frame index.
Manman Renb3388602013-10-05 01:43:03 +000089 DwarfDebug *DD;
Eric Christophera5a79422013-12-09 23:32:48 +000090
Devang Patelf20c4f72011-04-12 22:53:02 +000091public:
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000092 /// Construct a DbgVariable.
93 ///
94 /// Creates a variable without any DW_AT_location. Call \a initializeMMI()
95 /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
96 DbgVariable(const DILocalVariable *V, const DILocation *IA, DwarfDebug *DD)
97 : Var(V), IA(IA), DD(DD) {}
98
99 /// Initialize from the MMI table.
100 void initializeMMI(const DIExpression *E, int FI) {
101 assert(Expr.empty() && "Already initialized?");
102 assert(FrameIndex.empty() && "Already initialized?");
103 assert(!MInsn && "Already initialized?");
104
105 assert((!E || E->isValid()) && "Expected valid expression");
106 assert(~FI && "Expected valid index");
107
108 Expr.push_back(E);
Adrian Prantlca7e4702015-02-10 23:18:28 +0000109 FrameIndex.push_back(FI);
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000110 }
Devang Patelf20c4f72011-04-12 22:53:02 +0000111
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000112 /// Initialize from a DBG_VALUE instruction.
113 void initializeDbgValue(const MachineInstr *DbgValue) {
114 assert(Expr.empty() && "Already initialized?");
115 assert(FrameIndex.empty() && "Already initialized?");
116 assert(!MInsn && "Already initialized?");
117
118 assert(Var == DbgValue->getDebugVariable() && "Wrong variable");
119 assert(IA == DbgValue->getDebugLoc()->getInlinedAt() && "Wrong inlined-at");
120
121 MInsn = DbgValue;
122 if (auto *E = DbgValue->getDebugExpression())
123 if (E->getNumElements())
124 Expr.push_back(E);
Adrian Prantlca7e4702015-02-10 23:18:28 +0000125 }
Adrian Prantlc1197542014-05-30 21:10:13 +0000126
Devang Patelf20c4f72011-04-12 22:53:02 +0000127 // Accessors.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000128 const DILocalVariable *getVariable() const { return Var; }
129 const DILocation *getInlinedAt() const { return IA; }
130 const ArrayRef<const DIExpression *> getExpression() const { return Expr; }
David Blaikiee071fc82014-04-25 17:32:19 +0000131 void setDIE(DIE &D) { TheDIE = &D; }
Eric Christophera5a79422013-12-09 23:32:48 +0000132 DIE *getDIE() const { return TheDIE; }
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000133 void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
134 unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000135 StringRef getName() const { return Var->getName(); }
Eric Christophera5a79422013-12-09 23:32:48 +0000136 const MachineInstr *getMInsn() const { return MInsn; }
Adrian Prantlca7e4702015-02-10 23:18:28 +0000137 const ArrayRef<int> getFrameIndex() const { return FrameIndex; }
138
139 void addMMIEntry(const DbgVariable &V) {
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000140 assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");
141 assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");
Duncan P. N. Exon Smith60635e32015-04-21 18:44:06 +0000142 assert(V.Var == Var && "conflicting variable");
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000143 assert(V.IA == IA && "conflicting inlined-at location");
Adrian Prantlca7e4702015-02-10 23:18:28 +0000144
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000145 assert(!FrameIndex.empty() && "Expected an MMI entry");
146 assert(!V.FrameIndex.empty() && "Expected an MMI entry");
147 assert(Expr.size() == FrameIndex.size() && "Mismatched expressions");
148 assert(V.Expr.size() == V.FrameIndex.size() && "Mismatched expressions");
149
150 Expr.append(V.Expr.begin(), V.Expr.end());
151 FrameIndex.append(V.FrameIndex.begin(), V.FrameIndex.end());
152 assert(std::all_of(Expr.begin(), Expr.end(), [](const DIExpression *E) {
153 return E && E->isBitPiece();
154 }) && "conflicting locations for variable");
Adrian Prantlca7e4702015-02-10 23:18:28 +0000155 }
156
Eric Christopher27527b22012-11-21 00:03:28 +0000157 // Translate tag to proper Dwarf tag.
David Blaikieefc403b2014-04-12 02:24:04 +0000158 dwarf::Tag getTag() const {
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000159 if (Var->getTag() == dwarf::DW_TAG_arg_variable)
Devang Patel6e4d2c92011-08-15 18:35:42 +0000160 return dwarf::DW_TAG_formal_parameter;
Eric Christopher27527b22012-11-21 00:03:28 +0000161
Devang Patel6e4d2c92011-08-15 18:35:42 +0000162 return dwarf::DW_TAG_variable;
163 }
Adrian Prantl857237e2015-07-13 18:25:29 +0000164 /// Return true if DbgVariable is artificial.
Eric Christophera5a79422013-12-09 23:32:48 +0000165 bool isArtificial() const {
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000166 if (Var->isArtificial())
Devang Pateld7d80aa2011-08-15 18:40:16 +0000167 return true;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000168 if (getType()->isArtificial())
Devang Pateld7d80aa2011-08-15 18:40:16 +0000169 return true;
170 return false;
171 }
Eric Christophere3417762012-09-12 23:36:19 +0000172
Eric Christophera5a79422013-12-09 23:32:48 +0000173 bool isObjectPointer() const {
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000174 if (Var->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000175 return true;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000176 if (getType()->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000177 return true;
178 return false;
179 }
Eric Christopher27527b22012-11-21 00:03:28 +0000180
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000181 bool hasComplexAddress() const {
182 assert(MInsn && "Expected DBG_VALUE, not MMI variable");
183 assert(FrameIndex.empty() && "Expected DBG_VALUE, not MMI variable");
184 assert(
185 (Expr.empty() || (Expr.size() == 1 && Expr.back()->getNumElements())) &&
186 "Invalid Expr for DBG_VALUE");
187 return !Expr.empty();
Devang Patelf20c4f72011-04-12 22:53:02 +0000188 }
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000189 bool isBlockByrefVariable() const;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000190 const DIType *getType() const;
Manman Renbe5576f2013-10-08 19:07:44 +0000191
192private:
Adrian Prantl857237e2015-07-13 18:25:29 +0000193 /// Look in the DwarfDebug map for the MDNode that
Manman Renbe5576f2013-10-08 19:07:44 +0000194 /// corresponds to the reference.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000195 template <typename T> T *resolve(TypedDINodeRef<T> Ref) const;
Devang Patelf20c4f72011-04-12 22:53:02 +0000196};
197
Eric Christopherc8a310e2012-12-10 23:34:43 +0000198
Adrian Prantl857237e2015-07-13 18:25:29 +0000199/// Helper used to pair up a symbol and its DWARF compile unit.
Richard Mitton21101b32013-09-19 23:21:01 +0000200struct SymbolCU {
Eric Christopher4287a492013-12-09 23:57:44 +0000201 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
Richard Mitton21101b32013-09-19 23:21:01 +0000202 const MCSymbol *Sym;
Eric Christopher4287a492013-12-09 23:57:44 +0000203 DwarfCompileUnit *CU;
Richard Mitton21101b32013-09-19 23:21:01 +0000204};
205
Paul Robinsonb9de1062015-07-15 22:04:54 +0000206/// Identify a debugger for "tuning" the debug info.
207///
208/// The "debugger tuning" concept allows us to present a more intuitive
209/// interface that unpacks into different sets of defaults for the various
210/// individual feature-flag settings, that suit the preferences of the
211/// various debuggers. However, it's worth remembering that debuggers are
212/// not the only consumers of debug info, and some variations in DWARF might
213/// better be treated as target/platform issues. Fundamentally,
214/// o if the feature is useful (or not) to a particular debugger, regardless
215/// of the target, that's a tuning decision;
216/// o if the feature is useful (or not) on a particular platform, regardless
217/// of the debugger, that's a target decision.
218/// It's not impossible to see both factors in some specific case.
219///
220/// The "tuning" should be used to set defaults for individual feature flags
221/// in DwarfDebug; if a given feature has a more specific command-line option,
222/// that option should take precedence over the tuning.
223enum class DebuggerKind {
224 Default, // No specific tuning requested.
225 GDB, // Tune debug info for gdb.
226 LLDB, // Tune debug info for lldb.
227 SCE // Tune debug info for SCE targets (e.g. PS4).
228};
229
Adrian Prantl857237e2015-07-13 18:25:29 +0000230/// Collects and handles dwarf debug information.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000231class DwarfDebug : public AsmPrinterHandler {
Adrian Prantl857237e2015-07-13 18:25:29 +0000232 /// Target of Dwarf emission.
Chris Lattner3a383cb2010-04-05 00:13:49 +0000233 AsmPrinter *Asm;
Chris Lattneracda87b2010-04-05 05:31:04 +0000234
Adrian Prantl857237e2015-07-13 18:25:29 +0000235 /// Collected machine module information.
Chris Lattner3a383cb2010-04-05 00:13:49 +0000236 MachineModuleInfo *MMI;
237
Adrian Prantl857237e2015-07-13 18:25:29 +0000238 /// All DIEValues are allocated through this allocator.
Benjamin Kramer07480082012-06-09 10:34:15 +0000239 BumpPtrAllocator DIEValueAllocator;
240
Adrian Prantl857237e2015-07-13 18:25:29 +0000241 /// Maps MDNode with its corresponding DwarfCompileUnit.
Eric Christopher179fba12014-01-29 22:06:23 +0000242 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
Bill Wendling2f921f82009-05-15 09:23:25 +0000243
Adrian Prantl857237e2015-07-13 18:25:29 +0000244 /// Maps subprogram MDNode with its corresponding DwarfCompileUnit.
David Blaikie7d6f29d2014-10-10 16:59:52 +0000245 MapVector<const MDNode *, DwarfCompileUnit *> SPMap;
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000246
Adrian Prantl857237e2015-07-13 18:25:29 +0000247 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
Eric Christopher4287a492013-12-09 23:57:44 +0000248 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
Manman Rence20d462013-10-29 22:57:10 +0000249
Adrian Prantl857237e2015-07-13 18:25:29 +0000250 /// List of all labels used in aranges generation.
Alexey Samsonov4436bf02013-10-03 08:54:43 +0000251 std::vector<SymbolCU> ArangeLabels;
Richard Mitton21101b32013-09-19 23:21:01 +0000252
Adrian Prantl857237e2015-07-13 18:25:29 +0000253 /// Size of each symbol emitted (for those symbols that have a specific size).
Eric Christophera5a79422013-12-09 23:32:48 +0000254 DenseMap<const MCSymbol *, uint64_t> SymSize;
Richard Mitton089ed892013-09-23 17:56:20 +0000255
Devang Patel7e623022011-08-10 20:55:27 +0000256 LexicalScopes LScopes;
Devang Patel95cd4b92010-03-25 15:09:44 +0000257
Adrian Prantl857237e2015-07-13 18:25:29 +0000258 /// Collection of abstract variables.
David Blaikie825bdd22014-05-21 22:41:17 +0000259 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
David Blaikieeb1a2722014-06-13 22:18:23 +0000260 SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000261
Adrian Prantl857237e2015-07-13 18:25:29 +0000262 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
263 /// can refer to them in spite of insertions into this list.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000264 DebugLocStream DebugLocs;
Devang Patel9fc11702010-05-25 23:40:22 +0000265
Adrian Prantl857237e2015-07-13 18:25:29 +0000266 /// This is a collection of subprogram MDNodes that are processed to
267 /// create DIEs.
Devang Patelf3b2db62010-06-28 18:25:03 +0000268 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
269
Adrian Prantl857237e2015-07-13 18:25:29 +0000270 /// Maps instruction with label emitted before instruction.
Devang Patel6c74a872010-04-27 19:46:33 +0000271 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
Devang Patel3ebd8932010-04-08 16:50:29 +0000272
Adrian Prantl857237e2015-07-13 18:25:29 +0000273 /// Maps instruction with label emitted after instruction.
Devang Patel6c74a872010-04-27 19:46:33 +0000274 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
Devang Patel3ebd8932010-04-08 16:50:29 +0000275
Adrian Prantl857237e2015-07-13 18:25:29 +0000276 /// History of DBG_VALUE and clobber instructions for each user
277 /// variable. Variables are listed in order of appearance.
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000278 DbgValueHistoryMap DbgValues;
Jakob Stoklund Olesenec0ac3c2011-03-22 22:33:08 +0000279
Adrian Prantl857237e2015-07-13 18:25:29 +0000280 /// Previous instruction's location information. This is used to
281 /// determine label location to indicate scope boundries in dwarf
282 /// debug info.
Chris Lattner915c5f92010-04-02 19:42:39 +0000283 DebugLoc PrevInstLoc;
Devang Patel12563b32010-04-16 23:33:45 +0000284 MCSymbol *PrevLabel;
Devang Patelbd477be2010-03-29 17:20:31 +0000285
Adrian Prantl857237e2015-07-13 18:25:29 +0000286 /// This location indicates end of function prologue and beginning of
287 /// function body.
Devang Patel34a66202011-05-11 19:22:19 +0000288 DebugLoc PrologEndLoc;
289
Adrian Prantl857237e2015-07-13 18:25:29 +0000290 /// If nonnull, stores the current machine function we're processing.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000291 const MachineFunction *CurFn;
292
Adrian Prantl857237e2015-07-13 18:25:29 +0000293 /// If nonnull, stores the current machine instruction we're processing.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000294 const MachineInstr *CurMI;
295
Adrian Prantl857237e2015-07-13 18:25:29 +0000296 /// If nonnull, stores the CU in which the previous subprogram was contained.
Eric Christopher384f3fe2014-03-20 19:16:16 +0000297 const DwarfCompileUnit *PrevCU;
298
Adrian Prantl857237e2015-07-13 18:25:29 +0000299 /// As an optimization, there is no need to emit an entry in the directory
300 /// table for the same directory as DW_AT_comp_dir.
Nick Lewyckyd1ee7f82011-11-02 20:55:33 +0000301 StringRef CompilationDir;
302
Adrian Prantl857237e2015-07-13 18:25:29 +0000303 /// Holder for the file specific debug information.
Eric Christopherf8194852013-12-05 18:06:10 +0000304 DwarfFile InfoHolder;
Eric Christopherc8a310e2012-12-10 23:34:43 +0000305
Adrian Prantl857237e2015-07-13 18:25:29 +0000306 /// Holders for the various debug information flags that we might need to
307 /// have exposed. See accessor functions below for description.
David Blaikied51dea62015-07-01 18:07:16 +0000308
Adrian Prantl857237e2015-07-13 18:25:29 +0000309 /// Holder for imported entities.
Eric Christopher070bf162013-07-03 01:57:26 +0000310 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
David Blaikied51dea62015-07-01 18:07:16 +0000311 ImportedEntityMap;
312 ImportedEntityMap ScopesWithImportedEntities;
Eric Christopher070bf162013-07-03 01:57:26 +0000313
Adrian Prantl857237e2015-07-13 18:25:29 +0000314 /// Map from MDNodes for user-defined types to the type units that
315 /// describe them.
David Blaikie47f615e2013-12-17 23:32:35 +0000316 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
Eric Christopher67646432013-07-26 17:02:41 +0000317
Duncan P. N. Exon Smithc6246882015-04-20 21:17:32 +0000318 SmallVector<
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000319 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
Eric Christopherffc5ff32015-02-17 20:02:28 +0000320 TypeUnitsUnderConstruction;
David Blaikiee12b49a2014-04-26 17:27:38 +0000321
Adrian Prantl857237e2015-07-13 18:25:29 +0000322 /// Whether to emit the pubnames/pubtypes sections.
Eric Christopher4d36ca02013-08-26 23:24:35 +0000323 bool HasDwarfPubSections;
324
Adrian Prantl857237e2015-07-13 18:25:29 +0000325 /// Whether or not to use AT_ranges for compilation units.
Eric Christopher1ad84572014-01-15 00:04:29 +0000326 bool HasCURanges;
327
Adrian Prantl857237e2015-07-13 18:25:29 +0000328 /// Whether we emitted a function into a section other than the
329 /// default text.
Eric Christopher2037caf2014-01-28 00:49:26 +0000330 bool UsedNonDefaultText;
331
Adrian Prantl857237e2015-07-13 18:25:29 +0000332 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
Paul Robinson78cc0822015-03-04 20:55:11 +0000333 bool UseGNUTLSOpcode;
334
Adrian Prantl857237e2015-07-13 18:25:29 +0000335 /// Version of dwarf we're emitting.
Eric Christopher4d36ca02013-08-26 23:24:35 +0000336 unsigned DwarfVersion;
337
Adrian Prantl857237e2015-07-13 18:25:29 +0000338 /// Maps from a type identifier to the actual MDNode.
Eric Christopher0a13eb32013-11-21 22:56:11 +0000339 DITypeIdentifierMap TypeIdentifierMap;
340
Adrian Prantl857237e2015-07-13 18:25:29 +0000341 /// DWARF5 Experimental Options
342 /// @{
Eric Christopher7b30f2e42012-11-21 00:34:35 +0000343 bool HasDwarfAccelTables;
Eric Christophercdf218d2012-12-10 19:51:21 +0000344 bool HasSplitDwarf;
Manman Renac8062b2013-07-02 23:40:10 +0000345
Adrian Prantl857237e2015-07-13 18:25:29 +0000346 /// Separated Dwarf Variables
347 /// In general these will all be for bits that are left in the
348 /// original object file, rather than things that are meant
349 /// to be in the .dwo sections.
Eric Christopherd79f5482012-12-10 19:51:13 +0000350
Adrian Prantl857237e2015-07-13 18:25:29 +0000351 /// Holder for the skeleton information.
Eric Christopherf8194852013-12-05 18:06:10 +0000352 DwarfFile SkeletonHolder;
Eric Christopherd79f5482012-12-10 19:51:13 +0000353
Adrian Prantl857237e2015-07-13 18:25:29 +0000354 /// Store file names for type units under fission in a line table
355 /// header that will be emitted into debug_line.dwo.
356 // FIXME: replace this with a map from comp_dir to table so that we
357 // can emit multiple tables during LTO each of which uses directory
358 // 0, referencing the comp_dir of all the type units that use it.
David Blaikie8287aff2014-03-18 02:13:23 +0000359 MCDwarfDwoLineTable SplitTypeUnitFileTable;
Adrian Prantl857237e2015-07-13 18:25:29 +0000360 /// @}
361
362 /// True iff there are multiple CUs in this module.
David Blaikie47f4b822014-03-19 00:11:28 +0000363 bool SingleCU;
David Blaikiee1c79742014-09-30 21:28:32 +0000364 bool IsDarwin;
David Blaikie47f4b822014-03-19 00:11:28 +0000365
David Blaikied75fb282014-04-23 21:20:10 +0000366 AddressPool AddrPool;
367
David Blaikie2406a0622014-04-23 23:37:35 +0000368 DwarfAccelTable AccelNames;
David Blaikie0ee82b92014-04-24 00:53:32 +0000369 DwarfAccelTable AccelObjC;
David Blaikieecf04152014-04-24 01:02:42 +0000370 DwarfAccelTable AccelNamespace;
David Blaikie18d33752014-04-24 01:23:49 +0000371 DwarfAccelTable AccelTypes;
David Blaikie2406a0622014-04-23 23:37:35 +0000372
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000373 DenseMap<const Function *, DISubprogram *> FunctionDIs;
David Blaikie2f040112014-07-25 16:10:16 +0000374
Paul Robinsonb9de1062015-07-15 22:04:54 +0000375 // Identify a debugger for "tuning" the debug info.
376 DebuggerKind DebuggerTuning;
377
David Blaikie47f4b822014-03-19 00:11:28 +0000378 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
379
David Blaikiec33b3cd2014-04-22 21:27:37 +0000380 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
Eric Christophera5a79422013-12-09 23:32:48 +0000381 return InfoHolder.getUnits();
382 }
David Blaikiefd1eff52013-11-26 19:14:34 +0000383
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000384 typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
385
Adrian Prantl857237e2015-07-13 18:25:29 +0000386 /// Find abstract variable associated with Var.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000387 DbgVariable *getExistingAbstractVariable(InlinedVariable IV,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000388 const DILocalVariable *&Cleansed);
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000389 DbgVariable *getExistingAbstractVariable(InlinedVariable IV);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000390 void createAbstractVariable(const DILocalVariable *DV, LexicalScope *Scope);
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000391 void ensureAbstractVariableIsCreated(InlinedVariable Var,
David Blaikie6f9e8672014-06-13 23:52:55 +0000392 const MDNode *Scope);
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000393 void ensureAbstractVariableIsCreatedIfScoped(InlinedVariable Var,
David Blaikie6f9e8672014-06-13 23:52:55 +0000394 const MDNode *Scope);
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000395
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000396 DbgVariable *createConcreteVariable(LexicalScope &Scope, InlinedVariable IV);
397
Adrian Prantl857237e2015-07-13 18:25:29 +0000398 /// Construct a DIE for this abstract scope.
David Blaikie73cc7052014-10-09 20:36:27 +0000399 void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
400
Adrian Prantl857237e2015-07-13 18:25:29 +0000401 /// Compute the size and offset of a DIE given an incoming Offset.
Eric Christopher1f0cbb82012-11-20 22:14:13 +0000402 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
Bill Wendling2f921f82009-05-15 09:23:25 +0000403
Adrian Prantl857237e2015-07-13 18:25:29 +0000404 /// Compute the size and offset of all the DIEs.
Devang Patel930143b2009-11-21 02:48:08 +0000405 void computeSizeAndOffsets();
Bill Wendling2f921f82009-05-15 09:23:25 +0000406
Adrian Prantl857237e2015-07-13 18:25:29 +0000407 /// Collect info for variables that were optimized out.
Eric Christopher960ac372012-11-22 00:59:49 +0000408 void collectDeadVariables();
409
David Blaikieeb1a2722014-06-13 22:18:23 +0000410 void finishVariableDefinitions();
411
David Blaikief7221ad2014-05-27 18:37:43 +0000412 void finishSubprogramDefinitions();
413
Adrian Prantl857237e2015-07-13 18:25:29 +0000414 /// Finish off debug information after all functions have been
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000415 /// processed.
Eric Christopher960ac372012-11-22 00:59:49 +0000416 void finalizeModuleInfo();
417
Adrian Prantl857237e2015-07-13 18:25:29 +0000418 /// Emit the debug info section.
Devang Patel930143b2009-11-21 02:48:08 +0000419 void emitDebugInfo();
Bill Wendling2f921f82009-05-15 09:23:25 +0000420
Adrian Prantl857237e2015-07-13 18:25:29 +0000421 /// Emit the abbreviation section.
Eric Christopher38371952012-11-20 23:30:11 +0000422 void emitAbbreviations();
Bill Wendling2f921f82009-05-15 09:23:25 +0000423
Adrian Prantl857237e2015-07-13 18:25:29 +0000424 /// Emit a specified accelerator table.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000425 void emitAccel(DwarfAccelTable &Accel, MCSection *Section,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000426 StringRef TableName);
David Blaikie6741bb02014-09-11 21:12:48 +0000427
Adrian Prantl857237e2015-07-13 18:25:29 +0000428 /// Emit visible names into a hashed accelerator table section.
Eric Christopher4996c702011-11-07 09:24:32 +0000429 void emitAccelNames();
Eric Christopher27527b22012-11-21 00:03:28 +0000430
Adrian Prantl857237e2015-07-13 18:25:29 +0000431 /// Emit objective C classes and categories into a hashed
Eric Christopher4996c702011-11-07 09:24:32 +0000432 /// accelerator table section.
433 void emitAccelObjC();
434
Adrian Prantl857237e2015-07-13 18:25:29 +0000435 /// Emit namespace dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +0000436 void emitAccelNamespaces();
437
Adrian Prantl857237e2015-07-13 18:25:29 +0000438 /// Emit type dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +0000439 void emitAccelTypes();
Eric Christopher27527b22012-11-21 00:03:28 +0000440
Adrian Prantl857237e2015-07-13 18:25:29 +0000441 /// Emit visible names into a debug pubnames section.
Eric Christopherdd1a0122013-09-13 00:35:05 +0000442 /// \param GnuStyle determines whether or not we want to emit
443 /// additional information into the table ala newer gcc for gdb
444 /// index.
445 void emitDebugPubNames(bool GnuStyle = false);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000446
Adrian Prantl857237e2015-07-13 18:25:29 +0000447 /// Emit visible types into a debug pubtypes section.
Eric Christopherdd1a0122013-09-13 00:35:05 +0000448 /// \param GnuStyle determines whether or not we want to emit
449 /// additional information into the table ala newer gcc for gdb
450 /// index.
451 void emitDebugPubTypes(bool GnuStyle = false);
Devang Patel04d2f2d2009-11-24 01:14:22 +0000452
David Blaikie192b45c2014-11-02 06:16:39 +0000453 void emitDebugPubSection(
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000454 bool GnuStyle, MCSection *PSec, StringRef Name,
David Blaikie192b45c2014-11-02 06:16:39 +0000455 const StringMap<const DIE *> &(DwarfCompileUnit::*Accessor)() const);
David Blaikie0f55e832014-03-11 23:18:15 +0000456
Adrian Prantl857237e2015-07-13 18:25:29 +0000457 /// Emit visible names into a debug str section.
Devang Patel930143b2009-11-21 02:48:08 +0000458 void emitDebugStr();
Bill Wendling2f921f82009-05-15 09:23:25 +0000459
Adrian Prantl857237e2015-07-13 18:25:29 +0000460 /// Emit visible names into a debug loc section.
Devang Patel930143b2009-11-21 02:48:08 +0000461 void emitDebugLoc();
Bill Wendling2f921f82009-05-15 09:23:25 +0000462
Adrian Prantl857237e2015-07-13 18:25:29 +0000463 /// Emit visible names into a debug loc dwo section.
David Blaikie94c1d7f2014-04-02 01:50:20 +0000464 void emitDebugLocDWO();
465
Adrian Prantl857237e2015-07-13 18:25:29 +0000466 /// Emit visible names into a debug aranges section.
Eric Christopher7b30f2e42012-11-21 00:34:35 +0000467 void emitDebugARanges();
Bill Wendling2f921f82009-05-15 09:23:25 +0000468
Adrian Prantl857237e2015-07-13 18:25:29 +0000469 /// Emit visible names into a debug ranges section.
Devang Patel930143b2009-11-21 02:48:08 +0000470 void emitDebugRanges();
Bill Wendling2f921f82009-05-15 09:23:25 +0000471
Adrian Prantl857237e2015-07-13 18:25:29 +0000472 /// Emit inline info using custom format.
Devang Patel930143b2009-11-21 02:48:08 +0000473 void emitDebugInlineInfo();
Bill Wendling2b128d72009-05-20 23:19:06 +0000474
Eric Christophercdf218d2012-12-10 19:51:21 +0000475 /// DWARF 5 Experimental Split Dwarf Emitters
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000476
Adrian Prantl857237e2015-07-13 18:25:29 +0000477 /// Initialize common features of skeleton units.
David Blaikie65a74662014-04-25 18:26:14 +0000478 void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
David Blaikief9b6a552014-04-22 22:39:41 +0000479 std::unique_ptr<DwarfUnit> NewU);
David Blaikie38fe6342014-01-09 04:28:46 +0000480
Adrian Prantl857237e2015-07-13 18:25:29 +0000481 /// Construct the split debug info compile unit for the debug info
Eric Christophercdf218d2012-12-10 19:51:21 +0000482 /// section.
David Blaikief9b6a552014-04-22 22:39:41 +0000483 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000484
Adrian Prantl857237e2015-07-13 18:25:29 +0000485 /// Construct the split debug info compile unit for the debug info
David Blaikie15ed5eb2014-01-10 01:38:41 +0000486 /// section.
David Blaikief9b6a552014-04-22 22:39:41 +0000487 DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
David Blaikie15ed5eb2014-01-10 01:38:41 +0000488
Adrian Prantl857237e2015-07-13 18:25:29 +0000489 /// Emit the debug info dwo section.
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000490 void emitDebugInfoDWO();
491
Adrian Prantl857237e2015-07-13 18:25:29 +0000492 /// Emit the debug abbrev dwo section.
Eric Christopher3c5a1912012-12-19 22:02:53 +0000493 void emitDebugAbbrevDWO();
494
Adrian Prantl857237e2015-07-13 18:25:29 +0000495 /// Emit the debug line dwo section.
David Blaikie4a2f95f2014-03-18 01:17:26 +0000496 void emitDebugLineDWO();
497
Adrian Prantl857237e2015-07-13 18:25:29 +0000498 /// Emit the debug str dwo section.
Eric Christopher3bf29fd2012-12-27 02:14:01 +0000499 void emitDebugStrDWO();
500
David Blaikie3c842622013-12-04 21:31:26 +0000501 /// Flags to let the linker know we have emitted new style pubnames. Only
502 /// emit it here if we don't have a skeleton CU for split dwarf.
David Blaikie65a74662014-04-25 18:26:14 +0000503 void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
David Blaikie3c842622013-12-04 21:31:26 +0000504
Adrian Prantl857237e2015-07-13 18:25:29 +0000505 /// Create new DwarfCompileUnit for the given metadata node with tag
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000506 /// DW_TAG_compile_unit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000507 DwarfCompileUnit &constructDwarfCompileUnit(const DICompileUnit *DIUnit);
Devang Patel1a0df9a2010-05-10 22:49:55 +0000508
Adrian Prantl857237e2015-07-13 18:25:29 +0000509 /// Construct imported_module or imported_declaration DIE.
David Blaikie8912df12014-08-31 05:41:15 +0000510 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000511 const DIImportedEntity *N);
David Blaikie684fc532013-05-06 23:33:07 +0000512
Adrian Prantl857237e2015-07-13 18:25:29 +0000513 /// Register a source line with debug info. Returns the unique
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000514 /// label that was emitted and which provides correspondence to the
515 /// source line list.
Devang Patel34a66202011-05-11 19:22:19 +0000516 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
517 unsigned Flags);
Eric Christopher27527b22012-11-21 00:03:28 +0000518
Adrian Prantl857237e2015-07-13 18:25:29 +0000519 /// Indentify instructions that are marking the beginning of or
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000520 /// ending of a scope.
Devang Patel359b0132010-04-08 18:43:56 +0000521 void identifyScopeMarkers();
Devang Patelf1d5a1e2010-04-08 15:37:09 +0000522
Adrian Prantl857237e2015-07-13 18:25:29 +0000523 /// Populate LexicalScope entries with variables' info.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000524 void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000525 DenseSet<InlinedVariable> &ProcessedVars);
Eric Christopher27527b22012-11-21 00:03:28 +0000526
Adrian Prantl857237e2015-07-13 18:25:29 +0000527 /// Build the location list for all DBG_VALUEs in the
Adrian Prantlb1416832014-08-01 22:11:58 +0000528 /// function that describe the same variable.
529 void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
David Blaikiee1a26a62014-08-05 23:14:16 +0000530 const DbgValueHistoryMap::InstrRanges &Ranges);
Adrian Prantlb1416832014-08-01 22:11:58 +0000531
Adrian Prantl857237e2015-07-13 18:25:29 +0000532 /// Collect variable information from the side table maintained
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000533 /// by MMI.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000534 void collectVariableInfoFromMMITable(DenseSet<InlinedVariable> &P);
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000535
Adrian Prantl857237e2015-07-13 18:25:29 +0000536 /// Ensure that a label will be emitted before MI.
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000537 void requestLabelBeforeInsn(const MachineInstr *MI) {
Craig Toppere73658d2014-04-28 04:05:08 +0000538 LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000539 }
540
Adrian Prantl857237e2015-07-13 18:25:29 +0000541 /// Ensure that a label will be emitted after MI.
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000542 void requestLabelAfterInsn(const MachineInstr *MI) {
Craig Toppere73658d2014-04-28 04:05:08 +0000543 LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000544 }
545
Bill Wendling2f921f82009-05-15 09:23:25 +0000546public:
547 //===--------------------------------------------------------------------===//
548 // Main entry points.
549 //
Chris Lattnerf0d6bd32010-04-05 05:11:15 +0000550 DwarfDebug(AsmPrinter *A, Module *M);
Bill Wendling2f921f82009-05-15 09:23:25 +0000551
Reid Klecknerdd2647e2014-04-30 20:34:31 +0000552 ~DwarfDebug() override;
553
Adrian Prantl857237e2015-07-13 18:25:29 +0000554 /// Emit all Dwarf sections that should come prior to the
Bill Wendling2f921f82009-05-15 09:23:25 +0000555 /// content.
Eric Christopher58f41952012-11-19 22:42:15 +0000556 void beginModule();
Bill Wendling2f921f82009-05-15 09:23:25 +0000557
Adrian Prantl857237e2015-07-13 18:25:29 +0000558 /// Emit all Dwarf sections that should come after the content.
Craig Topper7b883b32014-03-08 06:31:39 +0000559 void endModule() override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000560
Adrian Prantl857237e2015-07-13 18:25:29 +0000561 /// Gather pre-function debug information.
Craig Topper7b883b32014-03-08 06:31:39 +0000562 void beginFunction(const MachineFunction *MF) override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000563
Adrian Prantl857237e2015-07-13 18:25:29 +0000564 /// Gather and emit post-function debug information.
Craig Topper7b883b32014-03-08 06:31:39 +0000565 void endFunction(const MachineFunction *MF) override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000566
Adrian Prantl857237e2015-07-13 18:25:29 +0000567 /// Process beginning of an instruction.
Craig Topper7b883b32014-03-08 06:31:39 +0000568 void beginInstruction(const MachineInstr *MI) override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000569
Adrian Prantl857237e2015-07-13 18:25:29 +0000570 /// Process end of an instruction.
Craig Topper7b883b32014-03-08 06:31:39 +0000571 void endInstruction() override;
Devang Patelf20c4f72011-04-12 22:53:02 +0000572
Adrian Prantlee5feaf2015-07-15 17:01:41 +0000573 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
574 static uint64_t makeTypeSignature(StringRef Identifier);
575
Adrian Prantl857237e2015-07-13 18:25:29 +0000576 /// Add a DIE to the set of types that we're going to pull into
Eric Christopher67646432013-07-26 17:02:41 +0000577 /// type units.
David Blaikie15632ae2014-02-12 00:31:30 +0000578 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000579 DIE &Die, const DICompositeType *CTy);
Eric Christopher67646432013-07-26 17:02:41 +0000580
Adrian Prantl857237e2015-07-13 18:25:29 +0000581 /// Add a label so that arange data can be generated for it.
Alexey Samsonov4436bf02013-10-03 08:54:43 +0000582 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
Richard Mitton21101b32013-09-19 23:21:01 +0000583
Adrian Prantl857237e2015-07-13 18:25:29 +0000584 /// For symbols that have a size designated (e.g. common symbols),
Richard Mitton089ed892013-09-23 17:56:20 +0000585 /// this tracks that size.
Craig Topper7b883b32014-03-08 06:31:39 +0000586 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
Eric Christophera5a79422013-12-09 23:32:48 +0000587 SymSize[Sym] = Size;
588 }
Richard Mitton089ed892013-09-23 17:56:20 +0000589
Adrian Prantl857237e2015-07-13 18:25:29 +0000590 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
Paul Robinson78cc0822015-03-04 20:55:11 +0000591 /// standard DW_OP_form_tls_address opcode
592 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
593
Paul Robinsonb9de1062015-07-15 22:04:54 +0000594 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
595 ///
596 /// Returns whether we are "tuning" for a given debugger.
597 /// @{
598 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
599 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
600 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
601 /// @}
602
Eric Christopher55c51812012-11-21 00:03:31 +0000603 // Experimental DWARF5 features.
604
Adrian Prantl857237e2015-07-13 18:25:29 +0000605 /// Returns whether or not to emit tables that dwarf consumers can
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000606 /// use to accelerate lookup.
Eric Christopher411bd592014-03-06 00:00:53 +0000607 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
Eric Christopher55c51812012-11-21 00:03:31 +0000608
Adrian Prantl857237e2015-07-13 18:25:29 +0000609 /// Returns whether or not to change the current debug info for the
Eric Christophercdf218d2012-12-10 19:51:21 +0000610 /// split dwarf proposal support.
Eric Christopher411bd592014-03-06 00:00:53 +0000611 bool useSplitDwarf() const { return HasSplitDwarf; }
Manman Renac8062b2013-07-02 23:40:10 +0000612
613 /// Returns the Dwarf Version.
614 unsigned getDwarfVersion() const { return DwarfVersion; }
Manman Ren60352032013-09-05 18:48:31 +0000615
Eric Christopher384f3fe2014-03-20 19:16:16 +0000616 /// Returns the previous CU that was being updated
617 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
David Blaikied0f10372014-09-09 23:13:01 +0000618 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
Eric Christopher384f3fe2014-03-20 19:16:16 +0000619
Eric Christopher4f17ee02014-03-08 00:29:41 +0000620 /// Returns the entries for the .debug_loc section.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000621 const DebugLocStream &getDebugLocs() const { return DebugLocs; }
Eric Christopher4f17ee02014-03-08 00:29:41 +0000622
Adrian Prantl857237e2015-07-13 18:25:29 +0000623 /// Emit an entry for the debug loc section. This can be used to
Eric Christopher4f17ee02014-03-08 00:29:41 +0000624 /// handle an entry that's going to be emitted into the debug loc section.
Adrian Prantl92da14b2015-03-02 22:02:33 +0000625 void emitDebugLocEntry(ByteStreamer &Streamer,
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000626 const DebugLocStream::Entry &Entry);
Eric Christopher4f17ee02014-03-08 00:29:41 +0000627
David Blaikie0e84adc2014-04-01 16:17:41 +0000628 /// Emit the location for a debug loc entry, including the size header.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000629 void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry);
David Blaikie0e84adc2014-04-01 16:17:41 +0000630
Eric Christopher87b9c492013-10-05 00:32:34 +0000631 /// Find the MDNode for the given reference.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000632 template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000633 return Ref.resolve(TypeIdentifierMap);
634 }
Manman Ren60352032013-09-05 18:48:31 +0000635
Adrian Prantl857237e2015-07-13 18:25:29 +0000636 /// Return the TypeIdentifierMap.
Eric Christopherc0bd5f82014-03-18 20:39:54 +0000637 const DITypeIdentifierMap &getTypeIdentifierMap() const {
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000638 return TypeIdentifierMap;
639 }
640
Eric Christopherdd508382014-03-06 00:00:56 +0000641 /// Find the DwarfCompileUnit for the given CU Die.
642 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
643 return CUDieMap.lookup(CU);
644 }
Manman Ren3eb9dff2013-09-09 19:05:21 +0000645 /// isSubprogramContext - Return true if Context is either a subprogram
646 /// or another context nested inside a subprogram.
647 bool isSubprogramContext(const MDNode *Context);
David Blaikied75fb282014-04-23 21:20:10 +0000648
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000649 void addSubprogramNames(const DISubprogram *SP, DIE &Die);
David Blaikie2406a0622014-04-23 23:37:35 +0000650
David Blaikied75fb282014-04-23 21:20:10 +0000651 AddressPool &getAddressPool() { return AddrPool; }
David Blaikie2406a0622014-04-23 23:37:35 +0000652
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000653 void addAccelName(StringRef Name, const DIE &Die);
David Blaikie0ee82b92014-04-24 00:53:32 +0000654
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000655 void addAccelObjC(StringRef Name, const DIE &Die);
David Blaikieecf04152014-04-24 01:02:42 +0000656
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000657 void addAccelNamespace(StringRef Name, const DIE &Die);
David Blaikie18d33752014-04-24 01:23:49 +0000658
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000659 void addAccelType(StringRef Name, const DIE &Die, char Flags);
David Blaikiecda2aa82014-10-04 16:24:00 +0000660
661 const MachineFunction *getCurrentFunction() const { return CurFn; }
David Blaikie9c65b132014-10-08 22:20:02 +0000662
David Blaikied51dea62015-07-01 18:07:16 +0000663 iterator_range<ImportedEntityMap::const_iterator>
664 findImportedEntitiesForScope(const MDNode *Scope) const {
David Blaikie9c65b132014-10-08 22:20:02 +0000665 return make_range(std::equal_range(
David Blaikied51dea62015-07-01 18:07:16 +0000666 ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
David Blaikie33702a32014-10-08 23:09:42 +0000667 std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
668 less_first()));
David Blaikie9c65b132014-10-08 22:20:02 +0000669 }
670
Adrian Prantl857237e2015-07-13 18:25:29 +0000671 /// A helper function to check whether the DIE for a given Scope is
David Blaikie9c65b132014-10-08 22:20:02 +0000672 /// going to be null.
673 bool isLexicalScopeDIENull(LexicalScope *Scope);
674
Adrian Prantl857237e2015-07-13 18:25:29 +0000675 /// Return Label preceding the instruction.
David Blaikie01b48a82014-10-09 16:50:53 +0000676 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
677
Adrian Prantl857237e2015-07-13 18:25:29 +0000678 /// Return Label immediately following the instruction.
David Blaikie01b48a82014-10-09 16:50:53 +0000679 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
680
David Blaikie9c65b132014-10-08 22:20:02 +0000681 // FIXME: Sink these functions down into DwarfFile/Dwarf*Unit.
682
David Blaikie1d072342014-10-09 20:21:36 +0000683 SmallPtrSet<const MDNode *, 16> &getProcessedSPNodes() {
684 return ProcessedSPNodes;
685 }
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000686};
Bill Wendling2f921f82009-05-15 09:23:25 +0000687} // End of namespace llvm
688
689#endif