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 
18 namespace llvm {
19 
20 class raw_ostream;
21 
22 class 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 
32 public:
33   DWARFAbbreviationDeclarationSet();
34 
35   uint64_t getOffset() const { return Offset; }
36   void dump(raw_ostream &OS) const;
37   bool 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 private:
53   void clear();
54 };
55 
56 class DWARFDebugAbbrev {
57   using DWARFAbbreviationDeclarationSetMap =
58       std::map<uint64_t, DWARFAbbreviationDeclarationSet>;
59 
60   mutable DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
61   mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
62   mutable std::optional<DataExtractor> Data;
63 
64 public:
65   DWARFDebugAbbrev();
66 
67   const DWARFAbbreviationDeclarationSet *
68   getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
69 
70   void dump(raw_ostream &OS) const;
71   void parse() const;
72   void extract(DataExtractor Data);
73 
74   DWARFAbbreviationDeclarationSetMap::const_iterator begin() const {
75     parse();
76     return AbbrDeclSets.begin();
77   }
78 
79   DWARFAbbreviationDeclarationSetMap::const_iterator end() const {
80     return AbbrDeclSets.end();
81   }
82 
83 private:
84   void clear();
85 };
86 
87 } // end namespace llvm
88 
89 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGABBREV_H
90