Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
DWARFDebugRnglists.cpp
Go to the documentation of this file.
1//===- DWARFDebugRnglists.cpp ---------------------------------------------===//
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 "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
10#include "llvm/BinaryFormat/Dwarf.h"
11#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
12#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
13#include "llvm/Support/Errc.h"
14#include "llvm/Support/Error.h"
15#include "llvm/Support/Format.h"
16#include "llvm/Support/raw_ostream.h"
17
18using namespacellvm;
19
20ErrorRangeListEntry::extract(DWARFDataExtractor Data,uint64_t *OffsetPtr) {
21Offset = *OffsetPtr;
22SectionIndex = -1ULL;
23// The caller should guarantee that we have at least 1 byte available, so
24// we just assert instead of revalidate.
25assert(*OffsetPtr <Data.size() &&
26"not enough space to extract a rangelist encoding");
27uint8_t Encoding =Data.getU8(OffsetPtr);
28
29DataExtractor::CursorC(*OffsetPtr);
30switch (Encoding) {
31case dwarf::DW_RLE_end_of_list:
32Value0 =Value1 = 0;
33break;
34// TODO: Support other encodings.
35case dwarf::DW_RLE_base_addressx: {
36Value0 =Data.getULEB128(C);
37break;
38 }
39case dwarf::DW_RLE_startx_endx:
40Value0 =Data.getULEB128(C);
41Value1 =Data.getULEB128(C);
42break;
43case dwarf::DW_RLE_startx_length: {
44Value0 =Data.getULEB128(C);
45Value1 =Data.getULEB128(C);
46break;
47 }
48case dwarf::DW_RLE_offset_pair: {
49Value0 =Data.getULEB128(C);
50Value1 =Data.getULEB128(C);
51break;
52 }
53case dwarf::DW_RLE_base_address: {
54Value0 =Data.getRelocatedAddress(C, &SectionIndex);
55break;
56 }
57case dwarf::DW_RLE_start_end: {
58Value0 =Data.getRelocatedAddress(C, &SectionIndex);
59Value1 =Data.getRelocatedAddress(C);
60break;
61 }
62case dwarf::DW_RLE_start_length: {
63Value0 =Data.getRelocatedAddress(C, &SectionIndex);
64Value1 =Data.getULEB128(C);
65break;
66 }
67default:
68consumeError(C.takeError());
69returncreateStringError(errc::not_supported,
70"unknown rnglists encoding 0x%" PRIx32
71" at offset 0x%" PRIx64,
72uint32_t(Encoding),Offset);
73 }
74
75if (!C) {
76consumeError(C.takeError());
77returncreateStringError(
78errc::invalid_argument,
79"read past end of table when reading %s encoding at offset 0x%" PRIx64,
80dwarf::RLEString(Encoding).data(),Offset);
81 }
82
83 *OffsetPtr =C.tell();
84EntryKind = Encoding;
85returnError::success();
86}
87
88DWARFAddressRangesVectorDWARFDebugRnglist::getAbsoluteRanges(
89 std::optional<object::SectionedAddress> BaseAddr,DWARFUnit &U) const{
90returngetAbsoluteRanges(
91 BaseAddr, U.getAddressByteSize(),
92 [&](uint32_t Index) { return U.getAddrOffsetSectionItem(Index); });
93}
94
95DWARFAddressRangesVectorDWARFDebugRnglist::getAbsoluteRanges(
96 std::optional<object::SectionedAddress> BaseAddr,uint8_t AddressByteSize,
97function_ref<std::optional<object::SectionedAddress>(uint32_t)>
98 LookupPooledAddress) const{
99DWARFAddressRangesVector Res;
100uint64_t Tombstone =dwarf::computeTombstoneAddress(AddressByteSize);
101for (constRangeListEntry &RLE :Entries) {
102if (RLE.EntryKind == dwarf::DW_RLE_end_of_list)
103break;
104if (RLE.EntryKind == dwarf::DW_RLE_base_addressx) {
105 BaseAddr = LookupPooledAddress(RLE.Value0);
106if (!BaseAddr)
107 BaseAddr = {RLE.Value0, -1ULL};
108continue;
109 }
110if (RLE.EntryKind == dwarf::DW_RLE_base_address) {
111 BaseAddr = {RLE.Value0, RLE.SectionIndex};
112continue;
113 }
114
115DWARFAddressRange E;
116 E.SectionIndex = RLE.SectionIndex;
117if (BaseAddr && E.SectionIndex == -1ULL)
118 E.SectionIndex = BaseAddr->SectionIndex;
119
120switch (RLE.EntryKind) {
121case dwarf::DW_RLE_offset_pair:
122 E.LowPC = RLE.Value0;
123if (E.LowPC == Tombstone)
124continue;
125 E.HighPC = RLE.Value1;
126if (BaseAddr) {
127if (BaseAddr->Address == Tombstone)
128continue;
129 E.LowPC += BaseAddr->Address;
130 E.HighPC += BaseAddr->Address;
131 }
132break;
133case dwarf::DW_RLE_start_end:
134 E.LowPC = RLE.Value0;
135 E.HighPC = RLE.Value1;
136break;
137case dwarf::DW_RLE_start_length:
138 E.LowPC = RLE.Value0;
139 E.HighPC = E.LowPC + RLE.Value1;
140break;
141case dwarf::DW_RLE_startx_length: {
142auto Start = LookupPooledAddress(RLE.Value0);
143if (!Start)
144 Start = {0, -1ULL};
145 E.SectionIndex = Start->SectionIndex;
146 E.LowPC = Start->Address;
147 E.HighPC = E.LowPC + RLE.Value1;
148break;
149 }
150case dwarf::DW_RLE_startx_endx: {
151auto Start = LookupPooledAddress(RLE.Value0);
152if (!Start)
153 Start = {0, -1ULL};
154autoEnd = LookupPooledAddress(RLE.Value1);
155if (!End)
156End = {0, -1ULL};
157// FIXME: Some error handling if Start.SectionIndex != End.SectionIndex
158 E.SectionIndex = Start->SectionIndex;
159 E.LowPC = Start->Address;
160 E.HighPC =End->Address;
161break;
162 }
163default:
164// Unsupported encodings should have been reported during extraction,
165// so we should not run into any here.
166llvm_unreachable("Unsupported range list encoding");
167 }
168if (E.LowPC == Tombstone)
169continue;
170 Res.push_back(E);
171 }
172return Res;
173}
174
175voidRangeListEntry::dump(
176raw_ostream &OS,uint8_t AddrSize,uint8_t MaxEncodingStringLength,
177uint64_t &CurrentBase,DIDumpOptions DumpOpts,
178llvm::function_ref<std::optional<object::SectionedAddress>(uint32_t)>
179 LookupPooledAddress) const{
180auto PrintRawEntry = [](raw_ostream &OS,constRangeListEntry &Entry,
181uint8_t AddrSize,DIDumpOptions DumpOpts) {
182if (DumpOpts.Verbose) {
183 DumpOpts.DisplayRawContents =true;
184DWARFAddressRange(Entry.Value0, Entry.Value1)
185 .dump(OS, AddrSize, DumpOpts);
186OS <<" => ";
187 }
188 };
189
190if (DumpOpts.Verbose) {
191// Print the section offset in verbose mode.
192OS <<format("0x%8.8" PRIx64":",Offset);
193auto EncodingString =dwarf::RangeListEncodingString(EntryKind);
194// Unsupported encodings should have been reported during parsing.
195assert(!EncodingString.empty() &&"Unknown range entry encoding");
196OS <<format(" [%s%*c", EncodingString.data(),
197 MaxEncodingStringLength - EncodingString.size() + 1,']');
198if (EntryKind != dwarf::DW_RLE_end_of_list)
199OS <<": ";
200 }
201
202uint64_t Tombstone =dwarf::computeTombstoneAddress(AddrSize);
203
204switch (EntryKind) {
205case dwarf::DW_RLE_end_of_list:
206OS << (DumpOpts.Verbose ?"" :"<End of list>");
207break;
208case dwarf::DW_RLE_base_addressx: {
209if (auto SA = LookupPooledAddress(Value0))
210 CurrentBase = SA->Address;
211else
212 CurrentBase =Value0;
213if (!DumpOpts.Verbose)
214return;
215DWARFFormValue::dumpAddress(OS <<' ', AddrSize,Value0);
216break;
217 }
218case dwarf::DW_RLE_base_address:
219// In non-verbose mode we do not print anything for this entry.
220 CurrentBase =Value0;
221if (!DumpOpts.Verbose)
222return;
223DWARFFormValue::dumpAddress(OS <<' ', AddrSize,Value0);
224break;
225case dwarf::DW_RLE_start_length:
226 PrintRawEntry(OS, *this, AddrSize, DumpOpts);
227DWARFAddressRange(Value0,Value0 +Value1).dump(OS, AddrSize, DumpOpts);
228break;
229case dwarf::DW_RLE_offset_pair:
230 PrintRawEntry(OS, *this, AddrSize, DumpOpts);
231if (CurrentBase != Tombstone)
232DWARFAddressRange(Value0 + CurrentBase,Value1 + CurrentBase)
233 .dump(OS, AddrSize, DumpOpts);
234else
235OS <<"dead code";
236break;
237case dwarf::DW_RLE_start_end:
238DWARFAddressRange(Value0,Value1).dump(OS, AddrSize, DumpOpts);
239break;
240case dwarf::DW_RLE_startx_length: {
241 PrintRawEntry(OS, *this, AddrSize, DumpOpts);
242uint64_t Start = 0;
243if (auto SA = LookupPooledAddress(Value0))
244 Start = SA->Address;
245DWARFAddressRange(Start, Start +Value1).dump(OS, AddrSize, DumpOpts);
246break;
247 }
248case dwarf::DW_RLE_startx_endx: {
249 PrintRawEntry(OS, *this, AddrSize, DumpOpts);
250uint64_t Start = 0;
251if (auto SA = LookupPooledAddress(Value0))
252 Start = SA->Address;
253uint64_tEnd = 0;
254if (auto SA = LookupPooledAddress(Value1))
255End = SA->Address;
256DWARFAddressRange(Start,End).dump(OS, AddrSize, DumpOpts);
257break;
258 }
259default:
260llvm_unreachable("Unsupported range list encoding");
261 }
262OS <<"\n";
263}
DWARFDebugRnglists.h
DWARFFormValue.h
DWARFUnit.h
Dwarf.h
This file contains constants used for implementing Dwarf debug support.
End
bool End
Definition:ELF_riscv.cpp:480
Errc.h
Format.h
if
if(PassOpts->AAPipeline)
Definition:PassBuilderBindings.cpp:64
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
data
static Split data
Definition:StaticDataSplitter.cpp:176
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition:DWARFDataExtractor.h:21
llvm::DWARFDebugRnglist::getAbsoluteRanges
DWARFAddressRangesVector getAbsoluteRanges(std::optional< object::SectionedAddress > BaseAddr, uint8_t AddressByteSize, function_ref< std::optional< object::SectionedAddress >(uint32_t)> LookupPooledAddress) const
Build a DWARFAddressRangesVector from a rangelist.
Definition:DWARFDebugRnglists.cpp:95
llvm::DWARFFormValue::dumpAddress
void dumpAddress(raw_ostream &OS, uint64_t Address) const
llvm::DWARFListType< RangeListEntry >::Entries
ListEntries Entries
Definition:DWARFListTable.h:42
llvm::DWARFUnit
Definition:DWARFUnit.h:211
llvm::DataExtractor::Cursor
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition:DataExtractor.h:54
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition:STLFunctionalExtras.h:37
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
uint32_t
uint64_t
uint8_t
llvm::dwarf::RangeListEncodingString
StringRef RangeListEncodingString(unsigned Encoding)
Definition:Dwarf.cpp:591
llvm::dwarf::RLEString
StringRef RLEString(unsigned RLE)
Definition:Dwarf.cpp:882
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
Error.h
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::dwarf::computeTombstoneAddress
uint64_t computeTombstoneAddress(uint8_t AddressByteSize)
Definition:Dwarf.h:1212
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::DWARFAddressRangesVector
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Definition:DWARFAddressRange.h:88
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition:Error.h:1291
llvm::errc::not_supported
@ not_supported
llvm::errc::invalid_argument
@ invalid_argument
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
raw_ostream.h
llvm::DIDumpOptions
Container for dump options that control which debug information will be dumped.
Definition:DIContext.h:196
llvm::DIDumpOptions::Verbose
bool Verbose
Definition:DIContext.h:207
llvm::DIDumpOptions::DisplayRawContents
bool DisplayRawContents
Definition:DIContext.h:208
llvm::DWARFAddressRange
Definition:DWARFAddressRange.h:25
llvm::DWARFAddressRange::LowPC
uint64_t LowPC
Definition:DWARFAddressRange.h:26
llvm::DWARFAddressRange::SectionIndex
uint64_t SectionIndex
Definition:DWARFAddressRange.h:28
llvm::DWARFAddressRange::HighPC
uint64_t HighPC
Definition:DWARFAddressRange.h:27
llvm::DWARFAddressRange::dump
void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts={}, const DWARFObject *Obj=nullptr) const
Definition:DWARFAddressRange.cpp:16
llvm::DWARFListEntryBase::SectionIndex
uint64_t SectionIndex
The index of the section this entry belongs to.
Definition:DWARFListTable.h:32
llvm::DWARFListEntryBase::EntryKind
uint8_t EntryKind
The DWARF encoding (DW_RLE_* or DW_LLE_*).
Definition:DWARFListTable.h:30
llvm::DWARFListEntryBase::Offset
uint64_t Offset
The offset at which the entry is located in the section.
Definition:DWARFListTable.h:28
llvm::RangeListEntry
A class representing a single range list entry.
Definition:DWARFDebugRnglists.h:30
llvm::RangeListEntry::extract
Error extract(DWARFDataExtractor Data, uint64_t *OffsetPtr)
Definition:DWARFDebugRnglists.cpp:20
llvm::RangeListEntry::Value1
uint64_t Value1
Definition:DWARFDebugRnglists.h:36
llvm::RangeListEntry::dump
void dump(raw_ostream &OS, uint8_t AddrSize, uint8_t MaxEncodingStringLength, uint64_t &CurrentBase, DIDumpOptions DumpOpts, llvm::function_ref< std::optional< object::SectionedAddress >(uint32_t)> LookupPooledAddress) const
Definition:DWARFDebugRnglists.cpp:175
llvm::RangeListEntry::Value0
uint64_t Value0
The values making up the range list entry.
Definition:DWARFDebugRnglists.h:35

Generated on Sun Jul 20 2025 09:09:06 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp