LLDB mainline
VariableList.cpp
Go to the documentation of this file.
1//===-- VariableList.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
10
11#include "lldb/Symbol/Block.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19// VariableList constructor
21
22// Destructor
24
26 m_variables.push_back(var_sp);
27}
28
30 if (FindVariableIndex(var_sp) == UINT32_MAX) {
31 m_variables.push_back(var_sp);
32 return true;
33 }
34 return false;
35}
36
38 if (variable_list) {
39 std::copy(variable_list->m_variables.begin(), // source begin
40 variable_list->m_variables.end(), // source end
41 back_inserter(m_variables)); // destination
42 }
43}
44
46
48 VariableSP var_sp;
49 if (idx < m_variables.size())
50 var_sp = m_variables[idx];
51 return var_sp;
52}
53
55 VariableSP var_sp;
56 if (idx < m_variables.size()) {
57 var_sp = m_variables[idx];
58 m_variables.erase(m_variables.begin() + idx);
59 }
60 return var_sp;
61}
62
64 iterator pos, end = m_variables.end();
65 for (pos = m_variables.begin(); pos != end; ++pos) {
66 if (pos->get() == var_sp.get())
67 return std::distance(m_variables.begin(), pos);
68 }
69 return UINT32_MAX;
70}
71
73 bool include_static_members) const {
74 for (const auto &var_sp : m_variables)
75 if (var_sp->NameMatches(name))
76 if (include_static_members || !var_sp->IsStaticMember())
77 return var_sp;
78 return {};
79}
80
82 lldb::ValueType value_type,
83 bool include_static_members) const {
84 for (const auto &var_sp : m_variables)
85 if (var_sp->NameMatches(name) && var_sp->GetScope() == value_type)
86 if (include_static_members || !var_sp->IsStaticMember())
87 return var_sp;
88 return {};
89}
90
92 const size_t initial_size = var_list.GetSize();
93 iterator pos, end = m_variables.end();
94 for (pos = m_variables.begin(); pos != end; ++pos)
95 var_list.AddVariableIfUnique(*pos);
96 return var_list.GetSize() - initial_size;
97}
98
100 VariableList &var_list,
101 size_t &total_matches) {
102 const size_t initial_size = var_list.GetSize();
103 iterator pos, end = m_variables.end();
104 for (pos = m_variables.begin(); pos != end; ++pos) {
105 if ((*pos)->NameMatches(regex)) {
106 // Note the total matches found
107 total_matches++;
108 // Only add this variable if it isn't already in the "var_list"
109 var_list.AddVariableIfUnique(*pos);
110 }
111 }
112 // Return the number of new unique variables added to "var_list"
113 return var_list.GetSize() - initial_size;
114}
115
117 VariableList &var_list,
118 bool if_unique) {
119 const size_t initial_size = var_list.GetSize();
120 iterator pos, end = m_variables.end();
121 for (pos = m_variables.begin(); pos != end; ++pos) {
122 if ((*pos)->GetScope() == type) {
123 if (if_unique)
124 var_list.AddVariableIfUnique(*pos);
125 else
126 var_list.AddVariable(*pos);
127 }
128 }
129 // Return the number of new unique variables added to "var_list"
130 return var_list.GetSize() - initial_size;
131}
132
134 VariableSP var_sp;
135 iterator pos;
136 const iterator begin = m_variables.begin();
137 const iterator end = m_variables.end();
138 for (pos = m_variables.begin(); pos != end; ++pos) {
139 if ((*pos).get() == variable)
140 return std::distance(begin, pos);
141 }
142 return UINT32_MAX;
143}
144
146 size_t mem_size = sizeof(VariableList);
147 const_iterator pos, end = m_variables.end();
148 for (pos = m_variables.begin(); pos != end; ++pos)
149 mem_size += (*pos)->MemorySize();
150 return mem_size;
151}
152
153size_t VariableList::GetSize() const { return m_variables.size(); }
154
155void VariableList::Dump(Stream *s, bool show_context) const {
156 // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
157 // s.Indent();
158 // s << "VariableList\n";
159
160 const_iterator pos, end = m_variables.end();
161 for (pos = m_variables.begin(); pos != end; ++pos) {
162 (*pos)->Dump(s, show_context);
163 }
164}
A uniqued constant string class.
Definition ConstString.h:40
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Dump(Stream *s, bool show_context) const
bool AddVariableIfUnique(const lldb::VariableSP &var_sp)
lldb::VariableSP GetVariableAtIndex(size_t idx) const
uint32_t FindVariableIndex(const lldb::VariableSP &var_sp)
lldb::VariableSP RemoveVariableAtIndex(size_t idx)
collection::const_iterator const_iterator
uint32_t FindIndexForVariable(Variable *variable)
void AddVariable(const lldb::VariableSP &var_sp)
size_t AppendVariablesWithScope(lldb::ValueType type, VariableList &var_list, bool if_unique=true)
lldb::VariableSP FindVariable(ConstString name, bool include_static_members=true) const
collection::iterator iterator
void AddVariables(VariableList *variable_list)
size_t AppendVariablesIfUnique(VariableList &var_list)
#define UINT32_MAX
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Variable > VariableSP