1//===- DWARFDebugAbbrev.h ---------------------------------------*- 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#ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGABBREV_H
10#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGABBREV_H
11
12#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
13#include "llvm/Support/DataExtractor.h"
14#include <cstdint>
15#include <map>
16#include <vector>
17
18namespace llvm {
19
20class raw_ostream;
21
22class DWARFAbbreviationDeclarationSet {
23 uint64_t Offset;
24 /// Code of the first abbreviation, if all abbreviations in the set have
25 /// consecutive codes. UINT32_MAX otherwise.
26 uint32_t FirstAbbrCode;
27 std::vector<DWARFAbbreviationDeclaration> Decls;
28
29 using const_iterator =
30 std::vector<DWARFAbbreviationDeclaration>::const_iterator;
31
32public:
33 DWARFAbbreviationDeclarationSet();
34
35 uint64_t getOffset() const { return Offset; }
36 void dump(raw_ostream &OS) const;
37 Error extract(DataExtractor Data, uint64_t *OffsetPtr);
38
39 const DWARFAbbreviationDeclaration *
40 getAbbreviationDeclaration(uint32_t AbbrCode) const;
41
42 const_iterator begin() const {
43 return Decls.begin();
44 }
45
46 const_iterator end() const {
47 return Decls.end();
48 }
49
50 std::string getCodeRange() const;
51
52 uint32_t getFirstAbbrCode() const { return FirstAbbrCode; }
53
54private:
55 void clear();
56};
57
58class DWARFDebugAbbrev {
59 using DWARFAbbreviationDeclarationSetMap =
60 std::map<uint64_t, DWARFAbbreviationDeclarationSet>;
61
62 mutable DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
63 mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
64 mutable std::optional<DataExtractor> Data;
65
66public:
67 DWARFDebugAbbrev(DataExtractor Data);
68
69 Expected<const DWARFAbbreviationDeclarationSet *>
70 getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
71
72 void dump(raw_ostream &OS) const;
73 Error parse() const;
74
75 DWARFAbbreviationDeclarationSetMap::const_iterator begin() const {
76 assert(!Data && "Must call parse before iterating over DWARFDebugAbbrev");
77 return AbbrDeclSets.begin();
78 }
79
80 DWARFAbbreviationDeclarationSetMap::const_iterator end() const {
81 return AbbrDeclSets.end();
82 }
83};
84
85} // end namespace llvm
86
87#endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGABBREV_H
88

source code of llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h