1 //===-- DumpDataExtractor.cpp -----------------------------------*- C++ -*-===// 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 9 #include "lldb/Core/DumpDataExtractor.h" 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/Symbol/ClangASTContext.h" 18 #include "lldb/Target/ExecutionContext.h" 19 #include "lldb/Target/ExecutionContextScope.h" 20 #include "lldb/Target/SectionLoadList.h" 21 #include "lldb/Target/Target.h" 22 #include "lldb/Utility/DataExtractor.h" 23 #include "lldb/Utility/Log.h" 24 #include "lldb/Utility/Stream.h" 25 26 #include "clang/AST/ASTContext.h" 27 #include "clang/AST/CanonicalType.h" 28 29 #include "llvm/ADT/APFloat.h" 30 #include "llvm/ADT/APInt.h" 31 #include "llvm/ADT/ArrayRef.h" 32 #include "llvm/ADT/Optional.h" 33 #include "llvm/ADT/SmallVector.h" 34 35 #include <limits> 36 #include <memory> 37 #include <string> 38 39 #include <assert.h> 40 #include <ctype.h> 41 #include <inttypes.h> 42 #include <math.h> 43 44 #include <bitset> 45 #include <sstream> 46 47 using namespace lldb_private; 48 using namespace lldb; 49 50 #define NON_PRINTABLE_CHAR '.' 51 52 static float half2float(uint16_t half) { 53 union { 54 float f; 55 uint32_t u; 56 } u; 57 int32_t v = (int16_t)half; 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 llvm::SmallVector<uint64_t, 2> uint64_array; 73 lldb::offset_t bytes_left = byte_size; 74 uint64_t u64; 75 const lldb::ByteOrder byte_order = data.GetByteOrder(); 76 if (byte_order == lldb::eByteOrderLittle) { 77 while (bytes_left > 0) { 78 if (bytes_left >= 8) { 79 u64 = data.GetU64(offset_ptr); 80 bytes_left -= 8; 81 } else { 82 u64 = data.GetMaxU64(offset_ptr, (uint32_t)bytes_left); 83 bytes_left = 0; 84 } 85 uint64_array.push_back(u64); 86 } 87 return llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array)); 88 } else if (byte_order == lldb::eByteOrderBig) { 89 lldb::offset_t be_offset = *offset_ptr + byte_size; 90 lldb::offset_t temp_offset; 91 while (bytes_left > 0) { 92 if (bytes_left >= 8) { 93 be_offset -= 8; 94 temp_offset = be_offset; 95 u64 = data.GetU64(&temp_offset); 96 bytes_left -= 8; 97 } else { 98 be_offset -= bytes_left; 99 temp_offset = be_offset; 100 u64 = data.GetMaxU64(&temp_offset, (uint32_t)bytes_left); 101 bytes_left = 0; 102 } 103 uint64_array.push_back(u64); 104 } 105 *offset_ptr += byte_size; 106 return llvm::APInt(byte_size * 8, llvm::ArrayRef<uint64_t>(uint64_array)); 107 } 108 return llvm::None; 109 } 110 111 static lldb::offset_t DumpAPInt(Stream *s, const DataExtractor &data, 112 lldb::offset_t offset, lldb::offset_t byte_size, 113 bool is_signed, unsigned radix) { 114 llvm::Optional<llvm::APInt> apint = GetAPInt(data, &offset, byte_size); 115 if (apint.hasValue()) { 116 std::string apint_str(apint.getValue().toString(radix, is_signed)); 117 switch (radix) { 118 case 2: 119 s->Write("0b", 2); 120 break; 121 case 8: 122 s->Write("0", 1); 123 break; 124 case 10: 125 break; 126 } 127 s->Write(apint_str.c_str(), apint_str.size()); 128 } 129 return offset; 130 } 131 132 lldb::offset_t lldb_private::DumpDataExtractor( 133 const DataExtractor &DE, Stream *s, offset_t start_offset, 134 lldb::Format item_format, size_t item_byte_size, size_t item_count, 135 size_t num_per_line, uint64_t base_addr, 136 uint32_t item_bit_size, // If zero, this is not a bitfield value, if 137 // non-zero, the value is a bitfield 138 uint32_t item_bit_offset, // If "item_bit_size" is non-zero, this is the 139 // shift amount to apply to a bitfield 140 ExecutionContextScope *exe_scope) { 141 if (s == nullptr) 142 return start_offset; 143 144 if (item_format == eFormatPointer) { 145 if (item_byte_size != 4 && item_byte_size != 8) 146 item_byte_size = s->GetAddressByteSize(); 147 } 148 149 offset_t offset = start_offset; 150 151 if (item_format == eFormatInstruction) { 152 TargetSP target_sp; 153 if (exe_scope) 154 target_sp = exe_scope->CalculateTarget(); 155 if (target_sp) { 156 DisassemblerSP disassembler_sp(Disassembler::FindPlugin( 157 target_sp->GetArchitecture(), 158 target_sp->GetDisassemblyFlavor(), nullptr)); 159 if (disassembler_sp) { 160 lldb::addr_t addr = base_addr + start_offset; 161 lldb_private::Address so_addr; 162 bool data_from_file = true; 163 if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { 164 data_from_file = false; 165 } else { 166 if (target_sp->GetSectionLoadList().IsEmpty() || 167 !target_sp->GetImages().ResolveFileAddress(addr, so_addr)) 168 so_addr.SetRawAddress(addr); 169 } 170 171 size_t bytes_consumed = disassembler_sp->DecodeInstructions( 172 so_addr, DE, start_offset, item_count, false, data_from_file); 173 174 if (bytes_consumed) { 175 offset += bytes_consumed; 176 const bool show_address = base_addr != LLDB_INVALID_ADDRESS; 177 const bool show_bytes = true; 178 ExecutionContext exe_ctx; 179 exe_scope->CalculateExecutionContext(exe_ctx); 180 disassembler_sp->GetInstructionList().Dump(s, show_address, 181 show_bytes, &exe_ctx); 182 } 183 } 184 } else 185 s->Printf("invalid target"); 186 187 return offset; 188 } 189 190 if ((item_format == eFormatOSType || item_format == eFormatAddressInfo) && 191 item_byte_size > 8) 192 item_format = eFormatHex; 193 194 lldb::offset_t line_start_offset = start_offset; 195 for (uint32_t count = 0; DE.ValidOffset(offset) && count < item_count; 196 ++count) { 197 if ((count % num_per_line) == 0) { 198 if (count > 0) { 199 if (item_format == eFormatBytesWithASCII && 200 offset > line_start_offset) { 201 s->Printf("%*s", 202 static_cast<int>( 203 (num_per_line - (offset - line_start_offset)) * 3 + 2), 204 ""); 205 DumpDataExtractor(DE, s, line_start_offset, eFormatCharPrintable, 1, 206 offset - line_start_offset, SIZE_MAX, 207 LLDB_INVALID_ADDRESS, 0, 0); 208 } 209 s->EOL(); 210 } 211 if (base_addr != LLDB_INVALID_ADDRESS) 212 s->Printf("0x%8.8" PRIx64 ": ", 213 (uint64_t)(base_addr + 214 (offset - start_offset) / DE.getTargetByteSize())); 215 216 line_start_offset = offset; 217 } else if (item_format != eFormatChar && 218 item_format != eFormatCharPrintable && 219 item_format != eFormatCharArray && count > 0) { 220 s->PutChar(' '); 221 } 222 223 switch (item_format) { 224 case eFormatBoolean: 225 if (item_byte_size <= 8) 226 s->Printf("%s", DE.GetMaxU64Bitfield(&offset, item_byte_size, 227 item_bit_size, item_bit_offset) 228 ? "true" 229 : "false"); 230 else { 231 s->Printf("error: unsupported byte size (%" PRIu64 232 ") for boolean format", 233 (uint64_t)item_byte_size); 234 return offset; 235 } 236 break; 237 238 case eFormatBinary: 239 if (item_byte_size <= 8) { 240 uint64_t uval64 = DE.GetMaxU64Bitfield(&offset, item_byte_size, 241 item_bit_size, item_bit_offset); 242 // Avoid std::bitset<64>::to_string() since it is missing in earlier 243 // C++ libraries 244 std::string binary_value(64, '0'); 245 std::bitset<64> bits(uval64); 246 for (uint32_t i = 0; i < 64; ++i) 247 if (bits[i]) 248 binary_value[64 - 1 - i] = '1'; 249 if (item_bit_size > 0) 250 s->Printf("0b%s", binary_value.c_str() + 64 - item_bit_size); 251 else if (item_byte_size > 0 && item_byte_size <= 8) 252 s->Printf("0b%s", binary_value.c_str() + 64 - item_byte_size * 8); 253 } else { 254 const bool is_signed = false; 255 const unsigned radix = 2; 256 offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix); 257 } 258 break; 259 260 case eFormatBytes: 261 case eFormatBytesWithASCII: 262 for (uint32_t i = 0; i < item_byte_size; ++i) { 263 s->Printf("%2.2x", DE.GetU8(&offset)); 264 } 265 266 // Put an extra space between the groups of bytes if more than one is 267 // being dumped in a group (item_byte_size is more than 1). 268 if (item_byte_size > 1) 269 s->PutChar(' '); 270 break; 271 272 case eFormatChar: 273 case eFormatCharPrintable: 274 case eFormatCharArray: { 275 // Reject invalid item_byte_size. 276 if (item_byte_size > 8) { 277 s->Printf("error: unsupported byte size (%" PRIu64 ") for char format", 278 (uint64_t)item_byte_size); 279 return offset; 280 } 281 282 // If we are only printing one character surround it with single quotes 283 if (item_count == 1 && item_format == eFormatChar) 284 s->PutChar('\''); 285 286 const uint64_t ch = DE.GetMaxU64Bitfield(&offset, item_byte_size, 287 item_bit_size, item_bit_offset); 288 if (isprint(ch)) 289 s->Printf("%c", (char)ch); 290 else if (item_format != eFormatCharPrintable) { 291 switch (ch) { 292 case '\033': 293 s->Printf("\\e"); 294 break; 295 case '\a': 296 s->Printf("\\a"); 297 break; 298 case '\b': 299 s->Printf("\\b"); 300 break; 301 case '\f': 302 s->Printf("\\f"); 303 break; 304 case '\n': 305 s->Printf("\\n"); 306 break; 307 case '\r': 308 s->Printf("\\r"); 309 break; 310 case '\t': 311 s->Printf("\\t"); 312 break; 313 case '\v': 314 s->Printf("\\v"); 315 break; 316 case '\0': 317 s->Printf("\\0"); 318 break; 319 default: 320 if (item_byte_size == 1) 321 s->Printf("\\x%2.2x", (uint8_t)ch); 322 else 323 s->Printf("%" PRIu64, ch); 324 break; 325 } 326 } else { 327 s->PutChar(NON_PRINTABLE_CHAR); 328 } 329 330 // If we are only printing one character surround it with single quotes 331 if (item_count == 1 && item_format == eFormatChar) 332 s->PutChar('\''); 333 } break; 334 335 case eFormatEnum: // Print enum value as a signed integer when we don't get 336 // the enum type 337 case eFormatDecimal: 338 if (item_byte_size <= 8) 339 s->Printf("%" PRId64, 340 DE.GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size, 341 item_bit_offset)); 342 else { 343 const bool is_signed = true; 344 const unsigned radix = 10; 345 offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix); 346 } 347 break; 348 349 case eFormatUnsigned: 350 if (item_byte_size <= 8) 351 s->Printf("%" PRIu64, 352 DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, 353 item_bit_offset)); 354 else { 355 const bool is_signed = false; 356 const unsigned radix = 10; 357 offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix); 358 } 359 break; 360 361 case eFormatOctal: 362 if (item_byte_size <= 8) 363 s->Printf("0%" PRIo64, 364 DE.GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size, 365 item_bit_offset)); 366 else { 367 const bool is_signed = false; 368 const unsigned radix = 8; 369 offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix); 370 } 371 break; 372 373 case eFormatOSType: { 374 uint64_t uval64 = DE.GetMaxU64Bitfield(&offset, item_byte_size, 375 item_bit_size, item_bit_offset); 376 s->PutChar('\''); 377 for (uint32_t i = 0; i < item_byte_size; ++i) { 378 uint8_t ch = (uint8_t)(uval64 >> ((item_byte_size - i - 1) * 8)); 379 if (isprint(ch)) 380 s->Printf("%c", ch); 381 else { 382 switch (ch) { 383 case '\033': 384 s->Printf("\\e"); 385 break; 386 case '\a': 387 s->Printf("\\a"); 388 break; 389 case '\b': 390 s->Printf("\\b"); 391 break; 392 case '\f': 393 s->Printf("\\f"); 394 break; 395 case '\n': 396 s->Printf("\\n"); 397 break; 398 case '\r': 399 s->Printf("\\r"); 400 break; 401 case '\t': 402 s->Printf("\\t"); 403 break; 404 case '\v': 405 s->Printf("\\v"); 406 break; 407 case '\0': 408 s->Printf("\\0"); 409 break; 410 default: 411 s->Printf("\\x%2.2x", ch); 412 break; 413 } 414 } 415 } 416 s->PutChar('\''); 417 } break; 418 419 case eFormatCString: { 420 const char *cstr = DE.GetCStr(&offset); 421 422 if (!cstr) { 423 s->Printf("NULL"); 424 offset = LLDB_INVALID_OFFSET; 425 } else { 426 s->PutChar('\"'); 427 428 while (const char c = *cstr) { 429 if (isprint(c)) { 430 s->PutChar(c); 431 } else { 432 switch (c) { 433 case '\033': 434 s->Printf("\\e"); 435 break; 436 case '\a': 437 s->Printf("\\a"); 438 break; 439 case '\b': 440 s->Printf("\\b"); 441 break; 442 case '\f': 443 s->Printf("\\f"); 444 break; 445 case '\n': 446 s->Printf("\\n"); 447 break; 448 case '\r': 449 s->Printf("\\r"); 450 break; 451 case '\t': 452 s->Printf("\\t"); 453 break; 454 case '\v': 455 s->Printf("\\v"); 456 break; 457 default: 458 s->Printf("\\x%2.2x", c); 459 break; 460 } 461 } 462 463 ++cstr; 464 } 465 466 s->PutChar('\"'); 467 } 468 } break; 469 470 case eFormatPointer: 471 s->Address(DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, 472 item_bit_offset), 473 sizeof(addr_t)); 474 break; 475 476 case eFormatComplexInteger: { 477 size_t complex_int_byte_size = item_byte_size / 2; 478 479 if (complex_int_byte_size > 0 && complex_int_byte_size <= 8) { 480 s->Printf("%" PRIu64, 481 DE.GetMaxU64Bitfield(&offset, complex_int_byte_size, 0, 0)); 482 s->Printf(" + %" PRIu64 "i", 483 DE.GetMaxU64Bitfield(&offset, complex_int_byte_size, 0, 0)); 484 } else { 485 s->Printf("error: unsupported byte size (%" PRIu64 486 ") for complex integer format", 487 (uint64_t)item_byte_size); 488 return offset; 489 } 490 } break; 491 492 case eFormatComplex: 493 if (sizeof(float) * 2 == item_byte_size) { 494 float f32_1 = DE.GetFloat(&offset); 495 float f32_2 = DE.GetFloat(&offset); 496 497 s->Printf("%g + %gi", f32_1, f32_2); 498 break; 499 } else if (sizeof(double) * 2 == item_byte_size) { 500 double d64_1 = DE.GetDouble(&offset); 501 double d64_2 = DE.GetDouble(&offset); 502 503 s->Printf("%lg + %lgi", d64_1, d64_2); 504 break; 505 } else if (sizeof(long double) * 2 == item_byte_size) { 506 long double ld64_1 = DE.GetLongDouble(&offset); 507 long double ld64_2 = DE.GetLongDouble(&offset); 508 s->Printf("%Lg + %Lgi", ld64_1, ld64_2); 509 break; 510 } else { 511 s->Printf("error: unsupported byte size (%" PRIu64 512 ") for complex float format", 513 (uint64_t)item_byte_size); 514 return offset; 515 } 516 break; 517 518 default: 519 case eFormatDefault: 520 case eFormatHex: 521 case eFormatHexUppercase: { 522 bool wantsuppercase = (item_format == eFormatHexUppercase); 523 switch (item_byte_size) { 524 case 1: 525 case 2: 526 case 4: 527 case 8: 528 s->Printf(wantsuppercase ? "0x%*.*" PRIX64 : "0x%*.*" PRIx64, 529 (int)(2 * item_byte_size), (int)(2 * item_byte_size), 530 DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, 531 item_bit_offset)); 532 break; 533 default: { 534 assert(item_bit_size == 0 && item_bit_offset == 0); 535 const uint8_t *bytes = 536 (const uint8_t *)DE.GetData(&offset, item_byte_size); 537 if (bytes) { 538 s->PutCString("0x"); 539 uint32_t idx; 540 if (DE.GetByteOrder() == eByteOrderBig) { 541 for (idx = 0; idx < item_byte_size; ++idx) 542 s->Printf(wantsuppercase ? "%2.2X" : "%2.2x", bytes[idx]); 543 } else { 544 for (idx = 0; idx < item_byte_size; ++idx) 545 s->Printf(wantsuppercase ? "%2.2X" : "%2.2x", 546 bytes[item_byte_size - 1 - idx]); 547 } 548 } 549 } break; 550 } 551 } break; 552 553 case eFormatFloat: { 554 TargetSP target_sp; 555 bool used_upfloat = false; 556 if (exe_scope) 557 target_sp = exe_scope->CalculateTarget(); 558 if (target_sp) { 559 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 560 if (clang_ast) { 561 clang::ASTContext *ast = clang_ast->getASTContext(); 562 if (ast) { 563 llvm::SmallVector<char, 256> sv; 564 // Show full precision when printing float values 565 const unsigned format_precision = 0; 566 const unsigned format_max_padding = 567 target_sp->GetMaxZeroPaddingInFloatFormat(); 568 size_t item_bit_size = item_byte_size * 8; 569 570 if (item_bit_size == ast->getTypeSize(ast->FloatTy)) { 571 llvm::Optional<llvm::APInt> apint = 572 GetAPInt(DE, &offset, item_byte_size); 573 if (apint.hasValue()) { 574 llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->FloatTy), 575 apint.getValue()); 576 apfloat.toString(sv, format_precision, format_max_padding); 577 } 578 } else if (item_bit_size == ast->getTypeSize(ast->DoubleTy)) { 579 llvm::Optional<llvm::APInt> apint = 580 GetAPInt(DE, &offset, item_byte_size); 581 if (apint.hasValue()) { 582 llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->DoubleTy), 583 apint.getValue()); 584 apfloat.toString(sv, format_precision, format_max_padding); 585 } 586 } else if (item_bit_size == ast->getTypeSize(ast->LongDoubleTy)) { 587 const auto &semantics = 588 ast->getFloatTypeSemantics(ast->LongDoubleTy); 589 590 offset_t byte_size = item_byte_size; 591 if (&semantics == &llvm::APFloatBase::x87DoubleExtended()) 592 byte_size = (llvm::APFloat::getSizeInBits(semantics) + 7) / 8; 593 594 llvm::Optional<llvm::APInt> apint = 595 GetAPInt(DE, &offset, byte_size); 596 if (apint.hasValue()) { 597 llvm::APFloat apfloat(semantics, apint.getValue()); 598 apfloat.toString(sv, format_precision, format_max_padding); 599 } 600 } else if (item_bit_size == ast->getTypeSize(ast->HalfTy)) { 601 llvm::Optional<llvm::APInt> apint = 602 GetAPInt(DE, &offset, item_byte_size); 603 if (apint.hasValue()) { 604 llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->HalfTy), 605 apint.getValue()); 606 apfloat.toString(sv, format_precision, format_max_padding); 607 } 608 } 609 610 if (!sv.empty()) { 611 s->Printf("%*.*s", (int)sv.size(), (int)sv.size(), sv.data()); 612 used_upfloat = true; 613 } 614 } 615 } 616 } 617 618 if (!used_upfloat) { 619 std::ostringstream ss; 620 if (item_byte_size == sizeof(float) || item_byte_size == 2) { 621 float f; 622 if (item_byte_size == 2) { 623 uint16_t half = DE.GetU16(&offset); 624 f = half2float(half); 625 } else { 626 f = DE.GetFloat(&offset); 627 } 628 ss.precision(std::numeric_limits<float>::digits10); 629 ss << f; 630 } else if (item_byte_size == sizeof(double)) { 631 ss.precision(std::numeric_limits<double>::digits10); 632 ss << DE.GetDouble(&offset); 633 } else if (item_byte_size == sizeof(long double) || 634 item_byte_size == 10) { 635 ss.precision(std::numeric_limits<long double>::digits10); 636 ss << DE.GetLongDouble(&offset); 637 } else { 638 s->Printf("error: unsupported byte size (%" PRIu64 639 ") for float format", 640 (uint64_t)item_byte_size); 641 return offset; 642 } 643 ss.flush(); 644 s->Printf("%s", ss.str().c_str()); 645 } 646 } break; 647 648 case eFormatUnicode16: 649 s->Printf("U+%4.4x", DE.GetU16(&offset)); 650 break; 651 652 case eFormatUnicode32: 653 s->Printf("U+0x%8.8x", DE.GetU32(&offset)); 654 break; 655 656 case eFormatAddressInfo: { 657 addr_t addr = DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, 658 item_bit_offset); 659 s->Printf("0x%*.*" PRIx64, (int)(2 * item_byte_size), 660 (int)(2 * item_byte_size), addr); 661 if (exe_scope) { 662 TargetSP target_sp(exe_scope->CalculateTarget()); 663 lldb_private::Address so_addr; 664 if (target_sp) { 665 if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr, 666 so_addr)) { 667 s->PutChar(' '); 668 so_addr.Dump(s, exe_scope, Address::DumpStyleResolvedDescription, 669 Address::DumpStyleModuleWithFileAddress); 670 } else { 671 so_addr.SetOffset(addr); 672 so_addr.Dump(s, exe_scope, 673 Address::DumpStyleResolvedPointerDescription); 674 } 675 } 676 } 677 } break; 678 679 case eFormatHexFloat: 680 if (sizeof(float) == item_byte_size) { 681 char float_cstr[256]; 682 llvm::APFloat ap_float(DE.GetFloat(&offset)); 683 ap_float.convertToHexString(float_cstr, 0, false, 684 llvm::APFloat::rmNearestTiesToEven); 685 s->Printf("%s", float_cstr); 686 break; 687 } else if (sizeof(double) == item_byte_size) { 688 char float_cstr[256]; 689 llvm::APFloat ap_float(DE.GetDouble(&offset)); 690 ap_float.convertToHexString(float_cstr, 0, false, 691 llvm::APFloat::rmNearestTiesToEven); 692 s->Printf("%s", float_cstr); 693 break; 694 } else { 695 s->Printf("error: unsupported byte size (%" PRIu64 696 ") for hex float format", 697 (uint64_t)item_byte_size); 698 return offset; 699 } 700 break; 701 702 // please keep the single-item formats below in sync with 703 // FormatManager::GetSingleItemFormat if you fail to do so, users will 704 // start getting different outputs depending on internal implementation 705 // details they should not care about || 706 case eFormatVectorOfChar: // || 707 s->PutChar('{'); // \/ 708 offset = 709 DumpDataExtractor(DE, s, offset, eFormatCharArray, 1, item_byte_size, 710 item_byte_size, LLDB_INVALID_ADDRESS, 0, 0); 711 s->PutChar('}'); 712 break; 713 714 case eFormatVectorOfSInt8: 715 s->PutChar('{'); 716 offset = 717 DumpDataExtractor(DE, s, offset, eFormatDecimal, 1, item_byte_size, 718 item_byte_size, LLDB_INVALID_ADDRESS, 0, 0); 719 s->PutChar('}'); 720 break; 721 722 case eFormatVectorOfUInt8: 723 s->PutChar('{'); 724 offset = DumpDataExtractor(DE, s, offset, eFormatHex, 1, item_byte_size, 725 item_byte_size, LLDB_INVALID_ADDRESS, 0, 0); 726 s->PutChar('}'); 727 break; 728 729 case eFormatVectorOfSInt16: 730 s->PutChar('{'); 731 offset = DumpDataExtractor( 732 DE, s, offset, eFormatDecimal, sizeof(uint16_t), 733 item_byte_size / sizeof(uint16_t), item_byte_size / sizeof(uint16_t), 734 LLDB_INVALID_ADDRESS, 0, 0); 735 s->PutChar('}'); 736 break; 737 738 case eFormatVectorOfUInt16: 739 s->PutChar('{'); 740 offset = DumpDataExtractor(DE, s, offset, eFormatHex, sizeof(uint16_t), 741 item_byte_size / sizeof(uint16_t), 742 item_byte_size / sizeof(uint16_t), 743 LLDB_INVALID_ADDRESS, 0, 0); 744 s->PutChar('}'); 745 break; 746 747 case eFormatVectorOfSInt32: 748 s->PutChar('{'); 749 offset = DumpDataExtractor( 750 DE, s, offset, eFormatDecimal, sizeof(uint32_t), 751 item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), 752 LLDB_INVALID_ADDRESS, 0, 0); 753 s->PutChar('}'); 754 break; 755 756 case eFormatVectorOfUInt32: 757 s->PutChar('{'); 758 offset = DumpDataExtractor(DE, s, offset, eFormatHex, sizeof(uint32_t), 759 item_byte_size / sizeof(uint32_t), 760 item_byte_size / sizeof(uint32_t), 761 LLDB_INVALID_ADDRESS, 0, 0); 762 s->PutChar('}'); 763 break; 764 765 case eFormatVectorOfSInt64: 766 s->PutChar('{'); 767 offset = DumpDataExtractor( 768 DE, s, offset, eFormatDecimal, sizeof(uint64_t), 769 item_byte_size / sizeof(uint64_t), item_byte_size / sizeof(uint64_t), 770 LLDB_INVALID_ADDRESS, 0, 0); 771 s->PutChar('}'); 772 break; 773 774 case eFormatVectorOfUInt64: 775 s->PutChar('{'); 776 offset = DumpDataExtractor(DE, s, offset, eFormatHex, sizeof(uint64_t), 777 item_byte_size / sizeof(uint64_t), 778 item_byte_size / sizeof(uint64_t), 779 LLDB_INVALID_ADDRESS, 0, 0); 780 s->PutChar('}'); 781 break; 782 783 case eFormatVectorOfFloat16: 784 s->PutChar('{'); 785 offset = 786 DumpDataExtractor(DE, s, offset, eFormatFloat, 2, item_byte_size / 2, 787 item_byte_size / 2, LLDB_INVALID_ADDRESS, 0, 0); 788 s->PutChar('}'); 789 break; 790 791 case eFormatVectorOfFloat32: 792 s->PutChar('{'); 793 offset = 794 DumpDataExtractor(DE, s, offset, eFormatFloat, 4, item_byte_size / 4, 795 item_byte_size / 4, LLDB_INVALID_ADDRESS, 0, 0); 796 s->PutChar('}'); 797 break; 798 799 case eFormatVectorOfFloat64: 800 s->PutChar('{'); 801 offset = 802 DumpDataExtractor(DE, s, offset, eFormatFloat, 8, item_byte_size / 8, 803 item_byte_size / 8, LLDB_INVALID_ADDRESS, 0, 0); 804 s->PutChar('}'); 805 break; 806 807 case eFormatVectorOfUInt128: 808 s->PutChar('{'); 809 offset = 810 DumpDataExtractor(DE, s, offset, eFormatHex, 16, item_byte_size / 16, 811 item_byte_size / 16, LLDB_INVALID_ADDRESS, 0, 0); 812 s->PutChar('}'); 813 break; 814 } 815 } 816 817 if (item_format == eFormatBytesWithASCII && offset > line_start_offset) { 818 s->Printf("%*s", static_cast<int>( 819 (num_per_line - (offset - line_start_offset)) * 3 + 2), 820 ""); 821 DumpDataExtractor(DE, s, line_start_offset, eFormatCharPrintable, 1, 822 offset - line_start_offset, SIZE_MAX, 823 LLDB_INVALID_ADDRESS, 0, 0); 824 } 825 return offset; // Return the offset at which we ended up 826 } 827 828 void lldb_private::DumpHexBytes(Stream *s, const void *src, size_t src_len, 829 uint32_t bytes_per_line, 830 lldb::addr_t base_addr) { 831 DataExtractor data(src, src_len, lldb::eByteOrderLittle, 4); 832 DumpDataExtractor(data, s, 833 0, // Offset into "src" 834 lldb::eFormatBytes, // Dump as hex bytes 835 1, // Size of each item is 1 for single bytes 836 src_len, // Number of bytes 837 bytes_per_line, // Num bytes per line 838 base_addr, // Base address 839 0, 0); // Bitfield info 840 } 841