[Lldb-commits] [lldb] r371258 - [Core] Remove use of ClangASTContext in DumpDataExtractor
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 6 14:05:22 PDT 2019
Author: xiaobai
Date: Fri Sep 6 14:05:21 2019
New Revision: 371258
URL: http://llvm.org/viewvc/llvm-project?rev=371258&view=rev
Log:
[Core] Remove use of ClangASTContext in DumpDataExtractor
Summary:
DumpDataExtractor uses ClangASTContext in order to get the proper llvm
fltSemantics for the type it needs so that it can dump floats in a more
precise way. However, there's no reason that this behavior needs to be
specific ClangASTContext. Instead, I think it makes sense to ask
TypeSystems for the float semantics for a type of a given size.
Differential Revision: https://reviews.llvm.org/D67239
Modified:
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/include/lldb/Symbol/TypeSystem.h
lldb/trunk/source/Core/DumpDataExtractor.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp
Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=371258&r1=371257&r2=371258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Fri Sep 6 14:05:21 2019
@@ -694,6 +694,8 @@ public:
// Exploring the type
+ const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override;
+
llvm::Optional<uint64_t> GetByteSize(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) {
if (llvm::Optional<uint64_t> bit_size = GetBitSize(type, exe_scope))
Modified: lldb/trunk/include/lldb/Symbol/TypeSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=371258&r1=371257&r2=371258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeSystem.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeSystem.h Fri Sep 6 14:05:21 2019
@@ -14,6 +14,7 @@
#include <mutex>
#include <string>
+#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/Support/Casting.h"
@@ -276,6 +277,8 @@ public:
// Exploring the type
+ virtual const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) = 0;
+
virtual llvm::Optional<uint64_t>
GetBitSize(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) = 0;
Modified: lldb/trunk/source/Core/DumpDataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DumpDataExtractor.cpp?rev=371258&r1=371257&r2=371258&view=diff
==============================================================================
--- lldb/trunk/source/Core/DumpDataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DumpDataExtractor.cpp Fri Sep 6 14:05:21 2019
@@ -14,7 +14,6 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/ModuleList.h"
-#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/SectionLoadList.h"
@@ -69,6 +68,9 @@ static float half2float(uint16_t half) {
static llvm::Optional<llvm::APInt> GetAPInt(const DataExtractor &data,
lldb::offset_t *offset_ptr,
lldb::offset_t byte_size) {
+ if (byte_size == 0)
+ return llvm::None;
+
llvm::SmallVector<uint64_t, 2> uint64_array;
lldb::offset_t bytes_left = byte_size;
uint64_t u64;
@@ -556,57 +558,31 @@ lldb::offset_t lldb_private::DumpDataExt
if (exe_scope)
target_sp = exe_scope->CalculateTarget();
if (target_sp) {
- ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
- if (clang_ast) {
- clang::ASTContext *ast = clang_ast->getASTContext();
- if (ast) {
- llvm::SmallVector<char, 256> sv;
- // Show full precision when printing float values
- const unsigned format_precision = 0;
- const unsigned format_max_padding =
- target_sp->GetMaxZeroPaddingInFloatFormat();
- size_t item_bit_size = item_byte_size * 8;
-
- if (item_bit_size == ast->getTypeSize(ast->FloatTy)) {
- llvm::Optional<llvm::APInt> apint =
- GetAPInt(DE, &offset, item_byte_size);
- if (apint.hasValue()) {
- llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->FloatTy),
- apint.getValue());
- apfloat.toString(sv, format_precision, format_max_padding);
- }
- } else if (item_bit_size == ast->getTypeSize(ast->DoubleTy)) {
- llvm::Optional<llvm::APInt> apint =
- GetAPInt(DE, &offset, item_byte_size);
- if (apint.hasValue()) {
- llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->DoubleTy),
- apint.getValue());
- apfloat.toString(sv, format_precision, format_max_padding);
- }
- } else if (item_bit_size == ast->getTypeSize(ast->LongDoubleTy)) {
- const auto &semantics =
- ast->getFloatTypeSemantics(ast->LongDoubleTy);
-
- offset_t byte_size = item_byte_size;
- if (&semantics == &llvm::APFloatBase::x87DoubleExtended())
- byte_size = (llvm::APFloat::getSizeInBits(semantics) + 7) / 8;
-
- llvm::Optional<llvm::APInt> apint =
- GetAPInt(DE, &offset, byte_size);
- if (apint.hasValue()) {
- llvm::APFloat apfloat(semantics, apint.getValue());
- apfloat.toString(sv, format_precision, format_max_padding);
- }
- } else if (item_bit_size == ast->getTypeSize(ast->HalfTy)) {
- llvm::Optional<llvm::APInt> apint =
- GetAPInt(DE, &offset, item_byte_size);
- if (apint.hasValue()) {
- llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->HalfTy),
- apint.getValue());
- apfloat.toString(sv, format_precision, format_max_padding);
- }
- }
-
+ auto type_system_or_err =
+ target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC);
+ if (!type_system_or_err) {
+ llvm::consumeError(type_system_or_err.takeError());
+ } else {
+ auto &type_system = *type_system_or_err;
+ llvm::SmallVector<char, 256> sv;
+ // Show full precision when printing float values
+ const unsigned format_precision = 0;
+ const unsigned format_max_padding =
+ target_sp->GetMaxZeroPaddingInFloatFormat();
+
+ const auto &semantics =
+ type_system.GetFloatTypeSemantics(item_byte_size);
+
+ // Recalculate the byte size in case of a difference. This is possible
+ // when item_byte_size is 16 (128-bit), because you could get back the
+ // x87DoubleExtended semantics which has a byte size of 10 (80-bit).
+ const size_t semantics_byte_size =
+ (llvm::APFloat::getSizeInBits(semantics) + 7) / 8;
+ llvm::Optional<llvm::APInt> apint =
+ GetAPInt(DE, &offset, semantics_byte_size);
+ if (apint.hasValue()) {
+ llvm::APFloat apfloat(semantics, apint.getValue());
+ apfloat.toString(sv, format_precision, format_max_padding);
if (!sv.empty()) {
s->Printf("%*.*s", (int)sv.size(), (int)sv.size(), sv.data());
used_upfloat = true;
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=371258&r1=371257&r2=371258&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Sep 6 14:05:21 2019
@@ -4991,6 +4991,22 @@ CompilerType ClangASTContext::GetBasicTy
}
// Exploring the type
+const llvm::fltSemantics &
+ClangASTContext::GetFloatTypeSemantics(size_t byte_size) {
+ if (auto *ast = getASTContext()) {
+ const size_t bit_size = byte_size * 8;
+ if (bit_size == ast->getTypeSize(ast->FloatTy))
+ return ast->getFloatTypeSemantics(ast->FloatTy);
+ else if (bit_size == ast->getTypeSize(ast->DoubleTy))
+ return ast->getFloatTypeSemantics(ast->DoubleTy);
+ else if (bit_size == ast->getTypeSize(ast->LongDoubleTy))
+ return ast->getFloatTypeSemantics(ast->LongDoubleTy);
+ else if (bit_size == ast->getTypeSize(ast->HalfTy))
+ return ast->getFloatTypeSemantics(ast->HalfTy);
+ }
+ return llvm::APFloatBase::Bogus();
+}
+
Optional<uint64_t>
ClangASTContext::GetBitSize(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) {
More information about the lldb-commits
mailing list