diff options
Diffstat (limited to 'lldb/source/Utility/DataExtractor.cpp')
-rw-r--r-- | lldb/source/Utility/DataExtractor.cpp | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/lldb/source/Utility/DataExtractor.cpp b/lldb/source/Utility/DataExtractor.cpp index bc1af650830..61aacf4169a 100644 --- a/lldb/source/Utility/DataExtractor.cpp +++ b/lldb/source/Utility/DataExtractor.cpp @@ -124,10 +124,8 @@ DataExtractor::DataExtractor() m_byte_order(endian::InlHostByteOrder()), m_addr_size(sizeof(void *)), m_data_sp(), m_target_byte_size(1) {} -//---------------------------------------------------------------------- // This constructor allows us to use data that is owned by someone else. The // data must stay around as long as this object is valid. -//---------------------------------------------------------------------- DataExtractor::DataExtractor(const void *data, offset_t length, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size /*=1*/) @@ -139,12 +137,10 @@ DataExtractor::DataExtractor(const void *data, offset_t length, assert(addr_size == 4 || addr_size == 8); } -//---------------------------------------------------------------------- // Make a shared pointer reference to the shared data in "data_sp" and set the // endian swapping setting to "swap", and the address size to "addr_size". The // shared data reference will ensure the data lives as long as any // DataExtractor objects exist that have a reference to this data. -//---------------------------------------------------------------------- DataExtractor::DataExtractor(const DataBufferSP &data_sp, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size /*=1*/) @@ -155,13 +151,11 @@ DataExtractor::DataExtractor(const DataBufferSP &data_sp, ByteOrder endian, SetData(data_sp); } -//---------------------------------------------------------------------- // Initialize this object with a subset of the data bytes in "data". If "data" // contains shared data, then a reference to this shared data will added and // the shared data will stay around as long as any object contains a reference // to that data. The endian swap and address size settings are copied from // "data". -//---------------------------------------------------------------------- DataExtractor::DataExtractor(const DataExtractor &data, offset_t offset, offset_t length, uint32_t target_byte_size /*=1*/) : m_start(nullptr), m_end(nullptr), m_byte_order(data.m_byte_order), @@ -183,9 +177,7 @@ DataExtractor::DataExtractor(const DataExtractor &rhs) assert(m_addr_size == 4 || m_addr_size == 8); } -//---------------------------------------------------------------------- // Assignment operator -//---------------------------------------------------------------------- const DataExtractor &DataExtractor::operator=(const DataExtractor &rhs) { if (this != &rhs) { m_start = rhs.m_start; @@ -199,10 +191,8 @@ const DataExtractor &DataExtractor::operator=(const DataExtractor &rhs) { DataExtractor::~DataExtractor() = default; -//------------------------------------------------------------------ // Clears the object contents back to a default invalid state, and release any // references to shared data that this object may contain. -//------------------------------------------------------------------ void DataExtractor::Clear() { m_start = nullptr; m_end = nullptr; @@ -211,10 +201,8 @@ void DataExtractor::Clear() { m_data_sp.reset(); } -//------------------------------------------------------------------ // If this object contains shared data, this function returns the offset into // that shared data. Else zero is returned. -//------------------------------------------------------------------ size_t DataExtractor::GetSharedDataOffset() const { if (m_start != nullptr) { const DataBuffer *data = m_data_sp.get(); @@ -229,7 +217,6 @@ size_t DataExtractor::GetSharedDataOffset() const { return 0; } -//---------------------------------------------------------------------- // Set the data with which this object will extract from to data starting at // BYTES and set the length of the data to LENGTH bytes long. The data is // externally owned must be around at least as long as this object points to @@ -237,7 +224,6 @@ size_t DataExtractor::GetSharedDataOffset() const { // and can extract from it. If this object refers to any shared data upon // entry, the reference to that data will be released. Is SWAP is set to true, // any data extracted will be endian swapped. -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::SetData(const void *bytes, offset_t length, ByteOrder endian) { m_byte_order = endian; @@ -252,7 +238,6 @@ lldb::offset_t DataExtractor::SetData(const void *bytes, offset_t length, return GetByteSize(); } -//---------------------------------------------------------------------- // Assign the data for this object to be a subrange in "data" starting // "data_offset" bytes into "data" and ending "data_length" bytes later. If // "data_offset" is not a valid offset into "data", then this object will @@ -263,7 +248,6 @@ lldb::offset_t DataExtractor::SetData(const void *bytes, offset_t length, // a shared pointer to data, then the bytes referred to in "data" will need to // exist at least as long as this object refers to those bytes. The address // size and endian swap settings are copied from the current values in "data". -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::SetData(const DataExtractor &data, offset_t data_offset, offset_t data_length) { @@ -286,7 +270,6 @@ lldb::offset_t DataExtractor::SetData(const DataExtractor &data, return 0; } -//---------------------------------------------------------------------- // Assign the data for this object to be a subrange of the shared data in // "data_sp" starting "data_offset" bytes into "data_sp" and ending // "data_length" bytes later. If "data_offset" is not a valid offset into @@ -298,7 +281,6 @@ lldb::offset_t DataExtractor::SetData(const DataExtractor &data, // starting at "data_offset") to ensure the data stays around as long as it is // needed. The address size and endian swap settings will remain unchanged from // their current settings. -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::SetData(const DataBufferSP &data_sp, offset_t data_offset, offset_t data_length) { @@ -331,12 +313,10 @@ lldb::offset_t DataExtractor::SetData(const DataBufferSP &data_sp, return new_size; } -//---------------------------------------------------------------------- // Extract a single unsigned char from the binary data and update the offset // pointed to by "offset_ptr". // // RETURNS the byte that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const { const uint8_t *data = (const uint8_t *)GetData(offset_ptr, 1); if (data) @@ -344,14 +324,12 @@ uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const { return 0; } -//---------------------------------------------------------------------- // Extract "count" unsigned chars from the binary data and update the offset // pointed to by "offset_ptr". The extracted data is copied into "dst". // // RETURNS the non-nullptr buffer pointer upon successful extraction of // all the requested bytes, or nullptr when the data is not available in the // buffer due to being out of bounds, or insufficient data. -//---------------------------------------------------------------------- void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst, uint32_t count) const { const uint8_t *data = (const uint8_t *)GetData(offset_ptr, count); @@ -365,12 +343,10 @@ void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst, return nullptr; } -//---------------------------------------------------------------------- // Extract a single uint16_t from the data and update the offset pointed to by // "offset_ptr". // // RETURNS the uint16_t that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint16_t DataExtractor::GetU16(offset_t *offset_ptr) const { uint16_t val = 0; const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); @@ -413,14 +389,12 @@ uint64_t DataExtractor::GetU64_unchecked(offset_t *offset_ptr) const { return val; } -//---------------------------------------------------------------------- // Extract "count" uint16_t values from the binary data and update the offset // pointed to by "offset_ptr". The extracted data is copied into "dst". // // RETURNS the non-nullptr buffer pointer upon successful extraction of // all the requested bytes, or nullptr when the data is not available in the // buffer due to being out of bounds, or insufficient data. -//---------------------------------------------------------------------- void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint16_t) * count; @@ -445,12 +419,10 @@ void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst, return nullptr; } -//---------------------------------------------------------------------- // Extract a single uint32_t from the data and update the offset pointed to by // "offset_ptr". // // RETURNS the uint32_t that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const { uint32_t val = 0; const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); @@ -464,14 +436,12 @@ uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const { return val; } -//---------------------------------------------------------------------- // Extract "count" uint32_t values from the binary data and update the offset // pointed to by "offset_ptr". The extracted data is copied into "dst". // // RETURNS the non-nullptr buffer pointer upon successful extraction of // all the requested bytes, or nullptr when the data is not available in the // buffer due to being out of bounds, or insufficient data. -//---------------------------------------------------------------------- void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint32_t) * count; @@ -496,12 +466,10 @@ void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst, return nullptr; } -//---------------------------------------------------------------------- // Extract a single uint64_t from the data and update the offset pointed to by // "offset_ptr". // // RETURNS the uint64_t that was extracted, or zero on failure. -//---------------------------------------------------------------------- uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const { uint64_t val = 0; const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val)); @@ -515,13 +483,11 @@ uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const { return val; } -//---------------------------------------------------------------------- // GetU64 // // Get multiple consecutive 64 bit values. Return true if the entire read // succeeds and increment the offset pointed to by offset_ptr, else return // false and leave the offset pointed to by offset_ptr unchanged. -//---------------------------------------------------------------------- void *DataExtractor::GetU64(offset_t *offset_ptr, void *void_dst, uint32_t count) const { const size_t src_size = sizeof(uint64_t) * count; @@ -687,14 +653,12 @@ long double DataExtractor::GetLongDouble(offset_t *offset_ptr) const { return val; } -//------------------------------------------------------------------ // Extract a single address from the data and update the offset pointed to by // "offset_ptr". The size of the extracted address comes from the // "this->m_addr_size" member variable and should be set correctly prior to // extracting any address values. // // RETURNS the address that was extracted, or zero on failure. -//------------------------------------------------------------------ uint64_t DataExtractor::GetAddress(offset_t *offset_ptr) const { assert(m_addr_size == 4 || m_addr_size == 8); return GetMaxU64(offset_ptr, m_addr_size); @@ -705,14 +669,12 @@ uint64_t DataExtractor::GetAddress_unchecked(offset_t *offset_ptr) const { return GetMaxU64_unchecked(offset_ptr, m_addr_size); } -//------------------------------------------------------------------ // Extract a single pointer from the data and update the offset pointed to by // "offset_ptr". The size of the extracted pointer comes from the // "this->m_addr_size" member variable and should be set correctly prior to // extracting any pointer values. // // RETURNS the pointer that was extracted, or zero on failure. -//------------------------------------------------------------------ uint64_t DataExtractor::GetPointer(offset_t *offset_ptr) const { assert(m_addr_size == 4 || m_addr_size == 8); return GetMaxU64(offset_ptr, m_addr_size); @@ -836,7 +798,6 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, return 0; } -//---------------------------------------------------------------------- // Extracts a variable length NULL terminated C string from the data at the // offset pointed to by "offset_ptr". The "offset_ptr" will be updated with // the offset of the byte that follows the NULL terminator byte. @@ -844,7 +805,6 @@ DataExtractor::CopyByteOrderedData(offset_t src_offset, offset_t src_len, // If the offset pointed to by "offset_ptr" is out of bounds, or if "length" is // non-zero and there aren't enough available bytes, nullptr will be returned // and "offset_ptr" will not be updated. -//---------------------------------------------------------------------- const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { const char *cstr = (const char *)PeekData(*offset_ptr, 1); if (cstr) { @@ -868,7 +828,6 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { return nullptr; } -//---------------------------------------------------------------------- // Extracts a NULL terminated C string from the fixed length field of length // "len" at the offset pointed to by "offset_ptr". The "offset_ptr" will be // updated with the offset of the byte that follows the fixed length field. @@ -877,7 +836,6 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr) const { // plus the length of the field is out of bounds, or if the field does not // contain a NULL terminator byte, nullptr will be returned and "offset_ptr" // will not be updated. -//---------------------------------------------------------------------- const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const { const char *cstr = (const char *)PeekData(*offset_ptr, len); if (cstr != nullptr) { @@ -890,26 +848,22 @@ const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const { return nullptr; } -//------------------------------------------------------------------ // Peeks at a string in the contained data. No verification is done to make // sure the entire string lies within the bounds of this object's data, only // "offset" is verified to be a valid offset. // // Returns a valid C string pointer if "offset" is a valid offset in this // object's data, else nullptr is returned. -//------------------------------------------------------------------ const char *DataExtractor::PeekCStr(offset_t offset) const { return (const char *)PeekData(offset, 1); } -//---------------------------------------------------------------------- // Extracts an unsigned LEB128 number from this object's data starting at the // offset pointed to by "offset_ptr". The offset pointed to by "offset_ptr" // will be updated with the offset of the byte following the last extracted // byte. // // Returned the extracted integer value. -//---------------------------------------------------------------------- uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); if (src == nullptr) @@ -937,14 +891,12 @@ uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const { return 0; } -//---------------------------------------------------------------------- // Extracts an signed LEB128 number from this object's data starting at the // offset pointed to by "offset_ptr". The offset pointed to by "offset_ptr" // will be updated with the offset of the byte following the last extracted // byte. // // Returned the extracted integer value. -//---------------------------------------------------------------------- int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); if (src == nullptr) @@ -979,14 +931,12 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const { return 0; } -//---------------------------------------------------------------------- // Skips a ULEB128 number (signed or unsigned) from this object's data starting // at the offset pointed to by "offset_ptr". The offset pointed to by // "offset_ptr" will be updated with the offset of the byte following the last // extracted byte. // // Returns the number of bytes consumed during the extraction. -//---------------------------------------------------------------------- uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { uint32_t bytes_consumed = 0; const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1); @@ -1004,7 +954,6 @@ uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { return bytes_consumed; } -//---------------------------------------------------------------------- // Dumps bytes from this object's data to the stream "s" starting // "start_offset" bytes into this data, and ending with the byte before // "end_offset". "base_addr" will be added to the offset into the dumped data @@ -1014,7 +963,6 @@ uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const { // printf style formatting string. If "type_format" is nullptr, then an // appropriate format string will be used for the supplied "type". If the // stream "s" is nullptr, then the output will be send to Log(). -//---------------------------------------------------------------------- lldb::offset_t DataExtractor::PutToLog(Log *log, offset_t start_offset, offset_t length, uint64_t base_addr, uint32_t num_per_line, |