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/LexicalScopes.h"
26 #include "llvm/IR/DebugInfo.h"
27 #include "llvm/IR/DebugLoc.h"
28 #include "llvm/MC/MachineLocation.h"
29 #include "llvm/MC/MCDwarf.h"
30 #include "llvm/Support/Allocator.h"
38 class DwarfCompileUnit;
42 class MachineFrameInfo;
43 class MachineModuleInfo;
46 class MCObjectFileInfo;
52 //===----------------------------------------------------------------------===//
53 /// \brief This class is used to record source line correspondence.
55 unsigned Line; // Source line number.
56 unsigned Column; // Source column.
57 unsigned SourceID; // Source ID number.
58 MCSymbol *Label; // Label in code ID number.
60 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
61 : Line(L), Column(C), SourceID(S), Label(label) {}
64 unsigned getLine() const { return Line; }
65 unsigned getColumn() const { return Column; }
66 unsigned getSourceID() const { return SourceID; }
67 MCSymbol *getLabel() const { return Label; }
70 /// \brief This struct describes location entries emitted in the .debug_loc
73 // Begin and end symbols for the address range that this location is valid.
74 const MCSymbol *Begin;
77 // Type of entry that this represents.
78 enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
79 enum EntryType EntryKind;
83 const ConstantFP *CFP;
84 const ConstantInt *CIP;
87 // The location in the machine frame.
90 // The variable to which this location entry corresponds.
91 const MDNode *Variable;
93 // Whether this location has been merged.
97 DebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
100 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
102 : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
104 EntryKind = E_Location;
106 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
107 : Begin(B), End(E), Variable(0), Merged(false) {
109 EntryKind = E_Integer;
111 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
112 : Begin(B), End(E), Variable(0), Merged(false) {
113 Constants.CFP = FPtr;
114 EntryKind = E_ConstantFP;
116 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr)
117 : Begin(B), End(E), Variable(0), Merged(false) {
118 Constants.CIP = IPtr;
119 EntryKind = E_ConstantInt;
122 /// \brief Empty entries are also used as a trigger to emit temp label. Such
123 /// labels are referenced is used to find debug_loc offset for a given DIE.
124 bool isEmpty() const { return Begin == 0 && End == 0; }
125 bool isMerged() const { return Merged; }
126 void Merge(DebugLocEntry *Next) {
127 if (!(Begin && Loc == Next->Loc && End == Next->Begin))
132 bool isLocation() const { return EntryKind == E_Location; }
133 bool isInt() const { return EntryKind == E_Integer; }
134 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
135 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
136 int64_t getInt() const { return Constants.Int; }
137 const ConstantFP *getConstantFP() const { return Constants.CFP; }
138 const ConstantInt *getConstantInt() const { return Constants.CIP; }
139 const MDNode *getVariable() const { return Variable; }
140 const MCSymbol *getBeginSym() const { return Begin; }
141 const MCSymbol *getEndSym() const { return End; }
142 MachineLocation getLoc() const { return Loc; }
145 //===----------------------------------------------------------------------===//
146 /// \brief This class is used to track local variable information.
148 DIVariable Var; // Variable Descriptor.
149 DIE *TheDIE; // Variable DIE.
150 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
151 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
152 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
157 // AbsVar may be NULL.
158 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
159 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
160 FrameIndex(~0), DD(DD) {}
163 DIVariable getVariable() const { return Var; }
164 void setDIE(DIE *D) { TheDIE = D; }
165 DIE *getDIE() const { return TheDIE; }
166 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
167 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
168 StringRef getName() const { return Var.getName(); }
169 DbgVariable *getAbstractVariable() const { return AbsVar; }
170 const MachineInstr *getMInsn() const { return MInsn; }
171 void setMInsn(const MachineInstr *M) { MInsn = M; }
172 int getFrameIndex() const { return FrameIndex; }
173 void setFrameIndex(int FI) { FrameIndex = FI; }
174 // Translate tag to proper Dwarf tag.
175 uint16_t getTag() const {
176 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
177 return dwarf::DW_TAG_formal_parameter;
179 return dwarf::DW_TAG_variable;
181 /// \brief Return true if DbgVariable is artificial.
182 bool isArtificial() const {
183 if (Var.isArtificial())
185 if (getType().isArtificial())
190 bool isObjectPointer() const {
191 if (Var.isObjectPointer())
193 if (getType().isObjectPointer())
198 bool variableHasComplexAddress() const {
199 assert(Var.isVariable() && "Invalid complex DbgVariable!");
200 return Var.hasComplexAddress();
202 bool isBlockByrefVariable() const;
203 unsigned getNumAddrElements() const {
204 assert(Var.isVariable() && "Invalid complex DbgVariable!");
205 return Var.getNumAddrElements();
207 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
208 DIType getType() const;
211 /// resolve - Look in the DwarfDebug map for the MDNode that
212 /// corresponds to the reference.
213 template <typename T> T resolve(DIRef<T> Ref) const;
216 /// \brief Collects and handles information specific to a particular
217 /// collection of units. This collection represents all of the units
218 /// that will be ultimately output into a single object file.
220 // Target of Dwarf emission, used for sizing of abbreviations.
223 // Used to uniquely define abbreviations.
224 FoldingSet<DIEAbbrev> AbbreviationsSet;
226 // A list of all the unique abbreviations in use.
227 std::vector<DIEAbbrev *> Abbreviations;
229 // A pointer to all units in the section.
230 SmallVector<DwarfUnit *, 1> CUs;
232 // Collection of strings for this unit and assorted symbols.
233 // A String->Symbol mapping of strings used by indirect
235 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
238 unsigned NextStringPoolNumber;
239 std::string StringPref;
241 struct AddressPoolEntry {
244 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
246 // Collection of addresses for this unit and assorted labels.
247 // A Symbol->unsigned mapping of addresses used by indirect
249 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
250 AddrPool AddressPool;
251 unsigned NextAddrPoolNumber;
254 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
255 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
256 AddressPool(), NextAddrPoolNumber(0) {}
260 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
262 /// \brief Compute the size and offset of a DIE given an incoming Offset.
263 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
265 /// \brief Compute the size and offset of all the DIEs.
266 void computeSizeAndOffsets();
268 /// \brief Define a unique number for the abbreviation.
269 void assignAbbrevNumber(DIEAbbrev &Abbrev);
271 /// \brief Add a unit to the list of CUs.
272 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
274 /// \brief Emit all of the units to the section listed with the given
275 /// abbreviation section.
276 void emitUnits(DwarfDebug *DD, const MCSection *ASection,
277 const MCSymbol *ASectionSym);
279 /// \brief Emit a set of abbreviations to the specific section.
280 void emitAbbrevs(const MCSection *);
282 /// \brief Emit all of the strings to the section given.
283 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
284 const MCSymbol *StrSecSym);
286 /// \brief Emit all of the addresses to the section given.
287 void emitAddresses(const MCSection *AddrSection);
289 /// \brief Returns the entry into the start of the pool.
290 MCSymbol *getStringPoolSym();
292 /// \brief Returns an entry into the string pool with the given
294 MCSymbol *getStringPoolEntry(StringRef Str);
296 /// \brief Returns the index into the string pool with the given
298 unsigned getStringPoolIndex(StringRef Str);
300 /// \brief Returns the string pool.
301 StrPool *getStringPool() { return &StringPool; }
303 /// \brief Returns the index into the address pool with the given
305 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
307 /// \brief Returns the address pool.
308 AddrPool *getAddrPool() { return &AddressPool; }
311 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
313 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
315 DwarfCompileUnit *CU;
318 /// \brief Collects and handles dwarf debug information.
319 class DwarfDebug : public AsmPrinterHandler {
320 // Target of Dwarf emission.
323 // Collected machine module information.
324 MachineModuleInfo *MMI;
326 // All DIEValues are allocated through this allocator.
327 BumpPtrAllocator DIEValueAllocator;
329 // Handle to the compile unit used for the inline extension handling,
330 // this is just so that the DIEValue allocator has a place to store
331 // the particular elements.
332 // FIXME: Store these off of DwarfDebug instead?
333 DwarfCompileUnit *FirstCU;
335 // Maps MDNode with its corresponding DwarfCompileUnit.
336 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
338 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
339 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
341 // Maps a CU DIE with its corresponding DwarfCompileUnit.
342 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
344 /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
345 /// be shared across CUs, that is why we keep the map here instead
346 /// of in DwarfCompileUnit.
347 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
349 // Used to unique C++ member function declarations.
350 StringMap<const MDNode *> OdrMemberMap;
352 // List of all labels used in aranges generation.
353 std::vector<SymbolCU> ArangeLabels;
355 // Size of each symbol emitted (for those symbols that have a specific size).
356 DenseMap<const MCSymbol *, uint64_t> SymSize;
358 // Provides a unique id per text section.
359 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
360 SectionMapType SectionMap;
362 // List of arguments for current function.
363 SmallVector<DbgVariable *, 8> CurrentFnArguments;
365 LexicalScopes LScopes;
367 // Collection of abstract subprogram DIEs.
368 DenseMap<const MDNode *, DIE *> AbstractSPDies;
370 // Collection of dbg variables of a scope.
371 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
373 ScopeVariablesMap ScopeVariables;
375 // Collection of abstract variables.
376 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
378 // Collection of DebugLocEntry.
379 SmallVector<DebugLocEntry, 4> DotDebugLocEntries;
381 // Collection of subprogram DIEs that are marked (at the end of the module)
383 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
385 // This is a collection of subprogram MDNodes that are processed to
387 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
389 // Maps instruction with label emitted before instruction.
390 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
392 // Maps instruction with label emitted after instruction.
393 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
395 // Every user variable mentioned by a DBG_VALUE instruction in order of
397 SmallVector<const MDNode *, 8> UserVariables;
399 // For each user variable, keep a list of DBG_VALUE instructions in order.
400 // The list can also contain normal instructions that clobber the previous
402 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
404 DbgValueHistoryMap DbgValues;
406 // Previous instruction's location information. This is used to determine
407 // label location to indicate scope boundries in dwarf debug info.
408 DebugLoc PrevInstLoc;
411 // This location indicates end of function prologue and beginning of function
413 DebugLoc PrologEndLoc;
415 // If nonnull, stores the current machine function we're processing.
416 const MachineFunction *CurFn;
418 // If nonnull, stores the current machine instruction we're processing.
419 const MachineInstr *CurMI;
421 // Section Symbols: these are assembler temporary labels that are emitted at
422 // the beginning of each supported dwarf section. These are used to form
423 // section offsets and are created by EmitSectionLabels.
424 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
425 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
426 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
427 MCSymbol *FunctionBeginSym, *FunctionEndSym;
428 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
429 MCSymbol *DwarfStrDWOSectionSym;
430 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
432 // As an optimization, there is no need to emit an entry in the directory
433 // table for the same directory as DW_AT_comp_dir.
434 StringRef CompilationDir;
436 // Counter for assigning globally unique IDs for ranges.
437 unsigned GlobalRangeCount;
439 // Holder for the file specific debug information.
440 DwarfFile InfoHolder;
442 // Holders for the various debug information flags that we might need to
443 // have exposed. See accessor functions below for description.
445 // Holder for imported entities.
446 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
448 ImportedEntityMap ScopesWithImportedEntities;
450 // Map from MDNodes for user-defined types to the type units that describe
452 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
454 // Whether to emit the pubnames/pubtypes sections.
455 bool HasDwarfPubSections;
457 // Whether or not to use AT_ranges for compilation units.
460 // Whether we emitted a function into a section other than the default
462 bool UsedNonDefaultText;
464 // Version of dwarf we're emitting.
465 unsigned DwarfVersion;
467 // Maps from a type identifier to the actual MDNode.
468 DITypeIdentifierMap TypeIdentifierMap;
470 // DWARF5 Experimental Options
471 bool HasDwarfAccelTables;
474 // Separated Dwarf Variables
475 // In general these will all be for bits that are left in the
476 // original object file, rather than things that are meant
477 // to be in the .dwo sections.
479 // Holder for the skeleton information.
480 DwarfFile SkeletonHolder;
482 // Store file names for type units under fission in a line table header that
483 // will be emitted into debug_line.dwo.
484 MCDwarfDwoLineTable SplitTypeUnitFileTable;
486 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
488 const SmallVectorImpl<DwarfUnit *> &getUnits() {
489 return InfoHolder.getUnits();
492 /// \brief Find abstract variable associated with Var.
493 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
495 /// \brief Find DIE for the given subprogram and attach appropriate
496 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
497 /// variables in this scope then create and insert DIEs for these
499 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
501 /// \brief A helper function to check whether the DIE for a given Scope is
502 /// going to be null.
503 bool isLexicalScopeDIENull(LexicalScope *Scope);
505 /// \brief A helper function to construct a RangeSpanList for a given
507 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
508 const SmallVectorImpl<InsnRange> &Range);
510 /// \brief Construct new DW_TAG_lexical_block for this scope and
511 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
512 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
514 /// \brief This scope represents inlined body of a function. Construct
515 /// DIE to represent this concrete inlined copy of the function.
516 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
518 /// \brief Construct a DIE for this scope.
519 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
520 /// A helper function to create children of a Scope DIE.
521 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
522 SmallVectorImpl<DIE *> &Children);
524 /// \brief Emit initial Dwarf sections with a label at the start of each one.
525 void emitSectionLabels();
527 /// \brief Compute the size and offset of a DIE given an incoming Offset.
528 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
530 /// \brief Compute the size and offset of all the DIEs.
531 void computeSizeAndOffsets();
533 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
534 void computeInlinedDIEs();
536 /// \brief Collect info for variables that were optimized out.
537 void collectDeadVariables();
539 /// \brief Finish off debug information after all functions have been
541 void finalizeModuleInfo();
543 /// \brief Emit labels to close any remaining sections that have been left
547 /// \brief Emit the debug info section.
548 void emitDebugInfo();
550 /// \brief Emit the abbreviation section.
551 void emitAbbreviations();
553 /// \brief Emit the last address of the section and the end of
555 void emitEndOfLineMatrix(unsigned SectionEnd);
557 /// \brief Emit visible names into a hashed accelerator table section.
558 void emitAccelNames();
560 /// \brief Emit objective C classes and categories into a hashed
561 /// accelerator table section.
562 void emitAccelObjC();
564 /// \brief Emit namespace dies into a hashed accelerator table.
565 void emitAccelNamespaces();
567 /// \brief Emit type dies into a hashed accelerator table.
568 void emitAccelTypes();
570 /// \brief Emit visible names into a debug pubnames section.
571 /// \param GnuStyle determines whether or not we want to emit
572 /// additional information into the table ala newer gcc for gdb
574 void emitDebugPubNames(bool GnuStyle = false);
576 /// \brief Emit visible types into a debug pubtypes section.
577 /// \param GnuStyle determines whether or not we want to emit
578 /// additional information into the table ala newer gcc for gdb
580 void emitDebugPubTypes(bool GnuStyle = false);
583 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
584 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
587 /// \brief Emit visible names into a debug str section.
590 /// \brief Emit visible names into a debug loc section.
593 /// \brief Emit visible names into a debug aranges section.
594 void emitDebugARanges();
596 /// \brief Emit visible names into a debug ranges section.
597 void emitDebugRanges();
599 /// \brief Emit inline info using custom format.
600 void emitDebugInlineInfo();
602 /// DWARF 5 Experimental Split Dwarf Emitters
604 /// \brief Initialize common features of skeleton units.
605 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
607 /// \brief Construct the split debug info compile unit for the debug info
609 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
611 /// \brief Construct the split debug info compile unit for the debug info
613 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
615 /// \brief Emit the debug info dwo section.
616 void emitDebugInfoDWO();
618 /// \brief Emit the debug abbrev dwo section.
619 void emitDebugAbbrevDWO();
621 /// \brief Emit the debug line dwo section.
622 void emitDebugLineDWO();
624 /// \brief Emit the debug str dwo section.
625 void emitDebugStrDWO();
627 /// Flags to let the linker know we have emitted new style pubnames. Only
628 /// emit it here if we don't have a skeleton CU for split dwarf.
629 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
631 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
632 /// DW_TAG_compile_unit.
633 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit,
636 /// \brief Construct subprogram DIE.
637 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
639 /// \brief Construct imported_module or imported_declaration DIE.
640 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
642 /// \brief Construct import_module DIE.
643 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
646 /// \brief Construct import_module DIE.
647 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
648 const DIImportedEntity &Module, DIE *Context);
650 /// \brief Register a source line with debug info. Returns the unique
651 /// label that was emitted and which provides correspondence to the
652 /// source line list.
653 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
656 /// \brief Indentify instructions that are marking the beginning of or
657 /// ending of a scope.
658 void identifyScopeMarkers();
660 /// \brief If Var is an current function argument that add it in
661 /// CurrentFnArguments list.
662 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
664 /// \brief Populate LexicalScope entries with variables' info.
665 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
667 /// \brief Collect variable information from the side table maintained
669 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
671 /// \brief Ensure that a label will be emitted before MI.
672 void requestLabelBeforeInsn(const MachineInstr *MI) {
673 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
676 /// \brief Return Label preceding the instruction.
677 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
679 /// \brief Ensure that a label will be emitted after MI.
680 void requestLabelAfterInsn(const MachineInstr *MI) {
681 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
684 /// \brief Return Label immediately following the instruction.
685 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
687 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
691 //===--------------------------------------------------------------------===//
692 // Main entry points.
694 DwarfDebug(AsmPrinter *A, Module *M);
696 void insertDIE(const MDNode *TypeMD, DIE *Die) {
697 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
699 DIE *getDIE(const MDNode *TypeMD) {
700 return MDTypeNodeToDieMap.lookup(TypeMD);
703 /// \brief Look up or create an entry in the OdrMemberMap.
704 const MDNode *&getOrCreateOdrMember(StringRef Key) {
705 return OdrMemberMap.GetOrCreateValue(Key).getValue();
708 /// \brief Emit all Dwarf sections that should come prior to the
712 /// \brief Emit all Dwarf sections that should come after the content.
713 void endModule() override;
715 /// \brief Gather pre-function debug information.
716 void beginFunction(const MachineFunction *MF) override;
718 /// \brief Gather and emit post-function debug information.
719 void endFunction(const MachineFunction *MF) override;
721 /// \brief Process beginning of an instruction.
722 void beginInstruction(const MachineInstr *MI) override;
724 /// \brief Process end of an instruction.
725 void endInstruction() override;
727 /// \brief Add a DIE to the set of types that we're going to pull into
729 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
730 DIE *Die, DICompositeType CTy);
732 /// \brief Add a label so that arange data can be generated for it.
733 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
735 /// \brief For symbols that have a size designated (e.g. common symbols),
736 /// this tracks that size.
737 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
741 /// \brief Recursively Emits a debug information entry.
742 void emitDIE(DIE *Die);
744 // Experimental DWARF5 features.
746 /// \brief Returns whether or not to emit tables that dwarf consumers can
747 /// use to accelerate lookup.
748 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
750 /// \brief Returns whether or not to change the current debug info for the
751 /// split dwarf proposal support.
752 bool useSplitDwarf() const { return HasSplitDwarf; }
754 /// \brief Returns whether or not to use AT_ranges for compilation units.
755 bool useCURanges() const { return HasCURanges; }
757 /// Returns the Dwarf Version.
758 unsigned getDwarfVersion() const { return DwarfVersion; }
760 /// Returns the section symbol for the .debug_loc section.
761 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
763 /// Returns the entries for the .debug_loc section.
764 const SmallVectorImpl<DebugLocEntry> &getDebugLocEntries() const {
765 return DotDebugLocEntries;
768 /// \brief Emit an entry for the debug loc section. This can be used to
769 /// handle an entry that's going to be emitted into the debug loc section.
770 void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
772 /// Find the MDNode for the given reference.
773 template <typename T> T resolve(DIRef<T> Ref) const {
774 return Ref.resolve(TypeIdentifierMap);
777 /// \brief Return the TypeIdentifierMap.
778 const DITypeIdentifierMap& getTypeIdentifierMap() const {
779 return TypeIdentifierMap;
782 /// Find the DwarfCompileUnit for the given CU Die.
783 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
784 return CUDieMap.lookup(CU);
786 /// isSubprogramContext - Return true if Context is either a subprogram
787 /// or another context nested inside a subprogram.
788 bool isSubprogramContext(const MDNode *Context);
790 } // End of namespace llvm