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