Skip to content

Commit 52f00a1

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

File tree

13 files changed

+66
-10
lines changed

13 files changed

+66
-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, lldb::Format format) = 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: 12 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+
lldb::Format format) {
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, format);
329330
}
330331
// No target, just make a reasonable guess
331332
switch(byte_size) {
@@ -335,7 +336,13 @@ static const llvm::fltSemantics &GetFloatSemantics(const TargetSP &target_sp,
335336
return llvm::APFloat::IEEEsingle();
336337
case 8:
337338
return llvm::APFloat::IEEEdouble();
338-
}
339+
case 16:
340+
if (format == eFormatFloat128) {
341+
return llvm::APFloat::IEEEquad();
342+
}
343+
// Otherwise it's ambigious whether a 16-byte float is a float128 or a
344+
// target-specific long double.
345+
}
339346
return llvm::APFloat::Bogus();
340347
}
341348

@@ -653,6 +660,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
653660
}
654661
} break;
655662

663+
case eFormatFloat128:
656664
case eFormatFloat: {
657665
TargetSP target_sp;
658666
if (exe_scope)
@@ -666,7 +674,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
666674
const unsigned format_precision = 0;
667675

668676
const llvm::fltSemantics &semantics =
669-
GetFloatSemantics(target_sp, item_byte_size);
677+
GetFloatSemantics(target_sp, item_byte_size, item_format);
670678

671679
// Recalculate the byte size in case of a difference. This is possible
672680
// 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: 25 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,24 @@ 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, lldb::Format format) {
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 (format == eFormatFloat128 &&
4761+
bit_size == ast.getTypeSize(ast.Float128Ty))
4762+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47474763
else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
47484764
bit_size == llvm::APFloat::semanticsSizeInBits(
47494765
ast.getFloatTypeSemantics(ast.LongDoubleTy)))
47504766
return ast.getFloatTypeSemantics(ast.LongDoubleTy);
47514767
else if (bit_size == ast.getTypeSize(ast.HalfTy))
47524768
return ast.getFloatTypeSemantics(ast.HalfTy);
4769+
else if (bit_size == ast.getTypeSize(ast.Float128Ty))
4770+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47534771
return llvm::APFloatBase::Bogus();
47544772
}
47554773

@@ -5222,6 +5240,8 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52225240
case clang::BuiltinType::Double:
52235241
case clang::BuiltinType::LongDouble:
52245242
return lldb::eFormatFloat;
5243+
case clang::BuiltinType::Float128:
5244+
return lldb::eFormatFloat128;
52255245
default:
52265246
return lldb::eFormatHex;
52275247
}
@@ -5545,6 +5565,8 @@ TypeSystemClang::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) {
55455565
return eBasicTypeDouble;
55465566
case clang::BuiltinType::LongDouble:
55475567
return eBasicTypeLongDouble;
5568+
case clang::BuiltinType::Float128:
5569+
return eBasicTypeFloat128;
55485570

55495571
case clang::BuiltinType::NullPtr:
55505572
return eBasicTypeNullPtr;
@@ -6106,6 +6128,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
61066128
case clang::BuiltinType::Float:
61076129
case clang::BuiltinType::Double:
61086130
case clang::BuiltinType::LongDouble:
6131+
case clang::BuiltinType::Float128:
61096132
case clang::BuiltinType::Dependent:
61106133
case clang::BuiltinType::Overload:
61116134
case clang::BuiltinType::ObjCId:
@@ -8837,6 +8860,7 @@ bool TypeSystemClang::DumpTypeValue(
88378860
case eFormatHex:
88388861
case eFormatHexUppercase:
88398862
case eFormatFloat:
8863+
case eFormatFloat128:
88408864
case eFormatOctal:
88418865
case eFormatOSType:
88428866
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 &GetFloatTypeSemantics(size_t byte_size,
830+
lldb::Format format) override;
830831

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

0 commit comments

Comments
 (0)