LLVM 22.0.0git
MCDwarf.h
Go to the documentation of this file.
1//===- MCDwarf.h - Machine Code Dwarf support -------------------*- 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 the declaration of the MCDwarfFile to support the dwarf
10// .file directive and the .loc directive.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCDWARF_H
15#define LLVM_MC_MCDWARF_H
16
17#include "llvm/ADT/MapVector.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/Error.h"
24#include "llvm/Support/MD5.h"
25#include "llvm/Support/SMLoc.h"
27#include <cassert>
28#include <cstdint>
29#include <optional>
30#include <string>
31#include <utility>
32#include <vector>
33
34namespace llvm {
35
36template <typename T> class ArrayRef;
37class MCAsmBackend;
38class MCContext;
39class MCObjectStreamer;
40class MCSection;
41class MCStreamer;
42class MCSymbol;
43class raw_ostream;
44class SourceMgr;
45
46namespace mcdwarf {
47// Emit the common part of the DWARF 5 range/locations list tables header.
49} // namespace mcdwarf
50
51/// Manage the .debug_line_str section contents, if we use it.
53 BumpPtrAllocator Alloc;
54 StringSaver Saver{Alloc};
55 MCSymbol *LineStrLabel = nullptr;
57 bool UseRelocs = false;
58
59public:
60 /// Construct an instance that can emit .debug_line_str (for use in a normal
61 /// v5 line table).
62 LLVM_ABI explicit MCDwarfLineStr(MCContext &Ctx);
63
64 StringSaver &getSaver() { return Saver; }
65
66 /// Emit a reference to the string.
67 LLVM_ABI void emitRef(MCStreamer *MCOS, StringRef Path);
68
69 /// Emit the .debug_line_str section if appropriate.
71
72 /// Returns finalized section.
74
75 /// Adds path \p Path to the line string. Returns offset in the
76 /// .debug_line_str section.
77 LLVM_ABI size_t addString(StringRef Path);
78};
79
80/// Instances of this class represent the name of the dwarf .file directive and
81/// its associated dwarf file number in the MC file. MCDwarfFile's are created
82/// and uniqued by the MCContext class. In Dwarf 4 file numbers start from 1;
83/// i.e. the entry with file number 1 is the first element in the vector of
84/// DwarfFiles and there is no MCDwarfFile with file number 0. In Dwarf 5 file
85/// numbers start from 0, with the MCDwarfFile with file number 0 being the
86/// primary source file, and file numbers correspond to their index in the
87/// vector.
89 // The base name of the file without its directory path.
90 std::string Name;
91
92 // The index into the list of directory names for this file name.
93 unsigned DirIndex = 0;
94
95 /// The MD5 checksum, if there is one. Non-owning pointer to data allocated
96 /// in MCContext.
97 std::optional<MD5::MD5Result> Checksum;
98
99 /// The source code of the file. Non-owning reference to data allocated in
100 /// MCContext.
101 std::optional<StringRef> Source;
102};
103
104/// Instances of this class represent the information from a
105/// dwarf .loc directive.
107 uint32_t FileNum;
108 uint32_t Line;
109 uint16_t Column;
110 // Flags (see #define's below)
111 uint8_t Flags;
112 uint8_t Isa;
113 uint32_t Discriminator;
114
115// Flag that indicates the initial value of the is_stmt_start flag.
116#define DWARF2_LINE_DEFAULT_IS_STMT 1
117
118#define DWARF2_FLAG_IS_STMT (1 << 0)
119#define DWARF2_FLAG_BASIC_BLOCK (1 << 1)
120#define DWARF2_FLAG_PROLOGUE_END (1 << 2)
121#define DWARF2_FLAG_EPILOGUE_BEGIN (1 << 3)
122
123private: // MCContext manages these
124 friend class MCContext;
125 friend class MCDwarfLineEntry;
126
127 MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags,
128 unsigned isa, unsigned discriminator)
129 : FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa),
130 Discriminator(discriminator) {}
131
132 // Allow the default copy constructor and assignment operator to be used
133 // for an MCDwarfLoc object.
134
135public:
136 /// Get the FileNum of this MCDwarfLoc.
137 unsigned getFileNum() const { return FileNum; }
138
139 /// Get the Line of this MCDwarfLoc.
140 unsigned getLine() const { return Line; }
141
142 /// Get the Column of this MCDwarfLoc.
143 unsigned getColumn() const { return Column; }
144
145 /// Get the Flags of this MCDwarfLoc.
146 unsigned getFlags() const { return Flags; }
147
148 /// Get the Isa of this MCDwarfLoc.
149 unsigned getIsa() const { return Isa; }
150
151 /// Get the Discriminator of this MCDwarfLoc.
152 unsigned getDiscriminator() const { return Discriminator; }
153
154 /// Set the FileNum of this MCDwarfLoc.
155 void setFileNum(unsigned fileNum) { FileNum = fileNum; }
156
157 /// Set the Line of this MCDwarfLoc.
158 void setLine(unsigned line) { Line = line; }
159
160 /// Set the Column of this MCDwarfLoc.
161 void setColumn(unsigned column) {
162 assert(column <= UINT16_MAX);
163 Column = column;
164 }
165
166 /// Set the Flags of this MCDwarfLoc.
167 void setFlags(unsigned flags) {
168 assert(flags <= UINT8_MAX);
169 Flags = flags;
170 }
171
172 /// Set the Isa of this MCDwarfLoc.
173 void setIsa(unsigned isa) {
174 assert(isa <= UINT8_MAX);
175 Isa = isa;
176 }
177
178 /// Set the Discriminator of this MCDwarfLoc.
179 void setDiscriminator(unsigned discriminator) {
180 Discriminator = discriminator;
181 }
182};
183
184/// Instances of this class represent the line information for
185/// the dwarf line table entries. Which is created after a machine
186/// instruction is assembled and uses an address from a temporary label
187/// created at the current address in the current section and the info from
188/// the last .loc directive seen as stored in the context.
190 MCSymbol *Label;
191
192private:
193 // Allow the default copy constructor and assignment operator to be used
194 // for an MCDwarfLineEntry object.
195
196public:
197 // Constructor to create an MCDwarfLineEntry given a symbol and the dwarf loc.
199 MCSymbol *lineStreamLabel = nullptr,
200 SMLoc streamLabelDefLoc = {})
201 : MCDwarfLoc(loc), Label(label), LineStreamLabel(lineStreamLabel),
202 StreamLabelDefLoc(streamLabelDefLoc) {}
203
204 MCSymbol *getLabel() const { return Label; }
205
206 // This is the label that is to be emitted into the line stream. If this is
207 // non-null and we need to emit a label, also make sure to restart the current
208 // line sequence.
210
211 // Location where LineStreamLabel was defined. If there is an error emitting
212 // LineStreamLabel, we can use the SMLoc to report an error.
214
215 // This indicates the line entry is synthesized for an end entry.
216 bool IsEndEntry = false;
217
218 // Override the label with the given EndLabel.
219 void setEndLabel(MCSymbol *EndLabel) {
220 // If we're setting this to be an end entry, make sure we don't have
221 // LineStreamLabel set.
222 assert(LineStreamLabel == nullptr);
223 Label = EndLabel;
224 IsEndEntry = true;
225 }
226
227 // This is called when an instruction is assembled into the specified
228 // section and if there is information from the last .loc directive that
229 // has yet to have a line entry made for it is made.
230 LLVM_ABI static void make(MCStreamer *MCOS, MCSection *Section);
231};
232
233/// Instances of this class represent the line information for a compile
234/// unit where machine instructions have been assembled after seeing .loc
235/// directives. This is the information used to build the dwarf line
236/// table for a section.
238public:
239 // Add an entry to this MCLineSection's line entries.
240 void addLineEntry(const MCDwarfLineEntry &LineEntry, MCSection *Sec) {
241 MCLineDivisions[Sec].push_back(LineEntry);
242 }
243
244 // Add an end entry by cloning the last entry, if exists, for the section
245 // the given EndLabel belongs to. The label is replaced by the given EndLabel.
246 LLVM_ABI void addEndEntry(MCSymbol *EndLabel);
247
248 using MCDwarfLineEntryCollection = std::vector<MCDwarfLineEntry>;
249 using iterator = MCDwarfLineEntryCollection::iterator;
250 using const_iterator = MCDwarfLineEntryCollection::const_iterator;
252
253private:
254 // A collection of MCDwarfLineEntry for each section.
255 MCLineDivisionMap MCLineDivisions;
256
257public:
258 // Returns the collection of MCDwarfLineEntry for a given Compile Unit ID.
260 return MCLineDivisions;
261 }
262};
263
265 /// First special line opcode - leave room for the standard opcodes.
266 /// Note: If you want to change this, you'll have to update the
267 /// "StandardOpcodeLengths" table that is emitted in
268 /// \c Emit().
270 /// Minimum line offset in a special line info. opcode. The value
271 /// -5 was chosen to give a reasonable range of values.
272 int8_t DWARF2LineBase = -5;
273 /// Range of line offsets in a special line info. opcode.
275};
276
278 MCSymbol *Label = nullptr;
282 std::string CompilationDir;
284 bool HasAnySource = false;
285
286private:
287 bool HasAllMD5 = true;
288 bool HasAnyMD5 = false;
289
290public:
292
294 StringRef &FileName,
295 std::optional<MD5::MD5Result> Checksum,
296 std::optional<StringRef> Source,
297 uint16_t DwarfVersion,
298 unsigned FileNumber = 0);
299 LLVM_ABI std::pair<MCSymbol *, MCSymbol *>
301 std::optional<MCDwarfLineStr> &LineStr) const;
302 LLVM_ABI std::pair<MCSymbol *, MCSymbol *>
304 ArrayRef<char> SpecialOpcodeLengths,
305 std::optional<MCDwarfLineStr> &LineStr) const;
307 HasAllMD5 = true;
308 HasAnyMD5 = false;
309 }
310 void trackMD5Usage(bool MD5Used) {
311 HasAllMD5 &= MD5Used;
312 HasAnyMD5 |= MD5Used;
313 }
314 bool isMD5UsageConsistent() const {
315 return MCDwarfFiles.empty() || (HasAllMD5 == HasAnyMD5);
316 }
317
318 void setRootFile(StringRef Directory, StringRef FileName,
319 std::optional<MD5::MD5Result> Checksum,
320 std::optional<StringRef> Source) {
321 CompilationDir = std::string(Directory);
322 RootFile.Name = std::string(FileName);
323 RootFile.DirIndex = 0;
324 RootFile.Checksum = Checksum;
325 RootFile.Source = Source;
326 trackMD5Usage(Checksum.has_value());
327 HasAnySource |= Source.has_value();
328 }
329
332 MCDwarfFiles.clear();
333 RootFile.Name.clear();
335 HasAnySource = false;
336 }
337
338private:
339 void emitV2FileDirTables(MCStreamer *MCOS) const;
340 void emitV5FileDirTables(MCStreamer *MCOS,
341 std::optional<MCDwarfLineStr> &LineStr) const;
342};
343
346 bool HasSplitLineTable = false;
347
348public:
349 void maybeSetRootFile(StringRef Directory, StringRef FileName,
350 std::optional<MD5::MD5Result> Checksum,
351 std::optional<StringRef> Source) {
352 if (!Header.RootFile.Name.empty())
353 return;
354 Header.setRootFile(Directory, FileName, Checksum, Source);
355 }
356
357 unsigned getFile(StringRef Directory, StringRef FileName,
358 std::optional<MD5::MD5Result> Checksum,
359 uint16_t DwarfVersion, std::optional<StringRef> Source) {
360 HasSplitLineTable = true;
361 return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source,
362 DwarfVersion));
363 }
364
366 MCSection *Section) const;
367};
368
371 MCLineSection MCLineSections;
372
373public:
374 // This emits the Dwarf file and the line tables for all Compile Units.
375 LLVM_ABI static void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params);
376
377 // This emits the Dwarf file and the line tables for a given Compile Unit.
379 std::optional<MCDwarfLineStr> &LineStr) const;
380
381 // This emits a single line table associated with a given Section.
382 LLVM_ABI static void
383 emitOne(MCStreamer *MCOS, MCSection *Section,
385
387 SMLoc DefLoc,
389
391 StringRef &FileName,
392 std::optional<MD5::MD5Result> Checksum,
393 std::optional<StringRef> Source,
394 uint16_t DwarfVersion,
395 unsigned FileNumber = 0);
396 unsigned getFile(StringRef &Directory, StringRef &FileName,
397 std::optional<MD5::MD5Result> Checksum,
398 std::optional<StringRef> Source, uint16_t DwarfVersion,
399 unsigned FileNumber = 0) {
400 return cantFail(tryGetFile(Directory, FileName, Checksum, Source,
401 DwarfVersion, FileNumber));
402 }
403
404 void setRootFile(StringRef Directory, StringRef FileName,
405 std::optional<MD5::MD5Result> Checksum,
406 std::optional<StringRef> Source) {
407 Header.CompilationDir = std::string(Directory);
408 Header.RootFile.Name = std::string(FileName);
409 Header.RootFile.DirIndex = 0;
410 Header.RootFile.Checksum = Checksum;
411 Header.RootFile.Source = Source;
412 Header.trackMD5Usage(Checksum.has_value());
413 Header.HasAnySource |= Source.has_value();
414 }
415
416 void resetFileTable() { Header.resetFileTable(); }
417
418 bool hasRootFile() const { return !Header.RootFile.Name.empty(); }
419
420 MCDwarfFile &getRootFile() { return Header.RootFile; }
421 const MCDwarfFile &getRootFile() const { return Header.RootFile; }
422
423 // Report whether MD5 usage has been consistent (all-or-none).
424 bool isMD5UsageConsistent() const { return Header.isMD5UsageConsistent(); }
425
427 return Header.Label;
428 }
429
430 void setLabel(MCSymbol *Label) {
431 Header.Label = Label;
432 }
433
435 return Header.MCDwarfDirs;
436 }
437
439 return Header.MCDwarfDirs;
440 }
441
443 return Header.MCDwarfFiles;
444 }
445
447 return Header.MCDwarfFiles;
448 }
449
451 return MCLineSections;
452 }
454 return MCLineSections;
455 }
456};
457
459public:
460 /// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
462 int64_t LineDelta, uint64_t AddrDelta,
464
465 /// Utility function to emit the encoding to a streamer.
466 LLVM_ABI static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
467 int64_t LineDelta, uint64_t AddrDelta);
468};
469
471public:
472 //
473 // When generating dwarf for assembly source files this emits the Dwarf
474 // sections.
475 //
476 LLVM_ABI static void Emit(MCStreamer *MCOS);
477};
478
479// When generating dwarf for assembly source files this is the info that is
480// needed to be gathered for each symbol that will have a dwarf label.
482private:
483 // Name of the symbol without a leading underbar, if any.
484 StringRef Name;
485 // The dwarf file number this symbol is in.
486 unsigned FileNumber;
487 // The line number this symbol is at.
488 unsigned LineNumber;
489 // The low_pc for the dwarf label is taken from this symbol.
490 MCSymbol *Label;
491
492public:
493 MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber,
494 MCSymbol *label)
495 : Name(name), FileNumber(fileNumber), LineNumber(lineNumber),
496 Label(label) {}
497
498 StringRef getName() const { return Name; }
499 unsigned getFileNumber() const { return FileNumber; }
500 unsigned getLineNumber() const { return LineNumber; }
501 MCSymbol *getLabel() const { return Label; }
502
503 // This is called when label is created when we are generating dwarf for
504 // assembly source files.
505 LLVM_ABI static void Make(MCSymbol *Symbol, MCStreamer *MCOS,
506 SourceMgr &SrcMgr, SMLoc &Loc);
507};
508
510public:
532 };
533
534private:
535 MCSymbol *Label;
536 union {
537 struct {
538 unsigned Register;
539 int64_t Offset;
540 } RI;
541 struct {
542 unsigned Register;
543 int64_t Offset;
544 unsigned AddressSpace;
546 struct {
547 unsigned Register;
548 unsigned Register2;
549 } RR;
551 } U;
552 OpType Operation;
553 SMLoc Loc;
554 std::vector<char> Values;
555 std::string Comment;
556
557 MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int64_t O, SMLoc Loc,
558 StringRef V = "", StringRef Comment = "")
559 : Label(L), Operation(Op), Loc(Loc), Values(V.begin(), V.end()),
560 Comment(Comment) {
562 U.RI = {R, O};
563 }
564 MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2, SMLoc Loc)
565 : Label(L), Operation(Op), Loc(Loc) {
566 assert(Op == OpRegister);
567 U.RR = {R1, R2};
568 }
569 MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int64_t O, unsigned AS,
570 SMLoc Loc)
571 : Label(L), Operation(Op), Loc(Loc) {
573 U.RIA = {R, O, AS};
574 }
575
576 MCCFIInstruction(OpType Op, MCSymbol *L, MCSymbol *CfiLabel, SMLoc Loc)
577 : Label(L), Operation(Op), Loc(Loc) {
578 assert(Op == OpLabel);
579 U.CfiLabel = CfiLabel;
580 }
581
582public:
583 /// .cfi_def_cfa defines a rule for computing CFA as: take address from
584 /// Register and add Offset to it.
586 int64_t Offset, SMLoc Loc = {}) {
587 return MCCFIInstruction(OpDefCfa, L, Register, Offset, Loc);
588 }
589
590 /// .cfi_def_cfa_register modifies a rule for computing CFA. From now
591 /// on Register will be used instead of the old one. Offset remains the same.
593 SMLoc Loc = {}) {
594 return MCCFIInstruction(OpDefCfaRegister, L, Register, INT64_C(0), Loc);
595 }
596
597 /// .cfi_def_cfa_offset modifies a rule for computing CFA. Register
598 /// remains the same, but offset is new. Note that it is the absolute offset
599 /// that will be added to a defined register to the compute CFA address.
601 SMLoc Loc = {}) {
602 return MCCFIInstruction(OpDefCfaOffset, L, 0, Offset, Loc);
603 }
604
605 /// .cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but
606 /// Offset is a relative value that is added/subtracted from the previous
607 /// offset.
608 static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment,
609 SMLoc Loc = {}) {
610 return MCCFIInstruction(OpAdjustCfaOffset, L, 0, Adjustment, Loc);
611 }
612
613 // FIXME: Update the remaining docs to use the new proposal wording.
614 /// .cfi_llvm_def_aspace_cfa defines the rule for computing the CFA to
615 /// be the result of evaluating the DWARF operation expression
616 /// `DW_OP_constu AS; DW_OP_aspace_bregx R, B` as a location description.
618 int64_t Offset,
619 unsigned AddressSpace,
620 SMLoc Loc) {
622 AddressSpace, Loc);
623 }
624
625 /// .cfi_offset Previous value of Register is saved at offset Offset
626 /// from CFA.
628 int64_t Offset, SMLoc Loc = {}) {
629 return MCCFIInstruction(OpOffset, L, Register, Offset, Loc);
630 }
631
632 /// .cfi_rel_offset Previous value of Register is saved at offset
633 /// Offset from the current CFA register. This is transformed to .cfi_offset
634 /// using the known displacement of the CFA register from the CFA.
636 int64_t Offset, SMLoc Loc = {}) {
638 }
639
640 /// .cfi_register Previous value of Register1 is saved in
641 /// register Register2.
642 static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1,
643 unsigned Register2, SMLoc Loc = {}) {
644 return MCCFIInstruction(OpRegister, L, Register1, Register2, Loc);
645 }
646
647 /// .cfi_window_save SPARC register window is saved.
649 return MCCFIInstruction(OpWindowSave, L, 0, INT64_C(0), Loc);
650 }
651
652 /// .cfi_negate_ra_state AArch64 negate RA state.
654 return MCCFIInstruction(OpNegateRAState, L, 0, INT64_C(0), Loc);
655 }
656
657 /// .cfi_negate_ra_state_with_pc AArch64 negate RA state with PC.
659 SMLoc Loc = {}) {
660 return MCCFIInstruction(OpNegateRAStateWithPC, L, 0, INT64_C(0), Loc);
661 }
662
663 /// .cfi_restore says that the rule for Register is now the same as it
664 /// was at the beginning of the function, after all initial instructions added
665 /// by .cfi_startproc were executed.
667 SMLoc Loc = {}) {
668 return MCCFIInstruction(OpRestore, L, Register, INT64_C(0), Loc);
669 }
670
671 /// .cfi_undefined From now on the previous value of Register can't be
672 /// restored anymore.
674 SMLoc Loc = {}) {
675 return MCCFIInstruction(OpUndefined, L, Register, INT64_C(0), Loc);
676 }
677
678 /// .cfi_same_value Current value of Register is the same as in the
679 /// previous frame. I.e., no restoration is needed.
681 SMLoc Loc = {}) {
682 return MCCFIInstruction(OpSameValue, L, Register, INT64_C(0), Loc);
683 }
684
685 /// .cfi_remember_state Save all current rules for all registers.
687 return MCCFIInstruction(OpRememberState, L, 0, INT64_C(0), Loc);
688 }
689
690 /// .cfi_restore_state Restore the previously saved state.
692 return MCCFIInstruction(OpRestoreState, L, 0, INT64_C(0), Loc);
693 }
694
695 /// .cfi_escape Allows the user to add arbitrary bytes to the unwind
696 /// info.
698 SMLoc Loc = {}, StringRef Comment = "") {
699 return MCCFIInstruction(OpEscape, L, 0, 0, Loc, Vals, Comment);
700 }
701
702 /// A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE
704 SMLoc Loc = {}) {
705 return MCCFIInstruction(OpGnuArgsSize, L, 0, Size, Loc);
706 }
707
709 SMLoc Loc) {
710 return MCCFIInstruction(OpLabel, L, CfiLabel, Loc);
711 }
712
713 /// .cfi_val_offset Previous value of Register is offset Offset from the
714 /// current CFA register.
716 int64_t Offset, SMLoc Loc = {}) {
718 }
719
720 OpType getOperation() const { return Operation; }
721 MCSymbol *getLabel() const { return Label; }
722
723 unsigned getRegister() const {
724 if (Operation == OpRegister)
725 return U.RR.Register;
727 return U.RIA.Register;
732 return U.RI.Register;
733 }
734
735 unsigned getRegister2() const {
737 return U.RR.Register2;
738 }
739
740 unsigned getAddressSpace() const {
742 return U.RIA.AddressSpace;
743 }
744
745 int64_t getOffset() const {
747 return U.RIA.Offset;
752 return U.RI.Offset;
753 }
754
757 return U.CfiLabel;
758 }
759
762 return StringRef(&Values[0], Values.size());
763 }
764
765 StringRef getComment() const { return Comment; }
766 SMLoc getLoc() const { return Loc; }
767};
768
770 MCDwarfFrameInfo() = default;
771
772 MCSymbol *Begin = nullptr;
773 MCSymbol *End = nullptr;
774 const MCSymbol *Personality = nullptr;
775 const MCSymbol *Lsda = nullptr;
776 std::vector<MCCFIInstruction> Instructions;
777 unsigned CurrentCfaRegister = 0;
779 unsigned LsdaEncoding = 0;
781 bool IsSignalFrame = false;
782 bool IsSimple = false;
783 unsigned RAReg = static_cast<unsigned>(INT_MAX);
784 bool IsBKeyFrame = false;
785 bool IsMTETaggedFrame = false;
786};
787
789public:
790 //
791 // This emits the frame info section.
792 //
793 LLVM_ABI static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB,
794 bool isEH);
795 LLVM_ABI static void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta,
797};
798
799} // end namespace llvm
800
801#endif // LLVM_MC_MCDWARF_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
uint64_t Size
This file implements a map that provides insertion order iteration.
#define R2(n)
PowerPC Reduce CR logical Operation
static const char * name
Definition: SMEABIPass.cpp:52
raw_pwrite_stream & OS
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
This class represents an Operation in the Expression.
Tagged union holding either a T or a Error.
Definition: Error.h:485
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:55
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition: MCDwarf.h:592
MCSymbol * getLabel() const
Definition: MCDwarf.h:721
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_undefined From now on the previous value of Register can't be restored anymore.
Definition: MCDwarf.h:673
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int64_t Size, SMLoc Loc={})
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
Definition: MCDwarf.h:703
struct llvm::MCCFIInstruction::@342::@345 RR
unsigned getAddressSpace() const
Definition: MCDwarf.h:740
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
Definition: MCDwarf.h:666
unsigned getRegister2() const
Definition: MCDwarf.h:735
static MCCFIInstruction createLLVMDefAspaceCfa(MCSymbol *L, unsigned Register, int64_t Offset, unsigned AddressSpace, SMLoc Loc)
.cfi_llvm_def_aspace_cfa defines the rule for computing the CFA to be the result of evaluating the DW...
Definition: MCDwarf.h:617
struct llvm::MCCFIInstruction::@342::@343 RI
unsigned getRegister() const
Definition: MCDwarf.h:723
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2, SMLoc Loc={})
.cfi_register Previous value of Register1 is saved in register Register2.
Definition: MCDwarf.h:642
unsigned AddressSpace
Definition: MCDwarf.h:544
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition: MCDwarf.h:585
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition: MCDwarf.h:627
SMLoc getLoc() const
Definition: MCDwarf.h:766
static MCCFIInstruction createValOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_val_offset Previous value of Register is offset Offset from the current CFA register.
Definition: MCDwarf.h:715
static MCCFIInstruction createNegateRAStateWithPC(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state_with_pc AArch64 negate RA state with PC.
Definition: MCDwarf.h:658
static MCCFIInstruction createNegateRAState(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state AArch64 negate RA state.
Definition: MCDwarf.h:653
static MCCFIInstruction createRememberState(MCSymbol *L, SMLoc Loc={})
.cfi_remember_state Save all current rules for all registers.
Definition: MCDwarf.h:686
OpType getOperation() const
Definition: MCDwarf.h:720
struct llvm::MCCFIInstruction::@342::@344 RIA
StringRef getComment() const
Definition: MCDwarf.h:765
StringRef getValues() const
Definition: MCDwarf.h:760
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:600
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
Definition: MCDwarf.h:697
static MCCFIInstruction createWindowSave(MCSymbol *L, SMLoc Loc={})
.cfi_window_save SPARC register window is saved.
Definition: MCDwarf.h:648
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment, SMLoc Loc={})
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
Definition: MCDwarf.h:608
MCSymbol * CfiLabel
Definition: MCDwarf.h:550
MCSymbol * getCfiLabel() const
Definition: MCDwarf.h:755
static MCCFIInstruction createRestoreState(MCSymbol *L, SMLoc Loc={})
.cfi_restore_state Restore the previously saved state.
Definition: MCDwarf.h:691
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_same_value Current value of Register is the same as in the previous frame.
Definition: MCDwarf.h:680
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_rel_offset Previous value of Register is saved at offset Offset from the current CFA register.
Definition: MCDwarf.h:635
int64_t getOffset() const
Definition: MCDwarf.h:745
static MCCFIInstruction createLabel(MCSymbol *L, MCSymbol *CfiLabel, SMLoc Loc)
Definition: MCDwarf.h:708
Context object for machine code objects.
Definition: MCContext.h:83
void maybeSetRootFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
Definition: MCDwarf.h:349
unsigned getFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, std::optional< StringRef > Source)
Definition: MCDwarf.h:357
LLVM_ABI void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, MCSection *Section) const
Definition: MCDwarf.cpp:325
static LLVM_ABI void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1896
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Definition: MCDwarf.cpp:1972
static LLVM_ABI void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition: MCDwarf.cpp:720
static LLVM_ABI void encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition: MCDwarf.cpp:735
Instances of this class represent the line information for the dwarf line table entries.
Definition: MCDwarf.h:189
void setEndLabel(MCSymbol *EndLabel)
Definition: MCDwarf.h:219
MCSymbol * getLabel() const
Definition: MCDwarf.h:204
MCDwarfLineEntry(MCSymbol *label, const MCDwarfLoc loc, MCSymbol *lineStreamLabel=nullptr, SMLoc streamLabelDefLoc={})
Definition: MCDwarf.h:198
MCSymbol * LineStreamLabel
Definition: MCDwarf.h:209
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:91
Manage the .debug_line_str section contents, if we use it.
Definition: MCDwarf.h:52
StringSaver & getSaver()
Definition: MCDwarf.h:64
LLVM_ABI void emitSection(MCStreamer *MCOS)
Emit the .debug_line_str section if appropriate.
Definition: MCDwarf.cpp:375
LLVM_ABI SmallString< 0 > getFinalizedData()
Returns finalized section.
Definition: MCDwarf.cpp:383
LLVM_ABI void emitRef(MCStreamer *MCOS, StringRef Path)
Emit a reference to the string.
Definition: MCDwarf.cpp:397
LLVM_ABI size_t addString(StringRef Path)
Adds path Path to the line string.
Definition: MCDwarf.cpp:393
bool isMD5UsageConsistent() const
Definition: MCDwarf.h:424
const MCDwarfFile & getRootFile() const
Definition: MCDwarf.h:421
void setLabel(MCSymbol *Label)
Definition: MCDwarf.h:430
const SmallVectorImpl< std::string > & getMCDwarfDirs() const
Definition: MCDwarf.h:434
LLVM_ABI void endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS, SMLoc DefLoc, StringRef Name)
Definition: MCDwarf.cpp:279
void setRootFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
Definition: MCDwarf.h:404
MCDwarfFile & getRootFile()
Definition: MCDwarf.h:420
const MCLineSection & getMCLineSections() const
Definition: MCDwarf.h:450
static LLVM_ABI void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
Definition: MCDwarf.cpp:298
bool hasRootFile() const
Definition: MCDwarf.h:418
unsigned getFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.h:396
SmallVectorImpl< std::string > & getMCDwarfDirs()
Definition: MCDwarf.h:438
SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles()
Definition: MCDwarf.h:446
MCLineSection & getMCLineSections()
Definition: MCDwarf.h:453
MCSymbol * getLabel() const
Definition: MCDwarf.h:426
static LLVM_ABI void emitOne(MCStreamer *MCOS, MCSection *Section, const MCLineSection::MCDwarfLineEntryCollection &LineEntries)
Definition: MCDwarf.cpp:178
LLVM_ABI Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.cpp:621
LLVM_ABI void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, std::optional< MCDwarfLineStr > &LineStr) const
Definition: MCDwarf.cpp:607
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:442
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:106
unsigned getLine() const
Get the Line of this MCDwarfLoc.
Definition: MCDwarf.h:140
void setLine(unsigned line)
Set the Line of this MCDwarfLoc.
Definition: MCDwarf.h:158
unsigned getIsa() const
Get the Isa of this MCDwarfLoc.
Definition: MCDwarf.h:149
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
Definition: MCDwarf.h:173
void setDiscriminator(unsigned discriminator)
Set the Discriminator of this MCDwarfLoc.
Definition: MCDwarf.h:179
unsigned getFlags() const
Get the Flags of this MCDwarfLoc.
Definition: MCDwarf.h:146
unsigned getColumn() const
Get the Column of this MCDwarfLoc.
Definition: MCDwarf.h:143
void setFlags(unsigned flags)
Set the Flags of this MCDwarfLoc.
Definition: MCDwarf.h:167
unsigned getDiscriminator() const
Get the Discriminator of this MCDwarfLoc.
Definition: MCDwarf.h:152
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
Definition: MCDwarf.h:161
unsigned getFileNum() const
Get the FileNum of this MCDwarfLoc.
Definition: MCDwarf.h:137
void setFileNum(unsigned fileNum)
Set the FileNum of this MCDwarfLoc.
Definition: MCDwarf.h:155
static LLVM_ABI void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1185
MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber, MCSymbol *label)
Definition: MCDwarf.h:493
StringRef getName() const
Definition: MCDwarf.h:498
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
Definition: MCDwarf.cpp:1248
MCSymbol * getLabel() const
Definition: MCDwarf.h:501
unsigned getLineNumber() const
Definition: MCDwarf.h:500
unsigned getFileNumber() const
Definition: MCDwarf.h:499
Instances of this class represent the line information for a compile unit where machine instructions ...
Definition: MCDwarf.h:237
const MCLineDivisionMap & getMCLineEntries() const
Definition: MCDwarf.h:259
LLVM_ABI void addEndEntry(MCSymbol *EndLabel)
Definition: MCDwarf.cpp:142
MCDwarfLineEntryCollection::const_iterator const_iterator
Definition: MCDwarf.h:250
MCDwarfLineEntryCollection::iterator iterator
Definition: MCDwarf.h:249
void addLineEntry(const MCDwarfLineEntry &LineEntry, MCSection *Sec)
Definition: MCDwarf.h:240
std::vector< MCDwarfLineEntry > MCDwarfLineEntryCollection
Definition: MCDwarf.h:248
Streaming object file generation interface.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Represents a location in source code.
Definition: SMLoc.h:23
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:32
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition: StringSaver.h:22
Utility for building string tables with deduplicated suffixes.
LLVM_ABI MCSymbol * emitListsTableHeaderStart(MCStreamer &S)
Definition: MCDwarf.cpp:44
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
SourceMgr SrcMgr
Definition: Error.cpp:24
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition: Casting.h:548
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:769
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
Definition: MCDwarf.h:88
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
Definition: MCDwarf.h:97
std::string Name
Definition: MCDwarf.h:90
std::optional< StringRef > Source
The source code of the file.
Definition: MCDwarf.h:101
unsigned DirIndex
Definition: MCDwarf.h:93
const MCSymbol * Personality
Definition: MCDwarf.h:774
unsigned PersonalityEncoding
Definition: MCDwarf.h:778
uint64_t CompactUnwindEncoding
Definition: MCDwarf.h:780
MCSymbol * Begin
Definition: MCDwarf.h:772
std::vector< MCCFIInstruction > Instructions
Definition: MCDwarf.h:776
unsigned LsdaEncoding
Definition: MCDwarf.h:779
const MCSymbol * Lsda
Definition: MCDwarf.h:775
unsigned CurrentCfaRegister
Definition: MCDwarf.h:777
void trackMD5Usage(bool MD5Used)
Definition: MCDwarf.h:310
SmallVector< MCDwarfFile, 3 > MCDwarfFiles
Definition: MCDwarf.h:280
bool isMD5UsageConsistent() const
Definition: MCDwarf.h:314
SmallVector< std::string, 3 > MCDwarfDirs
Definition: MCDwarf.h:279
LLVM_ABI std::pair< MCSymbol *, MCSymbol * > Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, std::optional< MCDwarfLineStr > &LineStr) const
Definition: MCDwarf.cpp:335
std::string CompilationDir
Definition: MCDwarf.h:282
StringMap< unsigned > SourceIdMap
Definition: MCDwarf.h:281
void setRootFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
Definition: MCDwarf.h:318
LLVM_ABI Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.cpp:638
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
Definition: MCDwarf.h:269
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
Definition: MCDwarf.h:274
int8_t DWARF2LineBase
Minimum line offset in a special line info.
Definition: MCDwarf.h:272