diff options
Diffstat (limited to 'lldb/include/lldb/Utility/DataExtractor.h')
-rw-r--r-- | lldb/include/lldb/Utility/DataExtractor.h | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/lldb/include/lldb/Utility/DataExtractor.h b/lldb/include/lldb/Utility/DataExtractor.h index bf0d1055cf43..0210af5cf6d1 100644 --- a/lldb/include/lldb/Utility/DataExtractor.h +++ b/lldb/include/lldb/Utility/DataExtractor.h @@ -9,12 +9,14 @@ #ifndef LLDB_UTILITY_DATAEXTRACTOR_H #define LLDB_UTILITY_DATAEXTRACTOR_H +#include "lldb/Utility/Endian.h" #include "lldb/lldb-defines.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-forward.h" #include "lldb/lldb-types.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/DataExtractor.h" +#include "llvm/Support/SwapByteOrder.h" #include <cassert> #include <stdint.h> @@ -535,13 +537,13 @@ public: uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset) const; - /// Extract an signed integer of size \a byte_size from \a *offset_ptr, then - /// extract and signe extend the bitfield from this value if \a + /// Extract an signed integer of size \a size from \a *offset_ptr, then + /// extract and sign-extend the bitfield from this value if \a /// bitfield_bit_size is non-zero. /// - /// Extract a single signed integer value (sign extending if required) and + /// Extract a single signed integer value (sign-extending if required) and /// update the offset pointed to by \a offset_ptr. The size of the extracted - /// integer is specified by the \a byte_size argument. \a byte_size must + /// integer is specified by the \a size argument. \a size must /// have a value greater than or equal to one and less than or equal to /// eight since the return value is 64 bits wide. /// @@ -573,24 +575,6 @@ public: uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset) const; - /// Extract an pointer from \a *offset_ptr. - /// - /// Extract a single pointer from the data and update the offset pointed to - /// by \a offset_ptr. The size of the extracted pointer comes from the \a - /// m_addr_size member variable and should be set correctly prior to - /// extracting any pointer values. - /// - /// \param[in,out] offset_ptr - /// A pointer to an offset within the data that will be advanced - /// by the appropriate number of bytes if the value is extracted - /// correctly. If the offset is out of bounds or there are not - /// enough bytes to extract this value, the offset will be left - /// unmodified. - /// - /// \return - /// The extracted pointer value as a 64 integer. - uint64_t GetPointer(lldb::offset_t *offset_ptr) const; - /// Get the current byte order value. /// /// \return @@ -997,19 +981,33 @@ public: } protected: + template <typename T> T Get(lldb::offset_t *offset_ptr, T fail_value) const { + constexpr size_t src_size = sizeof(T); + T val = fail_value; + + const T *src = static_cast<const T *>(GetData(offset_ptr, src_size)); + if (!src) + return val; + + memcpy(&val, src, src_size); + if (m_byte_order != endian::InlHostByteOrder()) + llvm::sys::swapByteOrder(val); + + return val; + } + // Member variables const uint8_t *m_start; ///< A pointer to the first byte of data. const uint8_t *m_end; ///< A pointer to the byte that is past the end of the data. lldb::ByteOrder m_byte_order; ///< The byte order of the data we are extracting from. - uint32_t m_addr_size; ///< The address size to use when extracting pointers or - /// addresses - mutable lldb::DataBufferSP m_data_sp; ///< The shared pointer to data that can - /// be shared among multiple instances + uint32_t m_addr_size; ///< The address size to use when extracting addresses. + /// The shared pointer to data that can be shared among multiple instances + lldb::DataBufferSP m_data_sp; const uint32_t m_target_byte_size; }; } // namespace lldb_private -#endif // liblldb_DataExtractor_h_ +#endif // LLDB_UTILITY_DATAEXTRACTOR_H |