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/Support/Allocator.h"
36 class DwarfCompileUnit;
40 class MachineFrameInfo;
41 class MachineModuleInfo;
44 class MCObjectFileInfo;
50 //===----------------------------------------------------------------------===//
51 /// \brief This class is used to record source line correspondence.
53 unsigned Line; // Source line number.
54 unsigned Column; // Source column.
55 unsigned SourceID; // Source ID number.
56 MCSymbol *Label; // Label in code ID number.
58 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
59 : Line(L), Column(C), SourceID(S), Label(label) {}
62 unsigned getLine() const { return Line; }
63 unsigned getColumn() const { return Column; }
64 unsigned getSourceID() const { return SourceID; }
65 MCSymbol *getLabel() const { return Label; }
68 /// \brief This struct describes location entries emitted in the .debug_loc
70 class DotDebugLocEntry {
71 // Begin and end symbols for the address range that this location is valid.
72 const MCSymbol *Begin;
75 // Type of entry that this represents.
82 enum EntryType EntryKind;
86 const ConstantFP *CFP;
87 const ConstantInt *CIP;
90 // The location in the machine frame.
93 // The variable to which this location entry corresponds.
94 const MDNode *Variable;
96 // Whether this location has been merged.
100 DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
103 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
105 : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
107 EntryKind = E_Location;
109 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
110 : Begin(B), End(E), Variable(0), Merged(false) {
112 EntryKind = E_Integer;
114 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
115 : Begin(B), End(E), Variable(0), Merged(false) {
116 Constants.CFP = FPtr;
117 EntryKind = E_ConstantFP;
119 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
120 const ConstantInt *IPtr)
121 : Begin(B), End(E), Variable(0), Merged(false) {
122 Constants.CIP = IPtr;
123 EntryKind = E_ConstantInt;
126 /// \brief Empty entries are also used as a trigger to emit temp label. Such
127 /// labels are referenced is used to find debug_loc offset for a given DIE.
128 bool isEmpty() const { return Begin == 0 && End == 0; }
129 bool isMerged() const { return Merged; }
130 void Merge(DotDebugLocEntry *Next) {
131 if (!(Begin && Loc == Next->Loc && End == Next->Begin))
136 bool isLocation() const { return EntryKind == E_Location; }
137 bool isInt() const { return EntryKind == E_Integer; }
138 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
139 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
140 int64_t getInt() const { return Constants.Int; }
141 const ConstantFP *getConstantFP() const { return Constants.CFP; }
142 const ConstantInt *getConstantInt() const { return Constants.CIP; }
143 const MDNode *getVariable() const { return Variable; }
144 const MCSymbol *getBeginSym() const { return Begin; }
145 const MCSymbol *getEndSym() const { return End; }
146 MachineLocation getLoc() const { return Loc; }
149 //===----------------------------------------------------------------------===//
150 /// \brief This class is used to track local variable information.
152 DIVariable Var; // Variable Descriptor.
153 DIE *TheDIE; // Variable DIE.
154 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
155 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
156 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
161 // AbsVar may be NULL.
162 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
163 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
164 FrameIndex(~0), DD(DD) {}
167 DIVariable getVariable() const { return Var; }
168 void setDIE(DIE *D) { TheDIE = D; }
169 DIE *getDIE() const { return TheDIE; }
170 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
171 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
172 StringRef getName() const { return Var.getName(); }
173 DbgVariable *getAbstractVariable() const { return AbsVar; }
174 const MachineInstr *getMInsn() const { return MInsn; }
175 void setMInsn(const MachineInstr *M) { MInsn = M; }
176 int getFrameIndex() const { return FrameIndex; }
177 void setFrameIndex(int FI) { FrameIndex = FI; }
178 // Translate tag to proper Dwarf tag.
179 uint16_t getTag() const {
180 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
181 return dwarf::DW_TAG_formal_parameter;
183 return dwarf::DW_TAG_variable;
185 /// \brief Return true if DbgVariable is artificial.
186 bool isArtificial() const {
187 if (Var.isArtificial())
189 if (getType().isArtificial())
194 bool isObjectPointer() const {
195 if (Var.isObjectPointer())
197 if (getType().isObjectPointer())
202 bool variableHasComplexAddress() const {
203 assert(Var.isVariable() && "Invalid complex DbgVariable!");
204 return Var.hasComplexAddress();
206 bool isBlockByrefVariable() const {
207 assert(Var.isVariable() && "Invalid complex DbgVariable!");
208 return Var.isBlockByrefVariable();
210 unsigned getNumAddrElements() const {
211 assert(Var.isVariable() && "Invalid complex DbgVariable!");
212 return Var.getNumAddrElements();
214 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
215 DIType getType() const;
218 /// resolve - Look in the DwarfDebug map for the MDNode that
219 /// corresponds to the reference.
220 template <typename T> T resolve(DIRef<T> Ref) const;
223 /// \brief Collects and handles information specific to a particular
224 /// collection of units. This collection represents all of the units
225 /// that will be ultimately output into a single object file.
227 // Target of Dwarf emission, used for sizing of abbreviations.
230 // Used to uniquely define abbreviations.
231 FoldingSet<DIEAbbrev> AbbreviationsSet;
233 // A list of all the unique abbreviations in use.
234 std::vector<DIEAbbrev *> Abbreviations;
236 // A pointer to all units in the section.
237 SmallVector<DwarfUnit *, 1> CUs;
239 // Collection of strings for this unit and assorted symbols.
240 // A String->Symbol mapping of strings used by indirect
242 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
245 unsigned NextStringPoolNumber;
246 std::string StringPref;
248 struct AddressPoolEntry {
251 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
253 // Collection of addresses for this unit and assorted labels.
254 // A Symbol->unsigned mapping of addresses used by indirect
256 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
257 AddrPool AddressPool;
258 unsigned NextAddrPoolNumber;
261 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
262 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
263 AddressPool(), NextAddrPoolNumber(0) {}
267 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
269 /// \brief Compute the size and offset of a DIE given an incoming Offset.
270 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
272 /// \brief Compute the size and offset of all the DIEs.
273 void computeSizeAndOffsets();
275 /// \brief Define a unique number for the abbreviation.
276 void assignAbbrevNumber(DIEAbbrev &Abbrev);
278 /// \brief Add a unit to the list of CUs.
279 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
281 /// \brief Emit all of the units to the section listed with the given
282 /// abbreviation section.
283 void emitUnits(DwarfDebug *DD, const MCSection *ASection,
284 const MCSymbol *ASectionSym);
286 /// \brief Emit a set of abbreviations to the specific section.
287 void emitAbbrevs(const MCSection *);
289 /// \brief Emit all of the strings to the section given.
290 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
291 const MCSymbol *StrSecSym);
293 /// \brief Emit all of the addresses to the section given.
294 void emitAddresses(const MCSection *AddrSection);
296 /// \brief Returns the entry into the start of the pool.
297 MCSymbol *getStringPoolSym();
299 /// \brief Returns an entry into the string pool with the given
301 MCSymbol *getStringPoolEntry(StringRef Str);
303 /// \brief Returns the index into the string pool with the given
305 unsigned getStringPoolIndex(StringRef Str);
307 /// \brief Returns the string pool.
308 StrPool *getStringPool() { return &StringPool; }
310 /// \brief Returns the index into the address pool with the given
312 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
314 /// \brief Returns the address pool.
315 AddrPool *getAddrPool() { return &AddressPool; }
318 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
320 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
322 DwarfCompileUnit *CU;
325 /// \brief Collects and handles dwarf debug information.
326 class DwarfDebug : public AsmPrinterHandler {
327 // Target of Dwarf emission.
330 // Collected machine module information.
331 MachineModuleInfo *MMI;
333 // All DIEValues are allocated through this allocator.
334 BumpPtrAllocator DIEValueAllocator;
336 // Handle to the compile unit used for the inline extension handling,
337 // this is just so that the DIEValue allocator has a place to store
338 // the particular elements.
339 // FIXME: Store these off of DwarfDebug instead?
340 DwarfCompileUnit *FirstCU;
342 // Maps MDNode with its corresponding DwarfCompileUnit.
343 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
345 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
346 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
348 // Maps a CU DIE with its corresponding DwarfCompileUnit.
349 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
351 /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
352 /// be shared across CUs, that is why we keep the map here instead
353 /// of in DwarfCompileUnit.
354 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
356 // Used to unique C++ member function declarations.
357 StringMap<const MDNode *> OdrMemberMap;
359 // Stores the current file ID for a given compile unit.
360 DenseMap<unsigned, unsigned> FileIDCUMap;
361 // Source id map, i.e. CUID, source filename and directory,
362 // separated by a zero byte, mapped to a unique id.
363 StringMap<unsigned, BumpPtrAllocator &> SourceIdMap;
365 // List of all labels used in aranges generation.
366 std::vector<SymbolCU> ArangeLabels;
368 // Size of each symbol emitted (for those symbols that have a specific size).
369 DenseMap<const MCSymbol *, uint64_t> SymSize;
371 // Provides a unique id per text section.
372 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
373 SectionMapType SectionMap;
375 // List of arguments for current function.
376 SmallVector<DbgVariable *, 8> CurrentFnArguments;
378 LexicalScopes LScopes;
380 // Collection of abstract subprogram DIEs.
381 DenseMap<const MDNode *, DIE *> AbstractSPDies;
383 // Collection of dbg variables of a scope.
384 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
386 ScopeVariablesMap ScopeVariables;
388 // Collection of abstract variables.
389 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
391 // Collection of DotDebugLocEntry.
392 SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
394 // Collection of subprogram DIEs that are marked (at the end of the module)
396 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
398 // This is a collection of subprogram MDNodes that are processed to
400 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
402 // Maps instruction with label emitted before instruction.
403 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
405 // Maps instruction with label emitted after instruction.
406 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
408 // Every user variable mentioned by a DBG_VALUE instruction in order of
410 SmallVector<const MDNode *, 8> UserVariables;
412 // For each user variable, keep a list of DBG_VALUE instructions in order.
413 // The list can also contain normal instructions that clobber the previous
415 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
417 DbgValueHistoryMap DbgValues;
419 // Previous instruction's location information. This is used to determine
420 // label location to indicate scope boundries in dwarf debug info.
421 DebugLoc PrevInstLoc;
424 // This location indicates end of function prologue and beginning of function
426 DebugLoc PrologEndLoc;
428 // If nonnull, stores the current machine function we're processing.
429 const MachineFunction *CurFn;
431 // If nonnull, stores the current machine instruction we're processing.
432 const MachineInstr *CurMI;
434 // Section Symbols: these are assembler temporary labels that are emitted at
435 // the beginning of each supported dwarf section. These are used to form
436 // section offsets and are created by EmitSectionLabels.
437 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
438 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
439 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
440 MCSymbol *FunctionBeginSym, *FunctionEndSym;
441 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
442 MCSymbol *DwarfStrDWOSectionSym;
443 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
445 // As an optimization, there is no need to emit an entry in the directory
446 // table for the same directory as DW_AT_comp_dir.
447 StringRef CompilationDir;
449 // Counter for assigning globally unique IDs for ranges.
450 unsigned GlobalRangeCount;
452 // Holder for the file specific debug information.
453 DwarfFile InfoHolder;
455 // Holders for the various debug information flags that we might need to
456 // have exposed. See accessor functions below for description.
458 // Holder for imported entities.
459 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
461 ImportedEntityMap ScopesWithImportedEntities;
463 // Map from MDNodes for user-defined types to the type units that describe
465 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
467 // Whether to emit the pubnames/pubtypes sections.
468 bool HasDwarfPubSections;
470 // Whether or not to use AT_ranges for compilation units.
473 // Whether we emitted a function into a section other than the default
475 bool UsedNonDefaultText;
477 // Version of dwarf we're emitting.
478 unsigned DwarfVersion;
480 // Maps from a type identifier to the actual MDNode.
481 DITypeIdentifierMap TypeIdentifierMap;
483 // DWARF5 Experimental Options
484 bool HasDwarfAccelTables;
487 // Separated Dwarf Variables
488 // In general these will all be for bits that are left in the
489 // original object file, rather than things that are meant
490 // to be in the .dwo sections.
492 // Holder for the skeleton information.
493 DwarfFile SkeletonHolder;
495 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
497 const SmallVectorImpl<DwarfUnit *> &getUnits() {
498 return InfoHolder.getUnits();
501 /// \brief Find abstract variable associated with Var.
502 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
504 /// \brief Find DIE for the given subprogram and attach appropriate
505 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
506 /// variables in this scope then create and insert DIEs for these
508 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
510 /// \brief A helper function to check whether the DIE for a given Scope is
511 /// going to be null.
512 bool isLexicalScopeDIENull(LexicalScope *Scope);
514 /// \brief A helper function to construct a RangeSpanList for a given
516 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
517 const SmallVectorImpl<InsnRange> &Range);
519 /// \brief Construct new DW_TAG_lexical_block for this scope and
520 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
521 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
523 /// \brief This scope represents inlined body of a function. Construct
524 /// DIE to represent this concrete inlined copy of the function.
525 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
527 /// \brief Construct a DIE for this scope.
528 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
529 /// A helper function to create children of a Scope DIE.
530 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
531 SmallVectorImpl<DIE *> &Children);
533 /// \brief Emit initial Dwarf sections with a label at the start of each one.
534 void emitSectionLabels();
536 /// \brief Compute the size and offset of a DIE given an incoming Offset.
537 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
539 /// \brief Compute the size and offset of all the DIEs.
540 void computeSizeAndOffsets();
542 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
543 void computeInlinedDIEs();
545 /// \brief Collect info for variables that were optimized out.
546 void collectDeadVariables();
548 /// \brief Finish off debug information after all functions have been
550 void finalizeModuleInfo();
552 /// \brief Emit labels to close any remaining sections that have been left
556 /// \brief Emit the debug info section.
557 void emitDebugInfo();
559 /// \brief Emit the abbreviation section.
560 void emitAbbreviations();
562 /// \brief Emit the last address of the section and the end of
564 void emitEndOfLineMatrix(unsigned SectionEnd);
566 /// \brief Emit visible names into a hashed accelerator table section.
567 void emitAccelNames();
569 /// \brief Emit objective C classes and categories into a hashed
570 /// accelerator table section.
571 void emitAccelObjC();
573 /// \brief Emit namespace dies into a hashed accelerator table.
574 void emitAccelNamespaces();
576 /// \brief Emit type dies into a hashed accelerator table.
577 void emitAccelTypes();
579 /// \brief Emit visible names into a debug pubnames section.
580 /// \param GnuStyle determines whether or not we want to emit
581 /// additional information into the table ala newer gcc for gdb
583 void emitDebugPubNames(bool GnuStyle = false);
585 /// \brief Emit visible types into a debug pubtypes section.
586 /// \param GnuStyle determines whether or not we want to emit
587 /// additional information into the table ala newer gcc for gdb
589 void emitDebugPubTypes(bool GnuStyle = false);
592 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
593 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
596 /// \brief Emit visible names into a debug str section.
599 /// \brief Emit visible names into a debug loc section.
602 /// \brief Emit visible names into a debug aranges section.
603 void emitDebugARanges();
605 /// \brief Emit visible names into a debug ranges section.
606 void emitDebugRanges();
608 /// \brief Emit inline info using custom format.
609 void emitDebugInlineInfo();
611 /// DWARF 5 Experimental Split Dwarf Emitters
613 /// \brief Initialize common features of skeleton units.
614 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
616 /// \brief Construct the split debug info compile unit for the debug info
618 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
620 /// \brief Construct the split debug info compile unit for the debug info
622 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
624 /// \brief Emit the debug info dwo section.
625 void emitDebugInfoDWO();
627 /// \brief Emit the debug abbrev dwo section.
628 void emitDebugAbbrevDWO();
630 /// \brief Emit the debug str dwo section.
631 void emitDebugStrDWO();
633 /// Flags to let the linker know we have emitted new style pubnames. Only
634 /// emit it here if we don't have a skeleton CU for split dwarf.
635 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
637 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
638 /// DW_TAG_compile_unit.
639 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
641 /// \brief Construct subprogram DIE.
642 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
644 /// \brief Construct imported_module or imported_declaration DIE.
645 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
647 /// \brief Construct import_module DIE.
648 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
651 /// \brief Construct import_module DIE.
652 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
653 const DIImportedEntity &Module, DIE *Context);
655 /// \brief Register a source line with debug info. Returns the unique
656 /// label that was emitted and which provides correspondence to the
657 /// source line list.
658 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
661 /// \brief Indentify instructions that are marking the beginning of or
662 /// ending of a scope.
663 void identifyScopeMarkers();
665 /// \brief If Var is an current function argument that add it in
666 /// CurrentFnArguments list.
667 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
669 /// \brief Populate LexicalScope entries with variables' info.
670 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
672 /// \brief Collect variable information from the side table maintained
674 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
676 /// \brief Ensure that a label will be emitted before MI.
677 void requestLabelBeforeInsn(const MachineInstr *MI) {
678 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
681 /// \brief Return Label preceding the instruction.
682 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
684 /// \brief Ensure that a label will be emitted after MI.
685 void requestLabelAfterInsn(const MachineInstr *MI) {
686 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
689 /// \brief Return Label immediately following the instruction.
690 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
692 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
696 //===--------------------------------------------------------------------===//
697 // Main entry points.
699 DwarfDebug(AsmPrinter *A, Module *M);
701 void insertDIE(const MDNode *TypeMD, DIE *Die) {
702 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
704 DIE *getDIE(const MDNode *TypeMD) {
705 return MDTypeNodeToDieMap.lookup(TypeMD);
708 /// \brief Look up or create an entry in the OdrMemberMap.
709 const MDNode *&getOrCreateOdrMember(StringRef Key) {
710 return OdrMemberMap.GetOrCreateValue(Key).getValue();
713 /// \brief Emit all Dwarf sections that should come prior to the
717 /// \brief Emit all Dwarf sections that should come after the content.
718 void endModule() override;
720 /// \brief Gather pre-function debug information.
721 void beginFunction(const MachineFunction *MF) override;
723 /// \brief Gather and emit post-function debug information.
724 void endFunction(const MachineFunction *MF) override;
726 /// \brief Process beginning of an instruction.
727 void beginInstruction(const MachineInstr *MI) override;
729 /// \brief Process end of an instruction.
730 void endInstruction() override;
732 /// \brief Add a DIE to the set of types that we're going to pull into
734 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
735 DIE *Die, DICompositeType CTy);
737 /// \brief Add a label so that arange data can be generated for it.
738 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
740 /// \brief For symbols that have a size designated (e.g. common symbols),
741 /// this tracks that size.
742 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
746 /// \brief Look up the source id with the given directory and source file
747 /// names. If none currently exists, create a new id and insert it in the
749 unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName,
752 /// \brief Recursively Emits a debug information entry.
753 void emitDIE(DIE *Die);
755 // Experimental DWARF5 features.
757 /// \brief Returns whether or not to emit tables that dwarf consumers can
758 /// use to accelerate lookup.
759 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
761 /// \brief Returns whether or not to change the current debug info for the
762 /// split dwarf proposal support.
763 bool useSplitDwarf() const { return HasSplitDwarf; }
765 /// \brief Returns whether or not to use AT_ranges for compilation units.
766 bool useCURanges() const { return HasCURanges; }
768 /// Returns the Dwarf Version.
769 unsigned getDwarfVersion() const { return DwarfVersion; }
771 /// Returns the section symbol for the .debug_loc section.
772 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
774 /// Returns the entries for the .debug_loc section.
775 const SmallVectorImpl<DotDebugLocEntry> &getDebugLocEntries() const {
776 return DotDebugLocEntries;
779 /// \brief Emit an entry for the debug loc section. This can be used to
780 /// handle an entry that's going to be emitted into the debug loc section.
781 void emitDebugLocEntry(ByteStreamer &Streamer, const DotDebugLocEntry &Entry);
783 /// Find the MDNode for the given reference.
784 template <typename T> T resolve(DIRef<T> Ref) const {
785 return Ref.resolve(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