]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/MemoryRegionInfo.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r305575, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / MemoryRegionInfo.h
1 //===-- MemoryRegionInfo.h ---------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef lldb_MemoryRegionInfo_h
12 #define lldb_MemoryRegionInfo_h
13
14 #include "lldb/Core/RangeMap.h"
15 #include "llvm/Support/FormatProviders.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/Utility/Range.h"
18
19 namespace lldb_private {
20 class MemoryRegionInfo {
21 public:
22   typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
23
24   enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
25
26   MemoryRegionInfo()
27       : m_range(), m_read(eDontKnow), m_write(eDontKnow), m_execute(eDontKnow),
28         m_mapped(eDontKnow) {}
29
30   ~MemoryRegionInfo() {}
31
32   RangeType &GetRange() { return m_range; }
33
34   void Clear() {
35     m_range.Clear();
36     m_read = m_write = m_execute = eDontKnow;
37   }
38
39   const RangeType &GetRange() const { return m_range; }
40
41   OptionalBool GetReadable() const { return m_read; }
42
43   OptionalBool GetWritable() const { return m_write; }
44
45   OptionalBool GetExecutable() const { return m_execute; }
46
47   OptionalBool GetMapped() const { return m_mapped; }
48
49   const ConstString &GetName() const { return m_name; }
50
51   void SetReadable(OptionalBool val) { m_read = val; }
52
53   void SetWritable(OptionalBool val) { m_write = val; }
54
55   void SetExecutable(OptionalBool val) { m_execute = val; }
56
57   void SetMapped(OptionalBool val) { m_mapped = val; }
58
59   void SetName(const char *name) { m_name = ConstString(name); }
60
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;
67     if (m_read)
68       permissions |= lldb::ePermissionsReadable;
69     if (m_write)
70       permissions |= lldb::ePermissionsWritable;
71     if (m_execute)
72       permissions |= lldb::ePermissionsExecutable;
73     return permissions;
74   }
75
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;
84   }
85
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;
90   }
91
92   bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
93
94 protected:
95   RangeType m_range;
96   OptionalBool m_read;
97   OptionalBool m_write;
98   OptionalBool m_execute;
99   OptionalBool m_mapped;
100   ConstString m_name;
101 };
102 }
103
104 namespace llvm {
105 template <>
106 struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
107   static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
108                      raw_ostream &OS, StringRef Options) {
109     switch(B) {
110     case lldb_private::MemoryRegionInfo::eNo:
111       OS << "no";
112       return;
113     case lldb_private::MemoryRegionInfo::eYes:
114       OS << "yes";
115       return;
116     case lldb_private::MemoryRegionInfo::eDontKnow:
117       OS << "don't know";
118       return;
119     }
120   }
121 };
122 }
123
124 #endif // #ifndef lldb_MemoryRegionInfo_h