1//===-- bolt/Core/GDBIndex.h - GDB Index support ----------------*- C++ -*-===//
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///
9/// This file contains declaration of classes required for generation of
10/// .gdb_index section.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef BOLT_CORE_GDB_INDEX_H
15#define BOLT_CORE_GDB_INDEX_H
16
17#include "bolt/Core/BinaryContext.h"
18#include <vector>
19
20namespace llvm {
21namespace bolt {
22
23class GDBIndex {
24public:
25 /// Contains information about TU so we can write out correct entries in GDB
26 /// index.
27 struct GDBIndexTUEntry {
28 uint64_t UnitOffset;
29 uint64_t TypeHash;
30 uint64_t TypeDIERelativeOffset;
31 };
32
33private:
34 BinaryContext &BC;
35
36 /// Entries for GDB Index Types CU List.
37 using GDBIndexTUEntryType = std::vector<GDBIndexTUEntry>;
38 GDBIndexTUEntryType GDBIndexTUEntryVector;
39
40public:
41 GDBIndex(BinaryContext &BC) : BC(BC) {}
42
43 std::mutex GDBIndexMutex;
44
45 /// Adds an GDBIndexTUEntry if .gdb_index section exists.
46 void addGDBTypeUnitEntry(const GDBIndexTUEntry &&Entry);
47
48 /// Rewrite .gdb_index section if present.
49 void updateGdbIndexSection(const CUOffsetMap &CUMap, const uint32_t NumCUs,
50 DebugARangesSectionWriter &ARangesSectionWriter);
51
52 /// Returns all entries needed for Types CU list.
53 const GDBIndexTUEntryType &getGDBIndexTUEntryVector() const {
54 return GDBIndexTUEntryVector;
55 }
56
57 /// Sorts entries in GDBIndexTUEntryVector according to the TypeHash.
58 void sortGDBIndexTUEntryVector() {
59 llvm::stable_sort(Range&: GDBIndexTUEntryVector, C: [](const GDBIndexTUEntry &LHS,
60 const GDBIndexTUEntry &RHS) {
61 return LHS.TypeHash > RHS.TypeHash;
62 });
63 }
64};
65
66} // namespace bolt
67} // namespace llvm
68
69#endif
70

source code of bolt/include/bolt/Core/GDBIndex.h