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