52be24c796316b67838a40ac9c5a8395767a348e
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.h
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 //===----------------------------------------------------------------------===//
13
14 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
16
17 #include "AsmPrinterHandler.h"
18 #include "DIE.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/CodeGen/LexicalScopes.h"
25 #include "llvm/IR/DebugInfo.h"
26 #include "llvm/IR/DebugLoc.h"
27 #include "llvm/MC/MachineLocation.h"
28 #include "llvm/MC/MCDwarf.h"
29 #include "llvm/Support/Allocator.h"
30
31 namespace llvm {
32
33 class AsmPrinter;
34 class ByteStreamer;
35 class ConstantInt;
36 class ConstantFP;
37 class DwarfCompileUnit;
38 class DwarfDebug;
39 class DwarfTypeUnit;
40 class DwarfUnit;
41 class MachineModuleInfo;
42
43 //===----------------------------------------------------------------------===//
44 /// \brief This class is used to record source line correspondence.
45 class SrcLineInfo {
46   unsigned Line;     // Source line number.
47   unsigned Column;   // Source column.
48   unsigned SourceID; // Source ID number.
49   MCSymbol *Label;   // Label in code ID number.
50 public:
51   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
52       : Line(L), Column(C), SourceID(S), Label(label) {}
53
54   // Accessors
55   unsigned getLine() const { return Line; }
56   unsigned getColumn() const { return Column; }
57   unsigned getSourceID() const { return SourceID; }
58   MCSymbol *getLabel() const { return Label; }
59 };
60
61 /// \brief This struct describes location entries emitted in the .debug_loc
62 /// section.
63 class DebugLocEntry {
64   // Begin and end symbols for the address range that this location is valid.
65   const MCSymbol *Begin;
66   const MCSymbol *End;
67
68   // Type of entry that this represents.
69   enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
70   enum EntryType EntryKind;
71
72   union {
73     int64_t Int;
74     const ConstantFP *CFP;
75     const ConstantInt *CIP;
76   } Constants;
77
78   // The location in the machine frame.
79   MachineLocation Loc;
80
81   // The variable to which this location entry corresponds.
82   const MDNode *Variable;
83
84   // Whether this location has been merged.
85   bool Merged;
86
87 public:
88   DebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
89     Constants.Int = 0;
90   }
91   DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
92                 const MDNode *V)
93       : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
94     Constants.Int = 0;
95     EntryKind = E_Location;
96   }
97   DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
98       : Begin(B), End(E), Variable(0), Merged(false) {
99     Constants.Int = i;
100     EntryKind = E_Integer;
101   }
102   DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
103       : Begin(B), End(E), Variable(0), Merged(false) {
104     Constants.CFP = FPtr;
105     EntryKind = E_ConstantFP;
106   }
107   DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr)
108       : Begin(B), End(E), Variable(0), Merged(false) {
109     Constants.CIP = IPtr;
110     EntryKind = E_ConstantInt;
111   }
112
113   /// \brief Empty entries are also used as a trigger to emit temp label. Such
114   /// labels are referenced is used to find debug_loc offset for a given DIE.
115   bool isEmpty() const { return Begin == 0 && End == 0; }
116   bool isMerged() const { return Merged; }
117   void Merge(DebugLocEntry *Next) {
118     if (!(Begin && Loc == Next->Loc && End == Next->Begin))
119       return;
120     Next->Begin = Begin;
121     Merged = true;
122   }
123   bool isLocation() const { return EntryKind == E_Location; }
124   bool isInt() const { return EntryKind == E_Integer; }
125   bool isConstantFP() const { return EntryKind == E_ConstantFP; }
126   bool isConstantInt() const { return EntryKind == E_ConstantInt; }
127   int64_t getInt() const { return Constants.Int; }
128   const ConstantFP *getConstantFP() const { return Constants.CFP; }
129   const ConstantInt *getConstantInt() const { return Constants.CIP; }
130   const MDNode *getVariable() const { return Variable; }
131   const MCSymbol *getBeginSym() const { return Begin; }
132   const MCSymbol *getEndSym() const { return End; }
133   MachineLocation getLoc() const { return Loc; }
134 };
135
136 //===----------------------------------------------------------------------===//
137 /// \brief This class is used to track local variable information.
138 class DbgVariable {
139   DIVariable Var;             // Variable Descriptor.
140   DIE *TheDIE;                // Variable DIE.
141   unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
142   DbgVariable *AbsVar;        // Corresponding Abstract variable, if any.
143   const MachineInstr *MInsn;  // DBG_VALUE instruction of the variable.
144   int FrameIndex;
145   DwarfDebug *DD;
146
147 public:
148   // AbsVar may be NULL.
149   DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
150       : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
151         FrameIndex(~0), DD(DD) {}
152
153   // Accessors.
154   DIVariable getVariable() const { return Var; }
155   void setDIE(DIE *D) { TheDIE = D; }
156   DIE *getDIE() const { return TheDIE; }
157   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
158   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
159   StringRef getName() const { return Var.getName(); }
160   DbgVariable *getAbstractVariable() const { return AbsVar; }
161   const MachineInstr *getMInsn() const { return MInsn; }
162   void setMInsn(const MachineInstr *M) { MInsn = M; }
163   int getFrameIndex() const { return FrameIndex; }
164   void setFrameIndex(int FI) { FrameIndex = FI; }
165   // Translate tag to proper Dwarf tag.
166   uint16_t getTag() const {
167     if (Var.getTag() == dwarf::DW_TAG_arg_variable)
168       return dwarf::DW_TAG_formal_parameter;
169
170     return dwarf::DW_TAG_variable;
171   }
172   /// \brief Return true if DbgVariable is artificial.
173   bool isArtificial() const {
174     if (Var.isArtificial())
175       return true;
176     if (getType().isArtificial())
177       return true;
178     return false;
179   }
180
181   bool isObjectPointer() const {
182     if (Var.isObjectPointer())
183       return true;
184     if (getType().isObjectPointer())
185       return true;
186     return false;
187   }
188
189   bool variableHasComplexAddress() const {
190     assert(Var.isVariable() && "Invalid complex DbgVariable!");
191     return Var.hasComplexAddress();
192   }
193   bool isBlockByrefVariable() const;
194   unsigned getNumAddrElements() const {
195     assert(Var.isVariable() && "Invalid complex DbgVariable!");
196     return Var.getNumAddrElements();
197   }
198   uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
199   DIType getType() const;
200
201 private:
202   /// resolve - Look in the DwarfDebug map for the MDNode that
203   /// corresponds to the reference.
204   template <typename T> T resolve(DIRef<T> Ref) const;
205 };
206
207 /// \brief Collects and handles information specific to a particular
208 /// collection of units. This collection represents all of the units
209 /// that will be ultimately output into a single object file.
210 class DwarfFile {
211   // Target of Dwarf emission, used for sizing of abbreviations.
212   AsmPrinter *Asm;
213
214   // Used to uniquely define abbreviations.
215   FoldingSet<DIEAbbrev> AbbreviationsSet;
216
217   // A list of all the unique abbreviations in use.
218   std::vector<DIEAbbrev *> Abbreviations;
219
220   // A pointer to all units in the section.
221   SmallVector<DwarfUnit *, 1> CUs;
222
223   // Collection of strings for this unit and assorted symbols.
224   // A String->Symbol mapping of strings used by indirect
225   // references.
226   typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
227   StrPool;
228   StrPool StringPool;
229   unsigned NextStringPoolNumber;
230   std::string StringPref;
231
232   struct AddressPoolEntry {
233     unsigned Number;
234     bool TLS;
235     AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
236   };
237   // Collection of addresses for this unit and assorted labels.
238   // A Symbol->unsigned mapping of addresses used by indirect
239   // references.
240   typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
241   AddrPool AddressPool;
242   unsigned NextAddrPoolNumber;
243
244 public:
245   DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
246       : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
247         AddressPool(), NextAddrPoolNumber(0) {}
248
249   ~DwarfFile();
250
251   const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
252
253   /// \brief Compute the size and offset of a DIE given an incoming Offset.
254   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
255
256   /// \brief Compute the size and offset of all the DIEs.
257   void computeSizeAndOffsets();
258
259   /// \brief Define a unique number for the abbreviation.
260   void assignAbbrevNumber(DIEAbbrev &Abbrev);
261
262   /// \brief Add a unit to the list of CUs.
263   void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
264
265   /// \brief Emit all of the units to the section listed with the given
266   /// abbreviation section.
267   void emitUnits(DwarfDebug *DD, const MCSection *ASection,
268                  const MCSymbol *ASectionSym);
269
270   /// \brief Emit a set of abbreviations to the specific section.
271   void emitAbbrevs(const MCSection *);
272
273   /// \brief Emit all of the strings to the section given.
274   void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
275                    const MCSymbol *StrSecSym);
276
277   /// \brief Emit all of the addresses to the section given.
278   void emitAddresses(const MCSection *AddrSection);
279
280   /// \brief Returns the entry into the start of the pool.
281   MCSymbol *getStringPoolSym();
282
283   /// \brief Returns an entry into the string pool with the given
284   /// string text.
285   MCSymbol *getStringPoolEntry(StringRef Str);
286
287   /// \brief Returns the index into the string pool with the given
288   /// string text.
289   unsigned getStringPoolIndex(StringRef Str);
290
291   /// \brief Returns the string pool.
292   StrPool *getStringPool() { return &StringPool; }
293
294   /// \brief Returns the index into the address pool with the given
295   /// label/symbol.
296   unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
297
298   /// \brief Returns the address pool.
299   AddrPool *getAddrPool() { return &AddressPool; }
300 };
301
302 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
303 struct SymbolCU {
304   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
305   const MCSymbol *Sym;
306   DwarfCompileUnit *CU;
307 };
308
309 /// \brief Collects and handles dwarf debug information.
310 class DwarfDebug : public AsmPrinterHandler {
311   // Target of Dwarf emission.
312   AsmPrinter *Asm;
313
314   // Collected machine module information.
315   MachineModuleInfo *MMI;
316
317   // All DIEValues are allocated through this allocator.
318   BumpPtrAllocator DIEValueAllocator;
319
320   // Handle to the compile unit used for the inline extension handling,
321   // this is just so that the DIEValue allocator has a place to store
322   // the particular elements.
323   // FIXME: Store these off of DwarfDebug instead?
324   DwarfCompileUnit *FirstCU;
325
326   // Maps MDNode with its corresponding DwarfCompileUnit.
327   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
328
329   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
330   DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
331
332   // Maps a CU DIE with its corresponding DwarfCompileUnit.
333   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
334
335   /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
336   /// be shared across CUs, that is why we keep the map here instead
337   /// of in DwarfCompileUnit.
338   DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
339
340   // List of all labels used in aranges generation.
341   std::vector<SymbolCU> ArangeLabels;
342
343   // Size of each symbol emitted (for those symbols that have a specific size).
344   DenseMap<const MCSymbol *, uint64_t> SymSize;
345
346   // Provides a unique id per text section.
347   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
348   SectionMapType SectionMap;
349
350   // List of arguments for current function.
351   SmallVector<DbgVariable *, 8> CurrentFnArguments;
352
353   LexicalScopes LScopes;
354
355   // Collection of abstract subprogram DIEs.
356   DenseMap<const MDNode *, DIE *> AbstractSPDies;
357
358   // Collection of dbg variables of a scope.
359   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
360   ScopeVariablesMap;
361   ScopeVariablesMap ScopeVariables;
362
363   // Collection of abstract variables.
364   DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
365
366   // Collection of DebugLocEntry.
367   SmallVector<DebugLocEntry, 4> DotDebugLocEntries;
368
369   // Collection of subprogram DIEs that are marked (at the end of the module)
370   // as DW_AT_inline.
371   SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
372
373   // This is a collection of subprogram MDNodes that are processed to
374   // create DIEs.
375   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
376
377   // Maps instruction with label emitted before instruction.
378   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
379
380   // Maps instruction with label emitted after instruction.
381   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
382
383   // Every user variable mentioned by a DBG_VALUE instruction in order of
384   // appearance.
385   SmallVector<const MDNode *, 8> UserVariables;
386
387   // For each user variable, keep a list of DBG_VALUE instructions in order.
388   // The list can also contain normal instructions that clobber the previous
389   // DBG_VALUE.
390   typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
391   DbgValueHistoryMap;
392   DbgValueHistoryMap DbgValues;
393
394   // Previous instruction's location information. This is used to determine
395   // label location to indicate scope boundries in dwarf debug info.
396   DebugLoc PrevInstLoc;
397   MCSymbol *PrevLabel;
398
399   // This location indicates end of function prologue and beginning of function
400   // body.
401   DebugLoc PrologEndLoc;
402
403   // If nonnull, stores the current machine function we're processing.
404   const MachineFunction *CurFn;
405
406   // If nonnull, stores the current machine instruction we're processing.
407   const MachineInstr *CurMI;
408
409   // If nonnull, stores the section that the previous function was allocated to
410   // emitting.
411   const MCSection *PrevSection;
412
413   // If nonnull, stores the CU in which the previous subprogram was contained.
414   const DwarfCompileUnit *PrevCU;
415
416   // Section Symbols: these are assembler temporary labels that are emitted at
417   // the beginning of each supported dwarf section.  These are used to form
418   // section offsets and are created by EmitSectionLabels.
419   MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
420   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
421   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
422   MCSymbol *FunctionBeginSym, *FunctionEndSym;
423   MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
424   MCSymbol *DwarfStrDWOSectionSym;
425   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
426
427   // As an optimization, there is no need to emit an entry in the directory
428   // table for the same directory as DW_AT_comp_dir.
429   StringRef CompilationDir;
430
431   // Counter for assigning globally unique IDs for ranges.
432   unsigned GlobalRangeCount;
433
434   // Holder for the file specific debug information.
435   DwarfFile InfoHolder;
436
437   // Holders for the various debug information flags that we might need to
438   // have exposed. See accessor functions below for description.
439
440   // Holder for imported entities.
441   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
442   ImportedEntityMap;
443   ImportedEntityMap ScopesWithImportedEntities;
444
445   // Map from MDNodes for user-defined types to the type units that describe
446   // them.
447   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
448
449   // Whether to emit the pubnames/pubtypes sections.
450   bool HasDwarfPubSections;
451
452   // Whether or not to use AT_ranges for compilation units.
453   bool HasCURanges;
454
455   // Whether we emitted a function into a section other than the default
456   // text.
457   bool UsedNonDefaultText;
458
459   // Version of dwarf we're emitting.
460   unsigned DwarfVersion;
461
462   // Maps from a type identifier to the actual MDNode.
463   DITypeIdentifierMap TypeIdentifierMap;
464
465   // DWARF5 Experimental Options
466   bool HasDwarfAccelTables;
467   bool HasSplitDwarf;
468
469   // Separated Dwarf Variables
470   // In general these will all be for bits that are left in the
471   // original object file, rather than things that are meant
472   // to be in the .dwo sections.
473
474   // Holder for the skeleton information.
475   DwarfFile SkeletonHolder;
476
477   /// Store file names for type units under fission in a line table header that
478   /// will be emitted into debug_line.dwo.
479   // FIXME: replace this with a map from comp_dir to table so that we can emit
480   // multiple tables during LTO each of which uses directory 0, referencing the
481   // comp_dir of all the type units that use it.
482   MCDwarfDwoLineTable SplitTypeUnitFileTable;
483
484   // True iff there are multiple CUs in this module.
485   bool SingleCU;
486
487   MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
488
489   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
490
491   const SmallVectorImpl<DwarfUnit *> &getUnits() {
492     return InfoHolder.getUnits();
493   }
494
495   /// \brief Find abstract variable associated with Var.
496   DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
497
498   /// \brief Find DIE for the given subprogram and attach appropriate
499   /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
500   /// variables in this scope then create and insert DIEs for these
501   /// variables.
502   DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
503
504   /// \brief A helper function to check whether the DIE for a given Scope is
505   /// going to be null.
506   bool isLexicalScopeDIENull(LexicalScope *Scope);
507
508   /// \brief A helper function to construct a RangeSpanList for a given
509   /// lexical scope.
510   void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
511                          const SmallVectorImpl<InsnRange> &Range);
512
513   /// \brief Construct new DW_TAG_lexical_block for this scope and
514   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
515   DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
516
517   /// \brief This scope represents inlined body of a function. Construct
518   /// DIE to represent this concrete inlined copy of the function.
519   DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
520
521   /// \brief Construct a DIE for this scope.
522   DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
523   /// A helper function to create children of a Scope DIE.
524   DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
525                               SmallVectorImpl<DIE *> &Children);
526
527   /// \brief Emit initial Dwarf sections with a label at the start of each one.
528   void emitSectionLabels();
529
530   /// \brief Compute the size and offset of a DIE given an incoming Offset.
531   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
532
533   /// \brief Compute the size and offset of all the DIEs.
534   void computeSizeAndOffsets();
535
536   /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
537   void computeInlinedDIEs();
538
539   /// \brief Collect info for variables that were optimized out.
540   void collectDeadVariables();
541
542   /// \brief Finish off debug information after all functions have been
543   /// processed.
544   void finalizeModuleInfo();
545
546   /// \brief Emit labels to close any remaining sections that have been left
547   /// open.
548   void endSections();
549
550   /// \brief Emit the debug info section.
551   void emitDebugInfo();
552
553   /// \brief Emit the abbreviation section.
554   void emitAbbreviations();
555
556   /// \brief Emit the last address of the section and the end of
557   /// the line matrix.
558   void emitEndOfLineMatrix(unsigned SectionEnd);
559
560   /// \brief Emit visible names into a hashed accelerator table section.
561   void emitAccelNames();
562
563   /// \brief Emit objective C classes and categories into a hashed
564   /// accelerator table section.
565   void emitAccelObjC();
566
567   /// \brief Emit namespace dies into a hashed accelerator table.
568   void emitAccelNamespaces();
569
570   /// \brief Emit type dies into a hashed accelerator table.
571   void emitAccelTypes();
572
573   /// \brief Emit visible names into a debug pubnames section.
574   /// \param GnuStyle determines whether or not we want to emit
575   /// additional information into the table ala newer gcc for gdb
576   /// index.
577   void emitDebugPubNames(bool GnuStyle = false);
578
579   /// \brief Emit visible types into a debug pubtypes section.
580   /// \param GnuStyle determines whether or not we want to emit
581   /// additional information into the table ala newer gcc for gdb
582   /// index.
583   void emitDebugPubTypes(bool GnuStyle = false);
584
585   void
586   emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
587                       const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
588                       const);
589
590   /// \brief Emit visible names into a debug str section.
591   void emitDebugStr();
592
593   /// \brief Emit visible names into a debug loc section.
594   void emitDebugLoc();
595
596   /// \brief Emit visible names into a debug aranges section.
597   void emitDebugARanges();
598
599   /// \brief Emit visible names into a debug ranges section.
600   void emitDebugRanges();
601
602   /// \brief Emit inline info using custom format.
603   void emitDebugInlineInfo();
604
605   /// DWARF 5 Experimental Split Dwarf Emitters
606
607   /// \brief Initialize common features of skeleton units.
608   void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
609
610   /// \brief Construct the split debug info compile unit for the debug info
611   /// section.
612   DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
613
614   /// \brief Construct the split debug info compile unit for the debug info
615   /// section.
616   DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
617
618   /// \brief Emit the debug info dwo section.
619   void emitDebugInfoDWO();
620
621   /// \brief Emit the debug abbrev dwo section.
622   void emitDebugAbbrevDWO();
623
624   /// \brief Emit the debug line dwo section.
625   void emitDebugLineDWO();
626
627   /// \brief Emit the debug str dwo section.
628   void emitDebugStrDWO();
629
630   /// Flags to let the linker know we have emitted new style pubnames. Only
631   /// emit it here if we don't have a skeleton CU for split dwarf.
632   void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
633
634   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
635   /// DW_TAG_compile_unit.
636   DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
637
638   /// \brief Construct subprogram DIE.
639   void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
640
641   /// \brief Construct imported_module or imported_declaration DIE.
642   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
643
644   /// \brief Construct import_module DIE.
645   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
646                                   DIE *Context);
647
648   /// \brief Construct import_module DIE.
649   void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
650                                   const DIImportedEntity &Module, DIE *Context);
651
652   /// \brief Register a source line with debug info. Returns the unique
653   /// label that was emitted and which provides correspondence to the
654   /// source line list.
655   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
656                         unsigned Flags);
657
658   /// \brief Indentify instructions that are marking the beginning of or
659   /// ending of a scope.
660   void identifyScopeMarkers();
661
662   /// \brief If Var is an current function argument that add it in
663   /// CurrentFnArguments list.
664   bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
665
666   /// \brief Populate LexicalScope entries with variables' info.
667   void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
668
669   /// \brief Collect variable information from the side table maintained
670   /// by MMI.
671   void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
672
673   /// \brief Ensure that a label will be emitted before MI.
674   void requestLabelBeforeInsn(const MachineInstr *MI) {
675     LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
676   }
677
678   /// \brief Return Label preceding the instruction.
679   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
680
681   /// \brief Ensure that a label will be emitted after MI.
682   void requestLabelAfterInsn(const MachineInstr *MI) {
683     LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
684   }
685
686   /// \brief Return Label immediately following the instruction.
687   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
688
689   void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
690                        MCSymbol *End);
691
692 public:
693   //===--------------------------------------------------------------------===//
694   // Main entry points.
695   //
696   DwarfDebug(AsmPrinter *A, Module *M);
697
698   void insertDIE(const MDNode *TypeMD, DIE *Die) {
699     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
700   }
701   DIE *getDIE(const MDNode *TypeMD) {
702     return MDTypeNodeToDieMap.lookup(TypeMD);
703   }
704
705   /// \brief Emit all Dwarf sections that should come prior to the
706   /// content.
707   void beginModule();
708
709   /// \brief Emit all Dwarf sections that should come after the content.
710   void endModule() override;
711
712   /// \brief Gather pre-function debug information.
713   void beginFunction(const MachineFunction *MF) override;
714
715   /// \brief Gather and emit post-function debug information.
716   void endFunction(const MachineFunction *MF) override;
717
718   /// \brief Process beginning of an instruction.
719   void beginInstruction(const MachineInstr *MI) override;
720
721   /// \brief Process end of an instruction.
722   void endInstruction() override;
723
724   /// \brief Add a DIE to the set of types that we're going to pull into
725   /// type units.
726   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
727                             DIE *Die, DICompositeType CTy);
728
729   /// \brief Add a label so that arange data can be generated for it.
730   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
731
732   /// \brief For symbols that have a size designated (e.g. common symbols),
733   /// this tracks that size.
734   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
735     SymSize[Sym] = Size;
736   }
737
738   /// \brief Recursively Emits a debug information entry.
739   void emitDIE(DIE *Die);
740
741   // Experimental DWARF5 features.
742
743   /// \brief Returns whether or not to emit tables that dwarf consumers can
744   /// use to accelerate lookup.
745   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
746
747   /// \brief Returns whether or not to change the current debug info for the
748   /// split dwarf proposal support.
749   bool useSplitDwarf() const { return HasSplitDwarf; }
750
751   /// Returns the Dwarf Version.
752   unsigned getDwarfVersion() const { return DwarfVersion; }
753
754   /// Returns the section symbol for the .debug_loc section.
755   MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
756
757   /// Returns the previous section that was emitted into.
758   const MCSection *getPrevSection() const { return PrevSection; }
759
760   /// Returns the previous CU that was being updated
761   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
762
763   /// Returns the entries for the .debug_loc section.
764   const SmallVectorImpl<DebugLocEntry> &getDebugLocEntries() const {
765     return DotDebugLocEntries;
766   }
767
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);
771
772   /// Find the MDNode for the given reference.
773   template <typename T> T resolve(DIRef<T> Ref) const {
774     return Ref.resolve(TypeIdentifierMap);
775   }
776
777   /// \brief Return the TypeIdentifierMap.
778   const DITypeIdentifierMap &getTypeIdentifierMap() const {
779     return TypeIdentifierMap;
780   }
781
782   /// Find the DwarfCompileUnit for the given CU Die.
783   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
784     return CUDieMap.lookup(CU);
785   }
786   /// isSubprogramContext - Return true if Context is either a subprogram
787   /// or another context nested inside a subprogram.
788   bool isSubprogramContext(const MDNode *Context);
789 };
790 } // End of namespace llvm
791
792 #endif