1 //===-- UserSettingsController.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 "lldb/Core/UserSettingsController.h"
10
11 #include "lldb/Interpreter/OptionValueProperties.h"
12 #include "lldb/Utility/Status.h"
13 #include "lldb/Utility/Stream.h"
14
15 #include <memory>
16
17 namespace lldb_private {
18 class CommandInterpreter;
19 }
20 namespace lldb_private {
21 class ConstString;
22 }
23 namespace lldb_private {
24 class ExecutionContext;
25 }
26 namespace lldb_private {
27 class Property;
28 }
29
30 using namespace lldb;
31 using namespace lldb_private;
32
33 Properties::Properties() = default;
34
Properties(const lldb::OptionValuePropertiesSP & collection_sp)35 Properties::Properties(const lldb::OptionValuePropertiesSP &collection_sp)
36 : m_collection_sp(collection_sp) {}
37
38 Properties::~Properties() = default;
39
40 lldb::OptionValueSP
GetPropertyValue(const ExecutionContext * exe_ctx,llvm::StringRef path,Status & error) const41 Properties::GetPropertyValue(const ExecutionContext *exe_ctx,
42 llvm::StringRef path, Status &error) const {
43 return m_collection_sp->GetSubValue(exe_ctx, path, error);
44 }
45
SetPropertyValue(const ExecutionContext * exe_ctx,VarSetOperationType op,llvm::StringRef path,llvm::StringRef value)46 Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
47 VarSetOperationType op,
48 llvm::StringRef path,
49 llvm::StringRef value) {
50 return m_collection_sp->SetSubValue(exe_ctx, op, path, value);
51 }
52
DumpAllPropertyValues(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask,bool is_json)53 void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
54 Stream &strm, uint32_t dump_mask,
55 bool is_json) {
56 if (is_json) {
57 llvm::json::Value json = m_collection_sp->ToJSON(exe_ctx);
58 strm.Printf("%s", llvm::formatv("{0:2}", json).str().c_str());
59 } else
60 m_collection_sp->DumpValue(exe_ctx, strm, dump_mask);
61 }
62
DumpAllDescriptions(CommandInterpreter & interpreter,Stream & strm) const63 void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
64 Stream &strm) const {
65 strm.PutCString("Top level variables:\n\n");
66
67 return m_collection_sp->DumpAllDescriptions(interpreter, strm);
68 }
69
DumpPropertyValue(const ExecutionContext * exe_ctx,Stream & strm,llvm::StringRef property_path,uint32_t dump_mask,bool is_json)70 Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
71 Stream &strm,
72 llvm::StringRef property_path,
73 uint32_t dump_mask, bool is_json) {
74 return m_collection_sp->DumpPropertyValue(exe_ctx, strm, property_path,
75 dump_mask, is_json);
76 }
77
78 size_t
Apropos(llvm::StringRef keyword,std::vector<const Property * > & matching_properties) const79 Properties::Apropos(llvm::StringRef keyword,
80 std::vector<const Property *> &matching_properties) const {
81 m_collection_sp->Apropos(keyword, matching_properties);
82 return matching_properties.size();
83 }
84
GetExperimentalSettingsName()85 llvm::StringRef Properties::GetExperimentalSettingsName() {
86 static constexpr llvm::StringLiteral g_experimental("experimental");
87 return g_experimental;
88 }
89
IsSettingExperimental(llvm::StringRef setting)90 bool Properties::IsSettingExperimental(llvm::StringRef setting) {
91 if (setting.empty())
92 return false;
93
94 llvm::StringRef experimental = GetExperimentalSettingsName();
95 size_t dot_pos = setting.find_first_of('.');
96 return setting.take_front(dot_pos) == experimental;
97 }
98