DwarfDebug.h revision f04e4efcaa02012b7943b44c61b321a0fb5e1a72
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 "DIE.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/FoldingSet.h"
20#include "llvm/ADT/SetVector.h"
21#include "llvm/ADT/SmallPtrSet.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/CodeGen/AsmPrinter.h"
24#include "llvm/CodeGen/LexicalScopes.h"
25#include "llvm/DebugInfo.h"
26#include "llvm/MC/MachineLocation.h"
27#include "llvm/Support/Allocator.h"
28#include "llvm/Support/DebugLoc.h"
29
30namespace llvm {
31
32class CompileUnit;
33class ConstantInt;
34class ConstantFP;
35class DbgVariable;
36class MachineFrameInfo;
37class MachineModuleInfo;
38class MachineOperand;
39class MCAsmInfo;
40class DIEAbbrev;
41class DIE;
42class DIEBlock;
43class DIEEntry;
44
45//===----------------------------------------------------------------------===//
46/// \brief This class is used to record source line correspondence.
47class SrcLineInfo {
48  unsigned Line;                     // Source line number.
49  unsigned Column;                   // Source column.
50  unsigned SourceID;                 // Source ID number.
51  MCSymbol *Label;                   // Label in code ID number.
52public:
53  SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
54    : Line(L), Column(C), SourceID(S), Label(label) {}
55
56  // Accessors
57  unsigned getLine() const { return Line; }
58  unsigned getColumn() const { return Column; }
59  unsigned getSourceID() const { return SourceID; }
60  MCSymbol *getLabel() const { return Label; }
61};
62
63/// \brief This struct describes location entries emitted in the .debug_loc
64/// section.
65class DotDebugLocEntry {
66  // Begin and end symbols for the address range that this location is valid.
67  const MCSymbol *Begin;
68  const MCSymbol *End;
69
70  // Type of entry that this represents.
71  enum EntryType {
72    E_Location,
73    E_Integer,
74    E_ConstantFP,
75    E_ConstantInt
76  };
77  enum EntryType EntryKind;
78
79  union {
80    int64_t Int;
81    const ConstantFP *CFP;
82    const ConstantInt *CIP;
83  } Constants;
84
85  // The location in the machine frame.
86  MachineLocation Loc;
87
88  // The variable to which this location entry corresponds.
89  const MDNode *Variable;
90
91  // Whether this location has been merged.
92  bool Merged;
93
94public:
95  DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
96    Constants.Int = 0;
97  }
98  DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
99                   const MDNode *V)
100      : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
101    Constants.Int = 0;
102    EntryKind = E_Location;
103  }
104  DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
105      : Begin(B), End(E), Variable(0), Merged(false) {
106    Constants.Int = i;
107    EntryKind = E_Integer;
108  }
109  DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
110      : Begin(B), End(E), Variable(0), Merged(false) {
111    Constants.CFP = FPtr;
112    EntryKind = E_ConstantFP;
113  }
114  DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
115                   const ConstantInt *IPtr)
116      : Begin(B), End(E), Variable(0), Merged(false) {
117    Constants.CIP = IPtr;
118    EntryKind = E_ConstantInt;
119  }
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() { return Begin == 0 && End == 0; }
124  bool isMerged() { return Merged; }
125  void Merge(DotDebugLocEntry *Next) {
126    if (!(Begin && Loc == Next->Loc && End == Next->Begin))
127      return;
128    Next->Begin = Begin;
129    Merged = true;
130  }
131  bool isLocation() const    { return EntryKind == E_Location; }
132  bool isInt() const         { return EntryKind == E_Integer; }
133  bool isConstantFP() const  { return EntryKind == E_ConstantFP; }
134  bool isConstantInt() const { return EntryKind == E_ConstantInt; }
135  int64_t getInt() const                    { return Constants.Int; }
136  const ConstantFP *getConstantFP() const   { return Constants.CFP; }
137  const ConstantInt *getConstantInt() const { return Constants.CIP; }
138  const MDNode *getVariable() const { return Variable; }
139  const MCSymbol *getBeginSym() const { return Begin; }
140  const MCSymbol *getEndSym() const { return End; }
141  MachineLocation getLoc() const { return Loc; }
142};
143
144//===----------------------------------------------------------------------===//
145/// \brief This class is used to track local variable information.
146class 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;
153public:
154  // AbsVar may be NULL.
155  DbgVariable(DIVariable V, DbgVariable *AV)
156    : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
157      FrameIndex(~0) {}
158
159  // Accessors.
160  DIVariable getVariable()           const { return Var; }
161  void setDIE(DIE *D)                      { TheDIE = D; }
162  DIE *getDIE()                      const { return TheDIE; }
163  void setDotDebugLocOffset(unsigned O)    { DotDebugLocOffset = O; }
164  unsigned getDotDebugLocOffset()    const { return DotDebugLocOffset; }
165  StringRef getName()                const { return Var.getName(); }
166  DbgVariable *getAbstractVariable() const { return AbsVar; }
167  const MachineInstr *getMInsn()     const { return MInsn; }
168  void setMInsn(const MachineInstr *M)     { MInsn = M; }
169  int getFrameIndex()                const { return FrameIndex; }
170  void setFrameIndex(int FI)               { FrameIndex = FI; }
171  // Translate tag to proper Dwarf tag.
172  uint16_t getTag()                  const {
173    if (Var.getTag() == dwarf::DW_TAG_arg_variable)
174      return dwarf::DW_TAG_formal_parameter;
175
176    return dwarf::DW_TAG_variable;
177  }
178  /// \brief Return true if DbgVariable is artificial.
179  bool isArtificial()                const {
180    if (Var.isArtificial())
181      return true;
182    if (getType().isArtificial())
183      return true;
184    return false;
185  }
186
187  bool isObjectPointer()             const {
188    if (Var.isObjectPointer())
189      return true;
190    if (getType().isObjectPointer())
191      return true;
192    return false;
193  }
194
195  bool variableHasComplexAddress()   const {
196    assert(Var.isVariable() && "Invalid complex DbgVariable!");
197    return Var.hasComplexAddress();
198  }
199  bool isBlockByrefVariable()        const {
200    assert(Var.isVariable() && "Invalid complex DbgVariable!");
201    return Var.isBlockByrefVariable();
202  }
203  unsigned getNumAddrElements()      const {
204    assert(Var.isVariable() && "Invalid complex DbgVariable!");
205    return Var.getNumAddrElements();
206  }
207  uint64_t getAddrElement(unsigned i) const {
208    return Var.getAddrElement(i);
209  }
210  DIType getType() const;
211};
212
213/// \brief Collects and handles information specific to a particular
214/// collection of units.
215class DwarfUnits {
216  // Target of Dwarf emission, used for sizing of abbreviations.
217  AsmPrinter *Asm;
218
219  // Used to uniquely define abbreviations.
220  FoldingSet<DIEAbbrev> *AbbreviationsSet;
221
222  // A list of all the unique abbreviations in use.
223  std::vector<DIEAbbrev *> *Abbreviations;
224
225  // A pointer to all units in the section.
226  SmallVector<CompileUnit *, 1> CUs;
227
228  // Collection of strings for this unit and assorted symbols.
229  // A String->Symbol mapping of strings used by indirect
230  // references.
231  typedef StringMap<std::pair<MCSymbol*, unsigned>,
232                    BumpPtrAllocator&> StrPool;
233  StrPool StringPool;
234  unsigned NextStringPoolNumber;
235  std::string StringPref;
236
237  // Collection of addresses for this unit and assorted labels.
238  // A Symbol->unsigned mapping of addresses used by indirect
239  // references.
240  typedef DenseMap<const MCExpr *, unsigned> AddrPool;
241  AddrPool AddressPool;
242  unsigned NextAddrPoolNumber;
243
244public:
245  DwarfUnits(AsmPrinter *AP, FoldingSet<DIEAbbrev> *AS,
246             std::vector<DIEAbbrev *> *A, const char *Pref,
247             BumpPtrAllocator &DA)
248      : Asm(AP), AbbreviationsSet(AS), Abbreviations(A), StringPool(DA),
249        NextStringPoolNumber(0), StringPref(Pref), AddressPool(),
250        NextAddrPoolNumber(0) {}
251
252  /// \brief Compute the size and offset of a DIE given an incoming Offset.
253  unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
254
255  /// \brief Compute the size and offset of all the DIEs.
256  void computeSizeAndOffsets();
257
258  /// \brief Define a unique number for the abbreviation.
259  void assignAbbrevNumber(DIEAbbrev &Abbrev);
260
261  /// \brief Add a unit to the list of CUs.
262  void addUnit(CompileUnit *CU) { CUs.push_back(CU); }
263
264  /// \brief Emit all of the units to the section listed with the given
265  /// abbreviation section.
266  void emitUnits(DwarfDebug *DD, const MCSection *USection,
267                 const MCSection *ASection, const MCSymbol *ASectionSym);
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 MCExpr *Sym);
293  unsigned getAddrPoolIndex(const MCSymbol *Sym);
294
295  /// \brief Returns the address pool.
296  AddrPool *getAddrPool() { return &AddressPool; }
297
298  /// \brief for a given compile unit DIE, returns offset from beginning of
299  /// debug info.
300  unsigned getCUOffset(DIE *Die);
301};
302
303/// \brief Collects and handles dwarf debug information.
304class DwarfDebug {
305  // Target of Dwarf emission.
306  AsmPrinter *Asm;
307
308  // Collected machine module information.
309  MachineModuleInfo *MMI;
310
311  // All DIEValues are allocated through this allocator.
312  BumpPtrAllocator DIEValueAllocator;
313
314  // Handle to the a compile unit used for the inline extension handling.
315  CompileUnit *FirstCU;
316
317  // Maps MDNode with its corresponding CompileUnit.
318  DenseMap <const MDNode *, CompileUnit *> CUMap;
319
320  // Maps subprogram MDNode with its corresponding CompileUnit.
321  DenseMap <const MDNode *, CompileUnit *> SPMap;
322
323  // Used to uniquely define abbreviations.
324  FoldingSet<DIEAbbrev> AbbreviationsSet;
325
326  // A list of all the unique abbreviations in use.
327  std::vector<DIEAbbrev *> Abbreviations;
328
329  // Stores the current file ID for a given compile unit.
330  DenseMap <unsigned, unsigned> FileIDCUMap;
331  // Source id map, i.e. CUID, source filename and directory,
332  // separated by a zero byte, mapped to a unique id.
333  StringMap<unsigned, BumpPtrAllocator&> SourceIdMap;
334
335  // Provides a unique id per text section.
336  SetVector<const MCSection*> SectionMap;
337
338  // List of arguments for current function.
339  SmallVector<DbgVariable *, 8> CurrentFnArguments;
340
341  LexicalScopes LScopes;
342
343  // Collection of abstract subprogram DIEs.
344  DenseMap<const MDNode *, DIE *> AbstractSPDies;
345
346  // Collection of dbg variables of a scope.
347  typedef DenseMap<LexicalScope *,
348                   SmallVector<DbgVariable *, 8> > ScopeVariablesMap;
349  ScopeVariablesMap ScopeVariables;
350
351  // Collection of abstract variables.
352  DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
353
354  // Collection of DotDebugLocEntry.
355  SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
356
357  // Collection of subprogram DIEs that are marked (at the end of the module)
358  // as DW_AT_inline.
359  SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
360
361  // Keep track of inlined functions and their location.  This
362  // information is used to populate the debug_inlined section.
363  typedef std::pair<const MCSymbol *, DIE *> InlineInfoLabels;
364  typedef DenseMap<const MDNode *,
365                   SmallVector<InlineInfoLabels, 4> > InlineInfoMap;
366  InlineInfoMap InlineInfo;
367  SmallVector<const MDNode *, 4> InlinedSPNodes;
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  SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
391
392  // Previous instruction's location information. This is used to determine
393  // label location to indicate scope boundries in dwarf debug info.
394  DebugLoc PrevInstLoc;
395  MCSymbol *PrevLabel;
396
397  // This location indicates end of function prologue and beginning of function
398  // body.
399  DebugLoc PrologEndLoc;
400
401  // Section Symbols: these are assembler temporary labels that are emitted at
402  // the beginning of each supported dwarf section.  These are used to form
403  // section offsets and are created by EmitSectionLabels.
404  MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
405  MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
406  MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
407  MCSymbol *FunctionBeginSym, *FunctionEndSym;
408  MCSymbol *DwarfAbbrevDWOSectionSym, *DwarfStrDWOSectionSym;
409
410  // As an optimization, there is no need to emit an entry in the directory
411  // table for the same directory as DW_AT_comp_dir.
412  StringRef CompilationDir;
413
414  // Counter for assigning globally unique IDs for CUs.
415  unsigned GlobalCUIndexCount;
416
417  // Holder for the file specific debug information.
418  DwarfUnits InfoHolder;
419
420  // Holders for the various debug information flags that we might need to
421  // have exposed. See accessor functions below for description.
422
423  // Whether or not we're emitting info for older versions of gdb on darwin.
424  bool IsDarwinGDBCompat;
425
426  // Holder for imported entities.
427  typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
428    ImportedEntityMap;
429  ImportedEntityMap ScopesWithImportedEntities;
430
431  // Holder for types that are going to be extracted out into a type unit.
432  std::vector<DIE *> TypeUnits;
433
434  // DWARF5 Experimental Options
435  bool HasDwarfAccelTables;
436  bool HasSplitDwarf;
437  bool HasDwarfPubNames;
438
439  unsigned DwarfVersion;
440
441  // Separated Dwarf Variables
442  // In general these will all be for bits that are left in the
443  // original object file, rather than things that are meant
444  // to be in the .dwo sections.
445
446  // The CUs left in the original object file for separated debug info.
447  SmallVector<CompileUnit *, 1> SkeletonCUs;
448
449  // Used to uniquely define abbreviations for the skeleton emission.
450  FoldingSet<DIEAbbrev> SkeletonAbbrevSet;
451
452  // A list of all the unique abbreviations in use.
453  std::vector<DIEAbbrev *> SkeletonAbbrevs;
454
455  // Holder for the skeleton information.
456  DwarfUnits SkeletonHolder;
457
458private:
459
460  void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
461
462  /// \brief Find abstract variable associated with Var.
463  DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
464
465  /// \brief Find DIE for the given subprogram and attach appropriate
466  /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
467  /// variables in this scope then create and insert DIEs for these
468  /// variables.
469  DIE *updateSubprogramScopeDIE(CompileUnit *SPCU, const MDNode *SPNode);
470
471  /// \brief Construct new DW_TAG_lexical_block for this scope and
472  /// attach DW_AT_low_pc/DW_AT_high_pc labels.
473  DIE *constructLexicalScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
474
475  /// \brief This scope represents inlined body of a function. Construct
476  /// DIE to represent this concrete inlined copy of the function.
477  DIE *constructInlinedScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
478
479  /// \brief Construct a DIE for this scope.
480  DIE *constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
481
482  /// \brief Emit initial Dwarf sections with a label at the start of each one.
483  void emitSectionLabels();
484
485  /// \brief Compute the size and offset of a DIE given an incoming Offset.
486  unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
487
488  /// \brief Compute the size and offset of all the DIEs.
489  void computeSizeAndOffsets();
490
491  /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
492  void computeInlinedDIEs();
493
494  /// \brief Collect info for variables that were optimized out.
495  void collectDeadVariables();
496
497  /// \brief Finish off debug information after all functions have been
498  /// processed.
499  void finalizeModuleInfo();
500
501  /// \brief Emit labels to close any remaining sections that have been left
502  /// open.
503  void endSections();
504
505  /// \brief Emit a set of abbreviations to the specific section.
506  void emitAbbrevs(const MCSection *, std::vector<DIEAbbrev*> *);
507
508  /// \brief Emit the debug info section.
509  void emitDebugInfo();
510
511  /// \brief Emit the abbreviation section.
512  void emitAbbreviations();
513
514  /// \brief Emit the last address of the section and the end of
515  /// the line matrix.
516  void emitEndOfLineMatrix(unsigned SectionEnd);
517
518  /// \brief Emit visible names into a hashed accelerator table section.
519  void emitAccelNames();
520
521  /// \brief Emit objective C classes and categories into a hashed
522  /// accelerator table section.
523  void emitAccelObjC();
524
525  /// \brief Emit namespace dies into a hashed accelerator table.
526  void emitAccelNamespaces();
527
528  /// \brief Emit type dies into a hashed accelerator table.
529  void emitAccelTypes();
530
531  /// \brief Emit visible names into a debug pubnames section.
532  void emitDebugPubnames();
533
534  /// \brief Emit visible types into a debug pubtypes section.
535  void emitDebugPubTypes();
536
537  /// \brief Emit visible names into a debug str section.
538  void emitDebugStr();
539
540  /// \brief Emit visible names into a debug loc section.
541  void emitDebugLoc();
542
543  /// \brief Emit visible names into a debug aranges section.
544  void emitDebugARanges();
545
546  /// \brief Emit visible names into a debug ranges section.
547  void emitDebugRanges();
548
549  /// \brief Emit visible names into a debug macinfo section.
550  void emitDebugMacInfo();
551
552  /// \brief Emit inline info using custom format.
553  void emitDebugInlineInfo();
554
555  /// DWARF 5 Experimental Split Dwarf Emitters
556
557  /// \brief Construct the split debug info compile unit for the debug info
558  /// section.
559  CompileUnit *constructSkeletonCU(const MDNode *);
560
561  /// \brief Emit the local split abbreviations.
562  void emitSkeletonAbbrevs(const MCSection *);
563
564  /// \brief Emit the debug info dwo section.
565  void emitDebugInfoDWO();
566
567  /// \brief Emit the debug abbrev dwo section.
568  void emitDebugAbbrevDWO();
569
570  /// \brief Emit the debug str dwo section.
571  void emitDebugStrDWO();
572
573  /// \brief Create new CompileUnit for the given metadata node with tag
574  /// DW_TAG_compile_unit.
575  CompileUnit *constructCompileUnit(const MDNode *N);
576
577  /// \brief Construct subprogram DIE.
578  void constructSubprogramDIE(CompileUnit *TheCU, const MDNode *N);
579
580  /// \brief Construct imported_module or imported_declaration DIE.
581  void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N);
582
583  /// \brief Construct import_module DIE.
584  void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N,
585                                  DIE *Context);
586
587  /// \brief Construct import_module DIE.
588  void constructImportedEntityDIE(CompileUnit *TheCU,
589                                  const DIImportedEntity &Module,
590                                  DIE *Context);
591
592  /// \brief Register a source line with debug info. Returns the unique
593  /// label that was emitted and which provides correspondence to the
594  /// source line list.
595  void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
596                        unsigned Flags);
597
598  /// \brief Indentify instructions that are marking the beginning of or
599  /// ending of a scope.
600  void identifyScopeMarkers();
601
602  /// \brief If Var is an current function argument that add it in
603  /// CurrentFnArguments list.
604  bool addCurrentFnArgument(const MachineFunction *MF,
605                            DbgVariable *Var, LexicalScope *Scope);
606
607  /// \brief Populate LexicalScope entries with variables' info.
608  void collectVariableInfo(const MachineFunction *,
609                           SmallPtrSet<const MDNode *, 16> &ProcessedVars);
610
611  /// \brief Collect variable information from the side table maintained
612  /// by MMI.
613  void collectVariableInfoFromMMITable(const MachineFunction * MF,
614                                       SmallPtrSet<const MDNode *, 16> &P);
615
616  /// \brief Ensure that a label will be emitted before MI.
617  void requestLabelBeforeInsn(const MachineInstr *MI) {
618    LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol*)0));
619  }
620
621  /// \brief Return Label preceding the instruction.
622  MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
623
624  /// \brief Ensure that a label will be emitted after MI.
625  void requestLabelAfterInsn(const MachineInstr *MI) {
626    LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol*)0));
627  }
628
629  /// \brief Return Label immediately following the instruction.
630  MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
631
632public:
633  //===--------------------------------------------------------------------===//
634  // Main entry points.
635  //
636  DwarfDebug(AsmPrinter *A, Module *M);
637  ~DwarfDebug();
638
639  /// \brief Emit all Dwarf sections that should come prior to the
640  /// content.
641  void beginModule();
642
643  /// \brief Emit all Dwarf sections that should come after the content.
644  void endModule();
645
646  /// \brief Gather pre-function debug information.
647  void beginFunction(const MachineFunction *MF);
648
649  /// \brief Gather and emit post-function debug information.
650  void endFunction(const MachineFunction *MF);
651
652  /// \brief Process beginning of an instruction.
653  void beginInstruction(const MachineInstr *MI);
654
655  /// \brief Process end of an instruction.
656  void endInstruction(const MachineInstr *MI);
657
658  /// \brief Add a DIE to the set of types that we're going to pull into
659  /// type units.
660  void addTypeUnitType(DIE *Die) { TypeUnits.push_back(Die); }
661
662  /// \brief Look up the source id with the given directory and source file
663  /// names. If none currently exists, create a new id and insert it in the
664  /// SourceIds map.
665  unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName,
666                               unsigned CUID);
667
668  /// \brief Recursively Emits a debug information entry.
669  void emitDIE(DIE *Die, std::vector<DIEAbbrev *> *Abbrevs);
670
671  /// \brief Returns whether or not to limit some of our debug
672  /// output to the limitations of darwin gdb.
673  bool useDarwinGDBCompat() { return IsDarwinGDBCompat; }
674
675  // Experimental DWARF5 features.
676
677  /// \brief Returns whether or not to emit tables that dwarf consumers can
678  /// use to accelerate lookup.
679  bool useDwarfAccelTables() { return HasDwarfAccelTables; }
680
681  /// \brief Returns whether or not to change the current debug info for the
682  /// split dwarf proposal support.
683  bool useSplitDwarf() { return HasSplitDwarf; }
684
685  /// Returns the Dwarf Version.
686  unsigned getDwarfVersion() const { return DwarfVersion; }
687};
688} // End of namespace llvm
689
690#endif
691