LLVM  8.0.1
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 LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
16 
17 #include "AddressPool.h"
18 #include "DebugLocStream.h"
19 #include "DwarfFile.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/DenseSet.h"
23 #include "llvm/ADT/MapVector.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/SetVector.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/StringMap.h"
29 #include "llvm/ADT/StringRef.h"
36 #include "llvm/IR/DebugLoc.h"
37 #include "llvm/IR/Metadata.h"
38 #include "llvm/MC/MCDwarf.h"
39 #include "llvm/Support/Allocator.h"
41 #include <cassert>
42 #include <cstdint>
43 #include <limits>
44 #include <memory>
45 #include <utility>
46 #include <vector>
47 
48 namespace llvm {
49 
50 class AsmPrinter;
51 class ByteStreamer;
52 class DebugLocEntry;
53 class DIE;
54 class DwarfCompileUnit;
55 class DwarfTypeUnit;
56 class DwarfUnit;
57 class LexicalScope;
58 class MachineFunction;
59 class MCSection;
60 class MCSymbol;
61 class MDNode;
62 class Module;
63 
64 //===----------------------------------------------------------------------===//
65 /// This class is defined as the common parent of DbgVariable and DbgLabel
66 /// such that it could levarage polymorphism to extract common code for
67 /// DbgVariable and DbgLabel.
68 class DbgEntity {
69  const DINode *Entity;
70  const DILocation *InlinedAt;
71  DIE *TheDIE = nullptr;
72  unsigned SubclassID;
73 
74 public:
78  };
79 
80  DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)
81  : Entity(N), InlinedAt(IA), SubclassID(ID) {}
82  virtual ~DbgEntity() {}
83 
84  /// Accessors.
85  /// @{
86  const DINode *getEntity() const { return Entity; }
87  const DILocation *getInlinedAt() const { return InlinedAt; }
88  DIE *getDIE() const { return TheDIE; }
89  unsigned getDbgEntityID() const { return SubclassID; }
90  /// @}
91 
92  void setDIE(DIE &D) { TheDIE = &D; }
93 
94  static bool classof(const DbgEntity *N) {
95  switch (N->getDbgEntityID()) {
96  default:
97  return false;
98  case DbgVariableKind:
99  case DbgLabelKind:
100  return true;
101  }
102  }
103 };
104 
105 //===----------------------------------------------------------------------===//
106 /// This class is used to track local variable information.
107 ///
108 /// Variables can be created from allocas, in which case they're generated from
109 /// the MMI table. Such variables can have multiple expressions and frame
110 /// indices.
111 ///
112 /// Variables can be created from \c DBG_VALUE instructions. Those whose
113 /// location changes over time use \a DebugLocListIndex, while those with a
114 /// single instruction use \a MInsn and (optionally) a single entry of \a Expr.
115 ///
116 /// Variables that have been optimized out use none of these fields.
117 class DbgVariable : public DbgEntity {
118  unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs.
119  const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction.
120 
121  struct FrameIndexExpr {
122  int FI;
123  const DIExpression *Expr;
124  };
126  FrameIndexExprs; /// Frame index + expression.
127 
128 public:
129  /// Construct a DbgVariable.
130  ///
131  /// Creates a variable without any DW_AT_location. Call \a initializeMMI()
132  /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
134  : DbgEntity(V, IA, DbgVariableKind) {}
135 
136  /// Initialize from the MMI table.
137  void initializeMMI(const DIExpression *E, int FI) {
138  assert(FrameIndexExprs.empty() && "Already initialized?");
139  assert(!MInsn && "Already initialized?");
140 
141  assert((!E || E->isValid()) && "Expected valid expression");
142  assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
143 
144  FrameIndexExprs.push_back({FI, E});
145  }
146 
147  /// Initialize from a DBG_VALUE instruction.
148  void initializeDbgValue(const MachineInstr *DbgValue) {
149  assert(FrameIndexExprs.empty() && "Already initialized?");
150  assert(!MInsn && "Already initialized?");
151 
152  assert(getVariable() == DbgValue->getDebugVariable() && "Wrong variable");
153  assert(getInlinedAt() == DbgValue->getDebugLoc()->getInlinedAt() &&
154  "Wrong inlined-at");
155 
156  MInsn = DbgValue;
157  if (auto *E = DbgValue->getDebugExpression())
158  if (E->getNumElements())
159  FrameIndexExprs.push_back({0, E});
160  }
161 
162  // Accessors.
163  const DILocalVariable *getVariable() const {
164  return cast<DILocalVariable>(getEntity());
165  }
166 
168  assert(MInsn && FrameIndexExprs.size() <= 1);
169  return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;
170  }
171 
172  void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
173  unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
174  StringRef getName() const { return getVariable()->getName(); }
175  const MachineInstr *getMInsn() const { return MInsn; }
176  /// Get the FI entries, sorted by fragment offset.
177  ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;
178  bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
179  void addMMIEntry(const DbgVariable &V);
180 
181  // Translate tag to proper Dwarf tag.
182  dwarf::Tag getTag() const {
183  // FIXME: Why don't we just infer this tag and store it all along?
184  if (getVariable()->isParameter())
185  return dwarf::DW_TAG_formal_parameter;
186 
187  return dwarf::DW_TAG_variable;
188  }
189 
190  /// Return true if DbgVariable is artificial.
191  bool isArtificial() const {
192  if (getVariable()->isArtificial())
193  return true;
194  if (getType()->isArtificial())
195  return true;
196  return false;
197  }
198 
199  bool isObjectPointer() const {
200  if (getVariable()->isObjectPointer())
201  return true;
202  if (getType()->isObjectPointer())
203  return true;
204  return false;
205  }
206 
207  bool hasComplexAddress() const {
208  assert(MInsn && "Expected DBG_VALUE, not MMI variable");
209  assert((FrameIndexExprs.empty() ||
210  (FrameIndexExprs.size() == 1 &&
211  FrameIndexExprs[0].Expr->getNumElements())) &&
212  "Invalid Expr for DBG_VALUE");
213  return !FrameIndexExprs.empty();
214  }
215 
216  bool isBlockByrefVariable() const;
217  const DIType *getType() const;
218 
219  static bool classof(const DbgEntity *N) {
220  return N->getDbgEntityID() == DbgVariableKind;
221  }
222 
223 private:
224  template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
225  return Ref.resolve();
226  }
227 };
228 
229 //===----------------------------------------------------------------------===//
230 /// This class is used to track label information.
231 ///
232 /// Labels are collected from \c DBG_LABEL instructions.
233 class DbgLabel : public DbgEntity {
234  const MCSymbol *Sym; /// Symbol before DBG_LABEL instruction.
235 
236 public:
237  /// We need MCSymbol information to generate DW_AT_low_pc.
238  DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
239  : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
240 
241  /// Accessors.
242  /// @{
243  const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
244  const MCSymbol *getSymbol() const { return Sym; }
245 
246  StringRef getName() const { return getLabel()->getName(); }
247  /// @}
248 
249  /// Translate tag to proper Dwarf tag.
250  dwarf::Tag getTag() const {
251  return dwarf::DW_TAG_label;
252  }
253 
254  static bool classof(const DbgEntity *N) {
255  return N->getDbgEntityID() == DbgLabelKind;
256  }
257 
258 private:
259  template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
260  return Ref.resolve();
261  }
262 };
263 
264 /// Helper used to pair up a symbol and its DWARF compile unit.
265 struct SymbolCU {
266  SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
267 
268  const MCSymbol *Sym;
270 };
271 
272 /// The kind of accelerator tables we should emit.
273 enum class AccelTableKind {
274  Default, ///< Platform default.
275  None, ///< None.
276  Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
277  Dwarf, ///< DWARF v5 .debug_names.
278 };
279 
280 /// Collects and handles dwarf debug information.
281 class DwarfDebug : public DebugHandlerBase {
282  /// All DIEValues are allocated through this allocator.
283  BumpPtrAllocator DIEValueAllocator;
284 
285  /// Maps MDNode with its corresponding DwarfCompileUnit.
287 
288  /// Maps a CU DIE with its corresponding DwarfCompileUnit.
290 
291  /// List of all labels used in aranges generation.
292  std::vector<SymbolCU> ArangeLabels;
293 
294  /// Size of each symbol emitted (for those symbols that have a specific size).
296 
297  /// Collection of abstract variables/labels.
298  SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
299 
300  /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
301  /// can refer to them in spite of insertions into this list.
302  DebugLocStream DebugLocs;
303 
304  /// This is a collection of subprogram MDNodes that are processed to
305  /// create DIEs.
308  ProcessedSPNodes;
309 
310  /// If nonnull, stores the current machine function we're processing.
311  const MachineFunction *CurFn = nullptr;
312 
313  /// If nonnull, stores the CU in which the previous subprogram was contained.
314  const DwarfCompileUnit *PrevCU;
315 
316  /// As an optimization, there is no need to emit an entry in the directory
317  /// table for the same directory as DW_AT_comp_dir.
318  StringRef CompilationDir;
319 
320  /// Holder for the file specific debug information.
321  DwarfFile InfoHolder;
322 
323  /// Holders for the various debug information flags that we might need to
324  /// have exposed. See accessor functions below for description.
325 
326  /// Map from MDNodes for user-defined types to their type signatures. Also
327  /// used to keep track of which types we have emitted type units for.
328  DenseMap<const MDNode *, uint64_t> TypeSignatures;
329 
331 
332  SmallVector<
333  std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
334  TypeUnitsUnderConstruction;
335 
336  /// Whether to use the GNU TLS opcode (instead of the standard opcode).
337  bool UseGNUTLSOpcode;
338 
339  /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
340  bool UseDWARF2Bitfields;
341 
342  /// Whether to emit all linkage names, or just abstract subprograms.
343  bool UseAllLinkageNames;
344 
345  /// Use inlined strings.
346  bool UseInlineStrings = false;
347 
348  /// Allow emission of .debug_ranges section.
349  bool UseRangesSection = true;
350 
351  /// True if the sections itself must be used as references and don't create
352  /// temp symbols inside DWARF sections.
353  bool UseSectionsAsReferences = false;
354 
355  ///Allow emission of the .debug_loc section.
356  bool UseLocSection = true;
357 
358  /// Generate DWARF v4 type units.
359  bool GenerateTypeUnits;
360 
361  /// DWARF5 Experimental Options
362  /// @{
363  AccelTableKind TheAccelTableKind;
364  bool HasAppleExtensionAttributes;
365  bool HasSplitDwarf;
366 
367  /// Whether to generate the DWARF v5 string offsets table.
368  /// It consists of a series of contributions, each preceded by a header.
369  /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
370  /// a monolithic sequence of string offsets.
371  bool UseSegmentedStringOffsetsTable;
372 
373  /// Separated Dwarf Variables
374  /// In general these will all be for bits that are left in the
375  /// original object file, rather than things that are meant
376  /// to be in the .dwo sections.
377 
378  /// Holder for the skeleton information.
379  DwarfFile SkeletonHolder;
380 
381  /// Store file names for type units under fission in a line table
382  /// header that will be emitted into debug_line.dwo.
383  // FIXME: replace this with a map from comp_dir to table so that we
384  // can emit multiple tables during LTO each of which uses directory
385  // 0, referencing the comp_dir of all the type units that use it.
386  MCDwarfDwoLineTable SplitTypeUnitFileTable;
387  /// @}
388 
389  /// True iff there are multiple CUs in this module.
390  bool SingleCU;
391  bool IsDarwin;
392 
393  AddressPool AddrPool;
394 
395  /// Accelerator tables.
396  AccelTable<DWARF5AccelTableData> AccelDebugNames;
401 
402  // Identify a debugger for "tuning" the debug info.
403  DebuggerKind DebuggerTuning = DebuggerKind::Default;
404 
405  MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
406 
408  return InfoHolder.getUnits();
409  }
410 
411  using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
412 
413  void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
414  const DINode *Node,
415  const MDNode *Scope);
416  void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
417  const DINode *Node,
418  const MDNode *Scope);
419 
420  DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
421  LexicalScope &Scope,
422  const DINode *Node,
423  const DILocation *Location,
424  const MCSymbol *Sym = nullptr);
425 
426  /// Construct a DIE for this abstract scope.
427  void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
428 
429  /// Construct DIEs for call site entries describing the calls in \p MF.
430  void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
431  DIE &ScopeDIE, const MachineFunction &MF);
432 
433  template <typename DataT>
434  void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
435  StringRef Name, const DIE &Die);
436 
437  void finishEntityDefinitions();
438 
439  void finishSubprogramDefinitions();
440 
441  /// Finish off debug information after all functions have been
442  /// processed.
443  void finalizeModuleInfo();
444 
445  /// Emit the debug info section.
446  void emitDebugInfo();
447 
448  /// Emit the abbreviation section.
449  void emitAbbreviations();
450 
451  /// Emit the string offsets table header.
452  void emitStringOffsetsTableHeader();
453 
454  /// Emit a specified accelerator table.
455  template <typename AccelTableT>
456  void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
457 
458  /// Emit DWARF v5 accelerator table.
459  void emitAccelDebugNames();
460 
461  /// Emit visible names into a hashed accelerator table section.
462  void emitAccelNames();
463 
464  /// Emit objective C classes and categories into a hashed
465  /// accelerator table section.
466  void emitAccelObjC();
467 
468  /// Emit namespace dies into a hashed accelerator table.
469  void emitAccelNamespaces();
470 
471  /// Emit type dies into a hashed accelerator table.
472  void emitAccelTypes();
473 
474  /// Emit visible names and types into debug pubnames and pubtypes sections.
475  void emitDebugPubSections();
476 
477  void emitDebugPubSection(bool GnuStyle, StringRef Name,
478  DwarfCompileUnit *TheU,
479  const StringMap<const DIE *> &Globals);
480 
481  /// Emit null-terminated strings into a debug str section.
482  void emitDebugStr();
483 
484  /// Emit variable locations into a debug loc section.
485  void emitDebugLoc();
486 
487  /// Emit variable locations into a debug loc dwo section.
488  void emitDebugLocDWO();
489 
490  /// Emit address ranges into a debug aranges section.
491  void emitDebugARanges();
492 
493  /// Emit address ranges into a debug ranges section.
494  void emitDebugRanges();
495  void emitDebugRangesDWO();
496 
497  /// Emit macros into a debug macinfo section.
498  void emitDebugMacinfo();
499  void emitMacro(DIMacro &M);
500  void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
501  void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
502 
503  /// DWARF 5 Experimental Split Dwarf Emitters
504 
505  /// Initialize common features of skeleton units.
506  void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
507  std::unique_ptr<DwarfCompileUnit> NewU);
508 
509  /// Construct the split debug info compile unit for the debug info section.
510  /// In DWARF v5, the skeleton unit DIE may have the following attributes:
511  /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
512  /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
513  /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
514  /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
515  /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
516  DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
517 
518  /// Emit the debug info dwo section.
519  void emitDebugInfoDWO();
520 
521  /// Emit the debug abbrev dwo section.
522  void emitDebugAbbrevDWO();
523 
524  /// Emit the debug line dwo section.
525  void emitDebugLineDWO();
526 
527  /// Emit the dwo stringoffsets table header.
528  void emitStringOffsetsTableHeaderDWO();
529 
530  /// Emit the debug str dwo section.
531  void emitDebugStrDWO();
532 
533  /// Emit DWO addresses.
534  void emitDebugAddr();
535 
536  /// Flags to let the linker know we have emitted new style pubnames. Only
537  /// emit it here if we don't have a skeleton CU for split dwarf.
538  void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
539 
540  /// Create new DwarfCompileUnit for the given metadata node with tag
541  /// DW_TAG_compile_unit.
542  DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
543  void finishUnitAttributes(const DICompileUnit *DIUnit,
544  DwarfCompileUnit &NewCU);
545 
546  /// Construct imported_module or imported_declaration DIE.
547  void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
548  const DIImportedEntity *N);
549 
550  /// Register a source line with debug info. Returns the unique
551  /// label that was emitted and which provides correspondence to the
552  /// source line list.
553  void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
554  unsigned Flags);
555 
556  /// Populate LexicalScope entries with variables' info.
557  void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
558  DenseSet<InlinedEntity> &ProcessedVars);
559 
560  /// Build the location list for all DBG_VALUEs in the
561  /// function that describe the same variable.
562  void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
563  const DbgValueHistoryMap::InstrRanges &Ranges);
564 
565  /// Collect variable information from the side table maintained by MF.
566  void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
568 
569  /// Emit the reference to the section.
570  void emitSectionReference(const DwarfCompileUnit &CU);
571 
572 protected:
573  /// Gather pre-function debug information.
574  void beginFunctionImpl(const MachineFunction *MF) override;
575 
576  /// Gather and emit post-function debug information.
577  void endFunctionImpl(const MachineFunction *MF) override;
578 
579  void skippedNonDebugFunction() override;
580 
581 public:
582  //===--------------------------------------------------------------------===//
583  // Main entry points.
584  //
585  DwarfDebug(AsmPrinter *A, Module *M);
586 
587  ~DwarfDebug() override;
588 
589  /// Emit all Dwarf sections that should come prior to the
590  /// content.
591  void beginModule();
592 
593  /// Emit all Dwarf sections that should come after the content.
594  void endModule() override;
595 
596  /// Process beginning of an instruction.
597  void beginInstruction(const MachineInstr *MI) override;
598 
599  /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
600  static uint64_t makeTypeSignature(StringRef Identifier);
601 
602  /// Add a DIE to the set of types that we're going to pull into
603  /// type units.
604  void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
605  DIE &Die, const DICompositeType *CTy);
606 
607  /// Add a label so that arange data can be generated for it.
608  void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
609 
610  /// For symbols that have a size designated (e.g. common symbols),
611  /// this tracks that size.
612  void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
613  SymSize[Sym] = Size;
614  }
615 
616  /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
617  /// If not, we still might emit certain cases.
618  bool useAllLinkageNames() const { return UseAllLinkageNames; }
619 
620  /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
621  /// standard DW_OP_form_tls_address opcode
622  bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
623 
624  /// Returns whether to use the DWARF2 format for bitfields instyead of the
625  /// DWARF4 format.
626  bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
627 
628  /// Returns whether to use inline strings.
629  bool useInlineStrings() const { return UseInlineStrings; }
630 
631  /// Returns whether ranges section should be emitted.
632  bool useRangesSection() const { return UseRangesSection; }
633 
634  /// Returns whether to use sections as labels rather than temp symbols.
635  bool useSectionsAsReferences() const {
636  return UseSectionsAsReferences;
637  }
638 
639  /// Returns whether .debug_loc section should be emitted.
640  bool useLocSection() const { return UseLocSection; }
641 
642  /// Returns whether to generate DWARF v4 type units.
643  bool generateTypeUnits() const { return GenerateTypeUnits; }
644 
645  // Experimental DWARF5 features.
646 
647  /// Returns what kind (if any) of accelerator tables to emit.
648  AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
649 
651  return HasAppleExtensionAttributes;
652  }
653 
654  /// Returns whether or not to change the current debug info for the
655  /// split dwarf proposal support.
656  bool useSplitDwarf() const { return HasSplitDwarf; }
657 
658  /// Returns whether to generate a string offsets table with (possibly shared)
659  /// contributions from each CU and type unit. This implies the use of
660  /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
661  /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
662  /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
663  /// monolithic string offsets table.
665  return UseSegmentedStringOffsetsTable;
666  }
667 
668  bool shareAcrossDWOCUs() const;
669 
670  /// Returns the Dwarf Version.
671  uint16_t getDwarfVersion() const;
672 
673  /// Returns the previous CU that was being updated
674  const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
675  void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
676 
677  /// Returns the entries for the .debug_loc section.
678  const DebugLocStream &getDebugLocs() const { return DebugLocs; }
679 
680  /// Emit an entry for the debug loc section. This can be used to
681  /// handle an entry that's going to be emitted into the debug loc section.
682  void emitDebugLocEntry(ByteStreamer &Streamer,
683  const DebugLocStream::Entry &Entry);
684 
685  /// Emit the location for a debug loc entry, including the size header.
686  void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry);
687 
688  /// Find the MDNode for the given reference.
689  template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
690  return Ref.resolve();
691  }
692 
693  void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
694  DIE &Die);
695 
696  AddressPool &getAddressPool() { return AddrPool; }
697 
698  void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
699 
700  void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
701 
702  void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
703  const DIE &Die);
704 
705  void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
706  char Flags);
707 
708  const MachineFunction *getCurrentFunction() const { return CurFn; }
709 
710  /// A helper function to check whether the DIE for a given Scope is
711  /// going to be null.
712  bool isLexicalScopeDIENull(LexicalScope *Scope);
713 
714  /// Find the matching DwarfCompileUnit for the given CU DIE.
715  DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
716  const DwarfCompileUnit *lookupCU(const DIE *Die) const {
717  return CUDieMap.lookup(Die);
718  }
719 
720  /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
721  ///
722  /// Returns whether we are "tuning" for a given debugger.
723  /// @{
724  bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
725  bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
726  bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
727  /// @}
728 
729  void addSectionLabel(const MCSymbol *Sym);
730  const MCSymbol *getSectionLabel(const MCSection *S);
731 };
732 
733 } // end namespace llvm
734 
735 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
DIE * getDIE() const
Definition: DwarfDebug.h:88
void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override
For symbols that have a size designated (e.g.
Definition: DwarfDebug.h:612
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
unsigned getDebugLocListIndex() const
Definition: DwarfDebug.h:173
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:254
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
DWARF v5 .debug_names.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:250
void push_back(const T &Elt)
Definition: SmallVector.h:218
AccelTableKind getAccelTableKind() const
Returns what kind (if any) of accelerator tables to emit.
Definition: DwarfDebug.h:648
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:383
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:678
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:281
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
Definition: AccelTable.h:199
This file contains the declarations for metadata subclasses.
bool useGNUTLSOpcode() const
Returns whether to use DW_OP_GNU_push_tls_address, instead of the standard DW_OP_form_tls_address opc...
Definition: DwarfDebug.h:622
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition: DwarfDebug.h:68
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:38
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:864
F(f)
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:45
const MachineFunction * getCurrentFunction() const
Definition: DwarfDebug.h:708
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
Tagged DWARF-like metadata node.
DebuggerKind
Identify a debugger for "tuning" the debug info.
Definition: TargetOptions.h:92
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:656
void initializeDbgValue(const MachineInstr *DbgValue)
Initialize from a DBG_VALUE instruction.
Definition: DwarfDebug.h:148
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:219
const MCSymbol * getSymbol() const
Definition: DwarfDebug.h:244
amdgpu Simplify well known AMD library false Value Value const Twine & Name
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
Definition: DwarfDebug.h:608
bool isObjectPointer() const
Definition: DwarfDebug.h:199
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
The access may reference the value stored in memory.
Holds a subclass of DINode.
AccelTableKind
The kind of accelerator tables we should emit.
Definition: DwarfDebug.h:273
AddressPool & getAddressPool()
Definition: DwarfDebug.h:696
Subprogram description.
const DIExpression * getSingleExpression() const
Definition: DwarfDebug.h:167
This class is used to track local variable information.
Definition: DwarfDebug.h:117
const DILocalVariable * getVariable() const
Definition: DwarfDebug.h:163
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:121
const MachineInstr * getMInsn() const
Definition: DwarfDebug.h:175
Debug location.
const DwarfCompileUnit * getPrevCU() const
Returns the previous CU that was being updated.
Definition: DwarfDebug.h:674
bool hasComplexAddress() const
Definition: DwarfDebug.h:207
This class is used to track label information.
Definition: DwarfDebug.h:233
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:41
#define P(N)
DwarfCompileUnit * CU
Definition: DwarfDebug.h:269
bool tuneForLLDB() const
Definition: DwarfDebug.h:725
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A structured debug information entry.
Definition: DIE.h:662
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:79
void setDIE(DIE &D)
Definition: DwarfDebug.h:92
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
Definition: DwarfDebug.h:626
bool hasFrameIndexExprs() const
Definition: DwarfDebug.h:178
bool useSegmentedStringOffsetsTable() const
Returns whether to generate a string offsets table with (possibly shared) contributions from each CU ...
Definition: DwarfDebug.h:664
const DILabel * getLabel() const
Accessors.
Definition: DwarfDebug.h:243
dwarf::Tag getTag() const
Definition: DwarfDebug.h:182
T * resolve(TypedDINodeRef< T > Ref) const
Find the MDNode for the given reference.
Definition: DwarfDebug.h:689
Helper used to pair up a symbol and its DWARF compile unit.
Definition: DwarfDebug.h:265
void initializeMMI(const DIExpression *E, int FI)
Initialize from the MMI table.
Definition: DwarfDebug.h:137
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:618
size_t size() const
Definition: SmallVector.h:53
static wasm::ValType getType(const TargetRegisterClass *RC)
SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym)
Definition: DwarfDebug.h:266
const DILocation * getInlinedAt() const
Definition: DwarfDebug.h:87
std::pair< const DINode *, const DILocation * > InlinedEntity
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
An imported module (C++ using directive or similar).
bool useLocSection() const
Returns whether .debug_loc section should be emitted.
Definition: DwarfDebug.h:640
bool tuneForGDB() const
Definition: DwarfDebug.h:724
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
Definition: DwarfDebug.h:635
StringRef getName() const
Definition: DwarfDebug.h:246
void setPrevCU(const DwarfCompileUnit *PrevCU)
Definition: DwarfDebug.h:675
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
Base class for types.
DwarfCompileUnit * lookupCU(const DIE *Die)
Find the matching DwarfCompileUnit for the given CU DIE.
Definition: DwarfDebug.h:715
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:94
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:650
DWARF expression.
virtual ~DbgEntity()
Definition: DwarfDebug.h:82
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
This file contains constants used for implementing Dwarf debug support.
StringRef getName() const
Definition: DwarfDebug.h:174
const DwarfCompileUnit * lookupCU(const DIE *Die) const
Definition: DwarfDebug.h:716
dwarf::Tag getTag() const
Translate tag to proper Dwarf tag.
Definition: DwarfDebug.h:250
Representation of each machine instruction.
Definition: MachineInstr.h:64
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:56
bool useRangesSection() const
Returns whether ranges section should be emitted.
Definition: DwarfDebug.h:632
DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym=nullptr)
Symbol before DBG_LABEL instruction.
Definition: DwarfDebug.h:238
#define N
unsigned getDbgEntityID() const
Definition: DwarfDebug.h:89
Base class for debug information backends.
uint32_t Size
Definition: Profile.cpp:47
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:211
void setDebugLocListIndex(unsigned O)
Definition: DwarfDebug.h:172
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A vector that has set insertion semantics.
Definition: SetVector.h:41
const DILocalVariable * getDebugVariable() const
Return the debug variable referenced by this DBG_VALUE instruction.
unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
Return the slots used by the insn.
DbgVariable(const DILocalVariable *V, const DILocation *IA)
Frame index + expression.
Definition: DwarfDebug.h:133
const DINode * getEntity() const
Accessors.
Definition: DwarfDebug.h:86
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool tuneForSCE() const
Definition: DwarfDebug.h:726
Byte stream of .debug_loc entries.
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
Definition: DwarfDebug.h:643
bool isArtificial() const
Return true if DbgVariable is artificial.
Definition: DwarfDebug.h:191
DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)
Definition: DwarfDebug.h:80
bool useInlineStrings() const
Returns whether to use inline strings.
Definition: DwarfDebug.h:629
const MCSymbol * Sym
Definition: DwarfDebug.h:268