6d22f2721495788bd6e51d0d6a9471b8346f16e4
1 //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for writing dwarf debug info into asm files.
11 //
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
17 #include "DIE.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/SetVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/CodeGen/AsmPrinter.h"
24 #include "llvm/CodeGen/LexicalScopes.h"
25 #include "llvm/DebugInfo.h"
26 #include "llvm/MC/MachineLocation.h"
27 #include "llvm/Support/Allocator.h"
28 #include "llvm/Support/DebugLoc.h"
30 namespace llvm {
32 class CompileUnit;
33 class ConstantInt;
34 class ConstantFP;
35 class DbgVariable;
36 class MachineFrameInfo;
37 class MachineModuleInfo;
38 class MachineOperand;
39 class MCAsmInfo;
40 class DIEAbbrev;
41 class DIE;
42 class DIEBlock;
43 class DIEEntry;
45 //===----------------------------------------------------------------------===//
46 /// \brief This class is used to record source line correspondence.
47 class SrcLineInfo {
48 unsigned Line; // Source line number.
49 unsigned Column; // Source column.
50 unsigned SourceID; // Source ID number.
51 MCSymbol *Label; // Label in code ID number.
52 public:
53 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
54 : Line(L), Column(C), SourceID(S), Label(label) {}
56 // Accessors
57 unsigned getLine() const { return Line; }
58 unsigned getColumn() const { return Column; }
59 unsigned getSourceID() const { return SourceID; }
60 MCSymbol *getLabel() const { return Label; }
61 };
63 /// \brief This struct describes location entries emitted in the .debug_loc
64 /// section.
65 class DotDebugLocEntry {
66 // Begin and end symbols for the address range that this location is valid.
67 const MCSymbol *Begin;
68 const MCSymbol *End;
70 // Type of entry that this represents.
71 enum EntryType {
72 E_Location,
73 E_Integer,
74 E_ConstantFP,
75 E_ConstantInt
76 };
77 enum EntryType EntryKind;
79 union {
80 int64_t Int;
81 const ConstantFP *CFP;
82 const ConstantInt *CIP;
83 } Constants;
85 // The location in the machine frame.
86 MachineLocation Loc;
88 // The variable to which this location entry corresponds.
89 const MDNode *Variable;
91 // Whether this location has been merged.
92 bool Merged;
94 public:
95 DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
96 Constants.Int = 0;
97 }
98 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
99 const MDNode *V)
100 : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
101 Constants.Int = 0;
102 EntryKind = E_Location;
103 }
104 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
105 : Begin(B), End(E), Variable(0), Merged(false) {
106 Constants.Int = i;
107 EntryKind = E_Integer;
108 }
109 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
110 : Begin(B), End(E), Variable(0), Merged(false) {
111 Constants.CFP = FPtr;
112 EntryKind = E_ConstantFP;
113 }
114 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
115 const ConstantInt *IPtr)
116 : Begin(B), End(E), Variable(0), Merged(false) {
117 Constants.CIP = IPtr;
118 EntryKind = E_ConstantInt;
119 }
121 /// \brief Empty entries are also used as a trigger to emit temp label. Such
122 /// labels are referenced is used to find debug_loc offset for a given DIE.
123 bool isEmpty() { return Begin == 0 && End == 0; }
124 bool isMerged() { return Merged; }
125 void Merge(DotDebugLocEntry *Next) {
126 if (!(Begin && Loc == Next->Loc && End == Next->Begin))
127 return;
128 Next->Begin = Begin;
129 Merged = true;
130 }
131 bool isLocation() const { return EntryKind == E_Location; }
132 bool isInt() const { return EntryKind == E_Integer; }
133 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
134 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
135 int64_t getInt() const { return Constants.Int; }
136 const ConstantFP *getConstantFP() const { return Constants.CFP; }
137 const ConstantInt *getConstantInt() const { return Constants.CIP; }
138 const MDNode *getVariable() const { return Variable; }
139 const MCSymbol *getBeginSym() const { return Begin; }
140 const MCSymbol *getEndSym() const { return End; }
141 MachineLocation getLoc() const { return Loc; }
142 };
144 //===----------------------------------------------------------------------===//
145 /// \brief This class is used to track local variable information.
146 class DbgVariable {
147 DIVariable Var; // Variable Descriptor.
148 DIE *TheDIE; // Variable DIE.
149 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
150 DbgVariable *AbsVar; // Corresponding Abstract variable, if any.
151 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable.
152 int FrameIndex;
153 DwarfDebug *DD;
154 public:
155 // AbsVar may be NULL.
156 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
157 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
158 FrameIndex(~0), DD(DD) {}
160 // Accessors.
161 DIVariable getVariable() const { return Var; }
162 void setDIE(DIE *D) { TheDIE = D; }
163 DIE *getDIE() const { return TheDIE; }
164 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
165 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
166 StringRef getName() const { return Var.getName(); }
167 DbgVariable *getAbstractVariable() const { return AbsVar; }
168 const MachineInstr *getMInsn() const { return MInsn; }
169 void setMInsn(const MachineInstr *M) { MInsn = M; }
170 int getFrameIndex() const { return FrameIndex; }
171 void setFrameIndex(int FI) { FrameIndex = FI; }
172 // Translate tag to proper Dwarf tag.
173 uint16_t getTag() const {
174 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
175 return dwarf::DW_TAG_formal_parameter;
177 return dwarf::DW_TAG_variable;
178 }
179 /// \brief Return true if DbgVariable is artificial.
180 bool isArtificial() const {
181 if (Var.isArtificial())
182 return true;
183 if (getType().isArtificial())
184 return true;
185 return false;
186 }
188 bool isObjectPointer() const {
189 if (Var.isObjectPointer())
190 return true;
191 if (getType().isObjectPointer())
192 return true;
193 return false;
194 }
196 bool variableHasComplexAddress() const {
197 assert(Var.isVariable() && "Invalid complex DbgVariable!");
198 return Var.hasComplexAddress();
199 }
200 bool isBlockByrefVariable() const {
201 assert(Var.isVariable() && "Invalid complex DbgVariable!");
202 return Var.isBlockByrefVariable();
203 }
204 unsigned getNumAddrElements() const {
205 assert(Var.isVariable() && "Invalid complex DbgVariable!");
206 return Var.getNumAddrElements();
207 }
208 uint64_t getAddrElement(unsigned i) const {
209 return Var.getAddrElement(i);
210 }
211 DIType getType() const;
213 private:
214 /// resolve - Look in the DwarfDebug map for the MDNode that
215 /// corresponds to the reference.
216 template <typename T> T resolve(DIRef<T> Ref) const;
217 };
219 /// \brief Collects and handles information specific to a particular
220 /// collection of units.
221 class DwarfUnits {
222 // Target of Dwarf emission, used for sizing of abbreviations.
223 AsmPrinter *Asm;
225 // Used to uniquely define abbreviations.
226 FoldingSet<DIEAbbrev> *AbbreviationsSet;
228 // A list of all the unique abbreviations in use.
229 std::vector<DIEAbbrev *> *Abbreviations;
231 // A pointer to all units in the section.
232 SmallVector<CompileUnit *, 1> CUs;
234 // Collection of strings for this unit and assorted symbols.
235 // A String->Symbol mapping of strings used by indirect
236 // references.
237 typedef StringMap<std::pair<MCSymbol*, unsigned>,
238 BumpPtrAllocator&> StrPool;
239 StrPool StringPool;
240 unsigned NextStringPoolNumber;
241 std::string StringPref;
243 // Collection of addresses for this unit and assorted labels.
244 // A Symbol->unsigned mapping of addresses used by indirect
245 // references.
246 typedef DenseMap<const MCExpr *, unsigned> AddrPool;
247 AddrPool AddressPool;
248 unsigned NextAddrPoolNumber;
250 public:
251 DwarfUnits(AsmPrinter *AP, FoldingSet<DIEAbbrev> *AS,
252 std::vector<DIEAbbrev *> *A, const char *Pref,
253 BumpPtrAllocator &DA)
254 : Asm(AP), AbbreviationsSet(AS), Abbreviations(A), StringPool(DA),
255 NextStringPoolNumber(0), StringPref(Pref), AddressPool(),
256 NextAddrPoolNumber(0) {}
258 /// \brief Compute the size and offset of a DIE given an incoming Offset.
259 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
261 /// \brief Compute the size and offset of all the DIEs.
262 void computeSizeAndOffsets();
264 /// \brief Define a unique number for the abbreviation.
265 void assignAbbrevNumber(DIEAbbrev &Abbrev);
267 /// \brief Add a unit to the list of CUs.
268 void addUnit(CompileUnit *CU) { CUs.push_back(CU); }
270 /// \brief Emit all of the units to the section listed with the given
271 /// abbreviation section.
272 void emitUnits(DwarfDebug *DD, const MCSection *USection,
273 const MCSection *ASection, const MCSymbol *ASectionSym);
275 /// \brief Emit all of the strings to the section given.
276 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
277 const MCSymbol *StrSecSym);
279 /// \brief Emit all of the addresses to the section given.
280 void emitAddresses(const MCSection *AddrSection);
282 /// \brief Returns the entry into the start of the pool.
283 MCSymbol *getStringPoolSym();
285 /// \brief Returns an entry into the string pool with the given
286 /// string text.
287 MCSymbol *getStringPoolEntry(StringRef Str);
289 /// \brief Returns the index into the string pool with the given
290 /// string text.
291 unsigned getStringPoolIndex(StringRef Str);
293 /// \brief Returns the string pool.
294 StrPool *getStringPool() { return &StringPool; }
296 /// \brief Returns the index into the address pool with the given
297 /// label/symbol.
298 unsigned getAddrPoolIndex(const MCExpr *Sym);
299 unsigned getAddrPoolIndex(const MCSymbol *Sym);
301 /// \brief Returns the address pool.
302 AddrPool *getAddrPool() { return &AddressPool; }
303 };
305 /// \brief Helper used to pair up a symbol and it's DWARF compile unit.
306 struct SymbolCU {
307 SymbolCU(CompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
308 const MCSymbol *Sym;
309 CompileUnit *CU;
310 };
312 /// \brief Collects and handles dwarf debug information.
313 class DwarfDebug {
314 // Target of Dwarf emission.
315 AsmPrinter *Asm;
317 // Collected machine module information.
318 MachineModuleInfo *MMI;
320 // All DIEValues are allocated through this allocator.
321 BumpPtrAllocator DIEValueAllocator;
323 // Handle to the a compile unit used for the inline extension handling.
324 CompileUnit *FirstCU;
326 // Maps MDNode with its corresponding CompileUnit.
327 DenseMap <const MDNode *, CompileUnit *> CUMap;
329 // Maps subprogram MDNode with its corresponding CompileUnit.
330 DenseMap <const MDNode *, CompileUnit *> SPMap;
332 // Used to uniquely define abbreviations.
333 FoldingSet<DIEAbbrev> AbbreviationsSet;
335 // A list of all the unique abbreviations in use.
336 std::vector<DIEAbbrev *> Abbreviations;
338 // Stores the current file ID for a given compile unit.
339 DenseMap <unsigned, unsigned> FileIDCUMap;
340 // Source id map, i.e. CUID, source filename and directory,
341 // separated by a zero byte, mapped to a unique id.
342 StringMap<unsigned, BumpPtrAllocator&> SourceIdMap;
344 // List of all labels used in aranges generation.
345 std::vector<SymbolCU> ArangeLabels;
347 // Size of each symbol emitted (for those symbols that have a specific size).
348 DenseMap <const MCSymbol *, uint64_t> SymSize;
350 // Provides a unique id per text section.
351 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
352 SectionMapType SectionMap;
354 // List of arguments for current function.
355 SmallVector<DbgVariable *, 8> CurrentFnArguments;
357 LexicalScopes LScopes;
359 // Collection of abstract subprogram DIEs.
360 DenseMap<const MDNode *, DIE *> AbstractSPDies;
362 // Collection of dbg variables of a scope.
363 typedef DenseMap<LexicalScope *,
364 SmallVector<DbgVariable *, 8> > ScopeVariablesMap;
365 ScopeVariablesMap ScopeVariables;
367 // Collection of abstract variables.
368 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
370 // Collection of DotDebugLocEntry.
371 SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
373 // Collection of subprogram DIEs that are marked (at the end of the module)
374 // as DW_AT_inline.
375 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
377 // This is a collection of subprogram MDNodes that are processed to
378 // create DIEs.
379 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
381 // Maps instruction with label emitted before instruction.
382 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
384 // Maps instruction with label emitted after instruction.
385 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
387 // Every user variable mentioned by a DBG_VALUE instruction in order of
388 // appearance.
389 SmallVector<const MDNode*, 8> UserVariables;
391 // For each user variable, keep a list of DBG_VALUE instructions in order.
392 // The list can also contain normal instructions that clobber the previous
393 // DBG_VALUE.
394 typedef DenseMap<const MDNode*, SmallVector<const MachineInstr*, 4> >
395 DbgValueHistoryMap;
396 DbgValueHistoryMap DbgValues;
398 SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
400 // Previous instruction's location information. This is used to determine
401 // label location to indicate scope boundries in dwarf debug info.
402 DebugLoc PrevInstLoc;
403 MCSymbol *PrevLabel;
405 // This location indicates end of function prologue and beginning of function
406 // body.
407 DebugLoc PrologEndLoc;
409 // Section Symbols: these are assembler temporary labels that are emitted at
410 // the beginning of each supported dwarf section. These are used to form
411 // section offsets and are created by EmitSectionLabels.
412 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
413 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
414 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
415 MCSymbol *FunctionBeginSym, *FunctionEndSym;
416 MCSymbol *DwarfAbbrevDWOSectionSym, *DwarfStrDWOSectionSym;
417 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
419 // As an optimization, there is no need to emit an entry in the directory
420 // table for the same directory as DW_AT_comp_dir.
421 StringRef CompilationDir;
423 // Counter for assigning globally unique IDs for CUs.
424 unsigned GlobalCUIndexCount;
426 // Holder for the file specific debug information.
427 DwarfUnits InfoHolder;
429 // Holders for the various debug information flags that we might need to
430 // have exposed. See accessor functions below for description.
432 // Whether or not we're emitting info for older versions of gdb on darwin.
433 bool IsDarwinGDBCompat;
435 // Holder for imported entities.
436 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
437 ImportedEntityMap;
438 ImportedEntityMap ScopesWithImportedEntities;
440 // Holder for types that are going to be extracted out into a type unit.
441 std::vector<DIE *> TypeUnits;
443 // Whether to emit the pubnames/pubtypes sections.
444 bool HasDwarfPubSections;
446 // Version of dwarf we're emitting.
447 unsigned DwarfVersion;
449 // DWARF5 Experimental Options
450 bool HasDwarfAccelTables;
451 bool HasSplitDwarf;
453 // Separated Dwarf Variables
454 // In general these will all be for bits that are left in the
455 // original object file, rather than things that are meant
456 // to be in the .dwo sections.
458 // The CUs left in the original object file for separated debug info.
459 SmallVector<CompileUnit *, 1> SkeletonCUs;
461 // Used to uniquely define abbreviations for the skeleton emission.
462 FoldingSet<DIEAbbrev> SkeletonAbbrevSet;
464 // A list of all the unique abbreviations in use.
465 std::vector<DIEAbbrev *> SkeletonAbbrevs;
467 // Holder for the skeleton information.
468 DwarfUnits SkeletonHolder;
470 // Maps from a type identifier to the actual MDNode.
471 DITypeIdentifierMap TypeIdentifierMap;
473 private:
475 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
477 /// \brief Find abstract variable associated with Var.
478 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
480 /// \brief Find DIE for the given subprogram and attach appropriate
481 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
482 /// variables in this scope then create and insert DIEs for these
483 /// variables.
484 DIE *updateSubprogramScopeDIE(CompileUnit *SPCU, const MDNode *SPNode);
486 /// \brief Construct new DW_TAG_lexical_block for this scope and
487 /// attach DW_AT_low_pc/DW_AT_high_pc labels.
488 DIE *constructLexicalScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
489 /// A helper function to check whether the DIE for a given Scope is going
490 /// to be null.
491 bool isLexicalScopeDIENull(LexicalScope *Scope);
493 /// \brief This scope represents inlined body of a function. Construct
494 /// DIE to represent this concrete inlined copy of the function.
495 DIE *constructInlinedScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
497 /// \brief Construct a DIE for this scope.
498 DIE *constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
499 /// A helper function to create children of a Scope DIE.
500 DIE *createScopeChildrenDIE(CompileUnit *TheCU, LexicalScope *Scope,
501 SmallVectorImpl<DIE*> &Children);
503 /// \brief Emit initial Dwarf sections with a label at the start of each one.
504 void emitSectionLabels();
506 /// \brief Compute the size and offset of a DIE given an incoming Offset.
507 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
509 /// \brief Compute the size and offset of all the DIEs.
510 void computeSizeAndOffsets();
512 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
513 void computeInlinedDIEs();
515 /// \brief Collect info for variables that were optimized out.
516 void collectDeadVariables();
518 /// \brief Finish off debug information after all functions have been
519 /// processed.
520 void finalizeModuleInfo();
522 /// \brief Emit labels to close any remaining sections that have been left
523 /// open.
524 void endSections();
526 /// \brief Emit a set of abbreviations to the specific section.
527 void emitAbbrevs(const MCSection *, std::vector<DIEAbbrev*> *);
529 /// \brief Emit the debug info section.
530 void emitDebugInfo();
532 /// \brief Emit the abbreviation section.
533 void emitAbbreviations();
535 /// \brief Emit the last address of the section and the end of
536 /// the line matrix.
537 void emitEndOfLineMatrix(unsigned SectionEnd);
539 /// \brief Emit visible names into a hashed accelerator table section.
540 void emitAccelNames();
542 /// \brief Emit objective C classes and categories into a hashed
543 /// accelerator table section.
544 void emitAccelObjC();
546 /// \brief Emit namespace dies into a hashed accelerator table.
547 void emitAccelNamespaces();
549 /// \brief Emit type dies into a hashed accelerator table.
550 void emitAccelTypes();
552 /// \brief Emit visible names into a debug pubnames section.
553 /// \param GnuStyle determines whether or not we want to emit
554 /// additional information into the table ala newer gcc for gdb
555 /// index.
556 void emitDebugPubNames(bool GnuStyle = false);
558 /// \brief Emit visible types into a debug pubtypes section.
559 /// \param GnuStyle determines whether or not we want to emit
560 /// additional information into the table ala newer gcc for gdb
561 /// index.
562 void emitDebugPubTypes(bool GnuStyle = false);
564 /// \brief Emit visible names into a debug str section.
565 void emitDebugStr();
567 /// \brief Emit visible names into a debug loc section.
568 void emitDebugLoc();
570 /// \brief Emit visible names into a debug aranges section.
571 void emitDebugARanges();
573 /// \brief Emit visible names into a debug ranges section.
574 void emitDebugRanges();
576 /// \brief Emit visible names into a debug macinfo section.
577 void emitDebugMacInfo();
579 /// \brief Emit inline info using custom format.
580 void emitDebugInlineInfo();
582 /// DWARF 5 Experimental Split Dwarf Emitters
584 /// \brief Construct the split debug info compile unit for the debug info
585 /// section.
586 CompileUnit *constructSkeletonCU(const CompileUnit *CU);
588 /// \brief Emit the local split abbreviations.
589 void emitSkeletonAbbrevs(const MCSection *);
591 /// \brief Emit the debug info dwo section.
592 void emitDebugInfoDWO();
594 /// \brief Emit the debug abbrev dwo section.
595 void emitDebugAbbrevDWO();
597 /// \brief Emit the debug str dwo section.
598 void emitDebugStrDWO();
600 /// \brief Create new CompileUnit for the given metadata node with tag
601 /// DW_TAG_compile_unit.
602 CompileUnit *constructCompileUnit(const MDNode *N);
604 /// \brief Construct subprogram DIE.
605 void constructSubprogramDIE(CompileUnit *TheCU, const MDNode *N);
607 /// \brief Construct imported_module or imported_declaration DIE.
608 void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N);
610 /// \brief Construct import_module DIE.
611 void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N,
612 DIE *Context);
614 /// \brief Construct import_module DIE.
615 void constructImportedEntityDIE(CompileUnit *TheCU,
616 const DIImportedEntity &Module,
617 DIE *Context);
619 /// \brief Register a source line with debug info. Returns the unique
620 /// label that was emitted and which provides correspondence to the
621 /// source line list.
622 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
623 unsigned Flags);
625 /// \brief Indentify instructions that are marking the beginning of or
626 /// ending of a scope.
627 void identifyScopeMarkers();
629 /// \brief If Var is an current function argument that add it in
630 /// CurrentFnArguments list.
631 bool addCurrentFnArgument(const MachineFunction *MF,
632 DbgVariable *Var, LexicalScope *Scope);
634 /// \brief Populate LexicalScope entries with variables' info.
635 void collectVariableInfo(const MachineFunction *,
636 SmallPtrSet<const MDNode *, 16> &ProcessedVars);
638 /// \brief Collect variable information from the side table maintained
639 /// by MMI.
640 void collectVariableInfoFromMMITable(const MachineFunction * MF,
641 SmallPtrSet<const MDNode *, 16> &P);
643 /// \brief Ensure that a label will be emitted before MI.
644 void requestLabelBeforeInsn(const MachineInstr *MI) {
645 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol*)0));
646 }
648 /// \brief Return Label preceding the instruction.
649 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
651 /// \brief Ensure that a label will be emitted after MI.
652 void requestLabelAfterInsn(const MachineInstr *MI) {
653 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol*)0));
654 }
656 /// \brief Return Label immediately following the instruction.
657 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
659 public:
660 //===--------------------------------------------------------------------===//
661 // Main entry points.
662 //
663 DwarfDebug(AsmPrinter *A, Module *M);
664 ~DwarfDebug();
666 /// \brief Emit all Dwarf sections that should come prior to the
667 /// content.
668 void beginModule();
670 /// \brief Emit all Dwarf sections that should come after the content.
671 void endModule();
673 /// \brief Gather pre-function debug information.
674 void beginFunction(const MachineFunction *MF);
676 /// \brief Gather and emit post-function debug information.
677 void endFunction(const MachineFunction *MF);
679 /// \brief Process beginning of an instruction.
680 void beginInstruction(const MachineInstr *MI);
682 /// \brief Process end of an instruction.
683 void endInstruction(const MachineInstr *MI);
685 /// \brief Add a DIE to the set of types that we're going to pull into
686 /// type units.
687 void addTypeUnitType(DIE *Die) { TypeUnits.push_back(Die); }
689 /// \brief Add a label so that arange data can be generated for it.
690 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
692 /// \brief For symbols that have a size designated (e.g. common symbols),
693 /// this tracks that size.
694 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) { SymSize[Sym] = Size;}
696 /// \brief Look up the source id with the given directory and source file
697 /// names. If none currently exists, create a new id and insert it in the
698 /// SourceIds map.
699 unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName,
700 unsigned CUID);
702 /// \brief Recursively Emits a debug information entry.
703 void emitDIE(DIE *Die, std::vector<DIEAbbrev *> *Abbrevs);
705 /// \brief Returns whether or not to limit some of our debug
706 /// output to the limitations of darwin gdb.
707 bool useDarwinGDBCompat() { return IsDarwinGDBCompat; }
709 // Experimental DWARF5 features.
711 /// \brief Returns whether or not to emit tables that dwarf consumers can
712 /// use to accelerate lookup.
713 bool useDwarfAccelTables() { return HasDwarfAccelTables; }
715 /// \brief Returns whether or not to change the current debug info for the
716 /// split dwarf proposal support.
717 bool useSplitDwarf() { return HasSplitDwarf; }
719 /// Returns the Dwarf Version.
720 unsigned getDwarfVersion() const { return DwarfVersion; }
722 /// Find the MDNode for the given reference.
723 template <typename T> T resolve(DIRef<T> Ref) const {
724 return Ref.resolve(TypeIdentifierMap);
725 }
727 /// isSubprogramContext - Return true if Context is either a subprogram
728 /// or another context nested inside a subprogram.
729 bool isSubprogramContext(const MDNode *Context);
731 };
732 } // End of namespace llvm
734 #endif