LLVM  11.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/Format.h"
16 #include <cstdint>
17 
18 using namespace llvm;
19 using namespace dwarf;
20 
22  const DWARFSection &Sec,
23  bool LittleEndian, bool GnuStyle)
24  : GnuStyle(GnuStyle) {
25  DWARFDataExtractor PubNames(Obj, Sec, LittleEndian, 0);
26  uint64_t Offset = 0;
27  while (PubNames.isValidOffset(Offset)) {
28  Sets.push_back({});
29  Set &SetData = Sets.back();
30 
31  std::tie(SetData.Length, SetData.Format) =
32  PubNames.getInitialLength(&Offset);
33  const unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(SetData.Format);
34 
35  SetData.Version = PubNames.getU16(&Offset);
36  SetData.Offset = PubNames.getRelocatedValue(OffsetSize, &Offset);
37  SetData.Size = PubNames.getUnsigned(&Offset, OffsetSize);
38 
39  while (Offset < Sec.Data.size()) {
40  uint64_t DieRef = PubNames.getUnsigned(&Offset, OffsetSize);
41  if (DieRef == 0)
42  break;
43  uint8_t IndexEntryValue = GnuStyle ? PubNames.getU8(&Offset) : 0;
44  StringRef Name = PubNames.getCStrRef(&Offset);
45  SetData.Entries.push_back(
46  {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
47  }
48  }
49 }
50 
52  for (const Set &S : Sets) {
53  int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(S.Format);
54  OS << "length = " << format("0x%0*" PRIx64, OffsetDumpWidth, S.Length);
55  OS << ", format = " << dwarf::FormatString(S.Format);
56  OS << ", version = " << format("0x%04x", S.Version);
57  OS << ", unit_offset = "
58  << format("0x%0*" PRIx64, OffsetDumpWidth, S.Offset);
59  OS << ", unit_size = " << format("0x%0*" PRIx64, OffsetDumpWidth, S.Size)
60  << '\n';
61  OS << (GnuStyle ? "Offset Linkage Kind Name\n"
62  : "Offset Name\n");
63 
64  for (const Entry &E : S.Entries) {
65  OS << format("0x%0*" PRIx64 " ", OffsetDumpWidth, E.SecOffset);
66  if (GnuStyle) {
67  StringRef EntryLinkage =
70  OS << format("%-8s", EntryLinkage.data()) << ' '
71  << format("%-8s", EntryKind.data()) << ' ';
72  }
73  OS << '\"' << E.Name << "\"\n";
74  }
75  }
76 }
uint8_t getU8(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint8_t value from *offset_ptr.
uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
void dump(raw_ostream &OS) const
uint64_t Offset
The offset from the beginning of the .debug_info section of the compilation unit header referenced by...
Each table consists of sets of variable length entries.
std::pair< uint64_t, dwarf::DwarfFormat > getInitialLength(uint64_t *Off, Error *Err=nullptr) const
Extracts the DWARF "initial length" field, which can either be a 32-bit value smaller than 0xfffffff0...
DWARFDebugPubTable(const DWARFObject &Obj, const DWARFSection &Sec, bool LittleEndian, bool GnuStyle)
Describes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:621
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...
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:160
StringRef FormatString(DwarfFormat Format)
Definition: Dwarf.cpp:773
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:589
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.
uint64_t SecOffset
Section offset from the beginning of the compilation unit.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:612
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:623
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
uint64_t Size
The size in bytes of the contents of the .debug_info section generated to represent that compilation ...
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
This file contains constants used for implementing Dwarf debug support.
uint64_t Length
The total length of the entries for that set, not including the length field itself.
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:541
dwarf::PubIndexEntryDescriptor Descriptor
An entry of the various gnu_pub* debug sections.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:152
uint16_t Version
This number is specific to the name lookup table and is independent of the DWARF version number...
dwarf::DwarfFormat Format
The DWARF format of the set.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
StringRef getCStrRef(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a C string from *offset_ptr.
StringRef Name
The name of the object as given by the DW_AT_name attribute of the referenced DIE.