|
14 | 14 | #include "lldb/Core/Address.h" |
15 | 15 | #include "lldb/Core/Disassembler.h" |
16 | 16 | #include "lldb/Core/ModuleList.h" |
17 | | -#include "lldb/Symbol/ClangASTContext.h" |
18 | 17 | #include "lldb/Target/ExecutionContext.h" |
19 | 18 | #include "lldb/Target/ExecutionContextScope.h" |
20 | 19 | #include "lldb/Target/SectionLoadList.h" |
@@ -69,6 +68,9 @@ static float half2float(uint16_t half) { |
69 | 68 | static llvm::Optional<llvm::APInt> GetAPInt(const DataExtractor &data, |
70 | 69 | lldb::offset_t *offset_ptr, |
71 | 70 | lldb::offset_t byte_size) { |
| 71 | + if (byte_size == 0) |
| 72 | + return llvm::None; |
| 73 | + |
72 | 74 | llvm::SmallVector<uint64_t, 2> uint64_array; |
73 | 75 | lldb::offset_t bytes_left = byte_size; |
74 | 76 | uint64_t u64; |
@@ -556,57 +558,31 @@ lldb::offset_t lldb_private::DumpDataExtractor( |
556 | 558 | if (exe_scope) |
557 | 559 | target_sp = exe_scope->CalculateTarget(); |
558 | 560 | 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 | | - |
| 561 | + auto type_system_or_err = |
| 562 | + target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC); |
| 563 | + if (!type_system_or_err) { |
| 564 | + llvm::consumeError(type_system_or_err.takeError()); |
| 565 | + } else { |
| 566 | + auto &type_system = *type_system_or_err; |
| 567 | + llvm::SmallVector<char, 256> sv; |
| 568 | + // Show full precision when printing float values |
| 569 | + const unsigned format_precision = 0; |
| 570 | + const unsigned format_max_padding = |
| 571 | + target_sp->GetMaxZeroPaddingInFloatFormat(); |
| 572 | + |
| 573 | + const auto &semantics = |
| 574 | + type_system.GetFloatTypeSemantics(item_byte_size); |
| 575 | + |
| 576 | + // Recalculate the byte size in case of a difference. This is possible |
| 577 | + // when item_byte_size is 16 (128-bit), because you could get back the |
| 578 | + // x87DoubleExtended semantics which has a byte size of 10 (80-bit). |
| 579 | + const size_t semantics_byte_size = |
| 580 | + (llvm::APFloat::getSizeInBits(semantics) + 7) / 8; |
| 581 | + llvm::Optional<llvm::APInt> apint = |
| 582 | + GetAPInt(DE, &offset, semantics_byte_size); |
| 583 | + if (apint.hasValue()) { |
| 584 | + llvm::APFloat apfloat(semantics, apint.getValue()); |
| 585 | + apfloat.toString(sv, format_precision, format_max_padding); |
610 | 586 | if (!sv.empty()) { |
611 | 587 | s->Printf("%*.*s", (int)sv.size(), (int)sv.size(), sv.data()); |
612 | 588 | used_upfloat = true; |
|
0 commit comments