LLVM: include/llvm/DebugInfo/DWARF/DWARFUnit.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H

10#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H

11

26#include

27#include

28#include

29#include

30#include

31#include

32#include

33

34namespace llvm {

35

50}

51

52

53

54

56

58

62

63

65

66

69

70

71 std::optional<uint64_t> DWOId;

72

73

75

76

78

79public:

80

81

82

83

87

88

97 return FormParams.getDwarfOffsetByteSize();

98 }

101 std::optional<uint64_t> getDWOId() const { return DWOId; }

103 assert((!DWOId || *DWOId == Id) && "setting DWOId to a different value");

104 DWOId = Id;

105 }

111 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;

112 }

120};

121

123 DWARFSectionKind Kind);

124

125bool isCompileUnit(const std::unique_ptr &U);

126

127

128

133 Parser;

134 int NumInfoUnits = -1;

135

136public:

140

143

145

146

150

151

152

153

154

157

158

159

160

161

165 bool Lazy = false);

166

167

168

170

171

173

175 return NumInfoUnits == -1 ? size() : NumInfoUnits;

176 }

177

179

180

182

183private:

190};

191

192

193

196

198

200

205

209 return FormParams.getDwarfOffsetByteSize();

210 }

211

212

213

216};

217

220

222

228

229

230 std::unique_ptr LocTable;

231

237 std::optional<uint64_t> AddrOffsetSectionBase;

238 bool IsLittleEndian;

239 bool IsDWO;

241

242

243

244 std::optional

245 StringOffsetsTableContribution;

246

248 std::optionalobject::SectionedAddress BaseAddr;

249

250 std::vector DieArray;

251

252

253

254

255 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;

256

257

258

259 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;

261

262 using die_iterator_range =

264

265 std::shared_ptr DWO;

266

267protected:

269

270

271

272

273

274

275

277 auto First = DieArray.data();

279 return Die - First;

280 }

281

282

284 assert(Index < DieArray.size());

285 return &DieArray[Index];

286 }

287

298

300

301

302

303

306

307

308

309

310

313

314public:

321

323

330 return Header.getFormParams();

331 }

336 return Header.getDwarfOffsetByteSize();

337 }

338

343 bool isTypeUnit() const { return Header.isTypeUnit(); }

349 return StringOffsetSection;

350 }

351

353

354

355

357

359 AddrOffsetSection = AOS;

360 AddrOffsetSectionBase = Base;

361 }

362

364 return AddrOffsetSectionBase;

365 }

366

367

369 if (std::optional<uint64_t> AddrOffsetSectionBase =

372

373 return std::nullopt;

374 }

375

376

377 void updateAddressDieMap(DWARFDie Die);

378

379

380 void updateVariableDieMap(DWARFDie Die);

381

383 RangeSection = RS;

384 RangeSectionBase = Base;

385 }

386

388 return LocSectionBase;

389 }

390

391 std::optionalobject::SectionedAddress

392 getAddrOffsetSectionItem(uint32_t Index) const;

394

396

400

402

403

404

405

406

409 void clear();

410

411 const std::optional &

413 extractDIEsIfNeeded(true );

414 return StringOffsetsTableContribution;

415 }

416

418 assert(StringOffsetsTableContribution);

419 return StringOffsetsTableContribution->getDwarfOffsetByteSize();

420 }

421

423 assert(StringOffsetsTableContribution);

424 return StringOffsetsTableContribution->Base;

425 }

426

428

430

432 switch (UnitType) {

433 case dwarf::DW_UT_compile:

434 return Tag == dwarf::DW_TAG_compile_unit;

435 case dwarf::DW_UT_type:

436 return Tag == dwarf::DW_TAG_type_unit;

437 case dwarf::DW_UT_partial:

438 return Tag == dwarf::DW_TAG_partial_unit;

439 case dwarf::DW_UT_skeleton:

440 return Tag == dwarf::DW_TAG_skeleton_unit;

441 case dwarf::DW_UT_split_compile:

442 case dwarf::DW_UT_split_type:

444 }

445 return false;

446 }

447

448 std::optionalobject::SectionedAddress getBaseAddress();

449

451 extractDIEsIfNeeded(ExtractUnitDIEOnly);

452 if (DieArray.empty())

454 return DWARFDie(this, &DieArray[0]);

455 }

456

458 StringRef DWOAlternativeLocation = {}) {

459 parseDWO(DWOAlternativeLocation);

460 return DWO ? DWO->getUnitDIE(ExtractUnitDIEOnly)

461 : getUnitDIE(ExtractUnitDIEOnly);

462 }

463

464 const char *getCompilationDir();

466 extractDIEsIfNeeded( true);

468 }

470

471

472

474

475

476

477

479

480

481

482

483 std::optional<uint64_t> getRnglistOffset(uint32_t Index);

484

485 std::optional<uint64_t> getLoclistOffset(uint32_t Index);

486

488

491

492

493

494

496

497

498

500

501

502

503

506

507

509

510

511

