LLDB mainline
CoreMedia.cpp
Go to the documentation of this file.
1//===-- CoreMedia.cpp -----------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "CoreMedia.h"
10
11#include "lldb/Utility/Flags.h"
12#include "lldb/Utility/Log.h"
13
15#include "lldb/Target/Target.h"
16#include <cinttypes>
17
18using namespace lldb;
19using namespace lldb_private;
20using namespace lldb_private::formatters;
21
23 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
24 CompilerType type = valobj.GetCompilerType();
25 if (!type.IsValid())
26 return false;
27
28 auto type_system = type.GetTypeSystem();
29 if (!type_system)
30 return false;
31 // fetch children by offset to compensate for potential lack of debug info
32 auto int64_ty =
34 auto int32_ty =
35 type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32);
36
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));
40
41 if (!value_sp || !timescale_sp || !flags_sp)
42 return false;
43
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
47 // numerator occupies
48 auto flags = Flags(flags_sp->GetValueAsUnsigned(0) &
49 0x00000000000000FF); // the flags I need sit in the LSB
50
51 const unsigned int FlagPositiveInf = 4;
52 const unsigned int FlagNegativeInf = 8;
53 const unsigned int FlagIndefinite = 16;
54
55 if (flags.AnySet(FlagIndefinite)) {
56 stream.Printf("indefinite");
57 return true;
58 }
59
60 if (flags.AnySet(FlagPositiveInf)) {
61 stream.Printf("+oo");
62 return true;
63 }
64
65 if (flags.AnySet(FlagNegativeInf)) {
66 stream.Printf("-oo");
67 return true;
68 }
69
70 switch (timescale) {
71 case 0:
72 return false;
73 case 1:
74 stream.Printf("%" PRId64 " seconds", value);
75 return true;
76 case 2:
77 stream.Printf("%" PRId64 " half seconds", value);
78 return true;
79 case 3:
80 stream.Printf("%" PRId64 " third%sof a second", value,
81 value == 1 ? " " : "s ");
82 return true;
83 default:
84 stream.Printf("%" PRId64 " %" PRId32 "th%sof a second", value, timescale,
85 value == 1 ? " " : "s ");
86 return true;
87 }
88}
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
A class to manage flags.
Definition: Flags.h:22
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
virtual CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size)=0
CompilerType GetCompilerType()
Definition: ValueObject.h:352
virtual lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
bool CMTimeSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: CoreMedia.cpp:22
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
@ eEncodingSint
signed integer