LLVM: lib/DebugInfo/DWARF/DWARFDebugFrame.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

28#include

29#include

30#include

31#include

32

33using namespace llvm;

34using namespace dwarf;

35

38 if (Cie == nullptr)

40 "unable to get CIE for FDE at offset 0x%" PRIx64,

42

43

46

50 if (Error CieError = parseRows(Cie->cfis(), Row, nullptr).moveInto(CieRows))

51 return std::move(CieError);

52

53

56 if (Error FdeError =

57 parseRows(Fde->cfis(), Row, &InitialLocs).moveInto(FdeRows))

58 return std::move(FdeError);

59

61 AllRows.insert(AllRows.end(), CieRows.begin(), CieRows.end());

62 AllRows.insert(AllRows.end(), FdeRows.begin(), FdeRows.end());

63

64

65

66 if (Row.getRegisterLocations().hasLocations() ||

68 AllRows.push_back(Row);

70}

71

73

76

79 if (Error CieError = parseRows(Cie->cfis(), Row, nullptr).moveInto(Rows))

80 return std::move(CieError);

81

82

83 if (Row.getRegisterLocations().hasLocations() ||

85 Rows.push_back(Row);

87}

88

89

90

91

92

94 if (IsEH)

95 return 0;

96 if (IsDWARF64)

99}

100

102

104 OS << format("%08" PRIx64, Offset) << " ZERO terminator\n";

105 return;

106 }

107

112 << " CIE\n"

114 if (DumpOpts.IsEH && Version != 1)

115 OS << "WARNING: unsupported CIE version\n";

116 OS << format(" Version: %d\n", Version)

117 << " Augmentation: \"" << Augmentation << "\"\n";

118 if (Version >= 4) {

119 OS << format(" Address size: %u\n", (uint32_t)AddressSize);

120 OS << format(" Segment desc size: %u\n",

121 (uint32_t)SegmentDescriptorSize);

122 }

123 OS << format(" Code alignment factor: %u\n", (uint32_t)CodeAlignmentFactor);

124 OS << format(" Data alignment factor: %d\n", (int32_t)DataAlignmentFactor);

125 OS << format(" Return address column: %d\n", (int32_t)ReturnAddressRegister);

126 if (Personality)

127 OS << format(" Personality Address: %016" PRIx64 "\n", *Personality);

128 if (!AugmentationData.empty()) {

129 OS << " Augmentation data: ";

130 for (uint8_t Byte : AugmentationData)

132 OS << "\n";

133 }

134 OS << "\n";

136 {});

137 OS << "\n";

138

141 else {

144 "decoding the CIE opcodes into rows failed"),

145 RowsOrErr.takeError()));

146 }

147 OS << "\n";

148}

149

153 << format(" %0*" PRIx64, IsDWARF64 && !DumpOpts.IsEH ? 16 : 8, CIEPointer)

154 << " FDE cie=";

155 if (LinkedCIE)

156 OS << format("%08" PRIx64, LinkedCIE->getOffset());

157 else

158 OS << "";

159 OS << format(" pc=%08" PRIx64 "...%08" PRIx64 "\n", InitialLocation,

160 InitialLocation + AddressRange);

162 if (LSDAAddress)

163 OS << format(" LSDA Address: %016" PRIx64 "\n", *LSDAAddress);

165 OS << "\n";

166

169 else {

172 "decoding the FDE opcodes into rows failed"),

173 RowsOrErr.takeError()));

174 }

175 OS << "\n";

176}

177

179 bool IsEH, uint64_t EHFrameAddress)

180 : Arch(Arch), IsEH(IsEH), EHFrameAddress(EHFrameAddress) {}

181

183

186 errs() << "DUMP: ";

187 for (int i = 0; i < Length; ++i) {

190 }

191 errs() << "\n";

192}

193

197

200

205

206

207

208

210 auto Cie = std::make_unique(

211 IsDWARF64, StartOffset, 0, 0, SmallString<8>(), 0, 0, 0, 0, 0,

212 SmallString<8>(), 0, 0, std::nullopt, std::nullopt, Arch);

213 CIEs[StartOffset] = Cie.get();

214 Entries.push_back(std::move(Cie));

215 break;

216 }

217

218

219

220

221

224

225

227 uint64_t Id = Data.getRelocatedValue((IsDWARF64 && !IsEH) ? 8 : 4, &Offset,

228 nullptr, &Err);

229 if (Err)

230 return Err;

231