513 extractDIEsIfNeeded(false);

514 return DieArray.size();

515 }

516

517

518

519

520

521

522

526

527

531

537

538

539

542 return DWARFDie(this, &DieArray[*DieIdx]);

543

545 }

546

547

548

550 extractDIEsIfNeeded(false);

551 auto It =

554 });

555 if (It != DieArray.end() && It->getOffset() == Offset)

556 return It - DieArray.begin();

557 return std::nullopt;

558 }

559

561 if (auto IndexEntry = Header.getIndexEntry())

562 if (const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))

563 return Contrib->getOffset32();

564 return 0;

565 }

566

567 die_iterator_range dies() {

568 extractDIEsIfNeeded(false);

569 return DieArray;

570 }

571

573

575

576private:

577

578 size_t getDebugInfoSize() const {

579 return Header.getLength() + Header.getUnitLengthFieldByteSize() -

581 }

582

583

584

585 void extractDIEsIfNeeded(bool CUDieOnly);

586

587

588 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,

589 std::vector &DIEs) const;

590

591

592 void clearDIEs(bool KeepCUDie);

593

594

595

596

597

598

599 bool parseDWO(StringRef AlternativeLocation = {});

600};

601

602inline bool isCompileUnit(const std::unique_ptr &U) {

603 return !U->isTypeUnit();

604}

605

606}

607

608#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static const Function * getParent(const Value *V)

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This file defines the DenseSet and SmallDenseSet classes.

This file contains constants used for implementing Dwarf debug support.

static LLVM_PACKED_END size_t getHeaderSize(uint16_t Version)

This file defines the SmallVector class.

A structured debug information entry.

unsigned getOffset() const

Get the compile/type unit relative offset of this DIE.

DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...

DWARFDebugInfoEntry - A DIE with only the minimum required data.

Utility class that carries the DWARF compile/type unit and the debug info entry in an object.

An abstract base class for various kinds of location tables (.debug_loc, .debug_loclists,...

Describe a collection of units.

Definition DWARFUnit.h:129

SmallVectorImpl< std::unique_ptr< DWARFUnit > > UnitVector

Definition DWARFUnit.h:137

LLVM_ABI DWARFUnit * addUnit(std::unique_ptr< DWARFUnit > Unit)

Add an existing DWARFUnit to this UnitVector.

unsigned getNumInfoUnits() const

Returns number of units from all .debug_info[.dwo] sections.

Definition DWARFUnit.h:174

void finishedInfoUnits()

Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....

Definition DWARFUnit.h:181

llvm::iterator_range< UnitVector::iterator > iterator_range

Definition DWARFUnit.h:139

unsigned getNumTypesUnits() const

Returns number of units from all .debug_types[.dwo] sections.

Definition DWARFUnit.h:178

LLVM_ABI DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E, DWARFSectionKind Sec, const DWARFSection *Section=nullptr)

Returns the Unit from the .debug_info or .debug_types section by the index entry.

unsigned getNumUnits() const

Returns number of all units held by this instance.

Definition DWARFUnit.h:172

LLVM_ABI void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)

Read units from a .debug_info or .debug_types section.

LLVM_ABI DWARFUnit * getUnitForOffset(uint64_t Offset) const

UnitVector::iterator iterator

Definition DWARFUnit.h:138

LLVM_ABI void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection, DWARFSectionKind SectionKind, bool Lazy=false)

Read units from a .debug_info.dwo or .debug_types.dwo section.

decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range

Definition DWARFUnit.h:141

Definition DWARFUnit.h:218

const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const

Return DWARFDebugInfoEntry for the specified index Index.

Definition DWARFUnit.h:283

std::optional< uint64_t > getDWOId()

Definition DWARFUnit.h:465

uint32_t getHeaderSize() const

Size in bytes of the parsed unit header.

Definition DWARFUnit.h:339

const DWARFLocationTable & getLocationTable()

Definition DWARFUnit.h:401

unsigned getNumDIEs()

Returns the number of DIEs in the unit.

Definition DWARFUnit.h:512

const dwarf::FormParams & getFormParams() const

Definition DWARFUnit.h:329

DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly=true, StringRef DWOAlternativeLocation={})

Definition DWARFUnit.h:457

uint8_t getUnitType() const

Definition DWARFUnit.h:342

uint64_t getLength() const

Definition DWARFUnit.h:340

uint8_t getRefAddrByteSize() const

Definition DWARFUnit.h:334

DataExtractor getStringExtractor() const

Definition DWARFUnit.h:397

Error tryExtractDIEsIfNeeded(bool CUDieOnly)

DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)

Definition DWARFUnit.h:450

DWARFContext & getContext() const

Definition DWARFUnit.h:326

uint8_t getAddressByteSize() const

Definition DWARFUnit.h:333

void setSkeletonUnit(DWARFUnit *SU)

Definition DWARFUnit.h:352

std::optional< uint64_t > getAddrOffsetSectionBase() const

Definition DWARFUnit.h:363

