Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===//
2
//
3
// 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
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file contains support for writing dwarf debug info into asm files.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
14
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
15
16
#include "AddressPool.h"
17
#include "DebugLocStream.h"
18
#include "DebugLocEntry.h"
19
#include "DwarfFile.h"
20
#include "llvm/ADT/ArrayRef.h"
21
#include "llvm/ADT/DenseMap.h"
22
#include "llvm/ADT/DenseSet.h"
23
#include "llvm/ADT/MapVector.h"
24
#include "llvm/ADT/STLExtras.h"
25
#include "llvm/ADT/SetVector.h"
26
#include "llvm/ADT/SmallPtrSet.h"
27
#include "llvm/ADT/SmallVector.h"
28
#include "llvm/ADT/StringMap.h"
29
#include "llvm/ADT/StringRef.h"
30
#include "llvm/BinaryFormat/Dwarf.h"
31
#include "llvm/CodeGen/AccelTable.h"
32
#include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
33
#include "llvm/CodeGen/DebugHandlerBase.h"
34
#include "llvm/CodeGen/MachineInstr.h"
35
#include "llvm/IR/DebugInfoMetadata.h"
36
#include "llvm/IR/DebugLoc.h"
37
#include "llvm/IR/Metadata.h"
38
#include "llvm/MC/MCDwarf.h"
39
#include "llvm/Support/Allocator.h"
40
#include "llvm/Target/TargetOptions.h"
41
#include <cassert>
42
#include <cstdint>
43
#include <limits>
44
#include <memory>
45
#include <utility>
46
#include <vector>
47
48
namespace llvm {
49
50
class AsmPrinter;
51
class ByteStreamer;
52
class DebugLocEntry;
53
class DIE;
54
class DwarfCompileUnit;
55
class DwarfExpression;
56
class DwarfTypeUnit;
57
class DwarfUnit;
58
class LexicalScope;
59
class MachineFunction;
60
class MCSection;
61
class MCSymbol;
62
class MDNode;
63
class Module;
64
65
//===----------------------------------------------------------------------===//
66
/// This class is defined as the common parent of DbgVariable and DbgLabel
67
/// such that it could levarage polymorphism to extract common code for
68
/// DbgVariable and DbgLabel.
69
class DbgEntity {
70
  const DINode *Entity;
71
  const DILocation *InlinedAt;
72
  DIE *TheDIE = nullptr;
73
  unsigned SubclassID;
74
75
public:
76
  enum DbgEntityKind {
77
    DbgVariableKind,
78
    DbgLabelKind
79
  };
80
81
  DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)
82
1.32k
    : Entity(N), InlinedAt(IA), SubclassID(ID) {}
83
1.32k
  virtual ~DbgEntity() {}
84
85
  /// Accessors.
86
  /// @{
87
14.5k
  const DINode *getEntity() const { return Entity; }
88
0
  const DILocation *getInlinedAt() const { return InlinedAt; }
89
2.68k
  DIE *getDIE() const { return TheDIE; }
90
1.21k
  unsigned getDbgEntityID() const { return SubclassID; }
91
  /// @}
92
93
1.32k
  void setDIE(DIE &D) { TheDIE = &D; }
94
95
0
  static bool classof(const DbgEntity *N) {
96
0
    switch (N->getDbgEntityID()) {
97
0
    default:
98
0
      return false;
99
0
    case DbgVariableKind:
100
0
    case DbgLabelKind:
101
0
      return true;
102
0
    }
103
0
  }
104
};
105
106
//===----------------------------------------------------------------------===//
107
/// This class is used to track local variable information.
108
///
109
/// Variables can be created from allocas, in which case they're generated from
110
/// the MMI table.  Such variables can have multiple expressions and frame
111
/// indices.
112
///
113
/// Variables can be created from \c DBG_VALUE instructions.  Those whose
114
/// location changes over time use \a DebugLocListIndex, while those with a
115
/// single location use \a ValueLoc and (optionally) a single entry of \a Expr.
116
///
117
/// Variables that have been optimized out use none of these fields.
118
class DbgVariable : public DbgEntity {
119
  /// Offset in DebugLocs.
120
  unsigned DebugLocListIndex = ~0u;
121
  /// Single value location description.
122
  std::unique_ptr<DbgValueLoc> ValueLoc = nullptr;
123
124
  struct FrameIndexExpr {
125
    int FI;
126
    const DIExpression *Expr;
127
  };
128
  mutable SmallVector<FrameIndexExpr, 1>
129
      FrameIndexExprs; /// Frame index + expression.
130
131
public:
132
  /// Construct a DbgVariable.
133
  ///
134
  /// Creates a variable without any DW_AT_location.  Call \a initializeMMI()
135
  /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
136
  DbgVariable(const DILocalVariable *V, const DILocation *IA)
137
1.31k
      : DbgEntity(V, IA, DbgVariableKind) {}
138
139
  /// Initialize from the MMI table.
140
520
  void initializeMMI(const DIExpression *E, int FI) {
141
520
    assert(FrameIndexExprs.empty() && "Already initialized?");
142
520
    assert(!ValueLoc.get() && "Already initialized?");
143
520
144
520
    assert((!E || E->isValid()) && "Expected valid expression");
145
520
    assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
146
520
147
520
    FrameIndexExprs.push_back({FI, E});
148
520
  }
149
150
  // Initialize variable's location.
151
27
  void initializeDbgValue(DbgValueLoc Value) {
152
27
    assert(FrameIndexExprs.empty() && "Already initialized?");
153
27
    assert(!ValueLoc && "Already initialized?");
154
27
    assert(!Value.getExpression()->isFragment() && "Fragments not supported.");
155
27
156
27
    ValueLoc = llvm::make_unique<DbgValueLoc>(Value);
157
27
    if (auto *E = ValueLoc->getExpression())
158
27
      if (E->getNumElements())
159
4
        FrameIndexExprs.push_back({0, E});
160
27
  }
161
162
  /// Initialize from a DBG_VALUE instruction.
163
  void initializeDbgValue(const MachineInstr *DbgValue);
164
165
  // Accessors.
166
13.2k
  const DILocalVariable *getVariable() const {
167
13.2k
    return cast<DILocalVariable>(getEntity());
168
13.2k
  }
169
170
60
  const DIExpression *getSingleExpression() const {
171
60
    assert(ValueLoc.get() && FrameIndexExprs.size() <= 1);
172
60
    return FrameIndexExprs.size() ? 
FrameIndexExprs[0].Expr21
:
nullptr39
;
173
60
  }
174
175
419
  void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
176
1.20k
  unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
177
1.20k
  StringRef getName() const { return getVariable()->getName(); }
178
783
  const DbgValueLoc *getValueLoc() const { return ValueLoc.get(); }
179
  /// Get the FI entries, sorted by fragment offset.
180
  ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
181
657
  bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
182
  void addMMIEntry(const DbgVariable &V);
183
184
  // Translate tag to proper Dwarf tag.
185
1.31k
  dwarf::Tag getTag() const {
186
1.31k
    // FIXME: Why don't we just infer this tag and store it all along?
187
1.31k
    if (getVariable()->isParameter())
188
789
      return dwarf::DW_TAG_formal_parameter;
189
523
190
523
    return dwarf::DW_TAG_variable;
191
523
  }
192
193
  /// Return true if DbgVariable is artificial.
194
1.18k
  bool isArtificial() const {
195
1.18k
    if (getVariable()->isArtificial())
196
163
      return true;
197
1.01k
    if (getType()->isArtificial())
198
8
      return true;
199
1.01k
    return false;
200
1.01k
  }
201
202
1.31k
  bool isObjectPointer() const {
203
1.31k
    if (getVariable()->isObjectPointer())
204
137
      return true;
205
1.17k
    if (getType()->isObjectPointer())
206
4
      return true;
207
1.17k
    return false;
208
1.17k
  }
209
210
84
  bool hasComplexAddress() const {
211
84
    assert(ValueLoc.get() && "Expected DBG_VALUE, not MMI variable");
212
84
    assert((FrameIndexExprs.empty() ||
213
84
            (FrameIndexExprs.size() == 1 &&
214
84
             FrameIndexExprs[0].Expr->getNumElements())) &&
215
84
           "Invalid Expr for DBG_VALUE");
216
84
    return !FrameIndexExprs.empty();
217
84
  }
218
219
  bool isBlockByrefVariable() const;
220
  const DIType *getType() const;
221
222
1.07k
  static bool classof(const DbgEntity *N) {
223
1.07k
    return N->getDbgEntityID() == DbgVariableKind;
224
1.07k
  }
225
};
226
227
//===----------------------------------------------------------------------===//
228
/// This class is used to track label information.
229
///
230
/// Labels are collected from \c DBG_LABEL instructions.
231
class DbgLabel : public DbgEntity {
232
  const MCSymbol *Sym;                  /// Symbol before DBG_LABEL instruction.
233
234
public:
235
  /// We need MCSymbol information to generate DW_AT_low_pc.
236
  DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
237
8
      : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
238
239
  /// Accessors.
240
  /// @{
241
22
  const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
242
7
  const MCSymbol *getSymbol() const { return Sym; }
243
244
7
  StringRef getName() const { return getLabel()->getName(); }
245
  /// @}
246
247
  /// Translate tag to proper Dwarf tag.
248
8
  dwarf::Tag getTag() const {
249
8
    return dwarf::DW_TAG_label;
250
8
  }
251
252
138
  static bool classof(const DbgEntity *N) {
253
138
    return N->getDbgEntityID() == DbgLabelKind;
254
138
  }
255
};
256
257
/// Helper used to pair up a symbol and its DWARF compile unit.
258
struct SymbolCU {
259
519k
  SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
260
261
  const MCSymbol *Sym;
262
  DwarfCompileUnit *CU;
263
};
264
265
/// The kind of accelerator tables we should emit.
266
enum class AccelTableKind {
267
  Default, ///< Platform default.
268
  None,    ///< None.
269
  Apple,   ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
270
  Dwarf,   ///< DWARF v5 .debug_names.
271
};
272
273
/// Collects and handles dwarf debug information.
274
class DwarfDebug : public DebugHandlerBase {
275
  /// All DIEValues are allocated through this allocator.
276
  BumpPtrAllocator DIEValueAllocator;
277
278
  /// Maps MDNode with its corresponding DwarfCompileUnit.
279
  MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
280
281
  /// Maps a CU DIE with its corresponding DwarfCompileUnit.
282
  DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
283
284
  /// List of all labels used in aranges generation.
285
  std::vector<SymbolCU> ArangeLabels;
286
287
  /// Size of each symbol emitted (for those symbols that have a specific size).
288
  DenseMap<const MCSymbol *, uint64_t> SymSize;
289
290
  /// Collection of abstract variables/labels.
291
  SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
292
293
  /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
294
  /// can refer to them in spite of insertions into this list.
295
  DebugLocStream DebugLocs;
296
297
  /// This is a collection of subprogram MDNodes that are processed to
298
  /// create DIEs.
299
  SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>,
300
            SmallPtrSet<const DISubprogram *, 16>>
301
      ProcessedSPNodes;
302
303
  /// If nonnull, stores the current machine function we're processing.
304
  const MachineFunction *CurFn = nullptr;
305
306
  /// If nonnull, stores the CU in which the previous subprogram was contained.
307
  const DwarfCompileUnit *PrevCU;
308
309
  /// As an optimization, there is no need to emit an entry in the directory
310
  /// table for the same directory as DW_AT_comp_dir.
311
  StringRef CompilationDir;
312
313
  /// Holder for the file specific debug information.
314
  DwarfFile InfoHolder;
315
316
  /// Holders for the various debug information flags that we might need to
317
  /// have exposed. See accessor functions below for description.
318
319
  /// Map from MDNodes for user-defined types to their type signatures. Also
320
  /// used to keep track of which types we have emitted type units for.
321
  DenseMap<const MDNode *, uint64_t> TypeSignatures;
322
323
  DenseMap<const MCSection *, const MCSymbol *> SectionLabels;
324
325
  SmallVector<
326
      std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
327
      TypeUnitsUnderConstruction;
328
329
  /// Whether to use the GNU TLS opcode (instead of the standard opcode).
330
  bool UseGNUTLSOpcode;
331
332
  /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
333
  bool UseDWARF2Bitfields;
334
335
  /// Whether to emit all linkage names, or just abstract subprograms.
336
  bool UseAllLinkageNames;
337
338
  /// Use inlined strings.
339
  bool UseInlineStrings = false;
340
341
  /// Allow emission of .debug_ranges section.
342
  bool UseRangesSection = true;
343
344
  /// True if the sections itself must be used as references and don't create
345
  /// temp symbols inside DWARF sections.
346
  bool UseSectionsAsReferences = false;
347
348
  ///Allow emission of the .debug_loc section.
349
  bool UseLocSection = true;
350
351
  /// Generate DWARF v4 type units.
352
  bool GenerateTypeUnits;
353
354
  /// DWARF5 Experimental Options
355
  /// @{
356
  AccelTableKind TheAccelTableKind;
357
  bool HasAppleExtensionAttributes;
358
  bool HasSplitDwarf;
359
360
  /// Whether to generate the DWARF v5 string offsets table.
361
  /// It consists of a series of contributions, each preceded by a header.
362
  /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
363
  /// a monolithic sequence of string offsets.
364
  bool UseSegmentedStringOffsetsTable;
365
366
  /// Separated Dwarf Variables
367
  /// In general these will all be for bits that are left in the
368
  /// original object file, rather than things that are meant
369
  /// to be in the .dwo sections.
370
371
  /// Holder for the skeleton information.
372
  DwarfFile SkeletonHolder;
373
374
  /// Store file names for type units under fission in a line table
375
  /// header that will be emitted into debug_line.dwo.
376
  // FIXME: replace this with a map from comp_dir to table so that we
377
  // can emit multiple tables during LTO each of which uses directory
378
  // 0, referencing the comp_dir of all the type units that use it.
379
  MCDwarfDwoLineTable SplitTypeUnitFileTable;
380
  /// @}
381
382
  /// True iff there are multiple CUs in this module.
383
  bool SingleCU;
384
  bool IsDarwin;
385
386
  AddressPool AddrPool;
387
388
  /// Accelerator tables.
389
  AccelTable<DWARF5AccelTableData> AccelDebugNames;
390
  AccelTable<AppleAccelTableOffsetData> AccelNames;
391
  AccelTable<AppleAccelTableOffsetData> AccelObjC;
392
  AccelTable<AppleAccelTableOffsetData> AccelNamespace;
393
  AccelTable<AppleAccelTableTypeData> AccelTypes;
394
395
  // Identify a debugger for "tuning" the debug info.
396
  DebuggerKind DebuggerTuning = DebuggerKind::Default;
397
398
  MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
399
400
968k
  const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
401
968k
    return InfoHolder.getUnits();
402
968k
  }
