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