LLDB mainline
|
An binary data encoding class. More...
#include <DataEncoder.h>
Public Member Functions | |
DataEncoder () | |
Default constructor. | |
DataEncoder (const void *data, uint32_t data_length, lldb::ByteOrder byte_order, uint8_t addr_size) | |
Construct an encoder that copies the specified data into the object owned data buffer. | |
DataEncoder (lldb::ByteOrder byte_order, uint8_t addr_size) | |
Construct an encoder that owns a heap based memory buffer. | |
~DataEncoder () | |
uint32_t | PutUnsigned (uint32_t offset, uint32_t byte_size, uint64_t value) |
Encode an unsigned integer of size byte_size to offset. | |
uint32_t | PutU8 (uint32_t offset, uint8_t value) |
Encode an unsigned integer at offset offset. | |
uint32_t | PutU16 (uint32_t offset, uint16_t value) |
uint32_t | PutU32 (uint32_t offset, uint32_t value) |
uint32_t | PutU64 (uint32_t offset, uint64_t value) |
void | AppendU8 (uint8_t value) |
Append a unsigned integer to the end of the owned data. | |
void | AppendU16 (uint16_t value) |
void | AppendU32 (uint32_t value) |
void | AppendU64 (uint64_t value) |
void | AppendAddress (lldb::addr_t addr) |
Append an address sized integer to the end of the owned data. | |
void | AppendData (llvm::StringRef data) |
Append a bytes to the end of the owned data. | |
void | AppendData (llvm::ArrayRef< uint8_t > data) |
Append a bytes to the end of the owned data. | |
void | AppendCString (llvm::StringRef data) |
Append a C string to the end of the owned data. | |
uint32_t | PutData (uint32_t offset, const void *src, uint32_t src_len) |
Encode an arbitrary number of bytes. | |
uint32_t | PutAddress (uint32_t offset, lldb::addr_t addr) |
Encode an address in the existing buffer at offset bytes into the buffer. | |
uint32_t | PutCString (uint32_t offset, const char *cstr) |
Put a C string to offset. | |
std::shared_ptr< lldb_private::DataBufferHeap > | GetDataBuffer () |
Get a shared copy of the heap based memory buffer owned by this object. | |
llvm::ArrayRef< uint8_t > | GetData () const |
Get a access to the bytes that this references. | |
size_t | GetByteSize () const |
Get the number of bytes contained in this object. | |
lldb::ByteOrder | GetByteOrder () const |
uint8_t | GetAddressByteSize () const |
The address size to use when encoding pointers or addresses. | |
Private Member Functions | |
uint32_t | BytesLeft (uint32_t offset) const |
bool | ValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const |
Test the availability of length bytes of data from offset. | |
bool | ValidOffset (uint32_t offset) const |
Test the validity of offset. | |
DataEncoder (const DataEncoder &)=delete | |
const DataEncoder & | operator= (const DataEncoder &)=delete |
Private Attributes | |
std::shared_ptr< lldb_private::DataBufferHeap > | m_data_sp |
The shared pointer to data that can grow as data is added. | |
const lldb::ByteOrder | m_byte_order |
The byte order of the data we are encoding to. | |
const uint8_t | m_addr_size |
The address size to use when encoding pointers or addresses. | |
An binary data encoding class.
DataEncoder is a class that can encode binary data (swapping if needed) to a data buffer. The DataEncoder can be constructed with data that will be copied into the internally owned buffer. This allows data to be modified in the internal buffer. The DataEncoder object can also be constructed with just a byte order and address size and data can be appended to the internally owned buffer.
Clients can get a shared pointer to the data buffer when done modifying or creating the data to keep the data around after the lifetime of a DataEncoder object.
Client can get a reference to the object owned data as an array by calling the GetData method.
Definition at line 42 of file DataEncoder.h.
DataEncoder::DataEncoder | ( | ) |
Default constructor.
Initialize all members to a default empty state and create a empty memory buffer that can be appended to. The ByteOrder and address size will be set to match the current host system.
Definition at line 25 of file DataEncoder.cpp.
DataEncoder::DataEncoder | ( | const void * | data, |
uint32_t | data_length, | ||
lldb::ByteOrder | byte_order, | ||
uint8_t | addr_size | ||
) |
Construct an encoder that copies the specified data into the object owned data buffer.
This constructor is designed to be used when you have a data buffer and want to modify values within the buffer. A copy of the data will be made in the internally owned buffer and that data can be fixed up and appended to.
[in] | data | A pointer to caller owned data. |
[in] | data_length | The length in bytes of data. |
[in] | byte_order | A byte order for the data that will be encoded. |
[in] | addr_size | A size of an address in bytes. |
Definition at line 29 of file DataEncoder.cpp.
DataEncoder::DataEncoder | ( | lldb::ByteOrder | byte_order, |
uint8_t | addr_size | ||
) |
Construct an encoder that owns a heap based memory buffer.
This allows clients to create binary data from scratch by appending values with the methods that start with "Append".
[in] | byte_order | A byte order for the data that will be encoded. |
[in] | addr_size | A size of an address in bytes. |
Definition at line 34 of file DataEncoder.cpp.
|
default |
|
privatedelete |
void DataEncoder::AppendAddress | ( | lldb::addr_t | addr | ) |
Append an address sized integer to the end of the owned data.
addr | A unsigned integer address value to append. The size of the address will be determined by the address size specified in the constructor. |
Definition at line 155 of file DataEncoder.cpp.
References AppendU32(), AppendU64(), and m_addr_size.
Referenced by lldb_private::DWARFExpression::Update_DW_OP_addr().
void DataEncoder::AppendCString | ( | llvm::StringRef | data | ) |
Append a C string to the end of the owned data.
Append the bytes contained in the string reference along with an extra NULL termination character if the StringRef bytes doesn't include one as the last byte.
data | A string reference that contains bytes to append. |
Definition at line 182 of file DataEncoder.cpp.
References AppendU8(), and m_data_sp.
Referenced by lldb_private::ConstStringTable::Encode().
void DataEncoder::AppendData | ( | llvm::ArrayRef< uint8_t > | data | ) |
Append a bytes to the end of the owned data.
Append the bytes contained in the array reference.
data | A array reference that contains bytes to append. |
Definition at line 175 of file DataEncoder.cpp.
References m_data_sp.
void DataEncoder::AppendData | ( | llvm::StringRef | data | ) |
Append a bytes to the end of the owned data.
Append the bytes contained in the string reference. This function will not append a NULL termination character for a C string. Use the AppendCString function for this purpose.
data | A string reference that contains bytes to append. |
Definition at line 168 of file DataEncoder.cpp.
References m_data_sp.
Referenced by lldb_private::ConstStringTable::Encode(), lldb_private::CacheSignature::Encode(), lldb_private::Symtab::Encode(), lldb_private::plugin::dwarf::ManualDWARFIndex::IndexSet::Encode(), lldb_private::plugin::dwarf::NameToDIE::Encode(), EncodeCStrMap(), lldb_private::platform_android::AdbClient::SyncService::SendSyncRequest(), and lldb_private::DWARFExpression::Update_DW_OP_addr().
void DataEncoder::AppendU16 | ( | uint16_t | value | ) |
Definition at line 137 of file DataEncoder.cpp.
References m_data_sp, and PutU16().
Referenced by lldb_private::Symbol::Encode().
void DataEncoder::AppendU32 | ( | uint32_t | value | ) |
Definition at line 143 of file DataEncoder.cpp.
References m_data_sp, and PutU32().
Referenced by AppendAddress(), lldb_private::ConstStringTable::Encode(), lldb_private::CacheSignature::Encode(), lldb_private::Symtab::Encode(), lldb_private::plugin::dwarf::ManualDWARFIndex::IndexSet::Encode(), lldb_private::Mangled::Encode(), lldb_private::Symbol::Encode(), lldb_private::plugin::dwarf::NameToDIE::Encode(), EncodeCStrMap(), and lldb_private::platform_android::AdbClient::SyncService::SendSyncRequest().
void DataEncoder::AppendU64 | ( | uint64_t | value | ) |
Definition at line 149 of file DataEncoder.cpp.
References m_data_sp, and PutU64().
Referenced by AppendAddress(), lldb_private::plugin::dwarf::DIERef::Encode(), and lldb_private::Symbol::Encode().
void DataEncoder::AppendU8 | ( | uint8_t | value | ) |
Append a unsigned integer to the end of the owned data.
value | A unsigned integer value to append. |
Definition at line 133 of file DataEncoder.cpp.
References m_data_sp.
Referenced by AppendCString(), lldb_private::ConstStringTable::Encode(), lldb_private::CacheSignature::Encode(), lldb_private::Symtab::Encode(), lldb_private::plugin::dwarf::ManualDWARFIndex::IndexSet::Encode(), lldb_private::Mangled::Encode(), lldb_private::Symbol::Encode(), and lldb_private::DWARFExpression::Update_DW_OP_addr().
|
inlineprivate |
Definition at line 264 of file DataEncoder.h.
References GetByteSize().
Referenced by ValidOffsetForDataOfSize().
|
inline |
The address size to use when encoding pointers or addresses.
Definition at line 261 of file DataEncoder.h.
References m_addr_size.
Referenced by lldb_private::Symtab::Encode(), and lldb_private::plugin::dwarf::ManualDWARFIndex::IndexSet::Encode().
|
inline |
Definition at line 258 of file DataEncoder.h.
References m_byte_order.
Referenced by lldb_private::Symtab::Encode(), and lldb_private::plugin::dwarf::ManualDWARFIndex::IndexSet::Encode().
size_t DataEncoder::GetByteSize | ( | ) | const |
Get the number of bytes contained in this object.
Definition at line 44 of file DataEncoder.cpp.
References m_data_sp.
Referenced by BytesLeft(), lldb_private::ConstStringTable::Encode(), lldb_private::Symtab::Encode(), GetData(), and ValidOffset().
llvm::ArrayRef< uint8_t > DataEncoder::GetData | ( | ) | const |
Get a access to the bytes that this references.
This value will always return the data that this object references even if the object was constructed with caller owned data.
Definition at line 40 of file DataEncoder.cpp.
References GetByteSize(), and m_data_sp.
Referenced by lldb_private::Symtab::Encode(), lldb_private::plugin::dwarf::ManualDWARFIndex::IndexSet::Encode(), lldb_private::Symtab::SaveToCache(), lldb_private::plugin::dwarf::ManualDWARFIndex::SaveToCache(), and lldb_private::platform_android::AdbClient::SyncService::SendSyncRequest().
|
inline |
Get a shared copy of the heap based memory buffer owned by this object.
This allows a data encoder to be used to create a data buffer that can be extracted and used elsewhere after this object is destroyed.
Definition at line 239 of file DataEncoder.h.
References m_data_sp.
Referenced by lldb_private::DWARFExpression::LinkThreadLocalStorage(), and lldb_private::DWARFExpression::Update_DW_OP_addr().
|
privatedelete |
uint32_t DataEncoder::PutAddress | ( | uint32_t | offset, |
lldb::addr_t | addr | ||
) |
Encode an address in the existing buffer at offset bytes into the buffer.
Encode a single address to the data and return the next offset where subsequent data would go. The size of the address comes from the m_addr_size member variable and should be set correctly prior to encoding any address values.
[in] | offset | The offset where to encode the address. |
[in] | addr | The address to encode. |
Definition at line 123 of file DataEncoder.cpp.
References m_addr_size, and PutUnsigned().
Referenced by lldb_private::DWARFExpression::Update_DW_OP_addr().
uint32_t DataEncoder::PutCString | ( | uint32_t | offset, |
const char * | cstr | ||
) |
Put a C string to offset.
Encodes a C string into the existing data including the terminating. If there is not enough room in the buffer to fit the entire C string and the NULL terminator in the existing buffer bounds, then this function will fail.
[in] | offset | The offset where to encode the string. |
[in] | cstr | The string to encode. |
Definition at line 127 of file DataEncoder.cpp.
References PutData(), and UINT32_MAX.
uint32_t DataEncoder::PutData | ( | uint32_t | offset, |
const void * | src, | ||
uint32_t | src_len | ||
) |
Encode an arbitrary number of bytes.
[in] | offset | The offset in bytes into the contained data at which to start encoding. |
[in] | src | The buffer that contains the bytes to encode. |
[in] | src_len | The number of bytes to encode. |
Definition at line 111 of file DataEncoder.cpp.
References m_data_sp, UINT32_MAX, and ValidOffsetForDataOfSize().
Referenced by PutCString().
uint32_t DataEncoder::PutU16 | ( | uint32_t | offset, |
uint16_t | value | ||
) |
Definition at line 58 of file DataEncoder.cpp.
References lldb_private::endian::InlHostByteOrder(), m_byte_order, m_data_sp, UINT32_MAX, and ValidOffsetForDataOfSize().
Referenced by AppendU16(), and PutUnsigned().
uint32_t DataEncoder::PutU32 | ( | uint32_t | offset, |
uint32_t | value | ||
) |
Definition at line 70 of file DataEncoder.cpp.
References lldb_private::endian::InlHostByteOrder(), m_byte_order, m_data_sp, UINT32_MAX, and ValidOffsetForDataOfSize().
Referenced by AppendU32(), lldb_private::ConstStringTable::Encode(), and PutUnsigned().
uint32_t DataEncoder::PutU64 | ( | uint32_t | offset, |
uint64_t | value | ||
) |
Definition at line 82 of file DataEncoder.cpp.
References lldb_private::endian::InlHostByteOrder(), m_byte_order, m_data_sp, UINT32_MAX, and ValidOffsetForDataOfSize().
Referenced by AppendU64(), and PutUnsigned().
uint32_t DataEncoder::PutU8 | ( | uint32_t | offset, |
uint8_t | value | ||
) |
Encode an unsigned integer at offset offset.
Encode a single unsigned integer value at offset and return the offset that follows the newly encoded integer when the data is successfully encoded into the existing data. There must be enough room in the data, else UINT32_MAX will be returned to indicate that encoding failed.
[in] | offset | The offset within the contained data at which to put the encoded integer. |
[in] | value | The integer value to write. |
Definition at line 50 of file DataEncoder.cpp.
References m_data_sp, UINT32_MAX, and ValidOffset().
Referenced by lldb_private::Symtab::Encode(), and PutUnsigned().
uint32_t DataEncoder::PutUnsigned | ( | uint32_t | offset, |
uint32_t | byte_size, | ||
uint64_t | value | ||
) |
Encode an unsigned integer of size byte_size to offset.
Encode a single integer value at offset and return the offset that follows the newly encoded integer when the data is successfully encoded into the existing data. There must be enough room in the existing data, else UINT32_MAX will be returned to indicate that encoding failed.
[in] | offset | The offset within the contained data at which to put the encoded integer. |
[in] | byte_size | The size in byte of the integer to encode. |
[in] | value | The integer value to write. The least significant bytes of the integer value will be written if the size is less than 8 bytes. |
Definition at line 94 of file DataEncoder.cpp.
References PutU16(), PutU32(), PutU64(), PutU8(), and UINT32_MAX.
Referenced by lldb_private::DWARFExpression::LinkThreadLocalStorage(), and PutAddress().
|
inlineprivate |
Test the validity of offset.
Definition at line 285 of file DataEncoder.h.
References GetByteSize().
Referenced by PutU8().
|
inlineprivate |
Test the availability of length bytes of data from offset.
Definition at line 276 of file DataEncoder.h.
References BytesLeft().
|
private |
The address size to use when encoding pointers or addresses.
Definition at line 294 of file DataEncoder.h.
Referenced by AppendAddress(), GetAddressByteSize(), and PutAddress().
|
private |
The byte order of the data we are encoding to.
Definition at line 291 of file DataEncoder.h.
Referenced by GetByteOrder(), PutU16(), PutU32(), and PutU64().
|
private |
The shared pointer to data that can grow as data is added.
Definition at line 288 of file DataEncoder.h.
Referenced by AppendCString(), AppendData(), AppendU16(), AppendU32(), AppendU64(), AppendU8(), GetByteSize(), GetData(), GetDataBuffer(), PutData(), PutU16(), PutU32(), PutU64(), and PutU8().