403
404
  using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
405
406
  void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
407
                                     const DINode *Node,
408
                                     const MDNode *Scope);
409
  void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
410
                                             const DINode *Node,
411
                                             const MDNode *Scope);
412
413
  DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
414
                                  LexicalScope &Scope,
415
                                  const DINode *Node,
416
                                  const DILocation *Location,
417
                                  const MCSymbol *Sym = nullptr);
418
419
  /// Construct a DIE for this abstract scope.
420
  void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
421
422
  /// Construct DIEs for call site entries describing the calls in \p MF.
423
  void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
424
                                  DIE &ScopeDIE, const MachineFunction &MF);
425
426
  template <typename DataT>
427
  void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
428
                        StringRef Name, const DIE &Die);
429
430
  void finishEntityDefinitions();
431
432
  void finishSubprogramDefinitions();
433
434
  /// Finish off debug information after all functions have been
435
  /// processed.
436
  void finalizeModuleInfo();
437
438
  /// Emit the debug info section.
439
  void emitDebugInfo();
440
441
  /// Emit the abbreviation section.
442
  void emitAbbreviations();
443
444
  /// Emit the string offsets table header.
445
  void emitStringOffsetsTableHeader();
446
447
  /// Emit a specified accelerator table.
448
  template <typename AccelTableT>
