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 
14 #include "lldb/Symbol/TypeSystem.h"
15 #include "lldb/Target/Target.h"
16 #include <inttypes.h>
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 using 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_or_err =
29  valobj.GetExecutionContextRef()
30  .GetTargetSP()
31  ->GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC);
32  if (auto err = type_system_or_err.takeError()) {
35  std::move(err), "Failed to get scratch type system");
36  return false;
37  }
38  // fetch children by offset to compensate for potential lack of debug info
39  auto int64_ty = type_system_or_err->GetBuiltinTypeForEncodingAndBitSize(
40  eEncodingSint, 64);
41  auto int32_ty = type_system_or_err->GetBuiltinTypeForEncodingAndBitSize(
42  eEncodingSint, 32);
43 
44  auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true));
45  auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true));
46  auto flags_sp(valobj.GetSyntheticChildAtOffset(12, int32_ty, true));
47 
48  if (!value_sp || !timescale_sp || !flags_sp)
49  return false;
50 
51  auto value = value_sp->GetValueAsUnsigned(0);
52  auto timescale = (int32_t)timescale_sp->GetValueAsUnsigned(
53  0); // the timescale specifies the fraction of a second each unit in the
54  // numerator occupies
55  auto flags = Flags(flags_sp->GetValueAsUnsigned(0) &
56  0x00000000000000FF); // the flags I need sit in the LSB
57 
58  const unsigned int FlagPositiveInf = 4;
59  const unsigned int FlagNegativeInf = 8;
60  const unsigned int FlagIndefinite = 16;
61 
62  if (flags.AnySet(FlagIndefinite)) {
63  stream.Printf("indefinite");
64  return true;
65  }
66 
67  if (flags.AnySet(FlagPositiveInf)) {
68  stream.Printf("+oo");
69  return true;
70  }
71 
72  if (flags.AnySet(FlagNegativeInf)) {
73  stream.Printf("-oo");
74  return true;
75  }
76 
77  if (timescale == 0)
78  return false;
79 
80  switch (timescale) {
81  case 0:
82  return false;
83  case 1:
84  stream.Printf("%" PRId64 " seconds", value);
85  return true;
86  case 2:
87  stream.Printf("%" PRId64 " half seconds", value);
88  return true;
89  case 3:
90  stream.Printf("%" PRId64 " third%sof a second", value,
91  value == 1 ? " " : "s ");
92  return true;
93  default:
94  stream.Printf("%" PRId64 " %" PRId32 "th%sof a second", value, timescale,
95  value == 1 ? " " : "s ");
96  return true;
97  }
98 }
#define LIBLLDB_LOG_DATAFORMATTERS
Definition: Logging.h:43
CompilerType GetCompilerType()
A class that represents a running process on the host machine.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:265
virtual lldb::ValueObjectSP GetSyntheticChildAtOffset(uint32_t offset, const CompilerType &type, bool can_create, ConstString name_const_str=ConstString())
const ExecutionContextRef & GetExecutionContextRef() const
Definition: ValueObject.h:331
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb::TargetSP GetTargetSP() const
Get accessor that creates a strong reference from the weak target reference contained in this object...
A class to manage flags.
Definition: Flags.h:22
Non-standardized C, such as K&R.
Log * GetLogIfAnyCategoriesSet(uint32_t mask)
Definition: Logging.cpp:62
Definition: SBAddress.h:15
Represents a generic type in a programming language.
Definition: CompilerType.h:33
bool CMTimeSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: CoreMedia.cpp:22