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_DWARFDEBUGABBREV_H 10 #define LLVM_DEBUGINFO_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 private: 51 void clear(); 52 }; 53 54 class DWARFDebugAbbrev { 55 using DWARFAbbreviationDeclarationSetMap = 56 std::map<uint64_t, DWARFAbbreviationDeclarationSet>; 57 58 mutable DWARFAbbreviationDeclarationSetMap AbbrDeclSets; 59 mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos; 60 mutable Optional<DataExtractor> Data; 61 62 public: 63 DWARFDebugAbbrev(); 64 65 const DWARFAbbreviationDeclarationSet * 66 getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const; 67 68 void dump(raw_ostream &OS) const; 69 void parse() const; 70 void extract(DataExtractor Data); 71 72 DWARFAbbreviationDeclarationSetMap::const_iterator begin() const { 73 parse(); 74 return AbbrDeclSets.begin(); 75 } 76 77 DWARFAbbreviationDeclarationSetMap::const_iterator end() const { 78 return AbbrDeclSets.end(); 79 } 80 81 private: 82 void clear(); 83 }; 84 85 } // end namespace llvm 86 87 #endif // LLVM_DEBUGINFO_DWARFDEBUGABBREV_H 88