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