LLVM 17.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 <vector>
45
46namespace llvm {
47
48class AsmPrinter;
49class ByteStreamer;
50class DIE;
51class DwarfCompileUnit;
52class DwarfExpression;
53class DwarfTypeUnit;
54class DwarfUnit;
55class LexicalScope;
56class MachineFunction;
57class MCSection;
58class MCSymbol;
59class Module;
60
61//===----------------------------------------------------------------------===//
62/// This class is defined as the common parent of DbgVariable and DbgLabel
63/// such that it could levarage polymorphism to extract common code for
64/// DbgVariable and DbgLabel.
65class DbgEntity {
66public:
70 };
71
72private:
73 const DINode *Entity;
74 const DILocation *InlinedAt;
75 DIE *TheDIE = nullptr;
76 const DbgEntityKind SubclassID;
77
78public:
80 : Entity(N), InlinedAt(IA), SubclassID(ID) {}
81 virtual ~DbgEntity() = default;
82
83 /// Accessors.
84 /// @{
85 const DINode *getEntity() const { return Entity; }
86 const DILocation *getInlinedAt() const { return InlinedAt; }
87 DIE *getDIE() const { return TheDIE; }
88 DbgEntityKind getDbgEntityID() const { return SubclassID; }
89 /// @}
90
91 void setDIE(DIE &D) { TheDIE = &D; }
92
93 static bool classof(const DbgEntity *N) {
94 switch (N->getDbgEntityID()) {
95 case DbgVariableKind:
96 case DbgLabelKind:
97 return true;
98 }
99 llvm_unreachable("Invalid DbgEntityKind");
100 }
101};
102
103//===----------------------------------------------------------------------===//
104/// This class is used to track local variable information.
105///
106/// Variables can be created from allocas, in which case they're generated from
107/// the MMI table. Such variables can have multiple expressions and frame
108/// indices.
109///
110/// Variables can be created from \c DBG_VALUE instructions. Those whose
111/// location changes over time use \a DebugLocListIndex, while those with a
112/// single location use \a ValueLoc and (optionally) a single entry of \a Expr.
113///
114/// Variables that have been optimized out use none of these fields.
115class DbgVariable : public DbgEntity {
116 /// Index of the entry list in DebugLocs.
117 unsigned DebugLocListIndex = ~0u;
118 /// DW_OP_LLVM_tag_offset value from DebugLocs.
119 std::optional<uint8_t> DebugLocListTagOffset;
120
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
131public:
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.
164
165 // Accessors.
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 void setDebugLocListTagOffset(uint8_t O) { DebugLocListTagOffset = O; }
178 std::optional<uint8_t> getDebugLocListTagOffset() const {
179 return DebugLocListTagOffset;
180 }
181 StringRef getName() const { return getVariable()->getName(); }
182 const DbgValueLoc *getValueLoc() const { return ValueLoc.get(); }
183 /// Get the FI entries, sorted by fragment offset.
185 bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); }
186 void addMMIEntry(const DbgVariable &V);
187
188 // Translate tag to proper Dwarf tag.
190 // FIXME: Why don't we just infer this tag and store it all along?
191 if (getVariable()->isParameter())
192 return dwarf::DW_TAG_formal_parameter;
193
194 return dwarf::DW_TAG_variable;
195 }
196
197 /// Return true if DbgVariable is artificial.
198 bool isArtificial() const {
199 if (getVariable()->isArtificial())
200 return true;
201 if (getType()->isArtificial())
202 return true;
203 return false;
204 }
205
206 bool isObjectPointer() const {
208 return true;
209 if (getType()->isObjectPointer())
210 return true;
211 return false;
212 }
213
214 bool hasComplexAddress() const {
215 assert(ValueLoc.get() && "Expected DBG_VALUE, not MMI variable");
216 assert((FrameIndexExprs.empty() ||
217 (FrameIndexExprs.size() == 1 &&
218 FrameIndexExprs[0].Expr->getNumElements())) &&
219 "Invalid Expr for DBG_VALUE");
220 return !FrameIndexExprs.empty();
221 }
222
223 const DIType *getType() const;
224
225 static bool classof(const DbgEntity *N) {
226 return N->getDbgEntityID() == DbgVariableKind;
227 }
228};
229
230//===----------------------------------------------------------------------===//
231/// This class is used to track label information.
232///
233/// Labels are collected from \c DBG_LABEL instructions.
234class DbgLabel : public DbgEntity {
235 const MCSymbol *Sym; /// Symbol before DBG_LABEL instruction.
236
237public:
238 /// We need MCSymbol information to generate DW_AT_low_pc.
239 DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)
240 : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}
241
242 /// Accessors.
243 /// @{
244 const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }
245 const MCSymbol *getSymbol() const { return Sym; }
246
247 StringRef getName() const { return getLabel()->getName(); }
248 /// @}
249
250 /// Translate tag to proper Dwarf tag.
252 return dwarf::DW_TAG_label;
253 }
254
255 static bool classof(const DbgEntity *N) {
256 return N->getDbgEntityID() == DbgLabelKind;
257 }
258};
259
260/// Used for tracking debug info about call site parameters.
262private:
263 unsigned Register; ///< Parameter register at the callee entry point.
264 DbgValueLoc Value; ///< Corresponding location for the parameter value at
265 ///< the call site.
266public:
268 : Register(Reg), Value(Val) {
269 assert(Reg && "Parameter register cannot be undef");
270 }
271
272 unsigned getRegister() const { return Register; }
273 DbgValueLoc getValue() const { return Value; }
274};
275
276/// Collection used for storing debug call site parameters.
278
279/// Helper used to pair up a symbol and its DWARF compile unit.
280struct SymbolCU {
282
283 const MCSymbol *Sym;
285};
286
287/// The kind of accelerator tables we should emit.
288enum class AccelTableKind {
289 Default, ///< Platform default.
290 None, ///< None.
291 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
292 Dwarf, ///< DWARF v5 .debug_names.
293};
294
295/// Collects and handles dwarf debug information.
297 /// All DIEValues are allocated through this allocator.
298 BumpPtrAllocator DIEValueAllocator;
299
300 /// Maps MDNode with its corresponding DwarfCompileUnit.
302
303 /// Maps a CU DIE with its corresponding DwarfCompileUnit.
305
306 /// List of all labels used in aranges generation.
307 std::vector<SymbolCU> ArangeLabels;
308
309 /// Size of each symbol emitted (for those symbols that have a specific size).
311
312 /// Collection of abstract variables/labels.
313 SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;
314
315 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
316 /// can refer to them in spite of insertions into this list.
317 DebugLocStream DebugLocs;
318
319 /// This is a collection of subprogram MDNodes that are processed to
320 /// create DIEs.
323 ProcessedSPNodes;
324
325 /// If nonnull, stores the current machine function we're processing.
326 const MachineFunction *CurFn = nullptr;
327
328 /// If nonnull, stores the CU in which the previous subprogram was contained.
329 const DwarfCompileUnit *PrevCU = nullptr;
330
331 /// As an optimization, there is no need to emit an entry in the directory
332 /// table for the same directory as DW_AT_comp_dir.
333 StringRef CompilationDir;
334
335 /// Holder for the file specific debug information.
336 DwarfFile InfoHolder;
337
338 /// Holders for the various debug information flags that we might need to
339 /// have exposed. See accessor functions below for description.
340
341 /// Map from MDNodes for user-defined types to their type signatures. Also
342 /// used to keep track of which types we have emitted type units for.
344
346
348 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
349 TypeUnitsUnderConstruction;
350
351 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
352 bool UseGNUTLSOpcode;
353
354 /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format).
355 bool UseDWARF2Bitfields;
356
357 /// Whether to emit all linkage names, or just abstract subprograms.
358 bool UseAllLinkageNames;
359
360 /// Use inlined strings.
361 bool UseInlineStrings = false;
362
363 /// Allow emission of .debug_ranges section.
364 bool UseRangesSection = true;
365
366 /// True if the sections itself must be used as references and don't create
367 /// temp symbols inside DWARF sections.
368 bool UseSectionsAsReferences = false;
369
370 ///Allow emission of the .debug_loc section.
371 bool UseLocSection = true;
372
373 /// Generate DWARF v4 type units.
374 bool GenerateTypeUnits;
375
376 /// Emit a .debug_macro section instead of .debug_macinfo.
377 bool UseDebugMacroSection;
378
379 /// Avoid using DW_OP_convert due to consumer incompatibilities.
380 bool EnableOpConvert;
381
382public:
383 enum class MinimizeAddrInV5 {
384 Default,
385 Disabled,
386 Ranges,
388 Form,
389 };
390
391private:
392 /// Force the use of DW_AT_ranges even for single-entry range lists.
394
395 /// DWARF5 Experimental Options
396 /// @{
397 AccelTableKind TheAccelTableKind;
398 bool HasAppleExtensionAttributes;
399 bool HasSplitDwarf;
400
401 /// Whether to generate the DWARF v5 string offsets table.
402 /// It consists of a series of contributions, each preceded by a header.
403 /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast,
404 /// a monolithic sequence of string offsets.
405 bool UseSegmentedStringOffsetsTable;
406
407 /// Enable production of call site parameters needed to print the debug entry
408 /// values. Useful for testing purposes when a debugger does not support the
409 /// feature yet.
410 bool EmitDebugEntryValues;
411
412 /// Separated Dwarf Variables
413 /// In general these will all be for bits that are left in the
414 /// original object file, rather than things that are meant
415 /// to be in the .dwo sections.
416
417 /// Holder for the skeleton information.
418 DwarfFile SkeletonHolder;
419
420 /// Store file names for type units under fission in a line table
421 /// header that will be emitted into debug_line.dwo.
422 // FIXME: replace this with a map from comp_dir to table so that we
423 // can emit multiple tables during LTO each of which uses directory
424 // 0, referencing the comp_dir of all the type units that use it.
425 MCDwarfDwoLineTable SplitTypeUnitFileTable;
426 /// @}
427
428 /// True iff there are multiple CUs in this module.
429 bool SingleCU;
430 bool IsDarwin;
431
432 /// Map for tracking Fortran deferred CHARACTER lengths.
434
435 AddressPool AddrPool;
436
437 /// Accelerator tables.
438 AccelTable<DWARF5AccelTableData> AccelDebugNames;
443
444 /// Identify a debugger for "tuning" the debug info.
445 ///
446 /// The "tuning" should be used to set defaults for individual feature flags
447 /// in DwarfDebug; if a given feature has a more specific command-line option,
448 /// that option should take precedence over the tuning.
449 DebuggerKind DebuggerTuning = DebuggerKind::Default;
450
451 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
452
454 return InfoHolder.getUnits();
455 }
456
457 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
458
459 void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
460 const DINode *Node,
461 const MDNode *Scope);
462 void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
463 const DINode *Node,
464 const MDNode *Scope);
465
466 DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,
467 LexicalScope &Scope,
468 const DINode *Node,
469 const DILocation *Location,
470 const MCSymbol *Sym = nullptr);
471
472 /// Construct a DIE for this abstract scope.
473 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
474
475 /// Construct DIEs for call site entries describing the calls in \p MF.
476 void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
477 DIE &ScopeDIE, const MachineFunction &MF);
478
479 template <typename DataT>
480 void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
481 StringRef Name, const DIE &Die);
482
483 void finishEntityDefinitions();
484
485 void finishSubprogramDefinitions();
486
487 /// Finish off debug information after all functions have been
488 /// processed.
489 void finalizeModuleInfo();
490
491 /// Emit the debug info section.
492 void emitDebugInfo();
493
494 /// Emit the abbreviation section.
495 void emitAbbreviations();
496
497 /// Emit the string offsets table header.
498 void emitStringOffsetsTableHeader();
499
500 /// Emit a specified accelerator table.
501 template <typename AccelTableT>
502 void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName);
503
504 /// Emit DWARF v5 accelerator table.
505 void emitAccelDebugNames();
506
507 /// Emit visible names into a hashed accelerator table section.
508 void emitAccelNames();
509
510 /// Emit objective C classes and categories into a hashed
511 /// accelerator table section.
512 void emitAccelObjC();
513
514 /// Emit namespace dies into a hashed accelerator table.
515 void emitAccelNamespaces();
516
517 /// Emit type dies into a hashed accelerator table.
518 void emitAccelTypes();
519
520 /// Emit visible names and types into debug pubnames and pubtypes sections.
521 void emitDebugPubSections();
522
523 void emitDebugPubSection(bool GnuStyle, StringRef Name,
524 DwarfCompileUnit *TheU,
525 const StringMap<const DIE *> &Globals);
526
527 /// Emit null-terminated strings into a debug str section.
528 void emitDebugStr();
529
530 /// Emit variable locations into a debug loc section.
531 void emitDebugLoc();
532
533 /// Emit variable locations into a debug loc dwo section.
534 void emitDebugLocDWO();
535
536 void emitDebugLocImpl(MCSection *Sec);
537
538 /// Emit address ranges into a debug aranges section.
539 void emitDebugARanges();
540
541 /// Emit address ranges into a debug ranges section.
542 void emitDebugRanges();
543 void emitDebugRangesDWO();
544 void emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section);
545
546 /// Emit macros into a debug macinfo section.
547 void emitDebugMacinfo();
548 /// Emit macros into a debug macinfo.dwo section.
549 void emitDebugMacinfoDWO();
550 void emitDebugMacinfoImpl(MCSection *Section);
551 void emitMacro(DIMacro &M);
552 void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U);
553 void emitMacroFileImpl(DIMacroFile &F, DwarfCompileUnit &U,
554 unsigned StartFile, unsigned EndFile,
555 StringRef (*MacroFormToString)(unsigned Form));
556 void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U);
557
558 /// DWARF 5 Experimental Split Dwarf Emitters
559
560 /// Initialize common features of skeleton units.
561 void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
562 std::unique_ptr<DwarfCompileUnit> NewU);
563
564 /// Construct the split debug info compile unit for the debug info section.
565 /// In DWARF v5, the skeleton unit DIE may have the following attributes:
566 /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc,
567 /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base.
568 /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name
569 /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of
570 /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base.
571 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
572
573 /// Emit the debug info dwo section.
574 void emitDebugInfoDWO();
575
576 /// Emit the debug abbrev dwo section.
577 void emitDebugAbbrevDWO();
578
579 /// Emit the debug line dwo section.
580 void emitDebugLineDWO();
581
582 /// Emit the dwo stringoffsets table header.
583 void emitStringOffsetsTableHeaderDWO();
584
585 /// Emit the debug str dwo section.
586 void emitDebugStrDWO();
587
588 /// Emit DWO addresses.
589 void emitDebugAddr();
590
591 /// Flags to let the linker know we have emitted new style pubnames. Only
592 /// emit it here if we don't have a skeleton CU for split dwarf.
593 void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const;
594
595 /// Create new DwarfCompileUnit for the given metadata node with tag
596 /// DW_TAG_compile_unit.
597 DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit);
598 void finishUnitAttributes(const DICompileUnit *DIUnit,
599 DwarfCompileUnit &NewCU);
600
601 /// Construct imported_module or imported_declaration DIE.
602 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
603 const DIImportedEntity *N);
604
605 /// Register a source line with debug info. Returns the unique
606 /// label that was emitted and which provides correspondence to the
607 /// source line list.
608 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
609 unsigned Flags);
610
611 /// Populate LexicalScope entries with variables' info.
612 void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
613 DenseSet<InlinedEntity> &ProcessedVars);
614
615 /// Build the location list for all DBG_VALUEs in the
616 /// function that describe the same variable. If the resulting
617 /// list has only one entry that is valid for entire variable's
618 /// scope return true.
619 bool buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
620 const DbgValueHistoryMap::Entries &Entries);
621
622 /// Collect variable information from the side table maintained by MF.
623 void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,
624 DenseSet<InlinedEntity> &P);
625
626 /// Emit the reference to the section.
627 void emitSectionReference(const DwarfCompileUnit &CU);
628
629protected:
630 /// Gather pre-function debug information.
631 void beginFunctionImpl(const MachineFunction *MF) override;
632
633 /// Gather and emit post-function debug information.
634 void endFunctionImpl(const MachineFunction *MF) override;
635
636 /// Get Dwarf compile unit ID for line table.
637 unsigned getDwarfCompileUnitIDForLineTable(const DwarfCompileUnit &CU);
638
639 void skippedNonDebugFunction() override;
640
641public:
642 //===--------------------------------------------------------------------===//
643 // Main entry points.
644 //
645 DwarfDebug(AsmPrinter *A);
646
647 ~DwarfDebug() override;
648
649 /// Emit all Dwarf sections that should come prior to the
650 /// content.
651 void beginModule(Module *M) override;
652
653 /// Emit all Dwarf sections that should come after the content.
654 void endModule() override;
655
656 /// Emits inital debug location directive.
657 DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
658
659 /// Process beginning of an instruction.
660 void beginInstruction(const MachineInstr *MI) override;
661
662 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
663 static uint64_t makeTypeSignature(StringRef Identifier);
664
665 /// Add a DIE to the set of types that we're going to pull into
666 /// type units.
668 DIE &Die, const DICompositeType *CTy);
669
670 /// Add a label so that arange data can be generated for it.
671 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
672
673 /// For symbols that have a size designated (e.g. common symbols),
674 /// this tracks that size.
675 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
676 SymSize[Sym] = Size;
677 }
678
679 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
680 /// If not, we still might emit certain cases.
681 bool useAllLinkageNames() const { return UseAllLinkageNames; }
682
683 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
684 /// standard DW_OP_form_tls_address opcode
685 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
686
687 /// Returns whether to use the DWARF2 format for bitfields instyead of the
688 /// DWARF4 format.
689 bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; }
690
691 /// Returns whether to use inline strings.
692 bool useInlineStrings() const { return UseInlineStrings; }
693
694 /// Returns whether ranges section should be emitted.
695 bool useRangesSection() const { return UseRangesSection; }
696
697 /// Returns whether range encodings should be used for single entry range
698 /// lists.
699 bool alwaysUseRanges() const {
700 return MinimizeAddr == MinimizeAddrInV5::Ranges;
701 }
702
703 // Returns whether novel exprloc addrx+offset encodings should be used to
704 // reduce debug_addr size.
706 return MinimizeAddr == MinimizeAddrInV5::Expressions;
707 }
708
709 // Returns whether addrx+offset LLVM extension form should be used to reduce
710 // debug_addr size.
711 bool useAddrOffsetForm() const {
712 return MinimizeAddr == MinimizeAddrInV5::Form;
713 }
714
715 /// Returns whether to use sections as labels rather than temp symbols.
717 return UseSectionsAsReferences;
718 }
719
720 /// Returns whether .debug_loc section should be emitted.
721 bool useLocSection() const { return UseLocSection; }
722
723 /// Returns whether to generate DWARF v4 type units.
724 bool generateTypeUnits() const { return GenerateTypeUnits; }
725
726 // Experimental DWARF5 features.
727
728 /// Returns what kind (if any) of accelerator tables to emit.
729 AccelTableKind getAccelTableKind() const { return TheAccelTableKind; }
730
732 return HasAppleExtensionAttributes;
733 }
734
735 /// Returns whether or not to change the current debug info for the
736 /// split dwarf proposal support.
737 bool useSplitDwarf() const { return HasSplitDwarf; }
738
739 /// Returns whether to generate a string offsets table with (possibly shared)
740 /// contributions from each CU and type unit. This implies the use of
741 /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that
742 /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with
743 /// a pre-DWARF v5 implementation of split DWARF sections, which uses a
744 /// monolithic string offsets table.
746 return UseSegmentedStringOffsetsTable;
747 }
748
749 bool emitDebugEntryValues() const {
750 return EmitDebugEntryValues;
751 }
752
753 bool useOpConvert() const {
754 return EnableOpConvert;
755 }
756
757 bool shareAcrossDWOCUs() const;
758
759 /// Returns the Dwarf Version.
761
762 /// Returns a suitable DWARF form to represent a section offset, i.e.
763 /// * DW_FORM_sec_offset for DWARF version >= 4;
764 /// * DW_FORM_data8 for 64-bit DWARFv3;
765 /// * DW_FORM_data4 for 32-bit DWARFv3 and DWARFv2.
767
768 /// Returns the previous CU that was being updated
769 const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
770 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
771
772 /// Terminate the line table by adding the last range label.
774
775 /// Returns the entries for the .debug_loc section.
776 const DebugLocStream &getDebugLocs() const { return DebugLocs; }
777
778 /// Emit an entry for the debug loc section. This can be used to
779 /// handle an entry that's going to be emitted into the debug loc section.
780 void emitDebugLocEntry(ByteStreamer &Streamer,
781 const DebugLocStream::Entry &Entry,
782 const DwarfCompileUnit *CU);
783
784 /// Emit the location for a debug loc entry, including the size header.
786 const DwarfCompileUnit *CU);
787
788 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
789 DIE &Die);
790
791 AddressPool &getAddressPool() { return AddrPool; }
792
793 void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
794
795 void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
796
798 const DIE &Die);
799
800 void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
801 char Flags);
802
803 const MachineFunction *getCurrentFunction() const { return CurFn; }
804
805 /// A helper function to check whether the DIE for a given Scope is
806 /// going to be null.
808
809 /// Find the matching DwarfCompileUnit for the given CU DIE.
810 DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
811 const DwarfCompileUnit *lookupCU(const DIE *Die) const {
812 return CUDieMap.lookup(Die);
813 }
814
815 unsigned getStringTypeLoc(const DIStringType *ST) const {
816 return StringTypeLocMap.lookup(ST);
817 }
818
819 void addStringTypeLoc(const DIStringType *ST, unsigned Loc) {
820 assert(ST);
821 if (Loc)
822 StringTypeLocMap[ST] = Loc;
823 }
824
825 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
826 ///
827 /// Returns whether we are "tuning" for a given debugger.
828 /// @{
829 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
830 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
831 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
832 bool tuneForDBX() const { return DebuggerTuning == DebuggerKind::DBX; }
833 /// @}
834
835 const MCSymbol *getSectionLabel(const MCSection *S);
836 void insertSectionLabel(const MCSymbol *S);
837
838 static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
839 const DbgValueLoc &Value,
840 DwarfExpression &DwarfExpr);
841
842 /// If the \p File has an MD5 checksum, return it as an MD5Result
843 /// allocated in the MCContext.
844 std::optional<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const;
845};
846
847} // end namespace llvm
848
849#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
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
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.
@ Flags
Definition: TextStubV5.cpp:93
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:195
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
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:744
DWARF expression.
StringRef getName() const
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:261
unsigned getRegister() const
Definition: DwarfDebug.h:272
DbgCallSiteParam(unsigned Reg, DbgValueLoc Val)
Definition: DwarfDebug.h:267
DbgValueLoc getValue() const
Definition: DwarfDebug.h:273
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition: DwarfDebug.h:65
virtual ~DbgEntity()=default
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:93
const DINode * getEntity() const
Accessors.
Definition: DwarfDebug.h:85
DbgEntityKind getDbgEntityID() const
Definition: DwarfDebug.h:88
void setDIE(DIE &D)
Definition: DwarfDebug.h:91
DIE * getDIE() const
Definition: DwarfDebug.h:87
DbgEntity(const DINode *N, const DILocation *IA, DbgEntityKind ID)
Definition: DwarfDebug.h:79
const DILocation * getInlinedAt() const
Definition: DwarfDebug.h:86
This class is used to track label information.
Definition: DwarfDebug.h:234
dwarf::Tag getTag() const
Translate tag to proper Dwarf tag.
Definition: DwarfDebug.h:251
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:255
DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym=nullptr)
Symbol before DBG_LABEL instruction.
Definition: DwarfDebug.h:239
StringRef getName() const
Definition: DwarfDebug.h:247
const MCSymbol * getSymbol() const
Definition: DwarfDebug.h:245
const DILabel * getLabel() const
Accessors.
Definition: DwarfDebug.h:244
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:115
bool hasComplexAddress() const
Definition: DwarfDebug.h:214
bool isArtificial() const
Return true if DbgVariable is artificial.
Definition: DwarfDebug.h:198
dwarf::Tag getTag() const
Definition: DwarfDebug.h:189
void initializeMMI(const DIExpression *E, int FI)
Initialize from the MMI table.
Definition: DwarfDebug.h:140
bool isObjectPointer() const
Definition: DwarfDebug.h:206
const DILocalVariable * getVariable() const
Definition: DwarfDebug.h:166
void setDebugLocListIndex(unsigned O)
Definition: DwarfDebug.h:175
std::optional< uint8_t > getDebugLocListTagOffset() const
Definition: DwarfDebug.h:178
DbgVariable(const DILocalVariable *V, const DILocation *IA)
Frame index + expression.
Definition: DwarfDebug.h:136
void initializeDbgValue(DbgValueLoc Value)
Definition: DwarfDebug.h:151
unsigned getDebugLocListIndex() const
Definition: DwarfDebug.h:176
StringRef getName() const
Definition: DwarfDebug.h:181
const DIType * getType() const
Definition: DwarfDebug.cpp:229
static bool classof(const DbgEntity *N)
Definition: DwarfDebug.h:225
bool hasFrameIndexExprs() const
Definition: DwarfDebug.h:185
const DbgValueLoc * getValueLoc() const
Definition: DwarfDebug.h:182
const DIExpression * getSingleExpression() const
Definition: DwarfDebug.h:170
void addMMIEntry(const DbgVariable &V)
Definition: DwarfDebug.cpp:291
ArrayRef< FrameIndexExpr > getFrameIndexExprs() const
Get the FI entries, sorted by fragment offset.
Definition: DwarfDebug.cpp:273
void setDebugLocListTagOffset(uint8_t O)
Definition: DwarfDebug.h:177
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:296
bool useSegmentedStringOffsetsTable() const
Returns whether to generate a string offsets table with (possibly shared) contributions from each CU ...
Definition: DwarfDebug.h:745
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 alwaysUseRanges() const
Returns whether range encodings should be used for single entry range lists.
Definition: DwarfDebug.h:699
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:685
bool useAddrOffsetForm() const
Definition: DwarfDebug.h:711
const DwarfCompileUnit * getPrevCU() const
Returns the previous CU that was being updated.
Definition: DwarfDebug.h:769
void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override
For symbols that have a size designated (e.g.
Definition: DwarfDebug.h:675
bool emitDebugEntryValues() const
Definition: DwarfDebug.h:749
const DwarfCompileUnit * lookupCU(const DIE *Die) const
Definition: DwarfDebug.h:811
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.
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:681
void insertSectionLabel(const MCSymbol *S)
void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP, DIE &Die)
Definition: DwarfDebug.cpp:500
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:731
void setPrevCU(const DwarfCompileUnit *PrevCU)
Definition: DwarfDebug.h:770
const MachineFunction * getCurrentFunction() const
Definition: DwarfDebug.h:803
void skippedNonDebugFunction() override
bool useInlineStrings() const
Returns whether to use inline strings.
Definition: DwarfDebug.h:692
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
Definition: DwarfDebug.h:671
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
Definition: DwarfDebug.h:724
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
AddressPool & getAddressPool()
Definition: DwarfDebug.h:791
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:716
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:776
bool shareAcrossDWOCUs() const
Definition: DwarfDebug.cpp:558
bool useOpConvert() const
Definition: DwarfDebug.h:753
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:819
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:810
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:737
bool useLocSection() const
Returns whether .debug_loc section should be emitted.
Definition: DwarfDebug.h:721
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:689
DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID)
Emits inital debug location directive.
bool useAddrOffsetExpressions() const
Definition: DwarfDebug.h:705
bool useRangesSection() const
Returns whether ranges section should be emitted.
Definition: DwarfDebug.h:695
unsigned getStringTypeLoc(const DIStringType *ST) const
Definition: DwarfDebug.h:815
bool isLexicalScopeDIENull(LexicalScope *Scope)
A helper function to check whether the DIE for a given Scope is going to be null.
Definition: DwarfDebug.cpp:534
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:729
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:101
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:44
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:37
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:40
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void push_back(const T &Elt)
Definition: SmallVector.h:416
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:831
bool tuneForDBX() const
Definition: DwarfDebug.h:832
bool tuneForGDB() const
Definition: DwarfDebug.h:829
bool tuneForLLDB() const
Definition: DwarfDebug.h:830
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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:288
@ Dwarf
DWARF v5 .debug_names.
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
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.
constexpr std::nullopt_t None
Definition: None.h:28
#define N
Helper used to pair up a symbol and its DWARF compile unit.
Definition: DwarfDebug.h:280
const MCSymbol * Sym
Definition: DwarfDebug.h:283
DwarfCompileUnit * CU
Definition: DwarfDebug.h:284
SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym)
Definition: DwarfDebug.h:281