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