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
17namespace lldb_private {
18class CommandInterpreter;
19}
20namespace lldb_private {
21class ConstString;
22}
23namespace lldb_private {
24class ExecutionContext;
25}
26namespace lldb_private {
27class Property;
28}
29
30using namespace lldb;
31using namespace lldb_private;
32
33Properties::Properties() = default;
34
35Properties::Properties(const lldb::OptionValuePropertiesSP &collection_sp)
36 : m_collection_sp(collection_sp) {}
37
38Properties::~Properties() = default;
39
40lldb::OptionValueSP
41Properties::GetPropertyValue(const ExecutionContext *exe_ctx,
42 llvm::StringRef path, Status &error) const {
43 OptionValuePropertiesSP properties_sp(GetValueProperties());
44 if (properties_sp)
45 return properties_sp->GetSubValue(exe_ctx, name: path, error);
46 return lldb::OptionValueSP();
47}
48
49Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
50 VarSetOperationType op,
51 llvm::StringRef path,
52 llvm::StringRef value) {
53 OptionValuePropertiesSP properties_sp(GetValueProperties());
54 if (properties_sp)
55 return properties_sp->SetSubValue(exe_ctx, op, path, value);
56 Status error;
57 error.SetErrorString("no properties");
58 return error;
59}
60
61void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
62 Stream &strm, uint32_t dump_mask,
63 bool is_json) {
64 OptionValuePropertiesSP properties_sp(GetValueProperties());
65 if (!properties_sp)
66 return;
67
68 if (is_json) {
69 llvm::json::Value json = properties_sp->ToJSON(exe_ctx);
70 strm.Printf(format: "%s", llvm::formatv(Fmt: "{0:2}", Vals&: json).str().c_str());
71 } else
72 properties_sp->DumpValue(exe_ctx, strm, dump_mask);
73}
74
75void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
76 Stream &strm) const {
77 strm.PutCString(cstr: "Top level variables:\n\n");
78
79 OptionValuePropertiesSP properties_sp(GetValueProperties());
80 if (properties_sp)
81 return properties_sp->DumpAllDescriptions(interpreter, strm);
82}
83
84Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
85 Stream &strm,
86 llvm::StringRef property_path,
87 uint32_t dump_mask, bool is_json) {
88 OptionValuePropertiesSP properties_sp(GetValueProperties());
89 if (properties_sp) {
90 return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
91 dump_mask, is_json);
92 }
93 Status error;
94 error.SetErrorString("empty property list");
95 return error;
96}
97
98size_t
99Properties::Apropos(llvm::StringRef keyword,
100 std::vector<const Property *> &matching_properties) const {
101 OptionValuePropertiesSP properties_sp(GetValueProperties());
102 if (properties_sp) {
103 properties_sp->Apropos(keyword, matching_properties);
104 }
105 return matching_properties.size();
106}
107
108llvm::StringRef Properties::GetExperimentalSettingsName() {
109 static constexpr llvm::StringLiteral g_experimental("experimental");
110 return g_experimental;
111}
112
113bool Properties::IsSettingExperimental(llvm::StringRef setting) {
114 if (setting.empty())
115 return false;
116
117 llvm::StringRef experimental = GetExperimentalSettingsName();
118 size_t dot_pos = setting.find_first_of(C: '.');
119 return setting.take_front(N: dot_pos) == experimental;
120}
121

source code of lldb/source/Core/UserSettingsController.cpp