LLVM  10.0.0svn
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  SetData.Length = PubNames.getU32(&Offset);
32  SetData.Version = PubNames.getU16(&Offset);
33  SetData.Offset = PubNames.getRelocatedValue(4, &Offset);
34  SetData.Size = PubNames.getU32(&Offset);
35 
36  while (Offset < Sec.Data.size()) {
37  uint32_t DieRef = PubNames.getU32(&Offset);
38  if (DieRef == 0)
39  break;
40  uint8_t IndexEntryValue = GnuStyle ? PubNames.getU8(&Offset) : 0;
41  StringRef Name = PubNames.getCStrRef(&Offset);
42  SetData.Entries.push_back(
43  {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
44  }
45  }
46 }
47 
49  for (const Set &S : Sets) {
50  OS << "length = " << format("0x%08x", S.Length);
51  OS << " version = " << format("0x%04x", S.Version);
52  OS << " unit_offset = " << format("0x%08" PRIx64, S.Offset);
53  OS << " unit_size = " << format("0x%08x", S.Size) << '\n';
54  OS << (GnuStyle ? "Offset Linkage Kind Name\n"
55  : "Offset Name\n");
56 
57  for (const Entry &E : S.Entries) {
58  OS << format("0x%8.8" PRIx64 " ", E.SecOffset);
59  if (GnuStyle) {
60  StringRef EntryLinkage =
63  OS << format("%-8s", EntryLinkage.data()) << ' '
64  << format("%-8s", EntryKind.data()) << ' ';
65  }
66  OS << '\"' << E.Name << "\"\n";
67  }
68  }
69 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
uint32_t getU32(uint64_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
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 getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
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.
DWARFDebugPubTable(const DWARFObject &Obj, const DWARFSection &Sec, bool LittleEndian, bool GnuStyle)
Describes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:550
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:545
uint64_t SecOffset
Section offset from the beginning of the compilation unit.
uint32_t Size
The size in bytes of the contents of the .debug_info section generated to represent that compilation ...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint32_t Length
The total length of the entries for that set, not including the length field itself.
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:568
uint8_t getU8(uint64_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:552
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
This file contains constants used for implementing Dwarf debug support.
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:122
uint16_t Version
This number is specific to the name lookup table and is independent of the DWARF version number...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
StringRef getCStrRef(uint64_t *offset_ptr) const
Extract a C string from *offset_ptr.
uint16_t getU16(uint64_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
StringRef Name
The name of the object as given by the DW_AT_name attribute of the referenced DIE.