Skip to content

Commit 4f97749

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

File tree

11 files changed

+50
-4
lines changed

11 files changed

+50
-4
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/lldb-enumerations.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ enum Format {
200200
eFormatInstruction, ///< Disassemble an opcode
201201
eFormatVoid, ///< Do not print this
202202
eFormatUnicode8,
203+
eFormatFloat128, //< Disambiguate between 128-bit `long double` (which uses
204+
//< `eFormatFloat`) and `__float128` (which uses
205+
//< `eFormatFloat128`). If the value being formatted is not
206+
//< 128 bits, then this is identical to `eFormatFloat`.
203207
kNumFormats
204208
};
205209

@@ -826,7 +830,8 @@ enum BasicType {
826830
eBasicTypeObjCClass,
827831
eBasicTypeObjCSel,
828832
eBasicTypeNullPtr,
829-
eBasicTypeOther
833+
eBasicTypeOther,
834+
eBasicTypeFloat128
830835
};
831836

832837
/// 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:
@@ -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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
652652
}
653653
} break;
654654

655+
case eFormatFloat128:
655656
case eFormatFloat: {
656657
TargetSP target_sp;
657658
if (exe_scope)
@@ -665,7 +666,9 @@ lldb::offset_t lldb_private::DumpDataExtractor(
665666
const unsigned format_precision = 0;
666667

667668
const llvm::fltSemantics &semantics =
668-
GetFloatSemantics(target_sp, item_byte_size);
669+
item_format == eFormatFloat128 && item_byte_size == 16
670+
? llvm::APFloat::IEEEquad()
671+
: GetFloatSemantics(target_sp, item_byte_size);
669672

670673
// Recalculate the byte size in case of a difference. This is possible
671674
// 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
@@ -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: 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)