Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/ValueObjectCast.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ValueObjectCast.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 "lldb/Core/ValueObjectCast.h"
10
11
#include "lldb/Core/Value.h"
12
#include "lldb/Core/ValueObject.h"
13
#include "lldb/Symbol/CompilerType.h"
14
#include "lldb/Target/ExecutionContext.h"
15
#include "lldb/Utility/Scalar.h"
16
#include "lldb/Utility/Status.h"
17
18
namespace lldb_private {
19
class ConstString;
20
}
21
22
using namespace lldb_private;
23
24
lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
25
                                            ConstString name,
26
178
                                            const CompilerType &cast_type) {
27
178
  ValueObjectCast *cast_valobj_ptr =
28
178
      new ValueObjectCast(parent, name, cast_type);
29
178
  return cast_valobj_ptr->GetSP();
30
178
}
31
32
ValueObjectCast::ValueObjectCast(ValueObject &parent, ConstString name,
33
                                 const CompilerType &cast_type)
34
181
    : ValueObject(parent), m_cast_type(cast_type) {
35
181
  SetName(name);
36
181
  m_value.SetCompilerType(cast_type);
37
181
}
38
39
178
ValueObjectCast::~ValueObjectCast() = default;
40
41
8.47k
CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
42
43
168
size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
44
168
  ExecutionContext exe_ctx(GetExecutionContextRef());
45
168
  auto children_count = GetCompilerType().GetNumChildren(
46
168
      true, &exe_ctx);
47
168
  return children_count <= max ? children_count : 
max0
;
48
168
}
49
50
6
llvm::Optional<uint64_t> ValueObjectCast::GetByteSize() {
51
6
  ExecutionContext exe_ctx(GetExecutionContextRef());
52
6
  return m_value.GetValueByteSize(nullptr, &exe_ctx);
53
6
}
54
55
12
lldb::ValueType ValueObjectCast::GetValueType() const {
56
  // Let our parent answer global, local, argument, etc...
57
12
  return m_parent->GetValueType();
58
12
}
59
60
183
bool ValueObjectCast::UpdateValue() {
61
183
  SetValueIsValid(false);
62
183
  m_error.Clear();
63
64
183
  if (m_parent->UpdateValueIfNeeded(false)) {
65
180
    Value old_value(m_value);
66
180
    m_update_point.SetUpdated();
67
180
    m_value = m_parent->GetValue();
68
180
    CompilerType compiler_type(GetCompilerType());
69
180
    m_value.SetCompilerType(compiler_type);
70
180
    SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
71
180
    if (!CanProvideValue()) {
72
      // this value object represents an aggregate type whose children have
73
      // values, but this object does not. So we say we are changed if our
74
      // location has changed.
75
123
      SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
76
123
                        
m_value.GetScalar() != old_value.GetScalar()0
);
77
123
    }
78
180
    ExecutionContext exe_ctx(GetExecutionContextRef());
79
180
    m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
80
180
    SetValueDidChange(m_parent->GetValueDidChange());
81
180
    return true;
82
180
  }
83
84
  // The dynamic value failed to get an error, pass the error along
85
3
  if (m_error.Success() && m_parent->GetError().Fail())
86
3
    m_error = m_parent->GetError();
87
3
  SetValueIsValid(false);
88
3
  return false;
89
183
}
90
91
204
bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }