LLDB mainline
UserSettingsController.cpp
Go to the documentation of this file.
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
10
12#include "lldb/Utility/Status.h"
13#include "lldb/Utility/Stream.h"
14
15#include <memory>
16
17namespace lldb_private {
19}
20namespace lldb_private {
22}
23namespace lldb_private {
24class Property;
25}
26
27using namespace lldb;
28using namespace lldb_private;
29
30Properties::Properties() = default;
31
33 : m_collection_sp(collection_sp) {}
34
35Properties::~Properties() = default;
36
39 llvm::StringRef path, Status &error) const {
40 return m_collection_sp->GetSubValue(exe_ctx, path, error);
41}
42
45 llvm::StringRef path,
46 llvm::StringRef value) {
47 return m_collection_sp->SetSubValue(exe_ctx, op, path, value);
48}
49
51 Stream &strm, uint32_t dump_mask,
52 bool is_json) {
53 if (is_json) {
54 llvm::json::Value json = m_collection_sp->ToJSON(exe_ctx);
55 strm << llvm::formatv("{0:2}", json);
56 } else
57 m_collection_sp->DumpValue(exe_ctx, strm, dump_mask);
58}
59
61 Stream &strm,
62 bool include_deprecated) const {
63 strm.PutCString("Top level variables:\n\n");
64
65 return m_collection_sp->DumpAllDescriptions(interpreter, strm,
66 include_deprecated);
67}
68
70 Stream &strm,
71 llvm::StringRef property_path,
72 uint32_t dump_mask, bool is_json) {
73 return m_collection_sp->DumpPropertyValue(exe_ctx, strm, property_path,
74 dump_mask, is_json);
75}
76
78 llvm::StringRef keyword, std::vector<const Property *> &matching_properties,
79 std::vector<const Property *> &matching_property_paths) const {
80 m_collection_sp->Apropos(keyword, matching_properties,
81 matching_property_paths);
82}
83
84std::optional<std::string>
85Properties::GetDeprecationWarning(llvm::StringRef property_path) const {
86 // Drop any element access, as in "target.env-vars[FOO]".
87 llvm::StringRef setting_name =
88 property_path.take_front(property_path.find_first_of("[{"));
89 const Property *property =
90 m_collection_sp->GetPropertyAtPath(nullptr, setting_name);
91 if (!property || !property->IsDeprecated())
92 return std::nullopt;
93 std::string warning =
94 llvm::formatv("setting '{0}' is deprecated and may be removed in a "
95 "future release",
96 setting_name)
97 .str();
98 llvm::StringRef message = property->GetDeprecationMessage();
99 if (!message.empty())
100 warning += ("; " + message).str();
101 return warning;
102}
103
105 static constexpr llvm::StringLiteral g_experimental("experimental");
106 return g_experimental;
107}
108
109bool Properties::IsSettingExperimental(llvm::StringRef setting) {
110 if (setting.empty())
111 return false;
112
113 llvm::StringRef experimental = GetExperimentalSettingsName();
114 size_t dot_pos = setting.find_first_of('.');
115 return setting.take_front(dot_pos) == experimental;
116}
static llvm::raw_ostream & error(Stream &strm)
static llvm::raw_ostream & warning(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
std::optional< std::string > GetDeprecationWarning(llvm::StringRef property_path) const
The warning to show when the setting at property_path is changed, or std::nullopt if that setting isn...
virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx, Stream &strm, llvm::StringRef property_path, uint32_t dump_mask, bool is_json=false)
virtual void DumpAllPropertyValues(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask, bool is_json=false)
void Apropos(llvm::StringRef keyword, std::vector< const Property * > &matching_properties, std::vector< const Property * > &matching_property_paths) const
lldb::OptionValuePropertiesSP m_collection_sp
virtual Status SetPropertyValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef property_path, llvm::StringRef value)
virtual lldb::OptionValueSP GetPropertyValue(const ExecutionContext *exe_ctx, llvm::StringRef property_path, Status &error) const
static bool IsSettingExperimental(llvm::StringRef setting)
static llvm::StringRef GetExperimentalSettingsName()
virtual void DumpAllDescriptions(CommandInterpreter &interpreter, Stream &strm, bool include_deprecated) const
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
std::shared_ptr< lldb_private::OptionValueProperties > OptionValuePropertiesSP
std::shared_ptr< lldb_private::OptionValue > OptionValueSP