1 //===-- CoreMedia.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/DataFormatters/CXXFormatterFunctions.h"
12 #include "lldb/Core/Flags.h"
13 #include "lldb/Symbol/ClangASTContext.h"
18 using namespace lldb_private;
19 using namespace lldb_private::formatters;
22 lldb_private::formatters::CMTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
24 ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(valobj.GetClangType().GetASTContext());
28 // fetch children by offset to compensate for potential lack of debug info
29 auto int64_ty = ast_ctx->GetIntTypeFromBitSize(64, true);
30 auto int32_ty = ast_ctx->GetIntTypeFromBitSize(32, true);
32 auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true));
33 auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true));
34 auto flags_sp(valobj.GetSyntheticChildAtOffset(12, int32_ty, true));
36 if (!value_sp || !timescale_sp || !flags_sp)
39 auto value = value_sp->GetValueAsUnsigned(0);
40 auto timescale = (int32_t)timescale_sp->GetValueAsUnsigned(0); // the timescale specifies the fraction of a second each unit in the numerator occupies
41 auto flags = Flags(flags_sp->GetValueAsUnsigned(0) & 0x00000000000000FF); // the flags I need sit in the LSB
43 const unsigned int FlagPositiveInf = 4;
44 const unsigned int FlagNegativeInf = 8;
45 const unsigned int FlagIndefinite = 16;
47 if (flags.AnySet(FlagIndefinite))
49 stream.Printf("indefinite");
53 if (flags.AnySet(FlagPositiveInf))
59 if (flags.AnySet(FlagNegativeInf))
73 stream.Printf("%" PRId64 " seconds", value);
76 stream.Printf("%" PRId64 " half seconds", value);
79 stream.Printf("%" PRId64 " third%sof a second", value, value == 1 ? " " : "s ");
82 stream.Printf("%" PRId64 " %" PRId32 "th%sof a second", value, timescale, value == 1 ? " " : "s ");