1 #include "CFBasicHash.h"
3 #include "lldb/Utility/Endian.h"
6 using namespace lldb_private
;
8 bool CFBasicHash::IsValid() const {
9 if (m_address
!= LLDB_INVALID_ADDRESS
) {
10 if (m_ptr_size
== 4 && m_ht_32
)
12 else if (m_ptr_size
== 8 && m_ht_64
)
20 bool CFBasicHash::Update(addr_t addr
, ExecutionContextRef exe_ctx_rf
) {
21 if (addr
== LLDB_INVALID_ADDRESS
|| !addr
)
25 m_exe_ctx_ref
= exe_ctx_rf
;
27 m_exe_ctx_ref
.GetTargetSP()->GetArchitecture().GetAddressByteSize();
28 m_byte_order
= m_exe_ctx_ref
.GetTargetSP()->GetArchitecture().GetByteOrder();
31 return UpdateFor(m_ht_32
);
32 else if (m_ptr_size
== 8)
33 return UpdateFor(m_ht_64
);
37 "Unsupported architecture. Only 32bits and 64bits supported.");
41 bool CFBasicHash::UpdateFor(std::unique_ptr
<__CFBasicHash
<T
>> &m_ht
) {
42 if (m_byte_order
!= endian::InlHostByteOrder())
46 Target
*target
= m_exe_ctx_ref
.GetTargetSP().get();
47 addr_t addr
= m_address
.GetLoadAddress(target
);
48 size_t size
= sizeof(typename __CFBasicHash
<T
>::RuntimeBase
) +
49 sizeof(typename __CFBasicHash
<T
>::Bits
);
51 m_ht
= std::make_unique
<__CFBasicHash
<T
>>();
52 m_exe_ctx_ref
.GetProcessSP()->ReadMemory(addr
, m_ht
.get(),
57 m_mutable
= !(m_ht
->base
.cfinfoa
& (1 << 6));
58 m_multi
= m_ht
->bits
.counts_offset
;
59 m_type
= static_cast<HashType
>(m_ht
->bits
.keys_offset
);
60 addr_t ptr_offset
= addr
+ size
;
61 size_t ptr_count
= GetPointerCount();
62 size
= ptr_count
* sizeof(T
);
64 m_exe_ctx_ref
.GetProcessSP()->ReadMemory(ptr_offset
, m_ht
->pointers
, size
,
75 size_t CFBasicHash::GetCount() const {
80 return (m_ptr_size
== 4) ? m_ht_32
->bits
.used_buckets
81 : m_ht_64
->bits
.used_buckets
;
83 // FIXME: Add support for multi
87 size_t CFBasicHash::GetPointerCount() const {
92 return 3; // Bits::counts_offset;
93 return (m_type
== HashType::dict
) + 1;
96 addr_t
CFBasicHash::GetKeyPointer() const {
98 return LLDB_INVALID_ADDRESS
;
101 return m_ht_32
->pointers
[m_ht_32
->bits
.keys_offset
];
103 return m_ht_64
->pointers
[m_ht_64
->bits
.keys_offset
];
106 addr_t
CFBasicHash::GetValuePointer() const {
108 return LLDB_INVALID_ADDRESS
;
111 return m_ht_32
->pointers
[0];
113 return m_ht_64
->pointers
[0];