Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/ObjC/CFBasicHash.cpp
Line
Count
Source (jump to first uncovered line)
1
#include "CFBasicHash.h"
2
3
#include "lldb/Utility/Endian.h"
4
5
using namespace lldb;
6
using namespace lldb_private;
7
8
333
bool CFBasicHash::IsValid() const {
9
333
  if (m_address != LLDB_INVALID_ADDRESS) {
10
333
    if (m_ptr_size == 4 && 
m_ht_320
)
11
0
      return true;
12
333
    else if (m_ptr_size == 8 && m_ht_64)
13
333
      return true;
14
0
    else
15
0
      return false;
16
333
  }
17
0
  return false;
18
333
}
19
20
138
bool CFBasicHash::Update(addr_t addr, ExecutionContextRef exe_ctx_rf) {
21
138
  if (addr == LLDB_INVALID_ADDRESS || !addr)
22
0
    return false;
23
24
138
  m_address = addr;
25
138
  m_exe_ctx_ref = exe_ctx_rf;
26
138
  m_ptr_size =
27
138
      m_exe_ctx_ref.GetTargetSP()->GetArchitecture().GetAddressByteSize();
28
138
  m_byte_order = m_exe_ctx_ref.GetTargetSP()->GetArchitecture().GetByteOrder();
29
30
138
  if (m_ptr_size == 4)
31
0
    return UpdateFor(m_ht_32);
32
138
  else if (m_ptr_size == 8)
33
138
    return UpdateFor(m_ht_64);
34
0
  return false;
35
36
0
  llvm_unreachable(
37
0
      "Unsupported architecture. Only 32bits and 64bits supported.");
38
0
}
39
40
template <typename T>
41
138
bool CFBasicHash::UpdateFor(std::unique_ptr<__CFBasicHash<T>> &m_ht) {
42
138
  if (m_byte_order != endian::InlHostByteOrder())
43
0
    return false;
44
  
45
138
  Status error;
46
138
  Target *target = m_exe_ctx_ref.GetTargetSP().get();
47
138
  addr_t addr = m_address.GetLoadAddress(target);
48
138
  size_t size = sizeof(typename __CFBasicHash<T>::RuntimeBase) +
49
138
                sizeof(typename __CFBasicHash<T>::Bits);
50
51
138
  m_ht = std::make_unique<__CFBasicHash<T>>();
52
138
  m_exe_ctx_ref.GetProcessSP()->ReadMemory(addr, m_ht.get(),
53
138
                                           size, error);
54
138
  if (error.Fail())
55
0
    return false;
56
57
138
  m_mutable = !(m_ht->base.cfinfoa & (1 << 6));
58
138
  m_multi = m_ht->bits.counts_offset;
59
138
  m_type = static_cast<HashType>(m_ht->bits.keys_offset);
60
138
  addr_t ptr_offset = addr + size;
61
138
  size_t ptr_count = GetPointerCount();
62
138
  size = ptr_count * sizeof(T);
63
64
138
  m_exe_ctx_ref.GetProcessSP()->ReadMemory(ptr_offset, m_ht->pointers, size,
65
138
                                           error);
66
67
138
  if (error.Fail()) {
68
0
    m_ht = nullptr;
69
0
    return false;
70
0
  }
71
72
138
  return true;
73
138
}
Unexecuted instantiation: bool lldb_private::CFBasicHash::UpdateFor<unsigned int>(std::__1::unique_ptr<lldb_private::CFBasicHash::__CFBasicHash<unsigned int>, std::__1::default_delete<lldb_private::CFBasicHash::__CFBasicHash<unsigned int> > >&)
bool lldb_private::CFBasicHash::UpdateFor<unsigned long long>(std::__1::unique_ptr<lldb_private::CFBasicHash::__CFBasicHash<unsigned long long>, std::__1::default_delete<lldb_private::CFBasicHash::__CFBasicHash<unsigned long long> > >&)
Line
Count
Source
41
138
bool CFBasicHash::UpdateFor(std::unique_ptr<__CFBasicHash<T>> &m_ht) {
42
138
  if (m_byte_order != endian::InlHostByteOrder())
43
0
    return false;
44
  
45
138
  Status error;
46
138
  Target *target = m_exe_ctx_ref.GetTargetSP().get();
47
138
  addr_t addr = m_address.GetLoadAddress(target);
48
138
  size_t size = sizeof(typename __CFBasicHash<T>::RuntimeBase) +
49
138
                sizeof(typename __CFBasicHash<T>::Bits);
50
51
138
  m_ht = std::make_unique<__CFBasicHash<T>>();
52
138
  m_exe_ctx_ref.GetProcessSP()->ReadMemory(addr, m_ht.get(),
53
138
                                           size, error);
54
138
  if (error.Fail())
55
0
    return false;
56
57
138
  m_mutable = !(m_ht->base.cfinfoa & (1 << 6));
58
138
  m_multi = m_ht->bits.counts_offset;
59
138
  m_type = static_cast<HashType>(m_ht->bits.keys_offset);
60
138
  addr_t ptr_offset = addr + size;
61
138
  size_t ptr_count = GetPointerCount();
62
138
  size = ptr_count * sizeof(T);
63
64
138
  m_exe_ctx_ref.GetProcessSP()->ReadMemory(ptr_offset, m_ht->pointers, size,
65
138
                                           error);
66
67
138
  if (error.Fail()) {
68
0
    m_ht = nullptr;
69
0
    return false;
70
0
  }
71
72
138
  return true;
73
138
}
74
75
105
size_t CFBasicHash::GetCount() const {
76
105
  if (!IsValid())
77
0
    return 0;
78
79
105
  if (!m_multi)
80
105
    return (m_ptr_size == 4) ? 
m_ht_32->bits.used_buckets0
81
105
                             : m_ht_64->bits.used_buckets;
82
83
  //  FIXME: Add support for multi
84
0
  return 0;
85
105
}
86
87
138
size_t CFBasicHash::GetPointerCount() const {
88
138
  if (!IsValid())
89
0
    return 0;
90
91
138
  if (m_multi)
92
0
    return 3; // Bits::counts_offset;
93
138
  return (m_type == HashType::dict) + 1;
94
138
}
95
96
18
addr_t CFBasicHash::GetKeyPointer() const {
97
18
  if (!IsValid())
98
0
    return LLDB_INVALID_ADDRESS;
99
100
18
  if (m_ptr_size == 4)
101
0
    return m_ht_32->pointers[m_ht_32->bits.keys_offset];
102
103
18
  return m_ht_64->pointers[m_ht_64->bits.keys_offset];
104
18
}
105
106
30
addr_t CFBasicHash::GetValuePointer() const {
107
30
  if (!IsValid())
108
0
    return LLDB_INVALID_ADDRESS;
109
110
30
  if (m_ptr_size == 4)
111
0
    return m_ht_32->pointers[0];
112
113
30
  return m_ht_64->pointers[0];
114
30
}