Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- LibStdcppTuple.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 "LibStdcpp.h"
10
11
#include "lldb/Core/ValueObject.h"
12
#include "lldb/DataFormatters/FormattersHelpers.h"
13
#include "lldb/DataFormatters/TypeSynthetic.h"
14
#include "lldb/Utility/ConstString.h"
15
16
#include <memory>
17
#include <vector>
18
19
using namespace lldb;
20
using namespace lldb_private;
21
using namespace lldb_private::formatters;
22
23
namespace {
24
25
class LibStdcppTupleSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
26
public:
27
  explicit LibStdcppTupleSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
28
29
  size_t CalculateNumChildren() override;
30
31
  lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
32
33
  bool Update() override;
34
35
  bool MightHaveChildren() override;
36
37
  size_t GetIndexOfChildWithName(ConstString name) override;
38
39
private:
40
  // The lifetime of a ValueObject and all its derivative ValueObjects
41
  // (children, clones, etc.) is managed by a ClusterManager. These
42
  // objects are only destroyed when every shared pointer to any of them
43
  // is destroyed, so we must not store a shared pointer to any ValueObject
44
  // derived from our backend ValueObject (since we're in the same cluster).
45
  std::vector<ValueObject*> m_members;
46
};
47
48
} // end of anonymous namespace
49
50
LibStdcppTupleSyntheticFrontEnd::LibStdcppTupleSyntheticFrontEnd(
51
    lldb::ValueObjectSP valobj_sp)
52
0
    : SyntheticChildrenFrontEnd(*valobj_sp) {
53
0
  Update();
54
0
}
55
56
0
bool LibStdcppTupleSyntheticFrontEnd::Update() {
57
0
  m_members.clear();
58
59
0
  ValueObjectSP valobj_backend_sp = m_backend.GetSP();
60
0
  if (!valobj_backend_sp)
61
0
    return false;
62
63
0
  ValueObjectSP next_child_sp = valobj_backend_sp->GetNonSyntheticValue();
64
0
  while (next_child_sp != nullptr) {
65
0
    ValueObjectSP current_child = next_child_sp;
66
0
    next_child_sp = nullptr;
67
68
0
    size_t child_count = current_child->GetNumChildren();
69
0
    for (size_t i = 0; i < child_count; ++i) {
70
0
      ValueObjectSP child_sp = current_child->GetChildAtIndex(i, true);
71
0
      llvm::StringRef name_str = child_sp->GetName().GetStringRef();
72
0
      if (name_str.startswith("std::_Tuple_impl<")) {
73
0
        next_child_sp = child_sp;
74
0
      } else if (name_str.startswith("std::_Head_base<")) {
75
0
        ValueObjectSP value_sp =
76
0
            child_sp->GetChildMemberWithName(ConstString("_M_head_impl"), true);
77
0
        if (value_sp) {
78
0
          StreamString name;
79
0
          name.Printf("[%zd]", m_members.size());
80
0
          m_members.push_back(value_sp->Clone(ConstString(name.GetString())).get());
81
0
        }
82
0
      }
83
0
    }
84
0
  }
85
86
0
  return false;
87
0
}
88
89
0
bool LibStdcppTupleSyntheticFrontEnd::MightHaveChildren() { return true; }
90
91
lldb::ValueObjectSP
92
0
LibStdcppTupleSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
93
0
  if (idx < m_members.size() && m_members[idx])
94
0
    return m_members[idx]->GetSP();
95
0
  return lldb::ValueObjectSP();
96
0
}
97
98
0
size_t LibStdcppTupleSyntheticFrontEnd::CalculateNumChildren() {
99
0
  return m_members.size();
100
0
}
101
102
size_t LibStdcppTupleSyntheticFrontEnd::GetIndexOfChildWithName(
103
0
    ConstString name) {
104
0
  return ExtractIndexFromString(name.GetCString());
105
0
}
106
107
SyntheticChildrenFrontEnd *
108
lldb_private::formatters::LibStdcppTupleSyntheticFrontEndCreator(
109
0
    CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
110
0
  return (valobj_sp ? new LibStdcppTupleSyntheticFrontEnd(valobj_sp) : nullptr);
111
0
}