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