Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
DWARFDataExtractor.cpp
Go to the documentation of this file.
1//===- DWARFDataExtractor.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/DWARFDataExtractor.h"
10#include "llvm/DebugInfo/DWARF/DWARFObject.h"
11#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
12#include "llvm/Support/Errc.h"
13
14using namespacellvm;
15
16std::pair<uint64_t, dwarf::DwarfFormat>
17DWARFDataExtractor::getInitialLength(uint64_t *Off,Error *Err) const{
18ErrorAsOutParameter ErrAsOut(Err);
19if (Err && *Err)
20return {0,dwarf::DWARF32};
21
22CursorC(*Off);
23uint64_tLength =getRelocatedValue(C, 4);
24dwarf::DwarfFormatFormat =dwarf::DWARF32;
25if (Length ==dwarf::DW_LENGTH_DWARF64) {
26Length =getRelocatedValue(C, 8);
27Format =dwarf::DWARF64;
28 }elseif (Length >=dwarf::DW_LENGTH_lo_reserved) {
29cantFail(C.takeError());
30if (Err)
31 *Err =createStringError(
32errc::invalid_argument,
33"unsupported reserved unit length of value 0x%8.8" PRIx64,Length);
34return {0,dwarf::DWARF32};
35 }
36
37if (C) {
38 *Off =C.tell();
39return {Length,Format};
40 }
41if (Err)
42 *Err =C.takeError();
43else
44consumeError(C.takeError());
45return {0,dwarf::DWARF32};
46}
47
48uint64_tDWARFDataExtractor::getRelocatedValue(uint32_tSize,uint64_t *Off,
49uint64_t *SecNdx,
50Error *Err) const{
51if (SecNdx)
52 *SecNdx =object::SectionedAddress::UndefSection;
53if (!Section)
54returngetUnsigned(Off,Size, Err);
55
56ErrorAsOutParameter ErrAsOut(Err);
57 std::optional<RelocAddrEntry> E = Obj->find(*Section, *Off);
58uint64_t LocData =getUnsigned(Off,Size, Err);
59if (!E || (Err && *Err))
60return LocData;
61if (SecNdx)
62 *SecNdx = E->SectionIndex;
63
64uint64_t R =
65object::resolveRelocation(E->Resolver, E->Reloc, E->SymbolValue, LocData);
66if (E->Reloc2)
67 R =object::resolveRelocation(E->Resolver, *E->Reloc2, E->SymbolValue2, R);
68return R;
69}
70
71std::optional<uint64_t>
72DWARFDataExtractor::getEncodedPointer(uint64_t *Offset,uint8_t Encoding,
73uint64_t PCRelOffset) const{
74if (Encoding ==dwarf::DW_EH_PE_omit)
75return std::nullopt;
76
77uint64_t Result = 0;
78uint64_t OldOffset = *Offset;
79// First get value
80switch (Encoding & 0x0F) {
81casedwarf::DW_EH_PE_absptr:
82switch (getAddressSize()) {
83case 2:
84case 4:
85case 8:
86 Result =getUnsigned(Offset,getAddressSize());
87break;
88default:
89return std::nullopt;
90 }
91break;
92casedwarf::DW_EH_PE_uleb128:
93 Result =getULEB128(Offset);
94break;
95casedwarf::DW_EH_PE_sleb128:
96 Result =getSLEB128(Offset);
97break;
98casedwarf::DW_EH_PE_udata2:
99 Result =getUnsigned(Offset, 2);
100break;
101casedwarf::DW_EH_PE_udata4:
102 Result =getUnsigned(Offset, 4);
103break;
104casedwarf::DW_EH_PE_udata8:
105 Result =getUnsigned(Offset, 8);
106break;
107casedwarf::DW_EH_PE_sdata2:
108 Result =getSigned(Offset, 2);
109break;
110casedwarf::DW_EH_PE_sdata4:
111 Result = SignExtend64<32>(getRelocatedValue(4,Offset));
112break;
113casedwarf::DW_EH_PE_sdata8:
114 Result =getRelocatedValue(8,Offset);
115break;
116default:
117return std::nullopt;
118 }
119// Then add relative offset, if required
120switch (Encoding & 0x70) {
121casedwarf::DW_EH_PE_absptr:
122// do nothing
123break;
124casedwarf::DW_EH_PE_pcrel:
125 Result += PCRelOffset;
126break;
127casedwarf::DW_EH_PE_datarel:
128casedwarf::DW_EH_PE_textrel:
129casedwarf::DW_EH_PE_funcrel:
130casedwarf::DW_EH_PE_aligned:
131default:
132 *Offset = OldOffset;
133return std::nullopt;
134 }
135
136return Result;
137}
DWARFDataExtractor.h
DWARFObject.h
DWARFRelocMap.h
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
Errc.h
llvm::DWARFDataExtractor::getInitialLength
std::pair< uint64_t, dwarf::DwarfFormat > getInitialLength(uint64_t *Off, Error *Err=nullptr) const
Extracts the DWARF "initial length" field, which can either be a 32-bit value smaller than 0xfffffff0...
Definition:DWARFDataExtractor.cpp:17
llvm::DWARFDataExtractor::getRelocatedValue
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset.
Definition:DWARFDataExtractor.cpp:48
llvm::DWARFDataExtractor::getEncodedPointer
std::optional< uint64_t > getEncodedPointer(uint64_t *Offset, uint8_t Encoding, uint64_t AbsPosOffset=0) const
Extracts a DWARF-encoded pointer in Offset using Encoding.
Definition:DWARFDataExtractor.cpp:72
llvm::DWARFObject::find
virtual std::optional< RelocAddrEntry > find(const DWARFSection &Sec, uint64_t Pos) const =0
llvm::DataExtractor::Cursor
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition:DataExtractor.h:54
llvm::DataExtractor::getUnsigned
uint64_t getUnsigned(uint64_t *offset_ptr, uint32_t byte_size, Error *Err=nullptr) const
Extract an unsigned integer of size byte_size from *offset_ptr.
Definition:DataExtractor.cpp:126
llvm::DataExtractor::getSigned
int64_t getSigned(uint64_t *offset_ptr, uint32_t size) const
Extract an signed integer of size byte_size from *offset_ptr.
Definition:DataExtractor.cpp:142
llvm::DataExtractor::getULEB128
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition:DataExtractor.cpp:221
llvm::DataExtractor::getAddressSize
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition:DataExtractor.h:99
llvm::DataExtractor::getSLEB128
int64_t getSLEB128(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a signed LEB128 value from *offset_ptr.
Definition:DataExtractor.cpp:225
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition:Error.h:1130
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
uint32_t
uint64_t
uint8_t
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::dwarf::DwarfFormat
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition:Dwarf.h:91
llvm::dwarf::DWARF64
@ DWARF64
Definition:Dwarf.h:91
llvm::dwarf::DWARF32
@ DWARF32
Definition:Dwarf.h:91
llvm::dwarf::DW_EH_PE_textrel
@ DW_EH_PE_textrel
Definition:Dwarf.h:859
llvm::dwarf::DW_EH_PE_datarel
@ DW_EH_PE_datarel
Definition:Dwarf.h:860
llvm::dwarf::DW_EH_PE_pcrel
@ DW_EH_PE_pcrel
Definition:Dwarf.h:858
llvm::dwarf::DW_EH_PE_sdata4
@ DW_EH_PE_sdata4
Definition:Dwarf.h:855
llvm::dwarf::DW_EH_PE_funcrel
@ DW_EH_PE_funcrel
Definition:Dwarf.h:861
llvm::dwarf::DW_EH_PE_aligned
@ DW_EH_PE_aligned
Definition:Dwarf.h:862
llvm::dwarf::DW_EH_PE_udata2
@ DW_EH_PE_udata2
Definition:Dwarf.h:850
llvm::dwarf::DW_EH_PE_sdata8
@ DW_EH_PE_sdata8
Definition:Dwarf.h:856
llvm::dwarf::DW_EH_PE_absptr
@ DW_EH_PE_absptr
Definition:Dwarf.h:847
llvm::dwarf::DW_EH_PE_sdata2
@ DW_EH_PE_sdata2
Definition:Dwarf.h:854
llvm::dwarf::DW_EH_PE_udata4
@ DW_EH_PE_udata4
Definition:Dwarf.h:851
llvm::dwarf::DW_EH_PE_udata8
@ DW_EH_PE_udata8
Definition:Dwarf.h:852
llvm::dwarf::DW_EH_PE_uleb128
@ DW_EH_PE_uleb128
Definition:Dwarf.h:849
llvm::dwarf::DW_EH_PE_sleb128
@ DW_EH_PE_sleb128
Definition:Dwarf.h:853
llvm::dwarf::DW_EH_PE_omit
@ DW_EH_PE_omit
Definition:Dwarf.h:848
llvm::dwarf::DW_LENGTH_lo_reserved
@ DW_LENGTH_lo_reserved
Special values for an initial length field.
Definition:Dwarf.h:54
llvm::dwarf::DW_LENGTH_DWARF64
@ DW_LENGTH_DWARF64
Indicator of 64-bit DWARF format.
Definition:Dwarf.h:55
llvm::object::resolveRelocation
uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R, uint64_t S, uint64_t LocData)
Definition:RelocationResolver.cpp:875
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::Length
@ Length
Definition:DWP.cpp:480
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition:Error.h:1291
llvm::errc::invalid_argument
@ invalid_argument
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::ReplacementType::Format
@ Format
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
llvm::object::SectionedAddress::UndefSection
static const uint64_t UndefSection
Definition:ObjectFile.h:146

Generated on Thu Jul 17 2025 11:55:37 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp