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/FoldingSet.h"
21 #include "llvm/ADT/MapVector.h"
22 #include "llvm/ADT/SetVector.h"
23 #include "llvm/ADT/SmallPtrSet.h"
24 #include "llvm/ADT/StringMap.h"
25 #include "llvm/CodeGen/AsmPrinter.h"
26 #include "llvm/CodeGen/LexicalScopes.h"
27 #include "llvm/IR/DebugInfo.h"
28 #include "llvm/IR/DebugLoc.h"
29 #include "llvm/MC/MachineLocation.h"
30 #include "llvm/MC/MCDwarf.h"
31 #include "llvm/Support/Allocator.h"
37 class DwarfCompileUnit;
41 class MachineFrameInfo;
42 class MachineModuleInfo;
45 class MCObjectFileInfo;
51 //===----------------------------------------------------------------------===//
52 /// \brief This class is used to record source line correspondence.
54 unsigned Line; // Source line number.
55 unsigned Column; // Source column.
56 unsigned SourceID; // Source ID number.
57 MCSymbol *Label; // Label in code ID number.
59 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
60 : Line(L), Column(C), SourceID(S), Label(label) {}
63 unsigned getLine() const { return Line; }
64 unsigned getColumn() const { return Column; }
65 unsigned getSourceID() const { return SourceID; }
66 MCSymbol *getLabel() const { return Label; }
69 /// \brief This struct describes location entries emitted in the .debug_loc
71 class DotDebugLocEntry {
72 // Begin and end symbols for the address range that this location is valid.
73 const MCSymbol *Begin;
76 // Type of entry that this represents.
83 enum EntryType EntryKind;
87 const ConstantFP *CFP;
88 const ConstantInt *CIP;
91 // The location in the machine frame.
94 // The variable to which this location entry corresponds.
95 const MDNode *Variable;
97 // Whether this location has been merged.
101 DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
104 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
106 : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
108 EntryKind = E_Location;
110 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
111 : Begin(B), End(E), Variable(0), Merged(false) {
113 EntryKind = E_Integer;
115 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
116 : Begin(B), End(E), Variable(0), Merged(false) {
117 Constants.CFP = FPtr;
118 EntryKind = E_ConstantFP;
120 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
121 const ConstantInt *IPtr)
122 : Begin(B), End(E), Variable(0), Merged(false) {
123 Constants.CIP = IPtr;
124 EntryKind = E_ConstantInt;
127 /// \brief Empty entries are also used as a trigger to emit temp label. Such
128 /// labels are referenced is used to find debug_loc offset for a given DIE.
129 bool isEmpty() const { return Begin == 0 && End == 0; }
130 bool isMerged() const { return Merged; }
131 void Merge(DotDebugLocEntry *Next) {
132 if (!(Begin && Loc == Next->Loc && End == Next->Begin))
137 bool isLocation() const { return EntryKind == E_Location; }
138 bool isInt() const { return EntryKind == E_Integer; }
139 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
140 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
141 int64_t getInt() const { return Constants.Int; }
142 const ConstantFP *getConstantFP() const { return Constants.CFP; }
143 const ConstantInt *getConstantInt() const { return Constants.CIP; }
144 const MDNode *getVariable() const { return Variable; }
145 const MCSymbol *getBeginSym() const { return Begin; }
146 const MCSymbol *getEndSym() const { return End; }
147 MachineLocation getLoc() const { return Loc; }
150 //===----------------------------------------------------------------------===//
151 /// \brief This class is used to track local variable information.
153 DIVariable Var; // Variable Descriptor.
154 DIE *TheDIE; // Variable DIE.
155 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
156 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
157 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
162 // AbsVar may be NULL.
163 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
164 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
165 FrameIndex(~0), DD(DD) {}
168 DIVariable getVariable() const { return Var; }
169 void setDIE(DIE *D) { TheDIE = D; }
170 DIE *getDIE() const { return TheDIE; }
171 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
172 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
173 StringRef getName() const { return Var.getName(); }
174 DbgVariable *getAbstractVariable() const { return AbsVar; }
175 const MachineInstr *getMInsn() const { return MInsn; }
176 void setMInsn(const MachineInstr *M) { MInsn = M; }
177 int getFrameIndex() const { return FrameIndex; }
178 void setFrameIndex(int FI) { FrameIndex = FI; }
179 // Translate tag to proper Dwarf tag.
180 uint16_t getTag() const {
181 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
182 return dwarf::DW_TAG_formal_parameter;
184 return dwarf::DW_TAG_variable;
186 /// \brief Return true if DbgVariable is artificial.
187 bool isArtificial() const {
188 if (Var.isArtificial())
190 if (getType().isArtificial())
195 bool isObjectPointer() const {
196 if (Var.isObjectPointer())
198 if (getType().isObjectPointer())
203 bool variableHasComplexAddress() const {
204 assert(Var.isVariable() && "Invalid complex DbgVariable!");
205 return Var.hasComplexAddress();
207 bool isBlockByrefVariable() const {
208 assert(Var.isVariable() && "Invalid complex DbgVariable!");
209 return Var.isBlockByrefVariable();
211 unsigned getNumAddrElements() const {
212 assert(Var.isVariable() && "Invalid complex DbgVariable!");
213 return Var.getNumAddrElements();
215 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
216 DIType getType() const;
219 /// resolve - Look in the DwarfDebug map for the MDNode that
220 /// corresponds to the reference.
221 template <typename T> T resolve(DIRef<T> Ref) const;
224 /// \brief Collects and handles information specific to a particular
225 /// collection of units. This collection represents all of the units
226 /// that will be ultimately output into a single object file.
228 // Target of Dwarf emission, used for sizing of abbreviations.
231 // Used to uniquely define abbreviations.
232 FoldingSet<DIEAbbrev> AbbreviationsSet;
234 // A list of all the unique abbreviations in use.
235 std::vector<DIEAbbrev *> Abbreviations;
237 // A pointer to all units in the section.
238 SmallVector<DwarfUnit *, 1> CUs;
240 // Collection of strings for this unit and assorted symbols.
241 // A String->Symbol mapping of strings used by indirect
243 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
246 unsigned NextStringPoolNumber;
247 std::string StringPref;
249 struct AddressPoolEntry {
252 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
254 // Collection of addresses for this unit and assorted labels.
255 // A Symbol->unsigned mapping of addresses used by indirect
257 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
258 AddrPool AddressPool;
259 unsigned NextAddrPoolNumber;
262 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
263 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
264 AddressPool(), NextAddrPoolNumber(0) {}
268 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
270 /// \brief Compute the size and offset of a DIE given an incoming Offset.
271 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
273 /// \brief Compute the size and offset of all the DIEs.
274 void computeSizeAndOffsets();
276 /// \brief Define a unique number for the abbreviation.
277 void assignAbbrevNumber(DIEAbbrev &Abbrev);
279 /// \brief Add a unit to the list of CUs.
280 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
282 /// \brief Emit all of the units to the section listed with the given
283 /// abbreviation section.
284 void emitUnits(DwarfDebug *DD, const MCSection *ASection,
285 const MCSymbol *ASectionSym);
287 /// \brief Emit a set of abbreviations to the specific section.
288 void emitAbbrevs(const MCSection *);
290 /// \brief Emit all of the strings to the section given.
291 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
292 const MCSymbol *StrSecSym);
294 /// \brief Emit all of the addresses to the section given.
295 void emitAddresses(const MCSection *AddrSection);
297 /// \brief Returns the entry into the start of the pool.
298 MCSymbol *getStringPoolSym();
300 /// \brief Returns an entry into the string pool with the given
302 MCSymbol *getStringPoolEntry(StringRef Str);
304 /// \brief Returns the index into the string pool with the given
306 unsigned getStringPoolIndex(StringRef Str);
308 /// \brief Returns the string pool.
309 StrPool *getStringPool() { return &StringPool; }
311 /// \brief Returns the index into the address pool with the given
313 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
315 /// \brief Returns the address pool.
316 AddrPool *getAddrPool() { return &AddressPool; }
319 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
321 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
323 DwarfCompileUnit *CU;
326 /// \brief Collects and handles dwarf debug information.
327 class DwarfDebug : public AsmPrinterHandler {
328 // Target of Dwarf emission.
331 // Collected machine module information.
332 MachineModuleInfo *MMI;
334 // All DIEValues are allocated through this allocator.
335 BumpPtrAllocator DIEValueAllocator;
337 // Handle to the compile unit used for the inline extension handling,
338 // this is just so that the DIEValue allocator has a place to store
339 // the particular elements.
340 // FIXME: Store these off of DwarfDebug instead?
341 DwarfCompileUnit *FirstCU;
343 // Maps MDNode with its corresponding DwarfCompileUnit.
344 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
346 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
347 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
349 // Maps a CU DIE with its corresponding DwarfCompileUnit.
350 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
352 /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
353 /// be shared across CUs, that is why we keep the map here instead
354 /// of in DwarfCompileUnit.
355 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
357 // Used to unique C++ member function declarations.
358 StringMap<const MDNode *> OdrMemberMap;
360 // List of all labels used in aranges generation.
361 std::vector<SymbolCU> ArangeLabels;
363 // Size of each symbol emitted (for those symbols that have a specific size).
364 DenseMap<const MCSymbol *, uint64_t> SymSize;
366 // Provides a unique id per text section.
367 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
368 SectionMapType SectionMap;
370 // List of arguments for current function.
371 SmallVector<DbgVariable *, 8> CurrentFnArguments;
373 LexicalScopes LScopes;
375 // Collection of abstract subprogram DIEs.
376 DenseMap<const MDNode *, DIE *> AbstractSPDies;
378 // Collection of dbg variables of a scope.
379 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
381 ScopeVariablesMap ScopeVariables;
383 // Collection of abstract variables.
384 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
386 // Collection of DotDebugLocEntry.
387 SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
389 // Collection of subprogram DIEs that are marked (at the end of the module)
391 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
393 // This is a collection of subprogram MDNodes that are processed to
395 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
397 // Maps instruction with label emitted before instruction.
398 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
400 // Maps instruction with label emitted after instruction.
401 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
403 // Every user variable mentioned by a DBG_VALUE instruction in order of
405 SmallVector<const MDNode *, 8> UserVariables;
407 // For each user variable, keep a list of DBG_VALUE instructions in order.
408 // The list can also contain normal instructions that clobber the previous
410 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
412 DbgValueHistoryMap DbgValues;
414 // Previous instruction's location information. This is used to determine
415 // label location to indicate scope boundries in dwarf debug info.
416 DebugLoc PrevInstLoc;
419 // This location indicates end of function prologue and beginning of function
421 DebugLoc PrologEndLoc;
423 // If nonnull, stores the current machine function we're processing.
424 const MachineFunction *CurFn;
426 // If nonnull, stores the current machine instruction we're processing.
427 const MachineInstr *CurMI;
429 // Section Symbols: these are assembler temporary labels that are emitted at
430 // the beginning of each supported dwarf section. These are used to form
431 // section offsets and are created by EmitSectionLabels.
432 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
433 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
434 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
435 MCSymbol *FunctionBeginSym, *FunctionEndSym;
436 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
437 MCSymbol *DwarfStrDWOSectionSym;
438 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
440 // As an optimization, there is no need to emit an entry in the directory
441 // table for the same directory as DW_AT_comp_dir.
442 StringRef CompilationDir;
444 // Counter for assigning globally unique IDs for ranges.
445 unsigned GlobalRangeCount;
447 // Holder for the file specific debug information.
448 DwarfFile InfoHolder;
450 // Holders for the various debug information flags that we might need to
451 // have exposed. See accessor functions below for description.
453 // Holder for imported entities.
454 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
456 ImportedEntityMap ScopesWithImportedEntities;
458 // Map from MDNodes for user-defined types to the type units that describe
460 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
462 // Whether to emit the pubnames/pubtypes sections.
463 bool HasDwarfPubSections;
465 // Whether or not to use AT_ranges for compilation units.
468 // Whether we emitted a function into a section other than the default
470 bool UsedNonDefaultText;
472 // Version of dwarf we're emitting.
473 unsigned DwarfVersion;
475 // Maps from a type identifier to the actual MDNode.
476 DITypeIdentifierMap TypeIdentifierMap;
478 // DWARF5 Experimental Options
479 bool HasDwarfAccelTables;
482 // Separated Dwarf Variables
483 // In general these will all be for bits that are left in the
484 // original object file, rather than things that are meant
485 // to be in the .dwo sections.
487 // Holder for the skeleton information.
488 DwarfFile SkeletonHolder;
490 // Store file names for type units under fission in a line table header that
491 // will be emitted into debug_line.dwo.
492 MCDwarfDwoLineTable SplitTypeUnitFileTable;
494 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
496 const SmallVectorImpl<DwarfUnit *> &getUnits() {
497 return InfoHolder.getUnits();
500 /// \brief Find abstract variable associated with Var.
501 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
503 /// \brief Find DIE for the given subprogram and attach appropriate
504 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
505 /// variables in this scope then create and insert DIEs for these
507 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
509 /// \brief A helper function to check whether the DIE for a given Scope is
510 /// going to be null.
511 bool isLexicalScopeDIENull(LexicalScope *Scope);
513 /// \brief A helper function to construct a RangeSpanList for a given
515 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
516 const SmallVectorImpl<InsnRange> &Range);
518 /// \brief Construct new DW_TAG_lexical_block for this scope and
519 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
520 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
522 /// \brief This scope represents inlined body of a function. Construct
523 /// DIE to represent this concrete inlined copy of the function.
524 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
526 /// \brief Construct a DIE for this scope.
527 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
528 /// A helper function to create children of a Scope DIE.
529 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
530 SmallVectorImpl<DIE *> &Children);
532 /// \brief Emit initial Dwarf sections with a label at the start of each one.
533 void emitSectionLabels();
535 /// \brief Compute the size and offset of a DIE given an incoming Offset.
536 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
538 /// \brief Compute the size and offset of all the DIEs.
539 void computeSizeAndOffsets();
541 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
542 void computeInlinedDIEs();
544 /// \brief Collect info for variables that were optimized out.
545 void collectDeadVariables();
547 /// \brief Finish off debug information after all functions have been
549 void finalizeModuleInfo();
551 /// \brief Emit labels to close any remaining sections that have been left
555 /// \brief Emit the debug info section.
556 void emitDebugInfo();
558 /// \brief Emit the abbreviation section.
559 void emitAbbreviations();
561 /// \brief Emit the last address of the section and the end of
563 void emitEndOfLineMatrix(unsigned SectionEnd);
565 /// \brief Emit visible names into a hashed accelerator table section.
566 void emitAccelNames();
568 /// \brief Emit objective C classes and categories into a hashed
569 /// accelerator table section.
570 void emitAccelObjC();
572 /// \brief Emit namespace dies into a hashed accelerator table.
573 void emitAccelNamespaces();
575 /// \brief Emit type dies into a hashed accelerator table.
576 void emitAccelTypes();
578 /// \brief Emit visible names into a debug pubnames section.
579 /// \param GnuStyle determines whether or not we want to emit
580 /// additional information into the table ala newer gcc for gdb
582 void emitDebugPubNames(bool GnuStyle = false);
584 /// \brief Emit visible types into a debug pubtypes section.
585 /// \param GnuStyle determines whether or not we want to emit
586 /// additional information into the table ala newer gcc for gdb
588 void emitDebugPubTypes(bool GnuStyle = false);
591 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
592 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
595 /// \brief Emit visible names into a debug str section.
598 /// \brief Emit visible names into a debug loc section.
601 /// \brief Emit visible names into a debug aranges section.
602 void emitDebugARanges();
604 /// \brief Emit visible names into a debug ranges section.
605 void emitDebugRanges();
607 /// \brief Emit inline info using custom format.
608 void emitDebugInlineInfo();
610 /// DWARF 5 Experimental Split Dwarf Emitters
612 /// \brief Initialize common features of skeleton units.
613 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
615 /// \brief Construct the split debug info compile unit for the debug info
617 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
619 /// \brief Construct the split debug info compile unit for the debug info
621 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
623 /// \brief Emit the debug info dwo section.
624 void emitDebugInfoDWO();
626 /// \brief Emit the debug abbrev dwo section.
627 void emitDebugAbbrevDWO();
629 /// \brief Emit the debug line dwo section.
630 void emitDebugLineDWO();
632 /// \brief Emit the debug str dwo section.
633 void emitDebugStrDWO();
635 /// Flags to let the linker know we have emitted new style pubnames. Only
636 /// emit it here if we don't have a skeleton CU for split dwarf.
637 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
639 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
640 /// DW_TAG_compile_unit.
641 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit,
644 /// \brief Construct subprogram DIE.
645 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
647 /// \brief Construct imported_module or imported_declaration DIE.
648 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
650 /// \brief Construct import_module DIE.
651 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
654 /// \brief Construct import_module DIE.
655 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
656 const DIImportedEntity &Module, DIE *Context);
658 /// \brief Register a source line with debug info. Returns the unique
659 /// label that was emitted and which provides correspondence to the
660 /// source line list.
661 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
664 /// \brief Indentify instructions that are marking the beginning of or
665 /// ending of a scope.
666 void identifyScopeMarkers();
668 /// \brief If Var is an current function argument that add it in
669 /// CurrentFnArguments list.
670 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
672 /// \brief Populate LexicalScope entries with variables' info.
673 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
675 /// \brief Collect variable information from the side table maintained
677 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
679 /// \brief Ensure that a label will be emitted before MI.
680 void requestLabelBeforeInsn(const MachineInstr *MI) {
681 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
684 /// \brief Return Label preceding the instruction.
685 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
687 /// \brief Ensure that a label will be emitted after MI.
688 void requestLabelAfterInsn(const MachineInstr *MI) {
689 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
692 /// \brief Return Label immediately following the instruction.
693 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
695 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
699 //===--------------------------------------------------------------------===//
700 // Main entry points.
702 DwarfDebug(AsmPrinter *A, Module *M);
704 void insertDIE(const MDNode *TypeMD, DIE *Die) {
705 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
707 DIE *getDIE(const MDNode *TypeMD) {
708 return MDTypeNodeToDieMap.lookup(TypeMD);
711 /// \brief Look up or create an entry in the OdrMemberMap.
712 const MDNode *&getOrCreateOdrMember(StringRef Key) {
713 return OdrMemberMap.GetOrCreateValue(Key).getValue();
716 /// \brief Emit all Dwarf sections that should come prior to the
720 /// \brief Emit all Dwarf sections that should come after the content.
721 void endModule() override;
723 /// \brief Gather pre-function debug information.
724 void beginFunction(const MachineFunction *MF) override;
726 /// \brief Gather and emit post-function debug information.
727 void endFunction(const MachineFunction *MF) override;
729 /// \brief Process beginning of an instruction.
730 void beginInstruction(const MachineInstr *MI) override;
732 /// \brief Process end of an instruction.
733 void endInstruction() override;
735 /// \brief Add a DIE to the set of types that we're going to pull into
737 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
738 DIE *Die, DICompositeType CTy);
740 /// \brief Add a label so that arange data can be generated for it.
741 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
743 /// \brief For symbols that have a size designated (e.g. common symbols),
744 /// this tracks that size.
745 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
749 /// \brief Recursively Emits a debug information entry.
750 void emitDIE(DIE *Die);
752 // Experimental DWARF5 features.
754 /// \brief Returns whether or not to emit tables that dwarf consumers can
755 /// use to accelerate lookup.
756 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
758 /// \brief Returns whether or not to change the current debug info for the
759 /// split dwarf proposal support.
760 bool useSplitDwarf() const { return HasSplitDwarf; }
762 /// \brief Returns whether or not to use AT_ranges for compilation units.
763 bool useCURanges() const { return HasCURanges; }
765 /// Returns the Dwarf Version.
766 unsigned getDwarfVersion() const { return DwarfVersion; }
768 /// Returns the section symbol for the .debug_loc section.
769 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
771 /// Returns the entries for the .debug_loc section.
772 const SmallVectorImpl<DotDebugLocEntry> &getDebugLocEntries() const {
773 return DotDebugLocEntries;
776 /// \brief Emit an entry for the debug loc section. This can be used to
777 /// handle an entry that's going to be emitted into the debug loc section.
778 void emitDebugLocEntry(ByteStreamer &Streamer, const DotDebugLocEntry &Entry);
780 /// Find the MDNode for the given reference.
781 template <typename T> T resolve(DIRef<T> Ref) const {
782 return Ref.resolve(TypeIdentifierMap);
785 /// Find the DwarfCompileUnit for the given CU Die.
786 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
787 return CUDieMap.lookup(CU);
789 /// isSubprogramContext - Return true if Context is either a subprogram
790 /// or another context nested inside a subprogram.
791 bool isSubprogramContext(const MDNode *Context);
793 } // End of namespace llvm