const DWARFSection & getInfoSection() const

Definition DWARFUnit.h:327

void setAddrOffsetSection(const DWARFSection *AOS, uint64_t Base)

Definition DWARFUnit.h:358

void setDWOId(uint64_t NewID)

Definition DWARFUnit.h:469

uint64_t getLocSectionBase() const

Definition DWARFUnit.h:387

void setRangesSection(const DWARFSection *RS, uint64_t Base)

Definition DWARFUnit.h:382

uint8_t getDwarfStringOffsetsByteSize() const

Definition DWARFUnit.h:417

const DWARFUnitHeader & getHeader() const

Definition DWARFUnit.h:299

DWARFDie getDIEForOffset(uint64_t Offset)

Return the DIE object for a given offset Offset inside the unit's DIE vector.

Definition DWARFUnit.h:540

uint32_t getDIEIndex(const DWARFDie &D) const

Return the index of a DIE inside the unit's DIE vector.

Definition DWARFUnit.h:523

uint32_t getLineTableOffset() const

Definition DWARFUnit.h:560

uint64_t getStringOffsetsBase() const

Definition DWARFUnit.h:422

dwarf::DwarfFormat getFormat() const

Definition DWARFUnit.h:341

DWARFUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA, const DWARFSection *RS, const DWARFSection *LocSection, StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO, const DWARFUnitVector &UnitVector)

std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)

Return the DIE index for a given offset Offset inside the unit's DIE vector.

Definition DWARFUnit.h:549

uint64_t getAbbreviationsOffset() const

Definition DWARFUnit.h:427

uint16_t getVersion() const

Definition DWARFUnit.h:332

std::optional< uint64_t > getIndexedAddressOffset(uint64_t Index)

Returns offset to the indexed address value inside .debug_addr section.

Definition DWARFUnit.h:368

uint64_t getAbbrOffset() const

Definition DWARFUnit.h:344

uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const

Return the index of a Die entry inside the unit's DIE vector.

Definition DWARFUnit.h:276

die_iterator_range dies()

Definition DWARFUnit.h:567

bool isLittleEndian() const

Definition DWARFUnit.h:324

virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts)=0

const DWARFUnitVector & getUnitVector() const

Return the DWARFUnitVector containing this unit.

Definition DWARFUnit.h:508

const DWARFSection & getStringOffsetSection() const

Definition DWARFUnit.h:348

const DWARFSection & getLineSection() const

Definition DWARFUnit.h:346

StringRef getStringSection() const

Definition DWARFUnit.h:347

uint8_t getDwarfOffsetByteSize() const

Definition DWARFUnit.h:335

static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)

Definition DWARFUnit.h:431

uint64_t getNextUnitOffset() const

Definition DWARFUnit.h:345

const std::optional< StrOffsetsContributionDescriptor > & getStringOffsetsTableContribution()

Definition DWARFUnit.h:412

DWARFUnit * getLinkedUnit()

Definition DWARFUnit.h:356

bool isTypeUnit() const

Definition DWARFUnit.h:343

DWARFDie getDIEAtIndex(unsigned Index)

Return the DIE object at the given index Index.

Definition DWARFUnit.h:528

uint64_t getOffset() const

Definition DWARFUnit.h:328

bool isDWOUnit() const

Definition DWARFUnit.h:325

Implements a dense probed hash-table based set.

Lightweight error class with error context and mandatory checking.

Tagged union holding either a T or a Error.

SectionKind - This is a simple POD value that classifies the properties of a section.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

typename SuperClass::iterator iterator

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

Stores all information related to a compile unit, be it in its original instance of the object file o...

A range adaptor for a pair of iterators.

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

This provides a very simple, boring adaptor for a begin and end iterator into a range type.

@ C

The default llvm calling convention, compatible with C.

Definition DWARFUnit.h:47

uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)

Get the byte size of the unit length field depending on the DWARF format.

bool isUnitType(uint8_t UnitType)

DwarfFormat

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

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)

auto partition_point(R &&Range, Predicate P)

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

DWARFSectionKind

The enum of section identifiers to be used in internal interfaces.

FunctionAddr VTableAddr uintptr_t uintptr_t Version

iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)

Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

bool isCompileUnit(const std::unique_ptr< DWARFUnit > &U)

Definition DWARFUnit.h:602

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

uint64_t Base

Definition DWARFUnit.h:195

LLVM_ABI Expected< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)

Determine whether a contribution to the string offsets table is consistent with the relevant section ...

dwarf::DwarfFormat getFormat() const

Definition DWARFUnit.h:207

uint8_t getVersion() const

Definition DWARFUnit.h:206

uint64_t Size

The contribution size not including the header.

Definition DWARFUnit.h:197

StrOffsetsContributionDescriptor()=default

dwarf::FormParams FormParams

Format and version.

Definition DWARFUnit.h:199

uint8_t getDwarfOffsetByteSize() const

Definition DWARFUnit.h:208

StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format)

Definition DWARFUnit.h:201

A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...