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) {
120 if (!(Begin && Loc == Next.Loc && End == Next.Begin))
125 bool isLocation() const { return EntryKind == E_Location; }
126 bool isInt() const { return EntryKind == E_Integer; }
127 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
128 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
129 int64_t getInt() const { return Constants.Int; }
130 const ConstantFP *getConstantFP() const { return Constants.CFP; }
131 const ConstantInt *getConstantInt() const { return Constants.CIP; }
132 const MDNode *getVariable() const { return Variable; }
133 const MCSymbol *getBeginSym() const { return Begin; }
134 const MCSymbol *getEndSym() const { return End; }
135 const DwarfCompileUnit *getCU() const { return Unit; }
136 MachineLocation getLoc() const { return Loc; }
139 //===----------------------------------------------------------------------===//
140 /// \brief This class is used to track local variable information.
142 DIVariable Var; // Variable Descriptor.
143 DIE *TheDIE; // Variable DIE.
144 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
145 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
146 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
151 // AbsVar may be NULL.
152 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
153 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
154 FrameIndex(~0), DD(DD) {}
157 DIVariable getVariable() const { return Var; }
158 void setDIE(DIE *D) { TheDIE = D; }
159 DIE *getDIE() const { return TheDIE; }
160 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
161 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
162 StringRef getName() const { return Var.getName(); }
163 DbgVariable *getAbstractVariable() const { return AbsVar; }
164 const MachineInstr *getMInsn() const { return MInsn; }
165 void setMInsn(const MachineInstr *M) { MInsn = M; }
166 int getFrameIndex() const { return FrameIndex; }
167 void setFrameIndex(int FI) { FrameIndex = FI; }
168 // Translate tag to proper Dwarf tag.
169 uint16_t getTag() const {
170 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
171 return dwarf::DW_TAG_formal_parameter;
173 return dwarf::DW_TAG_variable;
175 /// \brief Return true if DbgVariable is artificial.
176 bool isArtificial() const {
177 if (Var.isArtificial())
179 if (getType().isArtificial())
184 bool isObjectPointer() const {
185 if (Var.isObjectPointer())
187 if (getType().isObjectPointer())
192 bool variableHasComplexAddress() const {
193 assert(Var.isVariable() && "Invalid complex DbgVariable!");
194 return Var.hasComplexAddress();
196 bool isBlockByrefVariable() const;
197 unsigned getNumAddrElements() const {
198 assert(Var.isVariable() && "Invalid complex DbgVariable!");
199 return Var.getNumAddrElements();
201 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
202 DIType getType() const;
205 /// resolve - Look in the DwarfDebug map for the MDNode that
206 /// corresponds to the reference.
207 template <typename T> T resolve(DIRef<T> Ref) const;
210 /// \brief Collects and handles information specific to a particular
211 /// collection of units. This collection represents all of the units
212 /// that will be ultimately output into a single object file.
214 // Target of Dwarf emission, used for sizing of abbreviations.
217 // Used to uniquely define abbreviations.
218 FoldingSet<DIEAbbrev> AbbreviationsSet;
220 // A list of all the unique abbreviations in use.
221 std::vector<DIEAbbrev *> Abbreviations;
223 // A pointer to all units in the section.
224 SmallVector<DwarfUnit *, 1> CUs;
226 // Collection of strings for this unit and assorted symbols.
227 // A String->Symbol mapping of strings used by indirect
229 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
232 unsigned NextStringPoolNumber;
233 std::string StringPref;
235 struct AddressPoolEntry {
238 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
240 // Collection of addresses for this unit and assorted labels.
241 // A Symbol->unsigned mapping of addresses used by indirect
243 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
244 AddrPool AddressPool;
245 unsigned NextAddrPoolNumber;
248 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
249 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
250 AddressPool(), NextAddrPoolNumber(0) {}
254 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
256 /// \brief Compute the size and offset of a DIE given an incoming Offset.
257 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
259 /// \brief Compute the size and offset of all the DIEs.
260 void computeSizeAndOffsets();
262 /// \brief Define a unique number for the abbreviation.
263 void assignAbbrevNumber(DIEAbbrev &Abbrev);
265 /// \brief Add a unit to the list of CUs.
266 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
268 /// \brief Emit all of the units to the section listed with the given
269 /// abbreviation section.
270 void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
272 /// \brief Emit a set of abbreviations to the specific section.
273 void emitAbbrevs(const MCSection *);
275 /// \brief Emit all of the strings to the section given.
276 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
277 const MCSymbol *StrSecSym);
279 /// \brief Emit all of the addresses to the section given.
280 void emitAddresses(const MCSection *AddrSection);
282 /// \brief Returns the entry into the start of the pool.
283 MCSymbol *getStringPoolSym();
285 /// \brief Returns an entry into the string pool with the given
287 MCSymbol *getStringPoolEntry(StringRef Str);
289 /// \brief Returns the index into the string pool with the given
291 unsigned getStringPoolIndex(StringRef Str);
293 /// \brief Returns the string pool.
294 StrPool *getStringPool() { return &StringPool; }
296 /// \brief Returns the index into the address pool with the given
298 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
300 /// \brief Returns the address pool.
301 AddrPool *getAddrPool() { return &AddressPool; }
304 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
306 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
308 DwarfCompileUnit *CU;
311 /// \brief Collects and handles dwarf debug information.
312 class DwarfDebug : public AsmPrinterHandler {
313 // Target of Dwarf emission.
316 // Collected machine module information.
317 MachineModuleInfo *MMI;
319 // All DIEValues are allocated through this allocator.
320 BumpPtrAllocator DIEValueAllocator;
322 // Handle to the compile unit used for the inline extension handling,
323 // this is just so that the DIEValue allocator has a place to store
324 // the particular elements.
325 // FIXME: Store these off of DwarfDebug instead?
326 DwarfCompileUnit *FirstCU;
328 // Maps MDNode with its corresponding DwarfCompileUnit.
329 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
331 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
332 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
334 // Maps a CU DIE with its corresponding DwarfCompileUnit.
335 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
337 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
338 /// be shared across CUs, that is why we keep the map here instead
339 /// of in DwarfCompileUnit.
340 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
342 // List of all labels used in aranges generation.
343 std::vector<SymbolCU> ArangeLabels;
345 // Size of each symbol emitted (for those symbols that have a specific size).
346 DenseMap<const MCSymbol *, uint64_t> SymSize;
348 // Provides a unique id per text section.
349 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
350 SectionMapType SectionMap;
352 // List of arguments for current function.
353 SmallVector<DbgVariable *, 8> CurrentFnArguments;
355 LexicalScopes LScopes;
357 // Collection of abstract subprogram DIEs.
358 DenseMap<const MDNode *, DIE *> AbstractSPDies;
360 // Collection of dbg variables of a scope.
361 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
363 ScopeVariablesMap ScopeVariables;
365 // Collection of abstract variables.
366 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
368 // Collection of DebugLocEntry.
369 SmallVector<SmallVector<DebugLocEntry, 4>, 4> DotDebugLocEntries;
371 // Collection of subprogram DIEs that are marked (at the end of the module)
373 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
375 // This is a collection of subprogram MDNodes that are processed to
377 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
379 // Maps instruction with label emitted before instruction.
380 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
382 // Maps instruction with label emitted after instruction.
383 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
385 // Every user variable mentioned by a DBG_VALUE instruction in order of
387 SmallVector<const MDNode *, 8> UserVariables;
389 // For each user variable, keep a list of DBG_VALUE instructions in order.
390 // The list can also contain normal instructions that clobber the previous
392 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
394 DbgValueHistoryMap DbgValues;
396 // Previous instruction's location information. This is used to determine
397 // label location to indicate scope boundries in dwarf debug info.
398 DebugLoc PrevInstLoc;
401 // This location indicates end of function prologue and beginning of function
403 DebugLoc PrologEndLoc;
405 // If nonnull, stores the current machine function we're processing.
406 const MachineFunction *CurFn;
408 // If nonnull, stores the current machine instruction we're processing.
409 const MachineInstr *CurMI;
411 // If nonnull, stores the section that the previous function was allocated to
413 const MCSection *PrevSection;
415 // If nonnull, stores the CU in which the previous subprogram was contained.
416 const DwarfCompileUnit *PrevCU;
418 // Section Symbols: these are assembler temporary labels that are emitted at
419 // the beginning of each supported dwarf section. These are used to form
420 // section offsets and are created by EmitSectionLabels.
421 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
422 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
423 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
424 MCSymbol *FunctionBeginSym, *FunctionEndSym;
425 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
426 MCSymbol *DwarfStrDWOSectionSym;
427 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
429 // As an optimization, there is no need to emit an entry in the directory
430 // table for the same directory as DW_AT_comp_dir.
431 StringRef CompilationDir;
433 // Counter for assigning globally unique IDs for ranges.
434 unsigned GlobalRangeCount;
436 // Holder for the file specific debug information.
437 DwarfFile InfoHolder;
439 // Holders for the various debug information flags that we might need to
440 // have exposed. See accessor functions below for description.
442 // Holder for imported entities.
443 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
445 ImportedEntityMap ScopesWithImportedEntities;
447 // Map from MDNodes for user-defined types to the type units that describe
449 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
451 // Whether to emit the pubnames/pubtypes sections.
452 bool HasDwarfPubSections;
454 // Whether or not to use AT_ranges for compilation units.
457 // Whether we emitted a function into a section other than the default
459 bool UsedNonDefaultText;
461 // Version of dwarf we're emitting.
462 unsigned DwarfVersion;
464 // Maps from a type identifier to the actual MDNode.
465 DITypeIdentifierMap TypeIdentifierMap;
467 // DWARF5 Experimental Options
468 bool HasDwarfAccelTables;
471 // Separated Dwarf Variables
472 // In general these will all be for bits that are left in the
473 // original object file, rather than things that are meant
474 // to be in the .dwo sections.
476 // Holder for the skeleton information.
477 DwarfFile SkeletonHolder;
479 /// Store file names for type units under fission in a line table header that
480 /// will be emitted into debug_line.dwo.
481 // FIXME: replace this with a map from comp_dir to table so that we can emit
482 // multiple tables during LTO each of which uses directory 0, referencing the
483 // comp_dir of all the type units that use it.
484 MCDwarfDwoLineTable SplitTypeUnitFileTable;
486 // True iff there are multiple CUs in this module.
489 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
491 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
493 const SmallVectorImpl<DwarfUnit *> &getUnits() {
494 return InfoHolder.getUnits();
497 /// \brief Find abstract variable associated with Var.
498 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
500 /// \brief Find DIE for the given subprogram and attach appropriate
501 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
502 /// variables in this scope then create and insert DIEs for these
504 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
506 /// \brief A helper function to check whether the DIE for a given Scope is
507 /// going to be null.
508 bool isLexicalScopeDIENull(LexicalScope *Scope);
510 /// \brief A helper function to construct a RangeSpanList for a given
512 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
513 const SmallVectorImpl<InsnRange> &Range);
515 /// \brief Construct new DW_TAG_lexical_block for this scope and
516 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
517 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
519 /// \brief This scope represents inlined body of a function. Construct
520 /// DIE to represent this concrete inlined copy of the function.
521 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
523 /// \brief Construct a DIE for this scope.
524 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
525 /// A helper function to create children of a Scope DIE.
526 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
527 SmallVectorImpl<DIE *> &Children);
529 /// \brief Emit initial Dwarf sections with a label at the start of each one.
530 void emitSectionLabels();
532 /// \brief Compute the size and offset of a DIE given an incoming Offset.
533 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
535 /// \brief Compute the size and offset of all the DIEs.
536 void computeSizeAndOffsets();
538 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
539 void computeInlinedDIEs();
541 /// \brief Collect info for variables that were optimized out.
542 void collectDeadVariables();
544 /// \brief Finish off debug information after all functions have been
546 void finalizeModuleInfo();
548 /// \brief Emit labels to close any remaining sections that have been left
552 /// \brief Emit the debug info section.
553 void emitDebugInfo();
555 /// \brief Emit the abbreviation section.
556 void emitAbbreviations();
558 /// \brief Emit the last address of the section and the end of
560 void emitEndOfLineMatrix(unsigned SectionEnd);
562 /// \brief Emit visible names into a hashed accelerator table section.
563 void emitAccelNames();
565 /// \brief Emit objective C classes and categories into a hashed
566 /// accelerator table section.
567 void emitAccelObjC();
569 /// \brief Emit namespace dies into a hashed accelerator table.
570 void emitAccelNamespaces();
572 /// \brief Emit type dies into a hashed accelerator table.
573 void emitAccelTypes();
575 /// \brief Emit visible names into a debug pubnames section.
576 /// \param GnuStyle determines whether or not we want to emit
577 /// additional information into the table ala newer gcc for gdb
579 void emitDebugPubNames(bool GnuStyle = false);
581 /// \brief Emit visible types into a debug pubtypes section.
582 /// \param GnuStyle determines whether or not we want to emit
583 /// additional information into the table ala newer gcc for gdb
585 void emitDebugPubTypes(bool GnuStyle = false);
588 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
589 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
592 /// \brief Emit visible names into a debug str section.
595 /// \brief Emit visible names into a debug loc section.
598 /// \brief Emit visible names into a debug aranges section.
599 void emitDebugARanges();
601 /// \brief Emit visible names into a debug ranges section.
602 void emitDebugRanges();
604 /// \brief Emit inline info using custom format.
605 void emitDebugInlineInfo();
607 /// DWARF 5 Experimental Split Dwarf Emitters
609 /// \brief Initialize common features of skeleton units.
610 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
612 /// \brief Construct the split debug info compile unit for the debug info
614 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
616 /// \brief Construct the split debug info compile unit for the debug info
618 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
620 /// \brief Emit the debug info dwo section.
621 void emitDebugInfoDWO();
623 /// \brief Emit the debug abbrev dwo section.
624 void emitDebugAbbrevDWO();
626 /// \brief Emit the debug line dwo section.
627 void emitDebugLineDWO();
629 /// \brief Emit the debug str dwo section.
630 void emitDebugStrDWO();
632 /// Flags to let the linker know we have emitted new style pubnames. Only
633 /// emit it here if we don't have a skeleton CU for split dwarf.
634 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
636 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
637 /// DW_TAG_compile_unit.
638 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
640 /// \brief Construct subprogram DIE.
641 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
643 /// \brief Construct imported_module or imported_declaration DIE.
644 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
646 /// \brief Construct import_module DIE.
647 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
650 /// \brief Construct import_module DIE.
651 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
652 const DIImportedEntity &Module, DIE *Context);
654 /// \brief Register a source line with debug info. Returns the unique
655 /// label that was emitted and which provides correspondence to the
656 /// source line list.
657 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
660 /// \brief Indentify instructions that are marking the beginning of or
661 /// ending of a scope.
662 void identifyScopeMarkers();
664 /// \brief If Var is an current function argument that add it in
665 /// CurrentFnArguments list.
666 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
668 /// \brief Populate LexicalScope entries with variables' info.
669 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
671 /// \brief Collect variable information from the side table maintained
673 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
675 /// \brief Ensure that a label will be emitted before MI.
676 void requestLabelBeforeInsn(const MachineInstr *MI) {
677 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
680 /// \brief Return Label preceding the instruction.
681 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
683 /// \brief Ensure that a label will be emitted after MI.
684 void requestLabelAfterInsn(const MachineInstr *MI) {
685 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
688 /// \brief Return Label immediately following the instruction.
689 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
691 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
695 //===--------------------------------------------------------------------===//
696 // Main entry points.
698 DwarfDebug(AsmPrinter *A, Module *M);
700 void insertDIE(const MDNode *TypeMD, DIE *Die) {
701 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
703 DIE *getDIE(const MDNode *TypeMD) {
704 return MDTypeNodeToDieMap.lookup(TypeMD);
707 /// \brief Emit all Dwarf sections that should come prior to the
711 /// \brief Emit all Dwarf sections that should come after the content.
712 void endModule() override;
714 /// \brief Gather pre-function debug information.
715 void beginFunction(const MachineFunction *MF) override;
717 /// \brief Gather and emit post-function debug information.
718 void endFunction(const MachineFunction *MF) override;
720 /// \brief Process beginning of an instruction.
721 void beginInstruction(const MachineInstr *MI) override;
723 /// \brief Process end of an instruction.
724 void endInstruction() override;
726 /// \brief Add a DIE to the set of types that we're going to pull into
728 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
729 DIE *Die, DICompositeType CTy);
731 /// \brief Add a label so that arange data can be generated for it.
732 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
734 /// \brief For symbols that have a size designated (e.g. common symbols),
735 /// this tracks that size.
736 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
740 /// \brief Recursively Emits a debug information entry.
741 void emitDIE(DIE *Die);
743 // Experimental DWARF5 features.
745 /// \brief Returns whether or not to emit tables that dwarf consumers can
746 /// use to accelerate lookup.
747 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
749 /// \brief Returns whether or not to change the current debug info for the
750 /// split dwarf proposal support.
751 bool useSplitDwarf() const { return HasSplitDwarf; }
753 /// Returns the Dwarf Version.
754 unsigned getDwarfVersion() const { return DwarfVersion; }
756 /// Returns the section symbol for the .debug_loc section.
757 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
759 /// Returns the previous section that was emitted into.
760 const MCSection *getPrevSection() const { return PrevSection; }
762 /// Returns the previous CU that was being updated
763 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
765 /// Returns the entries for the .debug_loc section.
766 const SmallVectorImpl<SmallVector<DebugLocEntry, 4>> &
767 getDebugLocEntries() const {
768 return DotDebugLocEntries;
771 /// \brief Emit an entry for the debug loc section. This can be used to
772 /// handle an entry that's going to be emitted into the debug loc section.
773 void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
775 /// Emit the location for a debug loc entry, including the size header.
776 void emitDebugLocEntryLocation(const DebugLocEntry &Entry);
778 /// Find the MDNode for the given reference.
779 template <typename T> T resolve(DIRef<T> Ref) const {
780 return Ref.resolve(TypeIdentifierMap);
783 /// \brief Return the TypeIdentifierMap.
784 const DITypeIdentifierMap &getTypeIdentifierMap() const {
785 return TypeIdentifierMap;
788 /// Find the DwarfCompileUnit for the given CU Die.
789 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
790 return CUDieMap.lookup(CU);
792 /// isSubprogramContext - Return true if Context is either a subprogram
793 /// or another context nested inside a subprogram.
794 bool isSubprogramContext(const MDNode *Context);
796 } // End of namespace llvm