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