]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/DataExtractor.h
Merge llvm, clang, lld and lldb trunk r291274, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / DataExtractor.h
1 //===-- DataExtractor.h -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_DataExtractor_h_
11 #define liblldb_DataExtractor_h_
12
13 // C Includes
14 #include <limits.h>
15 #include <stdint.h>
16 #include <string.h>
17
18 // C++ Includes
19 // Other libraries and framework includes
20 #include "llvm/ADT/SmallVector.h"
21
22 // Project includes
23 #include "lldb/lldb-private.h"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 /// @class DataExtractor DataExtractor.h "lldb/Core/DataExtractor.h"
29 /// @brief An data extractor class.
30 ///
31 /// DataExtractor is a class that can extract data (swapping if needed)
32 /// from a data buffer. The data buffer can be caller owned, or can be
33 /// shared data that can be shared between multiple DataExtractor
34 /// instances. Multiple DataExtractor objects can share the same data,
35 /// yet extract values in different address sizes and byte order modes.
36 /// Each object can have a unique position in the shared data and extract
37 /// data from different offsets.
38 ///
39 /// @see DataBuffer
40 //----------------------------------------------------------------------
41 class DataExtractor {
42 public:
43   //------------------------------------------------------------------
44   /// @typedef DataExtractor::Type
45   /// @brief Type enumerations used in the dump routines.
46   /// @see DataExtractor::Dump()
47   /// @see DataExtractor::DumpRawHexBytes()
48   //------------------------------------------------------------------
49   typedef enum {
50     TypeUInt8,   ///< Format output as unsigned 8 bit integers
51     TypeChar,    ///< Format output as characters
52     TypeUInt16,  ///< Format output as unsigned 16 bit integers
53     TypeUInt32,  ///< Format output as unsigned 32 bit integers
54     TypeUInt64,  ///< Format output as unsigned 64 bit integers
55     TypePointer, ///< Format output as pointers
56     TypeULEB128, ///< Format output as ULEB128 numbers
57     TypeSLEB128  ///< Format output as SLEB128 numbers
58   } Type;
59
60   static void DumpHexBytes(Stream *s, const void *src, size_t src_len,
61                            uint32_t bytes_per_line,
62                            lldb::addr_t base_addr); // Pass LLDB_INVALID_ADDRESS
63                                                     // to not show address at
64                                                     // start of line
65
66   //------------------------------------------------------------------
67   /// Default constructor.
68   ///
69   /// Initialize all members to a default empty state.
70   //------------------------------------------------------------------
71   DataExtractor();
72
73   //------------------------------------------------------------------
74   /// Construct with a buffer that is owned by the caller.
75   ///
76   /// This constructor allows us to use data that is owned by the
77   /// caller. The data must stay around as long as this object is
78   /// valid.
79   ///
80   /// @param[in] data
81   ///     A pointer to caller owned data.
82   ///
83   /// @param[in] data_length
84   ///     The length in bytes of \a data.
85   ///
86   /// @param[in] byte_order
87   ///     A byte order of the data that we are extracting from.
88   ///
89   /// @param[in] addr_size
90   ///     A new address byte size value.
91   ///
92   /// @param[in] target_byte_size
93   ///     A size of a target byte in 8-bit host bytes
94   //------------------------------------------------------------------
95   DataExtractor(const void *data, lldb::offset_t data_length,
96                 lldb::ByteOrder byte_order, uint32_t addr_size,
97                 uint32_t target_byte_size = 1);
98
99   //------------------------------------------------------------------
100   /// Construct with shared data.
101   ///
102   /// Copies the data shared pointer which adds a reference to the
103   /// contained in \a data_sp. The shared data reference is reference
104   /// counted to ensure the data lives as long as anyone still has a
105   /// valid shared pointer to the data in \a data_sp.
106   ///
107   /// @param[in] data_sp
108   ///     A shared pointer to data.
109   ///
110   /// @param[in] byte_order
111   ///     A byte order of the data that we are extracting from.
112   ///
113   /// @param[in] addr_size
114   ///     A new address byte size value.
115   ///
116   /// @param[in] target_byte_size
117   ///     A size of a target byte in 8-bit host bytes
118   //------------------------------------------------------------------
119   DataExtractor(const lldb::DataBufferSP &data_sp, lldb::ByteOrder byte_order,
120                 uint32_t addr_size, uint32_t target_byte_size = 1);
121
122   //------------------------------------------------------------------
123   /// Construct with a subset of \a data.
124   ///
125   /// Initialize this object with a subset of the data bytes in \a
126   /// data. If \a data contains shared data, then a reference to the
127   /// shared data will be added to ensure the shared data stays around
128   /// as long as any objects have references to the shared data. The
129   /// byte order value and the address size settings are copied from \a
130   /// data. If \a offset is not a valid offset in \a data, then no
131   /// reference to the shared data will be added. If there are not
132   /// \a length bytes available in \a data starting at \a offset,
133   /// the length will be truncated to contain as many bytes as
134   /// possible.
135   ///
136   /// @param[in] data
137   ///     Another DataExtractor object that contains data.
138   ///
139   /// @param[in] offset
140   ///     The offset into \a data at which the subset starts.
141   ///
142   /// @param[in] length
143   ///     The length in bytes of the subset of data.
144   ///
145   /// @param[in] target_byte_size
146   ///     A size of a target byte in 8-bit host bytes
147   //------------------------------------------------------------------
148   DataExtractor(const DataExtractor &data, lldb::offset_t offset,
149                 lldb::offset_t length, uint32_t target_byte_size = 1);
150
151   DataExtractor(const DataExtractor &rhs);
152
153   //------------------------------------------------------------------
154   /// Assignment operator.
155   ///
156   /// Copies all data, byte order and address size settings from \a rhs into
157   /// this object. If \a rhs contains shared data, a reference to that
158   /// shared data will be added.
159   ///
160   /// @param[in] rhs
161   ///     Another DataExtractor object to copy.
162   ///
163   /// @return
164   ///     A const reference to this object.
165   //------------------------------------------------------------------
166   const DataExtractor &operator=(const DataExtractor &rhs);
167
168   //------------------------------------------------------------------
169   /// Destructor
170   ///
171   /// If this object contains a valid shared data reference, the
172   /// reference count on the data will be decremented, and if zero,
173   /// the data will be freed.
174   //------------------------------------------------------------------
175   ~DataExtractor();
176
177   //------------------------------------------------------------------
178   /// Clears the object state.
179   ///
180   /// Clears the object contents back to a default invalid state, and
181   /// release any references to shared data that this object may
182   /// contain.
183   //------------------------------------------------------------------
184   void Clear();
185
186   //------------------------------------------------------------------
187   /// Dumps the binary data as \a type objects to stream \a s (or to
188   /// Log() if \a s is nullptr) starting \a offset bytes into the data
189   /// and stopping after dumping \a length bytes. The offset into the
190   /// data is displayed at the beginning of each line and can be
191   /// offset by base address \a base_addr. \a num_per_line objects
192   /// will be displayed on each line.
193   ///
194   /// @param[in] s
195   ///     The stream to dump the output to. If nullptr the output will
196   ///     be dumped to Log().
197   ///
198   /// @param[in] offset
199   ///     The offset into the data at which to start dumping.
200   ///
201   /// @param[in] length
202   ///     The number of bytes to dump.
203   ///
204   /// @param[in] base_addr
205   ///     The base address that gets added to the offset displayed on
206   ///     each line.
207   ///
208   /// @param[in] num_per_line
209   ///     The number of \a type objects to display on each line.
210   ///
211   /// @param[in] type
212   ///     The type of objects to use when dumping data from this
213   ///     object. See DataExtractor::Type.
214   ///
215   /// @param[in] type_format
216   ///     The optional format to use for the \a type objects. If this
217   ///     is nullptr, the default format for the \a type will be used.
218   ///
219   /// @return
220   ///     The offset at which dumping ended.
221   //------------------------------------------------------------------
222   lldb::offset_t PutToLog(Log *log, lldb::offset_t offset,
223                           lldb::offset_t length, uint64_t base_addr,
224                           uint32_t num_per_line, Type type,
225                           const char *type_format = nullptr) const;
226
227   //------------------------------------------------------------------
228   /// Dumps \a item_count objects into the stream \a s.
229   ///
230   /// Dumps \a item_count objects using \a item_format, each of which
231   /// are \a item_byte_size bytes long starting at offset \a offset
232   /// bytes into the contained data, into the stream \a s. \a
233   /// num_per_line objects will be dumped on each line before a new
234   /// line will be output. If \a base_addr is a valid address, then
235   /// each new line of output will be preceded by the address value
236   /// plus appropriate offset, and a colon and space. Bitfield values
237   /// can be dumped by calling this function multiple times with the
238   /// same start offset, format and size, yet differing \a
239   /// item_bit_size and \a item_bit_offset values.
240   ///
241   /// @param[in] s
242   ///     The stream to dump the output to. This value can not be nullptr.
243   ///
244   /// @param[in] offset
245   ///     The offset into the data at which to start dumping.
246   ///
247   /// @param[in] item_format
248   ///     The format to use when dumping each item.
249   ///
250   /// @param[in] item_byte_size
251   ///     The byte size of each item.
252   ///
253   /// @param[in] item_count
254   ///     The number of items to dump.
255   ///
256   /// @param[in] num_per_line
257   ///     The number of items to display on each line.
258   ///
259   /// @param[in] base_addr
260   ///     The base address that gets added to the offset displayed on
261   ///     each line if the value is valid. Is \a base_addr is
262   ///     LLDB_INVALID_ADDRESS then no address values will be prepended
263   ///     to any lines.
264   ///
265   /// @param[in] item_bit_size
266   ///     If the value to display is a bitfield, this value should
267   ///     be the number of bits that the bitfield item has within the
268   ///     item's byte size value. This function will need to be called
269   ///     multiple times with identical \a offset and \a item_byte_size
270   ///     values in order to display multiple bitfield values that
271   ///     exist within the same integer value. If the items being
272   ///     displayed are not bitfields, this value should be zero.
273   ///
274   /// @param[in] item_bit_offset
275   ///     If the value to display is a bitfield, this value should
276   ///     be the offset in bits, or shift right amount, that the
277   ///     bitfield item occupies within the item's byte size value.
278   ///     This function will need to be called multiple times with
279   ///     identical \a offset and \a item_byte_size values in order
280   ///     to display multiple bitfield values that exist within the
281   ///     same integer value. If the items being displayed are not
282   ///     bitfields, this value should be zero.
283   ///
284   /// @return
285   ///     The offset at which dumping ended.
286   //------------------------------------------------------------------
287   lldb::offset_t Dump(Stream *s, lldb::offset_t offset,
288                       lldb::Format item_format, size_t item_byte_size,
289                       size_t item_count, size_t num_per_line,
290                       uint64_t base_addr, uint32_t item_bit_size,
291                       uint32_t item_bit_offset,
292                       ExecutionContextScope *exe_scope = nullptr) const;
293
294   //------------------------------------------------------------------
295   /// Dump a UUID value at \a offset.
296   ///
297   /// Dump a UUID starting at \a offset bytes into this object's data.
298   /// If the stream \a s is nullptr, the output will be sent to Log().
299   ///
300   /// @param[in] s
301   ///     The stream to dump the output to. If nullptr the output will
302   ///     be dumped to Log().
303   ///
304   /// @param[in] offset
305   ///     The offset into the data at which to extract and dump a
306   ///     UUID value.
307   //------------------------------------------------------------------
308   void DumpUUID(Stream *s, lldb::offset_t offset) const;
309
310   //------------------------------------------------------------------
311   /// Extract an arbitrary number of bytes in the specified byte
312   /// order.
313   ///
314   /// Attemps to extract \a length bytes starting at \a offset bytes
315   /// into this data in the requested byte order (\a dst_byte_order)
316   /// and place the results in \a dst. \a dst must be at least \a
317   /// length bytes long.
318   ///
319   /// @param[in] offset
320   ///     The offset in bytes into the contained data at which to
321   ///     start extracting.
322   ///
323   /// @param[in] length
324   ///     The number of bytes to extract.
325   ///
326   /// @param[in] dst_byte_order
327   ///     A byte order of the data that we want when the value in
328   ///     copied to \a dst.
329   ///
330   /// @param[out] dst
331   ///     The buffer that will receive the extracted value if there
332   ///     are enough bytes available in the current data.
333   ///
334   /// @return
335   ///     The number of bytes that were extracted which will be \a
336   ///     length when the value is successfully extracted, or zero
337   ///     if there aren't enough bytes at the specified offset.
338   //------------------------------------------------------------------
339   size_t ExtractBytes(lldb::offset_t offset, lldb::offset_t length,
340                       lldb::ByteOrder dst_byte_order, void *dst) const;
341
342   //------------------------------------------------------------------
343   /// Extract an address from \a *offset_ptr.
344   ///
345   /// Extract a single address from the data and update the offset
346   /// pointed to by \a offset_ptr. The size of the extracted address
347   /// comes from the \a m_addr_size member variable and should be
348   /// set correctly prior to extracting any address values.
349   ///
350   /// @param[in,out] offset_ptr
351   ///     A pointer to an offset within the data that will be advanced
352   ///     by the appropriate number of bytes if the value is extracted
353   ///     correctly. If the offset is out of bounds or there are not
354   ///     enough bytes to extract this value, the offset will be left
355   ///     unmodified.
356   ///
357   /// @return
358   ///     The extracted address value.
359   //------------------------------------------------------------------
360   uint64_t GetAddress(lldb::offset_t *offset_ptr) const;
361
362   uint64_t GetAddress_unchecked(lldb::offset_t *offset_ptr) const;
363
364   //------------------------------------------------------------------
365   /// Get the current address size.
366   ///
367   /// Return the size in bytes of any address values this object will
368   /// extract.
369   ///
370   /// @return
371   ///     The size in bytes of address values that will be extracted.
372   //------------------------------------------------------------------
373   uint32_t GetAddressByteSize() const { return m_addr_size; }
374
375   //------------------------------------------------------------------
376   /// Get the number of bytes contained in this object.
377   ///
378   /// @return
379   ///     The total number of bytes of data this object refers to.
380   //------------------------------------------------------------------
381   uint64_t GetByteSize() const { return m_end - m_start; }
382
383   //------------------------------------------------------------------
384   /// Extract a C string from \a *offset_ptr.
385   ///
386   /// Returns a pointer to a C String from the data at the offset
387   /// pointed to by \a offset_ptr. A variable length NULL terminated C
388   /// string will be extracted and the \a offset_ptr will be
389   /// updated with the offset of the byte that follows the NULL
390   /// terminator byte.
391   ///
392   /// @param[in,out] offset_ptr
393   ///     A pointer to an offset within the data that will be advanced
394   ///     by the appropriate number of bytes if the value is extracted
395   ///     correctly. If the offset is out of bounds or there are not
396   ///     enough bytes to extract this value, the offset will be left
397   ///     unmodified.
398   ///
399   /// @return
400   ///     A pointer to the C string value in the data. If the offset
401   ///     pointed to by \a offset_ptr is out of bounds, or if the
402   ///     offset plus the length of the C string is out of bounds,
403   ///     nullptr will be returned.
404   //------------------------------------------------------------------
405   const char *GetCStr(lldb::offset_t *offset_ptr) const;
406
407   //------------------------------------------------------------------
408   /// Extract a C string from \a *offset_ptr with field size \a len.
409   ///
410   /// Returns a pointer to a C String from the data at the offset
411   /// pointed to by \a offset_ptr, with a field length of \a len.
412   /// A NULL terminated C string will be extracted and the \a offset_ptr
413   /// will be updated with the offset of the byte that follows the fixed
414   /// length field.
415   ///
416   /// @param[in,out] offset_ptr
417   ///     A pointer to an offset within the data that will be advanced
418   ///     by the appropriate number of bytes if the value is extracted
419   ///     correctly. If the offset is out of bounds or there are not
420   ///     enough bytes to extract this value, the offset will be left
421   ///     unmodified.
422   ///
423   /// @return
424   ///     A pointer to the C string value in the data. If the offset
425   ///     pointed to by \a offset_ptr is out of bounds, or if the
426   ///     offset plus the length of the field is out of bounds, or if
427   ///     the field does not contain a NULL terminator byte, nullptr will
428   ///     be returned.
429   const char *GetCStr(lldb::offset_t *offset_ptr, lldb::offset_t len) const;
430
431   //------------------------------------------------------------------
432   /// Extract \a length bytes from \a *offset_ptr.
433   ///
434   /// Returns a pointer to a bytes in this object's data at the offset
435   /// pointed to by \a offset_ptr. If \a length is zero or too large,
436   /// then the offset pointed to by \a offset_ptr will not be updated
437   /// and nullptr will be returned.
438   ///
439   /// @param[in,out] offset_ptr
440   ///     A pointer to an offset within the data that will be advanced
441   ///     by the appropriate number of bytes if the value is extracted
442   ///     correctly. If the offset is out of bounds or there are not
443   ///     enough bytes to extract this value, the offset will be left
444   ///     unmodified.
445   ///
446   /// @param[in] length
447   ///     The optional length of a string to extract. If the value is
448   ///     zero, a NULL terminated C string will be extracted.
449   ///
450   /// @return
451   ///     A pointer to the bytes in this object's data if the offset
452   ///     and length are valid, or nullptr otherwise.
453   //------------------------------------------------------------------
454   const void *GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const {
455     const uint8_t *ptr = PeekData(*offset_ptr, length);
456     if (ptr)
457       *offset_ptr += length;
458     return ptr;
459   }
460
461   //------------------------------------------------------------------
462   /// Copy \a length bytes from \a *offset, without swapping bytes.
463   ///
464   /// @param[in] offset
465   ///     The offset into this data from which to start copying
466   ///
467   /// @param[in] length
468   ///     The length of the data to copy from this object
469   ///
470   /// @param[out] dst
471   ///     The buffer to place the output data.
472   ///
473   /// @return
474   ///     Returns the number of bytes that were copied, or zero if
475   ///     anything goes wrong.
476   //------------------------------------------------------------------
477   lldb::offset_t CopyData(lldb::offset_t offset, lldb::offset_t length,
478                           void *dst) const;
479
480   //------------------------------------------------------------------
481   /// Copy \a dst_len bytes from \a *offset_ptr and ensure the copied
482   /// data is treated as a value that can be swapped to match the
483   /// specified byte order.
484   ///
485   /// For values that are larger than the supported integer sizes,
486   /// this function can be used to extract data in a specified byte
487   /// order. It can also be used to copy a smaller integer value from
488   /// to a larger value. The extra bytes left over will be padded
489   /// correctly according to the byte order of this object and the
490   /// \a dst_byte_order. This can be very handy when say copying a
491   /// partial data value into a register.
492   ///
493   /// @param[in] src_offset
494   ///     The offset into this data from which to start copying an
495   ///     endian entity
496   ///
497   /// @param[in] src_len
498   ///     The length of the endian data to copy from this object
499   ///     into the \a dst object
500   ///
501   /// @param[out] dst
502   ///     The buffer where to place the endian data. The data might
503   ///     need to be byte swapped (and appropriately padded with
504   ///     zeroes if \a src_len != \a dst_len) if \a dst_byte_order
505   ///     does not match the byte order in this object.
506   ///
507   /// @param[in] dst_len
508   ///     The length number of bytes that the endian value will
509   ///     occupy is \a dst.
510   ///
511   /// @param[in] byte_order
512   ///     The byte order that the endian value should be in the \a dst
513   ///     buffer.
514   ///
515   /// @return
516   ///     Returns the number of bytes that were copied, or zero if
517   ///     anything goes wrong.
518   //------------------------------------------------------------------
519   lldb::offset_t CopyByteOrderedData(lldb::offset_t src_offset,
520                                      lldb::offset_t src_len, void *dst,
521                                      lldb::offset_t dst_len,
522                                      lldb::ByteOrder dst_byte_order) const;
523
524   //------------------------------------------------------------------
525   /// Get the data end pointer.
526   ///
527   /// @return
528   ///     Returns a pointer to the next byte contained in this
529   ///     object's data, or nullptr of there is no data in this object.
530   //------------------------------------------------------------------
531   const uint8_t *GetDataEnd() const { return m_end; }
532
533   //------------------------------------------------------------------
534   /// Get the shared data offset.
535   ///
536   /// Get the offset of the first byte of data in the shared data (if
537   /// any).
538   ///
539   /// @return
540   ///     If this object contains shared data, this function returns
541   ///     the offset in bytes into that shared data, zero otherwise.
542   //------------------------------------------------------------------
543   size_t GetSharedDataOffset() const;
544
545   //------------------------------------------------------------------
546   /// Get the data start pointer.
547   ///
548   /// @return
549   ///     Returns a pointer to the first byte contained in this
550   ///     object's data, or nullptr of there is no data in this object.
551   //------------------------------------------------------------------
552   const uint8_t *GetDataStart() const { return m_start; }
553
554   //------------------------------------------------------------------
555   /// Extract a float from \a *offset_ptr.
556   ///
557   /// Extract a single float value.
558   ///
559   /// @param[in,out] offset_ptr
560   ///     A pointer to an offset within the data that will be advanced
561   ///     by the appropriate number of bytes if the value is extracted
562   ///     correctly. If the offset is out of bounds or there are not
563   ///     enough bytes to extract this value, the offset will be left
564   ///     unmodified.
565   ///
566   /// @return
567   ///     The floating value that was extracted, or zero on failure.
568   //------------------------------------------------------------------
569   float GetFloat(lldb::offset_t *offset_ptr) const;
570
571   double GetDouble(lldb::offset_t *offset_ptr) const;
572
573   long double GetLongDouble(lldb::offset_t *offset_ptr) const;
574
575   //------------------------------------------------------------------
576   /// Extract a GNU encoded pointer value from \a *offset_ptr.
577   ///
578   /// @param[in,out] offset_ptr
579   ///     A pointer to an offset within the data that will be advanced
580   ///     by the appropriate number of bytes if the value is extracted
581   ///     correctly. If the offset is out of bounds or there are not
582   ///     enough bytes to extract this value, the offset will be left
583   ///     unmodified.
584   ///
585   /// @param[in] eh_ptr_enc
586   ///     The GNU pointer encoding type.
587   ///
588   /// @param[in] pc_rel_addr
589   ///     The PC relative address to use when the encoding is
590   ///     \c DW_GNU_EH_PE_pcrel.
591   ///
592   /// @param[in] text_addr
593   ///     The text (code) relative address to use when the encoding is
594   ///     \c DW_GNU_EH_PE_textrel.
595   ///
596   /// @param[in] data_addr
597   ///     The data relative address to use when the encoding is
598   ///     \c DW_GNU_EH_PE_datarel.
599   ///
600   /// @return
601   ///     The extracted GNU encoded pointer value.
602   //------------------------------------------------------------------
603   uint64_t GetGNUEHPointer(lldb::offset_t *offset_ptr, uint32_t eh_ptr_enc,
604                            lldb::addr_t pc_rel_addr, lldb::addr_t text_addr,
605                            lldb::addr_t data_addr);
606
607   //------------------------------------------------------------------
608   /// Extract an integer of size \a byte_size from \a *offset_ptr.
609   ///
610   /// Extract a single integer value and update the offset pointed to
611   /// by \a offset_ptr. The size of the extracted integer is specified
612   /// by the \a byte_size argument. \a byte_size should have a value
613   /// >= 1 and <= 4 since the return value is only 32 bits wide. Any
614   /// \a byte_size values less than 1 or greater than 4 will result in
615   /// nothing being extracted, and zero being returned.
616   ///
617   /// @param[in,out] offset_ptr
618   ///     A pointer to an offset within the data that will be advanced
619   ///     by the appropriate number of bytes if the value is extracted
620   ///     correctly. If the offset is out of bounds or there are not
621   ///     enough bytes to extract this value, the offset will be left
622   ///     unmodified.
623   ///
624   /// @param[in] byte_size
625   ///     The size in byte of the integer to extract.
626   ///
627   /// @return
628   ///     The integer value that was extracted, or zero on failure.
629   //------------------------------------------------------------------
630   uint32_t GetMaxU32(lldb::offset_t *offset_ptr, size_t byte_size) const;
631
632   //------------------------------------------------------------------
633   /// Extract an unsigned integer of size \a byte_size from \a
634   /// *offset_ptr.
635   ///
636   /// Extract a single unsigned integer value and update the offset
637   /// pointed to by \a offset_ptr. The size of the extracted integer
638   /// is specified by the \a byte_size argument. \a byte_size should
639   /// have a value greater than or equal to one and less than or equal
640   /// to eight since the return value is 64 bits wide. Any
641   /// \a byte_size values less than 1 or greater than 8 will result in
642   /// nothing being extracted, and zero being returned.
643   ///
644   /// @param[in,out] offset_ptr
645   ///     A pointer to an offset within the data that will be advanced
646   ///     by the appropriate number of bytes if the value is extracted
647   ///     correctly. If the offset is out of bounds or there are not
648   ///     enough bytes to extract this value, the offset will be left
649   ///     unmodified.
650   ///
651   /// @param[in] byte_size
652   ///     The size in byte of the integer to extract.
653   ///
654   /// @return
655   ///     The unsigned integer value that was extracted, or zero on
656   ///     failure.
657   //------------------------------------------------------------------
658   uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const;
659
660   uint64_t GetMaxU64_unchecked(lldb::offset_t *offset_ptr,
661                                size_t byte_size) const;
662
663   //------------------------------------------------------------------
664   /// Extract an signed integer of size \a byte_size from \a *offset_ptr.
665   ///
666   /// Extract a single signed integer value (sign extending if required)
667   /// and update the offset pointed to by \a offset_ptr. The size of
668   /// the extracted integer is specified by the \a byte_size argument.
669   /// \a byte_size should have a value greater than or equal to one
670   /// and less than or equal to eight since the return value is 64
671   /// bits wide. Any \a byte_size values less than 1 or greater than
672   /// 8 will result in nothing being extracted, and zero being returned.
673   ///
674   /// @param[in,out] offset_ptr
675   ///     A pointer to an offset within the data that will be advanced
676   ///     by the appropriate number of bytes if the value is extracted
677   ///     correctly. If the offset is out of bounds or there are not
678   ///     enough bytes to extract this value, the offset will be left
679   ///     unmodified.
680   ///
681   /// @param[in] byte_size
682   ///     The size in byte of the integer to extract.
683   ///
684   /// @return
685   ///     The sign extended signed integer value that was extracted,
686   ///     or zero on failure.
687   //------------------------------------------------------------------
688   int64_t GetMaxS64(lldb::offset_t *offset_ptr, size_t size) const;
689
690   //------------------------------------------------------------------
691   /// Extract an unsigned integer of size \a byte_size from \a
692   /// *offset_ptr, then extract the bitfield from this value if
693   /// \a bitfield_bit_size is non-zero.
694   ///
695   /// Extract a single unsigned integer value and update the offset
696   /// pointed to by \a offset_ptr. The size of the extracted integer
697   /// is specified by the \a byte_size argument. \a byte_size should
698   /// have a value greater than or equal to one and less than or equal
699   /// to 8 since the return value is 64 bits wide. Any
700   /// \a byte_size values less than 1 or greater than 8 will result in
701   /// nothing being extracted, and zero being returned.
702   ///
703   /// @param[in,out] offset_ptr
704   ///     A pointer to an offset within the data that will be advanced
705   ///     by the appropriate number of bytes if the value is extracted
706   ///     correctly. If the offset is out of bounds or there are not
707   ///     enough bytes to extract this value, the offset will be left
708   ///     unmodified.
709   ///
710   /// @param[in] byte_size
711   ///     The size in byte of the integer to extract.
712   ///
713   /// @param[in] bitfield_bit_size
714   ///     The size in bits of the bitfield value to extract, or zero
715   ///     to just extract the entire integer value.
716   ///
717   /// @param[in] bitfield_bit_offset
718   ///     The bit offset of the bitfield value in the extracted
719   ///     integer.  For little-endian data, this is the offset of
720   ///     the LSB of the bitfield from the LSB of the integer.
721   ///     For big-endian data, this is the offset of the MSB of the
722   ///     bitfield from the MSB of the integer.
723   ///
724   /// @return
725   ///     The unsigned bitfield integer value that was extracted, or
726   ///     zero on failure.
727   //------------------------------------------------------------------
728   uint64_t GetMaxU64Bitfield(lldb::offset_t *offset_ptr, size_t size,
729                              uint32_t bitfield_bit_size,
730                              uint32_t bitfield_bit_offset) const;
731
732   //------------------------------------------------------------------
733   /// Extract an signed integer of size \a byte_size from \a
734   /// *offset_ptr, then extract and signe extend the bitfield from
735   /// this value if \a bitfield_bit_size is non-zero.
736   ///
737   /// Extract a single signed integer value (sign extending if required)
738   /// and update the offset pointed to by \a offset_ptr. The size of
739   /// the extracted integer is specified by the \a byte_size argument.
740   /// \a byte_size should have a value greater than or equal to one
741   /// and less than or equal to eight since the return value is 64
742   /// bits wide. Any \a byte_size values less than 1 or greater than
743   /// 8 will result in nothing being extracted, and zero being returned.
744   ///
745   /// @param[in,out] offset_ptr
746   ///     A pointer to an offset within the data that will be advanced
747   ///     by the appropriate number of bytes if the value is extracted
748   ///     correctly. If the offset is out of bounds or there are not
749   ///     enough bytes to extract this value, the offset will be left
750   ///     unmodified.
751   ///
752   /// @param[in] byte_size
753   ///     The size in bytes of the integer to extract.
754   ///
755   /// @param[in] bitfield_bit_size
756   ///     The size in bits of the bitfield value to extract, or zero
757   ///     to just extract the entire integer value.
758   ///
759   /// @param[in] bitfield_bit_offset
760   ///     The bit offset of the bitfield value in the extracted
761   ///     integer.  For little-endian data, this is the offset of
762   ///     the LSB of the bitfield from the LSB of the integer.
763   ///     For big-endian data, this is the offset of the MSB of the
764   ///     bitfield from the MSB of the integer.
765   ///
766   /// @return
767   ///     The signed bitfield integer value that was extracted, or
768   ///     zero on failure.
769   //------------------------------------------------------------------
770   int64_t GetMaxS64Bitfield(lldb::offset_t *offset_ptr, size_t size,
771                             uint32_t bitfield_bit_size,
772                             uint32_t bitfield_bit_offset) const;
773
774   //------------------------------------------------------------------
775   /// Extract an pointer from \a *offset_ptr.
776   ///
777   /// Extract a single pointer from the data and update the offset
778   /// pointed to by \a offset_ptr. The size of the extracted pointer
779   /// comes from the \a m_addr_size member variable and should be
780   /// set correctly prior to extracting any pointer values.
781   ///
782   /// @param[in,out] offset_ptr
783   ///     A pointer to an offset within the data that will be advanced
784   ///     by the appropriate number of bytes if the value is extracted
785   ///     correctly. If the offset is out of bounds or there are not
786   ///     enough bytes to extract this value, the offset will be left
787   ///     unmodified.
788   ///
789   /// @return
790   ///     The extracted pointer value as a 64 integer.
791   //------------------------------------------------------------------
792   uint64_t GetPointer(lldb::offset_t *offset_ptr) const;
793
794   //------------------------------------------------------------------
795   /// Get the current byte order value.
796   ///
797   /// @return
798   ///     The current byte order value from this object's internal
799   ///     state.
800   //------------------------------------------------------------------
801   lldb::ByteOrder GetByteOrder() const { return m_byte_order; }
802
803   //------------------------------------------------------------------
804   /// Extract a uint8_t value from \a *offset_ptr.
805   ///
806   /// Extract a single uint8_t from the binary data at the offset
807   /// pointed to by \a offset_ptr, and advance the offset on success.
808   ///
809   /// @param[in,out] offset_ptr
810   ///     A pointer to an offset within the data that will be advanced
811   ///     by the appropriate number of bytes if the value is extracted
812   ///     correctly. If the offset is out of bounds or there are not
813   ///     enough bytes to extract this value, the offset will be left
814   ///     unmodified.
815   ///
816   /// @return
817   ///     The extracted uint8_t value.
818   //------------------------------------------------------------------
819   uint8_t GetU8(lldb::offset_t *offset_ptr) const;
820
821   uint8_t GetU8_unchecked(lldb::offset_t *offset_ptr) const {
822     uint8_t val = m_start[*offset_ptr];
823     *offset_ptr += 1;
824     return val;
825   }
826
827   uint16_t GetU16_unchecked(lldb::offset_t *offset_ptr) const;
828
829   uint32_t GetU32_unchecked(lldb::offset_t *offset_ptr) const;
830
831   uint64_t GetU64_unchecked(lldb::offset_t *offset_ptr) const;
832   //------------------------------------------------------------------
833   /// Extract \a count uint8_t values from \a *offset_ptr.
834   ///
835   /// Extract \a count uint8_t values from the binary data at the
836   /// offset pointed to by \a offset_ptr, and advance the offset on
837   /// success. The extracted values are copied into \a dst.
838   ///
839   /// @param[in,out] offset_ptr
840   ///     A pointer to an offset within the data that will be advanced
841   ///     by the appropriate number of bytes if the value is extracted
842   ///     correctly. If the offset is out of bounds or there are not
843   ///     enough bytes to extract this value, the offset will be left
844   ///     unmodified.
845   ///
846   /// @param[out] dst
847   ///     A buffer to copy \a count uint8_t values into. \a dst must
848   ///     be large enough to hold all requested data.
849   ///
850   /// @param[in] count
851   ///     The number of uint8_t values to extract.
852   ///
853   /// @return
854   ///     \a dst if all values were properly extracted and copied,
855   ///     nullptr otherwise.
856   //------------------------------------------------------------------
857   void *GetU8(lldb::offset_t *offset_ptr, void *dst, uint32_t count) const;
858
859   //------------------------------------------------------------------
860   /// Extract a uint16_t value from \a *offset_ptr.
861   ///
862   /// Extract a single uint16_t from the binary data at the offset
863   /// pointed to by \a offset_ptr, and update the offset on success.
864   ///
865   /// @param[in,out] offset_ptr
866   ///     A pointer to an offset within the data that will be advanced
867   ///     by the appropriate number of bytes if the value is extracted
868   ///     correctly. If the offset is out of bounds or there are not
869   ///     enough bytes to extract this value, the offset will be left
870   ///     unmodified.
871   ///
872   /// @return
873   ///     The extracted uint16_t value.
874   //------------------------------------------------------------------
875   uint16_t GetU16(lldb::offset_t *offset_ptr) const;
876
877   //------------------------------------------------------------------
878   /// Extract \a count uint16_t values from \a *offset_ptr.
879   ///
880   /// Extract \a count uint16_t values from the binary data at the
881   /// offset pointed to by \a offset_ptr, and advance the offset on
882   /// success. The extracted values are copied into \a dst.
883   ///
884   /// @param[in,out] offset_ptr
885   ///     A pointer to an offset within the data that will be advanced
886   ///     by the appropriate number of bytes if the value is extracted
887   ///     correctly. If the offset is out of bounds or there are not
888   ///     enough bytes to extract this value, the offset will be left
889   ///     unmodified.
890   ///
891   /// @param[out] dst
892   ///     A buffer to copy \a count uint16_t values into. \a dst must
893   ///     be large enough to hold all requested data.
894   ///
895   /// @param[in] count
896   ///     The number of uint16_t values to extract.
897   ///
898   /// @return
899   ///     \a dst if all values were properly extracted and copied,
900   ///     nullptr otherwise.
901   //------------------------------------------------------------------
902   void *GetU16(lldb::offset_t *offset_ptr, void *dst, uint32_t count) const;
903
904   //------------------------------------------------------------------
905   /// Extract a uint32_t value from \a *offset_ptr.
906   ///
907   /// Extract a single uint32_t from the binary data at the offset
908   /// pointed to by \a offset_ptr, and update the offset on success.
909   ///
910   /// @param[in,out] offset_ptr
911   ///     A pointer to an offset within the data that will be advanced
912   ///     by the appropriate number of bytes if the value is extracted
913   ///     correctly. If the offset is out of bounds or there are not
914   ///     enough bytes to extract this value, the offset will be left
915   ///     unmodified.
916   ///
917   /// @return
918   ///     The extracted uint32_t value.
919   //------------------------------------------------------------------
920   uint32_t GetU32(lldb::offset_t *offset_ptr) const;
921
922   //------------------------------------------------------------------
923   /// Extract \a count uint32_t values from \a *offset_ptr.
924   ///
925   /// Extract \a count uint32_t values from the binary data at the
926   /// offset pointed to by \a offset_ptr, and advance the offset on
927   /// success. The extracted values are copied into \a dst.
928   ///
929   /// @param[in,out] offset_ptr
930   ///     A pointer to an offset within the data that will be advanced
931   ///     by the appropriate number of bytes if the value is extracted
932   ///     correctly. If the offset is out of bounds or there are not
933   ///     enough bytes to extract this value, the offset will be left
934   ///     unmodified.
935   ///
936   /// @param[out] dst
937   ///     A buffer to copy \a count uint32_t values into. \a dst must
938   ///     be large enough to hold all requested data.
939   ///
940   /// @param[in] count
941   ///     The number of uint32_t values to extract.
942   ///
943   /// @return
944   ///     \a dst if all values were properly extracted and copied,
945   ///     nullptr otherwise.
946   //------------------------------------------------------------------
947   void *GetU32(lldb::offset_t *offset_ptr, void *dst, uint32_t count) const;
948
949   //------------------------------------------------------------------
950   /// Extract a uint64_t value from \a *offset_ptr.
951   ///
952   /// Extract a single uint64_t from the binary data at the offset
953   /// pointed to by \a offset_ptr, and update the offset on success.
954   ///
955   /// @param[in,out] offset_ptr
956   ///     A pointer to an offset within the data that will be advanced
957   ///     by the appropriate number of bytes if the value is extracted
958   ///     correctly. If the offset is out of bounds or there are not
959   ///     enough bytes to extract this value, the offset will be left
960   ///     unmodified.
961   ///
962   /// @return
963   ///     The extracted uint64_t value.
964   //------------------------------------------------------------------
965   uint64_t GetU64(lldb::offset_t *offset_ptr) const;
966
967   //------------------------------------------------------------------
968   /// Extract \a count uint64_t values from \a *offset_ptr.
969   ///
970   /// Extract \a count uint64_t values from the binary data at the
971   /// offset pointed to by \a offset_ptr, and advance the offset on
972   /// success. The extracted values are copied into \a dst.
973   ///
974   /// @param[in,out] offset_ptr
975   ///     A pointer to an offset within the data that will be advanced
976   ///     by the appropriate number of bytes if the value is extracted
977   ///     correctly. If the offset is out of bounds or there are not
978   ///     enough bytes to extract this value, the offset will be left
979   ///     unmodified.
980   ///
981   /// @param[out] dst
982   ///     A buffer to copy \a count uint64_t values into. \a dst must
983   ///     be large enough to hold all requested data.
984   ///
985   /// @param[in] count
986   ///     The number of uint64_t values to extract.
987   ///
988   /// @return
989   ///     \a dst if all values were properly extracted and copied,
990   ///     nullptr otherwise.
991   //------------------------------------------------------------------
992   void *GetU64(lldb::offset_t *offset_ptr, void *dst, uint32_t count) const;
993
994   //------------------------------------------------------------------
995   /// Extract a signed LEB128 value from \a *offset_ptr.
996   ///
997   /// Extracts an signed LEB128 number from this object's data
998   /// starting at the offset pointed to by \a offset_ptr. The offset
999   /// pointed to by \a offset_ptr will be updated with the offset of
1000   /// the byte following the last extracted byte.
1001   ///
1002   /// @param[in,out] offset_ptr
1003   ///     A pointer to an offset within the data that will be advanced
1004   ///     by the appropriate number of bytes if the value is extracted
1005   ///     correctly. If the offset is out of bounds or there are not
1006   ///     enough bytes to extract this value, the offset will be left
1007   ///     unmodified.
1008   ///
1009   /// @return
1010   ///     The extracted signed integer value.
1011   //------------------------------------------------------------------
1012   int64_t GetSLEB128(lldb::offset_t *offset_ptr) const;
1013
1014   //------------------------------------------------------------------
1015   /// Extract a unsigned LEB128 value from \a *offset_ptr.
1016   ///
1017   /// Extracts an unsigned LEB128 number from this object's data
1018   /// starting at the offset pointed to by \a offset_ptr. The offset
1019   /// pointed to by \a offset_ptr will be updated with the offset of
1020   /// the byte following the last extracted byte.
1021   ///
1022   /// @param[in,out] offset_ptr
1023   ///     A pointer to an offset within the data that will be advanced
1024   ///     by the appropriate number of bytes if the value is extracted
1025   ///     correctly. If the offset is out of bounds or there are not
1026   ///     enough bytes to extract this value, the offset will be left
1027   ///     unmodified.
1028   ///
1029   /// @return
1030   ///     The extracted unsigned integer value.
1031   //------------------------------------------------------------------
1032   uint64_t GetULEB128(lldb::offset_t *offset_ptr) const;
1033
1034   lldb::DataBufferSP &GetSharedDataBuffer() { return m_data_sp; }
1035
1036   //------------------------------------------------------------------
1037   /// Peek at a C string at \a offset.
1038   ///
1039   /// Peeks at a string in the contained data. No verification is done
1040   /// to make sure the entire string lies within the bounds of this
1041   /// object's data, only \a offset is verified to be a valid offset.
1042   ///
1043   /// @param[in] offset
1044   ///     An offset into the data.
1045   ///
1046   /// @return
1047   ///     A non-nullptr C string pointer if \a offset is a valid offset,
1048   ///     nullptr otherwise.
1049   //------------------------------------------------------------------
1050   const char *PeekCStr(lldb::offset_t offset) const;
1051
1052   //------------------------------------------------------------------
1053   /// Peek at a bytes at \a offset.
1054   ///
1055   /// Returns a pointer to \a length bytes at \a offset as long as
1056   /// there are \a length bytes available starting at \a offset.
1057   ///
1058   /// @return
1059   ///     A non-nullptr data pointer if \a offset is a valid offset and
1060   ///     there are \a length bytes available at that offset, nullptr
1061   ///     otherwise.
1062   //------------------------------------------------------------------
1063   const uint8_t *PeekData(lldb::offset_t offset, lldb::offset_t length) const {
1064     if (ValidOffsetForDataOfSize(offset, length))
1065       return m_start + offset;
1066     return nullptr;
1067   }
1068
1069   //------------------------------------------------------------------
1070   /// Set the address byte size.
1071   ///
1072   /// Set the size in bytes that will be used when extracting any
1073   /// address and pointer values from data contained in this object.
1074   ///
1075   /// @param[in] addr_size
1076   ///     The size in bytes to use when extracting addresses.
1077   //------------------------------------------------------------------
1078   void SetAddressByteSize(uint32_t addr_size) {
1079 #ifdef LLDB_CONFIGURATION_DEBUG
1080     assert(addr_size == 4 || addr_size == 8);
1081 #endif
1082     m_addr_size = addr_size;
1083   }
1084
1085   //------------------------------------------------------------------
1086   /// Set data with a buffer that is caller owned.
1087   ///
1088   /// Use data that is owned by the caller when extracting values.
1089   /// The data must stay around as long as this object, or any object
1090   /// that copies a subset of this object's data, is valid. If \a
1091   /// bytes is nullptr, or \a length is zero, this object will contain
1092   /// no data.
1093   ///
1094   /// @param[in] bytes
1095   ///     A pointer to caller owned data.
1096   ///
1097   /// @param[in] length
1098   ///     The length in bytes of \a bytes.
1099   ///
1100   /// @param[in] byte_order
1101   ///     A byte order of the data that we are extracting from.
1102   ///
1103   /// @return
1104   ///     The number of bytes that this object now contains.
1105   //------------------------------------------------------------------
1106   lldb::offset_t SetData(const void *bytes, lldb::offset_t length,
1107                          lldb::ByteOrder byte_order);
1108
1109   //------------------------------------------------------------------
1110   /// Adopt a subset of \a data.
1111   ///
1112   /// Set this object's data to be a subset of the data bytes in \a
1113   /// data. If \a data contains shared data, then a reference to the
1114   /// shared data will be added to ensure the shared data stays around
1115   /// as long as any objects have references to the shared data. The
1116   /// byte order and the address size settings are copied from \a
1117   /// data. If \a offset is not a valid offset in \a data, then no
1118   /// reference to the shared data will be added. If there are not
1119   /// \a length bytes available in \a data starting at \a offset,
1120   /// the length will be truncated to contains as many bytes as
1121   /// possible.
1122   ///
1123   /// @param[in] data
1124   ///     Another DataExtractor object that contains data.
1125   ///
1126   /// @param[in] offset
1127   ///     The offset into \a data at which the subset starts.
1128   ///
1129   /// @param[in] length
1130   ///     The length in bytes of the subset of \a data.
1131   ///
1132   /// @return
1133   ///     The number of bytes that this object now contains.
1134   //------------------------------------------------------------------
1135   lldb::offset_t SetData(const DataExtractor &data, lldb::offset_t offset,
1136                          lldb::offset_t length);
1137
1138   //------------------------------------------------------------------
1139   /// Adopt a subset of shared data in \a data_sp.
1140   ///
1141   /// Copies the data shared pointer which adds a reference to the
1142   /// contained in \a data_sp. The shared data reference is reference
1143   /// counted to ensure the data lives as long as anyone still has a
1144   /// valid shared pointer to the data in \a data_sp. The byte order
1145   /// and address byte size settings remain the same. If
1146   /// \a offset is not a valid offset in \a data_sp, then no reference
1147   /// to the shared data will be added. If there are not \a length
1148   /// bytes available in \a data starting at \a offset, the length
1149   /// will be truncated to contains as many bytes as possible.
1150   ///
1151   /// @param[in] data_sp
1152   ///     A shared pointer to data.
1153   ///
1154   /// @param[in] offset
1155   ///     The offset into \a data_sp at which the subset starts.
1156   ///
1157   /// @param[in] length
1158   ///     The length in bytes of the subset of \a data_sp.
1159   ///
1160   /// @return
1161   ///     The number of bytes that this object now contains.
1162   //------------------------------------------------------------------
1163   lldb::offset_t SetData(const lldb::DataBufferSP &data_sp,
1164                          lldb::offset_t offset = 0,
1165                          lldb::offset_t length = LLDB_INVALID_OFFSET);
1166
1167   //------------------------------------------------------------------
1168   /// Set the byte_order value.
1169   ///
1170   /// Sets the byte order of the data to extract. Extracted values
1171   /// will be swapped if necessary when decoding.
1172   ///
1173   /// @param[in] byte_order
1174   ///     The byte order value to use when extracting data.
1175   //------------------------------------------------------------------
1176   void SetByteOrder(lldb::ByteOrder byte_order) { m_byte_order = byte_order; }
1177
1178   //------------------------------------------------------------------
1179   /// Skip an LEB128 number at \a *offset_ptr.
1180   ///
1181   /// Skips a LEB128 number (signed or unsigned) from this object's
1182   /// data starting at the offset pointed to by \a offset_ptr. The
1183   /// offset pointed to by \a offset_ptr will be updated with the
1184   /// offset of the byte following the last extracted byte.
1185   ///
1186   /// @param[in,out] offset_ptr
1187   ///     A pointer to an offset within the data that will be advanced
1188   ///     by the appropriate number of bytes if the value is extracted
1189   ///     correctly. If the offset is out of bounds or there are not
1190   ///     enough bytes to extract this value, the offset will be left
1191   ///     unmodified.
1192   ///
1193   /// @return
1194   //      The number of bytes consumed during the extraction.
1195   //------------------------------------------------------------------
1196   uint32_t Skip_LEB128(lldb::offset_t *offset_ptr) const;
1197
1198   //------------------------------------------------------------------
1199   /// Test the validity of \a offset.
1200   ///
1201   /// @return
1202   ///     \b true if \a offset is a valid offset into the data in this
1203   ///     object, \b false otherwise.
1204   //------------------------------------------------------------------
1205   bool ValidOffset(lldb::offset_t offset) const {
1206     return offset < GetByteSize();
1207   }
1208
1209   //------------------------------------------------------------------
1210   /// Test the availability of \a length bytes of data from \a offset.
1211   ///
1212   /// @return
1213   ///     \b true if \a offset is a valid offset and there are \a
1214   ///     length bytes available at that offset, \b false otherwise.
1215   //------------------------------------------------------------------
1216   bool ValidOffsetForDataOfSize(lldb::offset_t offset,
1217                                 lldb::offset_t length) const {
1218     return length <= BytesLeft(offset);
1219   }
1220
1221   size_t Copy(DataExtractor &dest_data) const;
1222
1223   bool Append(DataExtractor &rhs);
1224
1225   bool Append(void *bytes, lldb::offset_t length);
1226
1227   lldb::offset_t BytesLeft(lldb::offset_t offset) const {
1228     const lldb::offset_t size = GetByteSize();
1229     if (size > offset)
1230       return size - offset;
1231     return 0;
1232   }
1233
1234   void Checksum(llvm::SmallVectorImpl<uint8_t> &dest, uint64_t max_data = 0);
1235
1236 protected:
1237   //------------------------------------------------------------------
1238   // Member variables
1239   //------------------------------------------------------------------
1240   const uint8_t *m_start; ///< A pointer to the first byte of data.
1241   const uint8_t
1242       *m_end; ///< A pointer to the byte that is past the end of the data.
1243   lldb::ByteOrder
1244       m_byte_order;     ///< The byte order of the data we are extracting from.
1245   uint32_t m_addr_size; ///< The address size to use when extracting pointers or
1246                         ///addresses
1247   mutable lldb::DataBufferSP m_data_sp; ///< The shared pointer to data that can
1248                                         ///be shared among multiple instances
1249   const uint32_t m_target_byte_size;
1250 };
1251
1252 } // namespace lldb_private
1253
1254 #endif // liblldb_DataExtractor_h_