Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
DwarfFile.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/DwarfFile.cpp - Dwarf Debug Framework -----------------===//
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#include "DwarfFile.h"
10#include "DwarfCompileUnit.h"
11#include "DwarfDebug.h"
12#include "DwarfUnit.h"
13#include "llvm/CodeGen/AsmPrinter.h"
14#include "llvm/IR/DebugInfoMetadata.h"
15#include "llvm/MC/MCStreamer.h"
16#include <cstdint>
17
18using namespacellvm;
19
20DwarfFile::DwarfFile(AsmPrinter *AP,StringRef Pref,BumpPtrAllocator &DA)
21 : Asm(AP), Abbrevs(AbbrevAllocator), StrPool(DA, *Asm, Pref) {}
22
23voidDwarfFile::addUnit(std::unique_ptr<DwarfCompileUnit> U) {
24 CUs.push_back(std::move(U));
25}
26
27// Emit the various dwarf units to the unit section USection with
28// the abbreviations going into ASection.
29voidDwarfFile::emitUnits(bool UseOffsets) {
30for (constauto &TheU : CUs)
31emitUnit(TheU.get(), UseOffsets);
32}
33
34voidDwarfFile::emitUnit(DwarfUnit *TheU,bool UseOffsets) {
35if (TheU->getCUNode()->isDebugDirectivesOnly())
36return;
37
38MCSection *S = TheU->getSection();
39
40if (!S)
41return;
42
43// Skip CUs that ended up not being needed (split CUs that were abandoned
44// because they added no information beyond the non-split CU)
45if (TheU->getUnitDie().values().empty())
46return;
47
48 Asm->OutStreamer->switchSection(S);
49 TheU->emitHeader(UseOffsets);
50 Asm->emitDwarfDIE(TheU->getUnitDie());
51
52if (MCSymbol *EndLabel = TheU->getEndLabel())
53 Asm->OutStreamer->emitLabel(EndLabel);
54}
55
56// Compute the size and offset for each DIE.
57voidDwarfFile::computeSizeAndOffsets() {
58// Offset from the first CU in the debug info section is 0 initially.
59uint64_t SecOffset = 0;
60
61// Iterate over each compile unit and set the size and offsets for each
62// DIE within each compile unit. All offsets are CU relative.
63for (constauto &TheU : CUs) {
64if (TheU->getCUNode()->isDebugDirectivesOnly())
65continue;
66
67// Skip CUs that ended up not being needed (split CUs that were abandoned
68// because they added no information beyond the non-split CU)
69if (TheU->getUnitDie().values().empty())
70return;
71
72 TheU->setDebugSectionOffset(SecOffset);
73 SecOffset +=computeSizeAndOffsetsForUnit(TheU.get());
74 }
75if (SecOffset > UINT32_MAX && !Asm->isDwarf64())
76report_fatal_error("The generated debug information is too large "
77"for the 32-bit DWARF format.");
78}
79
80unsignedDwarfFile::computeSizeAndOffsetsForUnit(DwarfUnit *TheU) {
81// CU-relative offset is reset to 0 here.
82unsignedOffset = Asm->getUnitLengthFieldByteSize() +// Length of Unit Info
83 TheU->getHeaderSize();// Unit-specific headers
84
85// The return value here is CU-relative, after laying out
86// all of the CU DIE.
87returncomputeSizeAndOffset(TheU->getUnitDie(),Offset);
88}
89
90// Compute the size and offset of a DIE. The offset is relative to start of the
91// CU. It returns the offset after laying out the DIE.
92unsignedDwarfFile::computeSizeAndOffset(DIE &Die,unsignedOffset) {
93return Die.computeOffsetsAndAbbrevs(Asm->getDwarfFormParams(), Abbrevs,
94Offset);
95}
96
97voidDwarfFile::emitAbbrevs(MCSection *Section) { Abbrevs.Emit(Asm, Section); }
98
99// Emit strings into a string section.
100voidDwarfFile::emitStrings(MCSection *StrSection,MCSection *OffsetSection,
101bool UseRelativeOffsets) {
102 StrPool.emit(*Asm, StrSection, OffsetSection, UseRelativeOffsets);
103}
104
105voidDwarfFile::addScopeVariable(LexicalScope *LS,DbgVariable *Var) {
106auto &ScopeVars = ScopeVariables[LS];
107constDILocalVariable *DV = Var->getVariable();
108if (unsigned ArgNum = DV->getArg()) {
109auto Ret = ScopeVars.Args.insert({ArgNum, Var});
110assert(Ret.second);
111 (void)Ret;
112 }else {
113 ScopeVars.Locals.push_back(Var);
114 }
115}
116
117voidDwarfFile::addScopeLabel(LexicalScope *LS,DbgLabel *Label) {
118SmallVectorImpl<DbgLabel *> &Labels = ScopeLabels[LS];
119 Labels.push_back(Label);
120}
121
122std::pair<uint32_t, RangeSpanList *>
123DwarfFile::addRange(constDwarfCompileUnit &CU,SmallVector<RangeSpan, 2> R) {
124bool CanReuseLastRange =false;
125
126if (!CURangeLists.empty()) {
127autoLast = CURangeLists.back();
128if (Last.CU == &CU &&Last.Ranges == R) {
129 CanReuseLastRange =true;
130 }
131 }
132
133if (!CanReuseLastRange) {
134 CURangeLists.push_back(RangeSpanList{Asm->createTempSymbol("debug_ranges"),
135 &CU, std::move(R)});
136 }
137
138return std::make_pair(CURangeLists.size() - 1, &CURangeLists.back());
139}
AsmPrinter.h
DebugInfoMetadata.h
DwarfCompileUnit.h
DwarfDebug.h
DwarfFile.h
DwarfUnit.h
MCStreamer.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition:AsmPrinter.h:87
llvm::AsmPrinter::isDwarf64
bool isDwarf64() const
Definition:AsmPrinter.cpp:4609
llvm::AsmPrinter::emitDwarfDIE
void emitDwarfDIE(const DIE &Die) const
Recursively emit Dwarf DIE tree.
Definition:AsmPrinterDwarf.cpp:269
llvm::AsmPrinter::getUnitLengthFieldByteSize
unsigned int getUnitLengthFieldByteSize() const
Returns 4 for DWARF32 and 12 for DWARF64.
Definition:AsmPrinter.cpp:4624
llvm::AsmPrinter::createTempSymbol
MCSymbol * createTempSymbol(const Twine &Name) const
Definition:AsmPrinter.cpp:4075
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition:AsmPrinter.h:102
llvm::AsmPrinter::getDwarfFormParams
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
Definition:AsmPrinter.cpp:4618
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition:Allocator.h:66
llvm::DICompileUnit::isDebugDirectivesOnly
bool isDebugDirectivesOnly() const
Definition:DebugInfoMetadata.h:1598
llvm::DIEAbbrevSet::Emit
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition:DIE.cpp:160
llvm::DIEUnit::getSection
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
Definition:DIE.h:996
llvm::DIEUnit::getUnitDie
DIE & getUnitDie()
Definition:DIE.h:999
llvm::DIEValueList::values
value_range values()
Definition:DIE.h:807
llvm::DIE
A structured debug information entry.
Definition:DIE.h:819
llvm::DIE::computeOffsetsAndAbbrevs
unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition:DIE.cpp:266
llvm::DILocalVariable
Local variable.
Definition:DebugInfoMetadata.h:3460
llvm::DILocalVariable::getArg
unsigned getArg() const
Definition:DebugInfoMetadata.h:3523
llvm::DbgLabel
This class is used to track label information.
Definition:DwarfDebug.h:289
llvm::DbgVariable
This class is used to track local variable information.
Definition:DwarfDebug.h:214
llvm::DbgVariable::getVariable
const DILocalVariable * getVariable() const
Definition:DwarfDebug.h:246
llvm::DwarfCompileUnit
Definition:DwarfCompileUnit.h:45
llvm::DwarfFile::computeSizeAndOffset
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition:DwarfFile.cpp:92
llvm::DwarfFile::addScopeLabel
void addScopeLabel(LexicalScope *LS, DbgLabel *Label)
Definition:DwarfFile.cpp:117
llvm::DwarfFile::addUnit
void addUnit(std::unique_ptr< DwarfCompileUnit > U)
Add a unit to the list of CUs.
Definition:DwarfFile.cpp:23
llvm::DwarfFile::computeSizeAndOffsets
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition:DwarfFile.cpp:57
llvm::DwarfFile::computeSizeAndOffsetsForUnit
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU)
Compute the size and offset of all the DIEs in the given unit.
Definition:DwarfFile.cpp:80
llvm::DwarfFile::emitUnits
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition:DwarfFile.cpp:29
llvm::DwarfFile::emitUnit
void emitUnit(DwarfUnit *TheU, bool UseOffsets)
Emit the given unit to its section.
Definition:DwarfFile.cpp:34
llvm::DwarfFile::emitAbbrevs
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition:DwarfFile.cpp:97
llvm::DwarfFile::DwarfFile
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition:DwarfFile.cpp:20
llvm::DwarfFile::emitStrings
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Emit all of the strings to the section given.
Definition:DwarfFile.cpp:100
llvm::DwarfFile::addScopeVariable
void addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition:DwarfFile.cpp:105
llvm::DwarfFile::addRange
std::pair< uint32_t, RangeSpanList * > addRange(const DwarfCompileUnit &CU, SmallVector< RangeSpan, 2 > R)
Definition:DwarfFile.cpp:123
llvm::DwarfStringPool::emit
void emit(AsmPrinter &Asm, MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Definition:DwarfStringPool.cpp:75
llvm::DwarfUnit
This dwarf writer support class manages information associated with a source file.
Definition:DwarfUnit.h:35
llvm::DwarfUnit::emitHeader
virtual void emitHeader(bool UseOffsets)=0
Emit the header for this unit, not including the initial length field.
llvm::DwarfUnit::getHeaderSize
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
Definition:DwarfUnit.h:285
llvm::DwarfUnit::getEndLabel
MCSymbol * getEndLabel() const
Definition:DwarfUnit.h:109
llvm::DwarfUnit::getCUNode
const DICompileUnit * getCUNode() const
Definition:DwarfUnit.h:111
llvm::LexicalScope
LexicalScope - This class is used to track scope information.
Definition:LexicalScopes.h:44
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition:MCSection.h:36
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition:MCSymbol.h:41
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::iterator_range::empty
bool empty() const
Definition:iterator_range.h:66
uint64_t
CU
Definition:AArch64AsmBackend.cpp:549
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::PseudoProbeReservedId::Last
@ Last
llvm::RangeSpanList
Definition:DwarfFile.h:46

Generated on Fri Jul 18 2025 10:27:57 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp