1 //===-- CoreMedia.cpp -----------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #include "lldb/Utility/Flags.h"
12 #include "lldb/Utility/Log.h"
14 #include "lldb/Symbol/TypeSystem.h"
15 #include "lldb/Target/Target.h"
19 using namespace lldb_private
;
20 using namespace lldb_private::formatters
;
22 bool lldb_private::formatters::CMTimeSummaryProvider(
23 ValueObject
&valobj
, Stream
&stream
, const TypeSummaryOptions
&options
) {
24 CompilerType type
= valobj
.GetCompilerType();
28 auto type_system
= type
.GetTypeSystem();
31 // fetch children by offset to compensate for potential lack of debug info
33 type_system
->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint
, 64);
35 type_system
->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint
, 32);
37 auto value_sp(valobj
.GetSyntheticChildAtOffset(0, int64_ty
, true));
38 auto timescale_sp(valobj
.GetSyntheticChildAtOffset(8, int32_ty
, true));
39 auto flags_sp(valobj
.GetSyntheticChildAtOffset(12, int32_ty
, true));
41 if (!value_sp
|| !timescale_sp
|| !flags_sp
)
44 auto value
= value_sp
->GetValueAsUnsigned(0);
45 auto timescale
= (int32_t)timescale_sp
->GetValueAsUnsigned(
46 0); // the timescale specifies the fraction of a second each unit in the
48 auto flags
= Flags(flags_sp
->GetValueAsUnsigned(0) &
49 0x00000000000000FF); // the flags I need sit in the LSB
51 const unsigned int FlagPositiveInf
= 4;
52 const unsigned int FlagNegativeInf
= 8;
53 const unsigned int FlagIndefinite
= 16;
55 if (flags
.AnySet(FlagIndefinite
)) {
56 stream
.Printf("indefinite");
60 if (flags
.AnySet(FlagPositiveInf
)) {
65 if (flags
.AnySet(FlagNegativeInf
)) {
74 stream
.Printf("%" PRId64
" seconds", value
);
77 stream
.Printf("%" PRId64
" half seconds", value
);
80 stream
.Printf("%" PRId64
" third%sof a second", value
,
81 value
== 1 ? " " : "s ");
84 stream
.Printf("%" PRId64
" %" PRId32
"th%sof a second", value
, timescale
,
85 value
== 1 ? " " : "s ");