Coverage Report

Created: 2022-01-18 06:27

/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 <vector>
14
15
#include "lldb/Utility/ConstString.h"
16
#include "lldb/Utility/RangeMap.h"
17
#include "llvm/ADT/Optional.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
184k
  MemoryRegionInfo() = default;
28
  MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
29
                   OptionalBool execute, OptionalBool mapped, ConstString name,
30
                   OptionalBool flash, lldb::offset_t blocksize,
31
                   OptionalBool memory_tagged, OptionalBool stack_memory)
32
      : m_range(range), m_read(read), m_write(write), m_execute(execute),
33
        m_mapped(mapped), m_name(name), m_flash(flash), m_blocksize(blocksize),
34
        m_memory_tagged(memory_tagged), m_is_stack_memory(stack_memory) {}
35
36
304k
  RangeType &GetRange() { return m_range; }
37
38
61.2k
  void Clear() { *this = MemoryRegionInfo(); }
39
40
6.37k
  const RangeType &GetRange() const { return m_range; }
41
42
12.7k
  OptionalBool GetReadable() const { return m_read; }
43
44
12.7k
  OptionalBool GetWritable() const { return m_write; }
45
46
12.7k
  OptionalBool GetExecutable() const { return m_execute; }
47
48
965
  OptionalBool GetMapped() const { return m_mapped; }
49
50
654
  ConstString GetName() const { return m_name; }
51
52
597
  OptionalBool GetMemoryTagged() const { return m_memory_tagged; }
53
54
62.4k
  void SetReadable(OptionalBool val) { m_read = val; }
55
56
62.3k
  void SetWritable(OptionalBool val) { m_write = val; }
57
58
62.3k
  void SetExecutable(OptionalBool val) { m_execute = val; }
59
60
62.4k
  void SetMapped(OptionalBool val) { m_mapped = val; }
61
62
537
  void SetName(const char *name) { m_name = ConstString(name); }
63
64
54.2k
  OptionalBool GetFlash() const { return m_flash; }
65
66
1
  void SetFlash(OptionalBool val) { m_flash = val; }
67
68
392
  lldb::offset_t GetBlocksize() const { return m_blocksize; }
69
70
1
  void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
71
72
10
  void SetMemoryTagged(OptionalBool val) { m_memory_tagged = val; }
73
74
  // Get permissions as a uint32_t that is a mask of one or more bits from the
75
  // lldb::Permissions
76
0
  uint32_t GetLLDBPermissions() const {
77
0
    uint32_t permissions = 0;
78
0
    if (m_read)
79
0
      permissions |= lldb::ePermissionsReadable;
80
0
    if (m_write)
81
0
      permissions |= lldb::ePermissionsWritable;
82
0
    if (m_execute)
83
0
      permissions |= lldb::ePermissionsExecutable;
84
0
    return permissions;
85
0
  }
86
87
  // Set permissions from a uint32_t that contains one or more bits from the
88
  // lldb::Permissions
89
36
  void SetLLDBPermissions(uint32_t permissions) {
90
36
    m_read = (permissions & lldb::ePermissionsReadable) ? eYes : 
eNo0
;
91
36
    m_write = (permissions & lldb::ePermissionsWritable) ? 
eYes2
:
eNo34
;
92
36
    m_execute = (permissions & lldb::ePermissionsExecutable) ? 
eYes32
:
eNo4
;
93
36
  }
94
95
840
  bool operator==(const MemoryRegionInfo &rhs) const {
96
840
    return m_range == rhs.m_range && 
m_read == rhs.m_read642
&&
97
840
           
m_write == rhs.m_write642
&&
m_execute == rhs.m_execute642
&&
98
840
           
m_mapped == rhs.m_mapped642
&&
m_name == rhs.m_name642
&&
99
840
           
m_flash == rhs.m_flash642
&&
m_blocksize == rhs.m_blocksize642
&&
100
840
           
m_memory_tagged == rhs.m_memory_tagged642
&&
101
840
           
m_pagesize == rhs.m_pagesize642
&&
102
840
           
m_is_stack_memory == rhs.m_is_stack_memory642
;
103
840
  }
104
105
198
  bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
106
107
  /// Get the target system's VM page size in bytes.
108
  /// \return
109
  ///     0 is returned if this information is unavailable.
110
1
  int GetPageSize() { return m_pagesize; }
111
112
  /// Get a vector of target VM pages that are dirty -- that have been
113
  /// modified -- within this memory region.  This is an Optional return
114
  /// value; it will only be available if the remote stub was able to
115
  /// detail this.
116
199
  llvm::Optional<std::vector<lldb::addr_t>> &GetDirtyPageList() {
117
199
    return m_dirty_pages;
118
199
  }
119
120
0
  OptionalBool IsStackMemory() const { return m_is_stack_memory; }
121
122
0
  void SetIsStackMemory(OptionalBool val) { m_is_stack_memory = val; }
123
124
4
  void SetPageSize(int pagesize) { m_pagesize = pagesize; }
125
126
3
  void SetDirtyPageList(std::vector<lldb::addr_t> pagelist) {
127
3
    if (m_dirty_pages.hasValue())
128
0
      m_dirty_pages.getValue().clear();
129
3
    m_dirty_pages = std::move(pagelist);
130
3
  }
131
132
protected:
133
  RangeType m_range;
134
  OptionalBool m_read = eDontKnow;
135
  OptionalBool m_write = eDontKnow;
136
  OptionalBool m_execute = eDontKnow;
137
  OptionalBool m_mapped = eDontKnow;
138
  ConstString m_name;
139
  OptionalBool m_flash = eDontKnow;
140
  lldb::offset_t m_blocksize = 0;
141
  OptionalBool m_memory_tagged = eDontKnow;
142
  OptionalBool m_is_stack_memory = eDontKnow;
143
  int m_pagesize = 0;
144
  llvm::Optional<std::vector<lldb::addr_t>> m_dirty_pages;
145
};
146
  
147
inline bool operator<(const MemoryRegionInfo &lhs,
148
2.38k
                      const MemoryRegionInfo &rhs) {
149
2.38k
  return lhs.GetRange() < rhs.GetRange();
150
2.38k
}
151
152
0
inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
153
0
  return lhs.GetRange().GetRangeBase() < rhs;
154
0
}
155
156
554
inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
157
554
  return lhs < rhs.GetRange().GetRangeBase();
158
554
}
159
160
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
161
                              const MemoryRegionInfo &Info);
162
163
// Forward-declarable wrapper.
164
class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
165
public:
166
  using std::vector<lldb_private::MemoryRegionInfo>::vector;
167
};
168
169
}
170
171
namespace llvm {
172
template <>
173
/// If Options is empty, prints a textual representation of the value. If
174
/// Options is a single character, it uses that character for the "yes" value,
175
/// while "no" is printed as "-", and "don't know" as "?". This can be used to
176
/// print the permissions in the traditional "rwx" form.
177
struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
178
  static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
179
                     raw_ostream &OS, StringRef Options);
180
};
181
}
182
183
#endif // LLDB_TARGET_MEMORYREGIONINFO_H