LLDB  mainline
DataExtractor.cpp
Go to the documentation of this file.
1 //===-- DataExtractor.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "lldb/lldb-defines.h"
12 #include "lldb/lldb-enumerations.h"
13 #include "lldb/lldb-forward.h"
14 #include "lldb/lldb-types.h"
15 
19 #include "lldb/Utility/Log.h"
20 #include "lldb/Utility/Stream.h"
22 #include "lldb/Utility/UUID.h"
23 
24 #include "llvm/ADT/ArrayRef.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/Support/LEB128.h"
27 #include "llvm/Support/MD5.h"
28 #include "llvm/Support/MathExtras.h"
29 
30 #include <algorithm>
31 #include <array>
32 #include <cassert>
33 #include <cstdint>
34 #include <string>
35 
36 #include <cctype>
37 #include <cinttypes>
38 #include <cstring>
39 
40 using namespace lldb;
41 using namespace lldb_private;
42 
43 static inline uint16_t ReadInt16(const unsigned char *ptr, offset_t offset) {
44  uint16_t value;
45  memcpy(&value, ptr + offset, 2);
46  return value;
47 }
48 
49 static inline uint32_t ReadInt32(const unsigned char *ptr,
50  offset_t offset = 0) {
51  uint32_t value;
52  memcpy(&value, ptr + offset, 4);
53  return value;
54 }
55 
56 static inline uint64_t ReadInt64(const unsigned char *ptr,
57  offset_t offset = 0) {
58  uint64_t value;
59  memcpy(&value, ptr + offset, 8);
60  return value;
61 }
62 
63 static inline uint16_t ReadInt16(const void *ptr) {
64  uint16_t value;
65  memcpy(&value, ptr, 2);
66  return value;
67 }
68 
69 static inline uint16_t ReadSwapInt16(const unsigned char *ptr,
70  offset_t offset) {
71  uint16_t value;
72  memcpy(&value, ptr + offset, 2);
73  return llvm::ByteSwap_16(value);
74 }
75 
76 static inline uint32_t ReadSwapInt32(const unsigned char *ptr,
77  offset_t offset) {
78  uint32_t value;
79  memcpy(&value, ptr + offset, 4);
80  return llvm::ByteSwap_32(value);
81 }
82 
83 static inline uint64_t ReadSwapInt64(const unsigned char *ptr,
84  offset_t offset) {
85  uint64_t value;
86  memcpy(&value, ptr + offset, 8);
87  return llvm::ByteSwap_64(value);
88 }
89 
90 static inline uint16_t ReadSwapInt16(const void *ptr) {
91  uint16_t value;
92  memcpy(&value, ptr, 2);
93  return llvm::ByteSwap_16(value);
94 }
95 
96 static inline uint32_t ReadSwapInt32(const void *ptr) {
97  uint32_t value;
98  memcpy(&value, ptr, 4);
99  return llvm::ByteSwap_32(value);
100 }
101 
102 static inline uint64_t ReadSwapInt64(const void *ptr) {
103  uint64_t value;
104  memcpy(&value, ptr, 8);
105  return llvm::ByteSwap_64(value);
106 }
107 
108 static inline uint64_t ReadMaxInt64(const uint8_t *data, size_t byte_size,
109  ByteOrder byte_order) {
110  uint64_t res = 0;
111  if (byte_order == eByteOrderBig)
112  for (size_t i = 0; i < byte_size; ++i)
113  res = (res << 8) | data[i];
114  else {
115  assert(byte_order == eByteOrderLittle);
116  for (size_t i = 0; i < byte_size; ++i)
117  res = (res << 8) | data[byte_size - 1 - i];
118  }
119  return res;
120 }
121 
122 DataExtractor::DataExtractor()
123  : m_start(nullptr), m_end(nullptr),
124  m_byte_order(endian::InlHostByteOrder()), m_addr_size(sizeof(void *)),
125  m_data_sp(), m_target_byte_size(1) {}
126 
127 // This constructor allows us to use data that is owned by someone else. The
128 // data must stay around as long as this object is valid.
129 DataExtractor::DataExtractor(const void *data, offset_t length,
130  ByteOrder endian, uint32_t addr_size,
131  uint32_t target_byte_size /*=1*/)
132  : m_start(const_cast<uint8_t *>(static_cast<const uint8_t *>(data))),
133  m_end(const_cast<uint8_t *>(static_cast<const uint8_t *>(data)) + length),
134  m_byte_order(endian), m_addr_size(addr_size), m_data_sp(),
135  m_target_byte_size(target_byte_size) {
136  assert(addr_size >= 1 && addr_size <= 8);
137 }
138 
139 // Make a shared pointer reference to the shared data in "data_sp" and set the
140 // endian swapping setting to "swap", and the address size to "addr_size". The
141 // shared data reference will ensure the data lives as long as any
142 // DataExtractor objects exist that have a reference to this data.
143 DataExtractor::DataExtractor(const DataBufferSP &data_sp, ByteOrder endian,
144  uint32_t addr_size,
145  uint32_t target_byte_size /*=1*/)
146  : m_start(nullptr), m_end(nullptr), m_byte_order(endian),
147  m_addr_size(addr_size), m_data_sp(),
148  m_target_byte_size(target_byte_size) {
149  assert(addr_size >= 1 && addr_size <= 8);
150  SetData(data_sp);
151 }
152 
153 // Initialize this object with a subset of the data bytes in "data". If "data"
154 // contains shared data, then a reference to this shared data will added and
155 // the shared data will stay around as long as any object contains a reference
156 // to that data. The endian swap and address size settings are copied from
157 // "data".
159  offset_t length, uint32_t target_byte_size /*=1*/)
160  : m_start(nullptr), m_end(nullptr), m_byte_order(data.m_byte_order),
161  m_addr_size(data.m_addr_size), m_data_sp(),
162  m_target_byte_size(target_byte_size) {
163  assert(m_addr_size >= 1 && m_addr_size <= 8);
164  if (data.ValidOffset(offset)) {
165  offset_t bytes_available = data.GetByteSize() - offset;
166  if (length > bytes_available)
167  length = bytes_available;
168  SetData(data, offset, length);
169  }
170 }
171 
173  : m_start(rhs.m_start), m_end(rhs.m_end), m_byte_order(rhs.m_byte_order),
174  m_addr_size(rhs.m_addr_size), m_data_sp(rhs.m_data_sp),
175  m_target_byte_size(rhs.m_target_byte_size) {
176  assert(m_addr_size >= 1 && m_addr_size <= 8);
177 }
178 
179 // Assignment operator
181  if (this != &rhs) {
182  m_start = rhs.m_start;
183  m_end = rhs.m_end;
185  m_addr_size = rhs.m_addr_size;
186  m_data_sp = rhs.m_data_sp;
187  }
188  return *this;
189 }
190 
192 
193 // Clears the object contents back to a default invalid state, and release any
194 // references to shared data that this object may contain.
196  m_start = nullptr;
197  m_end = nullptr;
199  m_addr_size = sizeof(void *);
200  m_data_sp.reset();
201 }
202 
203 // If this object contains shared data, this function returns the offset into
204 // that shared data. Else zero is returned.
206  if (m_start != nullptr) {
207  const DataBuffer *data = m_data_sp.get();
208  if (data != nullptr) {
209  const uint8_t *data_bytes = data->GetBytes();
210  if (data_bytes != nullptr) {
211  assert(m_start >= data_bytes);
212  return m_start - data_bytes;
213  }
214  }
215  }
216  return 0;
217 }
218 
219 // Set the data with which this object will extract from to data starting at
220 // BYTES and set the length of the data to LENGTH bytes long. The data is
221 // externally owned must be around at least as long as this object points to
222 // the data. No copy of the data is made, this object just refers to this data
223 // and can extract from it. If this object refers to any shared data upon
224 // entry, the reference to that data will be released. Is SWAP is set to true,
225 // any data extracted will be endian swapped.
227  ByteOrder endian) {
228  m_byte_order = endian;
229  m_data_sp.reset();
230  if (bytes == nullptr || length == 0) {
231  m_start = nullptr;
232  m_end = nullptr;
233  } else {
234  m_start = const_cast<uint8_t *>(static_cast<const uint8_t *>(bytes));
235  m_end = m_start + length;
236  }
237  return GetByteSize();
238 }
239 
240 // Assign the data for this object to be a subrange in "data" starting
241 // "data_offset" bytes into "data" and ending "data_length" bytes later. If
242 // "data_offset" is not a valid offset into "data", then this object will
243 // contain no bytes. If "data_offset" is within "data" yet "data_length" is too
244 // large, the length will be capped at the number of bytes remaining in "data".
245 // If "data" contains a shared pointer to other data, then a ref counted
246 // pointer to that data will be made in this object. If "data" doesn't contain
247 // a shared pointer to data, then the bytes referred to in "data" will need to
248 // exist at least as long as this object refers to those bytes. The address
249 // size and endian swap settings are copied from the current values in "data".
251  offset_t data_offset,
252  offset_t data_length) {
253  m_addr_size = data.m_addr_size;
254  assert(m_addr_size >= 1 && m_addr_size <= 8);
255  // If "data" contains shared pointer to data, then we can use that
256  if (data.m_data_sp) {
257  m_byte_order = data.m_byte_order;
258  return SetData(data.m_data_sp, data.GetSharedDataOffset() + data_offset,
259  data_length);
260  }
261 
262  // We have a DataExtractor object that just has a pointer to bytes
263  if (data.ValidOffset(data_offset)) {
264  if (data_length > data.GetByteSize() - data_offset)
265  data_length = data.GetByteSize() - data_offset;
266  return SetData(data.GetDataStart() + data_offset, data_length,
267  data.GetByteOrder());
268  }
269  return 0;
270 }
271 
272 // Assign the data for this object to be a subrange of the shared data in
273 // "data_sp" starting "data_offset" bytes into "data_sp" and ending
274 // "data_length" bytes later. If "data_offset" is not a valid offset into
275 // "data_sp", then this object will contain no bytes. If "data_offset" is
276 // within "data_sp" yet "data_length" is too large, the length will be capped
277 // at the number of bytes remaining in "data_sp". A ref counted pointer to the
278 // data in "data_sp" will be made in this object IF the number of bytes this
279 // object refers to in greater than zero (if at least one byte was available
280 // starting at "data_offset") to ensure the data stays around as long as it is
281 // needed. The address size and endian swap settings will remain unchanged from
282 // their current settings.
283 lldb::offset_t DataExtractor::SetData(const DataBufferSP &data_sp,
284  offset_t data_offset,
285  offset_t data_length) {
286  m_start = m_end = nullptr;
287 
288  if (data_length > 0) {
289  m_data_sp = data_sp;
290  if (data_sp) {
291  const size_t data_size = data_sp->GetByteSize();
292  if (data_offset < data_size) {
293  m_start = data_sp->GetBytes() + data_offset;
294  const size_t bytes_left = data_size - data_offset;
295  // Cap the length of we asked for too many
296  if (data_length <= bytes_left)
297  m_end = m_start + data_length; // We got all the bytes we wanted
298  else
299  m_end = m_start + bytes_left; // Not all the bytes requested were
300  // available in the shared data
301  }
302  }
303  }
304 
305  size_t new_size = GetByteSize();
306 
307  // Don't hold a shared pointer to the data buffer if we don't share any valid
308  // bytes in the shared buffer.
309  if (new_size == 0)
310  m_data_sp.reset();
311 
312  return new_size;
313 }
314 
315 // Extract a single unsigned char from the binary data and update the offset
316 // pointed to by "offset_ptr".
317 //
318 // RETURNS the byte that was extracted, or zero on failure.
319 uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const {
320  const uint8_t *data = static_cast<const uint8_t *>(GetData(offset_ptr, 1));
321  if (data)
322  return *data;
323  return 0;
324 }
325 
326 // Extract "count" unsigned chars from the binary data and update the offset
327 // pointed to by "offset_ptr". The extracted data is copied into "dst".
328 //
329 // RETURNS the non-nullptr buffer pointer upon successful extraction of
330 // all the requested bytes, or nullptr when the data is not available in the
331 // buffer due to being out of bounds, or insufficient data.
332 void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst,
333  uint32_t count) const {
334  const uint8_t *data =
335  static_cast<const uint8_t *>(GetData(offset_ptr, count));
336  if (data) {
337  // Copy the data into the buffer
338  memcpy(dst, data, count);
339  // Return a non-nullptr pointer to the converted data as an indicator of
340  // success
341  return dst;
342  }
343  return nullptr;
344 }
345 
346 // Extract a single uint16_t from the data and update the offset pointed to by
347 // "offset_ptr".
348 //
349 // RETURNS the uint16_t that was extracted, or zero on failure.
351  uint16_t val = 0;
352  const uint8_t *data =
353  static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val)));
354  if (data) {
356  val = ReadSwapInt16(data);
357  else
358  val = ReadInt16(data);
359  }
360  return val;
361 }
362 
364  uint16_t val;
366  val = ReadInt16(m_start, *offset_ptr);
367  else
368  val = ReadSwapInt16(m_start, *offset_ptr);
369  *offset_ptr += sizeof(val);
370  return val;
371 }
372 
374  uint32_t val;
376  val = ReadInt32(m_start, *offset_ptr);
377  else
378  val = ReadSwapInt32(m_start, *offset_ptr);
379  *offset_ptr += sizeof(val);
380  return val;
381 }
382 
383 uint64_t DataExtractor::GetU64_unchecked(offset_t *offset_ptr) const {
384  uint64_t val;
386  val = ReadInt64(m_start, *offset_ptr);
387  else
388  val = ReadSwapInt64(m_start, *offset_ptr);
389  *offset_ptr += sizeof(val);
390  return val;
391 }
392 
393 // Extract "count" uint16_t values from the binary data and update the offset
394 // pointed to by "offset_ptr". The extracted data is copied into "dst".
395 //
396 // RETURNS the non-nullptr buffer pointer upon successful extraction of
397 // all the requested bytes, or nullptr when the data is not available in the
398 // buffer due to being out of bounds, or insufficient data.
399 void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst,
400  uint32_t count) const {
401  const size_t src_size = sizeof(uint16_t) * count;
402  const uint16_t *src =
403  static_cast<const uint16_t *>(GetData(offset_ptr, src_size));
404  if (src) {
406  uint16_t *dst_pos = static_cast<uint16_t *>(void_dst);
407  uint16_t *dst_end = dst_pos + count;
408  const uint16_t *src_pos = src;
409  while (dst_pos < dst_end) {
410  *dst_pos = ReadSwapInt16(src_pos);
411  ++dst_pos;
412  ++src_pos;
413  }
414  } else {
415  memcpy(void_dst, src, src_size);
416  }
417  // Return a non-nullptr pointer to the converted data as an indicator of
418  // success
419  return void_dst;
420  }
421  return nullptr;
422 }
423 
424 // Extract a single uint32_t from the data and update the offset pointed to by
425 // "offset_ptr".
426 //
427 // RETURNS the uint32_t that was extracted, or zero on failure.
429  uint32_t val = 0;
430  const uint8_t *data =
431  static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val)));
432  if (data) {
434  val = ReadSwapInt32(data);
435  } else {
436  memcpy(&val, data, 4);
437  }
438  }
439  return val;
440 }
441 
442 // Extract "count" uint32_t values from the binary data and update the offset
443 // pointed to by "offset_ptr". The extracted data is copied into "dst".
444 //
445 // RETURNS the non-nullptr buffer pointer upon successful extraction of
446 // all the requested bytes, or nullptr when the data is not available in the
447 // buffer due to being out of bounds, or insufficient data.
448 void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst,
449  uint32_t count) const {
450  const size_t src_size = sizeof(uint32_t) * count;
451  const uint32_t *src =
452  static_cast<const uint32_t *>(GetData(offset_ptr, src_size));
453  if (src) {
455  uint32_t *dst_pos = static_cast<uint32_t *>(void_dst);
456  uint32_t *dst_end = dst_pos + count;
457  const uint32_t *src_pos = src;
458  while (dst_pos < dst_end) {
459  *dst_pos = ReadSwapInt32(src_pos);
460  ++dst_pos;
461  ++src_pos;
462  }
463  } else {
464  memcpy(void_dst, src, src_size);
465  }
466  // Return a non-nullptr pointer to the converted data as an indicator of
467  // success
468  return void_dst;
469  }
470  return nullptr;
471 }
472 
473 // Extract a single uint64_t from the data and update the offset pointed to by
474 // "offset_ptr".
475 //
476 // RETURNS the uint64_t that was extracted, or zero on failure.
477 uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const {
478  uint64_t val = 0;
479  const uint8_t *data =
480  static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val)));
481  if (data) {
483  val = ReadSwapInt64(data);
484  } else {
485  memcpy(&val, data, 8);
486  }
487  }
488  return val;
489 }
490 
491 // GetU64
492 //
493 // Get multiple consecutive 64 bit values. Return true if the entire read
494 // succeeds and increment the offset pointed to by offset_ptr, else return
495 // false and leave the offset pointed to by offset_ptr unchanged.
496 void *DataExtractor::GetU64(offset_t *offset_ptr, void *void_dst,
497  uint32_t count) const {
498  const size_t src_size = sizeof(uint64_t) * count;
499  const uint64_t *src =
500  static_cast<const uint64_t *>(GetData(offset_ptr, src_size));
501  if (src) {
503  uint64_t *dst_pos = static_cast<uint64_t *>(void_dst);
504  uint64_t *dst_end = dst_pos + count;
505  const uint64_t *src_pos = src;
506  while (dst_pos < dst_end) {
507  *dst_pos = ReadSwapInt64(src_pos);
508  ++dst_pos;
509  ++src_pos;
510  }
511  } else {
512  memcpy(void_dst, src, src_size);
513  }
514  // Return a non-nullptr pointer to the converted data as an indicator of
515  // success
516  return void_dst;
517  }
518  return nullptr;
519 }
520 
522  size_t byte_size) const {
523  lldbassert(byte_size > 0 && byte_size <= 4 && "GetMaxU32 invalid byte_size!");
524  return GetMaxU64(offset_ptr, byte_size);
525 }
526 
527 uint64_t DataExtractor::GetMaxU64(offset_t *offset_ptr,
528  size_t byte_size) const {
529  lldbassert(byte_size > 0 && byte_size <= 8 && "GetMaxU64 invalid byte_size!");
530  switch (byte_size) {
531  case 1:
532  return GetU8(offset_ptr);
533  case 2:
534  return GetU16(offset_ptr);
535  case 4:
536  return GetU32(offset_ptr);
537  case 8:
538  return GetU64(offset_ptr);
539  default: {
540  // General case.
541  const uint8_t *data =
542  static_cast<const uint8_t *>(GetData(offset_ptr, byte_size));
543  if (data == nullptr)
544  return 0;
545  return ReadMaxInt64(data, byte_size, m_byte_order);
546  }
547  }
548  return 0;
549 }
550 
552  size_t byte_size) const {
553  switch (byte_size) {
554  case 1:
555  return GetU8_unchecked(offset_ptr);
556  case 2:
557  return GetU16_unchecked(offset_ptr);
558  case 4:
559  return GetU32_unchecked(offset_ptr);
560  case 8:
561  return GetU64_unchecked(offset_ptr);
562  default: {
563  uint64_t res = ReadMaxInt64(&m_start[*offset_ptr], byte_size, m_byte_order);
564  *offset_ptr += byte_size;
565  return res;
566  }
567  }
568  return 0;
569 }
570 
571 int64_t DataExtractor::GetMaxS64(offset_t *offset_ptr, size_t byte_size) const {
572  uint64_t u64 = GetMaxU64(offset_ptr, byte_size);
573  return llvm::SignExtend64(u64, 8 * byte_size);
574 }
575 
576 uint64_t DataExtractor::GetMaxU64Bitfield(offset_t *offset_ptr, size_t size,
577  uint32_t bitfield_bit_size,
578  uint32_t bitfield_bit_offset) const {
579  assert(bitfield_bit_size <= 64);
580  uint64_t uval64 = GetMaxU64(offset_ptr, size);
581 
582  if (bitfield_bit_size == 0)
583  return uval64;
584 
585  int32_t lsbcount = bitfield_bit_offset;
587  lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size;
588 
589  if (lsbcount > 0)
590  uval64 >>= lsbcount;
591 
592  uint64_t bitfield_mask =
593  (bitfield_bit_size == 64
594  ? std::numeric_limits<uint64_t>::max()
595  : ((static_cast<uint64_t>(1) << bitfield_bit_size) - 1));
596  if (!bitfield_mask && bitfield_bit_offset == 0 && bitfield_bit_size == 64)
597  return uval64;
598 
599  uval64 &= bitfield_mask;
600 
601  return uval64;
602 }
603 
604 int64_t DataExtractor::GetMaxS64Bitfield(offset_t *offset_ptr, size_t size,
605  uint32_t bitfield_bit_size,
606  uint32_t bitfield_bit_offset) const {
607  assert(size >= 1 && "GetMaxS64Bitfield size must be >= 1");
608  assert(size <= 8 && "GetMaxS64Bitfield size must be <= 8");
609  int64_t sval64 = GetMaxS64(offset_ptr, size);
610  if (bitfield_bit_size == 0)
611  return sval64;
612  int32_t lsbcount = bitfield_bit_offset;
614  lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size;
615  if (lsbcount > 0)
616  sval64 >>= lsbcount;
617  uint64_t bitfield_mask = llvm::maskTrailingOnes<uint64_t>(bitfield_bit_size);
618  sval64 &= bitfield_mask;
619  // sign extend if needed
620  if (sval64 & ((static_cast<uint64_t>(1)) << (bitfield_bit_size - 1)))
621  sval64 |= ~bitfield_mask;
622  return sval64;
623 }
624 
625 float DataExtractor::GetFloat(offset_t *offset_ptr) const {
626  return Get<float>(offset_ptr, 0.0f);
627 }
628 
629 double DataExtractor::GetDouble(offset_t *offset_ptr) const {
630  return Get<double>(offset_ptr, 0.0);
631 }
632 
633 long double DataExtractor::GetLongDouble(offset_t *offset_ptr) const {
634  long double val = 0.0;
635 #if defined(__i386__) || defined(__amd64__) || defined(__x86_64__) || \
636  defined(_M_IX86) || defined(_M_IA64) || defined(_M_X64)
637  *offset_ptr += CopyByteOrderedData(*offset_ptr, 10, &val, sizeof(val),
639 #else
640  *offset_ptr += CopyByteOrderedData(*offset_ptr, sizeof(val), &val,
641  sizeof(val), endian::InlHostByteOrder());
642 #endif
643  return val;
644 }
645 
646 // Extract a single address from the data and update the offset pointed to by
647 // "offset_ptr". The size of the extracted address comes from the
648 // "this->m_addr_size" member variable and should be set correctly prior to
649 // extracting any address values.
650 //
651 // RETURNS the address that was extracted, or zero on failure.
652 uint64_t DataExtractor::GetAddress(offset_t *offset_ptr) const {
653  assert(m_addr_size >= 1 && m_addr_size <= 8);
654  return GetMaxU64(offset_ptr, m_addr_size);
655 }
656 
657 uint64_t DataExtractor::GetAddress_unchecked(offset_t *offset_ptr) const {
658  assert(m_addr_size >= 1 && m_addr_size <= 8);
659  return GetMaxU64_unchecked(offset_ptr, m_addr_size);
660 }
661 
663  ByteOrder dst_byte_order, void *dst) const {
664  const uint8_t *src = PeekData(offset, length);
665  if (src) {
666  if (dst_byte_order != GetByteOrder()) {
667  // Validate that only a word- or register-sized dst is byte swapped
668  assert(length == 1 || length == 2 || length == 4 || length == 8 ||
669  length == 10 || length == 16 || length == 32);
670 
671  for (uint32_t i = 0; i < length; ++i)
672  (static_cast<uint8_t *>(dst))[i] = src[length - i - 1];
673  } else
674  ::memcpy(dst, src, length);
675  return length;
676  }
677  return 0;
678 }
679 
680 // Extract data as it exists in target memory
682  void *dst) const {
683  const uint8_t *src = PeekData(offset, length);
684  if (src) {
685  ::memcpy(dst, src, length);
686  return length;
687  }
688  return 0;
689 }
690 
691 // Extract data and swap if needed when doing the copy
694  void *dst_void_ptr, offset_t dst_len,
695  ByteOrder dst_byte_order) const {
696  // Validate the source info
697  if (!ValidOffsetForDataOfSize(src_offset, src_len))
698  assert(ValidOffsetForDataOfSize(src_offset, src_len));
699  assert(src_len > 0);
701 
702  // Validate the destination info
703  assert(dst_void_ptr != nullptr);
704  assert(dst_len > 0);
705  assert(dst_byte_order == eByteOrderBig || dst_byte_order == eByteOrderLittle);
706 
707  // Validate that only a word- or register-sized dst is byte swapped
708  assert(dst_byte_order == m_byte_order || dst_len == 1 || dst_len == 2 ||
709  dst_len == 4 || dst_len == 8 || dst_len == 10 || dst_len == 16 ||
710  dst_len == 32);
711 
712  // Must have valid byte orders set in this object and for destination
713  if (!(dst_byte_order == eByteOrderBig ||
714  dst_byte_order == eByteOrderLittle) ||
716  return 0;
717 
718  uint8_t *dst = static_cast<uint8_t *>(dst_void_ptr);
719  const uint8_t *src = PeekData(src_offset, src_len);
720  if (src) {
721  if (dst_len >= src_len) {
722  // We are copying the entire value from src into dst. Calculate how many,
723  // if any, zeroes we need for the most significant bytes if "dst_len" is
724  // greater than "src_len"...
725  const size_t num_zeroes = dst_len - src_len;
726  if (dst_byte_order == eByteOrderBig) {
727  // Big endian, so we lead with zeroes...
728  if (num_zeroes > 0)
729  ::memset(dst, 0, num_zeroes);
730  // Then either copy or swap the rest
731  if (m_byte_order == eByteOrderBig) {
732  ::memcpy(dst + num_zeroes, src, src_len);
733  } else {
734  for (uint32_t i = 0; i < src_len; ++i)
735  dst[i + num_zeroes] = src[src_len - 1 - i];
736  }
737  } else {
738  // Little endian destination, so we lead the value bytes
739  if (m_byte_order == eByteOrderBig) {
740  for (uint32_t i = 0; i < src_len; ++i)
741  dst[i] = src[src_len - 1 - i];
742  } else {
743  ::memcpy(dst, src, src_len);
744  }
745  // And zero the rest...
746  if (num_zeroes > 0)
747  ::memset(dst + src_len, 0, num_zeroes);
748  }
749  return src_len;
750  } else {
751  // We are only copying some of the value from src into dst..
752 
753  if (dst_byte_order == eByteOrderBig) {
754  // Big endian dst
755  if (m_byte_order == eByteOrderBig) {
756  // Big endian dst, with big endian src
757  ::memcpy(dst, src + (src_len - dst_len), dst_len);
758  } else {
759  // Big endian dst, with little endian src
760  for (uint32_t i = 0; i < dst_len; ++i)
761  dst[i] = src[dst_len - 1 - i];
762  }
763  } else {
764  // Little endian dst
765  if (m_byte_order == eByteOrderBig) {
766  // Little endian dst, with big endian src
767  for (uint32_t i = 0; i < dst_len; ++i)
768  dst[i] = src[src_len - 1 - i];
769  } else {
770  // Little endian dst, with big endian src
771  ::memcpy(dst, src, dst_len);
772  }
773  }
774  return dst_len;
775  }
776  }
777  return 0;
778 }
779 
780 // Extracts a variable length NULL terminated C string from the data at the
781 // offset pointed to by "offset_ptr". The "offset_ptr" will be updated with
782 // the offset of the byte that follows the NULL terminator byte.
783 //
784 // If the offset pointed to by "offset_ptr" is out of bounds, or if "length" is
785 // non-zero and there aren't enough available bytes, nullptr will be returned
786 // and "offset_ptr" will not be updated.
787 const char *DataExtractor::GetCStr(offset_t *offset_ptr) const {
788  const char *start = reinterpret_cast<const char *>(PeekData(*offset_ptr, 1));
789  // Already at the end of the data.
790  if (!start)
791  return nullptr;
792 
793  const char *end = reinterpret_cast<const char *>(m_end);
794 
795  // Check all bytes for a null terminator that terminates a C string.
796  const char *terminator_or_end = std::find(start, end, '\0');
797 
798  // We didn't find a null terminator, so return nullptr to indicate that there
799  // is no valid C string at that offset.
800  if (terminator_or_end == end)
801  return nullptr;
802 
803  // Update offset_ptr for the caller to point to the data behind the
804  // terminator (which is 1 byte long).
805  *offset_ptr += (terminator_or_end - start + 1UL);
806  return start;
807 }
808 
809 // Extracts a NULL terminated C string from the fixed length field of length
810 // "len" at the offset pointed to by "offset_ptr". The "offset_ptr" will be
811 // updated with the offset of the byte that follows the fixed length field.
812 //
813 // If the offset pointed to by "offset_ptr" is out of bounds, or if the offset
814 // plus the length of the field is out of bounds, or if the field does not
815 // contain a NULL terminator byte, nullptr will be returned and "offset_ptr"
816 // will not be updated.
817 const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const {
818  const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, len));
819  if (cstr != nullptr) {
820  if (memchr(cstr, '\0', len) == nullptr) {
821  return nullptr;
822  }
823  *offset_ptr += len;
824  return cstr;
825  }
826  return nullptr;
827 }
828 
829 // Peeks at a string in the contained data. No verification is done to make
830 // sure the entire string lies within the bounds of this object's data, only
831 // "offset" is verified to be a valid offset.
832 //
833 // Returns a valid C string pointer if "offset" is a valid offset in this
834 // object's data, else nullptr is returned.
835 const char *DataExtractor::PeekCStr(offset_t offset) const {
836  return reinterpret_cast<const char *>(PeekData(offset, 1));
837 }
838 
839 // Extracts an unsigned LEB128 number from this object's data starting at the
840 // offset pointed to by "offset_ptr". The offset pointed to by "offset_ptr"
841 // will be updated with the offset of the byte following the last extracted
842 // byte.
843 //
844 // Returned the extracted integer value.
845 uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const {
846  const uint8_t *src = PeekData(*offset_ptr, 1);
847  if (src == nullptr)
848  return 0;
849 
850  unsigned byte_count = 0;
851  uint64_t result = llvm::decodeULEB128(src, &byte_count, m_end);
852  *offset_ptr += byte_count;
853  return result;
854 }
855 
856 // Extracts an signed LEB128 number from this object's data starting at the
857 // offset pointed to by "offset_ptr". The offset pointed to by "offset_ptr"
858 // will be updated with the offset of the byte following the last extracted
859 // byte.
860 //
861 // Returned the extracted integer value.
862 int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const {
863  const uint8_t *src = PeekData(*offset_ptr, 1);
864  if (src == nullptr)
865  return 0;
866 
867  unsigned byte_count = 0;
868  int64_t result = llvm::decodeSLEB128(src, &byte_count, m_end);
869  *offset_ptr += byte_count;
870  return result;
871 }
872 
873 // Skips a ULEB128 number (signed or unsigned) from this object's data starting
874 // at the offset pointed to by "offset_ptr". The offset pointed to by
875 // "offset_ptr" will be updated with the offset of the byte following the last
876 // extracted byte.
877 //
878 // Returns the number of bytes consumed during the extraction.
880  uint32_t bytes_consumed = 0;
881  const uint8_t *src = PeekData(*offset_ptr, 1);
882  if (src == nullptr)
883  return 0;
884 
885  const uint8_t *end = m_end;
886 
887  if (src < end) {
888  const uint8_t *src_pos = src;
889  while ((src_pos < end) && (*src_pos++ & 0x80))
890  ++bytes_consumed;
891  *offset_ptr += src_pos - src;
892  }
893  return bytes_consumed;
894 }
895 
896 // Dumps bytes from this object's data to the stream "s" starting
897 // "start_offset" bytes into this data, and ending with the byte before
898 // "end_offset". "base_addr" will be added to the offset into the dumped data
899 // when showing the offset into the data in the output information.
900 // "num_per_line" objects of type "type" will be dumped with the option to
901 // override the format for each object with "type_format". "type_format" is a
902 // printf style formatting string. If "type_format" is nullptr, then an
903 // appropriate format string will be used for the supplied "type". If the
904 // stream "s" is nullptr, then the output will be send to Log().
906  offset_t length, uint64_t base_addr,
907  uint32_t num_per_line,
908  DataExtractor::Type type) const {
909  if (log == nullptr)
910  return start_offset;
911 
912  offset_t offset;
913  offset_t end_offset;
914  uint32_t count;
915  StreamString sstr;
916  for (offset = start_offset, end_offset = offset + length, count = 0;
917  ValidOffset(offset) && offset < end_offset; ++count) {
918  if ((count % num_per_line) == 0) {
919  // Print out any previous string
920  if (sstr.GetSize() > 0) {
921  log->PutString(sstr.GetString());
922  sstr.Clear();
923  }
924  // Reset string offset and fill the current line string with address:
925  if (base_addr != LLDB_INVALID_ADDRESS)
926  sstr.Printf("0x%8.8" PRIx64 ":",
927  static_cast<uint64_t>(base_addr + (offset - start_offset)));
928  }
929 
930  switch (type) {
931  case TypeUInt8:
932  sstr.Printf(" %2.2x", GetU8(&offset));
933  break;
934  case TypeChar: {
935  char ch = GetU8(&offset);
936  sstr.Printf(" %c", llvm::isPrint(ch) ? ch : ' ');
937  } break;
938  case TypeUInt16:
939  sstr.Printf(" %4.4x", GetU16(&offset));
940  break;
941  case TypeUInt32:
942  sstr.Printf(" %8.8x", GetU32(&offset));
943  break;
944  case TypeUInt64:
945  sstr.Printf(" %16.16" PRIx64, GetU64(&offset));
946  break;
947  case TypePointer:
948  sstr.Printf(" 0x%" PRIx64, GetAddress(&offset));
949  break;
950  case TypeULEB128:
951  sstr.Printf(" 0x%" PRIx64, GetULEB128(&offset));
952  break;
953  case TypeSLEB128:
954  sstr.Printf(" %" PRId64, GetSLEB128(&offset));
955  break;
956  }
957  }
958 
959  if (!sstr.Empty())
960  log->PutString(sstr.GetString());
961 
962  return offset; // Return the offset at which we ended up
963 }
964 
965 size_t DataExtractor::Copy(DataExtractor &dest_data) const {
966  if (m_data_sp) {
967  // we can pass along the SP to the data
968  dest_data.SetData(m_data_sp);
969  } else {
970  const uint8_t *base_ptr = m_start;
971  size_t data_size = GetByteSize();
972  dest_data.SetData(DataBufferSP(new DataBufferHeap(base_ptr, data_size)));
973  }
974  return GetByteSize();
975 }
976 
978  if (rhs.GetByteOrder() != GetByteOrder())
979  return false;
980 
981  if (rhs.GetByteSize() == 0)
982  return true;
983 
984  if (GetByteSize() == 0)
985  return (rhs.Copy(*this) > 0);
986 
987  size_t bytes = GetByteSize() + rhs.GetByteSize();
988 
989  DataBufferHeap *buffer_heap_ptr = nullptr;
990  DataBufferSP buffer_sp(buffer_heap_ptr = new DataBufferHeap(bytes, 0));
991 
992  if (!buffer_sp || buffer_heap_ptr == nullptr)
993  return false;
994 
995  uint8_t *bytes_ptr = buffer_heap_ptr->GetBytes();
996 
997  memcpy(bytes_ptr, GetDataStart(), GetByteSize());
998  memcpy(bytes_ptr + GetByteSize(), rhs.GetDataStart(), rhs.GetByteSize());
999 
1000  SetData(buffer_sp);
1001 
1002  return true;
1003 }
1004 
1005 bool DataExtractor::Append(void *buf, offset_t length) {
1006  if (buf == nullptr)
1007  return false;
1008 
1009  if (length == 0)
1010  return true;
1011 
1012  size_t bytes = GetByteSize() + length;
1013 
1014  DataBufferHeap *buffer_heap_ptr = nullptr;
1015  DataBufferSP buffer_sp(buffer_heap_ptr = new DataBufferHeap(bytes, 0));
1016 
1017  if (!buffer_sp || buffer_heap_ptr == nullptr)
1018  return false;
1019 
1020  uint8_t *bytes_ptr = buffer_heap_ptr->GetBytes();
1021 
1022  if (GetByteSize() > 0)
1023  memcpy(bytes_ptr, GetDataStart(), GetByteSize());
1024 
1025  memcpy(bytes_ptr + GetByteSize(), buf, length);
1026 
1027  SetData(buffer_sp);
1028 
1029  return true;
1030 }
1031 
1033  uint64_t max_data) {
1034  if (max_data == 0)
1035  max_data = GetByteSize();
1036  else
1037  max_data = std::min(max_data, GetByteSize());
1038 
1039  llvm::MD5 md5;
1040 
1041  const llvm::ArrayRef<uint8_t> data(GetDataStart(), max_data);
1042  md5.update(data);
1043 
1044  llvm::MD5::MD5Result result;
1045  md5.final(result);
1046 
1047  dest.clear();
1048  dest.append(result.Bytes.begin(), result.Bytes.end());
1049 }
ReadSwapInt32
static uint32_t ReadSwapInt32(const unsigned char *ptr, offset_t offset)
Definition: DataExtractor.cpp:76
lldb_private::DataExtractor::PutToLog
lldb::offset_t PutToLog(Log *log, lldb::offset_t offset, lldb::offset_t length, uint64_t base_addr, uint32_t num_per_line, Type type) const
Dumps the binary data as type objects to stream s (or to Log() if s is nullptr) starting offset bytes...
Definition: DataExtractor.cpp:905
lldb_private::DataExtractor::GetULEB128
uint64_t GetULEB128(lldb::offset_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:845
lldb_private::DataBufferHeap::GetBytes
uint8_t * GetBytes() override
Definition: DataBufferHeap.cpp:34
lldb_private::Log::PutString
void PutString(llvm::StringRef str)
Definition: Log.cpp:118
lldb_private::DataExtractor::GetAddress
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
Definition: DataExtractor.cpp:652
lldb_private::DataExtractor::m_addr_size
uint32_t m_addr_size
The address size to use when extracting addresses.
Definition: DataExtractor.h:1005
UUID.h
lldb_private::DataExtractor::ValidOffset
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:945
lldb-defines.h
lldb_private::DataExtractor::TypeUInt16
@ TypeUInt16
Format output as unsigned 16 bit integers.
Definition: DataExtractor.h:55
lldb_private::DataExtractor::m_start
const uint8_t * m_start
A pointer to the first byte of data.
Definition: DataExtractor.h:1000
ReadInt32
static uint32_t ReadInt32(const unsigned char *ptr, offset_t offset=0)
Definition: DataExtractor.cpp:49
lldb_private::DataExtractor::Copy
size_t Copy(DataExtractor &dest_data) const
Definition: DataExtractor.cpp:965
lldb_private::DataExtractor::PeekData
const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
Definition: DataExtractor.h:821
lldb_private::DataExtractor::m_end
const uint8_t * m_end
A pointer to the byte that is past the end of the data.
Definition: DataExtractor.h:1002
lldb_private::DataExtractor::GetU16_unchecked
uint16_t GetU16_unchecked(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:363
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::DataExtractor::Append
bool Append(DataExtractor &rhs)
Definition: DataExtractor.cpp:977
ReadSwapInt64
static uint64_t ReadSwapInt64(const unsigned char *ptr, offset_t offset)
Definition: DataExtractor.cpp:83
lldb_private::DataExtractor::ExtractBytes
size_t ExtractBytes(lldb::offset_t offset, lldb::offset_t length, lldb::ByteOrder dst_byte_order, void *dst) const
Extract an arbitrary number of bytes in the specified byte order.
Definition: DataExtractor.cpp:662
ReadMaxInt64
static uint64_t ReadMaxInt64(const uint8_t *data, size_t byte_size, ByteOrder byte_order)
Definition: DataExtractor.cpp:108
lldb_private::DataExtractor::GetMaxU64_unchecked
uint64_t GetMaxU64_unchecked(lldb::offset_t *offset_ptr, size_t byte_size) const
Definition: DataExtractor.cpp:551
lldb_private::DataExtractor::GetU64
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
Definition: DataExtractor.cpp:477
lldb_private::DataExtractor::TypePointer
@ TypePointer
Format output as pointers.
Definition: DataExtractor.h:58
lldb_private::DataExtractor::SetData
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
Definition: DataExtractor.cpp:226
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::DataExtractor::PeekCStr
const char * PeekCStr(lldb::offset_t offset) const
Peek at a C string at offset.
Definition: DataExtractor.cpp:835
lldb_private::StreamString::GetSize
size_t GetSize() const
Definition: StreamString.cpp:38
lldb_private::DataExtractor::GetSLEB128
int64_t GetSLEB128(lldb::offset_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:862
lldb_private::DataExtractor::GetData
llvm::ArrayRef< uint8_t > GetData() const
Definition: DataExtractor.h:974
lldb_private::DataExtractor::TypeSLEB128
@ TypeSLEB128
Format output as SLEB128 numbers.
Definition: DataExtractor.h:60
lldb_private::DataExtractor::Type
Type
Definition: DataExtractor.h:52
LLDBAssert.h
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
lldb_private::DataExtractor::~DataExtractor
virtual ~DataExtractor()
Destructor.
ReadInt64
static uint64_t ReadInt64(const unsigned char *ptr, offset_t offset=0)
Definition: DataExtractor.cpp:56
lldb_private::DataExtractor::GetAddress_unchecked
uint64_t GetAddress_unchecked(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:657
lldb_private::StreamString::Clear
void Clear()
Definition: StreamString.cpp:31
lldb_private::DataExtractor::GetMaxU32
uint32_t GetMaxU32(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:521
lldb_private::DataExtractor::GetMaxS64
int64_t GetMaxS64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an signed integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:571
StreamString.h
lldb_private::DataExtractor::GetDouble
double GetDouble(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:629
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:411
lldb_private::DataExtractor::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
Definition: DataExtractor.h:583
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::DataExtractor::GetU8
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:319
lldb-enumerations.h
DataBuffer
lldb_private::DataExtractor::DataExtractor
DataExtractor()
Default constructor.
Definition: DataExtractor.cpp:122
lldb_private::StreamString::Empty
bool Empty() const
Definition: StreamString.cpp:36
lldb_private::DataExtractor::GetFloat
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
Definition: DataExtractor.cpp:625
lldb_private::DataExtractor::Skip_LEB128
uint32_t Skip_LEB128(lldb::offset_t *offset_ptr) const
Skip an LEB128 number at *offset_ptr.
Definition: DataExtractor.cpp:879
lldb_private::DataExtractor::GetU8_unchecked
uint8_t GetU8_unchecked(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.h:601
ReadSwapInt16
static uint16_t ReadSwapInt16(const unsigned char *ptr, offset_t offset)
Definition: DataExtractor.cpp:69
lldb-types.h
lldb_private::DataExtractor::m_data_sp
lldb::DataBufferSP m_data_sp
The shared pointer to data that can be shared among multiple instances.
Definition: DataExtractor.h:1007
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
ReadInt16
static uint16_t ReadInt16(const unsigned char *ptr, offset_t offset)
Definition: DataExtractor.cpp:43
uint32_t
lldb_private::DataExtractor::GetMaxU64
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:527
lldb_private::DataExtractor::GetSharedDataOffset
size_t GetSharedDataOffset() const
Get the shared data offset.
Definition: DataExtractor.cpp:205
lldb_private::endian::InlHostByteOrder
lldb::ByteOrder InlHostByteOrder()
Definition: Endian.h:25
lldb_private::DataExtractor::GetMaxS64Bitfield
int64_t GetMaxS64Bitfield(lldb::offset_t *offset_ptr, size_t size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset) const
Extract an signed integer of size size from *offset_ptr, then extract and sign-extend the bitfield fr...
Definition: DataExtractor.cpp:604
uint16_t
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:428
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
DataExtractor.h
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb-forward.h
lldb_private::DataExtractor::GetMaxU64Bitfield
uint64_t GetMaxU64Bitfield(lldb::offset_t *offset_ptr, size_t size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset) const
Extract an unsigned integer of size byte_size from *offset_ptr, then extract the bitfield from this v...
Definition: DataExtractor.cpp:576
lldb_private::DataExtractor::CopyData
lldb::offset_t CopyData(lldb::offset_t offset, lldb::offset_t length, void *dst) const
Copy length bytes from *offset, without swapping bytes.
Definition: DataExtractor.cpp:681
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DataExtractor::GetU16
uint16_t GetU16(lldb::offset_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
Definition: DataExtractor.cpp:350
lldb_private::DataExtractor::GetLongDouble
long double GetLongDouble(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:633
lldb_private::DataExtractor::GetCStr
const char * GetCStr(lldb::offset_t *offset_ptr) const
Extract a C string from *offset_ptr.
Definition: DataExtractor.cpp:787
lldb_private::DataExtractor::TypeUInt32
@ TypeUInt32
Format output as unsigned 32 bit integers.
Definition: DataExtractor.h:56
lldb::eByteOrderBig
@ eByteOrderBig
Definition: lldb-enumerations.h:140
lldb_private::DataExtractor::CopyByteOrderedData
lldb::offset_t CopyByteOrderedData(lldb::offset_t src_offset, lldb::offset_t src_len, void *dst, lldb::offset_t dst_len, lldb::ByteOrder dst_byte_order) const
Copy dst_len bytes from *offset_ptr and ensure the copied data is treated as a value that can be swap...
Definition: DataExtractor.cpp:693
lldb_private::DataExtractor::Clear
void Clear()
Clears the object state.
Definition: DataExtractor.cpp:195
lldb_private::DataExtractor::GetU64_unchecked
uint64_t GetU64_unchecked(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:383
Stream.h
lldb_private::Log
Definition: Log.h:49
lldb_private::DataExtractor::TypeUInt64
@ TypeUInt64
Format output as unsigned 64 bit integers.
Definition: DataExtractor.h:57
llvm::SmallVectorImpl
Definition: Disassembler.h:42
lldb_private::DataExtractor::Checksum
void Checksum(llvm::SmallVectorImpl< uint8_t > &dest, uint64_t max_data=0)
Definition: DataExtractor.cpp:1032
lldb_private::DataExtractor::TypeChar
@ TypeChar
Format output as characters.
Definition: DataExtractor.h:54
DataBuffer.h
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:259
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::DataExtractor::m_byte_order
lldb::ByteOrder m_byte_order
The byte order of the data we are extracting from.
Definition: DataExtractor.h:1004
lldb_private::DataExtractor::ValidOffsetForDataOfSize
bool ValidOffsetForDataOfSize(lldb::offset_t offset, lldb::offset_t length) const
Test the availability of length bytes of data from offset.
Definition: DataExtractor.h:954
lldb
Definition: SBAddress.h:15
lldb_private::DataExtractor::operator=
const DataExtractor & operator=(const DataExtractor &rhs)
Assignment operator.
Definition: DataExtractor.cpp:180
lldb_private::DataExtractor::TypeUInt8
@ TypeUInt8
Format output as unsigned 8 bit integers.
Definition: DataExtractor.h:53
DataBufferHeap.h
lldb_private::DataExtractor::GetU32_unchecked
uint32_t GetU32_unchecked(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:373
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
lldb_private::DataExtractor::TypeULEB128
@ TypeULEB128
Format output as ULEB128 numbers.
Definition: DataExtractor.h:59