LLDB  mainline
DumpDataExtractor.cpp
Go to the documentation of this file.
1 //===-- DumpDataExtractor.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-forward.h"
13 
14 #include "lldb/Core/Address.h"
15 #include "lldb/Core/Disassembler.h"
16 #include "lldb/Core/ModuleList.h"
17 #include "lldb/Target/ABI.h"
20 #include "lldb/Target/Process.h"
22 #include "lldb/Target/Target.h"
24 #include "lldb/Utility/Log.h"
25 #include "lldb/Utility/Stream.h"
26 
27 #include "llvm/ADT/APFloat.h"
28 #include "llvm/ADT/APInt.h"
29 #include "llvm/ADT/ArrayRef.h"
30 #include "llvm/ADT/Optional.h"
31 #include "llvm/ADT/SmallVector.h"
32 
33 #include <limits>
34 #include <memory>
35 #include <string>
36 
37 #include <cassert>
38 #include <cctype>
39 #include <cinttypes>
40 #include <cmath>
41 
42 #include <bitset>
43 #include <sstream>
44 
45 using namespace lldb_private;
46 using namespace lldb;
47 
48 #define NON_PRINTABLE_CHAR '.'
49 
50 static float half2float(uint16_t half) {
51  union {
52  float f;
53  uint32_t u;
54  } u;
55  // Sign extend to 4 byte.
56  int32_t sign_extended = static_cast<int16_t>(half);
57  uint32_t v = static_cast<uint32_t>(sign_extended);
58 
59  if (0 == (v & 0x7c00)) {
60  u.u = v & 0x80007FFFU;
61  return u.f * ldexpf(1, 125);
62  }
63 
64  v <<= 13;
65  u.u = v | 0x70000000U;
66  return u.f * ldexpf(1, -112);
67 }
68 
69 static llvm::Optional<llvm::APInt> GetAPInt(const DataExtractor &data,
70  lldb::offset_t *offset_ptr,
71  lldb::offset_t byte_size) {
72  if (byte_size == 0)
73  return llvm::None;
74 
75  llvm::SmallVector<uint64_t, 2> uint64_array;
76  lldb::offset_t bytes_left = byte_size;
77  uint64_t u64;
78  const lldb::ByteOrder byte_order = data.GetByteOrder();
79  if (byte_order == lldb::eByteOrderLittle) {
80  while (bytes_left > 0) {
81  if (bytes_left >= 8) {
82  u64 = data.GetU64(offset_ptr);
83  bytes_left -= 8;
84  } else {
85  u64 = data.GetMaxU64(offset_ptr, (uint32_t)bytes_left);
86  bytes_left = 0;
87  }
88  uint64_array.push_back(u64);
89  }
90  return llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array));
91  } else if (byte_order == lldb::eByteOrderBig) {
92  lldb::offset_t be_offset = *offset_ptr + byte_size;
93  lldb::offset_t temp_offset;
94  while (bytes_left > 0) {
95  if (bytes_left >= 8) {
96  be_offset -= 8;
97  temp_offset = be_offset;
98  u64 = data.GetU64(&temp_offset);
99  bytes_left -= 8;
100  } else {
101  be_offset -= bytes_left;
102  temp_offset = be_offset;
103  u64 = data.GetMaxU64(&temp_offset, (uint32_t)bytes_left);
104  bytes_left = 0;
105  }
106  uint64_array.push_back(u64);
107  }
108  *offset_ptr += byte_size;
109  return llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array));
110  }
111  return llvm::None;
112 }
113 
115  lldb::offset_t offset, lldb::offset_t byte_size,
116  bool is_signed, unsigned radix) {
117  llvm::Optional<llvm::APInt> apint = GetAPInt(data, &offset, byte_size);
118  if (apint.hasValue()) {
119  std::string apint_str = toString(apint.getValue(), radix, is_signed);
120  switch (radix) {
121  case 2:
122  s->Write("0b", 2);
123  break;
124  case 8:
125  s->Write("0", 1);
126  break;
127  case 10:
128  break;
129  }
130  s->Write(apint_str.c_str(), apint_str.size());
131  }
132  return offset;
133 }
134 
135 /// Dumps decoded instructions to a stream.
137  ExecutionContextScope *exe_scope,
138  offset_t start_offset,
139  uint64_t base_addr,
140  size_t number_of_instructions) {
141  offset_t offset = start_offset;
142 
143  TargetSP target_sp;
144  if (exe_scope)
145  target_sp = exe_scope->CalculateTarget();
146  if (target_sp) {
147  DisassemblerSP disassembler_sp(
148  Disassembler::FindPlugin(target_sp->GetArchitecture(),
149  target_sp->GetDisassemblyFlavor(), nullptr));
150  if (disassembler_sp) {
151  lldb::addr_t addr = base_addr + start_offset;
152  lldb_private::Address so_addr;
153  bool data_from_file = true;
154  if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) {
155  data_from_file = false;
156  } else {
157  if (target_sp->GetSectionLoadList().IsEmpty() ||
158  !target_sp->GetImages().ResolveFileAddress(addr, so_addr))
159  so_addr.SetRawAddress(addr);
160  }
161 
162  size_t bytes_consumed = disassembler_sp->DecodeInstructions(
163  so_addr, DE, start_offset, number_of_instructions, false,
164  data_from_file);
165 
166  if (bytes_consumed) {
167  offset += bytes_consumed;
168  const bool show_address = base_addr != LLDB_INVALID_ADDRESS;
169  const bool show_bytes = true;
170  ExecutionContext exe_ctx;
171  exe_scope->CalculateExecutionContext(exe_ctx);
172  disassembler_sp->GetInstructionList().Dump(s, show_address, show_bytes,
173  &exe_ctx);
174  }
175  }
176  } else
177  s->Printf("invalid target");
178 
179  return offset;
180 }
181 
182 /// Prints the specific escape sequence of the given character to the stream.
183 /// If the character doesn't have a known specific escape sequence (e.g., '\a',
184 /// '\n' but not generic escape sequences such as'\x12'), this function will
185 /// not modify the stream and return false.
186 static bool TryDumpSpecialEscapedChar(Stream &s, const char c) {
187  switch (c) {
188  case '\033':
189  // Common non-standard escape code for 'escape'.
190  s.Printf("\\e");
191  return true;
192  case '\a':
193  s.Printf("\\a");
194  return true;
195  case '\b':
196  s.Printf("\\b");
197  return true;
198  case '\f':
199  s.Printf("\\f");
200  return true;
201  case '\n':
202  s.Printf("\\n");
203  return true;
204  case '\r':
205  s.Printf("\\r");
206  return true;
207  case '\t':
208  s.Printf("\\t");
209  return true;
210  case '\v':
211  s.Printf("\\v");
212  return true;
213  case '\0':
214  s.Printf("\\0");
215  return true;
216  default:
217  return false;
218  }
219 }
220 
221 /// Dump the character to a stream. A character that is not printable will be
222 /// represented by its escape sequence.
223 static void DumpCharacter(Stream &s, const char c) {
224  if (TryDumpSpecialEscapedChar(s, c))
225  return;
226  if (llvm::isPrint(c)) {
227  s.PutChar(c);
228  return;
229  }
230  s.Printf("\\x%2.2x", c);
231 }
232 
233 /// Dump a floating point type.
234 template <typename FloatT>
235 void DumpFloatingPoint(std::ostringstream &ss, FloatT f) {
236  static_assert(std::is_floating_point<FloatT>::value,
237  "Only floating point types can be dumped.");
238  // NaN and Inf are potentially implementation defined and on Darwin it
239  // seems NaNs are printed without their sign. Manually implement dumping them
240  // here to avoid having to deal with platform differences.
241  if (std::isnan(f)) {
242  if (std::signbit(f))
243  ss << '-';
244  ss << "nan";
245  return;
246  }
247  if (std::isinf(f)) {
248  if (std::signbit(f))
249  ss << '-';
250  ss << "inf";
251  return;
252  }
253  ss << f;
254 }
255 
257  const DataExtractor &DE, Stream *s, offset_t start_offset,
258  lldb::Format item_format, size_t item_byte_size, size_t item_count,
259  size_t num_per_line, uint64_t base_addr,
260  uint32_t item_bit_size, // If zero, this is not a bitfield value, if
261  // non-zero, the value is a bitfield
262  uint32_t item_bit_offset, // If "item_bit_size" is non-zero, this is the
263  // shift amount to apply to a bitfield
264  ExecutionContextScope *exe_scope) {
265  if (s == nullptr)
266  return start_offset;
267 
268  if (item_format == eFormatPointer) {
269  if (item_byte_size != 4 && item_byte_size != 8)
270  item_byte_size = s->GetAddressByteSize();
271  }
272 
273  offset_t offset = start_offset;
274 
275  if (item_format == eFormatInstruction)
276  return DumpInstructions(DE, s, exe_scope, start_offset, base_addr,
277  item_count);
278 
279  if ((item_format == eFormatOSType || item_format == eFormatAddressInfo) &&
280  item_byte_size > 8)
281  item_format = eFormatHex;
282 
283  lldb::offset_t line_start_offset = start_offset;
284  for (uint32_t count = 0; DE.ValidOffset(offset) && count < item_count;
285  ++count) {
286  if ((count % num_per_line) == 0) {
287  if (count > 0) {
288  if (item_format == eFormatBytesWithASCII &&
289  offset > line_start_offset) {
290  s->Printf("%*s",
291  static_cast<int>(
292  (num_per_line - (offset - line_start_offset)) * 3 + 2),
293  "");
294  DumpDataExtractor(DE, s, line_start_offset, eFormatCharPrintable, 1,
295  offset - line_start_offset, SIZE_MAX,
296  LLDB_INVALID_ADDRESS, 0, 0);
297  }
298  s->EOL();
299  }
300  if (base_addr != LLDB_INVALID_ADDRESS)
301  s->Printf("0x%8.8" PRIx64 ": ",
302  (uint64_t)(base_addr +
303  (offset - start_offset) / DE.getTargetByteSize()));
304 
305  line_start_offset = offset;
306  } else if (item_format != eFormatChar &&
307  item_format != eFormatCharPrintable &&
308  item_format != eFormatCharArray && count > 0) {
309  s->PutChar(' ');
310  }
311 
312  switch (item_format) {
313  case eFormatBoolean:
314  if (item_byte_size <= 8)
315  s->Printf("%s", DE.GetMaxU64Bitfield(&offset, item_byte_size,
316  item_bit_size, item_bit_offset)
317  ? "true"
318  : "false");
319  else {
320  s->Printf("error: unsupported byte size (%" PRIu64
321  ") for boolean format",
322  (uint64_t)item_byte_size);
323  return offset;
324  }
325  break;
326 
327  case eFormatBinary:
328  if (item_byte_size <= 8) {
329  uint64_t uval64 = DE.GetMaxU64Bitfield(&offset, item_byte_size,
330  item_bit_size, item_bit_offset);
331  // Avoid std::bitset<64>::to_string() since it is missing in earlier
332  // C++ libraries
333  std::string binary_value(64, '0');
334  std::bitset<64> bits(uval64);
335  for (uint32_t i = 0; i < 64; ++i)
336  if (bits[i])
337  binary_value[64 - 1 - i] = '1';
338  if (item_bit_size > 0)
339  s->Printf("0b%s", binary_value.c_str() + 64 - item_bit_size);
340  else if (item_byte_size > 0 && item_byte_size <= 8)
341  s->Printf("0b%s", binary_value.c_str() + 64 - item_byte_size * 8);
342  } else {
343  const bool is_signed = false;
344  const unsigned radix = 2;
345  offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix);
346  }
347  break;
348 
349  case eFormatBytes:
351  for (uint32_t i = 0; i < item_byte_size; ++i) {
352  s->Printf("%2.2x", DE.GetU8(&offset));
353  }
354 
355  // Put an extra space between the groups of bytes if more than one is
356  // being dumped in a group (item_byte_size is more than 1).
357  if (item_byte_size > 1)
358  s->PutChar(' ');
359  break;
360 
361  case eFormatChar:
363  case eFormatCharArray: {
364  // Reject invalid item_byte_size.
365  if (item_byte_size > 8) {
366  s->Printf("error: unsupported byte size (%" PRIu64 ") for char format",
367  (uint64_t)item_byte_size);
368  return offset;
369  }
370 
371  // If we are only printing one character surround it with single quotes
372  if (item_count == 1 && item_format == eFormatChar)
373  s->PutChar('\'');
374 
375  const uint64_t ch = DE.GetMaxU64Bitfield(&offset, item_byte_size,
376  item_bit_size, item_bit_offset);
377  if (llvm::isPrint(ch))
378  s->Printf("%c", (char)ch);
379  else if (item_format != eFormatCharPrintable) {
380  if (!TryDumpSpecialEscapedChar(*s, ch)) {
381  if (item_byte_size == 1)
382  s->Printf("\\x%2.2x", (uint8_t)ch);
383  else
384  s->Printf("%" PRIu64, ch);
385  }
386  } else {
388  }
389 
390  // If we are only printing one character surround it with single quotes
391  if (item_count == 1 && item_format == eFormatChar)
392  s->PutChar('\'');
393  } break;
394 
395  case eFormatEnum: // Print enum value as a signed integer when we don't get
396  // the enum type
397  case eFormatDecimal:
398  if (item_byte_size <= 8)
399  s->Printf("%" PRId64,
400  DE.GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size,
401  item_bit_offset));
402  else {
403  const bool is_signed = true;
404  const unsigned radix = 10;
405  offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix);
406  }
407  break;
408 
409  case eFormatUnsigned:
410  if (item_byte_size <= 8)
411  s->Printf("%" PRIu64,
412  DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
413  item_bit_offset));
414  else {
415  const bool is_signed = false;
416  const unsigned radix = 10;
417  offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix);
418  }
419  break;
420 
421  case eFormatOctal:
422  if (item_byte_size <= 8)
423  s->Printf("0%" PRIo64,
424  DE.GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size,
425  item_bit_offset));
426  else {
427  const bool is_signed = false;
428  const unsigned radix = 8;
429  offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix);
430  }
431  break;
432 
433  case eFormatOSType: {
434  uint64_t uval64 = DE.GetMaxU64Bitfield(&offset, item_byte_size,
435  item_bit_size, item_bit_offset);
436  s->PutChar('\'');
437  for (uint32_t i = 0; i < item_byte_size; ++i) {
438  uint8_t ch = (uint8_t)(uval64 >> ((item_byte_size - i - 1) * 8));
439  DumpCharacter(*s, ch);
440  }
441  s->PutChar('\'');
442  } break;
443 
444  case eFormatCString: {
445  const char *cstr = DE.GetCStr(&offset);
446 
447  if (!cstr) {
448  s->Printf("NULL");
449  offset = LLDB_INVALID_OFFSET;
450  } else {
451  s->PutChar('\"');
452 
453  while (const char c = *cstr) {
454  DumpCharacter(*s, c);
455  ++cstr;
456  }
457 
458  s->PutChar('\"');
459  }
460  } break;
461 
462  case eFormatPointer:
464  DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
465  item_bit_offset),
466  sizeof(addr_t));
467  break;
468 
469  case eFormatComplexInteger: {
470  size_t complex_int_byte_size = item_byte_size / 2;
471 
472  if (complex_int_byte_size > 0 && complex_int_byte_size <= 8) {
473  s->Printf("%" PRIu64,
474  DE.GetMaxU64Bitfield(&offset, complex_int_byte_size, 0, 0));
475  s->Printf(" + %" PRIu64 "i",
476  DE.GetMaxU64Bitfield(&offset, complex_int_byte_size, 0, 0));
477  } else {
478  s->Printf("error: unsupported byte size (%" PRIu64
479  ") for complex integer format",
480  (uint64_t)item_byte_size);
481  return offset;
482  }
483  } break;
484 
485  case eFormatComplex:
486  if (sizeof(float) * 2 == item_byte_size) {
487  float f32_1 = DE.GetFloat(&offset);
488  float f32_2 = DE.GetFloat(&offset);
489 
490  s->Printf("%g + %gi", f32_1, f32_2);
491  break;
492  } else if (sizeof(double) * 2 == item_byte_size) {
493  double d64_1 = DE.GetDouble(&offset);
494  double d64_2 = DE.GetDouble(&offset);
495 
496  s->Printf("%lg + %lgi", d64_1, d64_2);
497  break;
498  } else if (sizeof(long double) * 2 == item_byte_size) {
499  long double ld64_1 = DE.GetLongDouble(&offset);
500  long double ld64_2 = DE.GetLongDouble(&offset);
501  s->Printf("%Lg + %Lgi", ld64_1, ld64_2);
502  break;
503  } else {
504  s->Printf("error: unsupported byte size (%" PRIu64
505  ") for complex float format",
506  (uint64_t)item_byte_size);
507  return offset;
508  }
509  break;
510 
511  default:
512  case eFormatDefault:
513  case eFormatHex:
514  case eFormatHexUppercase: {
515  bool wantsuppercase = (item_format == eFormatHexUppercase);
516  switch (item_byte_size) {
517  case 1:
518  case 2:
519  case 4:
520  case 8:
521  s->Printf(wantsuppercase ? "0x%*.*" PRIX64 : "0x%*.*" PRIx64,
522  (int)(2 * item_byte_size), (int)(2 * item_byte_size),
523  DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
524  item_bit_offset));
525  break;
526  default: {
527  assert(item_bit_size == 0 && item_bit_offset == 0);
528  const uint8_t *bytes =
529  (const uint8_t *)DE.GetData(&offset, item_byte_size);
530  if (bytes) {
531  s->PutCString("0x");
532  uint32_t idx;
533  if (DE.GetByteOrder() == eByteOrderBig) {
534  for (idx = 0; idx < item_byte_size; ++idx)
535  s->Printf(wantsuppercase ? "%2.2X" : "%2.2x", bytes[idx]);
536  } else {
537  for (idx = 0; idx < item_byte_size; ++idx)
538  s->Printf(wantsuppercase ? "%2.2X" : "%2.2x",
539  bytes[item_byte_size - 1 - idx]);
540  }
541  }
542  } break;
543  }
544  } break;
545 
546  case eFormatFloat: {
547  TargetSP target_sp;
548  bool used_upfloat = false;
549  if (exe_scope)
550  target_sp = exe_scope->CalculateTarget();
551  if (target_sp) {
552  auto type_system_or_err =
553  target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC);
554  if (!type_system_or_err) {
555  llvm::consumeError(type_system_or_err.takeError());
556  } else {
557  auto &type_system = *type_system_or_err;
558  llvm::SmallVector<char, 256> sv;
559  // Show full precision when printing float values
560  const unsigned format_precision = 0;
561  const unsigned format_max_padding =
562  target_sp->GetMaxZeroPaddingInFloatFormat();
563 
564  const auto &semantics =
565  type_system.GetFloatTypeSemantics(item_byte_size);
566 
567  // Recalculate the byte size in case of a difference. This is possible
568  // when item_byte_size is 16 (128-bit), because you could get back the
569  // x87DoubleExtended semantics which has a byte size of 10 (80-bit).
570  const size_t semantics_byte_size =
571  (llvm::APFloat::getSizeInBits(semantics) + 7) / 8;
572  llvm::Optional<llvm::APInt> apint =
573  GetAPInt(DE, &offset, semantics_byte_size);
574  if (apint.hasValue()) {
575  llvm::APFloat apfloat(semantics, apint.getValue());
576  apfloat.toString(sv, format_precision, format_max_padding);
577  if (!sv.empty()) {
578  s->Printf("%*.*s", (int)sv.size(), (int)sv.size(), sv.data());
579  used_upfloat = true;
580  }
581  }
582  }
583  }
584 
585  if (!used_upfloat) {
586  std::ostringstream ss;
587  if (item_byte_size == sizeof(float) || item_byte_size == 2) {
588  float f;
589  if (item_byte_size == 2) {
590  uint16_t half = DE.GetU16(&offset);
591  f = half2float(half);
592  } else {
593  f = DE.GetFloat(&offset);
594  }
595  ss.precision(std::numeric_limits<float>::digits10);
596  DumpFloatingPoint(ss, f);
597  } else if (item_byte_size == sizeof(double)) {
598  ss.precision(std::numeric_limits<double>::digits10);
599  DumpFloatingPoint(ss, DE.GetDouble(&offset));
600  } else if (item_byte_size == sizeof(long double) ||
601  item_byte_size == 10) {
602  ss.precision(std::numeric_limits<long double>::digits10);
603  DumpFloatingPoint(ss, DE.GetLongDouble(&offset));
604  } else {
605  s->Printf("error: unsupported byte size (%" PRIu64
606  ") for float format",
607  (uint64_t)item_byte_size);
608  return offset;
609  }
610  ss.flush();
611  s->Printf("%s", ss.str().c_str());
612  }
613  } break;
614 
615  case eFormatUnicode16:
616  s->Printf("U+%4.4x", DE.GetU16(&offset));
617  break;
618 
619  case eFormatUnicode32:
620  s->Printf("U+0x%8.8x", DE.GetU32(&offset));
621  break;
622 
623  case eFormatAddressInfo: {
624  addr_t addr = DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
625  item_bit_offset);
626  s->Printf("0x%*.*" PRIx64, (int)(2 * item_byte_size),
627  (int)(2 * item_byte_size), addr);
628  if (exe_scope) {
629  TargetSP target_sp(exe_scope->CalculateTarget());
630  lldb_private::Address so_addr;
631  if (target_sp) {
632  if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr,
633  so_addr)) {
634  s->PutChar(' ');
635  so_addr.Dump(s, exe_scope, Address::DumpStyleResolvedDescription,
637  } else {
638  so_addr.SetOffset(addr);
639  so_addr.Dump(s, exe_scope,
641  if (ProcessSP process_sp = exe_scope->CalculateProcess()) {
642  if (ABISP abi_sp = process_sp->GetABI()) {
643  addr_t addr_fixed = abi_sp->FixCodeAddress(addr);
644  if (target_sp->GetSectionLoadList().ResolveLoadAddress(
645  addr_fixed, so_addr)) {
646  s->PutChar(' ');
647  s->Printf("(0x%*.*" PRIx64 ")", (int)(2 * item_byte_size),
648  (int)(2 * item_byte_size), addr_fixed);
649  s->PutChar(' ');
650  so_addr.Dump(s, exe_scope,
653  }
654  }
655  }
656  }
657  }
658  }
659  } break;
660 
661  case eFormatHexFloat:
662  if (sizeof(float) == item_byte_size) {
663  char float_cstr[256];
664  llvm::APFloat ap_float(DE.GetFloat(&offset));
665  ap_float.convertToHexString(float_cstr, 0, false,
666  llvm::APFloat::rmNearestTiesToEven);
667  s->Printf("%s", float_cstr);
668  break;
669  } else if (sizeof(double) == item_byte_size) {
670  char float_cstr[256];
671  llvm::APFloat ap_float(DE.GetDouble(&offset));
672  ap_float.convertToHexString(float_cstr, 0, false,
673  llvm::APFloat::rmNearestTiesToEven);
674  s->Printf("%s", float_cstr);
675  break;
676  } else {
677  s->Printf("error: unsupported byte size (%" PRIu64
678  ") for hex float format",
679  (uint64_t)item_byte_size);
680  return offset;
681  }
682  break;
683 
684  // please keep the single-item formats below in sync with
685  // FormatManager::GetSingleItemFormat if you fail to do so, users will
686  // start getting different outputs depending on internal implementation
687  // details they should not care about ||
688  case eFormatVectorOfChar: // ||
689  s->PutChar('{'); // \/
690  offset =
691  DumpDataExtractor(DE, s, offset, eFormatCharArray, 1, item_byte_size,
692  item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
693  s->PutChar('}');
694  break;
695 
697  s->PutChar('{');
698  offset =
699  DumpDataExtractor(DE, s, offset, eFormatDecimal, 1, item_byte_size,
700  item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
701  s->PutChar('}');
702  break;
703 
705  s->PutChar('{');
706  offset = DumpDataExtractor(DE, s, offset, eFormatHex, 1, item_byte_size,
707  item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
708  s->PutChar('}');
709  break;
710 
712  s->PutChar('{');
713  offset = DumpDataExtractor(
714  DE, s, offset, eFormatDecimal, sizeof(uint16_t),
715  item_byte_size / sizeof(uint16_t), item_byte_size / sizeof(uint16_t),
716  LLDB_INVALID_ADDRESS, 0, 0);
717  s->PutChar('}');
718  break;
719 
721  s->PutChar('{');
722  offset = DumpDataExtractor(DE, s, offset, eFormatHex, sizeof(uint16_t),
723  item_byte_size / sizeof(uint16_t),
724  item_byte_size / sizeof(uint16_t),
725  LLDB_INVALID_ADDRESS, 0, 0);
726  s->PutChar('}');
727  break;
728 
730  s->PutChar('{');
731  offset = DumpDataExtractor(
732  DE, s, offset, eFormatDecimal, sizeof(uint32_t),
733  item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t),
734  LLDB_INVALID_ADDRESS, 0, 0);
735  s->PutChar('}');
736  break;
737 
739  s->PutChar('{');
740  offset = DumpDataExtractor(DE, s, offset, eFormatHex, sizeof(uint32_t),
741  item_byte_size / sizeof(uint32_t),
742  item_byte_size / sizeof(uint32_t),
743  LLDB_INVALID_ADDRESS, 0, 0);
744  s->PutChar('}');
745  break;
746 
748  s->PutChar('{');
749  offset = DumpDataExtractor(
750  DE, s, offset, eFormatDecimal, sizeof(uint64_t),
751  item_byte_size / sizeof(uint64_t), item_byte_size / sizeof(uint64_t),
752  LLDB_INVALID_ADDRESS, 0, 0);
753  s->PutChar('}');
754  break;
755 
757  s->PutChar('{');
758  offset = DumpDataExtractor(DE, s, offset, eFormatHex, sizeof(uint64_t),
759  item_byte_size / sizeof(uint64_t),
760  item_byte_size / sizeof(uint64_t),
761  LLDB_INVALID_ADDRESS, 0, 0);
762  s->PutChar('}');
763  break;
764 
766  s->PutChar('{');
767  offset =
768  DumpDataExtractor(DE, s, offset, eFormatFloat, 2, item_byte_size / 2,
769  item_byte_size / 2, LLDB_INVALID_ADDRESS, 0, 0);
770  s->PutChar('}');
771  break;
772 
774  s->PutChar('{');
775  offset =
776  DumpDataExtractor(DE, s, offset, eFormatFloat, 4, item_byte_size / 4,
777  item_byte_size / 4, LLDB_INVALID_ADDRESS, 0, 0);
778  s->PutChar('}');
779  break;
780 
782  s->PutChar('{');
783  offset =
784  DumpDataExtractor(DE, s, offset, eFormatFloat, 8, item_byte_size / 8,
785  item_byte_size / 8, LLDB_INVALID_ADDRESS, 0, 0);
786  s->PutChar('}');
787  break;
788 
790  s->PutChar('{');
791  offset =
792  DumpDataExtractor(DE, s, offset, eFormatHex, 16, item_byte_size / 16,
793  item_byte_size / 16, LLDB_INVALID_ADDRESS, 0, 0);
794  s->PutChar('}');
795  break;
796  }
797  }
798 
799  if (item_format == eFormatBytesWithASCII && offset > line_start_offset) {
800  s->Printf("%*s", static_cast<int>(
801  (num_per_line - (offset - line_start_offset)) * 3 + 2),
802  "");
803  DumpDataExtractor(DE, s, line_start_offset, eFormatCharPrintable, 1,
804  offset - line_start_offset, SIZE_MAX,
805  LLDB_INVALID_ADDRESS, 0, 0);
806  }
807  return offset; // Return the offset at which we ended up
808 }
809 
810 void lldb_private::DumpHexBytes(Stream *s, const void *src, size_t src_len,
811  uint32_t bytes_per_line,
812  lldb::addr_t base_addr) {
813  DataExtractor data(src, src_len, lldb::eByteOrderLittle, 4);
814  DumpDataExtractor(data, s,
815  0, // Offset into "src"
816  lldb::eFormatBytes, // Dump as hex bytes
817  1, // Size of each item is 1 for single bytes
818  src_len, // Number of bytes
819  bytes_per_line, // Num bytes per line
820  base_addr, // Base address
821  0, 0); // Bitfield info
822 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
lldb_private::DataExtractor::getTargetByteSize
uint32_t getTargetByteSize() const
Definition: DataExtractor.h:170
lldb::eFormatVectorOfUInt64
@ eFormatVectorOfUInt64
Definition: lldb-enumerations.h:187
lldb::eFormatOSType
@ eFormatOSType
OS character codes encoded into an integer 'PICT' 'text' etc...
Definition: lldb-enumerations.h:173
lldb::eFormatPointer
@ eFormatPointer
Definition: lldb-enumerations.h:178
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::Stream::GetAddressByteSize
uint32_t GetAddressByteSize() const
Get the address size in bytes.
Definition: Stream.cpp:179
lldb::eFormatVectorOfChar
@ eFormatVectorOfChar
Definition: lldb-enumerations.h:179
lldb::eFormatVectorOfUInt128
@ eFormatVectorOfUInt128
Definition: lldb-enumerations.h:191
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::DataExtractor::ValidOffset
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:956
lldb-defines.h
lldb_private::Disassembler::FindPlugin
static lldb::DisassemblerSP FindPlugin(const ArchSpec &arch, const char *flavor, const char *plugin_name)
Definition: Disassembler.cpp:58
lldb::eFormatInstruction
@ eFormatInstruction
Disassemble an opcode.
Definition: lldb-enumerations.h:199
lldb::eFormatVectorOfSInt16
@ eFormatVectorOfSInt16
Definition: lldb-enumerations.h:182
lldb::eFormatVectorOfSInt32
@ eFormatVectorOfSInt32
Definition: lldb-enumerations.h:184
lldb::eFormatBoolean
@ eFormatBoolean
Definition: lldb-enumerations.h:158
SectionLoadList.h
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
Disassembler.h
lldb_private::Stream
Definition: Stream.h:28
lldb::eFormatBytesWithASCII
@ eFormatBytesWithASCII
Definition: lldb-enumerations.h:161
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::DataExtractor::GetU64
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
Definition: DataExtractor.cpp:476
ABI.h
Process.h
lldb::eFormatVectorOfSInt8
@ eFormatVectorOfSInt8
Definition: lldb-enumerations.h:180
Target.h
lldb::eFormatBytes
@ eFormatBytes
Definition: lldb-enumerations.h:160
lldb_private::DumpHexBytes
void DumpHexBytes(Stream *s, const void *src, size_t src_len, uint32_t bytes_per_line, lldb::addr_t base_addr)
Definition: DumpDataExtractor.cpp:810
lldb::eFormatVectorOfFloat64
@ eFormatVectorOfFloat64
Definition: lldb-enumerations.h:190
lldb::eFormatVectorOfUInt32
@ eFormatVectorOfUInt32
Definition: lldb-enumerations.h:185
ModuleList.h
LLDB_INVALID_OFFSET
#define LLDB_INVALID_OFFSET
Definition: lldb-defines.h:97
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::DumpAddress
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address value to this stream.
Definition: Stream.cpp:81
DumpCharacter
static void DumpCharacter(Stream &s, const char c)
Dump the character to a stream.
Definition: DumpDataExtractor.cpp:223
DumpFloatingPoint
void DumpFloatingPoint(std::ostringstream &ss, FloatT f)
Dump a floating point type.
Definition: DumpDataExtractor.cpp:235
lldb_private::DataExtractor::GetDouble
double GetDouble(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:628
lldb_private::DataExtractor::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
Definition: DataExtractor.h:594
lldb_private::DataExtractor::GetU8
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:318
lldb::eFormatDecimal
@ eFormatDecimal
Definition: lldb-enumerations.h:167
lldb::eFormatVectorOfUInt16
@ eFormatVectorOfUInt16
Definition: lldb-enumerations.h:183
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::DataExtractor::GetFloat
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
Definition: DataExtractor.cpp:624
NON_PRINTABLE_CHAR
#define NON_PRINTABLE_CHAR
Definition: DumpDataExtractor.cpp:48
lldb_private::Stream::PutChar
size_t PutChar(char ch)
Definition: Stream.cpp:104
Address.h
DumpDataExtractor.h
lldb_private::Address::DumpStyleModuleWithFileAddress
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition: Address.h:90
GetAPInt
static llvm::Optional< llvm::APInt > GetAPInt(const DataExtractor &data, lldb::offset_t *offset_ptr, lldb::offset_t byte_size)
Definition: DumpDataExtractor.cpp:69
lldb::eFormatVectorOfFloat16
@ eFormatVectorOfFloat16
Definition: lldb-enumerations.h:188
lldb::eFormatChar
@ eFormatChar
Definition: lldb-enumerations.h:162
lldb_private::Address::SetRawAddress
void SetRawAddress(lldb::addr_t addr)
Definition: Address.h:435
lldb::eFormatHexFloat
@ eFormatHexFloat
ISO C99 hex float string.
Definition: lldb-enumerations.h:198
half2float
static float half2float(uint16_t half)
Definition: DumpDataExtractor.cpp:50
lldb::eFormatUnicode16
@ eFormatUnicode16
Definition: lldb-enumerations.h:175
lldb::eFormatUnsigned
@ eFormatUnsigned
Definition: lldb-enumerations.h:177
lldb_private::Address::DumpStyleResolvedDescription
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
Definition: Address.h:101
uint32_t
DumpInstructions
static lldb::offset_t DumpInstructions(const DataExtractor &DE, Stream *s, ExecutionContextScope *exe_scope, offset_t start_offset, uint64_t base_addr, size_t number_of_instructions)
Dumps decoded instructions to a stream.
Definition: DumpDataExtractor.cpp:136
lldb_private::Address
Definition: Address.h:59
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:526
lldb::eFormatCString
@ eFormatCString
NULL terminated C strings.
Definition: lldb-enumerations.h:166
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
ExecutionContextScope.h
lldb::eFormatVectorOfSInt64
@ eFormatVectorOfSInt64
Definition: lldb-enumerations.h:186
DumpAPInt
static lldb::offset_t DumpAPInt(Stream *s, const DataExtractor &data, lldb::offset_t offset, lldb::offset_t byte_size, bool is_signed, unsigned radix)
Definition: DumpDataExtractor.cpp:114
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
lldb::eFormatCharPrintable
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
Definition: lldb-enumerations.h:163
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:603
lldb_private::Address::Dump
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX) const
Dump a description of this object to a Stream.
Definition: Address.cpp:405
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:427
lldb::eFormatCharArray
@ eFormatCharArray
Print characters with no single quotes, used for character arrays that can contain non printable char...
Definition: lldb-enumerations.h:193
lldb_private::Address::SetOffset
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition: Address.h:429
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
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_private::DumpDataExtractor
lldb::offset_t DumpDataExtractor(const DataExtractor &DE, Stream *s, lldb::offset_t offset, lldb::Format item_format, size_t item_byte_size, size_t item_count, size_t num_per_line, uint64_t base_addr, uint32_t item_bit_size, uint32_t item_bit_offset, ExecutionContextScope *exe_scope=nullptr)
Dumps item_count objects into the stream s.
Definition: DumpDataExtractor.cpp:256
lldb-forward.h
lldb::eFormatBinary
@ eFormatBinary
Definition: lldb-enumerations.h:159
lldb::eFormatComplexInteger
@ eFormatComplexInteger
Integer complex type.
Definition: lldb-enumerations.h:192
lldb_private::ExecutionContextScope::CalculateProcess
virtual lldb::ProcessSP CalculateProcess()=0
lldb::eLanguageTypeC
@ eLanguageTypeC
Non-standardized C, such as K&R.
Definition: lldb-enumerations.h:439
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:575
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:349
lldb_private::DataExtractor::GetLongDouble
long double GetLongDouble(lldb::offset_t *offset_ptr) const
Definition: DataExtractor.cpp:632
lldb::eFormatHex
@ eFormatHex
Definition: lldb-enumerations.h:169
lldb_private::DataExtractor::GetCStr
const char * GetCStr(lldb::offset_t *offset_ptr) const
Extract a C string from *offset_ptr.
Definition: DataExtractor.cpp:786
lldb_private::ExecutionContextScope::CalculateTarget
virtual lldb::TargetSP CalculateTarget()=0
lldb::eFormatUnicode32
@ eFormatUnicode32
Definition: lldb-enumerations.h:176
lldb::eFormatEnum
@ eFormatEnum
Definition: lldb-enumerations.h:168
lldb::eByteOrderBig
@ eByteOrderBig
Definition: lldb-enumerations.h:140
lldb_private::Stream::Write
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition: Stream.h:101
lldb_private::DataExtractor::GetData
const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
Definition: DataExtractor.h:337
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::Address::DumpStyleResolvedPointerDescription
@ DumpStyleResolvedPointerDescription
Dereference a pointer at the current address and then lookup the dereferenced address using DumpStyle...
Definition: Address.h:112
lldb::eFormatVectorOfFloat32
@ eFormatVectorOfFloat32
Definition: lldb-enumerations.h:189
lldb_private::bits
static uint32_t bits(const uint32_t val, const uint32_t msbit, const uint32_t lsbit)
Definition: ARMUtils.h:264
lldb_private::ExecutionContextScope::CalculateExecutionContext
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
lldb::eFormatFloat
@ eFormatFloat
Definition: lldb-enumerations.h:171
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
TryDumpSpecialEscapedChar
static bool TryDumpSpecialEscapedChar(Stream &s, const char c)
Prints the specific escape sequence of the given character to the stream.
Definition: DumpDataExtractor.cpp:186
lldb
Definition: SBAddress.h:15
lldb::eFormatAddressInfo
@ eFormatAddressInfo
Describe what an address points to (func + offset.
Definition: lldb-enumerations.h:196
lldb::eFormatVectorOfUInt8
@ eFormatVectorOfUInt8
Definition: lldb-enumerations.h:181
lldb::eFormatDefault
@ eFormatDefault
Definition: lldb-enumerations.h:156
ExecutionContext.h
lldb::eFormatComplex
@ eFormatComplex
Floating point complex type.
Definition: lldb-enumerations.h:164
lldb::eFormatOctal
@ eFormatOctal
Definition: lldb-enumerations.h:172
lldb::eFormatHexUppercase
@ eFormatHexUppercase
Definition: lldb-enumerations.h:170
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138