LLVM 18.0.0git
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 "DebugLocEntry.h"
18#include "DebugLocStream.h"
19#include "DwarfFile.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/DenseSet.h"
23#include "llvm/ADT/MapVector.h"
24#include "llvm/ADT/SetVector.h"
27#include "llvm/ADT/StringMap.h"
28#include "llvm/ADT/StringRef.h"
34#include "llvm/IR/DebugLoc.h"
35#include "llvm/IR/Metadata.h"
36#include "llvm/MC/MCDwarf.h"
39#include <cassert>
40#include <cstdint>
41#include <limits>
42#include <memory>
43#include <utility>
44#include <variant>
45#include <vector>
46
47namespace llvm {
48
49class AsmPrinter;
50class ByteStreamer;
51class DIE;
52class DwarfCompileUnit;
53class DwarfExpression;
54class DwarfTypeUnit;
55class DwarfUnit;
56class LexicalScope;
57class MachineFunction;
58class MCSection;
59class MCSymbol;
60class Module;
61
62//===----------------------------------------------------------------------===//
63/// This class is defined as the common parent of DbgVariable and DbgLabel
64/// such that it could levarage polymorphism to extract common code for
65/// DbgVariable and DbgLabel.
66class DbgEntity {
67public:
71 };
72
73private:
74 const DINode *Entity;
75 const DILocation *InlinedAt;
76 DIE *TheDIE = nullptr;
77 const DbgEntityKind SubclassID;
78
79public:
81 : Entity(N), InlinedAt(IA), SubclassID(ID) {}
82 virtual ~DbgEntity() = default;
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 DbgEntityKind 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 case DbgVariableKind:
97 case DbgLabelKind:
98 return true;
99 }
100 llvm_unreachable("Invalid DbgEntityKind");
101 }
102};
103
104class DbgVariable;
105
106/// Proxy for one MMI entry.
108 int FI;
110
111 /// Operator enabling sorting based on fragment offset.
112 friend bool operator<(const FrameIndexExpr &LHS, const FrameIndexExpr &RHS);
113};
114
115/// Represents an entry-value location, or a fragment of one.
119
120 /// Operator enabling sorting based on fragment offset.
121 friend bool operator<(const EntryValueInfo &LHS, const EntryValueInfo &RHS);
122};
123
124// Namespace for alternatives of a DbgVariable.
125namespace Loc {
126/// Single value location description.
127class Single {
128 std::unique_ptr<DbgValueLoc> ValueLoc;
129 const DIExpression *Expr;
130
131public:
132 explicit Single(DbgValueLoc ValueLoc);
133 explicit Single(const MachineInstr *DbgValue);
134 const DbgValueLoc &getValueLoc() const { return *ValueLoc; }
135 const DIExpression *getExpr() const { return Expr; }
136};
137/// Multi-value location description.
138class Multi {
139 /// Index of the entry list in DebugLocs.
140 unsigned DebugLocListIndex;
141 /// DW_OP_LLVM_tag_offset value from DebugLocs.
142 std::optional<uint8_t> DebugLocListTagOffset;
143
144public:
145 explicit Multi(unsigned DebugLocListIndex,
146 std::optional<uint8_t> DebugLocListTagOffset)
147 : DebugLocListIndex(DebugLocListIndex),
148 DebugLocListTagOffset(DebugLocListTagOffset) {}
149 unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
150 std::optional<uint8_t> getDebugLocListTagOffset() const {
151 return DebugLocListTagOffset;
152 }
153};
154/// Single location defined by (potentially multiple) MMI entries.
155struct MMI {
156 std::set<FrameIndexExpr> FrameIndexExprs;
157
158public:
159 explicit MMI(const DIExpression *E, int FI) : FrameIndexExprs({{FI, E}}) {
160 assert((!E || E->isValid()) && "Expected valid expression");
161 assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
162 }
163 void addFrameIndexExpr(const DIExpression *Expr, int FI);
164 /// Get the FI entries, sorted by fragment offset.
165 const std::set<FrameIndexExpr> &getFrameIndexExprs() const;
166};
167/// Single location defined by (potentially multiple) EntryValueInfo.
169 std::set<EntryValueInfo> EntryValues;
170 explicit EntryValue(MCRegister Reg, const DIExpression &Expr) {
171 addExpr(Reg, Expr);
172 };
173 // Add the pair Reg, Expr to the list of entry values describing the variable.
174 // If multiple expressions are added, it is the callers responsibility to
175 // ensure they are all non-overlapping fragments.
176 void addExpr(MCRegister Reg, const DIExpression &Expr) {
177 std::optional<const DIExpression *> NonVariadicExpr =
179 assert(NonVariadicExpr && *NonVariadicExpr);
180
181 EntryValues.insert({Reg, **NonVariadicExpr});
182 }
183};
184/// Alias for the std::variant specialization base class of DbgVariable.
185using Variant = std::variant<std::monostate, Loc::Single, Loc::Multi, Loc::MMI,
187} // namespace Loc
188
189//===----------------------------------------------------------------------===//
190/// This class is used to track local variable information.
191///
192/// Variables that have been optimized out hold the \c monostate alternative.
193/// This is not distinguished from the case of a constructed \c DbgVariable
194/// which has not be initialized yet.
195///
196/// Variables can be created from allocas, in which case they're generated from
197/// the MMI table. Such variables hold the \c Loc::MMI alternative which can
198/// have multiple expressions and frame indices.
199///
200/// Variables can be created from the entry value of registers, in which case
201/// they're generated from the MMI table. Such variables hold the \c
202/// EntryValueLoc alternative which can either have a single expression or
203/// multiple *fragment* expressions.
204///
205/// Variables can be created from \c DBG_VALUE instructions. Those whose
206/// location changes over time hold a \c Loc::Multi alternative which uses \c
207/// DebugLocListIndex and (optionally) \c DebugLocListTagOffset, while those
208/// with a single location hold a \c Loc::Single alternative which use \c
209/// ValueLoc and (optionally) a single \c Expr.
210class DbgVariable : public DbgEntity, public Loc::Variant {
211
212public:
213 /// To workaround P2162R0 https://github.com/cplusplus/papers/issues/873 the
214 /// base class subobject needs to be passed directly to std::visit, so expose
215 /// it directly here.
216 Loc::Variant &asVariant() { return *static_cast<Loc::Variant *>(this); }
217 const Loc::Variant &asVariant() const {
218 return *static_cast<const Loc::Variant *>(this);
219 }
220 /// Member shorthand for std::holds_alternative
221 template <typename T> bool holds() const {
222 return std::holds_alternative<T>(*this);
223 }
224 /// Asserting, noexcept member alternative to std::get
225 template <typename T> auto &get() noexcept {
226 assert(holds<T>());
227 return *std::get_if<T>(this);
228 }
229 /// Asserting, noexcept member alternative to std::get
230 template <typename T> const auto &get() const noexcept {
231 assert(holds<T>());
232 return *std::get_if<T>(this);
233 }
234
235 /// Construct a DbgVariable.
236 ///
237 /// Creates a variable without any DW_AT_location.
239 : DbgEntity(V, IA, DbgVariableKind) {}
240
241 // Accessors.
243 return cast<DILocalVariable>(getEntity());
244 }
245
246 StringRef getName() const { return getVariable()->getName(); }
247
248 // Translate tag to proper Dwarf tag.
250 // FIXME: Why don't we just infer this tag and store it all along?
251 if (getVariable()->isParameter())
252 return dwarf::DW_TAG_formal_parameter;
253
254 return dwarf::DW_TAG_variable;
255 }
256
257 /// Return true if DbgVariable is artificial.
258 bool isArtificial() const {
259 if (getVariable()->isArtificial())
260 return true;
261 if (getType()->isArtificial())
262 return true;
263 return false;
264 }
265
266 bool isObjectPointer() const {
268 return true;
269 if (getType()->isObjectPointer())
270 return true;
271 return false;
272 }
273
274 const DIType *getType() const;
275
276 static bool classof(const DbgEntity *N) {
277 return N->getDbgEntityID() == DbgVariableKind;
278 }
279};
280
281//===----------------------------------------------------------------------===//
282/// This class is used to track label information.
283///
284/// Labels are collected from \c DBG_LABEL instructions.
285class DbgLabel : public DbgEntity {
286 const MCSymbol *Sym; /// Symbol before DBG_LABEL instruction.
287
288public:
289 /// We need MCSymbol information to generate DW_AT_low_pc.
290 DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
291 : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
292
293 /// Accessors.
294 /// @{
295 const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
296 const MCSymbol *getSymbol() const { return Sym; }
297
298 StringRef getName() const { return getLabel()->getName(); }
299 /// @}
300
301 /// Translate tag to proper Dwarf tag.
303 return dwarf::DW_TAG_label;
304 }
305
306 static bool classof(const DbgEntity *N) {
307 return N->getDbgEntityID() == DbgLabelKind;
308 }
309};
310
311/// Used for tracking debug info about call site parameters.
313private:
314 unsigned Register; ///< Parameter register at the callee entry point.
315 DbgValueLoc Value; ///< Corresponding location for the parameter value at
316 ///< the call site.
317public:
319 : Register(Reg), Value(Val) {
320 assert(Reg && "Parameter register cannot be undef");
321 }
322
323 unsigned getRegister() const { return Register; }
324 DbgValueLoc getValue() const { return Value; }
325};
326
327/// Collection used for storing debug call site parameters.
329
330/// Helper used to pair up a symbol and its DWARF compile unit.
331struct SymbolCU {
333
334 const MCSymbol *Sym;
336};
337
338/// The kind of accelerator tables we should emit.
339enum class AccelTableKind {
340 Default, ///< Platform default.
341 None, ///< None.
342 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
343 Dwarf, ///< DWARF v5 .debug_names.
344};
345
346/// Collects and handles dwarf debug information.
348 /// All DIEValues are allocated through this allocator.
349 BumpPtrAllocator DIEValueAllocator;
350
351 /// Maps MDNode with its corresponding DwarfCompileUnit.
353
354 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
356
357 /// List of all labels used in aranges generation.
358 std::vector<SymbolCU> ArangeLabels;
359
360 /// Size of each symbol emitted (for those symbols that have a specific size).
362
363 /// Collection of abstract variables/labels.
364 SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
365
366 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
367 /// can refer to them in spite of insertions into this list.
368 DebugLocStream DebugLocs;
369
370 /// This is a collection of subprogram MDNodes that are processed to
371 /// create DIEs.
373
374 /// Map function-local imported entities to their parent local scope
375 /// (either DILexicalBlock or DISubprogram) for a processed function
376 /// (including inlined subprograms).
380
381 /// If nonnull, stores the current machine function we're processing.
382 const MachineFunction *CurFn = nullptr;
383
384 /// If nonnull, stores the CU in which the previous subprogram was contained.
385 const DwarfCompileUnit *PrevCU = nullptr;
386
387 /// As an optimization, there is no need to emit an entry in the directory
388 /// table for the same directory as DW_AT_comp_dir.
389 StringRef CompilationDir;
390
391 /// Holder for the file specific debug information.
392 DwarfFile InfoHolder;
393
394 /// Holders for the various debug information flags that we might need to
395 /// have exposed. See accessor functions below for description.
396
397 /// Map from MDNodes for user-defined types to their type signatures. Also
398 /// used to keep track of which types we have emitted type units for.
400
402
404 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
405 TypeUnitsUnderConstruction;
406
407 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
408 bool UseGNUTLSOpcode;
409
410 /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
411 bool UseDWARF2Bitfields;
412
413 /// Whether to emit all linkage names, or just abstract subprograms.
414 bool UseAllLinkageNames;
415
416 /// Use inlined strings.
417 bool UseInlineStrings = false;
418
419 /// Allow emission of .debug_ranges section.
420 bool UseRangesSection = true;
421
422 /// True if the sections itself must be used as references and don't create
423 /// temp symbols inside DWARF sections.
424 bool UseSectionsAsReferences = false;
425
426 ///Allow emission of the .debug_loc section.
427 bool UseLocSection = true;
428
429 /// Generate DWARF v4 type units.
430 bool GenerateTypeUnits;
431
432 /// Emit a .debug_macro section instead of .debug_macinfo.
433 bool UseDebugMacroSection;
434
435 /// Avoid using DW_OP_convert due to consumer incompatibilities.
436 bool EnableOpConvert;
437
438public:
439 enum class MinimizeAddrInV5 {
440 Default,
441 Disabled,
442 Ranges,
444 Form,
445 };
446
447private:
448 /// Force the use of DW_AT_ranges even for single-entry range lists.
450
451 /// DWARF5 Experimental Options
452 /// @{
453 AccelTableKind TheAccelTableKind;
454 bool HasAppleExtensionAttributes;
455 bool HasSplitDwarf;
456
457 /// Whether to generate the DWARF v5 string offsets table.
458 /// It consists of a series of contributions, each preceded by a header.
459 /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
460 /// a monolithic sequence of string offsets.
461 bool UseSegmentedStringOffsetsTable;
462
463 /// Enable production of call site parameters needed to print the debug entry
464 /// values. Useful for testing purposes when a debugger does not support the
465 /// feature yet.
466 bool EmitDebugEntryValues;
467
468 /// Separated Dwarf Variables
469 /// In general these will all be for bits that are left in the
470 /// original object file, rather than things that are meant
471 /// to be in the .dwo sections.
472
473 /// Holder for the skeleton information.
474 DwarfFile SkeletonHolder;
475
476 /// Store file names for type units under fission in a line table
477 /// header that will be emitted into debug_line.dwo.
478 // FIXME: replace this with a map from comp_dir to table so that we
479 // can emit multiple tables during LTO each of which uses directory
480 // 0, referencing the comp_dir of all the type units that use it.
481 MCDwarfDwoLineTable SplitTypeUnitFileTable;
482 /// @}
483
484 /// True iff there are multiple CUs in this module.
485 bool SingleCU;
486 bool IsDarwin;
487
488 /// Map for tracking Fortran deferred CHARACTER lengths.
490
491 AddressPool AddrPool;
492
493 /// Accelerator tables.
494 AccelTable<DWARF5AccelTableData> AccelDebugNames;
499
500 /// Identify a debugger for "tuning" the debug info.
501 ///
502 /// The "tuning" should be used to set defaults for individual feature flags
503 /// in DwarfDebug; if a given feature has a more specific command-line option,
504 /// that option should take precedence over the tuning.
505 DebuggerKind DebuggerTuning = DebuggerKind::Default;
506
507 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
508
510 return InfoHolder.getUnits();
511 }
512
513 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
514
515 void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
516 const DINode *Node,
517 const MDNode *Scope);
518
519 DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
520 LexicalScope &Scope,
521 const DINode *Node,
522 const DILocation *Location,
523 const MCSymbol *Sym = nullptr);
524
525 /// Construct a DIE for this abstract scope.
526 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
527
528 /// Construct DIEs for call site entries describing the calls in \p MF.
529 void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
530 DIE &ScopeDIE, const MachineFunction &MF);
531
532 template <typename DataT>
533 void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
534 StringRef Name, const DIE &Die);
535
536 void finishEntityDefinitions();
537
538 void finishSubprogramDefinitions();
539
540 /// Finish off debug information after all functions have been
541 /// processed.
542 void finalizeModuleInfo();
543
544 /// Emit the debug info section.
545 void emitDebugInfo();
546
547 /// Emit the abbreviation section.
548 void emitAbbreviations();
549
550 /// Emit the string offsets table header.
551 void emitStringOffsetsTableHeader();
552
553 /// Emit a specified accelerator table.
554 template <typename AccelTableT>
555 void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
556
557 /// Emit DWARF v5 accelerator table.
558 void emitAccelDebugNames();
559
560 /// Emit visible names into a hashed accelerator table section.
561 void emitAccelNames();
562
563 /// Emit objective C classes and categories into a hashed
564 /// accelerator table section.
565 void emitAccelObjC();
566
567 /// Emit namespace dies into a hashed accelerator table.
568 void emitAccelNamespaces();
569
570 /// Emit type dies into a hashed accelerator table.
571 void emitAccelTypes();
572
573 /// Emit visible names and types into debug pubnames and pubtypes sections.
574 void emitDebugPubSections();
575
576 void emitDebugPubSection(bool GnuStyle, StringRef Name,
577 DwarfCompileUnit *TheU,
578 const StringMap<const DIE *> &Globals);
579
580 /// Emit null-terminated strings into a debug str section.
581 void emitDebugStr();
582
583 /// Emit variable locations into a debug loc section.
584 void emitDebugLoc();
585
586 /// Emit variable locations into a debug loc dwo section.
587 void emitDebugLocDWO();
588
589 void emitDebugLocImpl(MCSection *Sec);
590
591 /// Emit address ranges into a debug aranges section.
592 void emitDebugARanges();
593
594 /// Emit address ranges into a debug ranges section.
595 void emitDebugRanges();
596 void emitDebugRangesDWO();
597 void emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section);
598
599 /// Emit macros into a debug macinfo section.
600 void emitDebugMacinfo();
601 /// Emit macros into a debug macinfo.dwo section.
602 void emitDebugMacinfoDWO();
603 void emitDebugMacinfoImpl(MCSection *Section);
604 void emitMacro(DIMacro &M);
605 void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
606 void emitMacroFileImpl(DIMacroFile &F, DwarfCompileUnit &U,
607 unsigned StartFile, unsigned EndFile,
608 StringRef (*MacroFormToString)(unsigned Form));
609 void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
610
611 /// DWARF 5 Experimental Split Dwarf Emitters
612
613 /// Initialize common features of skeleton units.
614 void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
615 std::unique_ptr<DwarfCompileUnit> NewU);
616
617 /// Construct the split debug info compile unit for the debug info section.
618 /// In DWARF v5, the skeleton unit DIE may have the following attributes:
619 /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
620 /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
621 /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
622 /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
623 /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
624 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
625
626 /// Emit the debug info dwo section.
627 void emitDebugInfoDWO();
628
629 /// Emit the debug abbrev dwo section.
630 void emitDebugAbbrevDWO();
631
632 /// Emit the debug line dwo section.
633 void emitDebugLineDWO();
634
635 /// Emit the dwo stringoffsets table header.
636 void emitStringOffsetsTableHeaderDWO();
637
638 /// Emit the debug str dwo section.
639 void emitDebugStrDWO();
640
641 /// Emit DWO addresses.
642 void emitDebugAddr();
643
644 /// Flags to let the linker know we have emitted new style pubnames. Only
645 /// emit it here if we don't have a skeleton CU for split dwarf.
646 void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
647
648 /// Create new DwarfCompileUnit for the given metadata node with tag
649 /// DW_TAG_compile_unit.
650 DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
651 void finishUnitAttributes(const DICompileUnit *DIUnit,
652 DwarfCompileUnit &NewCU);
653
654 /// Register a source line with debug info. Returns the unique
655 /// label that was emitted and which provides correspondence to the
656 /// source line list.
657 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
658 unsigned Flags);
659
660 /// Populate LexicalScope entries with variables' info.
661 void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
662 DenseSet<InlinedEntity> &ProcessedVars);
663
664 /// Build the location list for all DBG_VALUEs in the
665 /// function that describe the same variable. If the resulting
666 /// list has only one entry that is valid for entire variable's
667 /// scope return true.
668 bool buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
669 const DbgValueHistoryMap::Entries &Entries);
670
671 /// Collect variable information from the side table maintained by MF.
672 void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
673 DenseSet<InlinedEntity> &P);
674
675 /// Emit the reference to the section.
676 void emitSectionReference(const DwarfCompileUnit &CU);
677
678protected:
679 /// Gather pre-function debug information.
680 void beginFunctionImpl(const MachineFunction *MF) override;
681
682 /// Gather and emit post-function debug information.
683 void endFunctionImpl(const MachineFunction *MF) override;
684
685 /// Get Dwarf compile unit ID for line table.
686 unsigned getDwarfCompileUnitIDForLineTable(const DwarfCompileUnit &CU);
687
688 void skippedNonDebugFunction() override;
689
690public:
691 //===--------------------------------------------------------------------===//
692 // Main entry points.
693 //
694 DwarfDebug(AsmPrinter *A);
695
696 ~DwarfDebug() override;
697
698 /// Emit all Dwarf sections that should come prior to the
699 /// content.
700 void beginModule(Module *M) override;
701
702 /// Emit all Dwarf sections that should come after the content.
703 void endModule() override;
704
705 /// Emits inital debug location directive.
706 DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
707
708 /// Process beginning of an instruction.
709 void beginInstruction(const MachineInstr *MI) override;
710
711 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
712 static uint64_t makeTypeSignature(StringRef Identifier);
713
714 /// Add a DIE to the set of types that we're going to pull into
715 /// type units.
717 DIE &Die, const DICompositeType *CTy);
718
719 /// Add a label so that arange data can be generated for it.
720 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
721
722 /// For symbols that have a size designated (e.g. common symbols),
723 /// this tracks that size.
724 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
725 SymSize[Sym] = Size;
726 }
727
728 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
729 /// If not, we still might emit certain cases.
730 bool useAllLinkageNames() const { return UseAllLinkageNames; }
731
732 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
733 /// standard DW_OP_form_tls_address opcode
734 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
735
736 /// Returns whether to use the DWARF2 format for bitfields instyead of the
737 /// DWARF4 format.
738 bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
739
740 /// Returns whether to use inline strings.
741 bool useInlineStrings() const { return UseInlineStrings; }
742
743 /// Returns whether ranges section should be emitted.
744 bool useRangesSection() const { return UseRangesSection; }
745
746 /// Returns whether range encodings should be used for single entry range
747 /// lists.
748 bool alwaysUseRanges(const DwarfCompileUnit &) const;
749
750 // Returns whether novel exprloc addrx+offset encodings should be used to
751 // reduce debug_addr size.
753 return MinimizeAddr == MinimizeAddrInV5::Expressions;
754 }
755
756 // Returns whether addrx+offset LLVM extension form should be used to reduce
757 // debug_addr size.
758 bool useAddrOffsetForm() const {
759 return MinimizeAddr == MinimizeAddrInV5::Form;
760 }
761
762 /// Returns whether to use sections as labels rather than temp symbols.
764 return UseSectionsAsReferences;
765 }
766
767 /// Returns whether .debug_loc section should be emitted.
768 bool useLocSection() const { return UseLocSection; }
769
770 /// Returns whether to generate DWARF v4 type units.
771 bool generateTypeUnits() const { return GenerateTypeUnits; }
772
773 // Experimental DWARF5 features.
774
775 /// Returns what kind (if any) of accelerator tables to emit.
776 AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
777
779 return HasAppleExtensionAttributes;
780 }
781
782 /// Returns whether or not to change the current debug info for the
783 /// split dwarf proposal support.
784 bool useSplitDwarf() const { return HasSplitDwarf; }
785
786 /// Returns whether to generate a string offsets table with (possibly shared)
787 /// contributions from each CU and type unit. This implies the use of
788 /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
789 /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
790 /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
791 /// monolithic string offsets table.
793 return UseSegmentedStringOffsetsTable;
794 }
795
796 bool emitDebugEntryValues() const {
797 return EmitDebugEntryValues;
798 }
799
800 bool useOpConvert() const {
801 return EnableOpConvert;
802 }
803
804 bool shareAcrossDWOCUs() const;
805
806 /// Returns the Dwarf Version.
808
809 /// Returns a suitable DWARF form to represent a section offset, i.e.
810 /// * DW_FORM_sec_offset for DWARF version >= 4;
811 /// * DW_FORM_data8 for 64-bit DWARFv3;
812 /// * DW_FORM_data4 for 32-bit DWARFv3 and DWARFv2.
814
815 /// Returns the previous CU that was being updated
816 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
817 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
818
819 /// Terminate the line table by adding the last range label.
821
822 /// Returns the entries for the .debug_loc section.
823 const DebugLocStream &getDebugLocs() const { return DebugLocs; }
824
825 /// Emit an entry for the debug loc section. This can be used to
826 /// handle an entry that's going to be emitted into the debug loc section.
827 void emitDebugLocEntry(ByteStreamer &Streamer,
828 const DebugLocStream::Entry &Entry,
829 const DwarfCompileUnit *CU);
830
831 /// Emit the location for a debug loc entry, including the size header.
833 const DwarfCompileUnit *CU);
834
835 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
836 DIE &Die);
837
838 AddressPool &getAddressPool() { return AddrPool; }
839
840 void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
841
842 void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
843
845 const DIE &Die);
846
847 void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
848 char Flags);
849
850 const MachineFunction *getCurrentFunction() const { return CurFn; }
851
852 /// A helper function to check whether the DIE for a given Scope is
853 /// going to be null.
855
856 /// Find the matching DwarfCompileUnit for the given CU DIE.
857 DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
858 const DwarfCompileUnit *lookupCU(const DIE *Die) const {
859 return CUDieMap.lookup(Die);
860 }
861
862 unsigned getStringTypeLoc(const DIStringType *ST) const {
863 return StringTypeLocMap.lookup(ST);
864 }
865
866 void addStringTypeLoc(const DIStringType *ST, unsigned Loc) {
867 assert(ST);
868 if (Loc)
869 StringTypeLocMap[ST] = Loc;
870 }
871
872 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
873 ///
874 /// Returns whether we are "tuning" for a given debugger.
875 /// @{
876 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
877 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
878 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
879 bool tuneForDBX() const { return DebuggerTuning == DebuggerKind::DBX; }
880 /// @}
881
882 const MCSymbol *getSectionLabel(const MCSection *S);
883 void insertSectionLabel(const MCSymbol *S);
884
885 static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
886 const DbgValueLoc &Value,
887 DwarfExpression &DwarfExpr);
888
889 /// If the \p File has an MD5 checksum, return it as an MD5Result
890 /// allocated in the MCContext.
891 std::optional<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const;
892
894 return LocalDeclsPerLS[S];
895 }
896};
897
898} // end namespace llvm
899
900#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
aarch64 promote const
This file defines the StringMap class.
This file contains support for writing accelerator tables.
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:468
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
unsigned Reg
This file implements a map that provides insertion order iteration.
This file contains the declarations for metadata subclasses.
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Value * RHS
Value * LHS
Class recording the (high level) value of a variable.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
Definition: AccelTable.h:193
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:85
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
Basic type, like 'int' or 'float'.
A structured debug information entry.
Definition: DIE.h:819
DWARF expression.
static std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
StringRef getName() const
A scope for locals.
Debug location.
Tagged DWARF-like metadata node.
String type, Fortran CHARACTER(n)
Subprogram description.
Base class for types.
StringRef getName() const
Used for tracking debug info about call site parameters.
Definition: DwarfDebug.h:312
unsigned getRegister() const
Definition: DwarfDebug.h:323
DbgCallSiteParam(unsigned Reg, DbgValueLoc Val)
Definition: DwarfDebug.h:318
DbgValueLoc getValue() const
Definition: DwarfDebug.h:324
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition: DwarfDebug.h:66
virtual ~DbgEntity()=default
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:94
const DINode * getEntity() const
Accessors.
Definition: DwarfDebug.h:86
DbgEntityKind getDbgEntityID() const
Definition: DwarfDebug.h:89
void setDIE(DIE &D)
Definition: DwarfDebug.h:92
DIE * getDIE() const
Definition: DwarfDebug.h:88
DbgEntity(const DINode *N, const DILocation *IA, DbgEntityKind ID)
Definition: DwarfDebug.h:80
const DILocation * getInlinedAt() const
Definition: DwarfDebug.h:87
This class is used to track label information.
Definition: DwarfDebug.h:285
dwarf::Tag getTag() const
Translate tag to proper Dwarf tag.
Definition: DwarfDebug.h:302
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:306
DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym=nullptr)
Symbol before DBG_LABEL instruction.
Definition: DwarfDebug.h:290
StringRef getName() const
Definition: DwarfDebug.h:298
const MCSymbol * getSymbol() const
Definition: DwarfDebug.h:296
const DILabel * getLabel() const
Accessors.
Definition: DwarfDebug.h:295
SmallVector< Entry, 4 > Entries
std::pair< const DINode *, const DILocation * > InlinedEntity
The location of a single variable, composed of an expression and 0 or more DbgValueLocEntries.
This class is used to track local variable information.
Definition: DwarfDebug.h:210
const Loc::Variant & asVariant() const
Definition: DwarfDebug.h:217
bool isArtificial() const
Return true if DbgVariable is artificial.
Definition: DwarfDebug.h:258
dwarf::Tag getTag() const
Definition: DwarfDebug.h:249
bool isObjectPointer() const
Definition: DwarfDebug.h:266
const DILocalVariable * getVariable() const
Definition: DwarfDebug.h:242
DbgVariable(const DILocalVariable *V, const DILocation *IA)
Construct a DbgVariable.
Definition: DwarfDebug.h:238
auto & get() noexcept
Asserting, noexcept member alternative to std::get.
Definition: DwarfDebug.h:225
StringRef getName() const
Definition: DwarfDebug.h:246
const DIType * getType() const
Definition: DwarfDebug.cpp:230
const auto & get() const noexcept
Asserting, noexcept member alternative to std::get.
Definition: DwarfDebug.h:230
Loc::Variant & asVariant()
To workaround P2162R0 https://github.com/cplusplus/papers/issues/873 the base class subobject needs t...
Definition: DwarfDebug.h:216
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:276
bool holds() const
Member shorthand for std::holds_alternative.
Definition: DwarfDebug.h:221
Base class for debug information backends.
Byte stream of .debug_loc entries.
A debug info location.
Definition: DebugLoc.h:33
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:202
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:347
bool useSegmentedStringOffsetsTable() const
Returns whether to generate a string offsets table with (possibly shared) contributions from each CU ...
Definition: DwarfDebug.h:792
MDNodeSet & getLocalDeclsForScope(const DILocalScope *S)
Definition: DwarfDebug.h:893
std::optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
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:734
bool useAddrOffsetForm() const
Definition: DwarfDebug.h:758
const DwarfCompileUnit * getPrevCU() const
Returns the previous CU that was being updated.
Definition: DwarfDebug.h:816
void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override
For symbols that have a size designated (e.g.
Definition: DwarfDebug.h:724
bool emitDebugEntryValues() const
Definition: DwarfDebug.h:796
const DwarfCompileUnit * lookupCU(const DIE *Die) const
Definition: DwarfDebug.h:858
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocStream::Entry &Entry, const DwarfCompileUnit *CU)
Emit an entry for the debug loc section.
bool alwaysUseRanges(const DwarfCompileUnit &) const
Returns whether range encodings should be used for single entry range lists.
void beginModule(Module *M) override
Emit all Dwarf sections that should come prior to the content.
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:730
void insertSectionLabel(const MCSymbol *S)
void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP, DIE &Die)
Definition: DwarfDebug.cpp:475
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:778
void setPrevCU(const DwarfCompileUnit *PrevCU)
Definition: DwarfDebug.h:817
const MachineFunction * getCurrentFunction() const
Definition: DwarfDebug.h:850
void skippedNonDebugFunction() override
bool useInlineStrings() const
Returns whether to use inline strings.
Definition: DwarfDebug.h:741
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
Definition: DwarfDebug.h:720
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
Definition: DwarfDebug.h:771
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
AddressPool & getAddressPool()
Definition: DwarfDebug.h:838
void addAccelNamespace(const DICompileUnit &CU, StringRef Name, const DIE &Die)
void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die, char Flags)
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
Definition: DwarfDebug.h:763
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:823
bool shareAcrossDWOCUs() const
Definition: DwarfDebug.cpp:534
bool useOpConvert() const
Definition: DwarfDebug.h:800
void terminateLineTable(const DwarfCompileUnit *CU)
Terminate the line table by adding the last range label.
~DwarfDebug() override
void endFunctionImpl(const MachineFunction *MF) override
Gather and emit post-function debug information.
void addStringTypeLoc(const DIStringType *ST, unsigned Loc)
Definition: DwarfDebug.h:866
void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry, const DwarfCompileUnit *CU)
Emit the location for a debug loc entry, including the size header.
void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die)
DwarfCompileUnit * lookupCU(const DIE *Die)
Find the matching DwarfCompileUnit for the given CU DIE.
Definition: DwarfDebug.h:857
const MCSymbol * getSectionLabel(const MCSection *S)
static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT, const DbgValueLoc &Value, DwarfExpression &DwarfExpr)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition: DwarfDebug.h:784
bool useLocSection() const
Returns whether .debug_loc section should be emitted.
Definition: DwarfDebug.h:768
unsigned getDwarfCompileUnitIDForLineTable(const DwarfCompileUnit &CU)
Get Dwarf compile unit ID for line table.
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
Definition: DwarfDebug.h:738
DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID)
Emits inital debug location directive.
bool useAddrOffsetExpressions() const
Definition: DwarfDebug.h:752
bool useRangesSection() const
Returns whether ranges section should be emitted.
Definition: DwarfDebug.h:744
unsigned getStringTypeLoc(const DIStringType *ST) const
Definition: DwarfDebug.h:862
bool isLexicalScopeDIENull(LexicalScope *Scope)
A helper function to check whether the DIE for a given Scope is going to be null.
Definition: DwarfDebug.cpp:510
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, DIE &Die, const DICompositeType *CTy)
Add a DIE to the set of types that we're going to pull into type units.
void endModule() override
Emit all Dwarf sections that should come after the content.
void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die)
void beginFunctionImpl(const MachineFunction *MF) override
Gather pre-function debug information.
AccelTableKind getAccelTableKind() const
Returns what kind (if any) of accelerator tables to emit.
Definition: DwarfDebug.h:776
static uint64_t makeTypeSignature(StringRef Identifier)
Perform an MD5 checksum of Identifier and return the lower 64 bits.
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:102
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:44
Multi-value location description.
Definition: DwarfDebug.h:138
Multi(unsigned DebugLocListIndex, std::optional< uint8_t > DebugLocListTagOffset)
Definition: DwarfDebug.h:145
unsigned getDebugLocListIndex() const
Definition: DwarfDebug.h:149
std::optional< uint8_t > getDebugLocListTagOffset() const
Definition: DwarfDebug.h:150
Single value location description.
Definition: DwarfDebug.h:127
const DbgValueLoc & getValueLoc() const
Definition: DwarfDebug.h:134
const DIExpression * getExpr() const
Definition: DwarfDebug.h:135
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Representation of each machine instruction.
Definition: MachineInstr.h:68
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
A vector that has set insertion semantics.
Definition: SetVector.h:57
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:451
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:370
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
bool tuneForSCE() const
Definition: DwarfDebug.h:878
bool tuneForDBX() const
Definition: DwarfDebug.h:879
bool tuneForGDB() const
Definition: DwarfDebug.h:876
bool tuneForLLDB() const
Definition: DwarfDebug.h:877
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::variant< std::monostate, Loc::Single, Loc::Multi, Loc::MMI, Loc::EntryValue > Variant
Alias for the std::variant specialization base class of DbgVariable.
Definition: DwarfDebug.h:186
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AccelTableKind
The kind of accelerator tables we should emit.
Definition: DwarfDebug.h:339
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
@ Dwarf
DWARF v5 .debug_names.
@ None
Not a recurrence.
DebuggerKind
Identify a debugger for "tuning" the debug info.
Definition: TargetOptions.h:97
@ SCE
Tune debug info for SCE targets (e.g. PS4).
@ DBX
Tune debug info for dbx.
@ Default
No specific tuning requested.
@ GDB
Tune debug info for gdb.
@ LLDB
Tune debug info for lldb.
@ Default
The result values are uniform if and only if all operands are uniform.
#define N
Represents an entry-value location, or a fragment of one.
Definition: DwarfDebug.h:116
friend bool operator<(const EntryValueInfo &LHS, const EntryValueInfo &RHS)
Operator enabling sorting based on fragment offset.
const DIExpression & Expr
Definition: DwarfDebug.h:118
Proxy for one MMI entry.
Definition: DwarfDebug.h:107
const DIExpression * Expr
Definition: DwarfDebug.h:109
friend bool operator<(const FrameIndexExpr &LHS, const FrameIndexExpr &RHS)
Operator enabling sorting based on fragment offset.
Single location defined by (potentially multiple) EntryValueInfo.
Definition: DwarfDebug.h:168
void addExpr(MCRegister Reg, const DIExpression &Expr)
Definition: DwarfDebug.h:176
std::set< EntryValueInfo > EntryValues
Definition: DwarfDebug.h:169
EntryValue(MCRegister Reg, const DIExpression &Expr)
Definition: DwarfDebug.h:170
Single location defined by (potentially multiple) MMI entries.
Definition: DwarfDebug.h:155
void addFrameIndexExpr(const DIExpression *Expr, int FI)
Definition: DwarfDebug.cpp:296
std::set< FrameIndexExpr > FrameIndexExprs
Definition: DwarfDebug.h:156
const std::set< FrameIndexExpr > & getFrameIndexExprs() const
Get the FI entries, sorted by fragment offset.
Definition: DwarfDebug.cpp:292
MMI(const DIExpression *E, int FI)
Definition: DwarfDebug.h:159
Helper used to pair up a symbol and its DWARF compile unit.
Definition: DwarfDebug.h:331
const MCSymbol * Sym
Definition: DwarfDebug.h:334
DwarfCompileUnit * CU
Definition: DwarfDebug.h:335
SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym)
Definition: DwarfDebug.h:332