LLVM 23.0.0git
DWARFDebugPubTable.cpp
Go to the documentation of this file.
1//===- DWARFDebugPubTable.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
10#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/Errc.h"
15#include "llvm/Support/Format.h"
19#include <cstdint>
20
21using namespace llvm;
22using namespace dwarf;
23
25 DWARFDataExtractor Data, bool GnuStyle,
26 function_ref<void(Error)> RecoverableErrorHandler) {
27 this->GnuStyle = GnuStyle;
28 Sets.clear();
29 uint64_t Offset = 0;
30 while (Data.isValidOffset(Offset)) {
31 uint64_t SetOffset = Offset;
32 Sets.push_back({});
33 Set &NewSet = Sets.back();
34
36 std::tie(NewSet.Length, NewSet.Format) = Data.getInitialLength(C);
37 if (!C) {
38 // Drop the newly added set because it does not contain anything useful
39 // to dump.
40 Sets.pop_back();
41 RecoverableErrorHandler(createStringError(
43 "name lookup table at offset 0x%" PRIx64 " parsing failed: %s",
44 SetOffset, toString(C.takeError()).c_str()));
45 return;
46 }
47
48 Offset = C.tell() + NewSet.Length;
50 const unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(NewSet.Format);
51
52 NewSet.Version = SetData.getU16(C);
53 NewSet.Offset = SetData.getRelocatedValue(C, OffsetSize);
54 NewSet.Size = SetData.getUnsigned(C, OffsetSize);
55
56 if (!C) {
57 // Preserve the newly added set because at least some fields of the header
58 // are read and can be dumped.
59 RecoverableErrorHandler(
61 "name lookup table at offset 0x%" PRIx64
62 " does not have a complete header: %s",
63 SetOffset, toString(C.takeError()).c_str()));
64 continue;
65 }
66
67 while (C) {
68 uint64_t DieRef = SetData.getUnsigned(C, OffsetSize);
69 if (DieRef == 0)
70 break;
71 uint8_t IndexEntryValue = GnuStyle ? SetData.getU8(C) : 0;
72 StringRef Name = SetData.getCStrRef(C);
73 if (C)
74 NewSet.Entries.push_back(
75 {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
76 }
77
78 if (!C) {
79 RecoverableErrorHandler(createStringError(
81 "name lookup table at offset 0x%" PRIx64 " parsing failed: %s",
82 SetOffset, toString(C.takeError()).c_str()));
83 continue;
84 }
85 if (C.tell() != Offset)
86 RecoverableErrorHandler(createStringError(
88 "name lookup table at offset 0x%" PRIx64
89 " has a terminator at offset 0x%" PRIx64
90 " before the expected end at 0x%" PRIx64,
91 SetOffset, C.tell() - OffsetSize, Offset - OffsetSize));
92 }
93}
94
96 for (const Set &S : Sets) {
97 int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(S.Format);
98 OS << "length = "
99 << formatv("0x{0:x-}",
100 fmt_align(S.Length, AlignStyle::Right, OffsetDumpWidth, '0'));
101 OS << ", format = " << dwarf::FormatString(S.Format);
102 OS << ", version = " << formatv("{0:x4}", S.Version);
103 OS << ", unit_offset = "
104 << formatv("0x{0:x-}",
105 fmt_align(S.Offset, AlignStyle::Right, OffsetDumpWidth, '0'));
106 OS << ", unit_size = "
107 << formatv("0x{0:x-}",
108 fmt_align(S.Size, AlignStyle::Right, OffsetDumpWidth, '0'))
109 << '\n';
110 OS << (GnuStyle ? "Offset Linkage Kind Name\n"
111 : "Offset Name\n");
112
113 for (const Entry &E : S.Entries) {
114 OS << formatv("0x{0:x-} ", fmt_align(E.SecOffset, AlignStyle::Right,
115 OffsetDumpWidth, '0'));
116 if (GnuStyle) {
117 StringRef EntryLinkage =
118 GDBIndexEntryLinkageString(E.Descriptor.Linkage);
119 StringRef EntryKind = dwarf::GDBIndexEntryKindString(E.Descriptor.Kind);
120 OS << formatv("{0,-8}", EntryLinkage.data()) << ' '
121 << formatv("{0,-8}", EntryKind.data()) << ' ';
122 }
123 OS << '\"' << E.Name << "\"\n";
124 }
125 }
126}
This file contains constants used for implementing Dwarf debug support.
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and returns it as adjusted by the Relocator.
A DWARFDataExtractor (typically for an in-memory copy of an object-file section) plus a relocation ma...
LLVM_ABI void extract(DWARFDataExtractor Data, bool GnuStyle, function_ref< void(Error)> RecoverableErrorHandler)
LLVM_ABI void dump(raw_ostream &OS) const
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
LLVM_ABI 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.
LLVM_ABI StringRef getCStrRef(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a C string from *offset_ptr.
LLVM_ABI uint8_t getU8(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint8_t value from *offset_ptr.
LLVM_ABI uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:137
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition Dwarf.cpp:857
LLVM_ABI StringRef FormatString(DwarfFormat Format)
Definition Dwarf.cpp:1023
LLVM_ABI StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition Dwarf.cpp:834
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
Definition Dwarf.h:1097
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
@ invalid_argument
Definition Errc.h:56
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
support::detail::AlignAdapter< T > fmt_align(T &&Item, AlignStyle Where, size_t Amount, char Fill=' ')
Each table consists of sets of variable length entries.
uint64_t Length
The total length of the entries for that set, not including the length field itself.
uint64_t Offset
The offset from the beginning of the .debug_info section of the compilation unit header referenced by...
dwarf::DwarfFormat Format
The DWARF format of the set.
uint64_t Size
The size in bytes of the contents of the .debug_info section generated to represent that compilation ...
uint16_t Version
This number is specific to the name lookup table and is independent of the DWARF version number.
Describes an entry of the various gnu_pub* debug sections.
Definition Dwarf.h:1185