Coverage Report

Created: 2023-05-31 04:38

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
Line
Count
Source (jump to first uncovered line)
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 <cinttypes>
17
18
using namespace lldb;
19
using namespace lldb_private;
20
using namespace lldb_private::formatters;
21
22
bool lldb_private::formatters::CMTimeSummaryProvider(
23
14
    ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
24
14
  CompilerType type = valobj.GetCompilerType();
25
14
  if (!type.IsValid())
26
0
    return false;
27
28
14
  auto type_system = type.GetTypeSystem();
29
14
  if (!type_system)
30
0
    return false;
31
  // fetch children by offset to compensate for potential lack of debug info
32
14
  auto int64_ty =
33
14
      type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 64);
34
14
  auto int32_ty =
35
14
      type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32);
36
37
14
  auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true));
38
14
  auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true));
39
14
  auto flags_sp(valobj.GetSyntheticChildAtOffset(12, int32_ty, true));
40
41
14
  if (!value_sp || !timescale_sp || !flags_sp)
42
0
    return false;
43
44
14
  auto value = value_sp->GetValueAsUnsigned(0);
45
14
  auto timescale = (int32_t)timescale_sp->GetValueAsUnsigned(
46
14
      0); // the timescale specifies the fraction of a second each unit in the
47
          // numerator occupies
48
14
  auto flags = Flags(flags_sp->GetValueAsUnsigned(0) &
49
14
                     0x00000000000000FF); // the flags I need sit in the LSB
50
51
14
  const unsigned int FlagPositiveInf = 4;
52
14
  const unsigned int FlagNegativeInf = 8;
53
14
  const unsigned int FlagIndefinite = 16;
54
55
14
  if (flags.AnySet(FlagIndefinite)) {
56
2
    stream.Printf("indefinite");
57
2
    return true;
58
2
  }
59
60
12
  if (flags.AnySet(FlagPositiveInf)) {
61
2
    stream.Printf("+oo");
62
2
    return true;
63
2
  }
64
65
10
  if (flags.AnySet(FlagNegativeInf)) {
66
2
    stream.Printf("-oo");
67
2
    return true;
68
2
  }
69
70
8
  switch (timescale) {
71
0
  case 0:
72
0
    return false;
73
2
  case 1:
74
2
    stream.Printf("%" PRId64 " seconds", value);
75
2
    return true;
76
2
  case 2:
77
2
    stream.Printf("%" PRId64 " half seconds", value);
78
2
    return true;
79
2
  case 3:
80
2
    stream.Printf("%" PRId64 " third%sof a second", value,
81
2
                  value == 1 ? " " : 
"s "0
);
82
2
    return true;
83
2
  default:
84
2
    stream.Printf("%" PRId64 " %" PRId32 "th%sof a second", value, timescale,
85
2
                  value == 1 ? " " : 
"s "0
);
86
2
    return true;
87
8
  }
88
8
}