LLDB  mainline
DataBufferHeap.cpp
Go to the documentation of this file.
1 //===-- DataBufferHeap.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 
12 using namespace lldb_private;
13 
14 // Default constructor
16 
17 // Initialize this class with "n" characters and fill the buffer with "ch".
19  if (n < m_data.max_size())
20  m_data.assign(n, ch);
21 }
22 
23 // Initialize this class with a copy of the "n" bytes from the "bytes" buffer.
25  : m_data() {
26  CopyData(src, src_len);
27 }
28 
29 DataBufferHeap::DataBufferHeap(const DataBuffer &data_buffer) : m_data() {
30  CopyData(data_buffer.GetBytes(), data_buffer.GetByteSize());
31 }
32 
33 // Virtual destructor since this class inherits from a pure virtual base class.
35 
36 // Return a const pointer to the bytes owned by this object, or nullptr if the
37 // object contains no bytes.
38 const uint8_t *DataBufferHeap::GetBytesImpl() const {
39  return (m_data.empty() ? nullptr : m_data.data());
40 }
41 
42 // Return the number of bytes this object currently contains.
43 uint64_t DataBufferHeap::GetByteSize() const { return m_data.size(); }
44 
45 // Sets the number of bytes that this object should be able to contain. This
46 // can be used prior to copying data into the buffer.
47 uint64_t DataBufferHeap::SetByteSize(uint64_t new_size) {
48  if (new_size < m_data.max_size())
49  m_data.resize(new_size);
50  return m_data.size();
51 }
52 
53 void DataBufferHeap::CopyData(const void *src, uint64_t src_len) {
54  const uint8_t *src_u8 = static_cast<const uint8_t *>(src);
55  if (src && src_len > 0)
56  m_data.assign(src_u8, src_u8 + src_len);
57  else
58  m_data.clear();
59 }
60 
61 void DataBufferHeap::AppendData(const void *src, uint64_t src_len) {
62  m_data.insert(m_data.end(), static_cast<const uint8_t *>(src),
63  static_cast<const uint8_t *>(src) + src_len);
64 }
65 
67  buffer_t empty;
68  m_data.swap(empty);
69 }
70 
71 char DataBuffer::ID;
lldb_private::DataBufferHeap::GetByteSize
lldb::offset_t GetByteSize() const override
Definition: DataBufferHeap.cpp:43
lldb_private::DataBufferHeap::AppendData
void AppendData(const void *src, uint64_t src_len)
Definition: DataBufferHeap.cpp:61
lldb_private::DataBufferHeap::SetByteSize
lldb::offset_t SetByteSize(lldb::offset_t byte_size)
Set the number of bytes in the data buffer.
Definition: DataBufferHeap.cpp:47
lldb_private::DataBufferHeap::CopyData
void CopyData(const void *src, lldb::offset_t src_len)
Makes a copy of the src_len bytes in src.
Definition: DataBufferHeap.cpp:53
lldb_private::DataBufferHeap::GetBytesImpl
const uint8_t * GetBytesImpl() const override
Definition: DataBufferHeap.cpp:38
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::DataBufferHeap::ID
static char ID
LLVM RTTI support.
Definition: DataBufferHeap.h:108
ID
static char ID
Definition: IRDynamicChecks.cpp:33
lldb_private::DataBufferHeap::buffer_t
std::vector< uint8_t > buffer_t
}
Definition: DataBufferHeap.h:120
DataBuffer
lldb_private::DataBufferHeap::~DataBufferHeap
~DataBufferHeap() override
Destructor.
lldb_private::DataBufferHeap::Clear
void Clear()
Definition: DataBufferHeap.cpp:66
lldb_private::DataBufferHeap::m_data
buffer_t m_data
The heap based buffer where data is stored.
Definition: DataBufferHeap.h:121
lldb_private::DataBufferHeap::DataBufferHeap
DataBufferHeap()
Default constructor.
Definition: DataBufferHeap.cpp:15
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
DataBufferHeap.h