Skip to content

Commit b96a6a1

Browse files
committed
[lldb] Add support for displaying __float128 variables
1 parent 0fb5720 commit b96a6a1

File tree

13 files changed

+63
-10
lines changed

13 files changed

+63
-10
lines changed

lldb/bindings/python/python-extensions.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ def is_numeric_type(basic_type):
594594
if basic_type == eBasicTypeFloat: return (True,True)
595595
if basic_type == eBasicTypeDouble: return (True,True)
596596
if basic_type == eBasicTypeLongDouble: return (True,True)
597+
if basic_type == eBasicTypeFloat128: return (True,True)
597598
if basic_type == eBasicTypeFloatComplex: return (True,True)
598599
if basic_type == eBasicTypeDoubleComplex: return (True,True)
599600
if basic_type == eBasicTypeLongDoubleComplex: return (True,True)

lldb/docs/python_api_enums.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ Format
321321
.. py:data:: eFormatInstruction
322322
.. py:data:: eFormatVoid
323323
.. py:data:: eFormatUnicode8
324+
.. py:data:: eFormatFloat128
324325
325326
326327
.. _DescriptionLevel:
@@ -1045,6 +1046,7 @@ BasicType
10451046
.. py:data:: eBasicTypeObjCSel
10461047
.. py:data:: eBasicTypeNullPtr
10471048
.. py:data:: eBasicTypeOther
1049+
.. py:data:: eBasicTypeFloat128
10481050
10491051
10501052
.. _TraceType:

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ class TypeSystem : public PluginInterface,
310310

311311
// Exploring the type
312312

313-
virtual const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) = 0;
313+
virtual const llvm::fltSemantics &
314+
GetFloatTypeSemantics(size_t byte_size, bool prefer_float128) = 0;
314315

