Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmDebuggerVariables.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
4
#include "cmDebuggerVariables.h"
5
6
#include <algorithm>
7
#include <vector>
8
9
#include <cm3p/cppdap/optional.h>
10
#include <cm3p/cppdap/protocol.h>
11
#include <cm3p/cppdap/types.h>
12
13
#include "cmDebuggerVariablesManager.h"
14
15
namespace cmDebugger {
16
17
namespace {
18
dap::VariablePresentationHint const PrivatePropertyHint = { {},
19
                                                            "property",
20
                                                            {},
21
                                                            "private" };
22
dap::VariablePresentationHint const PrivateDataHint = { {},
23
                                                        "data",
24
                                                        {},
25
                                                        "private" };
26
}
27
28
std::atomic<int64_t> cmDebuggerVariables::NextId(1);
29
30
cmDebuggerVariables::cmDebuggerVariables(
31
  std::shared_ptr<cmDebuggerVariablesManager> variablesManager,
32
  std::string name, bool supportsVariableType)
33
0
  : Id(NextId.fetch_add(1))
34
0
  , Name(std::move(name))
35
0
  , SupportsVariableType(supportsVariableType)
36
0
  , VariablesManager(std::move(variablesManager))
37
0
{
38
0
  VariablesManager->RegisterHandler(
39
0
    Id, [this](dap::VariablesRequest const& request) {
40
0
      (void)request;
41
0
      return this->HandleVariablesRequest();
42
0
    });
43
0
}
44
45
cmDebuggerVariables::cmDebuggerVariables(
46
  std::shared_ptr<cmDebuggerVariablesManager> variablesManager,
47
  std::string name, bool supportsVariableType,
48
  std::function<std::vector<cmDebuggerVariableEntry>()> getKeyValuesFunction)
49
0
  : Id(NextId.fetch_add(1))
50
0
  , Name(std::move(name))
51
0
  , GetKeyValuesFunction(std::move(getKeyValuesFunction))
52
0
  , SupportsVariableType(supportsVariableType)
53
0
  , VariablesManager(std::move(variablesManager))
54
0
{
55
0
  VariablesManager->RegisterHandler(
56
0
    Id, [this](dap::VariablesRequest const& request) {
57
0
      (void)request;
58
0
      return this->HandleVariablesRequest();
59
0
    });
60
0
}
61
62
void cmDebuggerVariables::AddSubVariables(
63
  std::shared_ptr<cmDebuggerVariables> const& variables)
64
0
{
65
0
  if (variables) {
66
0
    SubVariables.emplace_back(variables);
67
0
  }
68
0
}
69
70
dap::array<dap::Variable> cmDebuggerVariables::HandleVariablesRequest()
71
0
{
72
0
  dap::array<dap::Variable> variables;
73
74
0
  if (GetKeyValuesFunction) {
75
0
    auto values = GetKeyValuesFunction();
76
0
    for (auto const& entry : values) {
77
0
      if (IgnoreEmptyStringEntries && entry.Type == "string" &&
78
0
          entry.Value.empty()) {
79
0
        continue;
80
0
      }
81
0
      variables.push_back(dap::Variable{
82
0
        {},
83
0
        {},
84
0
        {},
85
0
        entry.Name,
86
0
        {},
87
0
        PrivateDataHint,
88
0
        SupportsVariableType ? entry.Type : dap::optional<dap::string>(),
89
0
        entry.Value,
90
0
        0 });
91
0
    }
92
0
  }
93
94
0
  EnumerateSubVariablesIfAny(variables);
95
96
0
  if (EnableSorting) {
97
0
    std::sort(variables.begin(), variables.end(),
98
0
              [](dap::Variable const& a, dap::Variable const& b) {
99
0
                return a.name < b.name;
100
0
              });
101
0
  }
102
0
  return variables;
103
0
}
104
105
void cmDebuggerVariables::EnumerateSubVariablesIfAny(
106
  dap::array<dap::Variable>& toBeReturned) const
107
0
{
108
0
  dap::array<dap::Variable> ret;
109
0
  for (auto const& variables : SubVariables) {
110
0
    toBeReturned.emplace_back(dap::Variable{
111
0
      {},
112
0
      {},
113
0
      {},
114
0
      variables->GetName(),
115
0
      {},
116
0
      PrivatePropertyHint,
117
0
      SupportsVariableType ? "collection" : dap::optional<dap::string>(),
118
0
      variables->GetValue(),
119
0
      variables->GetId() });
120
0
  }
121
0
}
122
123
void cmDebuggerVariables::ClearSubVariables()
124
0
{
125
0
  SubVariables.clear();
126
0
}
127
128
cmDebuggerVariables::~cmDebuggerVariables()
129
0
{
130
0
  ClearSubVariables();
131
0
  VariablesManager->UnregisterHandler(Id);
132
0
}
133
134
} // namespace cmDebugger