Skip to content

Commit 1fa7e90

Browse files
committed
[lldb] Add support for displaying __float128 variables
1 parent 33af4bd commit 1fa7e90

File tree

11 files changed

+51
-3
lines changed

11 files changed

+51
-3
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
@@ -295,6 +295,7 @@ Format
295295
.. py:data:: eFormatHex
296296
.. py:data:: eFormatHexUppercase
297297
.. py:data:: eFormatFloat
298+
.. py:data:: eFormatFloat128
298299
.. py:data:: eFormatOctal
299300
.. py:data:: eFormatOSType
300301
.. py:data:: eFormatUnicode16
@@ -1037,6 +1038,7 @@ BasicType
10371038
.. py:data:: eBasicTypeFloat
10381039
.. py:data:: eBasicTypeDouble
10391040
.. py:data:: eBasicTypeLongDouble
1041+
.. py:data:: eBasicTypeFloat128
10401042
.. py:data:: eBasicTypeFloatComplex
10411043
.. py:data:: eBasicTypeDoubleComplex
10421044
.. py:data:: eBasicTypeLongDoubleComplex

lldb/include/lldb/lldb-enumerations.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ enum Format {
170170
eFormatHex,
171171
eFormatHexUppercase,
172172
eFormatFloat,
173+
eFormatFloat128, //< Disambiguate between 128-bit `long double` (which uses
174+
//< `eFormatFloat`) and `__float128` (which uses
175+
//< `eFormatFloat128`). If the value being formatted is not
176+
//< 128 bits, then this is identical to `eFormatFloat`.
173177
eFormatOctal,
174178
eFormatOSType, ///< OS character codes encoded into an integer 'PICT' 'text'
175179
///< etc...
@@ -819,6 +823,7 @@ enum BasicType {
819823
eBasicTypeFloat,
820824
eBasicTypeDouble,
821825
eBasicTypeLongDouble,
826+
eBasicTypeFloat128,
822827
eBasicTypeFloatComplex,
823828
eBasicTypeDoubleComplex,
824829
eBasicTypeLongDoubleComplex,

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:
@@ -1329,6 +1330,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
13291330
switch (m_format_options.GetFormat()) {
13301331
case kNumFormats:
13311332
case eFormatFloat: // TODO: add support for floats soon
1333+
case eFormatFloat128:
13321334
case eFormatCharPrintable:
13331335
case eFormatBytesWithASCII:
13341336
case eFormatComplex:

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ static const llvm::fltSemantics &GetFloatSemantics(const TargetSP &target_sp,
334334
return llvm::APFloat::IEEEsingle();
335335
case 8:
336336
return llvm::APFloat::IEEEdouble();
337+
case 16:
338+
return llvm::APFloat::IEEEquad();
337339
}
338340
return llvm::APFloat::Bogus();
339341
}
@@ -652,6 +654,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
652654
}
653655
} break;
654656

