Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- LibCxxTuple.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 "LibCxx.h"
10
#include "lldb/DataFormatters/FormattersHelpers.h"
11
12
using namespace lldb;
13
using namespace lldb_private;
14
15
namespace {
16
17
class TupleFrontEnd: public SyntheticChildrenFrontEnd {
18
public:
19
169
  TupleFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
20
169
    Update();
21
169
  }
22
23
0
  size_t GetIndexOfChildWithName(ConstString name) override {
24
0
    return formatters::ExtractIndexFromString(name.GetCString());
25
0
  }
26
27
3
  bool MightHaveChildren() override { return true; }
28
  bool Update() override;
29
148
  size_t CalculateNumChildren() override { return m_elements.size(); }
30
  ValueObjectSP GetChildAtIndex(size_t idx) override;
31
32
private:
33
  // The lifetime of a ValueObject and all its derivative ValueObjects
34
  // (children, clones, etc.) is managed by a ClusterManager. These
35
  // objects are only destroyed when every shared pointer to any of them
36
  // is destroyed, so we must not store a shared pointer to any ValueObject
37
  // derived from our backend ValueObject (since we're in the same cluster).
38
  std::vector<ValueObject*> m_elements;
39
  ValueObject* m_base = nullptr;
40
};
41
}
42
43
338
bool TupleFrontEnd::Update() {
44
338
  m_elements.clear();
45
338
  m_base = nullptr;
46
47
338
  ValueObjectSP base_sp;
48
338
  base_sp = m_backend.GetChildMemberWithName(ConstString("__base_"), true);
49
338
  if (!base_sp) {
50
    // Pre r304382 name of the base element.
51
80
    base_sp = m_backend.GetChildMemberWithName(ConstString("base_"), true);
52
80
  }
53
338
  if (!base_sp)
54
80
    return false;
55
258
  m_base = base_sp.get();
56
258
  m_elements.assign(base_sp->GetCompilerType().GetNumDirectBaseClasses(),
57
258
                    nullptr);
58
258
  return false;
59
338
}
60
61
21
ValueObjectSP TupleFrontEnd::GetChildAtIndex(size_t idx) {
62
21
  if (idx >= m_elements.size())
63
0
    return ValueObjectSP();
64
21
  if (!m_base)
65
0
    return ValueObjectSP();
66
21
  if (m_elements[idx])
67
0
    return m_elements[idx]->GetSP();
68
69
21
  CompilerType holder_type =
70
21
      m_base->GetCompilerType().GetDirectBaseClassAtIndex(idx, nullptr);
71
21
  if (!holder_type)
72
0
    return ValueObjectSP();
73
21
  ValueObjectSP holder_sp = m_base->GetChildAtIndex(idx, true);
74
21
  if (!holder_sp)
75
0
    return ValueObjectSP();
76
77
21
  ValueObjectSP elem_sp = holder_sp->GetChildAtIndex(0, true);
78
21
  if (elem_sp)
79
21
    m_elements[idx] =
80
21
        elem_sp->Clone(ConstString(llvm::formatv("[{0}]", idx).str())).get();
81
82
21
  if (m_elements[idx])
83
21
    return m_elements[idx]->GetSP();
84
0
  return ValueObjectSP();
85
21
}
86
87
SyntheticChildrenFrontEnd *
88
formatters::LibcxxTupleFrontEndCreator(CXXSyntheticChildren *,
89
169
                                       lldb::ValueObjectSP valobj_sp) {
90
169
  if (valobj_sp)
91
169
    return new TupleFrontEnd(*valobj_sp);
92
0
  return nullptr;
93
169
}