449
  void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
450
451
  /// Emit DWARF v5 accelerator table.
452
  void emitAccelDebugNames();
453
454
  /// Emit visible names into a hashed accelerator table section.
455
  void emitAccelNames();
456
457
  /// Emit objective C classes and categories into a hashed
458
  /// accelerator table section.
459
  void emitAccelObjC();
460
461
  /// Emit namespace dies into a hashed accelerator table.
462
  void emitAccelNamespaces();
463
464
  /// Emit type dies into a hashed accelerator table.
465
  void emitAccelTypes();
466
467
  /// Emit visible names and types into debug pubnames and pubtypes sections.
468
  void emitDebugPubSections();
469
470
  void emitDebugPubSection(bool GnuStyle, StringRef Name,
471
                           DwarfCompileUnit *TheU,
472
                           const StringMap<const DIE *> &Globals);
473
474
  /// Emit null-terminated strings into a debug str section.
475
  void emitDebugStr();
476
477
  /// Emit variable locations into a debug loc section.
478
  void emitDebugLoc();
479
480
  /// Emit variable locations into a debug loc dwo section.
481
  void emitDebugLocDWO();
482
483
  /// Emit address ranges into a debug aranges section.
484
  void emitDebugARanges();
485
486
  /// Emit address ranges into a debug ranges section.
