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/CodeGen/LexicalScopes.h"
22 #include "llvm/IR/DebugInfo.h"
23 #include "llvm/MC/MachineLocation.h"
24 #include "llvm/MC/MCDwarf.h"
25 #include "llvm/Support/Allocator.h"
33 class DwarfCompileUnit;
37 class MachineModuleInfo;
39 //===----------------------------------------------------------------------===//
40 /// \brief This class is used to record source line correspondence.
42 unsigned Line; // Source line number.
43 unsigned Column; // Source column.
44 unsigned SourceID; // Source ID number.
45 MCSymbol *Label; // Label in code ID number.
47 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
48 : Line(L), Column(C), SourceID(S), Label(label) {}
51 unsigned getLine() const { return Line; }
52 unsigned getColumn() const { return Column; }
53 unsigned getSourceID() const { return SourceID; }
54 MCSymbol *getLabel() const { return Label; }
57 /// \brief This struct describes location entries emitted in the .debug_loc
60 // Begin and end symbols for the address range that this location is valid.
61 const MCSymbol *Begin;
64 // Type of entry that this represents.
65 enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
66 enum EntryType EntryKind;
70 const ConstantFP *CFP;
71 const ConstantInt *CIP;
74 // The location in the machine frame.
77 // The variable to which this location entry corresponds.
78 const MDNode *Variable;
80 // Whether this location has been merged.
84 DebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
87 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
89 : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
91 EntryKind = E_Location;
93 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
94 : Begin(B), End(E), Variable(0), Merged(false) {
96 EntryKind = E_Integer;
98 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
99 : Begin(B), End(E), Variable(0), Merged(false) {
100 Constants.CFP = FPtr;
101 EntryKind = E_ConstantFP;
103 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr)
104 : Begin(B), End(E), Variable(0), Merged(false) {
105 Constants.CIP = IPtr;
106 EntryKind = E_ConstantInt;
109 /// \brief Empty entries are also used as a trigger to emit temp label. Such
110 /// labels are referenced is used to find debug_loc offset for a given DIE.
111 bool isEmpty() const { return Begin == 0 && End == 0; }
112 bool isMerged() const { return Merged; }
113 void Merge(DebugLocEntry *Next) {
114 if (!(Begin && Loc == Next->Loc && End == Next->Begin))
119 bool isLocation() const { return EntryKind == E_Location; }
120 bool isInt() const { return EntryKind == E_Integer; }
121 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
122 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
123 int64_t getInt() const { return Constants.Int; }
124 const ConstantFP *getConstantFP() const { return Constants.CFP; }
125 const ConstantInt *getConstantInt() const { return Constants.CIP; }
126 const MDNode *getVariable() const { return Variable; }
127 const MCSymbol *getBeginSym() const { return Begin; }
128 const MCSymbol *getEndSym() const { return End; }
129 MachineLocation getLoc() const { return Loc; }
132 //===----------------------------------------------------------------------===//
133 /// \brief This class is used to track local variable information.
135 DIVariable Var; // Variable Descriptor.
136 DIE *TheDIE; // Variable DIE.
137 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
138 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
139 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
144 // AbsVar may be NULL.
145 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
146 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
147 FrameIndex(~0), DD(DD) {}
150 DIVariable getVariable() const { return Var; }
151 void setDIE(DIE *D) { TheDIE = D; }
152 DIE *getDIE() const { return TheDIE; }
153 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
154 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
155 StringRef getName() const { return Var.getName(); }
156 DbgVariable *getAbstractVariable() const { return AbsVar; }
157 const MachineInstr *getMInsn() const { return MInsn; }
158 void setMInsn(const MachineInstr *M) { MInsn = M; }
159 int getFrameIndex() const { return FrameIndex; }
160 void setFrameIndex(int FI) { FrameIndex = FI; }
161 // Translate tag to proper Dwarf tag.
162 uint16_t getTag() const {
163 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
164 return dwarf::DW_TAG_formal_parameter;
166 return dwarf::DW_TAG_variable;
168 /// \brief Return true if DbgVariable is artificial.
169 bool isArtificial() const {
170 if (Var.isArtificial())
172 if (getType().isArtificial())
177 bool isObjectPointer() const {
178 if (Var.isObjectPointer())
180 if (getType().isObjectPointer())
185 bool variableHasComplexAddress() const {
186 assert(Var.isVariable() && "Invalid complex DbgVariable!");
187 return Var.hasComplexAddress();
189 bool isBlockByrefVariable() const;
190 unsigned getNumAddrElements() const {
191 assert(Var.isVariable() && "Invalid complex DbgVariable!");
192 return Var.getNumAddrElements();
194 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
195 DIType getType() const;
198 /// resolve - Look in the DwarfDebug map for the MDNode that
199 /// corresponds to the reference.
200 template <typename T> T resolve(DIRef<T> Ref) const;
203 /// \brief Collects and handles information specific to a particular
204 /// collection of units. This collection represents all of the units
205 /// that will be ultimately output into a single object file.
207 // Target of Dwarf emission, used for sizing of abbreviations.
210 // Used to uniquely define abbreviations.
211 FoldingSet<DIEAbbrev> AbbreviationsSet;
213 // A list of all the unique abbreviations in use.
214 std::vector<DIEAbbrev *> Abbreviations;
216 // A pointer to all units in the section.
217 SmallVector<DwarfUnit *, 1> CUs;
219 // Collection of strings for this unit and assorted symbols.
220 // A String->Symbol mapping of strings used by indirect
222 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
225 unsigned NextStringPoolNumber;
226 std::string StringPref;
228 struct AddressPoolEntry {
231 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
233 // Collection of addresses for this unit and assorted labels.
234 // A Symbol->unsigned mapping of addresses used by indirect
236 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
237 AddrPool AddressPool;
238 unsigned NextAddrPoolNumber;
241 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
242 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
243 AddressPool(), NextAddrPoolNumber(0) {}
247 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
249 /// \brief Compute the size and offset of a DIE given an incoming Offset.
250 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
252 /// \brief Compute the size and offset of all the DIEs.
253 void computeSizeAndOffsets();
255 /// \brief Define a unique number for the abbreviation.
256 void assignAbbrevNumber(DIEAbbrev &Abbrev);
258 /// \brief Add a unit to the list of CUs.
259 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
261 /// \brief Emit all of the units to the section listed with the given
262 /// abbreviation section.
263 void emitUnits(DwarfDebug *DD, const MCSection *ASection,
264 const MCSymbol *ASectionSym);
266 /// \brief Emit a set of abbreviations to the specific section.
267 void emitAbbrevs(const MCSection *);
269 /// \brief Emit all of the strings to the section given.
270 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
271 const MCSymbol *StrSecSym);
273 /// \brief Emit all of the addresses to the section given.
274 void emitAddresses(const MCSection *AddrSection);
276 /// \brief Returns the entry into the start of the pool.
277 MCSymbol *getStringPoolSym();
279 /// \brief Returns an entry into the string pool with the given
281 MCSymbol *getStringPoolEntry(StringRef Str);
283 /// \brief Returns the index into the string pool with the given
285 unsigned getStringPoolIndex(StringRef Str);
287 /// \brief Returns the string pool.
288 StrPool *getStringPool() { return &StringPool; }
290 /// \brief Returns the index into the address pool with the given
292 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
294 /// \brief Returns the address pool.
295 AddrPool *getAddrPool() { return &AddressPool; }
298 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
300 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
302 DwarfCompileUnit *CU;
305 /// \brief Collects and handles dwarf debug information.
306 class DwarfDebug : public AsmPrinterHandler {
307 // Target of Dwarf emission.
310 // Collected machine module information.
311 MachineModuleInfo *MMI;
313 // All DIEValues are allocated through this allocator.
314 BumpPtrAllocator DIEValueAllocator;
316 // Handle to the compile unit used for the inline extension handling,
317 // this is just so that the DIEValue allocator has a place to store
318 // the particular elements.
319 // FIXME: Store these off of DwarfDebug instead?
320 DwarfCompileUnit *FirstCU;
322 // Maps MDNode with its corresponding DwarfCompileUnit.
323 MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
325 // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
326 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
328 // Maps a CU DIE with its corresponding DwarfCompileUnit.
329 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
331 /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
332 /// be shared across CUs, that is why we keep the map here instead
333 /// of in DwarfCompileUnit.
334 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
336 // List of all labels used in aranges generation.
337 std::vector<SymbolCU> ArangeLabels;
339 // Size of each symbol emitted (for those symbols that have a specific size).
340 DenseMap<const MCSymbol *, uint64_t> SymSize;
342 // Provides a unique id per text section.
343 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
344 SectionMapType SectionMap;
346 // List of arguments for current function.
347 SmallVector<DbgVariable *, 8> CurrentFnArguments;
349 LexicalScopes LScopes;
351 // Collection of abstract subprogram DIEs.
352 DenseMap<const MDNode *, DIE *> AbstractSPDies;
354 // Collection of dbg variables of a scope.
355 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
357 ScopeVariablesMap ScopeVariables;
359 // Collection of abstract variables.
360 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
362 // Collection of DebugLocEntry.
363 SmallVector<DebugLocEntry, 4> DotDebugLocEntries;
365 // Collection of subprogram DIEs that are marked (at the end of the module)
367 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
369 // This is a collection of subprogram MDNodes that are processed to
371 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
373 // Maps instruction with label emitted before instruction.
374 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
376 // Maps instruction with label emitted after instruction.
377 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
379 // Every user variable mentioned by a DBG_VALUE instruction in order of
381 SmallVector<const MDNode *, 8> UserVariables;
383 // For each user variable, keep a list of DBG_VALUE instructions in order.
384 // The list can also contain normal instructions that clobber the previous
386 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
388 DbgValueHistoryMap DbgValues;
390 // Previous instruction's location information. This is used to determine
391 // label location to indicate scope boundries in dwarf debug info.
392 DebugLoc PrevInstLoc;
395 // This location indicates end of function prologue and beginning of function
397 DebugLoc PrologEndLoc;
399 // If nonnull, stores the current machine function we're processing.
400 const MachineFunction *CurFn;
402 // If nonnull, stores the current machine instruction we're processing.
403 const MachineInstr *CurMI;
405 // Section Symbols: these are assembler temporary labels that are emitted at
406 // the beginning of each supported dwarf section. These are used to form
407 // section offsets and are created by EmitSectionLabels.
408 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
409 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
410 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
411 MCSymbol *FunctionBeginSym, *FunctionEndSym;
412 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
413 MCSymbol *DwarfStrDWOSectionSym;
414 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
416 // As an optimization, there is no need to emit an entry in the directory
417 // table for the same directory as DW_AT_comp_dir.
418 StringRef CompilationDir;
420 // Counter for assigning globally unique IDs for ranges.
421 unsigned GlobalRangeCount;
423 // Holder for the file specific debug information.
424 DwarfFile InfoHolder;
426 // Holders for the various debug information flags that we might need to
427 // have exposed. See accessor functions below for description.
429 // Holder for imported entities.
430 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
432 ImportedEntityMap ScopesWithImportedEntities;
434 // Map from MDNodes for user-defined types to the type units that describe
436 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
438 // Whether to emit the pubnames/pubtypes sections.
439 bool HasDwarfPubSections;
441 // Whether or not to use AT_ranges for compilation units.
444 // Whether we emitted a function into a section other than the default
446 bool UsedNonDefaultText;
448 // Version of dwarf we're emitting.
449 unsigned DwarfVersion;
451 // Maps from a type identifier to the actual MDNode.
452 DITypeIdentifierMap TypeIdentifierMap;
454 // DWARF5 Experimental Options
455 bool HasDwarfAccelTables;
458 // Separated Dwarf Variables
459 // In general these will all be for bits that are left in the
460 // original object file, rather than things that are meant
461 // to be in the .dwo sections.
463 // Holder for the skeleton information.
464 DwarfFile SkeletonHolder;
466 // Store file names for type units under fission in a line table header that
467 // will be emitted into debug_line.dwo.
468 MCDwarfDwoLineTable SplitTypeUnitFileTable;
470 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
472 const SmallVectorImpl<DwarfUnit *> &getUnits() {
473 return InfoHolder.getUnits();
476 /// \brief Find abstract variable associated with Var.
477 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
479 /// \brief Find DIE for the given subprogram and attach appropriate
480 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
481 /// variables in this scope then create and insert DIEs for these
483 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
485 /// \brief A helper function to check whether the DIE for a given Scope is
486 /// going to be null.
487 bool isLexicalScopeDIENull(LexicalScope *Scope);
489 /// \brief A helper function to construct a RangeSpanList for a given
491 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
492 const SmallVectorImpl<InsnRange> &Range);
494 /// \brief Construct new DW_TAG_lexical_block for this scope and
495 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
496 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
498 /// \brief This scope represents inlined body of a function. Construct
499 /// DIE to represent this concrete inlined copy of the function.
500 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
502 /// \brief Construct a DIE for this scope.
503 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
504 /// A helper function to create children of a Scope DIE.
505 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
506 SmallVectorImpl<DIE *> &Children);
508 /// \brief Emit initial Dwarf sections with a label at the start of each one.
509 void emitSectionLabels();
511 /// \brief Compute the size and offset of a DIE given an incoming Offset.
512 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
514 /// \brief Compute the size and offset of all the DIEs.
515 void computeSizeAndOffsets();
517 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
518 void computeInlinedDIEs();
520 /// \brief Collect info for variables that were optimized out.
521 void collectDeadVariables();
523 /// \brief Finish off debug information after all functions have been
525 void finalizeModuleInfo();
527 /// \brief Emit labels to close any remaining sections that have been left
531 /// \brief Emit the debug info section.
532 void emitDebugInfo();
534 /// \brief Emit the abbreviation section.
535 void emitAbbreviations();
537 /// \brief Emit the last address of the section and the end of
539 void emitEndOfLineMatrix(unsigned SectionEnd);
541 /// \brief Emit visible names into a hashed accelerator table section.
542 void emitAccelNames();
544 /// \brief Emit objective C classes and categories into a hashed
545 /// accelerator table section.
546 void emitAccelObjC();
548 /// \brief Emit namespace dies into a hashed accelerator table.
549 void emitAccelNamespaces();
551 /// \brief Emit type dies into a hashed accelerator table.
552 void emitAccelTypes();
554 /// \brief Emit visible names into a debug pubnames section.
555 /// \param GnuStyle determines whether or not we want to emit
556 /// additional information into the table ala newer gcc for gdb
558 void emitDebugPubNames(bool GnuStyle = false);
560 /// \brief Emit visible types into a debug pubtypes section.
561 /// \param GnuStyle determines whether or not we want to emit
562 /// additional information into the table ala newer gcc for gdb
564 void emitDebugPubTypes(bool GnuStyle = false);
567 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
568 const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
571 /// \brief Emit visible names into a debug str section.
574 /// \brief Emit visible names into a debug loc section.
577 /// \brief Emit visible names into a debug aranges section.
578 void emitDebugARanges();
580 /// \brief Emit visible names into a debug ranges section.
581 void emitDebugRanges();
583 /// \brief Emit inline info using custom format.
584 void emitDebugInlineInfo();
586 /// DWARF 5 Experimental Split Dwarf Emitters
588 /// \brief Initialize common features of skeleton units.
589 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
591 /// \brief Construct the split debug info compile unit for the debug info
593 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
595 /// \brief Construct the split debug info compile unit for the debug info
597 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
599 /// \brief Emit the debug info dwo section.
600 void emitDebugInfoDWO();
602 /// \brief Emit the debug abbrev dwo section.
603 void emitDebugAbbrevDWO();
605 /// \brief Emit the debug line dwo section.
606 void emitDebugLineDWO();
608 /// \brief Emit the debug str dwo section.
609 void emitDebugStrDWO();
611 /// Flags to let the linker know we have emitted new style pubnames. Only
612 /// emit it here if we don't have a skeleton CU for split dwarf.
613 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
615 /// \brief Create new DwarfCompileUnit for the given metadata node with tag
616 /// DW_TAG_compile_unit.
617 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit,
620 /// \brief Construct subprogram DIE.
621 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
623 /// \brief Construct imported_module or imported_declaration DIE.
624 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
626 /// \brief Construct import_module DIE.
627 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
630 /// \brief Construct import_module DIE.
631 void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
632 const DIImportedEntity &Module, DIE *Context);
634 /// \brief Register a source line with debug info. Returns the unique
635 /// label that was emitted and which provides correspondence to the
636 /// source line list.
637 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
640 /// \brief Indentify instructions that are marking the beginning of or
641 /// ending of a scope.
642 void identifyScopeMarkers();
644 /// \brief If Var is an current function argument that add it in
645 /// CurrentFnArguments list.
646 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
648 /// \brief Populate LexicalScope entries with variables' info.
649 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
651 /// \brief Collect variable information from the side table maintained
653 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
655 /// \brief Ensure that a label will be emitted before MI.
656 void requestLabelBeforeInsn(const MachineInstr *MI) {
657 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
660 /// \brief Return Label preceding the instruction.
661 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
663 /// \brief Ensure that a label will be emitted after MI.
664 void requestLabelAfterInsn(const MachineInstr *MI) {
665 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
668 /// \brief Return Label immediately following the instruction.
669 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
671 void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
675 //===--------------------------------------------------------------------===//
676 // Main entry points.
678 DwarfDebug(AsmPrinter *A, Module *M);
680 void insertDIE(const MDNode *TypeMD, DIE *Die) {
681 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
683 DIE *getDIE(const MDNode *TypeMD) {
684 return MDTypeNodeToDieMap.lookup(TypeMD);
687 /// \brief Emit all Dwarf sections that should come prior to the
691 /// \brief Emit all Dwarf sections that should come after the content.
692 void endModule() override;
694 /// \brief Gather pre-function debug information.
695 void beginFunction(const MachineFunction *MF) override;
697 /// \brief Gather and emit post-function debug information.
698 void endFunction(const MachineFunction *MF) override;
700 /// \brief Process beginning of an instruction.
701 void beginInstruction(const MachineInstr *MI) override;
703 /// \brief Process end of an instruction.
704 void endInstruction() override;
706 /// \brief Add a DIE to the set of types that we're going to pull into
708 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
709 DIE *Die, DICompositeType CTy);
711 /// \brief Add a label so that arange data can be generated for it.
712 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
714 /// \brief For symbols that have a size designated (e.g. common symbols),
715 /// this tracks that size.
716 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
720 /// \brief Recursively Emits a debug information entry.
721 void emitDIE(DIE *Die);
723 // Experimental DWARF5 features.
725 /// \brief Returns whether or not to emit tables that dwarf consumers can
726 /// use to accelerate lookup.
727 bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
729 /// \brief Returns whether or not to change the current debug info for the
730 /// split dwarf proposal support.
731 bool useSplitDwarf() const { return HasSplitDwarf; }
733 /// \brief Returns whether or not to use AT_ranges for compilation units.
734 bool useCURanges() const { return HasCURanges; }
736 /// Returns the Dwarf Version.
737 unsigned getDwarfVersion() const { return DwarfVersion; }
739 /// Returns the section symbol for the .debug_loc section.
740 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
742 /// Returns the entries for the .debug_loc section.
743 const SmallVectorImpl<DebugLocEntry> &getDebugLocEntries() const {
744 return DotDebugLocEntries;
747 /// \brief Emit an entry for the debug loc section. This can be used to
748 /// handle an entry that's going to be emitted into the debug loc section.
749 void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
751 /// Find the MDNode for the given reference.
752 template <typename T> T resolve(DIRef<T> Ref) const {
753 return Ref.resolve(TypeIdentifierMap);
756 /// \brief Return the TypeIdentifierMap.
757 const DITypeIdentifierMap& getTypeIdentifierMap() const {
758 return TypeIdentifierMap;
761 /// Find the DwarfCompileUnit for the given CU Die.
762 DwarfCompileUnit *lookupUnit(const DIE *CU) const {
763 return CUDieMap.lookup(CU);
765 /// isSubprogramContext - Return true if Context is either a subprogram
766 /// or another context nested inside a subprogram.
767 bool isSubprogramContext(const MDNode *Context);
769 } // End of namespace llvm