Fix for coding style.
[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/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"
26
27 namespace llvm {
28
29 class AsmPrinter;
30 class ByteStreamer;
31 class ConstantInt;
32 class ConstantFP;
33 class DwarfCompileUnit;
34 class DwarfDebug;
35 class DwarfTypeUnit;
36 class DwarfUnit;
37 class MachineModuleInfo;
38
39 //===----------------------------------------------------------------------===//
40 /// \brief This class is used to record source line correspondence.
41 class SrcLineInfo {
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.
46 public:
47   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
48       : Line(L), Column(C), SourceID(S), Label(label) {}
49
50   // Accessors
51   unsigned getLine() const { return Line; }
52   unsigned getColumn() const { return Column; }
53   unsigned getSourceID() const { return SourceID; }
54   MCSymbol *getLabel() const { return Label; }
55 };
56
57 /// \brief This struct describes location entries emitted in the .debug_loc
58 /// section.
59 class DebugLocEntry {
60   // Begin and end symbols for the address range that this location is valid.
61   const MCSymbol *Begin;
62   const MCSymbol *End;
63
64   // Type of entry that this represents.
65   enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
66   enum EntryType EntryKind;
67
68   union {
69     int64_t Int;
70     const ConstantFP *CFP;
71     const ConstantInt *CIP;
72   } Constants;
73
74   // The location in the machine frame.
75   MachineLocation Loc;
76
77   // The variable to which this location entry corresponds.
78   const MDNode *Variable;
79
80   // Whether this location has been merged.
81   bool Merged;
82
83 public:
84   DebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
85     Constants.Int = 0;
86   }
87   DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
88                 const MDNode *V)
89       : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
90     Constants.Int = 0;
91     EntryKind = E_Location;
92   }
93   DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
94       : Begin(B), End(E), Variable(0), Merged(false) {
95     Constants.Int = i;
96     EntryKind = E_Integer;
97   }
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;
102   }
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;
107   }
108
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))
115       return;
116     Next->Begin = Begin;
117     Merged = true;
118   }
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; }
130 };
131
132 //===----------------------------------------------------------------------===//
133 /// \brief This class is used to track local variable information.
134 class DbgVariable {
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.
140   int FrameIndex;
141   DwarfDebug *DD;
142
143 public:
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) {}
148
149   // Accessors.
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;
165
166     return dwarf::DW_TAG_variable;
167   }
168   /// \brief Return true if DbgVariable is artificial.
169   bool isArtificial() const {
170     if (Var.isArtificial())
171       return true;
172     if (getType().isArtificial())
173       return true;
174     return false;
175   }
176
177   bool isObjectPointer() const {
178     if (Var.isObjectPointer())
179       return true;
180     if (getType().isObjectPointer())
181       return true;
182     return false;
183   }
184
185   bool variableHasComplexAddress() const {
186     assert(Var.isVariable() && "Invalid complex DbgVariable!");
187     return Var.hasComplexAddress();
188   }
189   bool isBlockByrefVariable() const;
190   unsigned getNumAddrElements() const {
191     assert(Var.isVariable() && "Invalid complex DbgVariable!");
192     return Var.getNumAddrElements();
193   }
194   uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
195   DIType getType() const;
196
197 private:
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;
201 };
202
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.
206 class DwarfFile {
207   // Target of Dwarf emission, used for sizing of abbreviations.
208   AsmPrinter *Asm;
209
210   // Used to uniquely define abbreviations.
211   FoldingSet<DIEAbbrev> AbbreviationsSet;
212
213   // A list of all the unique abbreviations in use.
214   std::vector<DIEAbbrev *> Abbreviations;
215
216   // A pointer to all units in the section.
217   SmallVector<DwarfUnit *, 1> CUs;
218
219   // Collection of strings for this unit and assorted symbols.
220   // A String->Symbol mapping of strings used by indirect
221   // references.
222   typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
223   StrPool;
224   StrPool StringPool;
225   unsigned NextStringPoolNumber;
226   std::string StringPref;
227
228   struct AddressPoolEntry {
229     unsigned Number;
230     bool TLS;
231     AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
232   };
233   // Collection of addresses for this unit and assorted labels.
234   // A Symbol->unsigned mapping of addresses used by indirect
235   // references.
236   typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
237   AddrPool AddressPool;
238   unsigned NextAddrPoolNumber;
239
240 public:
241   DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
242       : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
243         AddressPool(), NextAddrPoolNumber(0) {}
244
245   ~DwarfFile();
246
247   const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
248
249   /// \brief Compute the size and offset of a DIE given an incoming Offset.
250   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
251
252   /// \brief Compute the size and offset of all the DIEs.
253   void computeSizeAndOffsets();
254
255   /// \brief Define a unique number for the abbreviation.
256   void assignAbbrevNumber(DIEAbbrev &Abbrev);
257
258   /// \brief Add a unit to the list of CUs.
259   void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
260
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);
265
266   /// \brief Emit a set of abbreviations to the specific section.
267   void emitAbbrevs(const MCSection *);
268
269   /// \brief Emit all of the strings to the section given.
270   void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
271                    const MCSymbol *StrSecSym);
272
273   /// \brief Emit all of the addresses to the section given.
274   void emitAddresses(const MCSection *AddrSection);
275
276   /// \brief Returns the entry into the start of the pool.
277   MCSymbol *getStringPoolSym();
278
279   /// \brief Returns an entry into the string pool with the given
280   /// string text.
281   MCSymbol *getStringPoolEntry(StringRef Str);
282
283   /// \brief Returns the index into the string pool with the given
284   /// string text.
285   unsigned getStringPoolIndex(StringRef Str);
286
287   /// \brief Returns the string pool.
288   StrPool *getStringPool() { return &StringPool; }
289
290   /// \brief Returns the index into the address pool with the given
291   /// label/symbol.
292   unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
293
294   /// \brief Returns the address pool.
295   AddrPool *getAddrPool() { return &AddressPool; }
296 };
297
298 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
299 struct SymbolCU {
300   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
301   const MCSymbol *Sym;
302   DwarfCompileUnit *CU;
303 };
304
305 /// \brief Collects and handles dwarf debug information.
306 class DwarfDebug : public AsmPrinterHandler {
307   // Target of Dwarf emission.
308   AsmPrinter *Asm;
309
310   // Collected machine module information.
311   MachineModuleInfo *MMI;
312
313   // All DIEValues are allocated through this allocator.
314   BumpPtrAllocator DIEValueAllocator;
315
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;
321
322   // Maps MDNode with its corresponding DwarfCompileUnit.
323   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
324
325   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
326   DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
327
328   // Maps a CU DIE with its corresponding DwarfCompileUnit.
329   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
330
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;
335
336   // List of all labels used in aranges generation.
337   std::vector<SymbolCU> ArangeLabels;
338
339   // Size of each symbol emitted (for those symbols that have a specific size).
340   DenseMap<const MCSymbol *, uint64_t> SymSize;
341
342   // Provides a unique id per text section.
343   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
344   SectionMapType SectionMap;
345
346   // List of arguments for current function.
347   SmallVector<DbgVariable *, 8> CurrentFnArguments;
348
349   LexicalScopes LScopes;
350
351   // Collection of abstract subprogram DIEs.
352   DenseMap<const MDNode *, DIE *> AbstractSPDies;
353
354   // Collection of dbg variables of a scope.
355   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
356   ScopeVariablesMap;
357   ScopeVariablesMap ScopeVariables;
358
359   // Collection of abstract variables.
360   DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
361
362   // Collection of DebugLocEntry.
363   SmallVector<DebugLocEntry, 4> DotDebugLocEntries;
364
365   // Collection of subprogram DIEs that are marked (at the end of the module)
366   // as DW_AT_inline.
367   SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
368
369   // This is a collection of subprogram MDNodes that are processed to
370   // create DIEs.
371   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
372
373   // Maps instruction with label emitted before instruction.
374   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
375
376   // Maps instruction with label emitted after instruction.
377   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
378
379   // Every user variable mentioned by a DBG_VALUE instruction in order of
380   // appearance.
381   SmallVector<const MDNode *, 8> UserVariables;
382
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
385   // DBG_VALUE.
386   typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
387   DbgValueHistoryMap;
388   DbgValueHistoryMap DbgValues;
389
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;
393   MCSymbol *PrevLabel;
394
395   // This location indicates end of function prologue and beginning of function
396   // body.
397   DebugLoc PrologEndLoc;
398
399   // If nonnull, stores the current machine function we're processing.
400   const MachineFunction *CurFn;
401
402   // If nonnull, stores the current machine instruction we're processing.
403   const MachineInstr *CurMI;
404
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;
415
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;
419
420   // Counter for assigning globally unique IDs for ranges.
421   unsigned GlobalRangeCount;
422
423   // Holder for the file specific debug information.
424   DwarfFile InfoHolder;
425
426   // Holders for the various debug information flags that we might need to
427   // have exposed. See accessor functions below for description.
428
429   // Holder for imported entities.
430   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
431   ImportedEntityMap;
432   ImportedEntityMap ScopesWithImportedEntities;
433
434   // Map from MDNodes for user-defined types to the type units that describe
435   // them.
436   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
437
438   // Whether to emit the pubnames/pubtypes sections.
439   bool HasDwarfPubSections;
440
441   // Whether or not to use AT_ranges for compilation units.
442   bool HasCURanges;
443
444   // Whether we emitted a function into a section other than the default
445   // text.
446   bool UsedNonDefaultText;
447
448   // Version of dwarf we're emitting.
449   unsigned DwarfVersion;
450
451   // Maps from a type identifier to the actual MDNode.
452   DITypeIdentifierMap TypeIdentifierMap;
453
454   // DWARF5 Experimental Options
455   bool HasDwarfAccelTables;
456   bool HasSplitDwarf;
457
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.
462
463   // Holder for the skeleton information.
464   DwarfFile SkeletonHolder;
465
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;
469
470   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
471
472   const SmallVectorImpl<DwarfUnit *> &getUnits() {
473     return InfoHolder.getUnits();
474   }
475
476   /// \brief Find abstract variable associated with Var.
477   DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
478
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
482   /// variables.
483   DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
484
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);
488
489   /// \brief A helper function to construct a RangeSpanList for a given
490   /// lexical scope.
491   void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
492                          const SmallVectorImpl<InsnRange> &Range);
493
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);
497
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);
501
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);
507
508   /// \brief Emit initial Dwarf sections with a label at the start of each one.
509   void emitSectionLabels();
510
511   /// \brief Compute the size and offset of a DIE given an incoming Offset.
512   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
513
514   /// \brief Compute the size and offset of all the DIEs.
515   void computeSizeAndOffsets();
516
517   /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
518   void computeInlinedDIEs();
519
520   /// \brief Collect info for variables that were optimized out.
521   void collectDeadVariables();
522
523   /// \brief Finish off debug information after all functions have been
524   /// processed.
525   void finalizeModuleInfo();
526
527   /// \brief Emit labels to close any remaining sections that have been left
528   /// open.
529   void endSections();
530
531   /// \brief Emit the debug info section.
532   void emitDebugInfo();
533
534   /// \brief Emit the abbreviation section.
535   void emitAbbreviations();
536
537   /// \brief Emit the last address of the section and the end of
538   /// the line matrix.
539   void emitEndOfLineMatrix(unsigned SectionEnd);
540
541   /// \brief Emit visible names into a hashed accelerator table section.
542   void emitAccelNames();
543
544   /// \brief Emit objective C classes and categories into a hashed
545   /// accelerator table section.
546   void emitAccelObjC();
547
548   /// \brief Emit namespace dies into a hashed accelerator table.
549   void emitAccelNamespaces();
550
551   /// \brief Emit type dies into a hashed accelerator table.
552   void emitAccelTypes();
553
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
557   /// index.
558   void emitDebugPubNames(bool GnuStyle = false);
559
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
563   /// index.
564   void emitDebugPubTypes(bool GnuStyle = false);
565
566   void
567   emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
568                       const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
569                       const);
570
571   /// \brief Emit visible names into a debug str section.
572   void emitDebugStr();
573
574   /// \brief Emit visible names into a debug loc section.
575   void emitDebugLoc();
576
577   /// \brief Emit visible names into a debug aranges section.
578   void emitDebugARanges();
579
580   /// \brief Emit visible names into a debug ranges section.
581   void emitDebugRanges();
582
583   /// \brief Emit inline info using custom format.
584   void emitDebugInlineInfo();
585
586   /// DWARF 5 Experimental Split Dwarf Emitters
587
588   /// \brief Initialize common features of skeleton units.
589   void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
590
591   /// \brief Construct the split debug info compile unit for the debug info
592   /// section.
593   DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
594
595   /// \brief Construct the split debug info compile unit for the debug info
596   /// section.
597   DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
598
599   /// \brief Emit the debug info dwo section.
600   void emitDebugInfoDWO();
601
602   /// \brief Emit the debug abbrev dwo section.
603   void emitDebugAbbrevDWO();
604
605   /// \brief Emit the debug line dwo section.
606   void emitDebugLineDWO();
607
608   /// \brief Emit the debug str dwo section.
609   void emitDebugStrDWO();
610
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;
614
615   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
616   /// DW_TAG_compile_unit.
617   DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit,
618                                               bool Singular);
619
620   /// \brief Construct subprogram DIE.
621   void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
622
623   /// \brief Construct imported_module or imported_declaration DIE.
624   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
625
626   /// \brief Construct import_module DIE.
627   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
628                                   DIE *Context);
629
630   /// \brief Construct import_module DIE.
631   void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
632                                   const DIImportedEntity &Module, DIE *Context);
633
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,
638                         unsigned Flags);
639
640   /// \brief Indentify instructions that are marking the beginning of or
641   /// ending of a scope.
642   void identifyScopeMarkers();
643
644   /// \brief If Var is an current function argument that add it in
645   /// CurrentFnArguments list.
646   bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
647
648   /// \brief Populate LexicalScope entries with variables' info.
649   void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
650
651   /// \brief Collect variable information from the side table maintained
652   /// by MMI.
653   void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
654
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));
658   }
659
660   /// \brief Return Label preceding the instruction.
661   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
662
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));
666   }
667
668   /// \brief Return Label immediately following the instruction.
669   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
670
671   void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
672                        MCSymbol *End);
673
674 public:
675   //===--------------------------------------------------------------------===//
676   // Main entry points.
677   //
678   DwarfDebug(AsmPrinter *A, Module *M);
679
680   void insertDIE(const MDNode *TypeMD, DIE *Die) {
681     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
682   }
683   DIE *getDIE(const MDNode *TypeMD) {
684     return MDTypeNodeToDieMap.lookup(TypeMD);
685   }
686
687   /// \brief Emit all Dwarf sections that should come prior to the
688   /// content.
689   void beginModule();
690
691   /// \brief Emit all Dwarf sections that should come after the content.
692   void endModule() override;
693
694   /// \brief Gather pre-function debug information.
695   void beginFunction(const MachineFunction *MF) override;
696
697   /// \brief Gather and emit post-function debug information.
698   void endFunction(const MachineFunction *MF) override;
699
700   /// \brief Process beginning of an instruction.
701   void beginInstruction(const MachineInstr *MI) override;
702
703   /// \brief Process end of an instruction.
704   void endInstruction() override;
705
706   /// \brief Add a DIE to the set of types that we're going to pull into
707   /// type units.
708   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
709                             DIE *Die, DICompositeType CTy);
710
711   /// \brief Add a label so that arange data can be generated for it.
712   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
713
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 {
717     SymSize[Sym] = Size;
718   }
719
720   /// \brief Recursively Emits a debug information entry.
721   void emitDIE(DIE *Die);
722
723   // Experimental DWARF5 features.
724
725   /// \brief Returns whether or not to emit tables that dwarf consumers can
726   /// use to accelerate lookup.
727   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
728
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; }
732
733   /// \brief Returns whether or not to use AT_ranges for compilation units.
734   bool useCURanges() const { return HasCURanges; }
735
736   /// Returns the Dwarf Version.
737   unsigned getDwarfVersion() const { return DwarfVersion; }
738
739   /// Returns the section symbol for the .debug_loc section.
740   MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
741
742   /// Returns the entries for the .debug_loc section.
743   const SmallVectorImpl<DebugLocEntry> &getDebugLocEntries() const {
744     return DotDebugLocEntries;
745   }
746
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);
750
751   /// Find the MDNode for the given reference.
752   template <typename T> T resolve(DIRef<T> Ref) const {
753     return Ref.resolve(TypeIdentifierMap);
754   }
755
756   /// \brief Return the TypeIdentifierMap.
757   const DITypeIdentifierMap &getTypeIdentifierMap() const {
758     return TypeIdentifierMap;
759   }
760
761   /// Find the DwarfCompileUnit for the given CU Die.
762   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
763     return CUDieMap.lookup(CU);
764   }
765   /// isSubprogramContext - Return true if Context is either a subprogram
766   /// or another context nested inside a subprogram.
767   bool isSubprogramContext(const MDNode *Context);
768 };
769 } // End of namespace llvm
770
771 #endif