315316
virtual llvm::Expected<uint64_t>
316317
GetBitSize(lldb::opaque_compiler_type_t type,

lldb/include/lldb/lldb-enumerations.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ enum Format {
203203
eFormatInstruction, ///< Disassemble an opcode
204204
eFormatVoid, ///< Do not print this
205205
eFormatUnicode8,
206+
eFormatFloat128, ///< Disambiguate between 128-bit `long double` (which uses
207+
///< `eFormatFloat`) and `__float128` (which uses
208+
///< `eFormatFloat128`). If the value being formatted is not
209+
///< 128 bits, then this is identical to `eFormatFloat`.
206210
kNumFormats
207211
};
208212

@@ -837,7 +841,8 @@ enum BasicType {
837841
eBasicTypeObjCClass,
838842
eBasicTypeObjCSel,
839843
eBasicTypeNullPtr,
840-
eBasicTypeOther
844+
eBasicTypeOther,
845+
eBasicTypeFloat128
841846
};
842847

843848
/// Deprecated

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class OptionGroupReadMemory : public OptionGroup {
156156

157157
case eFormatBinary:
158158
case eFormatFloat:
159+
case eFormatFloat128:
159160
case eFormatOctal:
160161
case eFormatDecimal:
161162
case eFormatEnum:
@@ -1330,6 +1331,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
13301331
switch (m_format_options.GetFormat()) {
13311332
case kNumFormats:
13321333
case eFormatFloat: // TODO: add support for floats soon
1334+
case eFormatFloat128:
13331335
case eFormatCharPrintable:
13341336
case eFormatBytesWithASCII:
13351337
case eFormatComplex:

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,15 @@ static void printMemoryTags(const DataExtractor &DE, Stream *s,
318318
}
319319

320320
static const llvm::fltSemantics &GetFloatSemantics(const TargetSP &target_sp,
321-
size_t byte_size) {
321+
size_t byte_size,
322+
bool prefer_float128) {
322323
if (target_sp) {
323324
auto type_system_or_err =
324325
target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC);
325326
if (!type_system_or_err)
326327
llvm::consumeError(type_system_or_err.takeError());
327328
else if (auto ts = *type_system_or_err)
328-
return ts->GetFloatTypeSemantics(byte_size);
329+
return ts->GetFloatTypeSemantics(byte_size, prefer_float128);
329330
}
330331
// No target, just make a reasonable guess
331332
switch(byte_size) {
@@ -335,6 +336,10 @@ static const llvm::fltSemantics &GetFloatSemantics(const TargetSP &target_sp,
335336
return llvm::APFloat::IEEEsingle();
336337
case 8:
337338
return llvm::APFloat::IEEEdouble();
339+
case 16:
340+
if (prefer_float128) {
341+
return llvm::APFloat::IEEEquad();
342+
}
338343
}
339344
return llvm::APFloat::Bogus();
340345
}
@@ -653,6 +658,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
653658
}
654659
} break;
655660

661+
case eFormatFloat128:
656662
case eFormatFloat: {
657663
TargetSP target_sp;
658664
if (exe_scope)
@@ -665,8 +671,8 @@ lldb::offset_t lldb_private::DumpDataExtractor(
665671
// Show full precision when printing float values
666672
const unsigned format_precision = 0;
667673

668-
const llvm::fltSemantics &semantics =
669-
GetFloatSemantics(target_sp, item_byte_size);
674+
const llvm::fltSemantics &semantics = GetFloatSemantics(
675+
target_sp, item_byte_size, item_format == eFormatFloat128);
670676

671677
// Recalculate the byte size in case of a difference. This is possible
672678
// when item_byte_size is 16 (128-bit), because you could get back the

lldb/source/DataFormatters/FormatManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static constexpr FormatInfo g_format_infos[] = {
7272
{eFormatInstruction, 'i', "instruction"},
7373
{eFormatVoid, 'v', "void"},
7474
{eFormatUnicode8, 'u', "unicode8"},
75+
{eFormatFloat128, '\0', "float128"},
7576
};
7677

7778
static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) ==

lldb/source/DataFormatters/VectorType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static CompilerType GetCompilerTypeForFormat(lldb::Format format,
5555

5656
case lldb::eFormatFloat:
5757
return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat);
58+
case lldb::eFormatFloat128:
59+
return type_system->GetBasicTypeFromAST(lldb::eBasicTypeFloat128);
5860

5961
case lldb::eFormatHex:
6062
case lldb::eFormatHexUppercase:

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,8 @@ TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding,
809809
return GetType(ast.LongDoubleTy);
810810
if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
811811
return GetType(ast.HalfTy);
812+
if (QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
813+
return GetType(ast.Float128Ty);
812814
break;
813815

814816
case eEncodingVector:
@@ -970,6 +972,13 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
970972
if (type_name == "long double" &&
971973
QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
972974
return GetType(ast.LongDoubleTy);
975+
// As Rust currently uses `TypeSystemClang`, match `f128` here as well so it
976+
// doesn't get misinterpreted as `long double` on targets where they are
977+
// the same size but different formats.
978+
if ((type_name == "__float128" || type_name == "_Float128" ||
979+
type_name == "f128") &&
980+
QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
981+
return GetType(ast.Float128Ty);
973982
// Fall back to not requiring a name match
974983
if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
975984
return GetType(ast.FloatTy);
@@ -979,6 +988,8 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
979988
return GetType(ast.LongDoubleTy);
980989
if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
981990
return GetType(ast.HalfTy);
991+
if (QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
992+
return GetType(ast.Float128Ty);
982993
break;
983994

984995
case DW_ATE_signed:
@@ -2068,6 +2079,8 @@ TypeSystemClang::GetOpaqueCompilerType(clang::ASTContext *ast,
20682079
return ast->DoubleTy.getAsOpaquePtr();
20692080
case eBasicTypeLongDouble:
20702081
return ast->LongDoubleTy.getAsOpaquePtr();
2082+
case eBasicTypeFloat128:
2083+
return ast->Float128Ty.getAsOpaquePtr();
20712084
case eBasicTypeFloatComplex:
20722085
return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
20732086
case eBasicTypeDoubleComplex:
@@ -4737,19 +4750,23 @@ CompilerType TypeSystemClang::CreateGenericFunctionPrototype() {
47374750
// Exploring the type
47384751

47394752
const llvm::fltSemantics &
4740-
TypeSystemClang::GetFloatTypeSemantics(size_t byte_size) {
4753+
TypeSystemClang::GetFloatTypeSemantics(size_t byte_size, bool prefer_float128) {
47414754
clang::ASTContext &ast = getASTContext();
47424755
const size_t bit_size = byte_size * 8;
47434756
if (bit_size == ast.getTypeSize(ast.FloatTy))
47444757
return ast.getFloatTypeSemantics(ast.FloatTy);
47454758
else if (bit_size == ast.getTypeSize(ast.DoubleTy))
47464759
return ast.getFloatTypeSemantics(ast.DoubleTy);
4760+
else if (prefer_float128 && bit_size == ast.getTypeSize(ast.Float128Ty))
4761+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47474762
else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
47484763
bit_size == llvm::APFloat::semanticsSizeInBits(
47494764
ast.getFloatTypeSemantics(ast.LongDoubleTy)))
47504765
return ast.getFloatTypeSemantics(ast.LongDoubleTy);
47514766
else if (bit_size == ast.getTypeSize(ast.HalfTy))
47524767
return ast.getFloatTypeSemantics(ast.HalfTy);
4768+
else if (bit_size == ast.getTypeSize(ast.Float128Ty))
4769+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47534770
return llvm::APFloatBase::Bogus();
47544771
}
47554772

@@ -5222,6 +5239,8 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52225239
case clang::BuiltinType::Double:
52235240
case clang::BuiltinType::LongDouble:
52245241
return lldb::eFormatFloat;
5242+
case clang::BuiltinType::Float128:
5243+
return lldb::eFormatFloat128;
52255244
default:
52265245
return lldb::eFormatHex;
52275246
}
@@ -5545,6 +5564,8 @@ TypeSystemClang::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) {
55455564
return eBasicTypeDouble;
55465565
case clang::BuiltinType::LongDouble:
55475566
return eBasicTypeLongDouble;
5567+
case clang::BuiltinType::Float128:
5568+
return eBasicTypeFloat128;
55485569

55495570
case clang::BuiltinType::NullPtr:
55505571
return eBasicTypeNullPtr;
@@ -6106,6 +6127,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
61066127
case clang::BuiltinType::Float:
61076128
case clang::BuiltinType::Double:
61086129
case clang::BuiltinType::LongDouble:
6130+
case clang::BuiltinType::Float128:
61096131
case clang::BuiltinType::Dependent:
61106132
case clang::BuiltinType::Overload:
61116133
case clang::BuiltinType::ObjCId:
@@ -8837,6 +8859,7 @@ bool TypeSystemClang::DumpTypeValue(
88378859
case eFormatHex:
88388860
case eFormatHexUppercase:
88398861
case eFormatFloat:
8862+
case eFormatFloat128:
88408863
case eFormatOctal:
88418864
case eFormatOSType:
88428865
case eFormatUnsigned:

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ class TypeSystemClang : public TypeSystem {
826826

827827
// Exploring the type
828828

829-
const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override;
829+
const llvm::fltSemantics &
830+
GetFloatTypeSemantics(size_t byte_size, bool prefer_float128) override;
830831

831832
llvm::Expected<uint64_t> GetByteSize(lldb::opaque_compiler_type_t type,
832833
ExecutionContextScope *exe_scope) {

0 commit comments

Comments
 (0)