232 if (Id == getCIEId(IsDWARF64, IsEH)) {

234 const char *Augmentation = Data.getCStr(&Offset);

235 StringRef AugmentationString(Augmentation ? Augmentation : "");

238 Data.setAddressSize(AddressSize);

241 int64_t DataAlignmentFactor = Data.getSLEB128(&Offset);

242 uint64_t ReturnAddressRegister =

244

245

249 std::optional<uint64_t> Personality;

250 std::optional<uint32_t> PersonalityEncoding;

251 if (IsEH) {

252 std::optional<uint64_t> AugmentationLength;

253 uint64_t StartAugmentationOffset;

254 uint64_t EndAugmentationOffset;

255

256

257 for (unsigned i = 0, e = AugmentationString.size(); i != e; ++i) {

258 switch (AugmentationString[i]) {

259 default:

262 "unknown augmentation character %c in entry at 0x%" PRIx64,

263 AugmentationString[i], StartOffset);

264 case 'L':

265 LSDAPointerEncoding = Data.getU8(&Offset);

266 break;

267 case 'P': {

268 if (Personality)

271 "duplicate personality in entry at 0x%" PRIx64, StartOffset);

272 PersonalityEncoding = Data.getU8(&Offset);

273 Personality = Data.getEncodedPointer(

274 &Offset, *PersonalityEncoding,

275 EHFrameAddress ? EHFrameAddress + Offset : 0);

276 break;

277 }

278 case 'R':

279 FDEPointerEncoding = Data.getU8(&Offset);

280 break;

281 case 'S':

282

283 break;

284 case 'z':

285 if (i)

288 "'z' must be the first character at 0x%" PRIx64, StartOffset);

289

290

291 AugmentationLength = Data.getULEB128(&Offset);

292 StartAugmentationOffset = Offset;

293 EndAugmentationOffset = Offset + *AugmentationLength;

294 break;

295 case 'B':

296

297

298 break;

299

300

301 case 'G':

302 break;

303 }

304 }

305

306 if (AugmentationLength) {

307 if (Offset != EndAugmentationOffset)

309 "parsing augmentation data at 0x%" PRIx64

310 " failed",

311 StartOffset);

312 AugmentationData = Data.getData().slice(StartAugmentationOffset,

313 EndAugmentationOffset);

314 }

315 }

316

317 auto Cie = std::make_unique(

318 IsDWARF64, StartOffset, Length, Version, AugmentationString,

319 AddressSize, SegmentDescriptorSize, CodeAlignmentFactor,

320 DataAlignmentFactor, ReturnAddressRegister, AugmentationData,

321 FDEPointerEncoding, LSDAPointerEncoding, Personality,

322 PersonalityEncoding, Arch);

323 CIEs[StartOffset] = Cie.get();

324 Entries.emplace_back(std::move(Cie));

325 } else {

326

328 uint64_t InitialLocation = 0;

330 std::optional<uint64_t> LSDAAddress;

331 CIE *Cie = CIEs[IsEH ? (StartStructureOffset - CIEPointer) : CIEPointer];

332

333 if (IsEH) {

334

335 if (!Cie)

337 "parsing FDE data at 0x%" PRIx64

338 " failed due to missing CIE",

339 StartOffset);

340 if (auto Val =

342 EHFrameAddress + Offset)) {

343 InitialLocation = *Val;

344 }

345 if (auto Val = Data.getEncodedPointer(

348 }

349

351 if (!AugmentationString.empty()) {

352

354

355 uint64_t EndAugmentationOffset = Offset + AugmentationLength;

356

357

359 LSDAAddress = Data.getEncodedPointer(

361 EHFrameAddress ? Offset + EHFrameAddress : 0);

362 }

363

364 if (Offset != EndAugmentationOffset)

366 "parsing augmentation data at 0x%" PRIx64

367 " failed",

368 StartOffset);

369 }

370 } else {

371 InitialLocation = Data.getRelocatedAddress(&Offset);

373 }

374

375 Entries.emplace_back(new FDE(IsDWARF64, StartOffset, Length, CIEPointer,

377 LSDAAddress, Arch));

378 }

379

381 Entries.back()->cfis().parse(Data, &Offset, EndStructureOffset))

382 return E;

383

384 if (Offset != EndStructureOffset)

387 "parsing entry instructions at 0x%" PRIx64 " failed", StartOffset);

388 }

389

391}

392

394 auto It = partition_point(Entries, [=](const std::unique_ptr &E) {

395 return E->getOffset() < Offset;

396 });

397 if (It != Entries.end() && (*It)->getOffset() == Offset)

398 return It->get();

399 return nullptr;

400}

401

403 std::optional<uint64_t> Offset) const {

404 DumpOpts.IsEH = IsEH;

406 if (auto *Entry = getEntryAtOffset(*Offset))

407 Entry->dump(OS, DumpOpts);

408 return;

409 }

