1 //===-- CoreMedia.cpp --------------------------------------------*- C++
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "CoreMedia.h"
12 #include "lldb/Utility/Flags.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 TypeSystem *type_system =
29 valobj.GetExecutionContextRef()
31 ->GetScratchTypeSystemForLanguage(nullptr, lldb::eLanguageTypeC);
35 // fetch children by offset to compensate for potential lack of debug info
37 type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 64);
39 type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32);
41 auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true));
42 auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true));
43 auto flags_sp(valobj.GetSyntheticChildAtOffset(12, int32_ty, true));
45 if (!value_sp || !timescale_sp || !flags_sp)
48 auto value = value_sp->GetValueAsUnsigned(0);
49 auto timescale = (int32_t)timescale_sp->GetValueAsUnsigned(
50 0); // the timescale specifies the fraction of a second each unit in the
52 auto flags = Flags(flags_sp->GetValueAsUnsigned(0) &
53 0x00000000000000FF); // the flags I need sit in the LSB
55 const unsigned int FlagPositiveInf = 4;
56 const unsigned int FlagNegativeInf = 8;
57 const unsigned int FlagIndefinite = 16;
59 if (flags.AnySet(FlagIndefinite)) {
60 stream.Printf("indefinite");
64 if (flags.AnySet(FlagPositiveInf)) {
69 if (flags.AnySet(FlagNegativeInf)) {
81 stream.Printf("%" PRId64 " seconds", value);
84 stream.Printf("%" PRId64 " half seconds", value);
87 stream.Printf("%" PRId64 " third%sof a second", value,
88 value == 1 ? " " : "s ");
91 stream.Printf("%" PRId64 " %" PRId32 "th%sof a second", value, timescale,
92 value == 1 ? " " : "s ");