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