LLVM  14.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 
11 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Errc.h"
15 #include "llvm/Support/Format.h"
17 #include <cstdint>
18 
19 using namespace llvm;
20 using namespace dwarf;
21 
23  DWARFDataExtractor Data, bool GnuStyle,
24  function_ref<void(Error)> RecoverableErrorHandler) {
25  this->GnuStyle = GnuStyle;
26  Sets.clear();
27  uint64_t Offset = 0;
28  while (Data.isValidOffset(Offset)) {
29  uint64_t SetOffset = Offset;
30  Sets.push_back({});
31  Set &NewSet = Sets.back();
32 
34  std::tie(NewSet.Length, NewSet.Format) = Data.getInitialLength(C);
35  if (!C) {
36  // Drop the newly added set because it does not contain anything useful
37  // to dump.
38  Sets.pop_back();
39  RecoverableErrorHandler(createStringError(
41  "name lookup table at offset 0x%" PRIx64 " parsing failed: %s",
42  SetOffset, toString(C.takeError()).c_str()));
43  return;
44  }
45 
46  Offset = C.tell() + NewSet.Length;
47  DWARFDataExtractor SetData(Data, Offset);
48  const unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(NewSet.Format);
49 
50  NewSet.Version = SetData.getU16(C);
51  NewSet.Offset = SetData.getRelocatedValue(C, OffsetSize);
52  NewSet.Size = SetData.getUnsigned(C, OffsetSize);
53 
54  if (!C) {
55  // Preserve the newly added set because at least some fields of the header
56  // are read and can be dumped.
57  RecoverableErrorHandler(
59  "name lookup table at offset 0x%" PRIx64
60  " does not have a complete header: %s",
61  SetOffset, toString(C.takeError()).c_str()));
62  continue;
63  }
64 
65  while (C) {
66  uint64_t DieRef = SetData.getUnsigned(C, OffsetSize);
67  if (DieRef == 0)
68  break;
69  uint8_t IndexEntryValue = GnuStyle ? SetData.getU8(C) : 0;
70  StringRef Name = SetData.getCStrRef(C);
71  if (C)
72  NewSet.Entries.push_back(
73  {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
74  }
75 
76  if (!C) {
77  RecoverableErrorHandler(createStringError(
79  "name lookup table at offset 0x%" PRIx64 " parsing failed: %s",
80  SetOffset, toString(C.takeError()).c_str()));
81  continue;
82  }
83  if (C.tell() != Offset)
84  RecoverableErrorHandler(createStringError(
86  "name lookup table at offset 0x%" PRIx64
87  " has a terminator at offset 0x%" PRIx64
88  " before the expected end at 0x%" PRIx64,
89  SetOffset, C.tell() - OffsetSize, Offset - OffsetSize));
90  }
91 }
92 
94  for (const Set &S : Sets) {
95  int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(S.Format);
96  OS << "length = " << format("0x%0*" PRIx64, OffsetDumpWidth, S.Length);
97  OS << ", format = " << dwarf::FormatString(S.Format);
98  OS << ", version = " << format("0x%04x", S.Version);
99  OS << ", unit_offset = "
100  << format("0x%0*" PRIx64, OffsetDumpWidth, S.Offset);
101  OS << ", unit_size = " << format("0x%0*" PRIx64, OffsetDumpWidth, S.Size)
102  << '\n';
103  OS << (GnuStyle ? "Offset Linkage Kind Name\n"
104  : "Offset Name\n");
105 
106  for (const Entry &E : S.Entries) {
107  OS << format("0x%0*" PRIx64 " ", OffsetDumpWidth, E.SecOffset);
108  if (GnuStyle) {
109  StringRef EntryLinkage =
110  GDBIndexEntryLinkageString(E.Descriptor.Linkage);
111  StringRef EntryKind = dwarf::GDBIndexEntryKindString(E.Descriptor.Kind);
112  OS << format("%-8s", EntryLinkage.data()) << ' '
113  << format("%-8s", EntryKind.data()) << ' ';
114  }
115  OS << '\"' << E.Name << "\"\n";
116  }
117  }
118 }
llvm::errc::invalid_argument
@ invalid_argument
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DWARFDebugPubTable::Set
Each table consists of sets of variable length entries.
Definition: DWARFDebugPubTable.h:43
llvm::DWARFDebugPubTable::Set::Entries
std::vector< Entry > Entries
Definition: DWARFDebugPubTable.h:63
llvm::DWARFDebugPubTable::dump
void dump(raw_ostream &OS) const
Definition: DWARFDebugPubTable.cpp:93
StringRef.h
llvm::dwarf::GDBIndexEntryLinkageString
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:629
Errc.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::DWARFDebugPubTable::Entry
Definition: DWARFDebugPubTable.h:27
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
Format.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::DWARFDataExtractor::getRelocatedValue
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset.
Definition: DWARFDataExtractor.cpp:46
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::DWARFDebugPubTable::Set::Offset
uint64_t Offset
The offset from the beginning of the .debug_info section of the compilation unit header referenced by...
Definition: DWARFDebugPubTable.h:57
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::dwarf::FormatString
StringRef FormatString(DwarfFormat Format)
Definition: Dwarf.cpp:790
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::dwarf::GDBIndexEntryKindString
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:606
llvm::DWARFDebugPubTable::Set::Length
uint64_t Length
The total length of the entries for that set, not including the length field itself.
Definition: DWARFDebugPubTable.h:46
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
DWARFDebugPubTable.h
llvm::DataExtractor::getUnsigned
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.
Definition: DataExtractor.cpp:126
llvm::DataExtractor::Cursor
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
llvm::dwarf::toString
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Definition: DWARFFormValue.h:166
llvm::DWARFDebugPubTable::Set::Size
uint64_t Size
The size in bytes of the contents of the .debug_info section generated to represent that compilation ...
Definition: DWARFDebugPubTable.h:61
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Dwarf.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::DataExtractor::getU8
uint8_t getU8(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:80
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
DataExtractor.h
llvm::DataExtractor::getCStrRef
StringRef getCStrRef(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a C string from *offset_ptr.
Definition: DataExtractor.cpp:156
llvm::DWARFDebugPubTable::extract
void extract(DWARFDataExtractor Data, bool GnuStyle, function_ref< void(Error)> RecoverableErrorHandler)
Definition: DWARFDebugPubTable.cpp:22
llvm::dwarf::PubIndexEntryDescriptor
Describes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:715
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::DWARFDebugPubTable::Set::Version
uint16_t Version
This number is specific to the name lookup table and is independent of the DWARF version number.
Definition: DWARFDebugPubTable.h:53
raw_ostream.h
llvm::dwarf::getDwarfOffsetByteSize
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:635
llvm::DWARFDebugPubTable::Set::Format
dwarf::DwarfFormat Format
The DWARF format of the set.
Definition: DWARFDebugPubTable.h:49
DWARFDataExtractor.h
llvm::DataExtractor::getU16
uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
Definition: DataExtractor.cpp:93