Coverage Report

Created: 2022-01-18 06:27

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