Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Target/MemoryRegionInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===-- MemoryRegionInfo.h ---------------------------------------*- C++
2
//-*-===//
3
//
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
// See https://llvm.org/LICENSE.txt for license information.
6
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLDB_TARGET_MEMORYREGIONINFO_H
11
#define LLDB_TARGET_MEMORYREGIONINFO_H
12
13
#include <optional>
14
#include <vector>
15
16
#include "lldb/Utility/ConstString.h"
17
#include "lldb/Utility/RangeMap.h"
18
#include "llvm/Support/FormatProviders.h"
19
20
namespace lldb_private {
21
class MemoryRegionInfo {
22
public:
23
  typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
24
25
  enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
26
27
146k
  MemoryRegionInfo() = default;
28
  MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
29
                   OptionalBool execute, OptionalBool shared,
30
                   OptionalBool mapped, ConstString name,
31
                   OptionalBool flash, lldb::offset_t blocksize,
32
                   OptionalBool memory_tagged, OptionalBool stack_memory)
33
      : m_range(range), m_read(read), m_write(write), m_execute(execute),
34
        m_shared(shared), m_mapped(mapped), m_name(name), m_flash(flash),
35
        m_blocksize(blocksize), m_memory_tagged(memory_tagged),
36
        m_is_stack_memory(stack_memory) {}
37
38
336k
  RangeType &GetRange() { return m_range; }
39
40
48.7k
  void Clear() { *this = MemoryRegionInfo(); }
41
42
7.20k
  const RangeType &GetRange() const { return m_range; }
43
44
9.46k
  OptionalBool GetReadable() const { return m_read; }
45
46
9.47k
  OptionalBool GetWritable() const { return m_write; }
47
48
9.49k
  OptionalBool GetExecutable() const { return m_execute; }
49
50
0
  OptionalBool GetShared() const { return m_shared; }
51
52
1.52k
  OptionalBool GetMapped() const { return m_mapped; }
53
54
729
  ConstString GetName() const { return m_name; }
55
56
711
  OptionalBool GetMemoryTagged() const { return m_memory_tagged; }
57
58
49.9k
  void SetReadable(OptionalBool val) { m_read = val; }
59
60
49.8k
  void SetWritable(OptionalBool val) { m_write = val; }
61
62
49.8k
  void SetExecutable(OptionalBool val) { m_execute = val; }
63
64
625
  void SetShared(OptionalBool val) { m_shared = val; }
65
66
49.9k
  void SetMapped(OptionalBool val) { m_mapped = val; }
67
68
542
  void SetName(const char *name) { m_name = ConstString(name); }
69
70
42.3k
  OptionalBool GetFlash() const { return m_flash; }
71
72
1
  void SetFlash(OptionalBool val) { m_flash = val; }
73
74
257
  lldb::offset_t GetBlocksize() const { return m_blocksize; }
75
76
1
  void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
77
78
1.68k
  void SetMemoryTagged(OptionalBool val) { m_memory_tagged = val; }
79
80
  // Get permissions as a uint32_t that is a mask of one or more bits from the
81
  // lldb::Permissions
82
0
  uint32_t GetLLDBPermissions() const {
83
0
    uint32_t permissions = 0;
84
0
    if (m_read)
85
0
      permissions |= lldb::ePermissionsReadable;
86
0
    if (m_write)
87
0
      permissions |= lldb::ePermissionsWritable;
88
0
    if (m_execute)
89
0
      permissions |= lldb::ePermissionsExecutable;
90
0
    return permissions;
91
0
  }
92
93
  // Set permissions from a uint32_t that contains one or more bits from the
94
  // lldb::Permissions
95
39
  void SetLLDBPermissions(uint32_t permissions) {
96
39
    m_read = (permissions & lldb::ePermissionsReadable) ? eYes : 
eNo0
;
97
39
    m_write = (permissions & lldb::ePermissionsWritable) ? 
eYes2
:
eNo37
;
98
39
    m_execute = (permissions & lldb::ePermissionsExecutable) ? 
eYes35
:
eNo4
;
99
39
  }
100
101
0
  bool operator==(const MemoryRegionInfo &rhs) const {
102
0
    return m_range == rhs.m_range && m_read == rhs.m_read &&
103
0
           m_write == rhs.m_write && m_execute == rhs.m_execute &&
104
0
           m_shared == rhs.m_shared &&
105
0
           m_mapped == rhs.m_mapped && m_name == rhs.m_name &&
106
0
           m_flash == rhs.m_flash && m_blocksize == rhs.m_blocksize &&
107
0
           m_memory_tagged == rhs.m_memory_tagged &&
108
0
           m_pagesize == rhs.m_pagesize &&
109
0
           m_is_stack_memory == rhs.m_is_stack_memory;
110
0
  }
111
112
811
  bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
113
114
  /// Get the target system's VM page size in bytes.
115
  /// \return
116
  ///     0 is returned if this information is unavailable.
117
1
  int GetPageSize() const { return m_pagesize; }
118
119
  /// Get a vector of target VM pages that are dirty -- that have been
120
  /// modified -- within this memory region.  This is an Optional return
121
  /// value; it will only be available if the remote stub was able to
122
  /// detail this.
123
419
  const std::optional<std::vector<lldb::addr_t>> &GetDirtyPageList() const {
124
419
    return m_dirty_pages;
125
419
  }
126
127
0
  OptionalBool IsStackMemory() const { return m_is_stack_memory; }
128
129
0
  void SetIsStackMemory(OptionalBool val) { m_is_stack_memory = val; }
130
131
4
  void SetPageSize(int pagesize) { m_pagesize = pagesize; }
132
133
3
  void SetDirtyPageList(std::vector<lldb::addr_t> pagelist) {
134
3
    if (m_dirty_pages)
135
0
      m_dirty_pages->clear();
136
3
    m_dirty_pages = std::move(pagelist);
137
3
  }
138
139
protected:
140
  RangeType m_range;
141
  OptionalBool m_read = eDontKnow;
142
  OptionalBool m_write = eDontKnow;
143
  OptionalBool m_execute = eDontKnow;
144
  OptionalBool m_shared = eDontKnow;
145
  OptionalBool m_mapped = eDontKnow;
146
  ConstString m_name;
147
  OptionalBool m_flash = eDontKnow;
148
  lldb::offset_t m_blocksize = 0;
149
  OptionalBool m_memory_tagged = eDontKnow;
150
  OptionalBool m_is_stack_memory = eDontKnow;
151
  int m_pagesize = 0;
152
  std::optional<std::vector<lldb::addr_t>> m_dirty_pages;
153
};
154
  
155
inline bool operator<(const MemoryRegionInfo &lhs,
156
2.38k
                      const MemoryRegionInfo &rhs) {
157
2.38k
  return lhs.GetRange() < rhs.GetRange();
158
2.38k
}
159
160
0
inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
161
0
  return lhs.GetRange().GetRangeBase() < rhs;
162
0
}
163
164
557
inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
165
557
  return lhs < rhs.GetRange().GetRangeBase();
166
557
}
167
168
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
169
                              const MemoryRegionInfo &Info);
170
171
// Forward-declarable wrapper.
172
class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
173
public:
174
  using std::vector<lldb_private::MemoryRegionInfo>::vector;
175
};
176
177
}
178
179
namespace llvm {
180
template <>
181
/// If Options is empty, prints a textual representation of the value. If
182
/// Options is a single character, it uses that character for the "yes" value,
183
/// while "no" is printed as "-", and "don't know" as "?". This can be used to
184
/// print the permissions in the traditional "rwx" form.
185
struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
186
  static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
187
                     raw_ostream &OS, StringRef Options);
188
};
189
}
190
191
#endif // LLDB_TARGET_MEMORYREGIONINFO_H