1 //===-- MemoryRegionInfo.h ---------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef lldb_MemoryRegionInfo_h
12 #define lldb_MemoryRegionInfo_h
14 #include "lldb/Core/RangeMap.h"
15 #include "llvm/Support/FormatProviders.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/Utility/Range.h"
19 namespace lldb_private {
20 class MemoryRegionInfo {
22 typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
24 enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
27 : m_range(), m_read(eDontKnow), m_write(eDontKnow), m_execute(eDontKnow),
28 m_mapped(eDontKnow) {}
30 ~MemoryRegionInfo() {}
32 RangeType &GetRange() { return m_range; }
36 m_read = m_write = m_execute = eDontKnow;
39 const RangeType &GetRange() const { return m_range; }
41 OptionalBool GetReadable() const { return m_read; }
43 OptionalBool GetWritable() const { return m_write; }
45 OptionalBool GetExecutable() const { return m_execute; }
47 OptionalBool GetMapped() const { return m_mapped; }
49 const ConstString &GetName() const { return m_name; }
51 void SetReadable(OptionalBool val) { m_read = val; }
53 void SetWritable(OptionalBool val) { m_write = val; }
55 void SetExecutable(OptionalBool val) { m_execute = val; }
57 void SetMapped(OptionalBool val) { m_mapped = val; }
59 void SetName(const char *name) { m_name = ConstString(name); }
61 //----------------------------------------------------------------------
62 // Get permissions as a uint32_t that is a mask of one or more bits from
63 // the lldb::Permissions
64 //----------------------------------------------------------------------
65 uint32_t GetLLDBPermissions() const {
66 uint32_t permissions = 0;
68 permissions |= lldb::ePermissionsReadable;
70 permissions |= lldb::ePermissionsWritable;
72 permissions |= lldb::ePermissionsExecutable;
76 //----------------------------------------------------------------------
77 // Set permissions from a uint32_t that contains one or more bits from
78 // the lldb::Permissions
79 //----------------------------------------------------------------------
80 void SetLLDBPermissions(uint32_t permissions) {
81 m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
82 m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
83 m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
86 bool operator==(const MemoryRegionInfo &rhs) const {
87 return m_range == rhs.m_range && m_read == rhs.m_read &&
88 m_write == rhs.m_write && m_execute == rhs.m_execute &&
89 m_mapped == rhs.m_mapped;
92 bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
98 OptionalBool m_execute;
99 OptionalBool m_mapped;
106 struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
107 static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
108 raw_ostream &OS, StringRef Options) {
110 case lldb_private::MemoryRegionInfo::eNo:
113 case lldb_private::MemoryRegionInfo::eYes:
116 case lldb_private::MemoryRegionInfo::eDontKnow:
124 #endif // #ifndef lldb_MemoryRegionInfo_h