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;
87 // Whether this location has been merged.
91 DebugLocEntry() : Begin(0), End(0), Variable(0), Unit(0), Merged(false) {
94 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
95 const MDNode *V, const DwarfCompileUnit *U)
96 : Begin(B), End(E), Loc(L), Variable(V), Unit(U), Merged(false) {
98 EntryKind = E_Location;
100 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i,
101 const DwarfCompileUnit *U)
102 : Begin(B), End(E), Variable(0), Unit(U), Merged(false) {
104 EntryKind = E_Integer;
106 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr,
107 const DwarfCompileUnit *U)
108 : Begin(B), End(E), Variable(0), Unit(U), Merged(false) {
109 Constants.CFP = FPtr;
110 EntryKind = E_ConstantFP;
112 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr,
113 const DwarfCompileUnit *U)
114 : Begin(B), End(E), Variable(0), Unit(U), Merged(false) {
115 Constants.CIP = IPtr;
116 EntryKind = E_ConstantInt;
119 /// \brief Empty entries are also used as a trigger to emit temp label. Such
120 /// labels are referenced is used to find debug_loc offset for a given DIE.
121 bool isEmpty() const { return Begin == 0 && End == 0; }
122 bool isMerged() const { return Merged; }
123 void Merge(DebugLocEntry *Next) {
124 if (!(Begin && Loc == Next->Loc && End == Next->Begin))
129 bool isLocation() const { return EntryKind == E_Location; }
130 bool isInt() const { return EntryKind == E_Integer; }
131 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
132 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
133 int64_t getInt() const { return Constants.Int; }
134 const ConstantFP *getConstantFP() const { return Constants.CFP; }
135 const ConstantInt *getConstantInt() const { return Constants.CIP; }
136 const MDNode *getVariable() const { return Variable; }
137 const MCSymbol *getBeginSym() const { return Begin; }
138 const MCSymbol *getEndSym() const { return End; }
139 const DwarfCompileUnit *getCU() const { return Unit; }
140 MachineLocation getLoc() const { return Loc; }
143 //===----------------------------------------------------------------------===//
144 /// \brief This class is used to track local variable information.
146 DIVariable Var; // Variable Descriptor.
147 DIE *TheDIE; // Variable DIE.
148 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
149 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
150 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
155 // AbsVar may be NULL.
156 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
157 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
158 FrameIndex(~0), DD(DD) {}
161 DIVariable getVariable() const { return Var; }
162 void setDIE(DIE *D) { TheDIE = D; }
163 DIE *getDIE() const { return TheDIE; }
164 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
165 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
166 StringRef getName() const { return Var.getName(); }
167 DbgVariable *getAbstractVariable() const { return AbsVar; }
168 const MachineInstr *getMInsn() const { return MInsn; }
169 void setMInsn(const MachineInstr *M) { MInsn = M; }
170 int getFrameIndex() const { return FrameIndex; }
171 void setFrameIndex(int FI) { FrameIndex = FI; }
172 // Translate tag to proper Dwarf tag.
173 uint16_t getTag() const {
174 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
175 return dwarf::DW_TAG_formal_parameter;
177 return dwarf::DW_TAG_variable;
179 /// \brief Return true if DbgVariable is artificial.
180 bool isArtificial() const {
181 if (Var.isArtificial())
183 if (getType().isArtificial())
188 bool isObjectPointer() const {
189 if (Var.isObjectPointer())
191 if (getType().isObjectPointer())
196 bool variableHasComplexAddress() const {
197 assert(Var.isVariable() && "Invalid complex DbgVariable!");
198 return Var.hasComplexAddress();
200 bool isBlockByrefVariable() const;
201 unsigned getNumAddrElements() const {
202 assert(Var.isVariable() && "Invalid complex DbgVariable!");
203 return Var.getNumAddrElements();
205 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
206 DIType getType() const;
209 /// resolve - Look in the DwarfDebug map for the MDNode that
210 /// corresponds to the reference.
211 template <typename T> T resolve(DIRef<T> Ref) const;
214 /// \brief Collects and handles information specific to a particular
215 /// collection of units. This collection represents all of the units
216 /// that will be ultimately output into a single object file.
218 // Target of Dwarf emission, used for sizing of abbreviations.
221 // Used to uniquely define abbreviations.
222 FoldingSet<DIEAbbrev> AbbreviationsSet;
224 // A list of all the unique abbreviations in use.
225 std::vector<DIEAbbrev *> Abbreviations;
227 // A pointer to all units in the section.
228 SmallVector<DwarfUnit *, 1> CUs;
230 // Collection of strings for this unit and assorted symbols.
231 // A String->Symbol mapping of strings used by indirect
233 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
236 unsigned NextStringPoolNumber;
237 std::string StringPref;
239 struct AddressPoolEntry {
242 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
244 // Collection of addresses for this unit and assorted labels.
245 // A Symbol->unsigned mapping of addresses used by indirect
247 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
248 AddrPool AddressPool;
249 unsigned NextAddrPoolNumber;
252 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
253 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
254 AddressPool(), NextAddrPoolNumber(0) {}
258 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
260 /// \brief Compute the size and offset of a DIE given an incoming Offset.
261 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
263 /// \brief Compute the size and offset of all the DIEs.
264 void computeSizeAndOffsets();
266 /// \brief Define a unique number for the abbreviation.
267 void assignAbbrevNumber(DIEAbbrev &Abbrev);
269 /// \brief Add a unit to the list of CUs.
270 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
272 /// \brief Emit all of the units to the section listed with the given
273 /// abbreviation section.
274 void emitUnits(DwarfDebug *DD, const MCSection *ASection,
275 const MCSymbol *ASectionSym);
277 /// \brief Emit a set of abbreviations to the specific section.
278 void emitAbbrevs(const MCSection *);
280 /// \brief Emit all of the strings to the section given.
281 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
282 const MCSymbol *StrSecSym);
284 /// \brief Emit all of the addresses to the section given.
285 void emitAddresses(const MCSection *AddrSection);
287 /// \brief Returns the entry into the start of the pool.
288 MCSymbol *getStringPoolSym();
290 /// \brief Returns an entry into the string pool with the given
292 MCSymbol *getStringPoolEntry(StringRef Str);
294 /// \brief Returns the index into the string pool with the given
296 unsigned getStringPoolIndex(StringRef Str);
298 /// \brief Returns the string pool.
299 StrPool *getStringPool() { return &StringPool; }
301 /// \brief Returns the index into the address pool with the given
303 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
305 /// \brief Returns the address pool.
306 AddrPool *getAddrPool() { return &AddressPool; }
309 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
311 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
313 DwarfCompileUnit *CU;
316 /// \brief Collects and handles dwarf debug information.
317 class DwarfDebug : public AsmPrinterHandler {
318 // Target of Dwarf emission.
321 // Collected machine module information.
322 MachineModuleInfo *MMI;
324 // All DIEValues are allocated through this allocator.
325 BumpPtrAllocator DIEValueAllocator;
327 // Handle to the compile unit used for the inline extension handling,
328 // this is just so that the DIEValue allocator has a place to store
329 // the particular elements.
330 // FIXME: Store these off of DwarfDebug instead?
331 DwarfCompileUnit *FirstCU;
333 // Maps MDNode with its corresponding DwarfCompileUnit.
334 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
336 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
337 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
339 // Maps a CU DIE with its corresponding DwarfCompileUnit.
340 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
342 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
343 /// be shared across CUs, that is why we keep the map here instead
344 /// of in DwarfCompileUnit.
345 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
347 // List of all labels used in aranges generation.
348 std::vector<SymbolCU> ArangeLabels;
350 // Size of each symbol emitted (for those symbols that have a specific size).
351 DenseMap<const MCSymbol *, uint64_t> SymSize;
353 // Provides a unique id per text section.
354 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
355 SectionMapType SectionMap;
357 // List of arguments for current function.
358 SmallVector<DbgVariable *, 8> CurrentFnArguments;
360 LexicalScopes LScopes;
362 // Collection of abstract subprogram DIEs.
363 DenseMap<const MDNode *, DIE *> AbstractSPDies;
365 // Collection of dbg variables of a scope.
366 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
368 ScopeVariablesMap ScopeVariables;
370 // Collection of abstract variables.
371 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
373 // Collection of DebugLocEntry.
374 SmallVector<DebugLocEntry, 4> DotDebugLocEntries;
376 // Collection of subprogram DIEs that are marked (at the end of the module)
378 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
380 // This is a collection of subprogram MDNodes that are processed to
382 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
384 // Maps instruction with label emitted before instruction.
385 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
387 // Maps instruction with label emitted after instruction.
388 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
390 // Every user variable mentioned by a DBG_VALUE instruction in order of
392 SmallVector<const MDNode *, 8> UserVariables;
394 // For each user variable, keep a list of DBG_VALUE instructions in order.
395 // The list can also contain normal instructions that clobber the previous
397 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
399 DbgValueHistoryMap DbgValues;
401 // Previous instruction's location information. This is used to determine
402 // label location to indicate scope boundries in dwarf debug info.
403 DebugLoc PrevInstLoc;
406 // This location indicates end of function prologue and beginning of function
408 DebugLoc PrologEndLoc;
410 // If nonnull, stores the current machine function we're processing.
411 const MachineFunction *CurFn;
413 // If nonnull, stores the current machine instruction we're processing.
414 const MachineInstr *CurMI;
416 // If nonnull, stores the section that the previous function was allocated to
418 const MCSection *PrevSection;
420 // If nonnull, stores the CU in which the previous subprogram was contained.
421 const DwarfCompileUnit *PrevCU;
423 // Section Symbols: these are assembler temporary labels that are emitted at
424 // the beginning of each supported dwarf section. These are used to form
425 // section offsets and are created by EmitSectionLabels.
426 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
427 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
428 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
429 MCSymbol *FunctionBeginSym, *FunctionEndSym;
430 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
431 MCSymbol *DwarfStrDWOSectionSym;
432 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
434 // As an optimization, there is no need to emit an entry in the directory
435 // table for the same directory as DW_AT_comp_dir.
436 StringRef CompilationDir;
438 // Counter for assigning globally unique IDs for ranges.
439 unsigned GlobalRangeCount;
441 // Holder for the file specific debug information.
442 DwarfFile InfoHolder;
444 // Holders for the various debug information flags that we might need to
445 // have exposed. See accessor functions below for description.
447 // Holder for imported entities.
448 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
450 ImportedEntityMap ScopesWithImportedEntities;
452 // Map from MDNodes for user-defined types to the type units that describe
454 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
456 // Whether to emit the pubnames/pubtypes sections.
457 bool HasDwarfPubSections;
459 // Whether or not to use AT_ranges for compilation units.
462 // Whether we emitted a function into a section other than the default
464 bool UsedNonDefaultText;
466 // Version of dwarf we're emitting.
467 unsigned DwarfVersion;
469 // Maps from a type identifier to the actual MDNode.
470 DITypeIdentifierMap TypeIdentifierMap;
472 // DWARF5 Experimental Options
473 bool HasDwarfAccelTables;
476 // Separated Dwarf Variables
477 // In general these will all be for bits that are left in the
478 // original object file, rather than things that are meant
479 // to be in the .dwo sections.
481 // Holder for the skeleton information.
482 DwarfFile SkeletonHolder;
484 /// Store file names for type units under fission in a line table header that
485 /// will be emitted into debug_line.dwo.
486 // FIXME: replace this with a map from comp_dir to table so that we can emit
487 // multiple tables during LTO each of which uses directory 0, referencing the
488 // comp_dir of all the type units that use it.
489 MCDwarfDwoLineTable SplitTypeUnitFileTable;
491 // True iff there are multiple CUs in this module.
494 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
496 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
498 const SmallVectorImpl<DwarfUnit *> &getUnits() {
499 return InfoHolder.getUnits();
502 /// \brief Find abstract variable associated with Var.
503 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
505 /// \brief Find DIE for the given subprogram and attach appropriate
506 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
507 /// variables in this scope then create and insert DIEs for these
509 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
511 /// \brief A helper function to check whether the DIE for a given Scope is
512 /// going to be null.
513 bool isLexicalScopeDIENull(LexicalScope *Scope);
515 /// \brief A helper function to construct a RangeSpanList for a given
517 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
518 const SmallVectorImpl<InsnRange> &Range);
520 /// \brief Construct new DW_TAG_lexical_block for this scope and
521 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
522 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
524 /// \brief This scope represents inlined body of a function. Construct
525 /// DIE to represent this concrete inlined copy of the function.
526 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
528 /// \brief Construct a DIE for this scope.
529 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
530 /// A helper function to create children of a Scope DIE.
531 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
532 SmallVectorImpl<DIE *> &Children);
534 /// \brief Emit initial Dwarf sections with a label at the start of each one.
535 void emitSectionLabels();
537 /// \brief Compute the size and offset of a DIE given an incoming Offset.
538 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
540 /// \brief Compute the size and offset of all the DIEs.
541 void computeSizeAndOffsets();
543 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
544 void computeInlinedDIEs();
546 /// \brief Collect info for variables that were optimized out.
547 void collectDeadVariables();
549 /// \brief Finish off debug information after all functions have been
551 void finalizeModuleInfo();
553 /// \brief Emit labels to close any remaining sections that have been left
557 /// \brief Emit the debug info section.
558 void emitDebugInfo();
560 /// \brief Emit the abbreviation section.
561 void emitAbbreviations();
563 /// \brief Emit the last address of the section and the end of
565 void emitEndOfLineMatrix(unsigned SectionEnd);
567 /// \brief Emit visible names into a hashed accelerator table section.
568 void emitAccelNames();
570 /// \brief Emit objective C classes and categories into a hashed
571 /// accelerator table section.
572 void emitAccelObjC();
574 /// \brief Emit namespace dies into a hashed accelerator table.
575 void emitAccelNamespaces();
577 /// \brief Emit type dies into a hashed accelerator table.
578 void emitAccelTypes();
580 /// \brief Emit visible names into a debug pubnames section.
581 /// \param GnuStyle determines whether or not we want to emit
582 /// additional information into the table ala newer gcc for gdb
584 void emitDebugPubNames(bool GnuStyle = false);
586 /// \brief Emit visible types into a debug pubtypes section.
587 /// \param GnuStyle determines whether or not we want to emit
588 /// additional information into the table ala newer gcc for gdb
590 void emitDebugPubTypes(bool GnuStyle = false);
593 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
594 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
597 /// \brief Emit visible names into a debug str section.
600 /// \brief Emit visible names into a debug loc section.
603 /// \brief Emit visible names into a debug aranges section.
604 void emitDebugARanges();
606 /// \brief Emit visible names into a debug ranges section.
607 void emitDebugRanges();
609 /// \brief Emit inline info using custom format.
610 void emitDebugInlineInfo();
612 /// DWARF 5 Experimental Split Dwarf Emitters
614 /// \brief Initialize common features of skeleton units.
615 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
617 /// \brief Construct the split debug info compile unit for the debug info
619 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
621 /// \brief Construct the split debug info compile unit for the debug info
623 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
625 /// \brief Emit the debug info dwo section.
626 void emitDebugInfoDWO();
628 /// \brief Emit the debug abbrev dwo section.
629 void emitDebugAbbrevDWO();
631 /// \brief Emit the debug line dwo section.
632 void emitDebugLineDWO();
634 /// \brief Emit the debug str dwo section.
635 void emitDebugStrDWO();
637 /// Flags to let the linker know we have emitted new style pubnames. Only
638 /// emit it here if we don't have a skeleton CU for split dwarf.
639 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
641 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
642 /// DW_TAG_compile_unit.
643 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
645 /// \brief Construct subprogram DIE.
646 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
648 /// \brief Construct imported_module or imported_declaration DIE.
649 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
651 /// \brief Construct import_module DIE.
652 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
655 /// \brief Construct import_module DIE.
656 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
657 const DIImportedEntity &Module, DIE *Context);
659 /// \brief Register a source line with debug info. Returns the unique
660 /// label that was emitted and which provides correspondence to the
661 /// source line list.
662 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
665 /// \brief Indentify instructions that are marking the beginning of or
666 /// ending of a scope.
667 void identifyScopeMarkers();
669 /// \brief If Var is an current function argument that add it in
670 /// CurrentFnArguments list.
671 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
673 /// \brief Populate LexicalScope entries with variables' info.
674 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
676 /// \brief Collect variable information from the side table maintained
678 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
680 /// \brief Ensure that a label will be emitted before MI.
681 void requestLabelBeforeInsn(const MachineInstr *MI) {
682 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
685 /// \brief Return Label preceding the instruction.
686 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
688 /// \brief Ensure that a label will be emitted after MI.
689 void requestLabelAfterInsn(const MachineInstr *MI) {
690 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
693 /// \brief Return Label immediately following the instruction.
694 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
696 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
700 //===--------------------------------------------------------------------===//
701 // Main entry points.
703 DwarfDebug(AsmPrinter *A, Module *M);
705 void insertDIE(const MDNode *TypeMD, DIE *Die) {
706 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
708 DIE *getDIE(const MDNode *TypeMD) {
709 return MDTypeNodeToDieMap.lookup(TypeMD);
712 /// \brief Emit all Dwarf sections that should come prior to the
716 /// \brief Emit all Dwarf sections that should come after the content.
717 void endModule() override;
719 /// \brief Gather pre-function debug information.
720 void beginFunction(const MachineFunction *MF) override;
722 /// \brief Gather and emit post-function debug information.
723 void endFunction(const MachineFunction *MF) override;
725 /// \brief Process beginning of an instruction.
726 void beginInstruction(const MachineInstr *MI) override;
728 /// \brief Process end of an instruction.
729 void endInstruction() override;
731 /// \brief Add a DIE to the set of types that we're going to pull into
733 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
734 DIE *Die, DICompositeType CTy);
736 /// \brief Add a label so that arange data can be generated for it.
737 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
739 /// \brief For symbols that have a size designated (e.g. common symbols),
740 /// this tracks that size.
741 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
745 /// \brief Recursively Emits a debug information entry.
746 void emitDIE(DIE *Die);
748 // Experimental DWARF5 features.
750 /// \brief Returns whether or not to emit tables that dwarf consumers can
751 /// use to accelerate lookup.
752 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
754 /// \brief Returns whether or not to change the current debug info for the
755 /// split dwarf proposal support.
756 bool useSplitDwarf() const { return HasSplitDwarf; }
758 /// Returns the Dwarf Version.
759 unsigned getDwarfVersion() const { return DwarfVersion; }
761 /// Returns the section symbol for the .debug_loc section.
762 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
764 /// Returns the previous section that was emitted into.
765 const MCSection *getPrevSection() const { return PrevSection; }
767 /// Returns the previous CU that was being updated
768 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
770 /// Returns the entries for the .debug_loc section.
771 const SmallVectorImpl<DebugLocEntry> &getDebugLocEntries() const {
772 return DotDebugLocEntries;
775 /// \brief Emit an entry for the debug loc section. This can be used to
776 /// handle an entry that's going to be emitted into the debug loc section.
777 void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
779 /// Find the MDNode for the given reference.
780 template <typename T> T resolve(DIRef<T> Ref) const {
781 return Ref.resolve(TypeIdentifierMap);
784 /// \brief Return the TypeIdentifierMap.
785 const DITypeIdentifierMap &getTypeIdentifierMap() const {
786 return TypeIdentifierMap;
789 /// Find the DwarfCompileUnit for the given CU Die.
790 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
791 return CUDieMap.lookup(CU);
793 /// isSubprogramContext - Return true if Context is either a subprogram
794 /// or another context nested inside a subprogram.
795 bool isSubprogramContext(const MDNode *Context);
797 } // End of namespace llvm