LLVM 24.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"
18#include <cstdint>
19
20using namespace llvm;
21using namespace dwarf;
22
24 DWARFDataExtractor Data, bool GnuStyle,
25 function_ref<void(Error)> RecoverableErrorHandler) {
26 this->GnuStyle = GnuStyle;
27 Sets.clear();
28 uint64_t Offset = 0;
29 while (Data.isValidOffset(Offset)) {
30 uint64_t SetOffset = Offset;
31 Sets.push_back({});
32 Set &NewSet = Sets.back();
33
35 std::tie(NewSet.Length, NewSet.Format) = Data.getInitialLength(C);
36 if (!C) {
37 // Drop the newly added set because it does not contain anything useful
38 // to dump.
39 Sets.pop_back();
40 RecoverableErrorHandler(createStringError(
42 "name lookup table at offset 0x%" PRIx64 " parsing failed: %s",
43 SetOffset, toString(C.takeError()).c_str()));
44 return;
45 }
46
47 Offset = C.tell() + NewSet.Length;
49 const unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(NewSet.Format);
50
51 NewSet.Version = SetData.getU16(C);
52 NewSet.Offset = SetData.getRelocatedValue(C, OffsetSize);
53 NewSet.Size = SetData.getUnsigned(C, OffsetSize);
54
55 if (!C) {
56 // Preserve the newly added set because at least some fields of the header
57 // are read and can be dumped.
58 RecoverableErrorHandler(
60 "name lookup table at offset 0x%" PRIx64
61 " does not have a complete header: %s",
62 SetOffset, toString(C.takeError()).c_str()));
63 continue;
64 }
65
66 while (C) {
67 uint64_t DieRef = SetData.getUnsigned(C, OffsetSize);
68 if (DieRef == 0)
69 break;
70 uint8_t IndexEntryValue = GnuStyle ? SetData.getU8(C) : 0;
71 StringRef Name = SetData.getCStrRef(C);
72 if (C)
73 NewSet.Entries.push_back(
74 {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
75 }
76
77 if (!C) {
78 RecoverableErrorHandler(createStringError(
80 "name lookup table at offset 0x%" PRIx64 " parsing failed: %s",
81 SetOffset, toString(C.takeError()).c_str()));
82 continue;
83 }
84 if (C.tell() != Offset)
85 RecoverableErrorHandler(createStringError(
87 "name lookup table at offset 0x%" PRIx64
88 " has a terminator at offset 0x%" PRIx64
89 " before the expected end at 0x%" PRIx64,
90 SetOffset, C.tell() - OffsetSize, Offset - OffsetSize));
91 }
92}
93
95 for (const Set &S : Sets) {
96 int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(S.Format);
97 OS << "length = "
98 << formatv("0x{0:x-}",
99 fmt_align(S.Length, AlignStyle::Right, OffsetDumpWidth, '0'));
100 OS << ", format = " << dwarf::FormatString(S.Format);
101 OS << ", version = " << formatv("{0:x4}", S.Version);
102 OS << ", unit_offset = "
103 << formatv("0x{0:x-}",
104 fmt_align(S.Offset, AlignStyle::Right, OffsetDumpWidth, '0'));
105 OS << ", unit_size = "
106 << formatv("0x{0:x-}",
107 fmt_align(S.Size, AlignStyle::Right, OffsetDumpWidth, '0'))
108 << '\n';
109 OS << (GnuStyle ? "Offset Linkage Kind Name\n"
110 : "Offset Name\n");
111
112 for (const Entry &E : S.Entries) {
113 OS << formatv("0x{0:x-} ", fmt_align(E.SecOffset, AlignStyle::Right,
114 OffsetDumpWidth, '0'));
115 if (GnuStyle) {
116 StringRef EntryLinkage =
117 GDBIndexEntryLinkageString(E.Descriptor.Linkage);
118 StringRef EntryKind = dwarf::GDBIndexEntryKindString(E.Descriptor.Kind);
119 OS << formatv("{0,-8}", EntryLinkage.data()) << ' '
120 << formatv("{0,-8}", EntryKind.data()) << ' ';
121 }
122 OS << '\"' << E.Name << "\"\n";
123 }
124 }
125}
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
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:894
LLVM_ABI StringRef FormatString(DwarfFormat Format)
Definition Dwarf.cpp:1062
LLVM_ABI StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition Dwarf.cpp:871
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:1186
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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)
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:1274