1//===- DWARFUnitIndex.cpp -------------------------------------------------===// 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 7//===----------------------------------------------------------------------===// 23enum class DWARFSectionKindV2 {
29 DW_SECT_STR_OFFSETS = 6,
36// Return true if the section identifier is defined in the DWARFv5 standard. 38returnID >= DW_SECT_INFO &&
ID <= DW_SECT_RNGLISTS &&
43unsigned IndexVersion) {
44if (IndexVersion == 5) {
52 return static_cast<uint32_t>(DWARFSectionKindV2::DW_SECT_##T) 58CASE(STR_OFFSETS, STR_OFFSETS);
59CASE(EXT_MACINFO, MACINFO);
63// All other section kinds have no corresponding values in v2 indexes. 69unsigned IndexVersion) {
75switch (
static_cast<DWARFSectionKindV2
>(
Value)) {
77 case DWARFSectionKindV2::DW_SECT_##S: \ 84CASE(STR_OFFSETS, STR_OFFSETS);
85CASE(MACINFO, EXT_MACINFO);
94constuint64_t BeginOffset = *OffsetPtr;
97// GCC Debug Fission defines the version as an unsigned 32-bit field 98// with value of 2, https://gcc.gnu.org/wiki/DebugFissionDWP. 99// DWARFv5 defines the same space as an uhalf version field with value of 5 100// and a 2 bytes long padding, see Section 7.3.5.3. 101 Version = IndexData.
getU32(OffsetPtr);
103 *OffsetPtr = BeginOffset;
104 Version = IndexData.
getU16(OffsetPtr);
107 *OffsetPtr += 2;
// Skip padding. 109 NumColumns = IndexData.
getU32(OffsetPtr);
110 NumUnits = IndexData.
getU32(OffsetPtr);
111 NumBuckets = IndexData.
getU32(OffsetPtr);
116OS <<
format(
"version = %u, units = %u, slots = %u\n\n", Version, NumUnits, NumBuckets);
120bool b = parseImpl(IndexData);
122// Make sure we don't try to dump anything 123 Header.NumBuckets = 0;
124// Release any partially initialized data. 133if (!Header.parse(IndexData, &
Offset))
136// Fix InfoColumnKind: in DWARFv5, type units are in .debug_info.dwo. 137if (Header.Version == 5)
138 InfoColumnKind = DW_SECT_INFO;
141Offset, Header.NumBuckets * (8 + 4) +
142 (2 * Header.NumUnits + 1) * 4 * Header.NumColumns))
145 Rows = std::make_unique<Entry[]>(Header.NumBuckets);
147 std::make_unique<Entry::SectionContribution *[]>(Header.NumUnits);
148 ColumnKinds = std::make_unique<DWARFSectionKind[]>(Header.NumColumns);
149 RawSectionIds = std::make_unique<uint32_t[]>(Header.NumColumns);
151// Read Hash Table of Signatures 152for (
unsigned i = 0; i != Header.NumBuckets; ++i)
155// Read Parallel Table of Indexes 156for (
unsigned i = 0; i != Header.NumBuckets; ++i) {
161 Rows[i].Contributions =
162 std::make_unique<Entry::SectionContribution[]>(Header.NumColumns);
163 Contribs[Index - 1] = Rows[i].Contributions.get();
166// Read the Column Headers 167for (
unsigned i = 0; i != Header.NumColumns; ++i) {
170if (ColumnKinds[i] == InfoColumnKind) {
180// Read Table of Section Offsets 181for (
unsigned i = 0; i != Header.NumUnits; ++i) {
182auto *Contrib = Contribs[i];
183for (
unsigned i = 0; i != Header.NumColumns; ++i)
187// Read Table of Section Sizes 188for (
unsigned i = 0; i != Header.NumUnits; ++i) {
189auto *Contrib = Contribs[i];
190for (
unsigned i = 0; i != Header.NumColumns; ++i)
199#define HANDLE_DW_SECT(ID, NAME) \ 200 case DW_SECT_##NAME: \ 202#include "llvm/BinaryFormat/Dwarf.def" 220OS <<
"Index Signature ";
221for (
unsigned i = 0; i != Header.NumColumns; ++i) {
227 Kind == DWARFSectionKind::DW_SECT_INFO ? 40 : 24);
229OS <<
format(
" Unknown: %-15" PRIu32, RawSectionIds[i]);
231OS <<
"\n----- ------------------";
232for (
unsigned i = 0; i != Header.NumColumns; ++i) {
234if (Kind == DWARFSectionKind::DW_SECT_INFO ||
236OS <<
" ----------------------------------------";
238OS <<
" ------------------------";
241for (
unsigned i = 0; i != Header.NumBuckets; ++i) {
243if (
auto *Contribs = Row.Contributions.get()) {
244OS <<
format(
"%5u 0x%016" PRIx64
" ", i + 1, Row.Signature);
245for (
unsigned i = 0; i != Header.NumColumns; ++i) {
246auto &Contrib = Contribs[i];
248if (Kind == DWARFSectionKind::DW_SECT_INFO ||
250OS <<
format(
"[0x%016" PRIx64
", 0x%016" PRIx64
") ",
252 Contrib.getOffset() + Contrib.getLength());
254OS <<
format(
"[0x%08" PRIx32
", 0x%08" PRIx32
") ",
255 Contrib.getOffset32(),
256 Contrib.getOffset32() + Contrib.getLength32());
266for (; i != Index->Header.NumColumns; ++i)
267if (Index->ColumnKinds[i] == Sec)
268return &Contributions[i];
274return Contributions[Index->InfoColumn];
279return &Contributions[Index->InfoColumn];
284if (OffsetLookup.empty()) {
285for (
uint32_t i = 0; i != Header.NumBuckets; ++i)
286if (Rows[i].Contributions)
287 OffsetLookup.push_back(&Rows[i]);
289return E1->Contributions[InfoColumn].getOffset() <
290 E2->Contributions[InfoColumn].getOffset();
294return E2->Contributions[InfoColumn].getOffset() <=
Offset;
296if (
I == OffsetLookup.begin())
300constauto &InfoContrib = E->Contributions[InfoColumn];
301if ((InfoContrib.getOffset() + InfoContrib.getLength()) <=
Offset)
307uint64_t Mask = Header.NumBuckets - 1;
310auto HP = ((S >> 32) & Mask) | 1;
311// The spec says "while 0 is a valid hash value, the row index in a used slot 312// will always be non-zero". Loop until we find a match or an empty slot. 316// If the slot is empty, we don't care whether the signature matches (it could 317// be zero and still match the zeros in the empty slot). 318if (Rows[
H].Index ==
nullptr)
constexpr bool isKnownV5SectionID(uint32_t ID)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
static std::string getSignature(FunctionType *FTy)
const SectionContribution * getContribution() const
void dump(raw_ostream &OS) const
bool parse(DataExtractor IndexData)
const Entry * getFromHash(uint64_t Offset) const
const Entry * getFromOffset(uint64_t Offset) const
uint32_t getU32(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint32_t value from *offset_ptr.
uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
uint64_t getU64(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint64_t value from *offset_ptr.
bool isValidOffsetForDataOfSize(uint64_t offset, uint64_t length) const
Test the availability of length bytes of data from offset.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
DWARFSectionKind deserializeSectionKind(uint32_t Value, unsigned IndexVersion)
Convert a value read from an index section to the internal representation.
DWARFSectionKind
The enum of section identifiers to be used in internal interfaces.
@ DW_SECT_EXT_unknown
Denotes a value read from an index section that does not correspond to any of the supported standards...
uint32_t serializeSectionKind(DWARFSectionKind Kind, unsigned IndexVersion)
Convert the internal value for a section kind to an on-disk value.
void sort(IteratorTy Start, IteratorTy End)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
FormattedString left_justify(StringRef Str, unsigned Width)
left_justify - append spaces after string so total output is Width characters.