1 //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf debug info into asm files.
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
17 #include "AsmPrinterHandler.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/CodeGen/LexicalScopes.h"
25 #include "llvm/IR/DebugInfo.h"
26 #include "llvm/IR/DebugLoc.h"
27 #include "llvm/MC/MachineLocation.h"
28 #include "llvm/MC/MCDwarf.h"
29 #include "llvm/Support/Allocator.h"
37 class DwarfCompileUnit;
41 class MachineModuleInfo;
43 //===----------------------------------------------------------------------===//
44 /// \brief This class is used to record source line correspondence.
46 unsigned Line; // Source line number.
47 unsigned Column; // Source column.
48 unsigned SourceID; // Source ID number.
49 MCSymbol *Label; // Label in code ID number.
51 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
52 : Line(L), Column(C), SourceID(S), Label(label) {}
55 unsigned getLine() const { return Line; }
56 unsigned getColumn() const { return Column; }
57 unsigned getSourceID() const { return SourceID; }
58 MCSymbol *getLabel() const { return Label; }
61 /// \brief This struct describes location entries emitted in the .debug_loc
64 // Begin and end symbols for the address range that this location is valid.
65 const MCSymbol *Begin;
68 // Type of entry that this represents.
69 enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
70 enum EntryType EntryKind;
74 const ConstantFP *CFP;
75 const ConstantInt *CIP;
78 // The location in the machine frame.
81 // The variable to which this location entry corresponds.
82 const MDNode *Variable;
84 // The compile unit to which this location entry is referenced by.
85 const DwarfCompileUnit *Unit;
88 DebugLocEntry() : Begin(0), End(0), Variable(0), Unit(0) {
91 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
92 const MDNode *V, const DwarfCompileUnit *U)
93 : Begin(B), End(E), Loc(L), Variable(V), Unit(U) {
95 EntryKind = E_Location;
97 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i,
98 const DwarfCompileUnit *U)
99 : Begin(B), End(E), Variable(0), Unit(U) {
101 EntryKind = E_Integer;
103 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr,
104 const DwarfCompileUnit *U)
105 : Begin(B), End(E), Variable(0), Unit(U) {
106 Constants.CFP = FPtr;
107 EntryKind = E_ConstantFP;
109 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr,
110 const DwarfCompileUnit *U)
111 : Begin(B), End(E), Variable(0), Unit(U) {
112 Constants.CIP = IPtr;
113 EntryKind = E_ConstantInt;
116 /// \brief Empty entries are also used as a trigger to emit temp label. Such
117 /// labels are referenced is used to find debug_loc offset for a given DIE.
118 bool isEmpty() const { return Begin == 0 && End == 0; }
119 bool Merge(const DebugLocEntry &Next) {
122 EntryKind == Next.EntryKind &&
123 (!isInt() || getInt() == Next.getInt()) &&
124 (!isConstantInt() || getConstantInt() == Next.getConstantInt()) &&
125 (!isConstantFP() || getConstantFP() == Next.getConstantFP()) &&
132 bool isLocation() const { return EntryKind == E_Location; }
133 bool isInt() const { return EntryKind == E_Integer; }
134 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
135 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
136 int64_t getInt() const { return Constants.Int; }
137 const ConstantFP *getConstantFP() const { return Constants.CFP; }
138 const ConstantInt *getConstantInt() const { return Constants.CIP; }
139 const MDNode *getVariable() const { return Variable; }
140 const MCSymbol *getBeginSym() const { return Begin; }
141 const MCSymbol *getEndSym() const { return End; }
142 const DwarfCompileUnit *getCU() const { return Unit; }
143 MachineLocation getLoc() const { return Loc; }
146 //===----------------------------------------------------------------------===//
147 /// \brief This class is used to track local variable information.
149 DIVariable Var; // Variable Descriptor.
150 DIE *TheDIE; // Variable DIE.
151 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
152 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
153 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
158 // AbsVar may be NULL.
159 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
160 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
161 FrameIndex(~0), DD(DD) {}
164 DIVariable getVariable() const { return Var; }
165 void setDIE(DIE *D) { TheDIE = D; }
166 DIE *getDIE() const { return TheDIE; }
167 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
168 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
169 StringRef getName() const { return Var.getName(); }
170 DbgVariable *getAbstractVariable() const { return AbsVar; }
171 const MachineInstr *getMInsn() const { return MInsn; }
172 void setMInsn(const MachineInstr *M) { MInsn = M; }
173 int getFrameIndex() const { return FrameIndex; }
174 void setFrameIndex(int FI) { FrameIndex = FI; }
175 // Translate tag to proper Dwarf tag.
176 uint16_t getTag() const {
177 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
178 return dwarf::DW_TAG_formal_parameter;
180 return dwarf::DW_TAG_variable;
182 /// \brief Return true if DbgVariable is artificial.
183 bool isArtificial() const {
184 if (Var.isArtificial())
186 if (getType().isArtificial())
191 bool isObjectPointer() const {
192 if (Var.isObjectPointer())
194 if (getType().isObjectPointer())
199 bool variableHasComplexAddress() const {
200 assert(Var.isVariable() && "Invalid complex DbgVariable!");
201 return Var.hasComplexAddress();
203 bool isBlockByrefVariable() const;
204 unsigned getNumAddrElements() const {
205 assert(Var.isVariable() && "Invalid complex DbgVariable!");
206 return Var.getNumAddrElements();
208 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
209 DIType getType() const;
212 /// resolve - Look in the DwarfDebug map for the MDNode that
213 /// corresponds to the reference.
214 template <typename T> T resolve(DIRef<T> Ref) const;
217 /// \brief Collects and handles information specific to a particular
218 /// collection of units. This collection represents all of the units
219 /// that will be ultimately output into a single object file.
221 // Target of Dwarf emission, used for sizing of abbreviations.
224 // Used to uniquely define abbreviations.
225 FoldingSet<DIEAbbrev> AbbreviationsSet;
227 // A list of all the unique abbreviations in use.
228 std::vector<DIEAbbrev *> Abbreviations;
230 // A pointer to all units in the section.
231 SmallVector<DwarfUnit *, 1> CUs;
233 // Collection of strings for this unit and assorted symbols.
234 // A String->Symbol mapping of strings used by indirect
236 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
239 unsigned NextStringPoolNumber;
240 std::string StringPref;
242 struct AddressPoolEntry {
245 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
247 // Collection of addresses for this unit and assorted labels.
248 // A Symbol->unsigned mapping of addresses used by indirect
250 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
251 AddrPool AddressPool;
252 unsigned NextAddrPoolNumber;
255 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
256 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
257 AddressPool(), NextAddrPoolNumber(0) {}
261 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
263 /// \brief Compute the size and offset of a DIE given an incoming Offset.
264 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
266 /// \brief Compute the size and offset of all the DIEs.
267 void computeSizeAndOffsets();
269 /// \brief Define a unique number for the abbreviation.
270 void assignAbbrevNumber(DIEAbbrev &Abbrev);
272 /// \brief Add a unit to the list of CUs.
273 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
275 /// \brief Emit all of the units to the section listed with the given
276 /// abbreviation section.
277 void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
279 /// \brief Emit a set of abbreviations to the specific section.
280 void emitAbbrevs(const MCSection *);
282 /// \brief Emit all of the strings to the section given.
283 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
284 const MCSymbol *StrSecSym);
286 /// \brief Emit all of the addresses to the section given.
287 void emitAddresses(const MCSection *AddrSection);
289 /// \brief Returns the entry into the start of the pool.
290 MCSymbol *getStringPoolSym();
292 /// \brief Returns an entry into the string pool with the given
294 MCSymbol *getStringPoolEntry(StringRef Str);
296 /// \brief Returns the index into the string pool with the given
298 unsigned getStringPoolIndex(StringRef Str);
300 /// \brief Returns the string pool.
301 StrPool *getStringPool() { return &StringPool; }
303 /// \brief Returns the index into the address pool with the given
305 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
307 /// \brief Returns the address pool.
308 AddrPool *getAddrPool() { return &AddressPool; }
311 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
313 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
315 DwarfCompileUnit *CU;
318 /// \brief Collects and handles dwarf debug information.
319 class DwarfDebug : public AsmPrinterHandler {
320 // Target of Dwarf emission.
323 // Collected machine module information.
324 MachineModuleInfo *MMI;
326 // All DIEValues are allocated through this allocator.
327 BumpPtrAllocator DIEValueAllocator;
329 // Handle to the compile unit used for the inline extension handling,
330 // this is just so that the DIEValue allocator has a place to store
331 // the particular elements.
332 // FIXME: Store these off of DwarfDebug instead?
333 DwarfCompileUnit *FirstCU;
335 // Maps MDNode with its corresponding DwarfCompileUnit.
336 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
338 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
339 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
341 // Maps a CU DIE with its corresponding DwarfCompileUnit.
342 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
344 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
345 /// be shared across CUs, that is why we keep the map here instead
346 /// of in DwarfCompileUnit.
347 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
349 // List of all labels used in aranges generation.
350 std::vector<SymbolCU> ArangeLabels;
352 // Size of each symbol emitted (for those symbols that have a specific size).
353 DenseMap<const MCSymbol *, uint64_t> SymSize;
355 // Provides a unique id per text section.
356 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
357 SectionMapType SectionMap;
359 // List of arguments for current function.
360 SmallVector<DbgVariable *, 8> CurrentFnArguments;
362 LexicalScopes LScopes;
364 // Collection of abstract subprogram DIEs.
365 DenseMap<const MDNode *, DIE *> AbstractSPDies;
367 // Collection of dbg variables of a scope.
368 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
370 ScopeVariablesMap ScopeVariables;
372 // Collection of abstract variables.
373 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
375 // Collection of DebugLocEntry.
376 SmallVector<SmallVector<DebugLocEntry, 4>, 4> DotDebugLocEntries;
378 // Collection of subprogram DIEs that are marked (at the end of the module)
380 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
382 // This is a collection of subprogram MDNodes that are processed to
384 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
386 // Maps instruction with label emitted before instruction.
387 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
389 // Maps instruction with label emitted after instruction.
390 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
392 // Every user variable mentioned by a DBG_VALUE instruction in order of
394 SmallVector<const MDNode *, 8> UserVariables;
396 // For each user variable, keep a list of DBG_VALUE instructions in order.
397 // The list can also contain normal instructions that clobber the previous
399 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
401 DbgValueHistoryMap DbgValues;
403 // Previous instruction's location information. This is used to determine
404 // label location to indicate scope boundries in dwarf debug info.
405 DebugLoc PrevInstLoc;
408 // This location indicates end of function prologue and beginning of function
410 DebugLoc PrologEndLoc;
412 // If nonnull, stores the current machine function we're processing.
413 const MachineFunction *CurFn;
415 // If nonnull, stores the current machine instruction we're processing.
416 const MachineInstr *CurMI;
418 // If nonnull, stores the section that the previous function was allocated to
420 const MCSection *PrevSection;
422 // If nonnull, stores the CU in which the previous subprogram was contained.
423 const DwarfCompileUnit *PrevCU;
425 // Section Symbols: these are assembler temporary labels that are emitted at
426 // the beginning of each supported dwarf section. These are used to form
427 // section offsets and are created by EmitSectionLabels.
428 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
429 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
430 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
431 MCSymbol *FunctionBeginSym, *FunctionEndSym;
432 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
433 MCSymbol *DwarfStrDWOSectionSym;
434 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
436 // As an optimization, there is no need to emit an entry in the directory
437 // table for the same directory as DW_AT_comp_dir.
438 StringRef CompilationDir;
440 // Counter for assigning globally unique IDs for ranges.
441 unsigned GlobalRangeCount;
443 // Holder for the file specific debug information.
444 DwarfFile InfoHolder;
446 // Holders for the various debug information flags that we might need to
447 // have exposed. See accessor functions below for description.
449 // Holder for imported entities.
450 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
452 ImportedEntityMap ScopesWithImportedEntities;
454 // Map from MDNodes for user-defined types to the type units that describe
456 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
458 // Whether to emit the pubnames/pubtypes sections.
459 bool HasDwarfPubSections;
461 // Whether or not to use AT_ranges for compilation units.
464 // Whether we emitted a function into a section other than the default
466 bool UsedNonDefaultText;
468 // Version of dwarf we're emitting.
469 unsigned DwarfVersion;
471 // Maps from a type identifier to the actual MDNode.
472 DITypeIdentifierMap TypeIdentifierMap;
474 // DWARF5 Experimental Options
475 bool HasDwarfAccelTables;
478 // Separated Dwarf Variables
479 // In general these will all be for bits that are left in the
480 // original object file, rather than things that are meant
481 // to be in the .dwo sections.
483 // Holder for the skeleton information.
484 DwarfFile SkeletonHolder;
486 /// Store file names for type units under fission in a line table header that
487 /// will be emitted into debug_line.dwo.
488 // FIXME: replace this with a map from comp_dir to table so that we can emit
489 // multiple tables during LTO each of which uses directory 0, referencing the
490 // comp_dir of all the type units that use it.
491 MCDwarfDwoLineTable SplitTypeUnitFileTable;
493 // True iff there are multiple CUs in this module.
496 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
498 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
500 const SmallVectorImpl<DwarfUnit *> &getUnits() {
501 return InfoHolder.getUnits();
504 /// \brief Find abstract variable associated with Var.
505 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
507 /// \brief Find DIE for the given subprogram and attach appropriate
508 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
509 /// variables in this scope then create and insert DIEs for these
511 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
513 /// \brief A helper function to check whether the DIE for a given Scope is
514 /// going to be null.
515 bool isLexicalScopeDIENull(LexicalScope *Scope);
517 /// \brief A helper function to construct a RangeSpanList for a given
519 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
520 const SmallVectorImpl<InsnRange> &Range);
522 /// \brief Construct new DW_TAG_lexical_block for this scope and
523 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
524 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
526 /// \brief This scope represents inlined body of a function. Construct
527 /// DIE to represent this concrete inlined copy of the function.
528 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
530 /// \brief Construct a DIE for this scope.
531 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
532 /// A helper function to create children of a Scope DIE.
533 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
534 SmallVectorImpl<DIE *> &Children);
536 /// \brief Emit initial Dwarf sections with a label at the start of each one.
537 void emitSectionLabels();
539 /// \brief Compute the size and offset of a DIE given an incoming Offset.
540 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
542 /// \brief Compute the size and offset of all the DIEs.
543 void computeSizeAndOffsets();
545 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
546 void computeInlinedDIEs();
548 /// \brief Collect info for variables that were optimized out.
549 void collectDeadVariables();
551 /// \brief Finish off debug information after all functions have been
553 void finalizeModuleInfo();
555 /// \brief Emit labels to close any remaining sections that have been left
559 /// \brief Emit the debug info section.
560 void emitDebugInfo();
562 /// \brief Emit the abbreviation section.
563 void emitAbbreviations();
565 /// \brief Emit the last address of the section and the end of
567 void emitEndOfLineMatrix(unsigned SectionEnd);
569 /// \brief Emit visible names into a hashed accelerator table section.
570 void emitAccelNames();
572 /// \brief Emit objective C classes and categories into a hashed
573 /// accelerator table section.
574 void emitAccelObjC();
576 /// \brief Emit namespace dies into a hashed accelerator table.
577 void emitAccelNamespaces();
579 /// \brief Emit type dies into a hashed accelerator table.
580 void emitAccelTypes();
582 /// \brief Emit visible names into a debug pubnames section.
583 /// \param GnuStyle determines whether or not we want to emit
584 /// additional information into the table ala newer gcc for gdb
586 void emitDebugPubNames(bool GnuStyle = false);
588 /// \brief Emit visible types into a debug pubtypes section.
589 /// \param GnuStyle determines whether or not we want to emit
590 /// additional information into the table ala newer gcc for gdb
592 void emitDebugPubTypes(bool GnuStyle = false);
595 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
596 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
599 /// \brief Emit visible names into a debug str section.
602 /// \brief Emit visible names into a debug loc section.
605 /// \brief Emit visible names into a debug aranges section.
606 void emitDebugARanges();
608 /// \brief Emit visible names into a debug ranges section.
609 void emitDebugRanges();
611 /// \brief Emit inline info using custom format.
612 void emitDebugInlineInfo();
614 /// DWARF 5 Experimental Split Dwarf Emitters
616 /// \brief Initialize common features of skeleton units.
617 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
619 /// \brief Construct the split debug info compile unit for the debug info
621 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
623 /// \brief Construct the split debug info compile unit for the debug info
625 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
627 /// \brief Emit the debug info dwo section.
628 void emitDebugInfoDWO();
630 /// \brief Emit the debug abbrev dwo section.
631 void emitDebugAbbrevDWO();
633 /// \brief Emit the debug line dwo section.
634 void emitDebugLineDWO();
636 /// \brief Emit the debug str dwo section.
637 void emitDebugStrDWO();
639 /// Flags to let the linker know we have emitted new style pubnames. Only
640 /// emit it here if we don't have a skeleton CU for split dwarf.
641 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
643 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
644 /// DW_TAG_compile_unit.
645 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
647 /// \brief Construct subprogram DIE.
648 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
650 /// \brief Construct imported_module or imported_declaration DIE.
651 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
653 /// \brief Construct import_module DIE.
654 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
657 /// \brief Construct import_module DIE.
658 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
659 const DIImportedEntity &Module, DIE *Context);
661 /// \brief Register a source line with debug info. Returns the unique
662 /// label that was emitted and which provides correspondence to the
663 /// source line list.
664 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
667 /// \brief Indentify instructions that are marking the beginning of or
668 /// ending of a scope.
669 void identifyScopeMarkers();
671 /// \brief If Var is an current function argument that add it in
672 /// CurrentFnArguments list.
673 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
675 /// \brief Populate LexicalScope entries with variables' info.
676 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
678 /// \brief Collect variable information from the side table maintained
680 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
682 /// \brief Ensure that a label will be emitted before MI.
683 void requestLabelBeforeInsn(const MachineInstr *MI) {
684 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
687 /// \brief Return Label preceding the instruction.
688 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
690 /// \brief Ensure that a label will be emitted after MI.
691 void requestLabelAfterInsn(const MachineInstr *MI) {
692 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
695 /// \brief Return Label immediately following the instruction.
696 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
698 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
702 //===--------------------------------------------------------------------===//
703 // Main entry points.
705 DwarfDebug(AsmPrinter *A, Module *M);
707 void insertDIE(const MDNode *TypeMD, DIE *Die) {
708 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
710 DIE *getDIE(const MDNode *TypeMD) {
711 return MDTypeNodeToDieMap.lookup(TypeMD);
714 /// \brief Emit all Dwarf sections that should come prior to the
718 /// \brief Emit all Dwarf sections that should come after the content.
719 void endModule() override;
721 /// \brief Gather pre-function debug information.
722 void beginFunction(const MachineFunction *MF) override;
724 /// \brief Gather and emit post-function debug information.
725 void endFunction(const MachineFunction *MF) override;
727 /// \brief Process beginning of an instruction.
728 void beginInstruction(const MachineInstr *MI) override;
730 /// \brief Process end of an instruction.
731 void endInstruction() override;
733 /// \brief Add a DIE to the set of types that we're going to pull into
735 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
736 DIE *Die, DICompositeType CTy);
738 /// \brief Add a label so that arange data can be generated for it.
739 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
741 /// \brief For symbols that have a size designated (e.g. common symbols),
742 /// this tracks that size.
743 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
747 /// \brief Recursively Emits a debug information entry.
748 void emitDIE(DIE *Die);
750 // Experimental DWARF5 features.
752 /// \brief Returns whether or not to emit tables that dwarf consumers can
753 /// use to accelerate lookup.
754 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
756 /// \brief Returns whether or not to change the current debug info for the
757 /// split dwarf proposal support.
758 bool useSplitDwarf() const { return HasSplitDwarf; }
760 /// Returns the Dwarf Version.
761 unsigned getDwarfVersion() const { return DwarfVersion; }
763 /// Returns the section symbol for the .debug_loc section.
764 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
766 /// Returns the previous section that was emitted into.
767 const MCSection *getPrevSection() const { return PrevSection; }
769 /// Returns the previous CU that was being updated
770 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
772 /// Returns the entries for the .debug_loc section.
773 const SmallVectorImpl<SmallVector<DebugLocEntry, 4>> &
774 getDebugLocEntries() const {
775 return DotDebugLocEntries;
778 /// \brief Emit an entry for the debug loc section. This can be used to
779 /// handle an entry that's going to be emitted into the debug loc section.
780 void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
782 /// Emit the location for a debug loc entry, including the size header.
783 void emitDebugLocEntryLocation(const DebugLocEntry &Entry);
785 /// Find the MDNode for the given reference.
786 template <typename T> T resolve(DIRef<T> Ref) const {
787 return Ref.resolve(TypeIdentifierMap);
790 /// \brief Return the TypeIdentifierMap.
791 const DITypeIdentifierMap &getTypeIdentifierMap() const {
792 return TypeIdentifierMap;
795 /// Find the DwarfCompileUnit for the given CU Die.
796 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
797 return CUDieMap.lookup(CU);
799 /// isSubprogramContext - Return true if Context is either a subprogram
800 /// or another context nested inside a subprogram.
801 bool isSubprogramContext(const MDNode *Context);
803 } // End of namespace llvm