487
  void emitDebugRanges();
488
  void emitDebugRangesDWO();
489
490
  /// Emit macros into a debug macinfo section.
491
  void emitDebugMacinfo();
492
  void emitMacro(DIMacro &M);
493
  void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
494
  void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
495
496
  /// DWARF 5 Experimental Split Dwarf Emitters
497
498
  /// Initialize common features of skeleton units.
499
  void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
500
                        std::unique_ptr<DwarfCompileUnit> NewU);
501
502
  /// Construct the split debug info compile unit for the debug info section.
503
  /// In DWARF v5, the skeleton unit DIE may have the following attributes:
504
  /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
505
  /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
506
  /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
507
  /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
508
  /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
509
  DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
510
511
  /// Emit the debug info dwo section.
512
  void emitDebugInfoDWO();
513
514
  /// Emit the debug abbrev dwo section.
515
  void emitDebugAbbrevDWO();
516
517
  /// Emit the debug line dwo section.
518
  void emitDebugLineDWO();
519
520
  /// Emit the dwo stringoffsets table header.
521
  void emitStringOffsetsTableHeaderDWO();
522
523
  /// Emit the debug str dwo section.
524
  void emitDebugStrDWO();
525
526
  /// Emit DWO addresses.
527
  void emitDebugAddr();
