LLDB mainline
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lldb_private::DataEncoder Class Reference

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::DataBufferHeapGetDataBuffer ()
 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 DataEncoderoperator= (const DataEncoder &)=delete
 

Private Attributes

std::shared_ptr< lldb_private::DataBufferHeapm_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.
 

Detailed Description

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.

See also
GetDataBuffer

Client can get a reference to the object owned data as an array by calling the GetData method.

See also
GetData

Definition at line 42 of file DataEncoder.h.

Constructor & Destructor Documentation

◆ DataEncoder() [1/4]

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() [2/4]

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.

Parameters
[in]dataA pointer to caller owned data.
[in]data_lengthThe length in bytes of data.
[in]byte_orderA byte order for the data that will be encoded.
[in]addr_sizeA size of an address in bytes.
See also
PutAddress, AppendAddress

Definition at line 29 of file DataEncoder.cpp.

◆ DataEncoder() [3/4]

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".

Parameters
[in]byte_orderA byte order for the data that will be encoded.
[in]addr_sizeA size of an address in bytes.
See also
PutAddress, AppendAddress

Definition at line 34 of file DataEncoder.cpp.

◆ ~DataEncoder()

DataEncoder::~DataEncoder ( )
default

◆ DataEncoder() [4/4]

lldb_private::DataEncoder::DataEncoder ( const DataEncoder )
privatedelete

Member Function Documentation

◆ AppendAddress()

void DataEncoder::AppendAddress ( lldb::addr_t  addr)

Append an address sized integer to the end of the owned data.

Parameters
addrA 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().

◆ AppendCString()

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.

Parameters
dataA 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().

◆ AppendData() [1/2]

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.

Parameters
dataA array reference that contains bytes to append.

Definition at line 175 of file DataEncoder.cpp.

References m_data_sp.

◆ AppendData() [2/2]

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.

Parameters
dataA 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().

◆ AppendU16()

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().

◆ AppendU32()

void DataEncoder::AppendU32 ( uint32_t  value)

◆ AppendU64()

void DataEncoder::AppendU64 ( uint64_t  value)

◆ AppendU8()

void DataEncoder::AppendU8 ( uint8_t  value)

◆ BytesLeft()

uint32_t lldb_private::DataEncoder::BytesLeft ( uint32_t  offset) const
inlineprivate

Definition at line 264 of file DataEncoder.h.

References GetByteSize().

Referenced by ValidOffsetForDataOfSize().

◆ GetAddressByteSize()

uint8_t lldb_private::DataEncoder::GetAddressByteSize ( ) const
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().

◆ GetByteOrder()

lldb::ByteOrder lldb_private::DataEncoder::GetByteOrder ( ) const
inline

◆ GetByteSize()

size_t DataEncoder::GetByteSize ( ) const

Get the number of bytes contained in this object.

Returns
The total number of bytes of data this object refers to.

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().

◆ GetData()

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.

Returns
A array reference to the data that this object references.

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().

◆ GetDataBuffer()

std::shared_ptr< lldb_private::DataBufferHeap > lldb_private::DataEncoder::GetDataBuffer ( )
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.

Returns
A shared pointer to the DataBufferHeap that contains the data that was encoded into this object.

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().

◆ operator=()

const DataEncoder & lldb_private::DataEncoder::operator= ( const DataEncoder )
privatedelete

◆ PutAddress()

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.

Parameters
[in]offsetThe offset where to encode the address.
[in]addrThe address to encode.
Returns
The next valid offset within data if the put operation was successful, else UINT32_MAX to indicate the put failed.

Definition at line 123 of file DataEncoder.cpp.

References m_addr_size, and PutUnsigned().

Referenced by lldb_private::DWARFExpression::Update_DW_OP_addr().

◆ PutCString()

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.

Parameters
[in]offsetThe offset where to encode the string.
[in]cstrThe string to encode.
Returns
The next valid offset within data if the put operation was successful, else UINT32_MAX to indicate the put failed.

Definition at line 127 of file DataEncoder.cpp.

References PutData(), and UINT32_MAX.

◆ PutData()

uint32_t DataEncoder::PutData ( uint32_t  offset,
const void *  src,
uint32_t  src_len 
)

Encode an arbitrary number of bytes.

Parameters
[in]offsetThe offset in bytes into the contained data at which to start encoding.
[in]srcThe buffer that contains the bytes to encode.
[in]src_lenThe number of bytes to encode.
Returns
The next valid offset within data if the put operation was successful, else UINT32_MAX to indicate the put failed.

Definition at line 111 of file DataEncoder.cpp.

References m_data_sp, UINT32_MAX, and ValidOffsetForDataOfSize().

Referenced by PutCString().

◆ PutU16()

uint32_t DataEncoder::PutU16 ( uint32_t  offset,
uint16_t  value 
)

◆ PutU32()

uint32_t DataEncoder::PutU32 ( uint32_t  offset,
uint32_t  value 
)

◆ PutU64()

uint32_t DataEncoder::PutU64 ( uint32_t  offset,
uint64_t  value 
)

◆ PutU8()

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.

Parameters
[in]offsetThe offset within the contained data at which to put the encoded integer.
[in]valueThe integer value to write.
Returns
The next offset in the bytes of this data if the integer was successfully encoded, UINT32_MAX if the encoding failed.

Definition at line 50 of file DataEncoder.cpp.

References m_data_sp, UINT32_MAX, and ValidOffset().

Referenced by lldb_private::Symtab::Encode(), and PutUnsigned().

◆ 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.

Parameters
[in]offsetThe offset within the contained data at which to put the encoded integer.
[in]byte_sizeThe size in byte of the integer to encode.
[in]valueThe integer value to write. The least significant bytes of the integer value will be written if the size is less than 8 bytes.
Returns
The next offset in the bytes of this data if the integer was successfully encoded, UINT32_MAX if the encoding failed.

Definition at line 94 of file DataEncoder.cpp.

References PutU16(), PutU32(), PutU64(), PutU8(), and UINT32_MAX.

Referenced by lldb_private::DWARFExpression::LinkThreadLocalStorage(), and PutAddress().

◆ ValidOffset()

bool lldb_private::DataEncoder::ValidOffset ( uint32_t  offset) const
inlineprivate

Test the validity of offset.

Returns
true if offset is a valid offset into the data in this object, false otherwise.

Definition at line 285 of file DataEncoder.h.

References GetByteSize().

Referenced by PutU8().

◆ ValidOffsetForDataOfSize()

bool lldb_private::DataEncoder::ValidOffsetForDataOfSize ( uint32_t  offset,
uint32_t  length 
) const
inlineprivate

Test the availability of length bytes of data from offset.

Returns
true if offset is a valid offset and there are length bytes available at that offset, false otherwise.

Definition at line 276 of file DataEncoder.h.

References BytesLeft().

Referenced by PutData(), PutU16(), PutU32(), and PutU64().

Member Data Documentation

◆ m_addr_size

const uint8_t lldb_private::DataEncoder::m_addr_size
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().

◆ m_byte_order

const lldb::ByteOrder lldb_private::DataEncoder::m_byte_order
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().

◆ m_data_sp

std::shared_ptr<lldb_private::DataBufferHeap> lldb_private::DataEncoder::m_data_sp
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().


The documentation for this class was generated from the following files: