blob: 8a96e7867b6e3da02a28ad9c30c56482a865c422 [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
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000017#include "DbgValueHistoryCalculator.h"
Reid Klecknerf9c275f2016-02-10 20:55:49 +000018#include "DebugHandlerBase.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"
Eric Christopheracbe42b2014-03-18 20:58:35 +000024#include "llvm/ADT/MapVector.h"
David Blaikie38b74bf2016-12-15 23:37:38 +000025#include "llvm/ADT/SetVector.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000026#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"
Paul Robinson6c27a2c2015-12-16 19:58:30 +000036#include "llvm/Target/TargetOptions.h"
David Blaikief9b6a552014-04-22 22:39:41 +000037#include <memory>
38
Bill Wendling2f921f82009-05-15 09:23:25 +000039namespace llvm {
40
Adrian Prantl702bf5a2014-03-18 02:34:52 +000041class AsmPrinter;
Eric Christopher29e874d2014-03-07 22:40:37 +000042class ByteStreamer;
Chris Lattner88fce102012-01-26 20:44:57 +000043class ConstantInt;
44class ConstantFP;
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +000045class DebugLocEntry;
Eric Christopherce4a9442014-03-18 20:37:10 +000046class DwarfCompileUnit;
47class DwarfDebug;
48class DwarfTypeUnit;
49class DwarfUnit;
Bill Wendling2f921f82009-05-15 09:23:25 +000050class MachineModuleInfo;
Bill Wendling2f921f82009-05-15 09:23:25 +000051
52//===----------------------------------------------------------------------===//
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000053/// This class is used to track local variable information.
Adrian Prantlca7e4702015-02-10 23:18:28 +000054///
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000055/// Variables can be created from allocas, in which case they're generated from
56/// the MMI table. Such variables can have multiple expressions and frame
Adrian Prantl67c24422017-02-17 19:42:32 +000057/// indices.
Adrian Prantlca7e4702015-02-10 23:18:28 +000058///
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000059/// Variables can be created from \c DBG_VALUE instructions. Those whose
60/// location changes over time use \a DebugLocListIndex, while those with a
61/// single instruction use \a MInsn and (optionally) a single entry of \a Expr.
62///
63/// Variables that have been optimized out use none of these fields.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000064class DbgVariable {
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000065 const DILocalVariable *Var; /// Variable Descriptor.
66 const DILocation *IA; /// Inlined at location.
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000067 DIE *TheDIE = nullptr; /// Variable DIE.
68 unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs.
69 const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction.
Adrian Prantl67c24422017-02-17 19:42:32 +000070
71 struct FrameIndexExpr {
72 int FI;
73 const DIExpression *Expr;
74 };
75 mutable SmallVector<FrameIndexExpr, 1>
76 FrameIndexExprs; /// Frame index + expression.
Eric Christophera5a79422013-12-09 23:32:48 +000077
Devang Patelf20c4f72011-04-12 22:53:02 +000078public:
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000079 /// Construct a DbgVariable.
80 ///
81 /// Creates a variable without any DW_AT_location. Call \a initializeMMI()
82 /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +000083 DbgVariable(const DILocalVariable *V, const DILocation *IA)
84 : Var(V), IA(IA) {}
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000085
86 /// Initialize from the MMI table.
87 void initializeMMI(const DIExpression *E, int FI) {
Adrian Prantl67c24422017-02-17 19:42:32 +000088 assert(FrameIndexExprs.empty() && "Already initialized?");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000089 assert(!MInsn && "Already initialized?");
90
91 assert((!E || E->isValid()) && "Expected valid expression");
Reid Klecknerf7c09802017-03-01 21:42:00 +000092 assert(FI != INT_MAX && "Expected valid index");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000093
Adrian Prantl67c24422017-02-17 19:42:32 +000094 FrameIndexExprs.push_back({FI, E});
Adrian Prantl87b7eb92014-10-01 18:55:02 +000095 }
Devang Patelf20c4f72011-04-12 22:53:02 +000096
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +000097 /// Initialize from a DBG_VALUE instruction.
98 void initializeDbgValue(const MachineInstr *DbgValue) {
Adrian Prantl67c24422017-02-17 19:42:32 +000099 assert(FrameIndexExprs.empty() && "Already initialized?");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000100 assert(!MInsn && "Already initialized?");
101
102 assert(Var == DbgValue->getDebugVariable() && "Wrong variable");
103 assert(IA == DbgValue->getDebugLoc()->getInlinedAt() && "Wrong inlined-at");
104
105 MInsn = DbgValue;
106 if (auto *E = DbgValue->getDebugExpression())
107 if (E->getNumElements())
Adrian Prantl67c24422017-02-17 19:42:32 +0000108 FrameIndexExprs.push_back({0, E});
Adrian Prantlca7e4702015-02-10 23:18:28 +0000109 }
Adrian Prantlc1197542014-05-30 21:10:13 +0000110
Devang Patelf20c4f72011-04-12 22:53:02 +0000111 // Accessors.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000112 const DILocalVariable *getVariable() const { return Var; }
113 const DILocation *getInlinedAt() const { return IA; }
Adrian Prantl6f4746b12016-02-17 22:19:59 +0000114 const DIExpression *getSingleExpression() const {
Adrian Prantl67c24422017-02-17 19:42:32 +0000115 assert(MInsn && FrameIndexExprs.size() <= 1);
116 return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;
Adrian Prantl6f4746b12016-02-17 22:19:59 +0000117 }
David Blaikiee071fc82014-04-25 17:32:19 +0000118 void setDIE(DIE &D) { TheDIE = &D; }
Eric Christophera5a79422013-12-09 23:32:48 +0000119 DIE *getDIE() const { return TheDIE; }
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000120 void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
121 unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000122 StringRef getName() const { return Var->getName(); }
Eric Christophera5a79422013-12-09 23:32:48 +0000123 const MachineInstr *getMInsn() const { return MInsn; }
Adrian Prantl67c24422017-02-17 19:42:32 +0000124 /// Get the FI entries, sorted by fragment offset.
125 ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
126 bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
Adrian Prantlca7e4702015-02-10 23:18:28 +0000127
128 void addMMIEntry(const DbgVariable &V) {
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000129 assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");
130 assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");
Duncan P. N. Exon Smith60635e32015-04-21 18:44:06 +0000131 assert(V.Var == Var && "conflicting variable");
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000132 assert(V.IA == IA && "conflicting inlined-at location");
Adrian Prantlca7e4702015-02-10 23:18:28 +0000133
Adrian Prantl67c24422017-02-17 19:42:32 +0000134 assert(!FrameIndexExprs.empty() && "Expected an MMI entry");
135 assert(!V.FrameIndexExprs.empty() && "Expected an MMI entry");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000136
Adrian Prantl67c24422017-02-17 19:42:32 +0000137 FrameIndexExprs.append(V.FrameIndexExprs.begin(), V.FrameIndexExprs.end());
138 assert(all_of(FrameIndexExprs,
139 [](FrameIndexExpr &FIE) {
140 return FIE.Expr && FIE.Expr->isFragment();
141 }) &&
142 "conflicting locations for variable");
Adrian Prantlca7e4702015-02-10 23:18:28 +0000143 }
144
Eric Christopher27527b22012-11-21 00:03:28 +0000145 // Translate tag to proper Dwarf tag.
David Blaikieefc403b2014-04-12 02:24:04 +0000146 dwarf::Tag getTag() const {
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000147 // FIXME: Why don't we just infer this tag and store it all along?
148 if (Var->isParameter())
Devang Patel6e4d2c92011-08-15 18:35:42 +0000149 return dwarf::DW_TAG_formal_parameter;
Eric Christopher27527b22012-11-21 00:03:28 +0000150
Devang Patel6e4d2c92011-08-15 18:35:42 +0000151 return dwarf::DW_TAG_variable;
152 }
Adrian Prantl857237e2015-07-13 18:25:29 +0000153 /// Return true if DbgVariable is artificial.
Eric Christophera5a79422013-12-09 23:32:48 +0000154 bool isArtificial() const {
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000155 if (Var->isArtificial())
Devang Pateld7d80aa2011-08-15 18:40:16 +0000156 return true;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000157 if (getType()->isArtificial())
Devang Pateld7d80aa2011-08-15 18:40:16 +0000158 return true;
159 return false;
160 }
Eric Christophere3417762012-09-12 23:36:19 +0000161
Eric Christophera5a79422013-12-09 23:32:48 +0000162 bool isObjectPointer() const {
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000163 if (Var->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000164 return true;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000165 if (getType()->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000166 return true;
167 return false;
168 }
Eric Christopher27527b22012-11-21 00:03:28 +0000169
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000170 bool hasComplexAddress() const {
171 assert(MInsn && "Expected DBG_VALUE, not MMI variable");
Adrian Prantl67c24422017-02-17 19:42:32 +0000172 assert((FrameIndexExprs.empty() ||
173 (FrameIndexExprs.size() == 1 &&
174 FrameIndexExprs[0].Expr->getNumElements())) &&
175 "Invalid Expr for DBG_VALUE");
176 return !FrameIndexExprs.empty();
Devang Patelf20c4f72011-04-12 22:53:02 +0000177 }
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000178 bool isBlockByrefVariable() const;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000179 const DIType *getType() const;
Manman Renbe5576f2013-10-08 19:07:44 +0000180
181private:
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000182 template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
183 return Ref.resolve();
184 }
Devang Patelf20c4f72011-04-12 22:53:02 +0000185};
186
Eric Christopherc8a310e2012-12-10 23:34:43 +0000187
Adrian Prantl857237e2015-07-13 18:25:29 +0000188/// Helper used to pair up a symbol and its DWARF compile unit.
Richard Mitton21101b32013-09-19 23:21:01 +0000189struct SymbolCU {
Eric Christopher4287a492013-12-09 23:57:44 +0000190 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
Richard Mitton21101b32013-09-19 23:21:01 +0000191 const MCSymbol *Sym;
Eric Christopher4287a492013-12-09 23:57:44 +0000192 DwarfCompileUnit *CU;
Richard Mitton21101b32013-09-19 23:21:01 +0000193};
194
Adrian Prantl857237e2015-07-13 18:25:29 +0000195/// Collects and handles dwarf debug information.
Reid Klecknerf9c275f2016-02-10 20:55:49 +0000196class DwarfDebug : public DebugHandlerBase {
Adrian Prantl857237e2015-07-13 18:25:29 +0000197 /// All DIEValues are allocated through this allocator.
Benjamin Kramer07480082012-06-09 10:34:15 +0000198 BumpPtrAllocator DIEValueAllocator;
199
Adrian Prantl857237e2015-07-13 18:25:29 +0000200 /// Maps MDNode with its corresponding DwarfCompileUnit.
Eric Christopher179fba12014-01-29 22:06:23 +0000201 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
Bill Wendling2f921f82009-05-15 09:23:25 +0000202
Adrian Prantl857237e2015-07-13 18:25:29 +0000203 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
Eric Christopher4287a492013-12-09 23:57:44 +0000204 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
Manman Rence20d462013-10-29 22:57:10 +0000205
Adrian Prantl857237e2015-07-13 18:25:29 +0000206 /// List of all labels used in aranges generation.
Alexey Samsonov4436bf02013-10-03 08:54:43 +0000207 std::vector<SymbolCU> ArangeLabels;
Richard Mitton21101b32013-09-19 23:21:01 +0000208
Adrian Prantl857237e2015-07-13 18:25:29 +0000209 /// Size of each symbol emitted (for those symbols that have a specific size).
Eric Christophera5a79422013-12-09 23:32:48 +0000210 DenseMap<const MCSymbol *, uint64_t> SymSize;
Richard Mitton089ed892013-09-23 17:56:20 +0000211
Adrian Prantl857237e2015-07-13 18:25:29 +0000212 /// Collection of abstract variables.
David Blaikie825bdd22014-05-21 22:41:17 +0000213 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
David Blaikieeb1a2722014-06-13 22:18:23 +0000214 SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000215
Adrian Prantl857237e2015-07-13 18:25:29 +0000216 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
217 /// can refer to them in spite of insertions into this list.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000218 DebugLocStream DebugLocs;
Devang Patel9fc11702010-05-25 23:40:22 +0000219
Adrian Prantl857237e2015-07-13 18:25:29 +0000220 /// This is a collection of subprogram MDNodes that are processed to
221 /// create DIEs.
David Blaikie38b74bf2016-12-15 23:37:38 +0000222 SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>,
223 SmallPtrSet<const DISubprogram *, 16>>
224 ProcessedSPNodes;
Devang Patelf3b2db62010-06-28 18:25:03 +0000225
Adrian Prantl857237e2015-07-13 18:25:29 +0000226 /// If nonnull, stores the current machine function we're processing.
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000227 const MachineFunction *CurFn;
228
Adrian Prantl857237e2015-07-13 18:25:29 +0000229 /// If nonnull, stores the CU in which the previous subprogram was contained.
Eric Christopher384f3fe2014-03-20 19:16:16 +0000230 const DwarfCompileUnit *PrevCU;
231
Adrian Prantl857237e2015-07-13 18:25:29 +0000232 /// As an optimization, there is no need to emit an entry in the directory
233 /// table for the same directory as DW_AT_comp_dir.
Nick Lewyckyd1ee7f82011-11-02 20:55:33 +0000234 StringRef CompilationDir;
235
Adrian Prantl857237e2015-07-13 18:25:29 +0000236 /// Holder for the file specific debug information.
Eric Christopherf8194852013-12-05 18:06:10 +0000237 DwarfFile InfoHolder;
Eric Christopherc8a310e2012-12-10 23:34:43 +0000238
Adrian Prantl857237e2015-07-13 18:25:29 +0000239 /// Holders for the various debug information flags that we might need to
240 /// have exposed. See accessor functions below for description.
David Blaikied51dea62015-07-01 18:07:16 +0000241
Peter Collingbourne7c384cc2016-02-11 19:57:46 +0000242 /// Map from MDNodes for user-defined types to their type signatures. Also
243 /// used to keep track of which types we have emitted type units for.
244 DenseMap<const MDNode *, uint64_t> TypeSignatures;
Eric Christopher67646432013-07-26 17:02:41 +0000245
Duncan P. N. Exon Smithc6246882015-04-20 21:17:32 +0000246 SmallVector<
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000247 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
Eric Christopherffc5ff32015-02-17 20:02:28 +0000248 TypeUnitsUnderConstruction;
David Blaikiee12b49a2014-04-26 17:27:38 +0000249
Adrian Prantl857237e2015-07-13 18:25:29 +0000250 /// Whether to emit the pubnames/pubtypes sections.
Eric Christopher4d36ca02013-08-26 23:24:35 +0000251 bool HasDwarfPubSections;
252
Adrian Prantl857237e2015-07-13 18:25:29 +0000253 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
Paul Robinson78cc0822015-03-04 20:55:11 +0000254 bool UseGNUTLSOpcode;
255
Adrian Prantl6323ddf2016-05-17 21:07:16 +0000256 /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
257 bool UseDWARF2Bitfields;
258
Paul Robinson43d1e452016-04-18 22:41:41 +0000259 /// Whether to emit all linkage names, or just abstract subprograms.
260 bool UseAllLinkageNames;
Paul Robinson78046b42015-08-11 21:36:45 +0000261
Adrian Prantl857237e2015-07-13 18:25:29 +0000262 /// DWARF5 Experimental Options
263 /// @{
Eric Christopher7b30f2e42012-11-21 00:34:35 +0000264 bool HasDwarfAccelTables;
David Blaikiec53e18d2016-05-24 21:19:28 +0000265 bool HasAppleExtensionAttributes;
Eric Christophercdf218d2012-12-10 19:51:21 +0000266 bool HasSplitDwarf;
Manman Renac8062b2013-07-02 23:40:10 +0000267
Adrian Prantl857237e2015-07-13 18:25:29 +0000268 /// Separated Dwarf Variables
269 /// In general these will all be for bits that are left in the
270 /// original object file, rather than things that are meant
271 /// to be in the .dwo sections.
Eric Christopherd79f5482012-12-10 19:51:13 +0000272
Adrian Prantl857237e2015-07-13 18:25:29 +0000273 /// Holder for the skeleton information.
Eric Christopherf8194852013-12-05 18:06:10 +0000274 DwarfFile SkeletonHolder;
Eric Christopherd79f5482012-12-10 19:51:13 +0000275
Adrian Prantl857237e2015-07-13 18:25:29 +0000276 /// Store file names for type units under fission in a line table
277 /// header that will be emitted into debug_line.dwo.
278 // FIXME: replace this with a map from comp_dir to table so that we
279 // can emit multiple tables during LTO each of which uses directory
280 // 0, referencing the comp_dir of all the type units that use it.
David Blaikie8287aff2014-03-18 02:13:23 +0000281 MCDwarfDwoLineTable SplitTypeUnitFileTable;
Adrian Prantl857237e2015-07-13 18:25:29 +0000282 /// @}
283
284 /// True iff there are multiple CUs in this module.
David Blaikie47f4b822014-03-19 00:11:28 +0000285 bool SingleCU;
David Blaikiee1c79742014-09-30 21:28:32 +0000286 bool IsDarwin;
David Blaikie47f4b822014-03-19 00:11:28 +0000287
David Blaikied75fb282014-04-23 21:20:10 +0000288 AddressPool AddrPool;
289
David Blaikie2406a0622014-04-23 23:37:35 +0000290 DwarfAccelTable AccelNames;
David Blaikie0ee82b92014-04-24 00:53:32 +0000291 DwarfAccelTable AccelObjC;
David Blaikieecf04152014-04-24 01:02:42 +0000292 DwarfAccelTable AccelNamespace;
David Blaikie18d33752014-04-24 01:23:49 +0000293 DwarfAccelTable AccelTypes;
David Blaikie2406a0622014-04-23 23:37:35 +0000294
Paul Robinsonb9de1062015-07-15 22:04:54 +0000295 // Identify a debugger for "tuning" the debug info.
296 DebuggerKind DebuggerTuning;
297
Paul Robinson10177212016-05-17 22:53:20 +0000298 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
299 ///
300 /// Returns whether we are "tuning" for a given debugger.
301 /// Should be used only within the constructor, to set feature flags.
302 /// @{
303 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
304 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
305 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
306 /// @}
307
David Blaikie47f4b822014-03-19 00:11:28 +0000308 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
309
Peter Collingbourne7c384cc2016-02-11 19:57:46 +0000310 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
Eric Christophera5a79422013-12-09 23:32:48 +0000311 return InfoHolder.getUnits();
312 }
David Blaikiefd1eff52013-11-26 19:14:34 +0000313
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000314 typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
315
Adrian Prantl857237e2015-07-13 18:25:29 +0000316 /// Find abstract variable associated with Var.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000317 DbgVariable *getExistingAbstractVariable(InlinedVariable IV,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000318 const DILocalVariable *&Cleansed);
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000319 DbgVariable *getExistingAbstractVariable(InlinedVariable IV);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000320 void createAbstractVariable(const DILocalVariable *DV, LexicalScope *Scope);
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000321 void ensureAbstractVariableIsCreated(InlinedVariable Var,
David Blaikie6f9e8672014-06-13 23:52:55 +0000322 const MDNode *Scope);
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000323 void ensureAbstractVariableIsCreatedIfScoped(InlinedVariable Var,
David Blaikie6f9e8672014-06-13 23:52:55 +0000324 const MDNode *Scope);
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000325
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000326 DbgVariable *createConcreteVariable(LexicalScope &Scope, InlinedVariable IV);
327
Adrian Prantl857237e2015-07-13 18:25:29 +0000328 /// Construct a DIE for this abstract scope.
David Blaikie73cc7052014-10-09 20:36:27 +0000329 void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
330
David Blaikieeb1a2722014-06-13 22:18:23 +0000331 void finishVariableDefinitions();
332
David Blaikief7221ad2014-05-27 18:37:43 +0000333 void finishSubprogramDefinitions();
334
Adrian Prantl857237e2015-07-13 18:25:29 +0000335 /// Finish off debug information after all functions have been
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000336 /// processed.
Eric Christopher960ac372012-11-22 00:59:49 +0000337 void finalizeModuleInfo();
338
Adrian Prantl857237e2015-07-13 18:25:29 +0000339 /// Emit the debug info section.
Devang Patel930143b2009-11-21 02:48:08 +0000340 void emitDebugInfo();
Bill Wendling2f921f82009-05-15 09:23:25 +0000341
Adrian Prantl857237e2015-07-13 18:25:29 +0000342 /// Emit the abbreviation section.
Eric Christopher38371952012-11-20 23:30:11 +0000343 void emitAbbreviations();
Bill Wendling2f921f82009-05-15 09:23:25 +0000344
Adrian Prantl857237e2015-07-13 18:25:29 +0000345 /// Emit a specified accelerator table.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000346 void emitAccel(DwarfAccelTable &Accel, MCSection *Section,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000347 StringRef TableName);
David Blaikie6741bb02014-09-11 21:12:48 +0000348
Adrian Prantl857237e2015-07-13 18:25:29 +0000349 /// Emit visible names into a hashed accelerator table section.
Eric Christopher4996c702011-11-07 09:24:32 +0000350 void emitAccelNames();
Eric Christopher27527b22012-11-21 00:03:28 +0000351
Adrian Prantl857237e2015-07-13 18:25:29 +0000352 /// Emit objective C classes and categories into a hashed
Eric Christopher4996c702011-11-07 09:24:32 +0000353 /// accelerator table section.
354 void emitAccelObjC();
355
Adrian Prantl857237e2015-07-13 18:25:29 +0000356 /// Emit namespace dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +0000357 void emitAccelNamespaces();
358
Adrian Prantl857237e2015-07-13 18:25:29 +0000359 /// Emit type dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +0000360 void emitAccelTypes();
Eric Christopher27527b22012-11-21 00:03:28 +0000361
Adrian Prantl857237e2015-07-13 18:25:29 +0000362 /// Emit visible names into a debug pubnames section.
Eric Christopherdd1a0122013-09-13 00:35:05 +0000363 /// \param GnuStyle determines whether or not we want to emit
364 /// additional information into the table ala newer gcc for gdb
365 /// index.
366 void emitDebugPubNames(bool GnuStyle = false);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000367
Adrian Prantl857237e2015-07-13 18:25:29 +0000368 /// Emit visible types into a debug pubtypes section.
Eric Christopherdd1a0122013-09-13 00:35:05 +0000369 /// \param GnuStyle determines whether or not we want to emit
370 /// additional information into the table ala newer gcc for gdb
371 /// index.
372 void emitDebugPubTypes(bool GnuStyle = false);
Devang Patel04d2f2d2009-11-24 01:14:22 +0000373
David Blaikie192b45c2014-11-02 06:16:39 +0000374 void emitDebugPubSection(
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000375 bool GnuStyle, MCSection *PSec, StringRef Name,
David Blaikie192b45c2014-11-02 06:16:39 +0000376 const StringMap<const DIE *> &(DwarfCompileUnit::*Accessor)() const);
David Blaikie0f55e832014-03-11 23:18:15 +0000377
Amjad Aboudc0778412016-01-24 08:18:55 +0000378 /// Emit null-terminated strings into a debug str section.
Devang Patel930143b2009-11-21 02:48:08 +0000379 void emitDebugStr();
Bill Wendling2f921f82009-05-15 09:23:25 +0000380
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000381 /// Emit variable locations into a debug loc section.
Devang Patel930143b2009-11-21 02:48:08 +0000382 void emitDebugLoc();
Bill Wendling2f921f82009-05-15 09:23:25 +0000383
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000384 /// Emit variable locations into a debug loc dwo section.
David Blaikie94c1d7f2014-04-02 01:50:20 +0000385 void emitDebugLocDWO();
386
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000387 /// Emit address ranges into a debug aranges section.
Eric Christopher7b30f2e42012-11-21 00:34:35 +0000388 void emitDebugARanges();
Bill Wendling2f921f82009-05-15 09:23:25 +0000389
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000390 /// Emit address ranges into a debug ranges section.
Devang Patel930143b2009-11-21 02:48:08 +0000391 void emitDebugRanges();
Bill Wendling2f921f82009-05-15 09:23:25 +0000392
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000393 /// Emit macros into a debug macinfo section.
394 void emitDebugMacinfo();
Amjad Aboud8bbce8a2016-02-01 14:09:41 +0000395 void emitMacro(DIMacro &M);
396 void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
397 void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000398
Eric Christophercdf218d2012-12-10 19:51:21 +0000399 /// DWARF 5 Experimental Split Dwarf Emitters
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000400
Adrian Prantl857237e2015-07-13 18:25:29 +0000401 /// Initialize common features of skeleton units.
David Blaikie65a74662014-04-25 18:26:14 +0000402 void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
Peter Collingbourne7c384cc2016-02-11 19:57:46 +0000403 std::unique_ptr<DwarfCompileUnit> NewU);
David Blaikie38fe6342014-01-09 04:28:46 +0000404
Adrian Prantl857237e2015-07-13 18:25:29 +0000405 /// Construct the split debug info compile unit for the debug info
Eric Christophercdf218d2012-12-10 19:51:21 +0000406 /// section.
David Blaikief9b6a552014-04-22 22:39:41 +0000407 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000408
Adrian Prantl857237e2015-07-13 18:25:29 +0000409 /// Emit the debug info dwo section.
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000410 void emitDebugInfoDWO();
411
Adrian Prantl857237e2015-07-13 18:25:29 +0000412 /// Emit the debug abbrev dwo section.
Eric Christopher3c5a1912012-12-19 22:02:53 +0000413 void emitDebugAbbrevDWO();
414
Adrian Prantl857237e2015-07-13 18:25:29 +0000415 /// Emit the debug line dwo section.
David Blaikie4a2f95f2014-03-18 01:17:26 +0000416 void emitDebugLineDWO();
417
Adrian Prantl857237e2015-07-13 18:25:29 +0000418 /// Emit the debug str dwo section.
Eric Christopher3bf29fd2012-12-27 02:14:01 +0000419 void emitDebugStrDWO();
420
David Blaikie3c842622013-12-04 21:31:26 +0000421 /// Flags to let the linker know we have emitted new style pubnames. Only
422 /// emit it here if we don't have a skeleton CU for split dwarf.
David Blaikie65a74662014-04-25 18:26:14 +0000423 void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
David Blaikie3c842622013-12-04 21:31:26 +0000424
Adrian Prantl857237e2015-07-13 18:25:29 +0000425 /// Create new DwarfCompileUnit for the given metadata node with tag
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000426 /// DW_TAG_compile_unit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000427 DwarfCompileUnit &constructDwarfCompileUnit(const DICompileUnit *DIUnit);
Devang Patel1a0df9a2010-05-10 22:49:55 +0000428
Adrian Prantl857237e2015-07-13 18:25:29 +0000429 /// Construct imported_module or imported_declaration DIE.
David Blaikie8912df12014-08-31 05:41:15 +0000430 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000431 const DIImportedEntity *N);
David Blaikie684fc532013-05-06 23:33:07 +0000432
Adrian Prantl857237e2015-07-13 18:25:29 +0000433 /// Register a source line with debug info. Returns the unique
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000434 /// label that was emitted and which provides correspondence to the
435 /// source line list.
Devang Patel34a66202011-05-11 19:22:19 +0000436 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
437 unsigned Flags);
Eric Christopher27527b22012-11-21 00:03:28 +0000438
Adrian Prantl857237e2015-07-13 18:25:29 +0000439 /// Populate LexicalScope entries with variables' info.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000440 void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000441 DenseSet<InlinedVariable> &ProcessedVars);
Eric Christopher27527b22012-11-21 00:03:28 +0000442
Adrian Prantl857237e2015-07-13 18:25:29 +0000443 /// Build the location list for all DBG_VALUEs in the
Adrian Prantlb1416832014-08-01 22:11:58 +0000444 /// function that describe the same variable.
445 void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
David Blaikiee1a26a62014-08-05 23:14:16 +0000446 const DbgValueHistoryMap::InstrRanges &Ranges);
Adrian Prantlb1416832014-08-01 22:11:58 +0000447
Matthias Braunef331ef2016-11-30 23:48:50 +0000448 /// Collect variable information from the side table maintained by MF.
449 void collectVariableInfoFromMFTable(DenseSet<InlinedVariable> &P);
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000450
David Blaikieb2fbb4b2017-02-16 18:48:33 +0000451protected:
452 /// Gather pre-function debug information.
453 void beginFunctionImpl(const MachineFunction *MF) override;
454
455 /// Gather and emit post-function debug information.
456 void endFunctionImpl(const MachineFunction *MF) override;
457
458 void skippedNonDebugFunction() override;
459
Bill Wendling2f921f82009-05-15 09:23:25 +0000460public:
461 //===--------------------------------------------------------------------===//
462 // Main entry points.
463 //
Chris Lattnerf0d6bd32010-04-05 05:11:15 +0000464 DwarfDebug(AsmPrinter *A, Module *M);
Bill Wendling2f921f82009-05-15 09:23:25 +0000465
Reid Klecknerdd2647e2014-04-30 20:34:31 +0000466 ~DwarfDebug() override;
467
Adrian Prantl857237e2015-07-13 18:25:29 +0000468 /// Emit all Dwarf sections that should come prior to the
Bill Wendling2f921f82009-05-15 09:23:25 +0000469 /// content.
Eric Christopher58f41952012-11-19 22:42:15 +0000470 void beginModule();
Bill Wendling2f921f82009-05-15 09:23:25 +0000471
Adrian Prantl857237e2015-07-13 18:25:29 +0000472 /// Emit all Dwarf sections that should come after the content.
Craig Topper7b883b32014-03-08 06:31:39 +0000473 void endModule() override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000474
Adrian Prantl857237e2015-07-13 18:25:29 +0000475 /// Process beginning of an instruction.
Craig Topper7b883b32014-03-08 06:31:39 +0000476 void beginInstruction(const MachineInstr *MI) override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000477
Adrian Prantlee5feaf2015-07-15 17:01:41 +0000478 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
479 static uint64_t makeTypeSignature(StringRef Identifier);
480
Adrian Prantl857237e2015-07-13 18:25:29 +0000481 /// Add a DIE to the set of types that we're going to pull into
Eric Christopher67646432013-07-26 17:02:41 +0000482 /// type units.
David Blaikie15632ae2014-02-12 00:31:30 +0000483 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000484 DIE &Die, const DICompositeType *CTy);
Eric Christopher67646432013-07-26 17:02:41 +0000485
Adrian Prantl857237e2015-07-13 18:25:29 +0000486 /// Add a label so that arange data can be generated for it.
Alexey Samsonov4436bf02013-10-03 08:54:43 +0000487 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
Richard Mitton21101b32013-09-19 23:21:01 +0000488
Adrian Prantl857237e2015-07-13 18:25:29 +0000489 /// For symbols that have a size designated (e.g. common symbols),
Richard Mitton089ed892013-09-23 17:56:20 +0000490 /// this tracks that size.
Craig Topper7b883b32014-03-08 06:31:39 +0000491 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
Eric Christophera5a79422013-12-09 23:32:48 +0000492 SymSize[Sym] = Size;
493 }
Richard Mitton089ed892013-09-23 17:56:20 +0000494
Paul Robinson43d1e452016-04-18 22:41:41 +0000495 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
496 /// If not, we still might emit certain cases.
497 bool useAllLinkageNames() const { return UseAllLinkageNames; }
Paul Robinson78046b42015-08-11 21:36:45 +0000498
Adrian Prantl857237e2015-07-13 18:25:29 +0000499 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
Paul Robinson78cc0822015-03-04 20:55:11 +0000500 /// standard DW_OP_form_tls_address opcode
501 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
502
Adrian Prantl6323ddf2016-05-17 21:07:16 +0000503 /// Returns whether to use the DWARF2 format for bitfields instyead of the
504 /// DWARF4 format.
505 bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
506
Eric Christopher55c51812012-11-21 00:03:31 +0000507 // Experimental DWARF5 features.
508
Adrian Prantl857237e2015-07-13 18:25:29 +0000509 /// Returns whether or not to emit tables that dwarf consumers can
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000510 /// use to accelerate lookup.
Eric Christopher411bd592014-03-06 00:00:53 +0000511 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
Eric Christopher55c51812012-11-21 00:03:31 +0000512
David Blaikiec53e18d2016-05-24 21:19:28 +0000513 bool useAppleExtensionAttributes() const {
514 return HasAppleExtensionAttributes;
515 }
516
Adrian Prantl857237e2015-07-13 18:25:29 +0000517 /// Returns whether or not to change the current debug info for the
Eric Christophercdf218d2012-12-10 19:51:21 +0000518 /// split dwarf proposal support.
Eric Christopher411bd592014-03-06 00:00:53 +0000519 bool useSplitDwarf() const { return HasSplitDwarf; }
Manman Renac8062b2013-07-02 23:40:10 +0000520
521 /// Returns the Dwarf Version.
Greg Claytone6543972016-11-23 23:30:37 +0000522 uint16_t getDwarfVersion() const;
Manman Ren60352032013-09-05 18:48:31 +0000523
Eric Christopher384f3fe2014-03-20 19:16:16 +0000524 /// Returns the previous CU that was being updated
525 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
David Blaikied0f10372014-09-09 23:13:01 +0000526 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
Eric Christopher384f3fe2014-03-20 19:16:16 +0000527
Eric Christopher4f17ee02014-03-08 00:29:41 +0000528 /// Returns the entries for the .debug_loc section.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000529 const DebugLocStream &getDebugLocs() const { return DebugLocs; }
Eric Christopher4f17ee02014-03-08 00:29:41 +0000530
Adrian Prantl857237e2015-07-13 18:25:29 +0000531 /// Emit an entry for the debug loc section. This can be used to
Eric Christopher4f17ee02014-03-08 00:29:41 +0000532 /// handle an entry that's going to be emitted into the debug loc section.
Adrian Prantl92da14b2015-03-02 22:02:33 +0000533 void emitDebugLocEntry(ByteStreamer &Streamer,
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000534 const DebugLocStream::Entry &Entry);
Eric Christopher4f17ee02014-03-08 00:29:41 +0000535
David Blaikie0e84adc2014-04-01 16:17:41 +0000536 /// Emit the location for a debug loc entry, including the size header.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000537 void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry);
David Blaikie0e84adc2014-04-01 16:17:41 +0000538
Eric Christopher87b9c492013-10-05 00:32:34 +0000539 /// Find the MDNode for the given reference.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000540 template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000541 return Ref.resolve();
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000542 }
543
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000544 void addSubprogramNames(const DISubprogram *SP, DIE &Die);
David Blaikie2406a0622014-04-23 23:37:35 +0000545
David Blaikied75fb282014-04-23 21:20:10 +0000546 AddressPool &getAddressPool() { return AddrPool; }
David Blaikie2406a0622014-04-23 23:37:35 +0000547
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000548 void addAccelName(StringRef Name, const DIE &Die);
David Blaikie0ee82b92014-04-24 00:53:32 +0000549
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000550 void addAccelObjC(StringRef Name, const DIE &Die);
David Blaikieecf04152014-04-24 01:02:42 +0000551
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000552 void addAccelNamespace(StringRef Name, const DIE &Die);
David Blaikie18d33752014-04-24 01:23:49 +0000553
David Blaikieb0b3fcf2014-04-25 18:52:29 +0000554 void addAccelType(StringRef Name, const DIE &Die, char Flags);
David Blaikiecda2aa82014-10-04 16:24:00 +0000555
556 const MachineFunction *getCurrentFunction() const { return CurFn; }
David Blaikie9c65b132014-10-08 22:20:02 +0000557
Adrian Prantl857237e2015-07-13 18:25:29 +0000558 /// A helper function to check whether the DIE for a given Scope is
David Blaikie9c65b132014-10-08 22:20:02 +0000559 /// going to be null.
560 bool isLexicalScopeDIENull(LexicalScope *Scope);
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000561};
Bill Wendling2f921f82009-05-15 09:23:25 +0000562} // End of namespace llvm
563
564#endif