Skip to content

Commit 13581a6

Browse files
committed
Move to void* buffer instead of data buffer heap
1 parent aa23a39 commit 13581a6

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ class Process : public std::enable_shared_from_this<Process>,
15991599
// uint64_t bytes_read_for_chunk, the actual count of bytes read for this
16001600
// chunk
16011601
typedef std::function<IterationAction(lldb_private::Status &, const void *,
1602-
lldb::addr_t, uint64_t, uint64_t)>
1602+
lldb::addr_t, uint64_t, uint64_t)>
16031603
ReadMemoryChunkCallback;
16041604

16051605
/// Read of memory from a process in discrete chunks, terminating
@@ -1610,9 +1610,13 @@ class Process : public std::enable_shared_from_this<Process>,
16101610
/// A virtual load address that indicates where to start reading
16111611
/// memory from.
16121612
///
1613-
/// \param[in] data
1614-
/// The data buffer heap to use to read the chunk. The chunk size
1615-
/// depends upon the byte size of the buffer.
1613+
/// \param[in] buf
1614+
/// A byte buffer that is at least \a chunk_size bytes long that
1615+
/// will receive the memory bytes.
1616+
///
1617+
/// \param[in] chunk_size
1618+
/// The minimum size of the byte buffer, and the chunk size of memory
1619+
/// to read.
16161620
///
16171621
/// \param[in] size
16181622
/// The number of bytes to read.
@@ -1627,8 +1631,9 @@ class Process : public std::enable_shared_from_this<Process>,
16271631
/// size, then this function will get called again with \a
16281632
/// vm_addr, \a buf, and \a size updated appropriately. Zero is
16291633
/// returned in the case of an error.
1630-
size_t ReadMemoryInChunks(lldb::addr_t vm_addr, DataBufferHeap &data,
1631-
size_t size, ReadMemoryChunkCallback callback);
1634+
size_t ReadMemoryInChunks(lldb::addr_t vm_addr, void *buf,
1635+
lldb::addr_t chunk_size, size_t size,
1636+
ReadMemoryChunkCallback callback);
16321637

16331638
/// Read a NULL terminated C string from memory
16341639
///

lldb/source/Target/Process.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,27 +2234,27 @@ size_t Process::ReadMemoryFromInferior(addr_t addr, void *buf, size_t size,
22342234
}
22352235

22362236
size_t Process::ReadMemoryInChunks(lldb::addr_t vm_addr, void *buf,
2237-
lldb::addr_t chunk_size, size_t size,
2238-
ReadMemoryChunkCallback callback) {
2239-
// Safety check to prevent an infinite loop.
2240-
if (chunk_size == 0)
2241-
return 0;
2242-
2243-
// Create a data buffer heap of the specified size, initialized to 0.
2244-
uint64_t bytes_remaining = size;
2245-
uint64_t bytes_read = 0;
2246-
Status error;
2247-
while (bytes_remaining > 0) {
2248-
// Get the next read chunk size as the minimum of the remaining bytes and
2249-
// the write chunk max size.
2250-
const size_t bytes_to_read = std::min(bytes_remaining, chunk_size);
2251-
const lldb::addr_t current_addr = vm_addr + bytes_read;
2252-
const size_t bytes_read_for_chunk =
2253-
ReadMemoryFromInferior(current_addr, buf, bytes_to_read, error);
2254-
2255-
if (callback(error, buf, current_addr, bytes_to_read,
2256-
bytes_read_for_chunk) == IterationAction::Stop)
2257-
break;
2237+
lldb::addr_t chunk_size, size_t size,
2238+
ReadMemoryChunkCallback callback) {
2239+
// Safety check to prevent an infinite loop.
2240+
if (chunk_size == 0)
2241+
return 0;
2242+
2243+
// Create a data buffer heap of the specified size, initialized to 0.
2244+
uint64_t bytes_remaining = size;
2245+
uint64_t bytes_read = 0;
2246+
Status error;
2247+
while (bytes_remaining > 0) {
2248+
// Get the next read chunk size as the minimum of the remaining bytes and
2249+
// the write chunk max size.
2250+
const size_t bytes_to_read = std::min(bytes_remaining, chunk_size);
2251+
const lldb::addr_t current_addr = vm_addr + bytes_read;
2252+
const size_t bytes_read_for_chunk =
2253+
ReadMemoryFromInferior(current_addr, buf, bytes_to_read, error);
2254+
2255+
if (callback(error, buf, current_addr, bytes_to_read,
2256+
bytes_read_for_chunk) == IterationAction::Stop)
2257+
break;
22582258

22592259
bytes_read += bytes_read_for_chunk;
22602260
// If the bytes read in this chunk would cause us to overflow, something

0 commit comments

Comments
 (0)