1 //===-- Memory.h ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Memory_h_
11 #define liblldb_Memory_h_
18 // Other libraries and framework includes
21 #include "lldb/lldb-private.h"
22 #include "lldb/Core/RangeMap.h"
23 #include "lldb/Host/Mutex.h"
25 namespace lldb_private {
26 //----------------------------------------------------------------------
27 // A class to track memory that was read from a live process between
29 //----------------------------------------------------------------------
33 //------------------------------------------------------------------
34 // Constructors and Destructors
35 //------------------------------------------------------------------
36 MemoryCache (Process &process);
41 Clear(bool clear_invalid_ranges = false);
44 Flush (lldb::addr_t addr, size_t size);
47 Read (lldb::addr_t addr,
53 GetMemoryCacheLineSize() const
55 return m_cache_line_byte_size ;
59 AddInvalidRange (lldb::addr_t base_addr, lldb::addr_t byte_size);
62 RemoveInvalidRange (lldb::addr_t base_addr, lldb::addr_t byte_size);
65 typedef std::map<lldb::addr_t, lldb::DataBufferSP> BlockMap;
66 typedef RangeArray<lldb::addr_t, lldb::addr_t, 4> InvalidRanges;
67 //------------------------------------------------------------------
68 // Classes that inherit from MemoryCache can see and modify these
69 //------------------------------------------------------------------
71 uint32_t m_cache_line_byte_size;
74 InvalidRanges m_invalid_ranges;
76 DISALLOW_COPY_AND_ASSIGN (MemoryCache);
83 AllocatedBlock (lldb::addr_t addr,
91 ReserveBlock (uint32_t size);
94 FreeBlock (lldb::addr_t addr);
97 GetBaseAddress () const
109 GetPermissions () const
111 return m_permissions;
115 GetChunkSize () const
121 Contains (lldb::addr_t addr) const
123 return ((addr >= m_addr) && addr < (m_addr + m_byte_size));
129 return m_byte_size / m_chunk_size;
133 CalculateChunksNeededForSize (uint32_t size) const
135 return (size + m_chunk_size - 1) / m_chunk_size;
137 const lldb::addr_t m_addr; // Base address of this block of memory
138 const uint32_t m_byte_size; // 4GB of chunk should be enough...
139 const uint32_t m_permissions; // Permissions for this memory (logical OR of lldb::Permissions bits)
140 const uint32_t m_chunk_size; // The size of chunks that the memory at m_addr is divied up into
141 typedef std::map<uint32_t, uint32_t> OffsetToChunkSize;
142 OffsetToChunkSize m_offset_to_chunk_size;
146 //----------------------------------------------------------------------
147 // A class that can track allocated memory and give out allocated memory
148 // without us having to make an allocate/deallocate call every time we
149 // need some memory in a process that is being debugged.
150 //----------------------------------------------------------------------
151 class AllocatedMemoryCache
154 //------------------------------------------------------------------
155 // Constructors and Destructors
156 //------------------------------------------------------------------
157 AllocatedMemoryCache (Process &process);
159 ~AllocatedMemoryCache ();
165 AllocateMemory (size_t byte_size,
166 uint32_t permissions,
170 DeallocateMemory (lldb::addr_t ptr);
173 typedef std::shared_ptr<AllocatedBlock> AllocatedBlockSP;
176 AllocatePage (uint32_t byte_size,
177 uint32_t permissions,
182 //------------------------------------------------------------------
183 // Classes that inherit from MemoryCache can see and modify these
184 //------------------------------------------------------------------
187 typedef std::multimap<uint32_t, AllocatedBlockSP> PermissionsToBlockMap;
188 PermissionsToBlockMap m_memory_map;
191 DISALLOW_COPY_AND_ASSIGN (AllocatedMemoryCache);
194 } // namespace lldb_private
196 #endif // liblldb_Memory_h_