/src/CMake/Source/cmDebuggerVariablesHelper.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 "cmDebuggerVariablesHelper.h" |
5 | | |
6 | | #include <algorithm> |
7 | | #include <cstddef> |
8 | | #include <functional> |
9 | | #include <iomanip> |
10 | | #include <iterator> |
11 | | #include <map> |
12 | | #include <sstream> |
13 | | |
14 | | #include "cm_codecvt_Encoding.hxx" |
15 | | |
16 | | #include "cmDebuggerStackFrame.h" |
17 | | #include "cmDebuggerVariables.h" |
18 | | #include "cmFileSet.h" |
19 | | #include "cmFileSetMetadata.h" |
20 | | #include "cmGlobalGenerator.h" |
21 | | #include "cmList.h" |
22 | | #include "cmListFileCache.h" |
23 | | #include "cmMakefile.h" |
24 | | #include "cmPropertyMap.h" |
25 | | #include "cmState.h" |
26 | | #include "cmStateSnapshot.h" |
27 | | #include "cmStringAlgorithms.h" |
28 | | #include "cmTarget.h" |
29 | | #include "cmTest.h" |
30 | | #include "cmValue.h" |
31 | | #include "cmake.h" |
32 | | |
33 | | namespace cmDebugger { |
34 | | |
35 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::Create( |
36 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
37 | | std::string const& name, bool supportsVariableType, |
38 | | cmPolicies::PolicyMap const& policyMap) |
39 | 0 | { |
40 | 0 | static std::map<cmPolicies::PolicyStatus, std::string> policyStatusString = { |
41 | 0 | { cmPolicies::PolicyStatus::OLD, "OLD" }, |
42 | 0 | { cmPolicies::PolicyStatus::WARN, "WARN" }, |
43 | 0 | { cmPolicies::PolicyStatus::NEW, "NEW" }, |
44 | 0 | }; |
45 | |
|
46 | 0 | return std::make_shared<cmDebuggerVariables>( |
47 | 0 | variablesManager, name, supportsVariableType, [=]() { |
48 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
49 | 0 | ret.reserve(cmPolicies::CMPCOUNT); |
50 | 0 | for (int i = 0; i < cmPolicies::CMPCOUNT; ++i) { |
51 | 0 | if (policyMap.IsDefined(static_cast<cmPolicies::PolicyID>(i))) { |
52 | 0 | auto status = policyMap.Get(static_cast<cmPolicies::PolicyID>(i)); |
53 | 0 | std::ostringstream ss; |
54 | 0 | ss << "CMP" << std::setfill('0') << std::setw(4) << i; |
55 | 0 | ret.emplace_back(ss.str(), policyStatusString[status]); |
56 | 0 | } |
57 | 0 | } |
58 | 0 | return ret; |
59 | 0 | }); |
60 | 0 | } |
61 | | |
62 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
63 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
64 | | std::string const& name, bool supportsVariableType, |
65 | | std::vector<std::pair<std::string, std::string>> const& list) |
66 | 0 | { |
67 | 0 | if (list.empty()) { |
68 | 0 | return {}; |
69 | 0 | } |
70 | | |
71 | 0 | auto listVariables = std::make_shared<cmDebuggerVariables>( |
72 | 0 | variablesManager, name, supportsVariableType, [=]() { |
73 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
74 | 0 | ret.reserve(list.size()); |
75 | 0 | for (auto const& kv : list) { |
76 | 0 | ret.emplace_back(kv.first, kv.second); |
77 | 0 | } |
78 | 0 | return ret; |
79 | 0 | }); |
80 | |
|
81 | 0 | listVariables->SetValue(std::to_string(list.size())); |
82 | 0 | return listVariables; |
83 | 0 | } |
84 | | |
85 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
86 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
87 | | std::string const& name, bool supportsVariableType, cmBTStringRange entries) |
88 | 0 | { |
89 | 0 | if (entries.empty()) { |
90 | 0 | return {}; |
91 | 0 | } |
92 | | |
93 | 0 | auto sourceEntries = std::make_shared<cmDebuggerVariables>( |
94 | 0 | variablesManager, name, supportsVariableType); |
95 | |
|
96 | 0 | for (auto const& entry : entries) { |
97 | 0 | auto arrayVariables = std::make_shared<cmDebuggerVariables>( |
98 | 0 | variablesManager, entry.Value, supportsVariableType, [=]() { |
99 | 0 | cmList items{ entry.Value }; |
100 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
101 | 0 | ret.reserve(items.size()); |
102 | 0 | int i = 0; |
103 | 0 | for (std::string const& item : items) { |
104 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), item); |
105 | 0 | } |
106 | 0 | return ret; |
107 | 0 | }); |
108 | 0 | arrayVariables->SetEnableSorting(false); |
109 | 0 | sourceEntries->AddSubVariables(arrayVariables); |
110 | 0 | } |
111 | |
|
112 | 0 | sourceEntries->SetValue(std::to_string(entries.size())); |
113 | 0 | return sourceEntries; |
114 | 0 | } |
115 | | |
116 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
117 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
118 | | std::string const& name, bool supportsVariableType, |
119 | | std::set<std::string> const& values) |
120 | 0 | { |
121 | 0 | if (values.empty()) { |
122 | 0 | return {}; |
123 | 0 | } |
124 | | |
125 | 0 | auto arrayVariables = std::make_shared<cmDebuggerVariables>( |
126 | 0 | variablesManager, name, supportsVariableType, [=]() { |
127 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
128 | 0 | ret.reserve(values.size()); |
129 | 0 | int i = 0; |
130 | 0 | for (std::string const& value : values) { |
131 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), value); |
132 | 0 | } |
133 | 0 | return ret; |
134 | 0 | }); |
135 | 0 | arrayVariables->SetValue(std::to_string(values.size())); |
136 | 0 | arrayVariables->SetEnableSorting(false); |
137 | 0 | return arrayVariables; |
138 | 0 | } |
139 | | |
140 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
141 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
142 | | std::string const& name, bool supportsVariableType, |
143 | | std::vector<std::string> const& values) |
144 | 0 | { |
145 | 0 | if (values.empty()) { |
146 | 0 | return {}; |
147 | 0 | } |
148 | | |
149 | 0 | auto arrayVariables = std::make_shared<cmDebuggerVariables>( |
150 | 0 | variablesManager, name, supportsVariableType, [=]() { |
151 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
152 | 0 | ret.reserve(values.size()); |
153 | 0 | int i = 0; |
154 | 0 | for (std::string const& value : values) { |
155 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), value); |
156 | 0 | } |
157 | 0 | return ret; |
158 | 0 | }); |
159 | |
|
160 | 0 | arrayVariables->SetValue(std::to_string(values.size())); |
161 | 0 | arrayVariables->SetEnableSorting(false); |
162 | 0 | return arrayVariables; |
163 | 0 | } |
164 | | |
165 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
166 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
167 | | std::string const& name, bool supportsVariableType, |
168 | | std::vector<BT<std::string>> const& list) |
169 | 0 | { |
170 | 0 | if (list.empty()) { |
171 | 0 | return {}; |
172 | 0 | } |
173 | | |
174 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
175 | 0 | variablesManager, name, supportsVariableType, [=]() { |
176 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
177 | 0 | ret.reserve(list.size()); |
178 | 0 | int i = 0; |
179 | 0 | for (auto const& item : list) { |
180 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), item.Value); |
181 | 0 | } |
182 | |
|
183 | 0 | return ret; |
184 | 0 | }); |
185 | |
|
186 | 0 | variables->SetValue(std::to_string(list.size())); |
187 | 0 | variables->SetEnableSorting(false); |
188 | 0 | return variables; |
189 | 0 | } |
190 | | |
191 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
192 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
193 | | std::string const& name, bool supportsVariableType, cmFileSet* fileSet) |
194 | 0 | { |
195 | 0 | if (!fileSet) { |
196 | 0 | return {}; |
197 | 0 | } |
198 | | |
199 | 0 | static auto visibilityString = |
200 | 0 | [](cm::FileSetMetadata::Visibility visibility) { |
201 | 0 | switch (visibility) { |
202 | 0 | case cm::FileSetMetadata::Visibility::Private: |
203 | 0 | return "Private"; |
204 | 0 | case cm::FileSetMetadata::Visibility::Public: |
205 | 0 | return "Public"; |
206 | 0 | case cm::FileSetMetadata::Visibility::Interface: |
207 | 0 | return "Interface"; |
208 | 0 | default: |
209 | 0 | return "Unknown"; |
210 | 0 | } |
211 | 0 | }; |
212 | |
|
213 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
214 | 0 | variablesManager, name, supportsVariableType, [=]() { |
215 | 0 | std::vector<cmDebuggerVariableEntry> ret{ |
216 | 0 | { "Name", fileSet->GetName() }, |
217 | 0 | { "Type", fileSet->GetType() }, |
218 | 0 | { "Visibility", visibilityString(fileSet->GetVisibility()) }, |
219 | 0 | }; |
220 | |
|
221 | 0 | return ret; |
222 | 0 | }); |
223 | |
|
224 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "Directories", |
225 | 0 | supportsVariableType, |
226 | 0 | fileSet->GetDirectoryEntries())); |
227 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "Files", |
228 | 0 | supportsVariableType, |
229 | 0 | fileSet->GetFileEntries())); |
230 | 0 | return variables; |
231 | 0 | } |
232 | | |
233 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
234 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
235 | | std::string const& name, bool supportsVariableType, |
236 | | std::vector<cmFileSet*> const& fileSets) |
237 | 0 | { |
238 | 0 | if (fileSets.empty()) { |
239 | 0 | return {}; |
240 | 0 | } |
241 | | |
242 | 0 | auto fileSetsVariables = std::make_shared<cmDebuggerVariables>( |
243 | 0 | variablesManager, name, supportsVariableType); |
244 | |
|
245 | 0 | for (auto const& fileSet : fileSets) { |
246 | 0 | fileSetsVariables->AddSubVariables(CreateIfAny( |
247 | 0 | variablesManager, fileSet->GetName(), supportsVariableType, fileSet)); |
248 | 0 | } |
249 | |
|
250 | 0 | return fileSetsVariables; |
251 | 0 | } |
252 | | |
253 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
254 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
255 | | std::string const& name, bool supportsVariableType, |
256 | | std::vector<cmTarget*> const& targets) |
257 | 0 | { |
258 | 0 | if (targets.empty()) { |
259 | 0 | return {}; |
260 | 0 | } |
261 | | |
262 | 0 | auto targetsVariables = std::make_shared<cmDebuggerVariables>( |
263 | 0 | variablesManager, name, supportsVariableType); |
264 | |
|
265 | 0 | for (auto const& target : targets) { |
266 | 0 | auto targetVariables = std::make_shared<cmDebuggerVariables>( |
267 | 0 | variablesManager, target->GetName(), supportsVariableType, [=]() { |
268 | 0 | std::vector<cmDebuggerVariableEntry> ret = { |
269 | 0 | { "InstallPath", target->GetInstallPath() }, |
270 | 0 | { "IsAIX", target->IsAIX() }, |
271 | 0 | { "IsAndroidGuiExecutable", target->IsAndroidGuiExecutable() }, |
272 | 0 | { "IsAppBundleOnApple", target->IsAppBundleOnApple() }, |
273 | 0 | { "IsDLLPlatform", target->IsDLLPlatform() }, |
274 | 0 | { "IsExecutableWithExports", target->IsExecutableWithExports() }, |
275 | 0 | { "IsFrameworkOnApple", target->IsFrameworkOnApple() }, |
276 | 0 | { "IsImported", target->IsImported() }, |
277 | 0 | { "IsImportedGloballyVisible", target->IsImportedGloballyVisible() }, |
278 | 0 | { "IsPerConfig", target->IsPerConfig() }, |
279 | 0 | { "Name", target->GetName() }, |
280 | 0 | { "RuntimeInstallPath", target->GetRuntimeInstallPath() }, |
281 | 0 | { "Type", cmState::GetTargetTypeName(target->GetType()) }, |
282 | 0 | }; |
283 | |
|
284 | 0 | return ret; |
285 | 0 | }); |
286 | 0 | targetVariables->SetValue(cmState::GetTargetTypeName(target->GetType())); |
287 | |
|
288 | 0 | targetVariables->AddSubVariables(Create(variablesManager, "PolicyMap", |
289 | 0 | supportsVariableType, |
290 | 0 | target->GetPolicyMap())); |
291 | 0 | targetVariables->AddSubVariables( |
292 | 0 | CreateIfAny(variablesManager, "Properties", supportsVariableType, |
293 | 0 | target->GetProperties().GetList())); |
294 | |
|
295 | 0 | targetVariables->AddSubVariables( |
296 | 0 | CreateIfAny(variablesManager, "IncludeDirectories", supportsVariableType, |
297 | 0 | target->GetIncludeDirectoriesEntries())); |
298 | 0 | targetVariables->AddSubVariables(CreateIfAny(variablesManager, "Sources", |
299 | 0 | supportsVariableType, |
300 | 0 | target->GetSourceEntries())); |
301 | 0 | targetVariables->AddSubVariables( |
302 | 0 | CreateIfAny(variablesManager, "CompileDefinitions", supportsVariableType, |
303 | 0 | target->GetCompileDefinitionsEntries())); |
304 | 0 | targetVariables->AddSubVariables( |
305 | 0 | CreateIfAny(variablesManager, "CompileFeatures", supportsVariableType, |
306 | 0 | target->GetCompileFeaturesEntries())); |
307 | 0 | targetVariables->AddSubVariables( |
308 | 0 | CreateIfAny(variablesManager, "CompileOptions", supportsVariableType, |
309 | 0 | target->GetCompileOptionsEntries())); |
310 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
311 | 0 | variablesManager, "CxxModuleSets", supportsVariableType, |
312 | 0 | target->GetFileSetsEntries(cm::FileSetMetadata::CXX_MODULES))); |
313 | 0 | targetVariables->AddSubVariables( |
314 | 0 | CreateIfAny(variablesManager, "HeaderSets", supportsVariableType, |
315 | 0 | target->GetFileSetsEntries(cm::FileSetMetadata::HEADERS))); |
316 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
317 | 0 | variablesManager, "InterfaceHeaderSets", supportsVariableType, |
318 | 0 | target->GetInterfaceFileSetsEntries(cm::FileSetMetadata::HEADERS))); |
319 | 0 | targetVariables->AddSubVariables( |
320 | 0 | CreateIfAny(variablesManager, "LinkDirectories", supportsVariableType, |
321 | 0 | target->GetLinkDirectoriesEntries())); |
322 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
323 | 0 | variablesManager, "LinkImplementations", supportsVariableType, |
324 | 0 | target->GetLinkImplementationEntries())); |
325 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
326 | 0 | variablesManager, "LinkInterfaceDirects", supportsVariableType, |
327 | 0 | target->GetLinkInterfaceDirectEntries())); |
328 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
329 | 0 | variablesManager, "LinkInterfaceDirectExcludes", supportsVariableType, |
330 | 0 | target->GetLinkInterfaceDirectExcludeEntries())); |
331 | 0 | targetVariables->AddSubVariables( |
332 | 0 | CreateIfAny(variablesManager, "LinkInterfaces", supportsVariableType, |
333 | 0 | target->GetLinkInterfaceEntries())); |
334 | 0 | targetVariables->AddSubVariables( |
335 | 0 | CreateIfAny(variablesManager, "LinkOptions", supportsVariableType, |
336 | 0 | target->GetLinkOptionsEntries())); |
337 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
338 | 0 | variablesManager, "SystemIncludeDirectories", supportsVariableType, |
339 | 0 | target->GetSystemIncludeDirectories())); |
340 | 0 | targetVariables->AddSubVariables(CreateIfAny(variablesManager, "Makefile", |
341 | 0 | supportsVariableType, |
342 | 0 | target->GetMakefile())); |
343 | 0 | targetVariables->AddSubVariables( |
344 | 0 | CreateIfAny(variablesManager, "GlobalGenerator", supportsVariableType, |
345 | 0 | target->GetGlobalGenerator())); |
346 | |
|
347 | 0 | std::vector<cmFileSet*> allFileSets; |
348 | 0 | auto allFileSetNames = target->GetAllFileSetNames(); |
349 | 0 | allFileSets.reserve(allFileSetNames.size()); |
350 | 0 | for (auto const& fileSetName : allFileSetNames) { |
351 | 0 | allFileSets.emplace_back(target->GetFileSet(fileSetName)); |
352 | 0 | } |
353 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
354 | 0 | variablesManager, "AllFileSets", supportsVariableType, allFileSets)); |
355 | |
|
356 | 0 | std::vector<cmFileSet*> allInterfaceFileSets; |
357 | 0 | auto allInterfaceFileSetNames = target->GetAllInterfaceFileSets(); |
358 | 0 | allInterfaceFileSets.reserve(allInterfaceFileSetNames.size()); |
359 | 0 | for (auto const& interfaceFileSetName : allInterfaceFileSetNames) { |
360 | 0 | allInterfaceFileSets.emplace_back( |
361 | 0 | target->GetFileSet(interfaceFileSetName)); |
362 | 0 | } |
363 | 0 | targetVariables->AddSubVariables( |
364 | 0 | CreateIfAny(variablesManager, "AllInterfaceFileSets", |
365 | 0 | supportsVariableType, allInterfaceFileSets)); |
366 | |
|
367 | 0 | targetVariables->SetIgnoreEmptyStringEntries(true); |
368 | 0 | targetsVariables->AddSubVariables(targetVariables); |
369 | 0 | } |
370 | |
|
371 | 0 | targetsVariables->SetValue(std::to_string(targets.size())); |
372 | 0 | return targetsVariables; |
373 | 0 | } |
374 | | |
375 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::Create( |
376 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
377 | | std::string const& name, bool supportsVariableType, |
378 | | std::shared_ptr<cmDebuggerStackFrame> const& frame) |
379 | 0 | { |
380 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
381 | 0 | variablesManager, name, supportsVariableType, [=]() { |
382 | 0 | return std::vector<cmDebuggerVariableEntry>{ { "CurrentLine", |
383 | 0 | frame->GetLine() } }; |
384 | 0 | }); |
385 | |
|
386 | 0 | auto closureKeys = frame->GetMakefile()->GetStateSnapshot().ClosureKeys(); |
387 | 0 | auto locals = std::make_shared<cmDebuggerVariables>( |
388 | 0 | variablesManager, "Locals", supportsVariableType, [=]() { |
389 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
390 | 0 | ret.reserve(closureKeys.size()); |
391 | 0 | for (auto const& key : closureKeys) { |
392 | 0 | ret.emplace_back( |
393 | 0 | key, frame->GetMakefile()->GetStateSnapshot().GetDefinition(key)); |
394 | 0 | } |
395 | 0 | return ret; |
396 | 0 | }); |
397 | 0 | locals->SetValue(std::to_string(closureKeys.size())); |
398 | 0 | variables->AddSubVariables(locals); |
399 | |
|
400 | 0 | std::function<bool(std::string const&)> isDirectory = |
401 | 0 | [](std::string const& key) { |
402 | 0 | size_t pos1 = key.rfind("_DIR"); |
403 | 0 | size_t pos2 = key.rfind("_DIRECTORY"); |
404 | 0 | return !((pos1 == std::string::npos || pos1 != key.size() - 4) && |
405 | 0 | (pos2 == std::string::npos || pos2 != key.size() - 10)); |
406 | 0 | }; |
407 | 0 | auto directorySize = |
408 | 0 | std::count_if(closureKeys.begin(), closureKeys.end(), isDirectory); |
409 | 0 | auto directories = std::make_shared<cmDebuggerVariables>( |
410 | 0 | variablesManager, "Directories", supportsVariableType, [=]() { |
411 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
412 | 0 | ret.reserve(directorySize); |
413 | 0 | for (auto const& key : closureKeys) { |
414 | 0 | if (isDirectory(key)) { |
415 | 0 | ret.emplace_back( |
416 | 0 | key, frame->GetMakefile()->GetStateSnapshot().GetDefinition(key)); |
417 | 0 | } |
418 | 0 | } |
419 | 0 | return ret; |
420 | 0 | }); |
421 | 0 | directories->SetValue(std::to_string(directorySize)); |
422 | 0 | variables->AddSubVariables(directories); |
423 | |
|
424 | 0 | auto cacheVariables = std::make_shared<cmDebuggerVariables>( |
425 | 0 | variablesManager, "CacheVariables", supportsVariableType); |
426 | 0 | auto* state = frame->GetMakefile()->GetCMakeInstance()->GetState(); |
427 | 0 | auto keys = state->GetCacheEntryKeys(); |
428 | 0 | for (auto const& key : keys) { |
429 | 0 | auto entry = std::make_shared<cmDebuggerVariables>( |
430 | 0 | variablesManager, |
431 | 0 | cmStrCat(key, ':', |
432 | 0 | cmState::CacheEntryTypeToString(state->GetCacheEntryType(key))), |
433 | 0 | supportsVariableType, [=]() { |
434 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
435 | 0 | auto properties = state->GetCacheEntryPropertyList(key); |
436 | 0 | ret.reserve(properties.size() + 2); |
437 | 0 | for (auto const& propertyName : properties) { |
438 | 0 | ret.emplace_back(propertyName, |
439 | 0 | state->GetCacheEntryProperty(key, propertyName)); |
440 | 0 | } |
441 | |
|
442 | 0 | ret.emplace_back( |
443 | 0 | "TYPE", |
444 | 0 | cmState::CacheEntryTypeToString(state->GetCacheEntryType(key))); |
445 | 0 | ret.emplace_back("VALUE", state->GetCacheEntryValue(key)); |
446 | 0 | return ret; |
447 | 0 | }); |
448 | |
|
449 | 0 | entry->SetValue(state->GetCacheEntryValue(key)); |
450 | 0 | cacheVariables->AddSubVariables(entry); |
451 | 0 | } |
452 | |
|
453 | 0 | cacheVariables->SetValue(std::to_string(keys.size())); |
454 | 0 | variables->AddSubVariables(cacheVariables); |
455 | |
|
456 | 0 | auto targetVariables = |
457 | 0 | CreateIfAny(variablesManager, "Targets", supportsVariableType, |
458 | 0 | frame->GetMakefile()->GetOrderedTargets()); |
459 | |
|
460 | 0 | variables->AddSubVariables(targetVariables); |
461 | 0 | std::vector<cmTest*> tests; |
462 | 0 | frame->GetMakefile()->GetTests( |
463 | 0 | frame->GetMakefile()->GetDefaultConfiguration(), tests); |
464 | 0 | variables->AddSubVariables( |
465 | 0 | CreateIfAny(variablesManager, "Tests", supportsVariableType, tests)); |
466 | |
|
467 | 0 | return variables; |
468 | 0 | } |
469 | | |
470 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
471 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
472 | | std::string const& name, bool supportsVariableType, cmTest* test) |
473 | 0 | { |
474 | 0 | if (!test) { |
475 | 0 | return {}; |
476 | 0 | } |
477 | | |
478 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
479 | 0 | variablesManager, name, supportsVariableType, [=]() { |
480 | 0 | std::vector<cmDebuggerVariableEntry> ret{ |
481 | 0 | { "CommandExpandLists", test->GetCommandExpandLists() }, |
482 | 0 | { "Name", test->GetName() }, |
483 | 0 | { "OldStyle", test->GetOldStyle() }, |
484 | 0 | }; |
485 | |
|
486 | 0 | return ret; |
487 | 0 | }); |
488 | |
|
489 | 0 | variables->AddSubVariables(CreateIfAny( |
490 | 0 | variablesManager, "Command", supportsVariableType, test->GetCommand())); |
491 | |
|
492 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "Properties", |
493 | 0 | supportsVariableType, |
494 | 0 | test->GetProperties().GetList())); |
495 | 0 | return variables; |
496 | 0 | } |
497 | | |
498 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
499 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
500 | | std::string const& name, bool supportsVariableType, |
501 | | std::vector<cmTest*> const& tests) |
502 | 0 | { |
503 | 0 | if (tests.empty()) { |
504 | 0 | return {}; |
505 | 0 | } |
506 | | |
507 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
508 | 0 | variablesManager, name, supportsVariableType); |
509 | |
|
510 | 0 | for (auto const& test : tests) { |
511 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, test->GetName(), |
512 | 0 | supportsVariableType, test)); |
513 | 0 | } |
514 | 0 | variables->SetValue(std::to_string(tests.size())); |
515 | 0 | return variables; |
516 | 0 | } |
517 | | |
518 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
519 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
520 | | std::string const& name, bool supportsVariableType, cmMakefile* mf) |
521 | 0 | { |
522 | 0 | if (!mf) { |
523 | 0 | return {}; |
524 | 0 | } |
525 | | |
526 | 0 | auto AppleSDKTypeString = [&](cmMakefile::AppleSDK sdk) { |
527 | 0 | switch (sdk) { |
528 | 0 | case cmMakefile::AppleSDK::MacOS: |
529 | 0 | return "MacOS"; |
530 | 0 | case cmMakefile::AppleSDK::IPhoneOS: |
531 | 0 | return "IPhoneOS"; |
532 | 0 | case cmMakefile::AppleSDK::IPhoneSimulator: |
533 | 0 | return "IPhoneSimulator"; |
534 | 0 | case cmMakefile::AppleSDK::AppleTVOS: |
535 | 0 | return "AppleTVOS"; |
536 | 0 | case cmMakefile::AppleSDK::AppleTVSimulator: |
537 | 0 | return "AppleTVSimulator"; |
538 | 0 | default: |
539 | 0 | return "Unknown"; |
540 | 0 | } |
541 | 0 | }; |
542 | |
|
543 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
544 | 0 | variablesManager, name, supportsVariableType, [=]() { |
545 | 0 | std::vector<cmDebuggerVariableEntry> ret = { |
546 | 0 | { "DefineFlags", mf->GetDefineFlags() }, |
547 | 0 | { "DirectoryId", mf->GetDirectoryId().String }, |
548 | 0 | { "IsRootMakefile", mf->IsRootMakefile() }, |
549 | 0 | { "HomeDirectory", mf->GetHomeDirectory() }, |
550 | 0 | { "HomeOutputDirectory", mf->GetHomeOutputDirectory() }, |
551 | 0 | { "CurrentSourceDirectory", mf->GetCurrentSourceDirectory() }, |
552 | 0 | { "CurrentBinaryDirectory", mf->GetCurrentBinaryDirectory() }, |
553 | 0 | { "PlatformIs32Bit", mf->PlatformIs32Bit() }, |
554 | 0 | { "PlatformIs64Bit", mf->PlatformIs64Bit() }, |
555 | 0 | { "PlatformIsx32", mf->PlatformIsx32() }, |
556 | 0 | { "AppleSDKType", AppleSDKTypeString(mf->GetAppleSDKType()) }, |
557 | 0 | { "PlatformIsAppleEmbedded", mf->PlatformIsAppleEmbedded() } |
558 | 0 | }; |
559 | |
|
560 | 0 | return ret; |
561 | 0 | }); |
562 | |
|
563 | 0 | variables->AddSubVariables(CreateIfAny( |
564 | 0 | variablesManager, "ListFiles", supportsVariableType, mf->GetListFiles())); |
565 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "OutputFiles", |
566 | 0 | supportsVariableType, |
567 | 0 | mf->GetOutputFiles())); |
568 | |
|
569 | 0 | variables->SetIgnoreEmptyStringEntries(true); |
570 | 0 | variables->SetValue(mf->GetDirectoryId().String); |
571 | 0 | return variables; |
572 | 0 | } |
573 | | |
574 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
575 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
576 | | std::string const& name, bool supportsVariableType, cmGlobalGenerator* gen) |
577 | 0 | { |
578 | 0 | if (!gen) { |
579 | 0 | return {}; |
580 | 0 | } |
581 | | |
582 | 0 | auto makeFileEncodingString = [](codecvt_Encoding encoding) { |
583 | 0 | switch (encoding) { |
584 | 0 | case codecvt_Encoding::None: |
585 | 0 | return "None"; |
586 | 0 | case codecvt_Encoding::UTF8: |
587 | 0 | return "UTF8"; |
588 | 0 | case codecvt_Encoding::UTF8_WITH_BOM: |
589 | 0 | return "UTF8_WITH_BOM"; |
590 | 0 | case codecvt_Encoding::ANSI: |
591 | 0 | return "ANSI"; |
592 | 0 | case codecvt_Encoding::ConsoleOutput: |
593 | 0 | return "ConsoleOutput"; |
594 | 0 | default: |
595 | 0 | return "Unknown"; |
596 | 0 | } |
597 | 0 | }; |
598 | |
|
599 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
600 | 0 | variablesManager, name, supportsVariableType, [=]() { |
601 | 0 | std::vector<cmDebuggerVariableEntry> ret = { |
602 | 0 | { "AllTargetName", gen->GetAllTargetName() }, |
603 | 0 | { "CleanTargetName", gen->GetCleanTargetName() }, |
604 | 0 | { "EditCacheCommand", gen->GetEditCacheCommand() }, |
605 | 0 | { "EditCacheTargetName", gen->GetEditCacheTargetName() }, |
606 | 0 | { "ExtraGeneratorName", gen->GetExtraGeneratorName() }, |
607 | 0 | { "ForceUnixPaths", gen->GetForceUnixPaths() }, |
608 | 0 | { "InstallLocalTargetName", gen->GetInstallLocalTargetName() }, |
609 | 0 | { "InstallStripTargetName", gen->GetInstallStripTargetName() }, |
610 | 0 | { "InstallTargetName", gen->GetInstallTargetName() }, |
611 | 0 | { "IsMultiConfig", gen->IsMultiConfig() }, |
612 | 0 | { "Name", gen->GetName() }, |
613 | 0 | { "MakefileEncoding", |
614 | 0 | makeFileEncodingString(gen->GetMakefileEncoding()) }, |
615 | 0 | { "PackageSourceTargetName", gen->GetPackageSourceTargetName() }, |
616 | 0 | { "PackageTargetName", gen->GetPackageTargetName() }, |
617 | 0 | { "PreinstallTargetName", gen->GetPreinstallTargetName() }, |
618 | 0 | { "NeedSymbolicMark", gen->GetNeedSymbolicMark() }, |
619 | 0 | { "RebuildCacheTargetName", gen->GetRebuildCacheTargetName() }, |
620 | 0 | { "TestTargetName", gen->GetTestTargetName() }, |
621 | 0 | { "UseLinkScript", gen->GetUseLinkScript() }, |
622 | 0 | }; |
623 | |
|
624 | 0 | return ret; |
625 | 0 | }); |
626 | |
|
627 | 0 | if (auto const* ic = gen->GetInstallComponents()) { |
628 | 0 | variables->AddSubVariables(CreateIfAny( |
629 | 0 | variablesManager, "InstallComponents", supportsVariableType, *ic)); |
630 | 0 | } |
631 | |
|
632 | 0 | variables->SetIgnoreEmptyStringEntries(true); |
633 | 0 | variables->SetValue(gen->GetName()); |
634 | |
|
635 | 0 | return variables; |
636 | 0 | } |
637 | | |
638 | | } // namespace cmDebugger |