aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Target/MemoryRegionInfo.h
blob: 5c82a1f294dd16c0dd7ac5594cc5fd81666596d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//===-- MemoryRegionInfo.h ---------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef lldb_MemoryRegionInfo_h
#define lldb_MemoryRegionInfo_h

#include "lldb/Core/RangeMap.h"
#include "lldb/Utility/Range.h"

namespace lldb_private
{
    class MemoryRegionInfo
    {
    public:
        typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
        
        enum OptionalBool {
            eDontKnow  = -1,
            eNo         = 0,
            eYes        = 1
        };
        
        MemoryRegionInfo () :
        m_range (),
        m_read (eDontKnow),
        m_write (eDontKnow),
        m_execute (eDontKnow),
        m_mapped (eDontKnow)
        {
        }
        
        ~MemoryRegionInfo ()
        {
        }
        
        RangeType &
        GetRange()
        {
            return m_range;
        }
        
        void
        Clear()
        {
            m_range.Clear();
            m_read = m_write = m_execute = eDontKnow;
        }
        
        const RangeType &
        GetRange() const
        {
            return m_range;
        }
        
        OptionalBool
        GetReadable () const
        {
            return m_read;
        }
        
        OptionalBool
        GetWritable () const
        {
            return m_write;
        }
        
        OptionalBool
        GetExecutable () const
        {
            return m_execute;
        }
        
        OptionalBool
        GetMapped () const
        {
            return m_mapped;
        }
        
        void
        SetReadable (OptionalBool val)
        {
            m_read = val;
        }
        
        void
        SetWritable (OptionalBool val)
        {
            m_write = val;
        }
        
        void
        SetExecutable (OptionalBool val)
        {
            m_execute = val;
        }
        
        void
        SetMapped (OptionalBool val)
        {
            m_mapped = val;
        }

        //----------------------------------------------------------------------
        // Get permissions as a uint32_t that is a mask of one or more bits from
        // the lldb::Permissions
        //----------------------------------------------------------------------
        uint32_t
        GetLLDBPermissions() const
        {
            uint32_t permissions = 0;
            if (m_read)
                permissions |= lldb::ePermissionsReadable;
            if (m_write)
                permissions |= lldb::ePermissionsWritable;
            if (m_execute)
                permissions |= lldb::ePermissionsExecutable;
            return permissions;
        }

        //----------------------------------------------------------------------
        // Set permissions from a uint32_t that contains one or more bits from
        // the lldb::Permissions
        //----------------------------------------------------------------------
        void
        SetLLDBPermissions(uint32_t permissions)
        {
            m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
            m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
            m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
        }

        bool
        operator == (const MemoryRegionInfo &rhs) const
        {
            return m_range == rhs.m_range &&
                   m_read == rhs.m_read &&
                   m_write == rhs.m_write &&
                   m_execute == rhs.m_execute &&
                   m_mapped == rhs.m_mapped;
        }
        
        bool
        operator != (const MemoryRegionInfo &rhs) const
        {
            return !(*this == rhs);
        }
        
    protected:
        RangeType m_range;
        OptionalBool m_read;
        OptionalBool m_write;
        OptionalBool m_execute;
        OptionalBool m_mapped;
    };
}

#endif // #ifndef lldb_MemoryRegionInfo_h