528
529
  /// Flags to let the linker know we have emitted new style pubnames. Only
530
  /// emit it here if we don't have a skeleton CU for split dwarf.
531
  void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
532
533
  /// Create new DwarfCompileUnit for the given metadata node with tag
534
  /// DW_TAG_compile_unit.
535
  DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
536
  void finishUnitAttributes(const DICompileUnit *DIUnit,
537
                            DwarfCompileUnit &NewCU);
538
539
  /// Construct imported_module or imported_declaration DIE.
540
  void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
541
                                        const DIImportedEntity *N);
542
543
  /// Register a source line with debug info. Returns the unique
544
  /// label that was emitted and which provides correspondence to the
545
  /// source line list.
546
  void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
547
                        unsigned Flags);
548
549
  /// Populate LexicalScope entries with variables' info.
550
  void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
551
                         DenseSet<InlinedEntity> &ProcessedVars);
552
553
  /// Build the location list for all DBG_VALUEs in the
554
  /// function that describe the same variable. If the resulting 
555
  /// list has only one entry that is valid for entire variable's
556
  /// scope return true.
557
  bool buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
558
                         const DbgValueHistoryMap::Entries &Entries);
559
560
  /// Collect variable information from the side table maintained by MF.
561
  void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
562
                                      DenseSet<InlinedEntity> &P);
563
564
  /// Emit the reference to the section.
565
  void emitSectionReference(const DwarfCompileUnit &CU);
566
567
protected:
568
  /// Gather pre-function debug information.
569
  void beginFunctionImpl(const MachineFunction *MF) override;
570
571
  /// Gather and emit post-function debug information.
572
  void endFunctionImpl(const MachineFunction *MF) override;
573
574
  void skippedNonDebugFunction() override;
575
576
public:
577
  //===--------------------------------------------------------------------===//
578
  // Main entry points.
579
  //
580
  DwarfDebug(AsmPrinter *A, Module *M);
581
582
  ~DwarfDebug() override;
583
584
  /// Emit all Dwarf sections that should come prior to the
585
  /// content.
586
  void beginModule();
587
588
  /// Emit all Dwarf sections that should come after the content.
589
  void endModule() override;
590
591
  /// Emits inital debug location directive.
592
  DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
593
594
  /// Process beginning of an instruction.
595
  void beginInstruction(const MachineInstr *MI) override;
596
597
  /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
598
  static uint64_t makeTypeSignature(StringRef Identifier);
599
600
  /// Add a DIE to the set of types that we're going to pull into
601
  /// type units.
602
  void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
603
                            DIE &Die, const DICompositeType *CTy);
604
605
  friend class NonTypeUnitContext;
606
  class NonTypeUnitContext {
607
    DwarfDebug *DD;
608
    decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
609
    friend class DwarfDebug;
610
    NonTypeUnitContext(DwarfDebug *DD);
611
  public:
612
    NonTypeUnitContext(NonTypeUnitContext&&) = default;
613
    ~NonTypeUnitContext();
614
  };
615
616
  NonTypeUnitContext enterNonTypeUnitContext();
617
618
  /// Add a label so that arange data can be generated for it.
