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 SymbolFileDWARF_DWARFDebugAbbrev_h_
10#define SymbolFileDWARF_DWARFDebugAbbrev_h_
11
12#include <list>
13#include <map>
14
15#include "lldb/lldb-private.h"
16
17#include "DWARFAbbreviationDeclaration.h"
18#include "DWARFDefines.h"
19
20typedef std::vector<DWARFAbbreviationDeclaration>
21    DWARFAbbreviationDeclarationColl;
22typedef DWARFAbbreviationDeclarationColl::iterator
23    DWARFAbbreviationDeclarationCollIter;
24typedef DWARFAbbreviationDeclarationColl::const_iterator
25    DWARFAbbreviationDeclarationCollConstIter;
26
27class DWARFAbbreviationDeclarationSet {
28public:
29  DWARFAbbreviationDeclarationSet()
30      : m_offset(DW_INVALID_OFFSET), m_idx_offset(0), m_decls() {}
31
32  DWARFAbbreviationDeclarationSet(dw_offset_t offset, uint32_t idx_offset)
33      : m_offset(offset), m_idx_offset(idx_offset), m_decls() {}
34
35  void Clear();
36  dw_offset_t GetOffset() const { return m_offset; }
37
38  /// Extract all abbrev decls in a set.  Returns llvm::ErrorSuccess() on
39  /// success, and an appropriate llvm::Error object otherwise.
40  llvm::Error extract(const lldb_private::DWARFDataExtractor &data,
41                      lldb::offset_t *offset_ptr);
42  // void Encode(BinaryStreamBuf& debug_abbrev_buf) const;
43  void GetUnsupportedForms(std::set<dw_form_t> &invalid_forms) const;
44
45  const DWARFAbbreviationDeclaration *
46  GetAbbreviationDeclaration(dw_uleb128_t abbrCode) const;
47
48  /// Unit test accessor functions.
49  /// @{
50  uint32_t GetIndexOffset() const { return m_idx_offset; }
51  /// @}
52private:
53  dw_offset_t m_offset;
54  uint32_t m_idx_offset;
55  std::vector<DWARFAbbreviationDeclaration> m_decls;
56};
57
58typedef std::map<dw_offset_t, DWARFAbbreviationDeclarationSet>
59    DWARFAbbreviationDeclarationCollMap;
60typedef DWARFAbbreviationDeclarationCollMap::iterator
61    DWARFAbbreviationDeclarationCollMapIter;
62typedef DWARFAbbreviationDeclarationCollMap::const_iterator
63    DWARFAbbreviationDeclarationCollMapConstIter;
64
65class DWARFDebugAbbrev {
66public:
67  DWARFDebugAbbrev();
68  const DWARFAbbreviationDeclarationSet *
69  GetAbbreviationDeclarationSet(dw_offset_t cu_abbr_offset) const;
70  /// Extract all abbreviations for a particular compile unit.  Returns
71  /// llvm::ErrorSuccess() on success, and an appropriate llvm::Error object
72  /// otherwise.
73  llvm::Error parse(const lldb_private::DWARFDataExtractor &data);
74  void GetUnsupportedForms(std::set<dw_form_t> &invalid_forms) const;
75
76protected:
77  DWARFAbbreviationDeclarationCollMap m_abbrevCollMap;
78  mutable DWARFAbbreviationDeclarationCollMapConstIter m_prev_abbr_offset_pos;
79};
80
81#endif // SymbolFileDWARF_DWARFDebugAbbrev_h_
82