Skip to content

Commit 8c0d1c6

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

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

656+
case eFormatFloat128:
656657
case eFormatFloat: {
657658
TargetSP target_sp;
658659
if (exe_scope)
@@ -666,7 +667,9 @@ lldb::offset_t lldb_private::DumpDataExtractor(
666667
const unsigned format_precision = 0;
667668

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

671674
// Recalculate the byte size in case of a difference. This is possible
672675
// 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: 21 additions & 0 deletions
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:
@@ -4750,6 +4763,8 @@ TypeSystemClang::GetFloatTypeSemantics(size_t byte_size) {
47504763
return ast.getFloatTypeSemantics(ast.LongDoubleTy);
47514764
else if (bit_size == ast.getTypeSize(ast.HalfTy))
47524765
return ast.getFloatTypeSemantics(ast.HalfTy);
4766+
else if (bit_size == ast.getTypeSize(ast.Float128Ty))
4767+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47534768
return llvm::APFloatBase::Bogus();
47544769
}
47554770

@@ -5222,6 +5237,8 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52225237
case clang::BuiltinType::Double:
52235238
case clang::BuiltinType::LongDouble:
52245239
return lldb::eFormatFloat;
5240+
case clang::BuiltinType::Float128:
5241+
return lldb::eFormatFloat128;
52255242
default:
52265243
return lldb::eFormatHex;
52275244
}
@@ -5545,6 +5562,8 @@ TypeSystemClang::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) {
55455562
return eBasicTypeDouble;
55465563
case clang::BuiltinType::LongDouble:
55475564
return eBasicTypeLongDouble;
5565+
case clang::BuiltinType::Float128:
5566+
return eBasicTypeFloat128;
55485567

55495568
case clang::BuiltinType::NullPtr:
55505569
return eBasicTypeNullPtr;
@@ -6106,6 +6125,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
61066125
case clang::BuiltinType::Float:
61076126
case clang::BuiltinType::Double:
61086127
case clang::BuiltinType::LongDouble:
6128+
case clang::BuiltinType::Float128:
61096129
case clang::BuiltinType::Dependent:
61106130
case clang::BuiltinType::Overload:
61116131
case clang::BuiltinType::ObjCId:
@@ -8837,6 +8857,7 @@ bool TypeSystemClang::DumpTypeValue(
88378857
case eFormatHex:
88388858
case eFormatHexUppercase:
88398859
case eFormatFloat:
8860+
case eFormatFloat128:
88408861
case eFormatOctal:
88418862
case eFormatOSType:
88428863
case eFormatUnsigned:

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,9 @@ bool ValueObject::DumpPrintableRepresentation(
14681468
(custom_format == eFormatComplexFloat) ||
14691469
(custom_format == eFormatDecimal) || (custom_format == eFormatHex) ||
14701470
(custom_format == eFormatHexUppercase) ||
1471-
(custom_format == eFormatFloat) || (custom_format == eFormatOctal) ||
1472-
(custom_format == eFormatOSType) ||
1471+
(custom_format == eFormatFloat) ||
1472+
(custom_format == eFormatFloat128) ||
1473+
(custom_format == eFormatOctal) || (custom_format == eFormatOSType) ||
14731474
(custom_format == eFormatUnicode16) ||
14741475
(custom_format == eFormatUnicode32) ||
14751476
(custom_format == 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)