1 //===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains support for writing dwarf debug info into asm files.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
16 #include "AddressPool.h"
17 #include "DebugLocStream.h"
18 #include "DebugLocEntry.h"
19 #include "DwarfFile.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/DenseSet.h"
23 #include "llvm/ADT/MapVector.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/SetVector.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/StringMap.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/BinaryFormat/Dwarf.h"
31 #include "llvm/CodeGen/AccelTable.h"
32 #include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
33 #include "llvm/CodeGen/DebugHandlerBase.h"
34 #include "llvm/CodeGen/MachineInstr.h"
35 #include "llvm/IR/DebugInfoMetadata.h"
36 #include "llvm/IR/DebugLoc.h"
37 #include "llvm/IR/Metadata.h"
38 #include "llvm/MC/MCDwarf.h"
39 #include "llvm/Support/Allocator.h"
40 #include "llvm/Target/TargetOptions.h"
53 class DwarfCompileUnit;
54 class DwarfExpression;
58 class MachineFunction;
63 //===----------------------------------------------------------------------===//
64 /// This class is defined as the common parent of DbgVariable and DbgLabel
65 /// such that it could levarage polymorphism to extract common code for
66 /// DbgVariable and DbgLabel.
69 const DILocation *InlinedAt;
70 DIE *TheDIE = nullptr;
79 DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)
80 : Entity(N), InlinedAt(IA), SubclassID(ID) {}
81 virtual ~DbgEntity() {}
85 const DINode *getEntity() const { return Entity; }
86 const DILocation *getInlinedAt() const { return InlinedAt; }
87 DIE *getDIE() const { return TheDIE; }
88 unsigned getDbgEntityID() const { return SubclassID; }
91 void setDIE(DIE &D) { TheDIE = &D; }
93 static bool classof(const DbgEntity *N) {
94 switch (N->getDbgEntityID()) {
104 //===----------------------------------------------------------------------===//
105 /// This class is used to track local variable information.
107 /// Variables can be created from allocas, in which case they're generated from
108 /// the MMI table. Such variables can have multiple expressions and frame
111 /// Variables can be created from \c DBG_VALUE instructions. Those whose
112 /// location changes over time use \a DebugLocListIndex, while those with a
113 /// single location use \a ValueLoc and (optionally) a single entry of \a Expr.
115 /// Variables that have been optimized out use none of these fields.
116 class DbgVariable : public DbgEntity {
117 /// Offset in DebugLocs.
118 unsigned DebugLocListIndex = ~0u;
119 /// DW_OP_LLVM_tag_offset value from DebugLocs.
120 Optional<uint8_t> DebugLocListTagOffset;
122 /// Single value location description.
123 std::unique_ptr<DbgValueLoc> ValueLoc = nullptr;
125 struct FrameIndexExpr {
127 const DIExpression *Expr;
129 mutable SmallVector<FrameIndexExpr, 1>
130 FrameIndexExprs; /// Frame index + expression.
133 /// Construct a DbgVariable.
135 /// Creates a variable without any DW_AT_location. Call \a initializeMMI()
136 /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
137 DbgVariable(const DILocalVariable *V, const DILocation *IA)
138 : DbgEntity(V, IA, DbgVariableKind) {}
140 /// Initialize from the MMI table.
141 void initializeMMI(const DIExpression *E, int FI) {
142 assert(FrameIndexExprs.empty() && "Already initialized?");
143 assert(!ValueLoc.get() && "Already initialized?");
145 assert((!E || E->isValid()) && "Expected valid expression");
146 assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
148 FrameIndexExprs.push_back({FI, E});
151 // Initialize variable's location.
152 void initializeDbgValue(DbgValueLoc Value) {
153 assert(FrameIndexExprs.empty() && "Already initialized?");
154 assert(!ValueLoc && "Already initialized?");
155 assert(!Value.getExpression()->isFragment() && "Fragments not supported.");
157 ValueLoc = std::make_unique<DbgValueLoc>(Value);
158 if (auto *E = ValueLoc->getExpression())
159 if (E->getNumElements())
160 FrameIndexExprs.push_back({0, E});
163 /// Initialize from a DBG_VALUE instruction.
164 void initializeDbgValue(const MachineInstr *DbgValue);
167 const DILocalVariable *getVariable() const {
168 return cast<DILocalVariable>(getEntity());
171 const DIExpression *getSingleExpression() const {
172 assert(ValueLoc.get() && FrameIndexExprs.size() <= 1);
173 return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;
176 void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
177 unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
178 void setDebugLocListTagOffset(uint8_t O) { DebugLocListTagOffset = O; }
179 Optional<uint8_t> getDebugLocListTagOffset() const { return DebugLocListTagOffset; }
180 StringRef getName() const { return getVariable()->getName(); }
181 const DbgValueLoc *getValueLoc() const { return ValueLoc.get(); }
182 /// Get the FI entries, sorted by fragment offset.
183 ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
184 bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
185 void addMMIEntry(const DbgVariable &V);
187 // Translate tag to proper Dwarf tag.
188 dwarf::Tag getTag() const {
189 // FIXME: Why don't we just infer this tag and store it all along?
190 if (getVariable()->isParameter())
191 return dwarf::DW_TAG_formal_parameter;
193 return dwarf::DW_TAG_variable;
196 /// Return true if DbgVariable is artificial.
197 bool isArtificial() const {
198 if (getVariable()->isArtificial())
200 if (getType()->isArtificial())
205 bool isObjectPointer() const {
206 if (getVariable()->isObjectPointer())
208 if (getType()->isObjectPointer())
213 bool hasComplexAddress() const {
214 assert(ValueLoc.get() && "Expected DBG_VALUE, not MMI variable");
215 assert((FrameIndexExprs.empty() ||
216 (FrameIndexExprs.size() == 1 &&
217 FrameIndexExprs[0].Expr->getNumElements())) &&
218 "Invalid Expr for DBG_VALUE");
219 return !FrameIndexExprs.empty();
222 const DIType *getType() const;
224 static bool classof(const DbgEntity *N) {
225 return N->getDbgEntityID() == DbgVariableKind;
229 //===----------------------------------------------------------------------===//
230 /// This class is used to track label information.
232 /// Labels are collected from \c DBG_LABEL instructions.
233 class DbgLabel : public DbgEntity {
234 const MCSymbol *Sym; /// Symbol before DBG_LABEL instruction.
237 /// We need MCSymbol information to generate DW_AT_low_pc.
238 DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
239 : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
243 const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
244 const MCSymbol *getSymbol() const { return Sym; }
246 StringRef getName() const { return getLabel()->getName(); }
249 /// Translate tag to proper Dwarf tag.
250 dwarf::Tag getTag() const {
251 return dwarf::DW_TAG_label;
254 static bool classof(const DbgEntity *N) {
255 return N->getDbgEntityID() == DbgLabelKind;
259 /// Used for tracking debug info about call site parameters.
260 class DbgCallSiteParam {
262 unsigned Register; ///< Parameter register at the callee entry point.
263 DbgValueLoc Value; ///< Corresponding location for the parameter value at
266 DbgCallSiteParam(unsigned Reg, DbgValueLoc Val)
267 : Register(Reg), Value(Val) {
268 assert(Reg && "Parameter register cannot be undef");
271 unsigned getRegister() const { return Register; }
272 DbgValueLoc getValue() const { return Value; }
275 /// Collection used for storing debug call site parameters.
276 using ParamSet = SmallVector<DbgCallSiteParam, 4>;
278 /// Helper used to pair up a symbol and its DWARF compile unit.
280 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
283 DwarfCompileUnit *CU;
286 /// The kind of accelerator tables we should emit.
287 enum class AccelTableKind {
288 Default, ///< Platform default.
290 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
291 Dwarf, ///< DWARF v5 .debug_names.
294 /// Collects and handles dwarf debug information.
295 class DwarfDebug : public DebugHandlerBase {
296 /// All DIEValues are allocated through this allocator.
297 BumpPtrAllocator DIEValueAllocator;
299 /// Maps MDNode with its corresponding DwarfCompileUnit.
300 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
302 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
303 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
305 /// List of all labels used in aranges generation.
306 std::vector<SymbolCU> ArangeLabels;
308 /// Size of each symbol emitted (for those symbols that have a specific size).
309 DenseMap<const MCSymbol *, uint64_t> SymSize;
311 /// Collection of abstract variables/labels.
312 SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
314 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
315 /// can refer to them in spite of insertions into this list.
316 DebugLocStream DebugLocs;
318 /// This is a collection of subprogram MDNodes that are processed to
320 SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>,
321 SmallPtrSet<const DISubprogram *, 16>>
324 /// If nonnull, stores the current machine function we're processing.
325 const MachineFunction *CurFn = nullptr;
327 /// If nonnull, stores the CU in which the previous subprogram was contained.
328 const DwarfCompileUnit *PrevCU = nullptr;
330 /// As an optimization, there is no need to emit an entry in the directory
331 /// table for the same directory as DW_AT_comp_dir.
332 StringRef CompilationDir;
334 /// Holder for the file specific debug information.
335 DwarfFile InfoHolder;
337 /// Holders for the various debug information flags that we might need to
338 /// have exposed. See accessor functions below for description.
340 /// Map from MDNodes for user-defined types to their type signatures. Also
341 /// used to keep track of which types we have emitted type units for.
342 DenseMap<const MDNode *, uint64_t> TypeSignatures;
344 DenseMap<const MCSection *, const MCSymbol *> SectionLabels;
347 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
348 TypeUnitsUnderConstruction;
350 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
351 bool UseGNUTLSOpcode;
353 /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
354 bool UseDWARF2Bitfields;
356 /// Whether to emit all linkage names, or just abstract subprograms.
357 bool UseAllLinkageNames;
359 /// Use inlined strings.
360 bool UseInlineStrings = false;
362 /// Allow emission of .debug_ranges section.
363 bool UseRangesSection = true;
365 /// True if the sections itself must be used as references and don't create
366 /// temp symbols inside DWARF sections.
367 bool UseSectionsAsReferences = false;
369 ///Allow emission of the .debug_loc section.
370 bool UseLocSection = true;
372 /// Generate DWARF v4 type units.
373 bool GenerateTypeUnits;
375 /// DWARF5 Experimental Options
377 AccelTableKind TheAccelTableKind;
378 bool HasAppleExtensionAttributes;
381 /// Whether to generate the DWARF v5 string offsets table.
382 /// It consists of a series of contributions, each preceded by a header.
383 /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
384 /// a monolithic sequence of string offsets.
385 bool UseSegmentedStringOffsetsTable;
387 /// Enable production of call site parameters needed to print the debug entry
388 /// values. Useful for testing purposes when a debugger does not support the
390 bool EmitDebugEntryValues;
392 /// Separated Dwarf Variables
393 /// In general these will all be for bits that are left in the
394 /// original object file, rather than things that are meant
395 /// to be in the .dwo sections.
397 /// Holder for the skeleton information.
398 DwarfFile SkeletonHolder;
400 /// Store file names for type units under fission in a line table
401 /// header that will be emitted into debug_line.dwo.
402 // FIXME: replace this with a map from comp_dir to table so that we
403 // can emit multiple tables during LTO each of which uses directory
404 // 0, referencing the comp_dir of all the type units that use it.
405 MCDwarfDwoLineTable SplitTypeUnitFileTable;
408 /// True iff there are multiple CUs in this module.
412 AddressPool AddrPool;
414 /// Accelerator tables.
415 AccelTable<DWARF5AccelTableData> AccelDebugNames;
416 AccelTable<AppleAccelTableOffsetData> AccelNames;
417 AccelTable<AppleAccelTableOffsetData> AccelObjC;
418 AccelTable<AppleAccelTableOffsetData> AccelNamespace;
419 AccelTable<AppleAccelTableTypeData> AccelTypes;
421 // Identify a debugger for "tuning" the debug info.
422 DebuggerKind DebuggerTuning = DebuggerKind::Default;
424 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
426 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
427 return InfoHolder.getUnits();
430 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
432 void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
434 const MDNode *Scope);
435 void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
437 const MDNode *Scope);
439 DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
442 const DILocation *Location,
443 const MCSymbol *Sym = nullptr);
445 /// Construct a DIE for this abstract scope.
446 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
448 /// Construct a DIE for the subprogram definition \p SP and return it.
449 DIE &constructSubprogramDefinitionDIE(const DISubprogram *SP);
451 /// Construct DIEs for call site entries describing the calls in \p MF.
452 void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
453 DIE &ScopeDIE, const MachineFunction &MF);
455 template <typename DataT>
456 void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
457 StringRef Name, const DIE &Die);
459 void finishEntityDefinitions();
461 void finishSubprogramDefinitions();
463 /// Finish off debug information after all functions have been
465 void finalizeModuleInfo();
467 /// Emit the debug info section.
468 void emitDebugInfo();
470 /// Emit the abbreviation section.
471 void emitAbbreviations();
473 /// Emit the string offsets table header.
474 void emitStringOffsetsTableHeader();
476 /// Emit a specified accelerator table.
477 template <typename AccelTableT>
478 void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
480 /// Emit DWARF v5 accelerator table.
481 void emitAccelDebugNames();
483 /// Emit visible names into a hashed accelerator table section.
484 void emitAccelNames();
486 /// Emit objective C classes and categories into a hashed
487 /// accelerator table section.
488 void emitAccelObjC();
490 /// Emit namespace dies into a hashed accelerator table.
491 void emitAccelNamespaces();
493 /// Emit type dies into a hashed accelerator table.
494 void emitAccelTypes();
496 /// Emit visible names and types into debug pubnames and pubtypes sections.
497 void emitDebugPubSections();
499 void emitDebugPubSection(bool GnuStyle, StringRef Name,
500 DwarfCompileUnit *TheU,
501 const StringMap<const DIE *> &Globals);
503 /// Emit null-terminated strings into a debug str section.
506 /// Emit variable locations into a debug loc section.
509 /// Emit variable locations into a debug loc dwo section.
510 void emitDebugLocDWO();
512 void emitDebugLocImpl(MCSection *Sec);
514 /// Emit address ranges into a debug aranges section.
515 void emitDebugARanges();
517 /// Emit address ranges into a debug ranges section.
518 void emitDebugRanges();
519 void emitDebugRangesDWO();
520 void emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section);
522 /// Emit macros into a debug macinfo section.
523 void emitDebugMacinfo();
524 /// Emit macros into a debug macinfo.dwo section.
525 void emitDebugMacinfoDWO();
526 void emitDebugMacinfoImpl(MCSection *Section);
527 void emitMacro(DIMacro &M);
528 void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
529 void emitMacroFileImpl(DIMacroFile &F, DwarfCompileUnit &U,
530 unsigned StartFile, unsigned EndFile,
531 StringRef (*MacroFormToString)(unsigned Form));
532 void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
534 /// DWARF 5 Experimental Split Dwarf Emitters
536 /// Initialize common features of skeleton units.
537 void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
538 std::unique_ptr<DwarfCompileUnit> NewU);
540 /// Construct the split debug info compile unit for the debug info section.
541 /// In DWARF v5, the skeleton unit DIE may have the following attributes:
542 /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
543 /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
544 /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
545 /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
546 /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
547 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
549 /// Emit the debug info dwo section.
550 void emitDebugInfoDWO();
552 /// Emit the debug abbrev dwo section.
553 void emitDebugAbbrevDWO();
555 /// Emit the debug line dwo section.
556 void emitDebugLineDWO();
558 /// Emit the dwo stringoffsets table header.
559 void emitStringOffsetsTableHeaderDWO();
561 /// Emit the debug str dwo section.
562 void emitDebugStrDWO();
564 /// Emit DWO addresses.
565 void emitDebugAddr();
567 /// Flags to let the linker know we have emitted new style pubnames. Only
568 /// emit it here if we don't have a skeleton CU for split dwarf.
569 void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
571 /// Create new DwarfCompileUnit for the given metadata node with tag
572 /// DW_TAG_compile_unit.
573 DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
574 void finishUnitAttributes(const DICompileUnit *DIUnit,
575 DwarfCompileUnit &NewCU);
577 /// Construct imported_module or imported_declaration DIE.
578 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
579 const DIImportedEntity *N);
581 /// Register a source line with debug info. Returns the unique
582 /// label that was emitted and which provides correspondence to the
583 /// source line list.
584 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
587 /// Populate LexicalScope entries with variables' info.
588 void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
589 DenseSet<InlinedEntity> &ProcessedVars);
591 /// Build the location list for all DBG_VALUEs in the
592 /// function that describe the same variable. If the resulting
593 /// list has only one entry that is valid for entire variable's
594 /// scope return true.
595 bool buildLocationList(
596 SmallVectorImpl<DebugLocEntry> &DebugLoc,
597 const DbgValueHistoryMap::Entries &Entries,
598 DenseSet<const MachineBasicBlock *> &VeryLargeBlocks);
600 /// Collect variable information from the side table maintained by MF.
601 void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
602 DenseSet<InlinedEntity> &P);
604 /// Emit the reference to the section.
605 void emitSectionReference(const DwarfCompileUnit &CU);
608 /// Gather pre-function debug information.
609 void beginFunctionImpl(const MachineFunction *MF) override;
611 /// Gather and emit post-function debug information.
612 void endFunctionImpl(const MachineFunction *MF) override;
614 void skippedNonDebugFunction() override;
617 //===--------------------------------------------------------------------===//
618 // Main entry points.
620 DwarfDebug(AsmPrinter *A, Module *M);
622 ~DwarfDebug() override;
624 /// Emit all Dwarf sections that should come prior to the
628 /// Emit all Dwarf sections that should come after the content.
629 void endModule() override;
631 /// Emits inital debug location directive.
632 DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
634 /// Process beginning of an instruction.
635 void beginInstruction(const MachineInstr *MI) override;
637 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
638 static uint64_t makeTypeSignature(StringRef Identifier);
640 /// Add a DIE to the set of types that we're going to pull into
642 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
643 DIE &Die, const DICompositeType *CTy);
645 class NonTypeUnitContext {
647 decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
648 friend class DwarfDebug;
649 NonTypeUnitContext(DwarfDebug *DD);
651 NonTypeUnitContext(NonTypeUnitContext&&) = default;
652 ~NonTypeUnitContext();
655 NonTypeUnitContext enterNonTypeUnitContext();
657 /// Add a label so that arange data can be generated for it.
658 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
660 /// For symbols that have a size designated (e.g. common symbols),
661 /// this tracks that size.
662 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
666 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
667 /// If not, we still might emit certain cases.
668 bool useAllLinkageNames() const { return UseAllLinkageNames; }
670 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
671 /// standard DW_OP_form_tls_address opcode
672 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
674 /// Returns whether to use the DWARF2 format for bitfields instyead of the
676 bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
678 /// Returns whether to use inline strings.
679 bool useInlineStrings() const { return UseInlineStrings; }
681 /// Returns whether ranges section should be emitted.
682 bool useRangesSection() const { return UseRangesSection; }
684 /// Returns whether to use sections as labels rather than temp symbols.
685 bool useSectionsAsReferences() const {
686 return UseSectionsAsReferences;
689 /// Returns whether .debug_loc section should be emitted.
690 bool useLocSection() const { return UseLocSection; }
692 /// Returns whether to generate DWARF v4 type units.
693 bool generateTypeUnits() const { return GenerateTypeUnits; }
695 // Experimental DWARF5 features.
697 /// Returns what kind (if any) of accelerator tables to emit.
698 AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
700 bool useAppleExtensionAttributes() const {
701 return HasAppleExtensionAttributes;
704 /// Returns whether or not to change the current debug info for the
705 /// split dwarf proposal support.
706 bool useSplitDwarf() const { return HasSplitDwarf; }
708 /// Returns whether to generate a string offsets table with (possibly shared)
709 /// contributions from each CU and type unit. This implies the use of
710 /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
711 /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
712 /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
713 /// monolithic string offsets table.
714 bool useSegmentedStringOffsetsTable() const {
715 return UseSegmentedStringOffsetsTable;
718 bool emitDebugEntryValues() const {
719 return EmitDebugEntryValues;
722 bool shareAcrossDWOCUs() const;
724 /// Returns the Dwarf Version.
725 uint16_t getDwarfVersion() const;
727 /// Returns the previous CU that was being updated
728 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
729 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
731 /// Returns the entries for the .debug_loc section.
732 const DebugLocStream &getDebugLocs() const { return DebugLocs; }
734 /// Emit an entry for the debug loc section. This can be used to
735 /// handle an entry that's going to be emitted into the debug loc section.
736 void emitDebugLocEntry(ByteStreamer &Streamer,
737 const DebugLocStream::Entry &Entry,
738 const DwarfCompileUnit *CU);
740 /// Emit the location for a debug loc entry, including the size header.
741 void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry,
742 const DwarfCompileUnit *CU);
744 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
747 AddressPool &getAddressPool() { return AddrPool; }
749 void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
751 void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
753 void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
756 void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
759 const MachineFunction *getCurrentFunction() const { return CurFn; }
761 /// A helper function to check whether the DIE for a given Scope is
762 /// going to be null.
763 bool isLexicalScopeDIENull(LexicalScope *Scope);
765 /// Find the matching DwarfCompileUnit for the given CU DIE.
766 DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
767 const DwarfCompileUnit *lookupCU(const DIE *Die) const {
768 return CUDieMap.lookup(Die);
771 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
773 /// Returns whether we are "tuning" for a given debugger.
775 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
776 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
777 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
780 void addSectionLabel(const MCSymbol *Sym);
781 const MCSymbol *getSectionLabel(const MCSection *S);
782 void insertSectionLabel(const MCSymbol *S);
784 static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
785 const DbgValueLoc &Value,
786 DwarfExpression &DwarfExpr);
789 } // end namespace llvm
791 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H