cmDebuggerVariablesHelper.cxx 23 KB

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