Coverage Report

Created: 2023-09-21 18:56

/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
#include <optional>
18
19
namespace lldb_private {
20
class ConstString;
21
}
22
23
using namespace lldb_private;
24
25
lldb::ValueObjectSP ValueObjectCast::Create(ValueObject &parent,
26
                                            ConstString name,
27
529
                                            const CompilerType &cast_type) {
28
529
  ValueObjectCast *cast_valobj_ptr =
29
529
      new ValueObjectCast(parent, name, cast_type);
30
529
  return cast_valobj_ptr->GetSP();
31
529
}
32
33
ValueObjectCast::ValueObjectCast(ValueObject &parent, ConstString name,
34
                                 const CompilerType &cast_type)
35
533
    : ValueObject(parent), m_cast_type(cast_type) {
36
533
  SetName(name);
37
533
  m_value.SetCompilerType(cast_type);
38
533
}
39
40
147
ValueObjectCast::~ValueObjectCast() = default;
41
42
26.5k
CompilerType ValueObjectCast::GetCompilerTypeImpl() { return m_cast_type; }
43
44
424
size_t ValueObjectCast::CalculateNumChildren(uint32_t max) {
45
424
  ExecutionContext exe_ctx(GetExecutionContextRef());
46
424
  auto children_count = GetCompilerType().GetNumChildren(
47
424
      true, &exe_ctx);
48
424
  return children_count <= max ? children_count : 
max0
;
49
424
}
50
51
6
std::optional<uint64_t> ValueObjectCast::GetByteSize() {
52
6
  ExecutionContext exe_ctx(GetExecutionContextRef());
53
6
  return m_value.GetValueByteSize(nullptr, &exe_ctx);
54
6
}
55
56
8
lldb::ValueType ValueObjectCast::GetValueType() const {
57
  // Let our parent answer global, local, argument, etc...
58
8
  return m_parent->GetValueType();
59
8
}
60
61
509
bool ValueObjectCast::UpdateValue() {
62
509
  SetValueIsValid(false);
63
509
  m_error.Clear();
64
65
509
  if (m_parent->UpdateValueIfNeeded(false)) {
66
509
    Value old_value(m_value);
67
509
    m_update_point.SetUpdated();
68
509
    m_value = m_parent->GetValue();
69
509
    CompilerType compiler_type(GetCompilerType());
70
509
    m_value.SetCompilerType(compiler_type);
71
509
    SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
72
509
    if (!CanProvideValue()) {
73
      // this value object represents an aggregate type whose children have
74
      // values, but this object does not. So we say we are changed if our
75
      // location has changed.
76
272
      SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() ||
77
272
                        
m_value.GetScalar() != old_value.GetScalar()2
);
78
272
    }
79
509
    ExecutionContext exe_ctx(GetExecutionContextRef());
80
509
    m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());
81
509
    SetValueDidChange(m_parent->GetValueDidChange());
82
509
    return true;
83
509
  }
84
85
  // The dynamic value failed to get an error, pass the error along
86
0
  if (m_error.Success() && m_parent->GetError().Fail())
87
0
    m_error = m_parent->GetError();
88
0
  SetValueIsValid(false);
89
0
  return false;
90
509
}
91
92
711
bool ValueObjectCast::IsInScope() { return m_parent->IsInScope(); }