Skip to content

Commit e02ded9

Browse files
committed
[lldb] Add support for displaying __float128 variables
1 parent 92ca087 commit e02ded9

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

@@ -838,7 +842,8 @@ enum BasicType {
838842
eBasicTypeObjCClass,
839843
eBasicTypeObjCSel,
840844
eBasicTypeNullPtr,
841-
eBasicTypeOther
845+
eBasicTypeOther,
846+
eBasicTypeFloat128
842847
};
843848

844849
/// 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:
@@ -1356,6 +1357,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
13561357
switch (m_format_options.GetFormat()) {
13571358
case kNumFormats:
13581359
case eFormatFloat: // TODO: add support for floats soon
1360+
case eFormatFloat128:
13591361
case eFormatCharPrintable:
13601362
case eFormatBytesWithASCII:
13611363
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
@@ -795,6 +795,8 @@ TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding,
795795
return GetType(ast.LongDoubleTy);
796796
if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
797797
return GetType(ast.HalfTy);
798+
if (QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
799+
return GetType(ast.Float128Ty);
798800
break;
799801

800802
case eEncodingVector:
@@ -956,6 +958,13 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
956958
if (type_name == "long double" &&
957959
QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
958960
return GetType(ast.LongDoubleTy);
961+
// As Rust currently uses `TypeSystemClang`, match `f128` here as well so it
962+
// doesn't get misinterpreted as `long double` on targets where they are
963+
// the same size but different formats.
964+
if ((type_name == "__float128" || type_name == "_Float128" ||
965+
type_name == "f128") &&
966+
QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
967+
return GetType(ast.Float128Ty);
959968
// Fall back to not requiring a name match
960969
if (QualTypeMatchesBitSize(bit_size, ast, ast.FloatTy))
961970
return GetType(ast.FloatTy);
@@ -965,6 +974,8 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
965974
return GetType(ast.LongDoubleTy);
966975
if (QualTypeMatchesBitSize(bit_size, ast, ast.HalfTy))
967976
return GetType(ast.HalfTy);
977+
if (QualTypeMatchesBitSize(bit_size, ast, ast.Float128Ty))
978+
return GetType(ast.Float128Ty);
968979
break;
969980

970981
case DW_ATE_signed:
@@ -2054,6 +2065,8 @@ TypeSystemClang::GetOpaqueCompilerType(clang::ASTContext *ast,
20542065
return ast->DoubleTy.getAsOpaquePtr();
20552066
case eBasicTypeLongDouble:
20562067
return ast->LongDoubleTy.getAsOpaquePtr();
2068+
case eBasicTypeFloat128:
2069+
return ast->Float128Ty.getAsOpaquePtr();
20572070
case eBasicTypeFloatComplex:
20582071
return ast->getComplexType(ast->FloatTy).getAsOpaquePtr();
20592072
case eBasicTypeDoubleComplex:
@@ -4742,19 +4755,24 @@ CompilerType TypeSystemClang::CreateGenericFunctionPrototype() {
47424755
// Exploring the type
47434756

47444757
const llvm::fltSemantics &
4745-
TypeSystemClang::GetFloatTypeSemantics(size_t byte_size) {
4758+
TypeSystemClang::GetFloatTypeSemantics(size_t byte_size, lldb::Format format) {
47464759
clang::ASTContext &ast = getASTContext();
47474760
const size_t bit_size = byte_size * 8;
47484761
if (bit_size == ast.getTypeSize(ast.FloatTy))
47494762
return ast.getFloatTypeSemantics(ast.FloatTy);
47504763
else if (bit_size == ast.getTypeSize(ast.DoubleTy))
47514764
return ast.getFloatTypeSemantics(ast.DoubleTy);
4765+
else if (format == eFormatFloat128 &&
4766+
bit_size == ast.getTypeSize(ast.Float128Ty))
4767+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47524768
else if (bit_size == ast.getTypeSize(ast.LongDoubleTy) ||
47534769
bit_size == llvm::APFloat::semanticsSizeInBits(
47544770
ast.getFloatTypeSemantics(ast.LongDoubleTy)))
47554771
return ast.getFloatTypeSemantics(ast.LongDoubleTy);
47564772
else if (bit_size == ast.getTypeSize(ast.HalfTy))
47574773
return ast.getFloatTypeSemantics(ast.HalfTy);
4774+
else if (bit_size == ast.getTypeSize(ast.Float128Ty))
4775+
return ast.getFloatTypeSemantics(ast.Float128Ty);
47584776
return llvm::APFloatBase::Bogus();
47594777
}
47604778

@@ -5232,6 +5250,8 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52325250
case clang::BuiltinType::Double:
52335251
case clang::BuiltinType::LongDouble:
52345252
return lldb::eFormatFloat;
5253+
case clang::BuiltinType::Float128:
5254+
return lldb::eFormatFloat128;
52355255
default:
52365256
return lldb::eFormatHex;
52375257
}
@@ -5529,6 +5549,8 @@ TypeSystemClang::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) {
55295549
return eBasicTypeDouble;
55305550
case clang::BuiltinType::LongDouble:
55315551
return eBasicTypeLongDouble;
5552+
case clang::BuiltinType::Float128:
5553+
return eBasicTypeFloat128;
55325554

55335555
case clang::BuiltinType::NullPtr:
55345556
return eBasicTypeNullPtr;
@@ -6090,6 +6112,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
60906112
case clang::BuiltinType::Float:
60916113
case clang::BuiltinType::Double:
60926114
case clang::BuiltinType::LongDouble:
6115+
case clang::BuiltinType::Float128:
60936116
case clang::BuiltinType::Dependent:
60946117
case clang::BuiltinType::Overload:
60956118
case clang::BuiltinType::ObjCId:
@@ -8733,6 +8756,7 @@ bool TypeSystemClang::DumpTypeValue(
87338756
case eFormatHex:
87348757
case eFormatHexUppercase:
87358758
case eFormatFloat:
8759+
case eFormatFloat128:
87368760
case eFormatOctal:
87378761
case eFormatOSType:
87388762
case eFormatUnsigned:

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

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

824824
// Exploring the type
825825

826-
const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override;
826+
const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size,
827+
lldb::Format format) override;
827828

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

0 commit comments

Comments
 (0)