LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DwarfDebug.h
Go to the documentation of this file.
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"
25 #include "llvm/DebugInfo.h"
27 #include "llvm/Support/Allocator.h"
28 #include "llvm/Support/DebugLoc.h"
29 
30 namespace llvm {
31 
32 class CompileUnit;
33 class ConstantInt;
34 class ConstantFP;
35 class DbgVariable;
36 class MachineFrameInfo;
37 class MachineModuleInfo;
38 class MachineOperand;
39 class MCAsmInfo;
40 class DIEAbbrev;
41 class DIE;
42 class DIEBlock;
43 class DIEEntry;
44 
45 //===----------------------------------------------------------------------===//
46 /// \brief This class is used to record source line correspondence.
47 class 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.
52 public:
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.
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 
94 public:
95  DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
96  Constants.Int = 0;
97  }
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.
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 public:
155  // AbsVar may be NULL.
157  : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
158  FrameIndex(~0), DD(DD) {}
159 
160  // Accessors.
161  DIVariable getVariable() const { return Var; }
162  void setDIE(DIE *D) { TheDIE = D; }
163  DIE *getDIE() const { return TheDIE; }
164  void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
165  unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
166  StringRef getName() const { return Var.getName(); }
167  DbgVariable *getAbstractVariable() const { return AbsVar; }
168  const MachineInstr *getMInsn() const { return MInsn; }
169  void setMInsn(const MachineInstr *M) { MInsn = M; }
170  int getFrameIndex() const { return FrameIndex; }
171  void setFrameIndex(int FI) { FrameIndex = FI; }
172  // Translate tag to proper Dwarf tag.
173  uint16_t getTag() const {
174  if (Var.getTag() == dwarf::DW_TAG_arg_variable)
175  return dwarf::DW_TAG_formal_parameter;
176 
177  return dwarf::DW_TAG_variable;
178  }
179  /// \brief Return true if DbgVariable is artificial.
180  bool isArtificial() const {
181  if (Var.isArtificial())
182  return true;
183  if (getType().isArtificial())
184  return true;
185  return false;
186  }
187 
188  bool isObjectPointer() const {
189  if (Var.isObjectPointer())
190  return true;
191  if (getType().isObjectPointer())
192  return true;
193  return false;
194  }
195 
197  assert(Var.isVariable() && "Invalid complex DbgVariable!");
198  return Var.hasComplexAddress();
199  }
200  bool isBlockByrefVariable() const {
201  assert(Var.isVariable() && "Invalid complex DbgVariable!");
202  return Var.isBlockByrefVariable();
203  }
204  unsigned getNumAddrElements() const {
205  assert(Var.isVariable() && "Invalid complex DbgVariable!");
206  return Var.getNumAddrElements();
207  }
208  uint64_t getAddrElement(unsigned i) const {
209  return Var.getAddrElement(i);
210  }
211  DIType getType() const;
212 
213 private:
214  /// resolve - Look in the DwarfDebug map for the MDNode that
215  /// corresponds to the reference.
216  template <typename T> T resolve(DIRef<T> Ref) const;
217 };
218 
219 /// \brief Collects and handles information specific to a particular
220 /// collection of units.
221 class DwarfUnits {
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.
233 
234  // Collection of strings for this unit and assorted symbols.
235  // A String->Symbol mapping of strings used by indirect
236  // references.
240  unsigned NextStringPoolNumber;
241  std::string StringPref;
242 
243  // Collection of addresses for this unit and assorted labels.
244  // A Symbol->unsigned mapping of addresses used by indirect
245  // references.
247  AddrPool AddressPool;
248  unsigned NextAddrPoolNumber;
249 
250 public:
252  std::vector<DIEAbbrev *> &A, const char *Pref,
254  : Asm(AP), AbbreviationsSet(AS), Abbreviations(A), StringPool(DA),
255  NextStringPoolNumber(0), StringPref(Pref), AddressPool(),
256  NextAddrPoolNumber(0) {}
257 
258  /// \brief Compute the size and offset of a DIE given an incoming Offset.
259  unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
260 
261  /// \brief Compute the size and offset of all the DIEs.
262  void computeSizeAndOffsets();
263 
264  /// \brief Define a unique number for the abbreviation.
265  void assignAbbrevNumber(DIEAbbrev &Abbrev);
266 
267  /// \brief Add a unit to the list of CUs.
268  void addUnit(CompileUnit *CU) { CUs.push_back(CU); }
269 
270  /// \brief Emit all of the units to the section listed with the given
271  /// abbreviation section.
272  void emitUnits(DwarfDebug *DD, const MCSection *USection,
273  const MCSection *ASection, const MCSymbol *ASectionSym);
274 
275  /// \brief Emit all of the strings to the section given.
276  void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
277  const MCSymbol *StrSecSym);
278 
279  /// \brief Emit all of the addresses to the section given.
280  void emitAddresses(const MCSection *AddrSection);
281 
282  /// \brief Returns the entry into the start of the pool.
284 
285  /// \brief Returns an entry into the string pool with the given
286  /// string text.
288 
289  /// \brief Returns the index into the string pool with the given
290  /// string text.
291  unsigned getStringPoolIndex(StringRef Str);
292 
293  /// \brief Returns the string pool.
295 
296  /// \brief Returns the index into the address pool with the given
297  /// label/symbol.
298  unsigned getAddrPoolIndex(const MCExpr *Sym);
299  unsigned getAddrPoolIndex(const MCSymbol *Sym);
300 
301  /// \brief Returns the address pool.
302  AddrPool *getAddrPool() { return &AddressPool; }
303 };
304 
305 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
306 struct SymbolCU {
307  SymbolCU(CompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
308  const MCSymbol *Sym;
310 };
311 
312 /// \brief Collects and handles dwarf debug information.
313 class DwarfDebug {
314  // Target of Dwarf emission.
315  AsmPrinter *Asm;
316 
317  // Collected machine module information.
318  MachineModuleInfo *MMI;
319 
320  // All DIEValues are allocated through this allocator.
321  BumpPtrAllocator DIEValueAllocator;
322 
323  // Handle to the a compile unit used for the inline extension handling.
324  CompileUnit *FirstCU;
325 
326  // Maps MDNode with its corresponding CompileUnit.
328 
329  // Maps subprogram MDNode with its corresponding CompileUnit.
331 
332  // Maps a CU DIE with its corresponding CompileUnit.
334 
335  /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
336  /// be shared across CUs, that is why we keep the map here instead
337  /// of in CompileUnit.
338  DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
339 
340  // Used to uniquely define abbreviations.
341  FoldingSet<DIEAbbrev> AbbreviationsSet;
342 
343  // A list of all the unique abbreviations in use.
344  std::vector<DIEAbbrev *> Abbreviations;
345 
346  // Stores the current file ID for a given compile unit.
347  DenseMap <unsigned, unsigned> FileIDCUMap;
348  // Source id map, i.e. CUID, source filename and directory,
349  // separated by a zero byte, mapped to a unique id.
351 
352  // List of all labels used in aranges generation.
353  std::vector<SymbolCU> ArangeLabels;
354 
355  // Size of each symbol emitted (for those symbols that have a specific size).
357 
358  // Provides a unique id per text section.
360  SectionMapType SectionMap;
361 
362  // List of arguments for current function.
363  SmallVector<DbgVariable *, 8> CurrentFnArguments;
364 
365  LexicalScopes LScopes;
366 
367  // Collection of abstract subprogram DIEs.
368  DenseMap<const MDNode *, DIE *> AbstractSPDies;
369 
370  // Collection of dbg variables of a scope.
371  typedef DenseMap<LexicalScope *,
373  ScopeVariablesMap ScopeVariables;
374 
375  // Collection of abstract variables.
376  DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
377 
378  // Collection of DotDebugLocEntry.
379  SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
380 
381  // Collection of subprogram DIEs that are marked (at the end of the module)
382  // as DW_AT_inline.
383  SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
384 
385  // This is a collection of subprogram MDNodes that are processed to
386  // create DIEs.
387  SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
388 
389  // Maps instruction with label emitted before instruction.
391 
392  // Maps instruction with label emitted after instruction.
394 
395  // Every user variable mentioned by a DBG_VALUE instruction in order of
396  // appearance.
397  SmallVector<const MDNode*, 8> UserVariables;
398 
399  // For each user variable, keep a list of DBG_VALUE instructions in order.
400  // The list can also contain normal instructions that clobber the previous
401  // DBG_VALUE.
404  DbgValueHistoryMap DbgValues;
405 
406  SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
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  // Section Symbols: these are assembler temporary labels that are emitted at
418  // the beginning of each supported dwarf section. These are used to form
419  // section offsets and are created by EmitSectionLabels.
420  MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
421  MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
422  MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
423  MCSymbol *FunctionBeginSym, *FunctionEndSym;
424  MCSymbol *DwarfAbbrevDWOSectionSym, *DwarfStrDWOSectionSym;
425  MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
426 
427  // As an optimization, there is no need to emit an entry in the directory
428  // table for the same directory as DW_AT_comp_dir.
429  StringRef CompilationDir;
430 
431  // Counter for assigning globally unique IDs for CUs.
432  unsigned GlobalCUIndexCount;
433 
434  // Holder for the file specific debug information.
435  DwarfUnits InfoHolder;
436 
437  // Holders for the various debug information flags that we might need to
438  // have exposed. See accessor functions below for description.
439 
440  // Holder for imported entities.
443  ImportedEntityMap ScopesWithImportedEntities;
444 
445  // Holder for types that are going to be extracted out into a type unit.
446  std::vector<DIE *> TypeUnits;
447 
448  // Whether to emit the pubnames/pubtypes sections.
449  bool HasDwarfPubSections;
450 
451  // Version of dwarf we're emitting.
452  unsigned DwarfVersion;
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  // The CUs left in the original object file for separated debug info.
464  SmallVector<CompileUnit *, 1> SkeletonCUs;
465 
466  // Used to uniquely define abbreviations for the skeleton emission.
467  FoldingSet<DIEAbbrev> SkeletonAbbrevSet;
468 
469  // A list of all the unique abbreviations in use.
470  std::vector<DIEAbbrev *> SkeletonAbbrevs;
471 
472  // Holder for the skeleton information.
473  DwarfUnits SkeletonHolder;
474 
475  // Maps from a type identifier to the actual MDNode.
476  DITypeIdentifierMap TypeIdentifierMap;
477 
478 private:
479 
480  void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
481 
482  /// \brief Find abstract variable associated with Var.
483  DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
484 
485  /// \brief Find DIE for the given subprogram and attach appropriate
486  /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
487  /// variables in this scope then create and insert DIEs for these
488  /// variables.
489  DIE *updateSubprogramScopeDIE(CompileUnit *SPCU, DISubprogram SP);
490 
491  /// \brief Construct new DW_TAG_lexical_block for this scope and
492  /// attach DW_AT_low_pc/DW_AT_high_pc labels.
493  DIE *constructLexicalScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
494  /// A helper function to check whether the DIE for a given Scope is going
495  /// to be null.
496  bool isLexicalScopeDIENull(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(CompileUnit *TheCU, LexicalScope *Scope);
501 
502  /// \brief Construct a DIE for this scope.
503  DIE *constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
504  /// A helper function to create children of a Scope DIE.
505  DIE *createScopeChildrenDIE(CompileUnit *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 a set of abbreviations to the specific section.
532  void emitAbbrevs(const MCSection *, std::vector<DIEAbbrev*> *);
533 
534  /// \brief Emit the debug info section.
535  void emitDebugInfo();
536 
537  /// \brief Emit the abbreviation section.
538  void emitAbbreviations();
539 
540  /// \brief Emit the last address of the section and the end of
541  /// the line matrix.
542  void emitEndOfLineMatrix(unsigned SectionEnd);
543 
544  /// \brief Emit visible names into a hashed accelerator table section.
545  void emitAccelNames();
546 
547  /// \brief Emit objective C classes and categories into a hashed
548  /// accelerator table section.
549  void emitAccelObjC();
550 
551  /// \brief Emit namespace dies into a hashed accelerator table.
552  void emitAccelNamespaces();
553 
554  /// \brief Emit type dies into a hashed accelerator table.
555  void emitAccelTypes();
556 
557  /// \brief Emit visible names into a debug pubnames section.
558  /// \param GnuStyle determines whether or not we want to emit
559  /// additional information into the table ala newer gcc for gdb
560  /// index.
561  void emitDebugPubNames(bool GnuStyle = false);
562 
563  /// \brief Emit visible types into a debug pubtypes section.
564  /// \param GnuStyle determines whether or not we want to emit
565  /// additional information into the table ala newer gcc for gdb
566  /// index.
567  void emitDebugPubTypes(bool GnuStyle = false);
568 
569  /// \brief Emit visible names into a debug str section.
570  void emitDebugStr();
571 
572  /// \brief Emit visible names into a debug loc section.
573  void emitDebugLoc();
574 
575  /// \brief Emit visible names into a debug aranges section.
576  void emitDebugARanges();
577 
578  /// \brief Emit visible names into a debug ranges section.
579  void emitDebugRanges();
580 
581  /// \brief Emit visible names into a debug macinfo section.
582  void emitDebugMacInfo();
583 
584  /// \brief Emit inline info using custom format.
585  void emitDebugInlineInfo();
586 
587  /// DWARF 5 Experimental Split Dwarf Emitters
588 
589  /// \brief Construct the split debug info compile unit for the debug info
590  /// section.
591  CompileUnit *constructSkeletonCU(const CompileUnit *CU);
592 
593  /// \brief Emit the local split abbreviations.
594  void emitSkeletonAbbrevs(const MCSection *);
595 
596  /// \brief Emit the debug info dwo section.
597  void emitDebugInfoDWO();
598 
599  /// \brief Emit the debug abbrev dwo section.
600  void emitDebugAbbrevDWO();
601 
602  /// \brief Emit the debug str dwo section.
603  void emitDebugStrDWO();
604 
605  /// \brief Create new CompileUnit for the given metadata node with tag
606  /// DW_TAG_compile_unit.
607  CompileUnit *constructCompileUnit(DICompileUnit DIUnit);
608 
609  /// \brief Construct subprogram DIE.
610  void constructSubprogramDIE(CompileUnit *TheCU, const MDNode *N);
611 
612  /// \brief Construct imported_module or imported_declaration DIE.
613  void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N);
614 
615  /// \brief Construct import_module DIE.
616  void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N,
617  DIE *Context);
618 
619  /// \brief Construct import_module DIE.
620  void constructImportedEntityDIE(CompileUnit *TheCU,
621  const DIImportedEntity &Module,
622  DIE *Context);
623 
624  /// \brief Register a source line with debug info. Returns the unique
625  /// label that was emitted and which provides correspondence to the
626  /// source line list.
627  void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
628  unsigned Flags);
629 
630  /// \brief Indentify instructions that are marking the beginning of or
631  /// ending of a scope.
632  void identifyScopeMarkers();
633 
634  /// \brief If Var is an current function argument that add it in
635  /// CurrentFnArguments list.
636  bool addCurrentFnArgument(const MachineFunction *MF,
637  DbgVariable *Var, LexicalScope *Scope);
638 
639  /// \brief Populate LexicalScope entries with variables' info.
640  void collectVariableInfo(const MachineFunction *,
641  SmallPtrSet<const MDNode *, 16> &ProcessedVars);
642 
643  /// \brief Collect variable information from the side table maintained
644  /// by MMI.
645  void collectVariableInfoFromMMITable(const MachineFunction * MF,
647 
648  /// \brief Ensure that a label will be emitted before MI.
649  void requestLabelBeforeInsn(const MachineInstr *MI) {
650  LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol*)0));
651  }
652 
653  /// \brief Return Label preceding the instruction.
654  MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
655 
656  /// \brief Ensure that a label will be emitted after MI.
657  void requestLabelAfterInsn(const MachineInstr *MI) {
658  LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol*)0));
659  }
660 
661  /// \brief Return Label immediately following the instruction.
662  MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
663 
664 public:
665  //===--------------------------------------------------------------------===//
666  // Main entry points.
667  //
668  DwarfDebug(AsmPrinter *A, Module *M);
669 
670  void insertDIE(const MDNode *TypeMD, DIE *Die) {
671  MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
672  }
673  DIE *getDIE(const MDNode *TypeMD) {
674  return MDTypeNodeToDieMap.lookup(TypeMD);
675  }
676 
677  /// \brief Emit all Dwarf sections that should come prior to the
678  /// content.
679  void beginModule();
680 
681  /// \brief Emit all Dwarf sections that should come after the content.
682  void endModule();
683 
684  /// \brief Gather pre-function debug information.
685  void beginFunction(const MachineFunction *MF);
686 
687  /// \brief Gather and emit post-function debug information.
688  void endFunction(const MachineFunction *MF);
689 
690  /// \brief Process beginning of an instruction.
691  void beginInstruction(const MachineInstr *MI);
692 
693  /// \brief Process end of an instruction.
694  void endInstruction(const MachineInstr *MI);
695 
696  /// \brief Add a DIE to the set of types that we're going to pull into
697  /// type units.
698  void addTypeUnitType(DIE *Die) { TypeUnits.push_back(Die); }
699 
700  /// \brief Add a label so that arange data can be generated for it.
701  void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
702 
703  /// \brief For symbols that have a size designated (e.g. common symbols),
704  /// this tracks that size.
705  void setSymbolSize(const MCSymbol *Sym, uint64_t Size) { SymSize[Sym] = Size;}
706 
707  /// \brief Look up the source id with the given directory and source file
708  /// names. If none currently exists, create a new id and insert it in the
709  /// SourceIds map.
710  unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName,
711  unsigned CUID);
712 
713  /// \brief Recursively Emits a debug information entry.
714  void emitDIE(DIE *Die, ArrayRef<DIEAbbrev *> Abbrevs);
715 
716  // Experimental DWARF5 features.
717 
718  /// \brief Returns whether or not to emit tables that dwarf consumers can
719  /// use to accelerate lookup.
720  bool useDwarfAccelTables() { return HasDwarfAccelTables; }
721 
722  /// \brief Returns whether or not to change the current debug info for the
723  /// split dwarf proposal support.
724  bool useSplitDwarf() { return HasSplitDwarf; }
725 
726  /// Returns the Dwarf Version.
727  unsigned getDwarfVersion() const { return DwarfVersion; }
728 
729  /// Find the MDNode for the given reference.
730  template <typename T> T resolve(DIRef<T> Ref) const {
731  return Ref.resolve(TypeIdentifierMap);
732  }
733 
734  /// isSubprogramContext - Return true if Context is either a subprogram
735  /// or another context nested inside a subprogram.
736  bool isSubprogramContext(const MDNode *Context);
737 
738 };
739 } // End of namespace llvm
740 
741 #endif
bool isBlockByrefVariable() const
Definition: DebugInfo.h:653
DbgVariable * getAbstractVariable() const
Definition: DwarfDebug.h:167
AddrPool * getAddrPool()
Returns the address pool.
Definition: DwarfDebug.h:302
const MachineInstr * getMInsn() const
Definition: DwarfDebug.h:168
CompileUnit * CU
Definition: DwarfDebug.h:309
bool isArtificial() const
Definition: DebugInfo.h:309
const ConstantFP * CFP
Definition: DwarfDebug.h:81
bool isVariable() const
isVariable - Return true if the specified tag is legal for DIVariable.
Definition: DebugInfo.cpp:206
uint16_t getTag() const
Definition: DebugInfo.h:121
bool useDwarfAccelTables()
Returns whether or not to emit tables that dwarf consumers can use to accelerate lookup.
Definition: DwarfDebug.h:720
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
Definition: DwarfDebug.h:156
DwarfUnits(AsmPrinter *AP, FoldingSet< DIEAbbrev > *AS, std::vector< DIEAbbrev * > &A, const char *Pref, BumpPtrAllocator &DA)
Definition: DwarfDebug.h:251
int64_t getInt() const
Definition: DwarfDebug.h:135
void endFunction(const MachineFunction *MF)
Gather and emit post-function debug information.
SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
Definition: DwarfDebug.h:53
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:313
void setFrameIndex(int FI)
Definition: DwarfDebug.h:171
Collects and handles information specific to a particular collection of units.
Definition: DwarfDebug.h:221
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfDebug.h:673
const MDNode * getVariable() const
Definition: DwarfDebug.h:138
MDNode - a tuple of other values.
Definition: Metadata.h:69
StringRef getName() const
Definition: DwarfDebug.h:166
void endInstruction(const MachineInstr *MI)
Process end of an instruction.
bool isObjectPointer() const
Definition: DebugInfo.h:627
bool isLocation() const
Definition: DwarfDebug.h:131
MachineLocation getLoc() const
Definition: DwarfDebug.h:141
SymbolCU(CompileUnit *CU, const MCSymbol *Sym)
Definition: DwarfDebug.h:307
void emitAddresses(const MCSection *AddrSection)
Emit all of the addresses to the section given.
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
Definition: DwarfDebug.h:701
uint64_t getAddrElement(unsigned Idx) const
Definition: DebugInfo.h:647
unsigned getNumAddrElements() const
Definition: DebugInfo.cpp:139
bool isArtificial() const
Return true if DbgVariable is artificial.
Definition: DwarfDebug.h:180
This class is used to record source line correspondence.
Definition: DwarfDebug.h:47
const ConstantInt * getConstantInt() const
Definition: DwarfDebug.h:137
StringRef getName() const
Definition: DebugInfo.h:613
#define false
Definition: ConvertUTF.c:64
int getFrameIndex() const
Definition: DwarfDebug.h:170
DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Definition: DebugInfo.h:429
This class is used to track local variable information.
Definition: DwarfDebug.h:146
unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName, unsigned CUID)
Look up the source id with the given directory and source file names. If none currently exists...
Definition: DwarfDebug.cpp:677
unsigned getLine() const
Definition: DwarfDebug.h:57
DIVariable getVariable() const
Definition: DwarfDebug.h:161
bool isArtificial() const
isArtificial - Return true if this variable is marked as "artificial".
Definition: DebugInfo.h:623
bool hasComplexAddress() const
HasComplexAddr - Return true if the variable has a complex address.
Definition: DebugInfo.h:643
DIE * getDIE() const
Definition: DwarfDebug.h:163
DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
Definition: DwarfDebug.h:109
unsigned getDotDebugLocOffset() const
Definition: DwarfDebug.h:165
unsigned getSourceID() const
Definition: DwarfDebug.h:59
void Merge(DotDebugLocEntry *Next)
Definition: DwarfDebug.h:125
void addUnit(CompileUnit *CU)
Add a unit to the list of CUs.
Definition: DwarfDebug.h:268
#define P(N)
This struct describes location entries emitted in the .debug_loc section.
Definition: DwarfDebug.h:65
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
DIType getType() const
Definition: DwarfDebug.cpp:126
void assignAbbrevNumber(DIEAbbrev &Abbrev)
Define a unique number for the abbreviation.
Definition: DwarfDebug.cpp:275
MCSymbol * getLabel() const
Definition: DwarfDebug.h:60
unsigned getNumAddrElements() const
Definition: DwarfDebug.h:204
Definition: DIE.h:109
bool variableHasComplexAddress() const
Definition: DwarfDebug.h:196
const MCSymbol * getBeginSym() const
Definition: DwarfDebug.h:139
DwarfDebug(AsmPrinter *A, Module *M)
Definition: DwarfDebug.cpp:181
const MCSymbol * getEndSym() const
Definition: DwarfDebug.h:140
Helper used to pair up a symbol and its DWARF compile unit.
Definition: DwarfDebug.h:306
bool isObjectPointer() const
Definition: DebugInfo.h:310
An imported module (C++ using directive or similar).
Definition: DebugInfo.h:716
T resolve(const DITypeIdentifierMap &Map) const
Definition: DebugInfo.h:238
bool isInt() const
Definition: DwarfDebug.h:132
bool isConstantFP() const
Definition: DwarfDebug.h:133
Class for constant integers.
Definition: Constants.h:51
unsigned getColumn() const
Definition: DwarfDebug.h:58
unsigned getStringPoolIndex(StringRef Str)
Returns the index into the string pool with the given string text.
Definition: DwarfDebug.cpp:251
void beginModule()
Emit all Dwarf sections that should come prior to the content.
Definition: DwarfDebug.cpp:896
bool isSubprogramContext(const MDNode *Context)
Definition: DwarfDebug.cpp:355
T resolve(DIRef< T > Ref) const
Find the MDNode for the given reference.
Definition: DwarfDebug.h:730
void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection, const MCSymbol *StrSecSym)
Emit all of the strings to the section given.
StrPool * getStringPool()
Returns the string pool.
Definition: DwarfDebug.h:294
bool isConstantInt() const
Definition: DwarfDebug.h:134
const ConstantInt * CIP
Definition: DwarfDebug.h:82
uint64_t getAddrElement(unsigned i) const
Definition: DwarfDebug.h:208
MCSymbol * getStringPoolSym()
Returns the entry into the start of the pool.
Definition: DwarfDebug.cpp:238
void setDotDebugLocOffset(unsigned O)
Definition: DwarfDebug.h:164
void setDIE(DIE *D)
Definition: DwarfDebug.h:162
unsigned getAddrPoolIndex(const MCExpr *Sym)
Returns the index into the address pool with the given label/symbol.
Definition: DwarfDebug.cpp:265
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfDebug.h:670
MCSymbol * getStringPoolEntry(StringRef Str)
Returns an entry into the string pool with the given string text.
Definition: DwarfDebug.cpp:242
#define N
bool isEmpty()
Empty entries are also used as a trigger to emit temp label. Such labels are referenced is used to fi...
Definition: DwarfDebug.h:123
bool isBlockByrefVariable() const
Definition: DwarfDebug.h:200
bool useSplitDwarf()
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:724
void setMInsn(const MachineInstr *M)
Definition: DwarfDebug.h:169
DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L, const MDNode *V)
Definition: DwarfDebug.h:98
bool isObjectPointer() const
Definition: DwarfDebug.h:188
unsigned computeSizeAndOffset(DIE *Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
void beginInstruction(const MachineInstr *MI)
Process beginning of an instruction.
uint16_t getTag() const
Definition: DwarfDebug.h:173
void emitUnits(DwarfDebug *DD, const MCSection *USection, const MCSection *ASection, const MCSymbol *ASectionSym)
Emit all of the units to the section listed with the given abbreviation section.
DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
Definition: DwarfDebug.h:104
DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr)
Definition: DwarfDebug.h:114
DICompileUnit - A wrapper for a compile unit.
Definition: DebugInfo.h:402
const ConstantFP * getConstantFP() const
Definition: DwarfDebug.h:136
unsigned getDwarfVersion() const
Returns the Dwarf Version.
Definition: DwarfDebug.h:727
void addTypeUnitType(DIE *Die)
Add a DIE to the set of types that we're going to pull into type units.
Definition: DwarfDebug.h:698
void emitDIE(DIE *Die, ArrayRef< DIEAbbrev * > Abbrevs)
Recursively Emits a debug information entry.
void beginFunction(const MachineFunction *MF)
Gather pre-function debug information.
void setSymbolSize(const MCSymbol *Sym, uint64_t Size)
For symbols that have a size designated (e.g. common symbols), this tracks that size.
Definition: DwarfDebug.h:705
void endModule()
Emit all Dwarf sections that should come after the content.
const MCSymbol * Sym
Definition: DwarfDebug.h:308