1 | //===-- CFBasicHash.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 LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_CFBASICHASH_H |
10 | #define LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_CFBASICHASH_H |
11 | |
12 | #include "lldb/Target/Process.h" |
13 | #include "lldb/Target/Target.h" |
14 | |
15 | namespace lldb_private { |
16 | |
17 | class CFBasicHash { |
18 | public: |
19 | enum class HashType { set = 0, dict }; |
20 | |
21 | CFBasicHash() = default; |
22 | ~CFBasicHash() = default; |
23 | |
24 | bool Update(lldb::addr_t addr, ExecutionContextRef exe_ctx_rf); |
25 | |
26 | bool IsValid() const; |
27 | |
28 | bool IsMutable() const { return m_mutable; }; |
29 | bool IsMultiVariant() const { return m_multi; } |
30 | HashType GetType() const { return m_type; } |
31 | |
32 | size_t GetCount() const; |
33 | lldb::addr_t GetKeyPointer() const; |
34 | lldb::addr_t GetValuePointer() const; |
35 | |
36 | private: |
37 | template <typename T> struct __CFBasicHash { |
38 | struct RuntimeBase { |
39 | T cfisa; |
40 | T cfinfoa; |
41 | } base; |
42 | |
43 | struct Bits { |
44 | uint16_t __reserved0; |
45 | uint16_t __reserved1 : 2; |
46 | uint16_t keys_offset : 1; |
47 | uint16_t counts_offset : 2; |
48 | uint16_t counts_width : 2; |
49 | uint16_t __reserved2 : 9; |
50 | uint32_t used_buckets; // number of used buckets |
51 | uint64_t deleted : 16; // number of elements deleted |
52 | uint64_t num_buckets_idx : 8; // index to number of buckets |
53 | uint64_t __reserved3 : 40; |
54 | uint64_t __reserved4; |
55 | } bits; |
56 | |
57 | T pointers[3]; |
58 | }; |
59 | template <typename T> bool UpdateFor(std::unique_ptr<__CFBasicHash<T>> &m_ht); |
60 | |
61 | size_t GetPointerCount() const; |
62 | |
63 | uint32_t m_ptr_size = UINT32_MAX; |
64 | lldb::ByteOrder m_byte_order = lldb::eByteOrderInvalid; |
65 | Address m_address = LLDB_INVALID_ADDRESS; |
66 | std::unique_ptr<__CFBasicHash<uint32_t>> m_ht_32 = nullptr; |
67 | std::unique_ptr<__CFBasicHash<uint64_t>> m_ht_64 = nullptr; |
68 | ExecutionContextRef m_exe_ctx_ref; |
69 | bool m_mutable = true; |
70 | bool m_multi = false; |
71 | HashType m_type = HashType::set; |
72 | }; |
73 | |
74 | } // namespace lldb_private |
75 | |
76 | #endif // LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_CFBASICHASH_H |
77 | |