|
|
|||
File indexing completed on 2026-05-10 08:42:57
0001 //===-- DataBuffer.h --------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLDB_UTILITY_DATABUFFER_H 0010 #define LLDB_UTILITY_DATABUFFER_H 0011 0012 #include <cstdint> 0013 #include <cstring> 0014 0015 #include "lldb/lldb-types.h" 0016 0017 #include "llvm/ADT/ArrayRef.h" 0018 0019 namespace lldb_private { 0020 0021 /// \class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h" 0022 /// A pure virtual protocol class for abstracted read only data buffers. 0023 /// 0024 /// DataBuffer is an abstract class that gets packaged into a shared 0025 /// pointer that can use to implement various ways to store data (on the heap, 0026 /// memory mapped, cached inferior memory). It gets used by DataExtractor so 0027 /// many DataExtractor objects can share the same data and sub-ranges of that 0028 /// shared data, and the last object that contains a reference to the shared 0029 /// data will free it. 0030 /// 0031 /// Subclasses can implement as many different constructors or member 0032 /// functions that allow data to be stored in the object's buffer prior to 0033 /// handing the shared data to clients that use these buffers. 0034 /// 0035 /// All subclasses must override all of the pure virtual functions as they are 0036 /// used by clients to access the data. Having a common interface allows 0037 /// different ways of storing data, yet using it in one common way. 0038 /// 0039 /// This class currently expects all data to be available without any extra 0040 /// calls being made, but we can modify it to optionally get data on demand 0041 /// with some extra function calls to load the data before it gets accessed. 0042 class DataBuffer { 0043 public: 0044 virtual ~DataBuffer() = default; 0045 0046 /// Get the number of bytes in the data buffer. 0047 /// 0048 /// \return 0049 /// The number of bytes this object currently contains. 0050 virtual lldb::offset_t GetByteSize() const = 0; 0051 0052 /// Get a const pointer to the data. 0053 /// 0054 /// \return 0055 /// A const pointer to the bytes owned by this object, or NULL 0056 /// if the object contains no bytes. 0057 const uint8_t *GetBytes() const { return GetBytesImpl(); } 0058 0059 llvm::ArrayRef<uint8_t> GetData() const { 0060 return llvm::ArrayRef<uint8_t>(GetBytes(), GetByteSize()); 0061 } 0062 0063 /// LLVM RTTI support. 0064 /// { 0065 static char ID; 0066 virtual bool isA(const void *ClassID) const { return ClassID == &ID; } 0067 static bool classof(const DataBuffer *data_buffer) { 0068 return data_buffer->isA(&ID); 0069 } 0070 /// } 0071 0072 protected: 0073 /// Get a const pointer to the data. 0074 /// 0075 /// \return 0076 /// A const pointer to the bytes owned by this object, or NULL 0077 /// if the object contains no bytes. 0078 virtual const uint8_t *GetBytesImpl() const = 0; 0079 }; 0080 0081 /// \class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h" 0082 /// A pure virtual protocol class for abstracted writable data buffers. 0083 /// 0084 /// DataBuffer is an abstract class that gets packaged into a shared pointer 0085 /// that can use to implement various ways to store data (on the heap, memory 0086 /// mapped, cached inferior memory). It gets used by DataExtractor so many 0087 /// DataExtractor objects can share the same data and sub-ranges of that 0088 /// shared data, and the last object that contains a reference to the shared 0089 /// data will free it. 0090 class WritableDataBuffer : public DataBuffer { 0091 public: 0092 /// Destructor 0093 /// 0094 /// The destructor is virtual as other classes will inherit from this class 0095 /// and be downcast to the DataBuffer pure virtual interface. The virtual 0096 /// destructor ensures that destructing the base class will destruct the 0097 /// class that inherited from it correctly. 0098 ~WritableDataBuffer() override = default; 0099 0100 using DataBuffer::GetBytes; 0101 using DataBuffer::GetData; 0102 0103 /// Get a pointer to the data. 0104 /// 0105 /// \return 0106 /// A pointer to the bytes owned by this object, or NULL if the 0107 /// object contains no bytes. 0108 uint8_t *GetBytes() { return const_cast<uint8_t *>(GetBytesImpl()); } 0109 0110 llvm::MutableArrayRef<uint8_t> GetData() { 0111 return llvm::MutableArrayRef<uint8_t>(GetBytes(), GetByteSize()); 0112 } 0113 0114 /// LLVM RTTI support. 0115 /// { 0116 static char ID; 0117 bool isA(const void *ClassID) const override { 0118 return ClassID == &ID || DataBuffer::isA(ClassID); 0119 } 0120 static bool classof(const DataBuffer *data_buffer) { 0121 return data_buffer->isA(&ID); 0122 } 0123 /// } 0124 }; 0125 0126 class DataBufferUnowned : public WritableDataBuffer { 0127 public: 0128 DataBufferUnowned(uint8_t *bytes, lldb::offset_t size) 0129 : m_bytes(bytes), m_size(size) {} 0130 0131 const uint8_t *GetBytesImpl() const override { return m_bytes; } 0132 lldb::offset_t GetByteSize() const override { return m_size; } 0133 0134 /// LLVM RTTI support. 0135 /// { 0136 static char ID; 0137 bool isA(const void *ClassID) const override { 0138 return ClassID == &ID || WritableDataBuffer::isA(ClassID); 0139 } 0140 static bool classof(const DataBuffer *data_buffer) { 0141 return data_buffer->isA(&ID); 0142 } 0143 /// } 0144 private: 0145 uint8_t *m_bytes; 0146 lldb::offset_t m_size; 0147 }; 0148 0149 } // namespace lldb_private 0150 0151 #endif // LLDB_UTILITY_DATABUFFER_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|