657+
case eFormatFloat128:
655658
case eFormatFloat: {
656659
TargetSP target_sp;
657660
if (exe_scope)
@@ -665,7 +668,9 @@ lldb::offset_t lldb_private::DumpDataExtractor(
665668
const unsigned format_precision = 0;
666669

667670
const llvm::fltSemantics &semantics =
668-
GetFloatSemantics(target_sp, item_byte_size);
671+
item_format == eFormatFloat128 && item_byte_size == 16
672+
? llvm::APFloat::IEEEquad()
673+
: GetFloatSemantics(target_sp, item_byte_size);
669674

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

lldb/source/Core/ValueObject.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,9 @@ bool ValueObject::DumpPrintableRepresentation(
14381438
(custom_format == eFormatComplexFloat) ||
14391439
(custom_format == eFormatDecimal) || (custom_format == eFormatHex) ||
14401440
(custom_format == eFormatHexUppercase) ||
1441-
(custom_format == eFormatFloat) || (custom_format == eFormatOctal) ||
1442-
(custom_format == eFormatOSType) ||
1441+
(custom_format == eFormatFloat) ||
1442+
(custom_format == eFormatFloat128) ||
1443+
(custom_format == eFormatOctal) || (custom_format == eFormatOSType) ||
14431444
(custom_format == eFormatUnicode16) ||
14441445
(custom_format == eFormatUnicode32) ||
14451446
(custom_format == eFormatUnsigned) ||

lldb/source/DataFormatters/FormatManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static constexpr FormatInfo g_format_infos[] = {
4646
{eFormatHex, 'x', "hex"},
4747
{eFormatHexUppercase, 'X', "uppercase hex"},
4848
{eFormatFloat, 'f', "float"},
49+
{eFormatFloat128, '\0', "float128"},
4950
{eFormatOctal, 'o', "octal"},
5051
{eFormatOSType, 'O', "OSType"},
5152
{eFormatUnicode16, 'U', "unicode16"},

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding,
790790
return GetType(ast.LongDoubleTy);
791791
if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
792792
return GetType(ast.HalfTy);
793+
if (QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
794+
return GetType(ast.Float128Ty);
793795
break;
794796

795797
case eEncodingVector:
@@ -948,6 +950,13 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
948950
if (type_name == "long double" &&
949951
QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
950952
return GetType(ast.LongDoubleTy);
953+
// As Rust currently uses `TypeSystemClang`, match `f128` here as well so it
954+
// doesn't get misinterpreted as `long double` on targets where they are
955+
// the same size but different formats.
956+
if ((type_name == "__float128" || type_name == "_Float128" ||
957+
type_name == "f128") &&
958+
QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
959+
return GetType(ast.Float128Ty);
951960
// Fall back to not requiring a name match
952961
if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
953962
return GetType(ast.FloatTy);
@@ -957,6 +966,8 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
957966
return GetType(ast.LongDoubleTy);
958967
if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
959968
return GetType(ast.HalfTy);
969+
if (QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
970+
return GetType(ast.Float128Ty);
960971
break;
961972

962973
case DW_ATE_signed:
@@ -2050,6 +2061,8 @@ TypeSystemClang::GetOpaqueCompilerType(clang::ASTContext *ast,
20502061
return ast->DoubleTy.getAsOpaquePtr();
20512062
case eBasicTypeLongDouble:
20522063
return ast->LongDoubleTy.getAsOpaquePtr();
2064+
case eBasicTypeFloat128:
2065+
return ast->Float128Ty.getAsOpaquePtr();
20532066
case eBasicTypeFloatComplex:
20542067
return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
20552068
case eBasicTypeDoubleComplex:
@@ -4722,6 +4735,8 @@ TypeSystemClang::GetFloatTypeSemantics(size_t byte_size) {
47224735
return ast.getFloatTypeSemantics(ast.LongDoubleTy);
47234736
else if (bit_size == ast.getTypeSize(ast.HalfTy))
47244737
return ast.getFloatTypeSemantics(ast.HalfTy);
4738+
else if (bit_size == ast.getTypeSize(ast.Float128Ty))
4739+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47254740
return llvm::APFloatBase::Bogus();
47264741
}
47274742

@@ -5232,6 +5247,8 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52325247
case clang::BuiltinType::Double:
52335248
case clang::BuiltinType::LongDouble:
52345249
return lldb::eFormatFloat;
5250+
case clang::BuiltinType::Float128:
5251+
return lldb::eFormatFloat128;
52355252
default:
52365253
return lldb::eFormatHex;
52375254
}
@@ -5551,6 +5568,8 @@ TypeSystemClang::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) {
55515568
return eBasicTypeDouble;
55525569
case clang::BuiltinType::LongDouble:
55535570
return eBasicTypeLongDouble;
5571+
case clang::BuiltinType::Float128:
5572+
return eBasicTypeFloat128;
55545573

55555574
case clang::BuiltinType::NullPtr:
55565575
return eBasicTypeNullPtr;
@@ -6111,6 +6130,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
61116130
case clang::BuiltinType::Float:
61126131
case clang::BuiltinType::Double:
61136132
case clang::BuiltinType::LongDouble:
6133+
case clang::BuiltinType::Float128:
61146134
case clang::BuiltinType::Dependent:
61156135
case clang::BuiltinType::Overload:
61166136
case clang::BuiltinType::ObjCId:
@@ -8807,6 +8827,7 @@ bool TypeSystemClang::DumpTypeValue(
88078827
case eFormatHex:
88088828
case eFormatHexUppercase:
88098829
case eFormatFloat:
8830+
case eFormatFloat128:
88108831
case eFormatOctal:
88118832
case eFormatOSType:
88128833
case eFormatUnsigned:

lldb/unittests/Core/DumpDataExtractorTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ TEST_F(DumpDataExtractorTest, Formats) {
163163
TestDump(0xcafef00d, lldb::Format::eFormatHex, "0xcafef00d");
164164
TestDump(0xcafef00d, lldb::Format::eFormatHexUppercase, "0xCAFEF00D");
165165
TestDump(0.456, lldb::Format::eFormatFloat, "0.45600000000000002");
166+
TestDump(std::vector<uint64_t>{0x47ae147ae147ae14, 0x40011147ae147ae1},
167+
lldb::Format::eFormatFloat128,
168+
"4.26999999999999999999999999999999963");
166169
TestDump(9, lldb::Format::eFormatOctal, "011");
167170
// Chars packed into an integer.
168171
TestDump<uint32_t>(0x4C4C4442, lldb::Format::eFormatOSType, "'LLDB'");
@@ -388,6 +391,9 @@ TEST_F(DumpDataExtractorTest, ItemByteSizeErrors) {
388391
TestDumpWithItemByteSize(
389392
18, lldb::Format::eFormatFloat,
390393
"error: unsupported byte size (18) for float format");
394+
TestDumpWithItemByteSize(
395+
17, lldb::Format::eFormatFloat128,
396+
"error: unsupported byte size (17) for float format");
391397

392398
// We want sizes to exactly match one of float/double.
393399
TestDumpWithItemByteSize(

0 commit comments

Comments
 (0)