619
519k
  void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
620
621
  /// For symbols that have a size designated (e.g. common symbols),
622
  /// this tracks that size.
623
428k
  void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
624
428k
    SymSize[Sym] = Size;
625
428k
  }
626
627
  /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
628
  /// If not, we still might emit certain cases.
629
3.28k
  bool useAllLinkageNames() const { return UseAllLinkageNames; }
630
631
  /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
632
  /// standard DW_OP_form_tls_address opcode
633
34
  bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
634
635
  /// Returns whether to use the DWARF2 format for bitfields instyead of the
636
  /// DWARF4 format.
637
99
  bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
638
639
  /// Returns whether to use inline strings.
640
103k
  bool useInlineStrings() const { return UseInlineStrings; }
641
642
  /// Returns whether ranges section should be emitted.
643
57.0k
  bool useRangesSection() const { return UseRangesSection; }
644
645
  /// Returns whether to use sections as labels rather than temp symbols.
646
11.5k
  bool useSectionsAsReferences() const {
647
11.5k
    return UseSectionsAsReferences;
648
11.5k
  }
649
650
  /// Returns whether .debug_loc section should be emitted.
651
512
  bool useLocSection() const { return UseLocSection; }
652
653
  /// Returns whether to generate DWARF v4 type units.
654
11.0k
  bool generateTypeUnits() const { return GenerateTypeUnits; }
655
656
  // Experimental DWARF5 features.
657
658
  /// Returns what kind (if any) of accelerator tables to emit.
659
1.27M
  AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
660
661
39.4k
  bool useAppleExtensionAttributes() const {
662
39.4k
    return HasAppleExtensionAttributes;
663
39.4k
  }
664
665
  /// Returns whether or not to change the current debug info for the
666
  /// split dwarf proposal support.
667
1.81M
  bool useSplitDwarf() const { return HasSplitDwarf; }
668
669
  /// Returns whether to generate a string offsets table with (possibly shared)
670
  /// contributions from each CU and type unit. This implies the use of
671
  /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
672
  /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
673
  /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
674
  /// monolithic string offsets table.
675
248k
  bool useSegmentedStringOffsetsTable() const {
676
248k
    return UseSegmentedStringOffsetsTable;
677
248k
  }
678
679
  bool shareAcrossDWOCUs() const;
680
681
  /// Returns the Dwarf Version.
682
  uint16_t getDwarfVersion() const;
683
684
  /// Returns the previous CU that was being updated
685
35.3k
  const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
686
35.3k
  void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
687
688
  /// Returns the entries for the .debug_loc section.
689
422
  const DebugLocStream &getDebugLocs() const { return DebugLocs; }
690
691
  /// Emit an entry for the debug loc section. This can be used to
692
  /// handle an entry that's going to be emitted into the debug loc section.
693
  void emitDebugLocEntry(ByteStreamer &Streamer,
694
                         const DebugLocStream::Entry &Entry,
695
                         const DwarfCompileUnit *CU);
696
697
  /// Emit the location for a debug loc entry, including the size header.
698
  void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry,
699
                                 const DwarfCompileUnit *CU);
700
701
  void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
702
                          DIE &Die);
703
704
341
  AddressPool &getAddressPool() { return AddrPool; }
705
706
  void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
707
708
  void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
709
710
  void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
711
                         const DIE &Die);
712
713
  void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
714
                    char Flags);
715
716
69.6k
  const MachineFunction *getCurrentFunction() const { return CurFn; }
717
718
  /// A helper function to check whether the DIE for a given Scope is
719
  /// going to be null.
720
  bool isLexicalScopeDIENull(LexicalScope *Scope);
721
722
  /// Find the matching DwarfCompileUnit for the given CU DIE.
723
73
  DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
724
275
  const DwarfCompileUnit *lookupCU(const DIE *Die) const {
725
275
    return CUDieMap.lookup(Die);
726
275
  }
727
728
  /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
729
  ///
730
  /// Returns whether we are "tuning" for a given debugger.
731
  /// @{
732
74.6k
  bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
733
35.7k
  bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
734
35.7k
  bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
735
  /// @}
736
737
  void addSectionLabel(const MCSymbol *Sym);
738
  const MCSymbol *getSectionLabel(const MCSection *S);
739
740
  static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
741
                                const DbgValueLoc &Value,
742
                                DwarfExpression &DwarfExpr);
743
};
744
745
} // end namespace llvm
746
747
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H