blob: 53e2baebbd01f7774b777f0db5065a53816f208c [file] [log] [blame]
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +00001//===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===//
Bill Wendling2f921f82009-05-15 09:23:25 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Bill Wendling2f921f82009-05-15 09:23:25 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file contains support for writing dwarf debug info into asm files.
10//
11//===----------------------------------------------------------------------===//
12
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000013#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
14#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
Bill Wendling2f921f82009-05-15 09:23:25 +000015
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000016#include "AddressPool.h"
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +000017#include "DebugLocStream.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000018#include "DwarfFile.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000019#include "llvm/ADT/ArrayRef.h"
Devang Patel018b29b2010-01-19 06:19:05 +000020#include "llvm/ADT/DenseMap.h"
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000021#include "llvm/ADT/DenseSet.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000022#include "llvm/ADT/MapVector.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000023#include "llvm/ADT/STLExtras.h"
David Blaikie38b74bf2016-12-15 23:37:38 +000024#include "llvm/ADT/SetVector.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000025#include "llvm/ADT/SmallPtrSet.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000026#include "llvm/ADT/SmallVector.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000027#include "llvm/ADT/StringMap.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000028#include "llvm/ADT/StringRef.h"
29#include "llvm/BinaryFormat/Dwarf.h"
Jonas Devlieghere855fc3b2018-01-29 14:52:41 +000030#include "llvm/CodeGen/AccelTable.h"
Yonghong Song61b189e2018-12-18 23:10:17 +000031#include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
32#include "llvm/CodeGen/DebugHandlerBase.h"
Adrian Prantlc1197542014-05-30 21:10:13 +000033#include "llvm/CodeGen/MachineInstr.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000034#include "llvm/IR/DebugInfoMetadata.h"
Eric Christopheracbe42b2014-03-18 20:58:35 +000035#include "llvm/IR/DebugLoc.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000036#include "llvm/IR/Metadata.h"
David Blaikie4a2f95f2014-03-18 01:17:26 +000037#include "llvm/MC/MCDwarf.h"
Chris Lattner3f3fb972010-04-05 05:24:55 +000038#include "llvm/Support/Allocator.h"
Paul Robinson6c27a2c2015-12-16 19:58:30 +000039#include "llvm/Target/TargetOptions.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000040#include <cassert>
41#include <cstdint>
42#include <limits>
David Blaikief9b6a552014-04-22 22:39:41 +000043#include <memory>
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000044#include <utility>
45#include <vector>
David Blaikief9b6a552014-04-22 22:39:41 +000046
Bill Wendling2f921f82009-05-15 09:23:25 +000047namespace llvm {
48
Adrian Prantl702bf5a2014-03-18 02:34:52 +000049class AsmPrinter;
Eric Christopher29e874d2014-03-07 22:40:37 +000050class ByteStreamer;
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +000051class DebugLocEntry;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000052class DIE;
Eric Christopherce4a9442014-03-18 20:37:10 +000053class DwarfCompileUnit;
Eric Christopherce4a9442014-03-18 20:37:10 +000054class DwarfTypeUnit;
55class DwarfUnit;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000056class LexicalScope;
57class MachineFunction;
58class MCSection;
59class MCSymbol;
60class MDNode;
61class Module;
Bill Wendling2f921f82009-05-15 09:23:25 +000062
63//===----------------------------------------------------------------------===//
Hsiangkai Wang2532ac82018-08-17 15:22:04 +000064/// This class is defined as the common parent of DbgVariable and DbgLabel
65/// such that it could levarage polymorphism to extract common code for
66/// DbgVariable and DbgLabel.
67class DbgEntity {
68 const DINode *Entity;
69 const DILocation *InlinedAt;
70 DIE *TheDIE = nullptr;
71 unsigned SubclassID;
72
73public:
74 enum DbgEntityKind {
75 DbgVariableKind,
76 DbgLabelKind
77 };
78
79 DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)
80 : Entity(N), InlinedAt(IA), SubclassID(ID) {}
81 virtual ~DbgEntity() {}
82
83 /// Accessors.
84 /// @{
85 const DINode *getEntity() const { return Entity; }
86 const DILocation *getInlinedAt() const { return InlinedAt; }
87 DIE *getDIE() const { return TheDIE; }
88 unsigned getDbgEntityID() const { return SubclassID; }
89 /// @}
90
91 void setDIE(DIE &D) { TheDIE = &D; }
92
93 static bool classof(const DbgEntity *N) {
94 switch (N->getDbgEntityID()) {
95 default:
96 return false;
97 case DbgVariableKind:
98 case DbgLabelKind:
99 return true;
100 }
101 }
102};
103
104//===----------------------------------------------------------------------===//
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000105/// This class is used to track local variable information.
Adrian Prantlca7e4702015-02-10 23:18:28 +0000106///
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000107/// Variables can be created from allocas, in which case they're generated from
108/// the MMI table. Such variables can have multiple expressions and frame
Adrian Prantl67c24422017-02-17 19:42:32 +0000109/// indices.
Adrian Prantlca7e4702015-02-10 23:18:28 +0000110///
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000111/// Variables can be created from \c DBG_VALUE instructions. Those whose
112/// location changes over time use \a DebugLocListIndex, while those with a
113/// single instruction use \a MInsn and (optionally) a single entry of \a Expr.
114///
115/// Variables that have been optimized out use none of these fields.
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000116class DbgVariable : public DbgEntity {
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000117 unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs.
118 const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction.
Adrian Prantl67c24422017-02-17 19:42:32 +0000119
120 struct FrameIndexExpr {
121 int FI;
122 const DIExpression *Expr;
123 };
124 mutable SmallVector<FrameIndexExpr, 1>
125 FrameIndexExprs; /// Frame index + expression.
Eric Christophera5a79422013-12-09 23:32:48 +0000126
Devang Patelf20c4f72011-04-12 22:53:02 +0000127public:
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000128 /// Construct a DbgVariable.
129 ///
130 /// Creates a variable without any DW_AT_location. Call \a initializeMMI()
131 /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000132 DbgVariable(const DILocalVariable *V, const DILocation *IA)
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000133 : DbgEntity(V, IA, DbgVariableKind) {}
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000134
135 /// Initialize from the MMI table.
136 void initializeMMI(const DIExpression *E, int FI) {
Adrian Prantl67c24422017-02-17 19:42:32 +0000137 assert(FrameIndexExprs.empty() && "Already initialized?");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000138 assert(!MInsn && "Already initialized?");
139
140 assert((!E || E->isValid()) && "Expected valid expression");
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000141 assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000142
Adrian Prantl67c24422017-02-17 19:42:32 +0000143 FrameIndexExprs.push_back({FI, E});
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000144 }
Devang Patelf20c4f72011-04-12 22:53:02 +0000145
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000146 /// Initialize from a DBG_VALUE instruction.
147 void initializeDbgValue(const MachineInstr *DbgValue) {
Adrian Prantl67c24422017-02-17 19:42:32 +0000148 assert(FrameIndexExprs.empty() && "Already initialized?");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000149 assert(!MInsn && "Already initialized?");
150
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000151 assert(getVariable() == DbgValue->getDebugVariable() && "Wrong variable");
152 assert(getInlinedAt() == DbgValue->getDebugLoc()->getInlinedAt() &&
153 "Wrong inlined-at");
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000154
155 MInsn = DbgValue;
156 if (auto *E = DbgValue->getDebugExpression())
157 if (E->getNumElements())
Adrian Prantl67c24422017-02-17 19:42:32 +0000158 FrameIndexExprs.push_back({0, E});
Adrian Prantlca7e4702015-02-10 23:18:28 +0000159 }
Adrian Prantlc1197542014-05-30 21:10:13 +0000160
Devang Patelf20c4f72011-04-12 22:53:02 +0000161 // Accessors.
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000162 const DILocalVariable *getVariable() const {
163 return cast<DILocalVariable>(getEntity());
164 }
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000165
Adrian Prantl6f4746b12016-02-17 22:19:59 +0000166 const DIExpression *getSingleExpression() const {
Adrian Prantl67c24422017-02-17 19:42:32 +0000167 assert(MInsn && FrameIndexExprs.size() <= 1);
168 return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;
Adrian Prantl6f4746b12016-02-17 22:19:59 +0000169 }
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000170
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000171 void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
172 unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000173 StringRef getName() const { return getVariable()->getName(); }
Eric Christophera5a79422013-12-09 23:32:48 +0000174 const MachineInstr *getMInsn() const { return MInsn; }
Adrian Prantl67c24422017-02-17 19:42:32 +0000175 /// Get the FI entries, sorted by fragment offset.
176 ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
177 bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
Bjorn Steinbrinkd36bbe92017-10-10 07:46:17 +0000178 void addMMIEntry(const DbgVariable &V);
Adrian Prantlca7e4702015-02-10 23:18:28 +0000179
Eric Christopher27527b22012-11-21 00:03:28 +0000180 // Translate tag to proper Dwarf tag.
David Blaikieefc403b2014-04-12 02:24:04 +0000181 dwarf::Tag getTag() const {
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000182 // FIXME: Why don't we just infer this tag and store it all along?
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000183 if (getVariable()->isParameter())
Devang Patel6e4d2c92011-08-15 18:35:42 +0000184 return dwarf::DW_TAG_formal_parameter;
Eric Christopher27527b22012-11-21 00:03:28 +0000185
Devang Patel6e4d2c92011-08-15 18:35:42 +0000186 return dwarf::DW_TAG_variable;
187 }
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000188
Adrian Prantl857237e2015-07-13 18:25:29 +0000189 /// Return true if DbgVariable is artificial.
Eric Christophera5a79422013-12-09 23:32:48 +0000190 bool isArtificial() const {
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000191 if (getVariable()->isArtificial())
Devang Pateld7d80aa2011-08-15 18:40:16 +0000192 return true;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000193 if (getType()->isArtificial())
Devang Pateld7d80aa2011-08-15 18:40:16 +0000194 return true;
195 return false;
196 }
Eric Christophere3417762012-09-12 23:36:19 +0000197
Eric Christophera5a79422013-12-09 23:32:48 +0000198 bool isObjectPointer() const {
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000199 if (getVariable()->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000200 return true;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000201 if (getType()->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000202 return true;
203 return false;
204 }
Eric Christopher27527b22012-11-21 00:03:28 +0000205
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000206 bool hasComplexAddress() const {
207 assert(MInsn && "Expected DBG_VALUE, not MMI variable");
Adrian Prantl67c24422017-02-17 19:42:32 +0000208 assert((FrameIndexExprs.empty() ||
209 (FrameIndexExprs.size() == 1 &&
210 FrameIndexExprs[0].Expr->getNumElements())) &&
211 "Invalid Expr for DBG_VALUE");
212 return !FrameIndexExprs.empty();
Devang Patelf20c4f72011-04-12 22:53:02 +0000213 }
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000214
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000215 bool isBlockByrefVariable() const;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000216 const DIType *getType() const;
Manman Renbe5576f2013-10-08 19:07:44 +0000217
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000218 static bool classof(const DbgEntity *N) {
219 return N->getDbgEntityID() == DbgVariableKind;
220 }
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000221};
222
223//===----------------------------------------------------------------------===//
224/// This class is used to track label information.
225///
226/// Labels are collected from \c DBG_LABEL instructions.
227class DbgLabel : public DbgEntity {
228 const MCSymbol *Sym; /// Symbol before DBG_LABEL instruction.
229
230public:
231 /// We need MCSymbol information to generate DW_AT_low_pc.
232 DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
233 : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
234
235 /// Accessors.
236 /// @{
237 const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
238 const MCSymbol *getSymbol() const { return Sym; }
239
240 StringRef getName() const { return getLabel()->getName(); }
241 /// @}
242
243 /// Translate tag to proper Dwarf tag.
244 dwarf::Tag getTag() const {
245 return dwarf::DW_TAG_label;
246 }
247
248 static bool classof(const DbgEntity *N) {
249 return N->getDbgEntityID() == DbgLabelKind;
250 }
Devang Patelf20c4f72011-04-12 22:53:02 +0000251};
252
Adrian Prantl857237e2015-07-13 18:25:29 +0000253/// Helper used to pair up a symbol and its DWARF compile unit.
Richard Mitton21101b32013-09-19 23:21:01 +0000254struct SymbolCU {
Eric Christopher4287a492013-12-09 23:57:44 +0000255 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000256
Richard Mitton21101b32013-09-19 23:21:01 +0000257 const MCSymbol *Sym;
Eric Christopher4287a492013-12-09 23:57:44 +0000258 DwarfCompileUnit *CU;
Richard Mitton21101b32013-09-19 23:21:01 +0000259};
260
Pavel Labath6088c232018-04-04 14:42:14 +0000261/// The kind of accelerator tables we should emit.
262enum class AccelTableKind {
263 Default, ///< Platform default.
264 None, ///< None.
265 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
266 Dwarf, ///< DWARF v5 .debug_names.
267};
268
Adrian Prantl857237e2015-07-13 18:25:29 +0000269/// Collects and handles dwarf debug information.
Reid Klecknerf9c275f2016-02-10 20:55:49 +0000270class DwarfDebug : public DebugHandlerBase {
Adrian Prantl857237e2015-07-13 18:25:29 +0000271 /// All DIEValues are allocated through this allocator.
Benjamin Kramer07480082012-06-09 10:34:15 +0000272 BumpPtrAllocator DIEValueAllocator;
273
Adrian Prantl857237e2015-07-13 18:25:29 +0000274 /// Maps MDNode with its corresponding DwarfCompileUnit.
Eric Christopher179fba12014-01-29 22:06:23 +0000275 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
Bill Wendling2f921f82009-05-15 09:23:25 +0000276
Adrian Prantl857237e2015-07-13 18:25:29 +0000277 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
Eric Christopher4287a492013-12-09 23:57:44 +0000278 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
Manman Rence20d462013-10-29 22:57:10 +0000279
Adrian Prantl857237e2015-07-13 18:25:29 +0000280 /// List of all labels used in aranges generation.
Alexey Samsonov4436bf02013-10-03 08:54:43 +0000281 std::vector<SymbolCU> ArangeLabels;
Richard Mitton21101b32013-09-19 23:21:01 +0000282
Adrian Prantl857237e2015-07-13 18:25:29 +0000283 /// Size of each symbol emitted (for those symbols that have a specific size).
Eric Christophera5a79422013-12-09 23:32:48 +0000284 DenseMap<const MCSymbol *, uint64_t> SymSize;
Richard Mitton089ed892013-09-23 17:56:20 +0000285
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000286 /// Collection of abstract variables/labels.
287 SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000288
Adrian Prantl857237e2015-07-13 18:25:29 +0000289 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
290 /// can refer to them in spite of insertions into this list.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000291 DebugLocStream DebugLocs;
Devang Patel9fc11702010-05-25 23:40:22 +0000292
Adrian Prantl857237e2015-07-13 18:25:29 +0000293 /// This is a collection of subprogram MDNodes that are processed to
294 /// create DIEs.
David Blaikie38b74bf2016-12-15 23:37:38 +0000295 SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>,
296 SmallPtrSet<const DISubprogram *, 16>>
297 ProcessedSPNodes;
Devang Patelf3b2db62010-06-28 18:25:03 +0000298
Adrian Prantl857237e2015-07-13 18:25:29 +0000299 /// If nonnull, stores the current machine function we're processing.
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000300 const MachineFunction *CurFn = nullptr;
Timur Iskhodzhanov1cd14442013-12-03 15:10:23 +0000301
Adrian Prantl857237e2015-07-13 18:25:29 +0000302 /// If nonnull, stores the CU in which the previous subprogram was contained.
Eric Christopher384f3fe2014-03-20 19:16:16 +0000303 const DwarfCompileUnit *PrevCU;
304
Adrian Prantl857237e2015-07-13 18:25:29 +0000305 /// As an optimization, there is no need to emit an entry in the directory
306 /// table for the same directory as DW_AT_comp_dir.
Nick Lewyckyd1ee7f82011-11-02 20:55:33 +0000307 StringRef CompilationDir;
308
Adrian Prantl857237e2015-07-13 18:25:29 +0000309 /// Holder for the file specific debug information.
Eric Christopherf8194852013-12-05 18:06:10 +0000310 DwarfFile InfoHolder;
Eric Christopherc8a310e2012-12-10 23:34:43 +0000311
Adrian Prantl857237e2015-07-13 18:25:29 +0000312 /// Holders for the various debug information flags that we might need to
313 /// have exposed. See accessor functions below for description.
David Blaikied51dea62015-07-01 18:07:16 +0000314
Peter Collingbourne7c384cc2016-02-11 19:57:46 +0000315 /// Map from MDNodes for user-defined types to their type signatures. Also
316 /// used to keep track of which types we have emitted type units for.
317 DenseMap<const MDNode *, uint64_t> TypeSignatures;
Eric Christopher67646432013-07-26 17:02:41 +0000318
David Blaikie60fddac2018-10-24 23:36:29 +0000319 DenseMap<const MCSection *, const MCSymbol *> SectionLabels;
320
Duncan P. N. Exon Smithc6246882015-04-20 21:17:32 +0000321 SmallVector<
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000322 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
Eric Christopherffc5ff32015-02-17 20:02:28 +0000323 TypeUnitsUnderConstruction;
David Blaikiee12b49a2014-04-26 17:27:38 +0000324
Adrian Prantl857237e2015-07-13 18:25:29 +0000325 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
Paul Robinson78cc0822015-03-04 20:55:11 +0000326 bool UseGNUTLSOpcode;
327
Adrian Prantl6323ddf2016-05-17 21:07:16 +0000328 /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
329 bool UseDWARF2Bitfields;
330
Paul Robinson43d1e452016-04-18 22:41:41 +0000331 /// Whether to emit all linkage names, or just abstract subprograms.
332 bool UseAllLinkageNames;
Paul Robinson78046b42015-08-11 21:36:45 +0000333
Alexey Bataev0d6aead2018-02-20 15:28:08 +0000334 /// Use inlined strings.
335 bool UseInlineStrings = false;
336
Alexey Bataev858a7dd2018-03-20 20:21:38 +0000337 /// Allow emission of .debug_ranges section.
338 bool UseRangesSection = true;
339
Alexey Bataevbff36082018-03-23 13:35:54 +0000340 /// True if the sections itself must be used as references and don't create
341 /// temp symbols inside DWARF sections.
342 bool UseSectionsAsReferences = false;
343
Alexey Bataev2a03d422018-06-29 14:23:28 +0000344 ///Allow emission of the .debug_loc section.
345 bool UseLocSection = true;
346
Pavel Labathf9adc202018-07-20 12:59:05 +0000347 /// Generate DWARF v4 type units.
348 bool GenerateTypeUnits;
349
Adrian Prantl857237e2015-07-13 18:25:29 +0000350 /// DWARF5 Experimental Options
351 /// @{
Pavel Labath0cc03062018-04-04 14:54:08 +0000352 AccelTableKind TheAccelTableKind;
David Blaikiec53e18d2016-05-24 21:19:28 +0000353 bool HasAppleExtensionAttributes;
Eric Christophercdf218d2012-12-10 19:51:21 +0000354 bool HasSplitDwarf;
Manman Renac8062b2013-07-02 23:40:10 +0000355
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000356 /// Whether to generate the DWARF v5 string offsets table.
357 /// It consists of a series of contributions, each preceded by a header.
358 /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
359 /// a monolithic sequence of string offsets.
360 bool UseSegmentedStringOffsetsTable;
361
Adrian Prantl857237e2015-07-13 18:25:29 +0000362 /// Separated Dwarf Variables
363 /// In general these will all be for bits that are left in the
364 /// original object file, rather than things that are meant
365 /// to be in the .dwo sections.
Eric Christopherd79f5482012-12-10 19:51:13 +0000366
Adrian Prantl857237e2015-07-13 18:25:29 +0000367 /// Holder for the skeleton information.
Eric Christopherf8194852013-12-05 18:06:10 +0000368 DwarfFile SkeletonHolder;
Eric Christopherd79f5482012-12-10 19:51:13 +0000369
Adrian Prantl857237e2015-07-13 18:25:29 +0000370 /// Store file names for type units under fission in a line table
371 /// header that will be emitted into debug_line.dwo.
372 // FIXME: replace this with a map from comp_dir to table so that we
373 // can emit multiple tables during LTO each of which uses directory
374 // 0, referencing the comp_dir of all the type units that use it.
David Blaikie8287aff2014-03-18 02:13:23 +0000375 MCDwarfDwoLineTable SplitTypeUnitFileTable;
Adrian Prantl857237e2015-07-13 18:25:29 +0000376 /// @}
Jonas Devlieghere294e6892017-11-15 10:57:05 +0000377
Adrian Prantl857237e2015-07-13 18:25:29 +0000378 /// True iff there are multiple CUs in this module.
David Blaikie47f4b822014-03-19 00:11:28 +0000379 bool SingleCU;
David Blaikiee1c79742014-09-30 21:28:32 +0000380 bool IsDarwin;
David Blaikie47f4b822014-03-19 00:11:28 +0000381
David Blaikied75fb282014-04-23 21:20:10 +0000382 AddressPool AddrPool;
383
Pavel Labath6088c232018-04-04 14:42:14 +0000384 /// Accelerator tables.
385 AccelTable<DWARF5AccelTableData> AccelDebugNames;
Pavel Labatha7c457d2018-02-19 16:12:20 +0000386 AccelTable<AppleAccelTableOffsetData> AccelNames;
387 AccelTable<AppleAccelTableOffsetData> AccelObjC;
388 AccelTable<AppleAccelTableOffsetData> AccelNamespace;
389 AccelTable<AppleAccelTableTypeData> AccelTypes;
David Blaikie2406a0622014-04-23 23:37:35 +0000390
Paul Robinsonb9de1062015-07-15 22:04:54 +0000391 // Identify a debugger for "tuning" the debug info.
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000392 DebuggerKind DebuggerTuning = DebuggerKind::Default;
Paul Robinsonb9de1062015-07-15 22:04:54 +0000393
David Blaikie47f4b822014-03-19 00:11:28 +0000394 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
395
Peter Collingbourne7c384cc2016-02-11 19:57:46 +0000396 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
Eric Christophera5a79422013-12-09 23:32:48 +0000397 return InfoHolder.getUnits();
398 }
David Blaikiefd1eff52013-11-26 19:14:34 +0000399
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000400 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000401
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000402 void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
403 const DINode *Node,
404 const MDNode *Scope);
405 void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
406 const DINode *Node,
407 const MDNode *Scope);
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000408
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000409 DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
410 LexicalScope &Scope,
411 const DINode *Node,
412 const DILocation *Location,
413 const MCSymbol *Sym = nullptr);
Duncan P. N. Exon Smithe6cc5312015-06-21 16:50:43 +0000414
Adrian Prantl857237e2015-07-13 18:25:29 +0000415 /// Construct a DIE for this abstract scope.
David Blaikie488393f2017-05-12 01:13:45 +0000416 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
David Blaikie73cc7052014-10-09 20:36:27 +0000417
Vedant Kumar5931b4e2018-10-05 20:37:17 +0000418 /// Construct DIEs for call site entries describing the calls in \p MF.
419 void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
420 DIE &ScopeDIE, const MachineFunction &MF);
421
Pavel Labath7f7e6062018-07-20 15:24:13 +0000422 template <typename DataT>
David Blaikie66cf14d2018-08-16 21:29:55 +0000423 void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
424 StringRef Name, const DIE &Die);
Pavel Labath3fb39c72018-04-18 12:11:59 +0000425
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000426 void finishEntityDefinitions();
David Blaikieeb1a2722014-06-13 22:18:23 +0000427
David Blaikief7221ad2014-05-27 18:37:43 +0000428 void finishSubprogramDefinitions();
429
Adrian Prantl857237e2015-07-13 18:25:29 +0000430 /// Finish off debug information after all functions have been
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000431 /// processed.
Eric Christopher960ac372012-11-22 00:59:49 +0000432 void finalizeModuleInfo();
433
Adrian Prantl857237e2015-07-13 18:25:29 +0000434 /// Emit the debug info section.
Devang Patel930143b2009-11-21 02:48:08 +0000435 void emitDebugInfo();
Bill Wendling2f921f82009-05-15 09:23:25 +0000436
Adrian Prantl857237e2015-07-13 18:25:29 +0000437 /// Emit the abbreviation section.
Eric Christopher38371952012-11-20 23:30:11 +0000438 void emitAbbreviations();
Bill Wendling2f921f82009-05-15 09:23:25 +0000439
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000440 /// Emit the string offsets table header.
441 void emitStringOffsetsTableHeader();
442
Adrian Prantl857237e2015-07-13 18:25:29 +0000443 /// Emit a specified accelerator table.
Jonas Devliegheree699dfa2018-01-29 14:52:34 +0000444 template <typename AccelTableT>
445 void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
David Blaikie6741bb02014-09-11 21:12:48 +0000446
Pavel Labath6088c232018-04-04 14:42:14 +0000447 /// Emit DWARF v5 accelerator table.
448 void emitAccelDebugNames();
449
Adrian Prantl857237e2015-07-13 18:25:29 +0000450 /// Emit visible names into a hashed accelerator table section.
Eric Christopher4996c702011-11-07 09:24:32 +0000451 void emitAccelNames();
Eric Christopher27527b22012-11-21 00:03:28 +0000452
Adrian Prantl857237e2015-07-13 18:25:29 +0000453 /// Emit objective C classes and categories into a hashed
Eric Christopher4996c702011-11-07 09:24:32 +0000454 /// accelerator table section.
455 void emitAccelObjC();
456
Adrian Prantl857237e2015-07-13 18:25:29 +0000457 /// Emit namespace dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +0000458 void emitAccelNamespaces();
459
Adrian Prantl857237e2015-07-13 18:25:29 +0000460 /// Emit type dies into a hashed accelerator table.
Eric Christopher4996c702011-11-07 09:24:32 +0000461 void emitAccelTypes();
Eric Christopher27527b22012-11-21 00:03:28 +0000462
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000463 /// Emit visible names and types into debug pubnames and pubtypes sections.
464 void emitDebugPubSections();
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000465
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000466 void emitDebugPubSection(bool GnuStyle, StringRef Name,
467 DwarfCompileUnit *TheU,
468 const StringMap<const DIE *> &Globals);
David Blaikie0f55e832014-03-11 23:18:15 +0000469
Amjad Aboudc0778412016-01-24 08:18:55 +0000470 /// Emit null-terminated strings into a debug str section.
Devang Patel930143b2009-11-21 02:48:08 +0000471 void emitDebugStr();
Bill Wendling2f921f82009-05-15 09:23:25 +0000472
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000473 /// Emit variable locations into a debug loc section.
Devang Patel930143b2009-11-21 02:48:08 +0000474 void emitDebugLoc();
Bill Wendling2f921f82009-05-15 09:23:25 +0000475
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000476 /// Emit variable locations into a debug loc dwo section.
David Blaikie94c1d7f2014-04-02 01:50:20 +0000477 void emitDebugLocDWO();
478
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000479 /// Emit address ranges into a debug aranges section.
Eric Christopher7b30f2e42012-11-21 00:34:35 +0000480 void emitDebugARanges();
Bill Wendling2f921f82009-05-15 09:23:25 +0000481
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000482 /// Emit address ranges into a debug ranges section.
Devang Patel930143b2009-11-21 02:48:08 +0000483 void emitDebugRanges();
David Blaikiec4af8bf2018-10-20 07:36:39 +0000484 void emitDebugRangesDWO();
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000485
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000486 /// Emit macros into a debug macinfo section.
487 void emitDebugMacinfo();
Amjad Aboud8bbce8a2016-02-01 14:09:41 +0000488 void emitMacro(DIMacro &M);
489 void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
490 void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000491
Eric Christophercdf218d2012-12-10 19:51:21 +0000492 /// DWARF 5 Experimental Split Dwarf Emitters
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000493
Adrian Prantl857237e2015-07-13 18:25:29 +0000494 /// Initialize common features of skeleton units.
David Blaikie65a74662014-04-25 18:26:14 +0000495 void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
Peter Collingbourne7c384cc2016-02-11 19:57:46 +0000496 std::unique_ptr<DwarfCompileUnit> NewU);
David Blaikie38fe6342014-01-09 04:28:46 +0000497
Wolfgang Pieb9ea65082018-07-26 22:48:52 +0000498 /// Construct the split debug info compile unit for the debug info section.
499 /// In DWARF v5, the skeleton unit DIE may have the following attributes:
500 /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
501 /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
502 /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
503 /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
504 /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
David Blaikief9b6a552014-04-22 22:39:41 +0000505 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000506
Adrian Prantl857237e2015-07-13 18:25:29 +0000507 /// Emit the debug info dwo section.
Eric Christopher9c2ecd92012-11-30 23:59:06 +0000508 void emitDebugInfoDWO();
509
Adrian Prantl857237e2015-07-13 18:25:29 +0000510 /// Emit the debug abbrev dwo section.
Eric Christopher3c5a1912012-12-19 22:02:53 +0000511 void emitDebugAbbrevDWO();
512
Adrian Prantl857237e2015-07-13 18:25:29 +0000513 /// Emit the debug line dwo section.
David Blaikie4a2f95f2014-03-18 01:17:26 +0000514 void emitDebugLineDWO();
515
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000516 /// Emit the dwo stringoffsets table header.
517 void emitStringOffsetsTableHeaderDWO();
518
Adrian Prantl857237e2015-07-13 18:25:29 +0000519 /// Emit the debug str dwo section.
Eric Christopher3bf29fd2012-12-27 02:14:01 +0000520 void emitDebugStrDWO();
521
Victor Leschuk64e0c562018-08-01 05:48:06 +0000522 /// Emit DWO addresses.
523 void emitDebugAddr();
524
David Blaikie3c842622013-12-04 21:31:26 +0000525 /// Flags to let the linker know we have emitted new style pubnames. Only
526 /// emit it here if we don't have a skeleton CU for split dwarf.
David Blaikieb3cee2f2017-05-25 18:50:28 +0000527 void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
David Blaikie3c842622013-12-04 21:31:26 +0000528
Adrian Prantl857237e2015-07-13 18:25:29 +0000529 /// Create new DwarfCompileUnit for the given metadata node with tag
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000530 /// DW_TAG_compile_unit.
David Blaikie07963bd2017-05-26 18:52:56 +0000531 DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
David Blaikie560ff352018-12-14 22:44:46 +0000532 void finishUnitAttributes(const DICompileUnit *DIUnit,
533 DwarfCompileUnit &NewCU);
Devang Patel1a0df9a2010-05-10 22:49:55 +0000534
Adrian Prantl857237e2015-07-13 18:25:29 +0000535 /// Construct imported_module or imported_declaration DIE.
David Blaikie8912df12014-08-31 05:41:15 +0000536 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000537 const DIImportedEntity *N);
David Blaikie684fc532013-05-06 23:33:07 +0000538
Adrian Prantl857237e2015-07-13 18:25:29 +0000539 /// Register a source line with debug info. Returns the unique
Eric Christopheracdcbdb2012-11-27 22:43:45 +0000540 /// label that was emitted and which provides correspondence to the
541 /// source line list.
Devang Patel34a66202011-05-11 19:22:19 +0000542 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
543 unsigned Flags);
Eric Christopher27527b22012-11-21 00:03:28 +0000544
Adrian Prantl857237e2015-07-13 18:25:29 +0000545 /// Populate LexicalScope entries with variables' info.
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000546 void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000547 DenseSet<InlinedEntity> &ProcessedVars);
Eric Christopher27527b22012-11-21 00:03:28 +0000548
Adrian Prantl857237e2015-07-13 18:25:29 +0000549 /// Build the location list for all DBG_VALUEs in the
Adrian Prantlb1416832014-08-01 22:11:58 +0000550 /// function that describe the same variable.
551 void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
David Stenberg6feef562019-04-10 09:07:43 +0000552 const DbgValueHistoryMap::Entries &Entries);
Adrian Prantlb1416832014-08-01 22:11:58 +0000553
Matthias Braunef331ef2016-11-30 23:48:50 +0000554 /// Collect variable information from the side table maintained by MF.
David Blaikie488393f2017-05-12 01:13:45 +0000555 void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000556 DenseSet<InlinedEntity> &P);
Jakob Stoklund Olesen9a624fa2011-03-26 02:19:36 +0000557
Alexey Bataevbff36082018-03-23 13:35:54 +0000558 /// Emit the reference to the section.
559 void emitSectionReference(const DwarfCompileUnit &CU);
560
David Blaikieb2fbb4b2017-02-16 18:48:33 +0000561protected:
562 /// Gather pre-function debug information.
563 void beginFunctionImpl(const MachineFunction *MF) override;
564
565 /// Gather and emit post-function debug information.
566 void endFunctionImpl(const MachineFunction *MF) override;
567
568 void skippedNonDebugFunction() override;
569
Bill Wendling2f921f82009-05-15 09:23:25 +0000570public:
571 //===--------------------------------------------------------------------===//
572 // Main entry points.
573 //
Chris Lattnerf0d6bd32010-04-05 05:11:15 +0000574 DwarfDebug(AsmPrinter *A, Module *M);
Bill Wendling2f921f82009-05-15 09:23:25 +0000575
Reid Klecknerdd2647e2014-04-30 20:34:31 +0000576 ~DwarfDebug() override;
577
Adrian Prantl857237e2015-07-13 18:25:29 +0000578 /// Emit all Dwarf sections that should come prior to the
Bill Wendling2f921f82009-05-15 09:23:25 +0000579 /// content.
Eric Christopher58f41952012-11-19 22:42:15 +0000580 void beginModule();
Bill Wendling2f921f82009-05-15 09:23:25 +0000581
Adrian Prantl857237e2015-07-13 18:25:29 +0000582 /// Emit all Dwarf sections that should come after the content.
Craig Topper7b883b32014-03-08 06:31:39 +0000583 void endModule() override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000584
Alexey Bataev9d5974a2019-01-22 17:24:16 +0000585 /// Emits inital debug location directive.
586 DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
587
Adrian Prantl857237e2015-07-13 18:25:29 +0000588 /// Process beginning of an instruction.
Craig Topper7b883b32014-03-08 06:31:39 +0000589 void beginInstruction(const MachineInstr *MI) override;
Bill Wendling2f921f82009-05-15 09:23:25 +0000590
Adrian Prantlee5feaf2015-07-15 17:01:41 +0000591 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
592 static uint64_t makeTypeSignature(StringRef Identifier);
593
Adrian Prantl857237e2015-07-13 18:25:29 +0000594 /// Add a DIE to the set of types that we're going to pull into
Eric Christopher67646432013-07-26 17:02:41 +0000595 /// type units.
David Blaikie15632ae2014-02-12 00:31:30 +0000596 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000597 DIE &Die, const DICompositeType *CTy);
Eric Christopher67646432013-07-26 17:02:41 +0000598
David Blaikie832c7d92019-04-24 18:09:44 +0000599 friend class NonTypeUnitContext;
600 class NonTypeUnitContext {
601 DwarfDebug *DD;
602 decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
603 friend class DwarfDebug;
604 NonTypeUnitContext(DwarfDebug *DD);
605 public:
606 NonTypeUnitContext(NonTypeUnitContext&&) = default;
607 ~NonTypeUnitContext();
608 };
609
610 NonTypeUnitContext enterNonTypeUnitContext();
611
Adrian Prantl857237e2015-07-13 18:25:29 +0000612 /// Add a label so that arange data can be generated for it.
Alexey Samsonov4436bf02013-10-03 08:54:43 +0000613 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
Richard Mitton21101b32013-09-19 23:21:01 +0000614
Adrian Prantl857237e2015-07-13 18:25:29 +0000615 /// For symbols that have a size designated (e.g. common symbols),
Richard Mitton089ed892013-09-23 17:56:20 +0000616 /// this tracks that size.
Craig Topper7b883b32014-03-08 06:31:39 +0000617 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
Eric Christophera5a79422013-12-09 23:32:48 +0000618 SymSize[Sym] = Size;
619 }
Richard Mitton089ed892013-09-23 17:56:20 +0000620
Paul Robinson43d1e452016-04-18 22:41:41 +0000621 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
622 /// If not, we still might emit certain cases.
623 bool useAllLinkageNames() const { return UseAllLinkageNames; }
Paul Robinson78046b42015-08-11 21:36:45 +0000624
Adrian Prantl857237e2015-07-13 18:25:29 +0000625 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
Paul Robinson78cc0822015-03-04 20:55:11 +0000626 /// standard DW_OP_form_tls_address opcode
627 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
628
Adrian Prantl6323ddf2016-05-17 21:07:16 +0000629 /// Returns whether to use the DWARF2 format for bitfields instyead of the
630 /// DWARF4 format.
631 bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
632
Alexey Bataev0d6aead2018-02-20 15:28:08 +0000633 /// Returns whether to use inline strings.
634 bool useInlineStrings() const { return UseInlineStrings; }
635
Alexey Bataev858a7dd2018-03-20 20:21:38 +0000636 /// Returns whether ranges section should be emitted.
637 bool useRangesSection() const { return UseRangesSection; }
638
Alexey Bataevbff36082018-03-23 13:35:54 +0000639 /// Returns whether to use sections as labels rather than temp symbols.
640 bool useSectionsAsReferences() const {
641 return UseSectionsAsReferences;
642 }
643
Alexey Bataev2a03d422018-06-29 14:23:28 +0000644 /// Returns whether .debug_loc section should be emitted.
645 bool useLocSection() const { return UseLocSection; }
646
Pavel Labathf9adc202018-07-20 12:59:05 +0000647 /// Returns whether to generate DWARF v4 type units.
648 bool generateTypeUnits() const { return GenerateTypeUnits; }
649
Eric Christopher55c51812012-11-21 00:03:31 +0000650 // Experimental DWARF5 features.
651
Pavel Labath6088c232018-04-04 14:42:14 +0000652 /// Returns what kind (if any) of accelerator tables to emit.
Pavel Labath0cc03062018-04-04 14:54:08 +0000653 AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
Eric Christopher55c51812012-11-21 00:03:31 +0000654
David Blaikiec53e18d2016-05-24 21:19:28 +0000655 bool useAppleExtensionAttributes() const {
656 return HasAppleExtensionAttributes;
657 }
658
Adrian Prantl857237e2015-07-13 18:25:29 +0000659 /// Returns whether or not to change the current debug info for the
Eric Christophercdf218d2012-12-10 19:51:21 +0000660 /// split dwarf proposal support.
Eric Christopher411bd592014-03-06 00:00:53 +0000661 bool useSplitDwarf() const { return HasSplitDwarf; }
Manman Renac8062b2013-07-02 23:40:10 +0000662
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000663 /// Returns whether to generate a string offsets table with (possibly shared)
664 /// contributions from each CU and type unit. This implies the use of
665 /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
666 /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
667 /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
668 /// monolithic string offsets table.
669 bool useSegmentedStringOffsetsTable() const {
670 return UseSegmentedStringOffsetsTable;
671 }
672
David Blaikie488393f2017-05-12 01:13:45 +0000673 bool shareAcrossDWOCUs() const;
674
Manman Renac8062b2013-07-02 23:40:10 +0000675 /// Returns the Dwarf Version.
Greg Claytone6543972016-11-23 23:30:37 +0000676 uint16_t getDwarfVersion() const;
Manman Ren60352032013-09-05 18:48:31 +0000677
Eric Christopher384f3fe2014-03-20 19:16:16 +0000678 /// Returns the previous CU that was being updated
679 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
David Blaikied0f10372014-09-09 23:13:01 +0000680 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
Eric Christopher384f3fe2014-03-20 19:16:16 +0000681
Eric Christopher4f17ee02014-03-08 00:29:41 +0000682 /// Returns the entries for the .debug_loc section.
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000683 const DebugLocStream &getDebugLocs() const { return DebugLocs; }
Eric Christopher4f17ee02014-03-08 00:29:41 +0000684
Adrian Prantl857237e2015-07-13 18:25:29 +0000685 /// Emit an entry for the debug loc section. This can be used to
Eric Christopher4f17ee02014-03-08 00:29:41 +0000686 /// handle an entry that's going to be emitted into the debug loc section.
Adrian Prantl92da14b2015-03-02 22:02:33 +0000687 void emitDebugLocEntry(ByteStreamer &Streamer,
Markus Lavinb86ce212019-03-19 13:16:28 +0000688 const DebugLocStream::Entry &Entry,
689 const DwarfCompileUnit *CU);
Eric Christopher4f17ee02014-03-08 00:29:41 +0000690
David Blaikie0e84adc2014-04-01 16:17:41 +0000691 /// Emit the location for a debug loc entry, including the size header.
Markus Lavinb86ce212019-03-19 13:16:28 +0000692 void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry,
693 const DwarfCompileUnit *CU);
David Blaikie0e84adc2014-04-01 16:17:41 +0000694
David Blaikie66cf14d2018-08-16 21:29:55 +0000695 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
696 DIE &Die);
David Blaikie2406a0622014-04-23 23:37:35 +0000697
David Blaikied75fb282014-04-23 21:20:10 +0000698 AddressPool &getAddressPool() { return AddrPool; }
David Blaikie2406a0622014-04-23 23:37:35 +0000699
David Blaikie66cf14d2018-08-16 21:29:55 +0000700 void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
David Blaikie0ee82b92014-04-24 00:53:32 +0000701
David Blaikie66cf14d2018-08-16 21:29:55 +0000702 void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
David Blaikieecf04152014-04-24 01:02:42 +0000703
David Blaikie66cf14d2018-08-16 21:29:55 +0000704 void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
705 const DIE &Die);
David Blaikie18d33752014-04-24 01:23:49 +0000706
David Blaikie66cf14d2018-08-16 21:29:55 +0000707 void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
708 char Flags);
David Blaikiecda2aa82014-10-04 16:24:00 +0000709
710 const MachineFunction *getCurrentFunction() const { return CurFn; }
David Blaikie9c65b132014-10-08 22:20:02 +0000711
Adrian Prantl857237e2015-07-13 18:25:29 +0000712 /// A helper function to check whether the DIE for a given Scope is
David Blaikie9c65b132014-10-08 22:20:02 +0000713 /// going to be null.
714 bool isLexicalScopeDIENull(LexicalScope *Scope);
David Blaikieb3cee2f2017-05-25 18:50:28 +0000715
Jonas Devlieghere294e6892017-11-15 10:57:05 +0000716 /// Find the matching DwarfCompileUnit for the given CU DIE.
717 DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
Pavel Labath6088c232018-04-04 14:42:14 +0000718 const DwarfCompileUnit *lookupCU(const DIE *Die) const {
719 return CUDieMap.lookup(Die);
720 }
Jonas Devlieghere294e6892017-11-15 10:57:05 +0000721
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000722 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
723 ///
724 /// Returns whether we are "tuning" for a given debugger.
725 /// @{
726 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
727 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
728 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
729 /// @}
David Blaikie60fddac2018-10-24 23:36:29 +0000730
731 void addSectionLabel(const MCSymbol *Sym);
732 const MCSymbol *getSectionLabel(const MCSection *S);
Devang Patelf6eeaeb2009-11-10 23:06:00 +0000733};
Bill Wendling2f921f82009-05-15 09:23:25 +0000734
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000735} // end namespace llvm
736
737#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H