410

411 OS << "\n";

412 for (const auto &Entry : Entries)

413 Entry->dump(OS, DumpOpts);

414}

constexpr uint64_t getCIEId(bool IsDWARF64, bool IsEH)

Definition DWARFDebugFrame.cpp:93

static void dumpDataAux(DataExtractor Data, uint64_t Offset, int Length)

Definition DWARFDebugFrame.cpp:184

This file defines the DenseMap class.

This file contains constants used for implementing Dwarf debug support.

A class that represents an address range.

LLVM_ABI DWARFDebugFrame(Triple::ArchType Arch, bool IsEH=false, uint64_t EHFrameAddress=0)

Definition DWARFDebugFrame.cpp:178

LLVM_ABI void dump(raw_ostream &OS, DIDumpOptions DumpOpts, std::optional< uint64_t > Offset) const

Dump the section data into the given stream.

Definition DWARFDebugFrame.cpp:402

LLVM_ABI ~DWARFDebugFrame()

LLVM_ABI Error parse(DWARFDataExtractor Data)

Parse the section from raw data.

Definition DWARFDebugFrame.cpp:194

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

StringRef - Represent a constant reference to a string, i.e.

constexpr bool empty() const

empty - Check if the string is empty.

constexpr size_t size() const

size - Get the string size.

DWARF Common Information Entry (CIE)

void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const override

Dump the instructions in this CFI fragment.

Definition DWARFDebugFrame.cpp:101

uint32_t getLSDAPointerEncoding() const

uint32_t getFDEPointerEncoding() const

StringRef getAugmentationString() const

DWARF Frame Description Entry (FDE)

uint64_t getInitialLocation() const

const CIE * getLinkedCIE() const

void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const override

Dump the instructions in this CFI fragment.

Definition DWARFDebugFrame.cpp:150

An entry in either debug_frame or eh_frame.

const uint64_t Length

Entry length as specified in DWARF.

const uint64_t Offset

Offset of this entry in the section.

const CFIProgram & cfis() const

uint64_t getOffset() const

A class that can track all registers with locations in a UnwindRow object.

@ Unspecified

Not specified.

A class that represents a single row in the unwind table that is decoded by parsing the DWARF Call Fr...

void setAddress(uint64_t Addr)

Set the address for this UnwindRow.

A class that contains all UnwindRow objects for an FDE or a single unwind row for a CIE.

std::vector< UnwindRow > RowContainer

This class implements an extremely fast bulk output stream that can only output to a stream.

raw_ostream & write_hex(unsigned long long N)

Output N in hexadecimal, without any prefix or padding.

LLVM_ABI StringRef FormatString(DwarfFormat Format)

Calculates the starting offsets for various sections within the .debug_names section.

const uint32_t DW_CIE_ID

Special ID values that distinguish a CIE from a FDE in DWARF CFI.

LLVM_ABI void printUnwindTable(const UnwindTable &Rows, raw_ostream &OS, DIDumpOptions DumpOpts, unsigned IndentLevel=0)

Print a UnwindTable to the stream.

const uint64_t DW64_CIE_ID

DwarfFormat

Constants that define the DWARF format as 32 or 64 bit.

LLVM_ABI Expected< UnwindTable > createUnwindTable(const CIE *Cie)

Create an UnwindTable from a Common Information Entry (CIE).

Definition DWARFDebugFrame.cpp:72

LLVM_ABI Expected< UnwindTable::RowContainer > parseRows(const CFIProgram &CFIP, UnwindRow &CurrRow, const RegisterLocations *InitialLocs)

Parse the information in the CFIProgram and update the CurrRow object that the state machine describe...

LLVM_ABI void printCFIProgram(const CFIProgram &P, raw_ostream &OS, const DIDumpOptions &DumpOpts, unsigned IndentLevel, std::optional< uint64_t > Address)

This is an optimization pass for GlobalISel generic memory operations.

auto partition_point(R &&Range, Predicate P)

Binary search for the first iterator in a range where a predicate is false.

Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)

Create formatted StringError object.

FunctionAddr VTableAddr uintptr_t uintptr_t Version

Error joinErrors(Error E1, Error E2)

Concatenate errors.

char hexdigit(unsigned X, bool LowerCase=false)

hexdigit - Return the hexadecimal character for the given number X (which should be less than 16).

format_object< Ts... > format(const char *Fmt, const Ts &... Vals)

These are helper functions used to produce formatted output.

LLVM_ABI raw_fd_ostream & errs()

This returns a reference to a raw_ostream for standard error.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

Container for dump options that control which debug information will be dumped.

std::function< void(Error)> RecoverableErrorHandler