1 //===- GdbIndex.h --------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===-------------------------------------------------------------------===//
10 #ifndef LLD_ELF_GDB_INDEX_H
11 #define LLD_ELF_GDB_INDEX_H
13 #include "InputFiles.h"
14 #include "llvm/Object/ELF.h"
15 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
20 template <class ELFT> class InputSection;
22 // Struct represents single entry of address area of gdb index.
23 template <class ELFT> struct AddressEntry {
24 InputSectionBase<ELFT> *Section;
30 // GdbIndexBuilder is a helper class used for extracting data required
31 // for building .gdb_index section from objects.
32 template <class ELFT> class GdbIndexBuilder : public llvm::LoadedObjectInfo {
33 typedef typename ELFT::uint uintX_t;
35 InputSection<ELFT> *DebugInfoSec;
37 std::unique_ptr<llvm::DWARFContext> Dwarf;
40 GdbIndexBuilder(InputSection<ELFT> *DebugInfoSec);
42 // Extracts the compilation units. Each first element of pair is a offset of a
43 // CU in the .debug_info section and second is the length of that CU.
44 std::vector<std::pair<uintX_t, uintX_t>> readCUList();
46 // Extracts the vector of address area entries. Accepts global index of last
48 std::vector<AddressEntry<ELFT>> readAddressArea(size_t CurrentCU);
50 // Method extracts public names and types. It returns list of name and
51 // gnu_pub* kind pairs.
52 std::vector<std::pair<StringRef, uint8_t>> readPubNamesAndTypes();
55 // Method returns section file offset as a load addres for DWARF parser. That
56 // allows to find the target section index for address ranges.
58 getSectionLoadAddress(const llvm::object::SectionRef &Sec) const override;
59 std::unique_ptr<llvm::LoadedObjectInfo> clone() const override;
62 // Element of GdbHashTab hash table.
64 GdbSymbol(uint32_t Hash, size_t Offset)
65 : NameHash(Hash), NameOffset(Offset) {}
71 // This class manages the hashed symbol table for the .gdb_index section.
72 // The hash value for a table entry is computed by applying an iterative hash
73 // function to the symbol's name.
74 class GdbHashTab final {
76 std::pair<bool, GdbSymbol *> add(uint32_t Hash, size_t Offset);
78 size_t getCapacity() { return Table.size(); }
79 GdbSymbol *getSymbol(size_t I) { return Table[I]; }
84 GdbSymbol **findSlot(uint32_t Hash, size_t Offset);
86 llvm::BumpPtrAllocator Alloc;
87 std::vector<GdbSymbol *> Table;
89 // Size keeps the amount of filled entries in Table.
92 // Initial size must be a power of 2.
93 static const int32_t InitialSize = 1024;