xref: /freebsd/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric //===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains support for writing dwarf debug info into asm files.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
140b57cec5SDimitry Andric #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "AddressPool.h"
170b57cec5SDimitry Andric #include "DebugLocStream.h"
180b57cec5SDimitry Andric #include "DebugLocEntry.h"
190b57cec5SDimitry Andric #include "DwarfFile.h"
200b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
210b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h"
220b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h"
230b57cec5SDimitry Andric #include "llvm/ADT/MapVector.h"
240b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h"
250b57cec5SDimitry Andric #include "llvm/ADT/SetVector.h"
260b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h"
270b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
280b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
290b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
300b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
310b57cec5SDimitry Andric #include "llvm/CodeGen/AccelTable.h"
320b57cec5SDimitry Andric #include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
330b57cec5SDimitry Andric #include "llvm/CodeGen/DebugHandlerBase.h"
340b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstr.h"
350b57cec5SDimitry Andric #include "llvm/IR/DebugInfoMetadata.h"
360b57cec5SDimitry Andric #include "llvm/IR/DebugLoc.h"
370b57cec5SDimitry Andric #include "llvm/IR/Metadata.h"
380b57cec5SDimitry Andric #include "llvm/MC/MCDwarf.h"
390b57cec5SDimitry Andric #include "llvm/Support/Allocator.h"
400b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.h"
410b57cec5SDimitry Andric #include <cassert>
420b57cec5SDimitry Andric #include <cstdint>
430b57cec5SDimitry Andric #include <limits>
440b57cec5SDimitry Andric #include <memory>
450b57cec5SDimitry Andric #include <utility>
460b57cec5SDimitry Andric #include <vector>
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric namespace llvm {
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric class AsmPrinter;
510b57cec5SDimitry Andric class ByteStreamer;
520b57cec5SDimitry Andric class DIE;
530b57cec5SDimitry Andric class DwarfCompileUnit;
540b57cec5SDimitry Andric class DwarfExpression;
550b57cec5SDimitry Andric class DwarfTypeUnit;
560b57cec5SDimitry Andric class DwarfUnit;
570b57cec5SDimitry Andric class LexicalScope;
580b57cec5SDimitry Andric class MachineFunction;
590b57cec5SDimitry Andric class MCSection;
600b57cec5SDimitry Andric class MCSymbol;
610b57cec5SDimitry Andric class Module;
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
640b57cec5SDimitry Andric /// This class is defined as the common parent of DbgVariable and DbgLabel
650b57cec5SDimitry Andric /// such that it could levarage polymorphism to extract common code for
660b57cec5SDimitry Andric /// DbgVariable and DbgLabel.
670b57cec5SDimitry Andric class DbgEntity {
680b57cec5SDimitry Andric   const DINode *Entity;
690b57cec5SDimitry Andric   const DILocation *InlinedAt;
700b57cec5SDimitry Andric   DIE *TheDIE = nullptr;
710b57cec5SDimitry Andric   unsigned SubclassID;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric public:
740b57cec5SDimitry Andric   enum DbgEntityKind {
750b57cec5SDimitry Andric     DbgVariableKind,
760b57cec5SDimitry Andric     DbgLabelKind
770b57cec5SDimitry Andric   };
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)
800b57cec5SDimitry Andric     : Entity(N), InlinedAt(IA), SubclassID(ID) {}
810b57cec5SDimitry Andric   virtual ~DbgEntity() {}
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   /// Accessors.
840b57cec5SDimitry Andric   /// @{
850b57cec5SDimitry Andric   const DINode *getEntity() const { return Entity; }
860b57cec5SDimitry Andric   const DILocation *getInlinedAt() const { return InlinedAt; }
870b57cec5SDimitry Andric   DIE *getDIE() const { return TheDIE; }
880b57cec5SDimitry Andric   unsigned getDbgEntityID() const { return SubclassID; }
890b57cec5SDimitry Andric   /// @}
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric   void setDIE(DIE &D) { TheDIE = &D; }
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   static bool classof(const DbgEntity *N) {
940b57cec5SDimitry Andric     switch (N->getDbgEntityID()) {
950b57cec5SDimitry Andric     default:
960b57cec5SDimitry Andric       return false;
970b57cec5SDimitry Andric     case DbgVariableKind:
980b57cec5SDimitry Andric     case DbgLabelKind:
990b57cec5SDimitry Andric       return true;
1000b57cec5SDimitry Andric     }
1010b57cec5SDimitry Andric   }
1020b57cec5SDimitry Andric };
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
1050b57cec5SDimitry Andric /// This class is used to track local variable information.
1060b57cec5SDimitry Andric ///
1070b57cec5SDimitry Andric /// Variables can be created from allocas, in which case they're generated from
1080b57cec5SDimitry Andric /// the MMI table.  Such variables can have multiple expressions and frame
1090b57cec5SDimitry Andric /// indices.
1100b57cec5SDimitry Andric ///
1110b57cec5SDimitry Andric /// Variables can be created from \c DBG_VALUE instructions.  Those whose
1120b57cec5SDimitry Andric /// location changes over time use \a DebugLocListIndex, while those with a
1130b57cec5SDimitry Andric /// single location use \a ValueLoc and (optionally) a single entry of \a Expr.
1140b57cec5SDimitry Andric ///
1150b57cec5SDimitry Andric /// Variables that have been optimized out use none of these fields.
1160b57cec5SDimitry Andric class DbgVariable : public DbgEntity {
117e8d8bef9SDimitry Andric   /// Index of the entry list in DebugLocs.
1180b57cec5SDimitry Andric   unsigned DebugLocListIndex = ~0u;
119480093f4SDimitry Andric   /// DW_OP_LLVM_tag_offset value from DebugLocs.
120480093f4SDimitry Andric   Optional<uint8_t> DebugLocListTagOffset;
121480093f4SDimitry Andric 
1220b57cec5SDimitry Andric   /// Single value location description.
1230b57cec5SDimitry Andric   std::unique_ptr<DbgValueLoc> ValueLoc = nullptr;
1240b57cec5SDimitry Andric 
1250b57cec5SDimitry Andric   struct FrameIndexExpr {
1260b57cec5SDimitry Andric     int FI;
1270b57cec5SDimitry Andric     const DIExpression *Expr;
1280b57cec5SDimitry Andric   };
1290b57cec5SDimitry Andric   mutable SmallVector<FrameIndexExpr, 1>
1300b57cec5SDimitry Andric       FrameIndexExprs; /// Frame index + expression.
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric public:
1330b57cec5SDimitry Andric   /// Construct a DbgVariable.
1340b57cec5SDimitry Andric   ///
1350b57cec5SDimitry Andric   /// Creates a variable without any DW_AT_location.  Call \a initializeMMI()
1360b57cec5SDimitry Andric   /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
1370b57cec5SDimitry Andric   DbgVariable(const DILocalVariable *V, const DILocation *IA)
1380b57cec5SDimitry Andric       : DbgEntity(V, IA, DbgVariableKind) {}
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric   /// Initialize from the MMI table.
1410b57cec5SDimitry Andric   void initializeMMI(const DIExpression *E, int FI) {
1420b57cec5SDimitry Andric     assert(FrameIndexExprs.empty() && "Already initialized?");
1430b57cec5SDimitry Andric     assert(!ValueLoc.get() && "Already initialized?");
1440b57cec5SDimitry Andric 
1450b57cec5SDimitry Andric     assert((!E || E->isValid()) && "Expected valid expression");
1460b57cec5SDimitry Andric     assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
1470b57cec5SDimitry Andric 
1480b57cec5SDimitry Andric     FrameIndexExprs.push_back({FI, E});
1490b57cec5SDimitry Andric   }
1500b57cec5SDimitry Andric 
1510b57cec5SDimitry Andric   // Initialize variable's location.
1520b57cec5SDimitry Andric   void initializeDbgValue(DbgValueLoc Value) {
1530b57cec5SDimitry Andric     assert(FrameIndexExprs.empty() && "Already initialized?");
1540b57cec5SDimitry Andric     assert(!ValueLoc && "Already initialized?");
1550b57cec5SDimitry Andric     assert(!Value.getExpression()->isFragment() && "Fragments not supported.");
1560b57cec5SDimitry Andric 
1578bcb0991SDimitry Andric     ValueLoc = std::make_unique<DbgValueLoc>(Value);
1580b57cec5SDimitry Andric     if (auto *E = ValueLoc->getExpression())
1590b57cec5SDimitry Andric       if (E->getNumElements())
1600b57cec5SDimitry Andric         FrameIndexExprs.push_back({0, E});
1610b57cec5SDimitry Andric   }
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   /// Initialize from a DBG_VALUE instruction.
1640b57cec5SDimitry Andric   void initializeDbgValue(const MachineInstr *DbgValue);
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric   // Accessors.
1670b57cec5SDimitry Andric   const DILocalVariable *getVariable() const {
1680b57cec5SDimitry Andric     return cast<DILocalVariable>(getEntity());
1690b57cec5SDimitry Andric   }
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric   const DIExpression *getSingleExpression() const {
1720b57cec5SDimitry Andric     assert(ValueLoc.get() && FrameIndexExprs.size() <= 1);
1730b57cec5SDimitry Andric     return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;
1740b57cec5SDimitry Andric   }
1750b57cec5SDimitry Andric 
1760b57cec5SDimitry Andric   void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
1770b57cec5SDimitry Andric   unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
178480093f4SDimitry Andric   void setDebugLocListTagOffset(uint8_t O) { DebugLocListTagOffset = O; }
179480093f4SDimitry Andric   Optional<uint8_t> getDebugLocListTagOffset() const { return DebugLocListTagOffset; }
1800b57cec5SDimitry Andric   StringRef getName() const { return getVariable()->getName(); }
1810b57cec5SDimitry Andric   const DbgValueLoc *getValueLoc() const { return ValueLoc.get(); }
1820b57cec5SDimitry Andric   /// Get the FI entries, sorted by fragment offset.
1830b57cec5SDimitry Andric   ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
1840b57cec5SDimitry Andric   bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
1850b57cec5SDimitry Andric   void addMMIEntry(const DbgVariable &V);
1860b57cec5SDimitry Andric 
1870b57cec5SDimitry Andric   // Translate tag to proper Dwarf tag.
1880b57cec5SDimitry Andric   dwarf::Tag getTag() const {
1890b57cec5SDimitry Andric     // FIXME: Why don't we just infer this tag and store it all along?
1900b57cec5SDimitry Andric     if (getVariable()->isParameter())
1910b57cec5SDimitry Andric       return dwarf::DW_TAG_formal_parameter;
1920b57cec5SDimitry Andric 
1930b57cec5SDimitry Andric     return dwarf::DW_TAG_variable;
1940b57cec5SDimitry Andric   }
1950b57cec5SDimitry Andric 
1960b57cec5SDimitry Andric   /// Return true if DbgVariable is artificial.
1970b57cec5SDimitry Andric   bool isArtificial() const {
1980b57cec5SDimitry Andric     if (getVariable()->isArtificial())
1990b57cec5SDimitry Andric       return true;
2000b57cec5SDimitry Andric     if (getType()->isArtificial())
2010b57cec5SDimitry Andric       return true;
2020b57cec5SDimitry Andric     return false;
2030b57cec5SDimitry Andric   }
2040b57cec5SDimitry Andric 
2050b57cec5SDimitry Andric   bool isObjectPointer() const {
2060b57cec5SDimitry Andric     if (getVariable()->isObjectPointer())
2070b57cec5SDimitry Andric       return true;
2080b57cec5SDimitry Andric     if (getType()->isObjectPointer())
2090b57cec5SDimitry Andric       return true;
2100b57cec5SDimitry Andric     return false;
2110b57cec5SDimitry Andric   }
2120b57cec5SDimitry Andric 
2130b57cec5SDimitry Andric   bool hasComplexAddress() const {
2140b57cec5SDimitry Andric     assert(ValueLoc.get() && "Expected DBG_VALUE, not MMI variable");
2150b57cec5SDimitry Andric     assert((FrameIndexExprs.empty() ||
2160b57cec5SDimitry Andric             (FrameIndexExprs.size() == 1 &&
2170b57cec5SDimitry Andric              FrameIndexExprs[0].Expr->getNumElements())) &&
2180b57cec5SDimitry Andric            "Invalid Expr for DBG_VALUE");
2190b57cec5SDimitry Andric     return !FrameIndexExprs.empty();
2200b57cec5SDimitry Andric   }
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric   const DIType *getType() const;
2230b57cec5SDimitry Andric 
2240b57cec5SDimitry Andric   static bool classof(const DbgEntity *N) {
2250b57cec5SDimitry Andric     return N->getDbgEntityID() == DbgVariableKind;
2260b57cec5SDimitry Andric   }
2270b57cec5SDimitry Andric };
2280b57cec5SDimitry Andric 
2290b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
2300b57cec5SDimitry Andric /// This class is used to track label information.
2310b57cec5SDimitry Andric ///
2320b57cec5SDimitry Andric /// Labels are collected from \c DBG_LABEL instructions.
2330b57cec5SDimitry Andric class DbgLabel : public DbgEntity {
2340b57cec5SDimitry Andric   const MCSymbol *Sym;                  /// Symbol before DBG_LABEL instruction.
2350b57cec5SDimitry Andric 
2360b57cec5SDimitry Andric public:
2370b57cec5SDimitry Andric   /// We need MCSymbol information to generate DW_AT_low_pc.
2380b57cec5SDimitry Andric   DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
2390b57cec5SDimitry Andric       : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric   /// Accessors.
2420b57cec5SDimitry Andric   /// @{
2430b57cec5SDimitry Andric   const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
2440b57cec5SDimitry Andric   const MCSymbol *getSymbol() const { return Sym; }
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric   StringRef getName() const { return getLabel()->getName(); }
2470b57cec5SDimitry Andric   /// @}
2480b57cec5SDimitry Andric 
2490b57cec5SDimitry Andric   /// Translate tag to proper Dwarf tag.
2500b57cec5SDimitry Andric   dwarf::Tag getTag() const {
2510b57cec5SDimitry Andric     return dwarf::DW_TAG_label;
2520b57cec5SDimitry Andric   }
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric   static bool classof(const DbgEntity *N) {
2550b57cec5SDimitry Andric     return N->getDbgEntityID() == DbgLabelKind;
2560b57cec5SDimitry Andric   }
2570b57cec5SDimitry Andric };
2580b57cec5SDimitry Andric 
2598bcb0991SDimitry Andric /// Used for tracking debug info about call site parameters.
2608bcb0991SDimitry Andric class DbgCallSiteParam {
2618bcb0991SDimitry Andric private:
2628bcb0991SDimitry Andric   unsigned Register; ///< Parameter register at the callee entry point.
2638bcb0991SDimitry Andric   DbgValueLoc Value; ///< Corresponding location for the parameter value at
2648bcb0991SDimitry Andric                      ///< the call site.
2658bcb0991SDimitry Andric public:
2668bcb0991SDimitry Andric   DbgCallSiteParam(unsigned Reg, DbgValueLoc Val)
2678bcb0991SDimitry Andric       : Register(Reg), Value(Val) {
2688bcb0991SDimitry Andric     assert(Reg && "Parameter register cannot be undef");
2698bcb0991SDimitry Andric   }
2708bcb0991SDimitry Andric 
2718bcb0991SDimitry Andric   unsigned getRegister() const { return Register; }
2728bcb0991SDimitry Andric   DbgValueLoc getValue() const { return Value; }
2738bcb0991SDimitry Andric };
2748bcb0991SDimitry Andric 
2758bcb0991SDimitry Andric /// Collection used for storing debug call site parameters.
2768bcb0991SDimitry Andric using ParamSet = SmallVector<DbgCallSiteParam, 4>;
2778bcb0991SDimitry Andric 
2780b57cec5SDimitry Andric /// Helper used to pair up a symbol and its DWARF compile unit.
2790b57cec5SDimitry Andric struct SymbolCU {
2800b57cec5SDimitry Andric   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
2810b57cec5SDimitry Andric 
2820b57cec5SDimitry Andric   const MCSymbol *Sym;
2830b57cec5SDimitry Andric   DwarfCompileUnit *CU;
2840b57cec5SDimitry Andric };
2850b57cec5SDimitry Andric 
2860b57cec5SDimitry Andric /// The kind of accelerator tables we should emit.
2870b57cec5SDimitry Andric enum class AccelTableKind {
2880b57cec5SDimitry Andric   Default, ///< Platform default.
2890b57cec5SDimitry Andric   None,    ///< None.
2900b57cec5SDimitry Andric   Apple,   ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
2910b57cec5SDimitry Andric   Dwarf,   ///< DWARF v5 .debug_names.
2920b57cec5SDimitry Andric };
2930b57cec5SDimitry Andric 
2940b57cec5SDimitry Andric /// Collects and handles dwarf debug information.
2950b57cec5SDimitry Andric class DwarfDebug : public DebugHandlerBase {
2960b57cec5SDimitry Andric   /// All DIEValues are allocated through this allocator.
2970b57cec5SDimitry Andric   BumpPtrAllocator DIEValueAllocator;
2980b57cec5SDimitry Andric 
2990b57cec5SDimitry Andric   /// Maps MDNode with its corresponding DwarfCompileUnit.
3000b57cec5SDimitry Andric   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
3010b57cec5SDimitry Andric 
3020b57cec5SDimitry Andric   /// Maps a CU DIE with its corresponding DwarfCompileUnit.
3030b57cec5SDimitry Andric   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
3040b57cec5SDimitry Andric 
3050b57cec5SDimitry Andric   /// List of all labels used in aranges generation.
3060b57cec5SDimitry Andric   std::vector<SymbolCU> ArangeLabels;
3070b57cec5SDimitry Andric 
3080b57cec5SDimitry Andric   /// Size of each symbol emitted (for those symbols that have a specific size).
3090b57cec5SDimitry Andric   DenseMap<const MCSymbol *, uint64_t> SymSize;
3100b57cec5SDimitry Andric 
3110b57cec5SDimitry Andric   /// Collection of abstract variables/labels.
3120b57cec5SDimitry Andric   SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
3130b57cec5SDimitry Andric 
3140b57cec5SDimitry Andric   /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
3150b57cec5SDimitry Andric   /// can refer to them in spite of insertions into this list.
3160b57cec5SDimitry Andric   DebugLocStream DebugLocs;
3170b57cec5SDimitry Andric 
3180b57cec5SDimitry Andric   /// This is a collection of subprogram MDNodes that are processed to
3190b57cec5SDimitry Andric   /// create DIEs.
3200b57cec5SDimitry Andric   SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>,
3210b57cec5SDimitry Andric             SmallPtrSet<const DISubprogram *, 16>>
3220b57cec5SDimitry Andric       ProcessedSPNodes;
3230b57cec5SDimitry Andric 
3240b57cec5SDimitry Andric   /// If nonnull, stores the current machine function we're processing.
3250b57cec5SDimitry Andric   const MachineFunction *CurFn = nullptr;
3260b57cec5SDimitry Andric 
3270b57cec5SDimitry Andric   /// If nonnull, stores the CU in which the previous subprogram was contained.
3285ffd83dbSDimitry Andric   const DwarfCompileUnit *PrevCU = nullptr;
3290b57cec5SDimitry Andric 
3300b57cec5SDimitry Andric   /// As an optimization, there is no need to emit an entry in the directory
3310b57cec5SDimitry Andric   /// table for the same directory as DW_AT_comp_dir.
3320b57cec5SDimitry Andric   StringRef CompilationDir;
3330b57cec5SDimitry Andric 
3340b57cec5SDimitry Andric   /// Holder for the file specific debug information.
3350b57cec5SDimitry Andric   DwarfFile InfoHolder;
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric   /// Holders for the various debug information flags that we might need to
3380b57cec5SDimitry Andric   /// have exposed. See accessor functions below for description.
3390b57cec5SDimitry Andric 
3400b57cec5SDimitry Andric   /// Map from MDNodes for user-defined types to their type signatures. Also
3410b57cec5SDimitry Andric   /// used to keep track of which types we have emitted type units for.
3420b57cec5SDimitry Andric   DenseMap<const MDNode *, uint64_t> TypeSignatures;
3430b57cec5SDimitry Andric 
3440b57cec5SDimitry Andric   DenseMap<const MCSection *, const MCSymbol *> SectionLabels;
3450b57cec5SDimitry Andric 
3460b57cec5SDimitry Andric   SmallVector<
3470b57cec5SDimitry Andric       std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
3480b57cec5SDimitry Andric       TypeUnitsUnderConstruction;
3490b57cec5SDimitry Andric 
3500b57cec5SDimitry Andric   /// Whether to use the GNU TLS opcode (instead of the standard opcode).
3510b57cec5SDimitry Andric   bool UseGNUTLSOpcode;
3520b57cec5SDimitry Andric 
3530b57cec5SDimitry Andric   /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
3540b57cec5SDimitry Andric   bool UseDWARF2Bitfields;
3550b57cec5SDimitry Andric 
3560b57cec5SDimitry Andric   /// Whether to emit all linkage names, or just abstract subprograms.
3570b57cec5SDimitry Andric   bool UseAllLinkageNames;
3580b57cec5SDimitry Andric 
3590b57cec5SDimitry Andric   /// Use inlined strings.
3600b57cec5SDimitry Andric   bool UseInlineStrings = false;
3610b57cec5SDimitry Andric 
3620b57cec5SDimitry Andric   /// Allow emission of .debug_ranges section.
3630b57cec5SDimitry Andric   bool UseRangesSection = true;
3640b57cec5SDimitry Andric 
3650b57cec5SDimitry Andric   /// True if the sections itself must be used as references and don't create
3660b57cec5SDimitry Andric   /// temp symbols inside DWARF sections.
3670b57cec5SDimitry Andric   bool UseSectionsAsReferences = false;
3680b57cec5SDimitry Andric 
3690b57cec5SDimitry Andric   ///Allow emission of the .debug_loc section.
3700b57cec5SDimitry Andric   bool UseLocSection = true;
3710b57cec5SDimitry Andric 
3720b57cec5SDimitry Andric   /// Generate DWARF v4 type units.
3730b57cec5SDimitry Andric   bool GenerateTypeUnits;
3740b57cec5SDimitry Andric 
375e8d8bef9SDimitry Andric   /// Emit a .debug_macro section instead of .debug_macinfo.
376e8d8bef9SDimitry Andric   bool UseDebugMacroSection;
377e8d8bef9SDimitry Andric 
378e8d8bef9SDimitry Andric   /// Avoid using DW_OP_convert due to consumer incompatibilities.
379e8d8bef9SDimitry Andric   bool EnableOpConvert;
380e8d8bef9SDimitry Andric 
381e8d8bef9SDimitry Andric public:
382e8d8bef9SDimitry Andric   enum class MinimizeAddrInV5 {
383e8d8bef9SDimitry Andric     Default,
384e8d8bef9SDimitry Andric     Disabled,
385e8d8bef9SDimitry Andric     Ranges,
386*fe6060f1SDimitry Andric     Expressions,
387*fe6060f1SDimitry Andric     Form,
388e8d8bef9SDimitry Andric   };
389e8d8bef9SDimitry Andric 
390e8d8bef9SDimitry Andric private:
391e8d8bef9SDimitry Andric   /// Force the use of DW_AT_ranges even for single-entry range lists.
392e8d8bef9SDimitry Andric   MinimizeAddrInV5 MinimizeAddr = MinimizeAddrInV5::Disabled;
393e8d8bef9SDimitry Andric 
3940b57cec5SDimitry Andric   /// DWARF5 Experimental Options
3950b57cec5SDimitry Andric   /// @{
3960b57cec5SDimitry Andric   AccelTableKind TheAccelTableKind;
3970b57cec5SDimitry Andric   bool HasAppleExtensionAttributes;
3980b57cec5SDimitry Andric   bool HasSplitDwarf;
3990b57cec5SDimitry Andric 
4000b57cec5SDimitry Andric   /// Whether to generate the DWARF v5 string offsets table.
4010b57cec5SDimitry Andric   /// It consists of a series of contributions, each preceded by a header.
4020b57cec5SDimitry Andric   /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
4030b57cec5SDimitry Andric   /// a monolithic sequence of string offsets.
4040b57cec5SDimitry Andric   bool UseSegmentedStringOffsetsTable;
4050b57cec5SDimitry Andric 
4065ffd83dbSDimitry Andric   /// Enable production of call site parameters needed to print the debug entry
4075ffd83dbSDimitry Andric   /// values. Useful for testing purposes when a debugger does not support the
4085ffd83dbSDimitry Andric   /// feature yet.
4095ffd83dbSDimitry Andric   bool EmitDebugEntryValues;
4105ffd83dbSDimitry Andric 
4110b57cec5SDimitry Andric   /// Separated Dwarf Variables
4120b57cec5SDimitry Andric   /// In general these will all be for bits that are left in the
4130b57cec5SDimitry Andric   /// original object file, rather than things that are meant
4140b57cec5SDimitry Andric   /// to be in the .dwo sections.
4150b57cec5SDimitry Andric 
4160b57cec5SDimitry Andric   /// Holder for the skeleton information.
4170b57cec5SDimitry Andric   DwarfFile SkeletonHolder;
4180b57cec5SDimitry Andric 
4190b57cec5SDimitry Andric   /// Store file names for type units under fission in a line table
4200b57cec5SDimitry Andric   /// header that will be emitted into debug_line.dwo.
4210b57cec5SDimitry Andric   // FIXME: replace this with a map from comp_dir to table so that we
4220b57cec5SDimitry Andric   // can emit multiple tables during LTO each of which uses directory
4230b57cec5SDimitry Andric   // 0, referencing the comp_dir of all the type units that use it.
4240b57cec5SDimitry Andric   MCDwarfDwoLineTable SplitTypeUnitFileTable;
4250b57cec5SDimitry Andric   /// @}
4260b57cec5SDimitry Andric 
4270b57cec5SDimitry Andric   /// True iff there are multiple CUs in this module.
4280b57cec5SDimitry Andric   bool SingleCU;
4290b57cec5SDimitry Andric   bool IsDarwin;
4300b57cec5SDimitry Andric 
431e8d8bef9SDimitry Andric   /// Map for tracking Fortran deferred CHARACTER lengths.
432e8d8bef9SDimitry Andric   DenseMap<const DIStringType *, unsigned> StringTypeLocMap;
433e8d8bef9SDimitry Andric 
4340b57cec5SDimitry Andric   AddressPool AddrPool;
4350b57cec5SDimitry Andric 
4360b57cec5SDimitry Andric   /// Accelerator tables.
4370b57cec5SDimitry Andric   AccelTable<DWARF5AccelTableData> AccelDebugNames;
4380b57cec5SDimitry Andric   AccelTable<AppleAccelTableOffsetData> AccelNames;
4390b57cec5SDimitry Andric   AccelTable<AppleAccelTableOffsetData> AccelObjC;
4400b57cec5SDimitry Andric   AccelTable<AppleAccelTableOffsetData> AccelNamespace;
4410b57cec5SDimitry Andric   AccelTable<AppleAccelTableTypeData> AccelTypes;
4420b57cec5SDimitry Andric 
443*fe6060f1SDimitry Andric   /// Identify a debugger for "tuning" the debug info.
444*fe6060f1SDimitry Andric   ///
445*fe6060f1SDimitry Andric   /// The "tuning" should be used to set defaults for individual feature flags
446*fe6060f1SDimitry Andric   /// in DwarfDebug; if a given feature has a more specific command-line option,
447*fe6060f1SDimitry Andric   /// that option should take precedence over the tuning.
4480b57cec5SDimitry Andric   DebuggerKind DebuggerTuning = DebuggerKind::Default;
4490b57cec5SDimitry Andric 
4500b57cec5SDimitry Andric   MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
4510b57cec5SDimitry Andric 
4520b57cec5SDimitry Andric   const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
4530b57cec5SDimitry Andric     return InfoHolder.getUnits();
4540b57cec5SDimitry Andric   }
4550b57cec5SDimitry Andric 
4560b57cec5SDimitry Andric   using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
4570b57cec5SDimitry Andric 
4580b57cec5SDimitry Andric   void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
4590b57cec5SDimitry Andric                                      const DINode *Node,
4600b57cec5SDimitry Andric                                      const MDNode *Scope);
4610b57cec5SDimitry Andric   void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
4620b57cec5SDimitry Andric                                              const DINode *Node,
4630b57cec5SDimitry Andric                                              const MDNode *Scope);
4640b57cec5SDimitry Andric 
4650b57cec5SDimitry Andric   DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
4660b57cec5SDimitry Andric                                   LexicalScope &Scope,
4670b57cec5SDimitry Andric                                   const DINode *Node,
4680b57cec5SDimitry Andric                                   const DILocation *Location,
4690b57cec5SDimitry Andric                                   const MCSymbol *Sym = nullptr);
4700b57cec5SDimitry Andric 
4710b57cec5SDimitry Andric   /// Construct a DIE for this abstract scope.
4720b57cec5SDimitry Andric   void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
4730b57cec5SDimitry Andric 
4745ffd83dbSDimitry Andric   /// Construct a DIE for the subprogram definition \p SP and return it.
4755ffd83dbSDimitry Andric   DIE &constructSubprogramDefinitionDIE(const DISubprogram *SP);
4765ffd83dbSDimitry Andric 
4770b57cec5SDimitry Andric   /// Construct DIEs for call site entries describing the calls in \p MF.
4780b57cec5SDimitry Andric   void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
4790b57cec5SDimitry Andric                                   DIE &ScopeDIE, const MachineFunction &MF);
4800b57cec5SDimitry Andric 
4810b57cec5SDimitry Andric   template <typename DataT>
4820b57cec5SDimitry Andric   void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
4830b57cec5SDimitry Andric                         StringRef Name, const DIE &Die);
4840b57cec5SDimitry Andric 
4850b57cec5SDimitry Andric   void finishEntityDefinitions();
4860b57cec5SDimitry Andric 
4870b57cec5SDimitry Andric   void finishSubprogramDefinitions();
4880b57cec5SDimitry Andric 
4890b57cec5SDimitry Andric   /// Finish off debug information after all functions have been
4900b57cec5SDimitry Andric   /// processed.
4910b57cec5SDimitry Andric   void finalizeModuleInfo();
4920b57cec5SDimitry Andric 
4930b57cec5SDimitry Andric   /// Emit the debug info section.
4940b57cec5SDimitry Andric   void emitDebugInfo();
4950b57cec5SDimitry Andric 
4960b57cec5SDimitry Andric   /// Emit the abbreviation section.
4970b57cec5SDimitry Andric   void emitAbbreviations();
4980b57cec5SDimitry Andric 
4990b57cec5SDimitry Andric   /// Emit the string offsets table header.
5000b57cec5SDimitry Andric   void emitStringOffsetsTableHeader();
5010b57cec5SDimitry Andric 
5020b57cec5SDimitry Andric   /// Emit a specified accelerator table.
5030b57cec5SDimitry Andric   template <typename AccelTableT>
5040b57cec5SDimitry Andric   void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
5050b57cec5SDimitry Andric 
5060b57cec5SDimitry Andric   /// Emit DWARF v5 accelerator table.
5070b57cec5SDimitry Andric   void emitAccelDebugNames();
5080b57cec5SDimitry Andric 
5090b57cec5SDimitry Andric   /// Emit visible names into a hashed accelerator table section.
5100b57cec5SDimitry Andric   void emitAccelNames();
5110b57cec5SDimitry Andric 
5120b57cec5SDimitry Andric   /// Emit objective C classes and categories into a hashed
5130b57cec5SDimitry Andric   /// accelerator table section.
5140b57cec5SDimitry Andric   void emitAccelObjC();
5150b57cec5SDimitry Andric 
5160b57cec5SDimitry Andric   /// Emit namespace dies into a hashed accelerator table.
5170b57cec5SDimitry Andric   void emitAccelNamespaces();
5180b57cec5SDimitry Andric 
5190b57cec5SDimitry Andric   /// Emit type dies into a hashed accelerator table.
5200b57cec5SDimitry Andric   void emitAccelTypes();
5210b57cec5SDimitry Andric 
5220b57cec5SDimitry Andric   /// Emit visible names and types into debug pubnames and pubtypes sections.
5230b57cec5SDimitry Andric   void emitDebugPubSections();
5240b57cec5SDimitry Andric 
5250b57cec5SDimitry Andric   void emitDebugPubSection(bool GnuStyle, StringRef Name,
5260b57cec5SDimitry Andric                            DwarfCompileUnit *TheU,
5270b57cec5SDimitry Andric                            const StringMap<const DIE *> &Globals);
5280b57cec5SDimitry Andric 
5290b57cec5SDimitry Andric   /// Emit null-terminated strings into a debug str section.
5300b57cec5SDimitry Andric   void emitDebugStr();
5310b57cec5SDimitry Andric 
5320b57cec5SDimitry Andric   /// Emit variable locations into a debug loc section.
5330b57cec5SDimitry Andric   void emitDebugLoc();
5340b57cec5SDimitry Andric 
5350b57cec5SDimitry Andric   /// Emit variable locations into a debug loc dwo section.
5360b57cec5SDimitry Andric   void emitDebugLocDWO();
5370b57cec5SDimitry Andric 
538480093f4SDimitry Andric   void emitDebugLocImpl(MCSection *Sec);
539480093f4SDimitry Andric 
5400b57cec5SDimitry Andric   /// Emit address ranges into a debug aranges section.
5410b57cec5SDimitry Andric   void emitDebugARanges();
5420b57cec5SDimitry Andric 
5430b57cec5SDimitry Andric   /// Emit address ranges into a debug ranges section.
5440b57cec5SDimitry Andric   void emitDebugRanges();
5450b57cec5SDimitry Andric   void emitDebugRangesDWO();
546480093f4SDimitry Andric   void emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section);
5470b57cec5SDimitry Andric 
5480b57cec5SDimitry Andric   /// Emit macros into a debug macinfo section.
5490b57cec5SDimitry Andric   void emitDebugMacinfo();
550480093f4SDimitry Andric   /// Emit macros into a debug macinfo.dwo section.
551480093f4SDimitry Andric   void emitDebugMacinfoDWO();
552480093f4SDimitry Andric   void emitDebugMacinfoImpl(MCSection *Section);
5530b57cec5SDimitry Andric   void emitMacro(DIMacro &M);
5540b57cec5SDimitry Andric   void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
5555ffd83dbSDimitry Andric   void emitMacroFileImpl(DIMacroFile &F, DwarfCompileUnit &U,
5565ffd83dbSDimitry Andric                          unsigned StartFile, unsigned EndFile,
5575ffd83dbSDimitry Andric                          StringRef (*MacroFormToString)(unsigned Form));
5580b57cec5SDimitry Andric   void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
5590b57cec5SDimitry Andric 
5600b57cec5SDimitry Andric   /// DWARF 5 Experimental Split Dwarf Emitters
5610b57cec5SDimitry Andric 
5620b57cec5SDimitry Andric   /// Initialize common features of skeleton units.
5630b57cec5SDimitry Andric   void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
5640b57cec5SDimitry Andric                         std::unique_ptr<DwarfCompileUnit> NewU);
5650b57cec5SDimitry Andric 
5660b57cec5SDimitry Andric   /// Construct the split debug info compile unit for the debug info section.
5670b57cec5SDimitry Andric   /// In DWARF v5, the skeleton unit DIE may have the following attributes:
5680b57cec5SDimitry Andric   /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
5690b57cec5SDimitry Andric   /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
5700b57cec5SDimitry Andric   /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
5710b57cec5SDimitry Andric   /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
5720b57cec5SDimitry Andric   /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
5730b57cec5SDimitry Andric   DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
5740b57cec5SDimitry Andric 
5750b57cec5SDimitry Andric   /// Emit the debug info dwo section.
5760b57cec5SDimitry Andric   void emitDebugInfoDWO();
5770b57cec5SDimitry Andric 
5780b57cec5SDimitry Andric   /// Emit the debug abbrev dwo section.
5790b57cec5SDimitry Andric   void emitDebugAbbrevDWO();
5800b57cec5SDimitry Andric 
5810b57cec5SDimitry Andric   /// Emit the debug line dwo section.
5820b57cec5SDimitry Andric   void emitDebugLineDWO();
5830b57cec5SDimitry Andric 
5840b57cec5SDimitry Andric   /// Emit the dwo stringoffsets table header.
5850b57cec5SDimitry Andric   void emitStringOffsetsTableHeaderDWO();
5860b57cec5SDimitry Andric 
5870b57cec5SDimitry Andric   /// Emit the debug str dwo section.
5880b57cec5SDimitry Andric   void emitDebugStrDWO();
5890b57cec5SDimitry Andric 
5900b57cec5SDimitry Andric   /// Emit DWO addresses.
5910b57cec5SDimitry Andric   void emitDebugAddr();
5920b57cec5SDimitry Andric 
5930b57cec5SDimitry Andric   /// Flags to let the linker know we have emitted new style pubnames. Only
5940b57cec5SDimitry Andric   /// emit it here if we don't have a skeleton CU for split dwarf.
5950b57cec5SDimitry Andric   void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
5960b57cec5SDimitry Andric 
5970b57cec5SDimitry Andric   /// Create new DwarfCompileUnit for the given metadata node with tag
5980b57cec5SDimitry Andric   /// DW_TAG_compile_unit.
5990b57cec5SDimitry Andric   DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
6000b57cec5SDimitry Andric   void finishUnitAttributes(const DICompileUnit *DIUnit,
6010b57cec5SDimitry Andric                             DwarfCompileUnit &NewCU);
6020b57cec5SDimitry Andric 
6030b57cec5SDimitry Andric   /// Construct imported_module or imported_declaration DIE.
6040b57cec5SDimitry Andric   void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
6050b57cec5SDimitry Andric                                         const DIImportedEntity *N);
6060b57cec5SDimitry Andric 
6070b57cec5SDimitry Andric   /// Register a source line with debug info. Returns the unique
6080b57cec5SDimitry Andric   /// label that was emitted and which provides correspondence to the
6090b57cec5SDimitry Andric   /// source line list.
6100b57cec5SDimitry Andric   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
6110b57cec5SDimitry Andric                         unsigned Flags);
6120b57cec5SDimitry Andric 
6130b57cec5SDimitry Andric   /// Populate LexicalScope entries with variables' info.
6140b57cec5SDimitry Andric   void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
6150b57cec5SDimitry Andric                          DenseSet<InlinedEntity> &ProcessedVars);
6160b57cec5SDimitry Andric 
6170b57cec5SDimitry Andric   /// Build the location list for all DBG_VALUEs in the
6180b57cec5SDimitry Andric   /// function that describe the same variable. If the resulting
6190b57cec5SDimitry Andric   /// list has only one entry that is valid for entire variable's
6200b57cec5SDimitry Andric   /// scope return true.
621e8d8bef9SDimitry Andric   bool buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
622e8d8bef9SDimitry Andric                          const DbgValueHistoryMap::Entries &Entries);
6230b57cec5SDimitry Andric 
6240b57cec5SDimitry Andric   /// Collect variable information from the side table maintained by MF.
6250b57cec5SDimitry Andric   void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
6260b57cec5SDimitry Andric                                       DenseSet<InlinedEntity> &P);
6270b57cec5SDimitry Andric 
6280b57cec5SDimitry Andric   /// Emit the reference to the section.
6290b57cec5SDimitry Andric   void emitSectionReference(const DwarfCompileUnit &CU);
6300b57cec5SDimitry Andric 
6310b57cec5SDimitry Andric protected:
6320b57cec5SDimitry Andric   /// Gather pre-function debug information.
6330b57cec5SDimitry Andric   void beginFunctionImpl(const MachineFunction *MF) override;
6340b57cec5SDimitry Andric 
6350b57cec5SDimitry Andric   /// Gather and emit post-function debug information.
6360b57cec5SDimitry Andric   void endFunctionImpl(const MachineFunction *MF) override;
6370b57cec5SDimitry Andric 
6380b57cec5SDimitry Andric   void skippedNonDebugFunction() override;
6390b57cec5SDimitry Andric 
6400b57cec5SDimitry Andric public:
6410b57cec5SDimitry Andric   //===--------------------------------------------------------------------===//
6420b57cec5SDimitry Andric   // Main entry points.
6430b57cec5SDimitry Andric   //
644e8d8bef9SDimitry Andric   DwarfDebug(AsmPrinter *A);
6450b57cec5SDimitry Andric 
6460b57cec5SDimitry Andric   ~DwarfDebug() override;
6470b57cec5SDimitry Andric 
6480b57cec5SDimitry Andric   /// Emit all Dwarf sections that should come prior to the
6490b57cec5SDimitry Andric   /// content.
650e8d8bef9SDimitry Andric   void beginModule(Module *M) override;
6510b57cec5SDimitry Andric 
6520b57cec5SDimitry Andric   /// Emit all Dwarf sections that should come after the content.
6530b57cec5SDimitry Andric   void endModule() override;
6540b57cec5SDimitry Andric 
6550b57cec5SDimitry Andric   /// Emits inital debug location directive.
6560b57cec5SDimitry Andric   DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
6570b57cec5SDimitry Andric 
6580b57cec5SDimitry Andric   /// Process beginning of an instruction.
6590b57cec5SDimitry Andric   void beginInstruction(const MachineInstr *MI) override;
6600b57cec5SDimitry Andric 
6610b57cec5SDimitry Andric   /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
6620b57cec5SDimitry Andric   static uint64_t makeTypeSignature(StringRef Identifier);
6630b57cec5SDimitry Andric 
6640b57cec5SDimitry Andric   /// Add a DIE to the set of types that we're going to pull into
6650b57cec5SDimitry Andric   /// type units.
6660b57cec5SDimitry Andric   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
6670b57cec5SDimitry Andric                             DIE &Die, const DICompositeType *CTy);
6680b57cec5SDimitry Andric 
6690b57cec5SDimitry Andric   class NonTypeUnitContext {
6700b57cec5SDimitry Andric     DwarfDebug *DD;
6710b57cec5SDimitry Andric     decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
672e8d8bef9SDimitry Andric     bool AddrPoolUsed;
6730b57cec5SDimitry Andric     friend class DwarfDebug;
6740b57cec5SDimitry Andric     NonTypeUnitContext(DwarfDebug *DD);
6750b57cec5SDimitry Andric   public:
6760b57cec5SDimitry Andric     NonTypeUnitContext(NonTypeUnitContext&&) = default;
6770b57cec5SDimitry Andric     ~NonTypeUnitContext();
6780b57cec5SDimitry Andric   };
6790b57cec5SDimitry Andric 
6800b57cec5SDimitry Andric   NonTypeUnitContext enterNonTypeUnitContext();
6810b57cec5SDimitry Andric 
6820b57cec5SDimitry Andric   /// Add a label so that arange data can be generated for it.
6830b57cec5SDimitry Andric   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
6840b57cec5SDimitry Andric 
6850b57cec5SDimitry Andric   /// For symbols that have a size designated (e.g. common symbols),
6860b57cec5SDimitry Andric   /// this tracks that size.
6870b57cec5SDimitry Andric   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
6880b57cec5SDimitry Andric     SymSize[Sym] = Size;
6890b57cec5SDimitry Andric   }
6900b57cec5SDimitry Andric 
6910b57cec5SDimitry Andric   /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
6920b57cec5SDimitry Andric   /// If not, we still might emit certain cases.
6930b57cec5SDimitry Andric   bool useAllLinkageNames() const { return UseAllLinkageNames; }
6940b57cec5SDimitry Andric 
6950b57cec5SDimitry Andric   /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
6960b57cec5SDimitry Andric   /// standard DW_OP_form_tls_address opcode
6970b57cec5SDimitry Andric   bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
6980b57cec5SDimitry Andric 
6990b57cec5SDimitry Andric   /// Returns whether to use the DWARF2 format for bitfields instyead of the
7000b57cec5SDimitry Andric   /// DWARF4 format.
7010b57cec5SDimitry Andric   bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
7020b57cec5SDimitry Andric 
7030b57cec5SDimitry Andric   /// Returns whether to use inline strings.
7040b57cec5SDimitry Andric   bool useInlineStrings() const { return UseInlineStrings; }
7050b57cec5SDimitry Andric 
7060b57cec5SDimitry Andric   /// Returns whether ranges section should be emitted.
7070b57cec5SDimitry Andric   bool useRangesSection() const { return UseRangesSection; }
7080b57cec5SDimitry Andric 
709e8d8bef9SDimitry Andric   /// Returns whether range encodings should be used for single entry range
710e8d8bef9SDimitry Andric   /// lists.
711e8d8bef9SDimitry Andric   bool alwaysUseRanges() const {
712e8d8bef9SDimitry Andric     return MinimizeAddr == MinimizeAddrInV5::Ranges;
713e8d8bef9SDimitry Andric   }
714e8d8bef9SDimitry Andric 
715*fe6060f1SDimitry Andric   // Returns whether novel exprloc addrx+offset encodings should be used to
716*fe6060f1SDimitry Andric   // reduce debug_addr size.
717*fe6060f1SDimitry Andric   bool useAddrOffsetExpressions() const {
718*fe6060f1SDimitry Andric     return MinimizeAddr == MinimizeAddrInV5::Expressions;
719*fe6060f1SDimitry Andric   }
720*fe6060f1SDimitry Andric 
721*fe6060f1SDimitry Andric   // Returns whether addrx+offset LLVM extension form should be used to reduce
722*fe6060f1SDimitry Andric   // debug_addr size.
723*fe6060f1SDimitry Andric   bool useAddrOffsetForm() const {
724*fe6060f1SDimitry Andric     return MinimizeAddr == MinimizeAddrInV5::Form;
725*fe6060f1SDimitry Andric   }
726*fe6060f1SDimitry Andric 
7270b57cec5SDimitry Andric   /// Returns whether to use sections as labels rather than temp symbols.
7280b57cec5SDimitry Andric   bool useSectionsAsReferences() const {
7290b57cec5SDimitry Andric     return UseSectionsAsReferences;
7300b57cec5SDimitry Andric   }
7310b57cec5SDimitry Andric 
7320b57cec5SDimitry Andric   /// Returns whether .debug_loc section should be emitted.
7330b57cec5SDimitry Andric   bool useLocSection() const { return UseLocSection; }
7340b57cec5SDimitry Andric 
7350b57cec5SDimitry Andric   /// Returns whether to generate DWARF v4 type units.
7360b57cec5SDimitry Andric   bool generateTypeUnits() const { return GenerateTypeUnits; }
7370b57cec5SDimitry Andric 
7380b57cec5SDimitry Andric   // Experimental DWARF5 features.
7390b57cec5SDimitry Andric 
7400b57cec5SDimitry Andric   /// Returns what kind (if any) of accelerator tables to emit.
7410b57cec5SDimitry Andric   AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
7420b57cec5SDimitry Andric 
7430b57cec5SDimitry Andric   bool useAppleExtensionAttributes() const {
7440b57cec5SDimitry Andric     return HasAppleExtensionAttributes;
7450b57cec5SDimitry Andric   }
7460b57cec5SDimitry Andric 
7470b57cec5SDimitry Andric   /// Returns whether or not to change the current debug info for the
7480b57cec5SDimitry Andric   /// split dwarf proposal support.
7490b57cec5SDimitry Andric   bool useSplitDwarf() const { return HasSplitDwarf; }
7500b57cec5SDimitry Andric 
7510b57cec5SDimitry Andric   /// Returns whether to generate a string offsets table with (possibly shared)
7520b57cec5SDimitry Andric   /// contributions from each CU and type unit. This implies the use of
7530b57cec5SDimitry Andric   /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
7540b57cec5SDimitry Andric   /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
7550b57cec5SDimitry Andric   /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
7560b57cec5SDimitry Andric   /// monolithic string offsets table.
7570b57cec5SDimitry Andric   bool useSegmentedStringOffsetsTable() const {
7580b57cec5SDimitry Andric     return UseSegmentedStringOffsetsTable;
7590b57cec5SDimitry Andric   }
7600b57cec5SDimitry Andric 
7615ffd83dbSDimitry Andric   bool emitDebugEntryValues() const {
7625ffd83dbSDimitry Andric     return EmitDebugEntryValues;
7635ffd83dbSDimitry Andric   }
7645ffd83dbSDimitry Andric 
765e8d8bef9SDimitry Andric   bool useOpConvert() const {
766e8d8bef9SDimitry Andric     return EnableOpConvert;
767e8d8bef9SDimitry Andric   }
768e8d8bef9SDimitry Andric 
7690b57cec5SDimitry Andric   bool shareAcrossDWOCUs() const;
7700b57cec5SDimitry Andric 
7710b57cec5SDimitry Andric   /// Returns the Dwarf Version.
7720b57cec5SDimitry Andric   uint16_t getDwarfVersion() const;
7730b57cec5SDimitry Andric 
774e8d8bef9SDimitry Andric   /// Returns a suitable DWARF form to represent a section offset, i.e.
775e8d8bef9SDimitry Andric   /// * DW_FORM_sec_offset for DWARF version >= 4;
776e8d8bef9SDimitry Andric   /// * DW_FORM_data8 for 64-bit DWARFv3;
777e8d8bef9SDimitry Andric   /// * DW_FORM_data4 for 32-bit DWARFv3 and DWARFv2.
778e8d8bef9SDimitry Andric   dwarf::Form getDwarfSectionOffsetForm() const;
779e8d8bef9SDimitry Andric 
7800b57cec5SDimitry Andric   /// Returns the previous CU that was being updated
7810b57cec5SDimitry Andric   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
7820b57cec5SDimitry Andric   void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
7830b57cec5SDimitry Andric 
7840b57cec5SDimitry Andric   /// Returns the entries for the .debug_loc section.
7850b57cec5SDimitry Andric   const DebugLocStream &getDebugLocs() const { return DebugLocs; }
7860b57cec5SDimitry Andric 
7870b57cec5SDimitry Andric   /// Emit an entry for the debug loc section. This can be used to
7880b57cec5SDimitry Andric   /// handle an entry that's going to be emitted into the debug loc section.
7890b57cec5SDimitry Andric   void emitDebugLocEntry(ByteStreamer &Streamer,
7900b57cec5SDimitry Andric                          const DebugLocStream::Entry &Entry,
7910b57cec5SDimitry Andric                          const DwarfCompileUnit *CU);
7920b57cec5SDimitry Andric 
7930b57cec5SDimitry Andric   /// Emit the location for a debug loc entry, including the size header.
7940b57cec5SDimitry Andric   void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry,
7950b57cec5SDimitry Andric                                  const DwarfCompileUnit *CU);
7960b57cec5SDimitry Andric 
7970b57cec5SDimitry Andric   void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
7980b57cec5SDimitry Andric                           DIE &Die);
7990b57cec5SDimitry Andric 
8000b57cec5SDimitry Andric   AddressPool &getAddressPool() { return AddrPool; }
8010b57cec5SDimitry Andric 
8020b57cec5SDimitry Andric   void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
8030b57cec5SDimitry Andric 
8040b57cec5SDimitry Andric   void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
8050b57cec5SDimitry Andric 
8060b57cec5SDimitry Andric   void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
8070b57cec5SDimitry Andric                          const DIE &Die);
8080b57cec5SDimitry Andric 
8090b57cec5SDimitry Andric   void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
8100b57cec5SDimitry Andric                     char Flags);
8110b57cec5SDimitry Andric 
8120b57cec5SDimitry Andric   const MachineFunction *getCurrentFunction() const { return CurFn; }
8130b57cec5SDimitry Andric 
8140b57cec5SDimitry Andric   /// A helper function to check whether the DIE for a given Scope is
8150b57cec5SDimitry Andric   /// going to be null.
8160b57cec5SDimitry Andric   bool isLexicalScopeDIENull(LexicalScope *Scope);
8170b57cec5SDimitry Andric 
8180b57cec5SDimitry Andric   /// Find the matching DwarfCompileUnit for the given CU DIE.
8190b57cec5SDimitry Andric   DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
8200b57cec5SDimitry Andric   const DwarfCompileUnit *lookupCU(const DIE *Die) const {
8210b57cec5SDimitry Andric     return CUDieMap.lookup(Die);
8220b57cec5SDimitry Andric   }
8230b57cec5SDimitry Andric 
824e8d8bef9SDimitry Andric   unsigned getStringTypeLoc(const DIStringType *ST) const {
825e8d8bef9SDimitry Andric     return StringTypeLocMap.lookup(ST);
826e8d8bef9SDimitry Andric   }
827e8d8bef9SDimitry Andric 
828e8d8bef9SDimitry Andric   void addStringTypeLoc(const DIStringType *ST, unsigned Loc) {
829e8d8bef9SDimitry Andric     assert(ST);
830e8d8bef9SDimitry Andric     if (Loc)
831e8d8bef9SDimitry Andric       StringTypeLocMap[ST] = Loc;
832e8d8bef9SDimitry Andric   }
833e8d8bef9SDimitry Andric 
8340b57cec5SDimitry Andric   /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
8350b57cec5SDimitry Andric   ///
8360b57cec5SDimitry Andric   /// Returns whether we are "tuning" for a given debugger.
8370b57cec5SDimitry Andric   /// @{
8380b57cec5SDimitry Andric   bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
8390b57cec5SDimitry Andric   bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
8400b57cec5SDimitry Andric   bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
841*fe6060f1SDimitry Andric   bool tuneForDBX() const { return DebuggerTuning == DebuggerKind::DBX; }
8420b57cec5SDimitry Andric   /// @}
8430b57cec5SDimitry Andric 
8440b57cec5SDimitry Andric   const MCSymbol *getSectionLabel(const MCSection *S);
8455ffd83dbSDimitry Andric   void insertSectionLabel(const MCSymbol *S);
8460b57cec5SDimitry Andric 
8470b57cec5SDimitry Andric   static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
8480b57cec5SDimitry Andric                                 const DbgValueLoc &Value,
8490b57cec5SDimitry Andric                                 DwarfExpression &DwarfExpr);
850e8d8bef9SDimitry Andric 
851e8d8bef9SDimitry Andric   /// If the \p File has an MD5 checksum, return it as an MD5Result
852e8d8bef9SDimitry Andric   /// allocated in the MCContext.
853e8d8bef9SDimitry Andric   Optional<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const;
8540b57cec5SDimitry Andric };
8550b57cec5SDimitry Andric 
8560b57cec5SDimitry Andric } // end namespace llvm
8570b57cec5SDimitry Andric 
8580b57cec5SDimitry Andric #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
859