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 {
21class ConstString;
22}
23namespace lldb_private {
25}
26namespace lldb_private {
27class Property;
28}
29
30using namespace lldb;
31using namespace lldb_private;
32
33Properties::Properties() = default;
34
36 : m_collection_sp(collection_sp) {}
37
38Properties::~Properties() = default;
39
42 llvm::StringRef path, Status &error) const {
44 if (properties_sp)
45 return properties_sp->GetSubValue(exe_ctx, path, error);
46 return lldb::OptionValueSP();
47}
48
51 llvm::StringRef path,
52 llvm::StringRef value) {
54 if (properties_sp)
55 return properties_sp->SetSubValue(exe_ctx, op, path, value);
56 return Status::FromErrorString("no properties");
57}
58
60 Stream &strm, uint32_t dump_mask,
61 bool is_json) {
63 if (!properties_sp)
64 return;
65
66 if (is_json) {
67 llvm::json::Value json = properties_sp->ToJSON(exe_ctx);
68 strm.Printf("%s", llvm::formatv("{0:2}", json).str().c_str());
69 } else
70 properties_sp->DumpValue(exe_ctx, strm, dump_mask);
71}
72
74 Stream &strm) const {
75 strm.PutCString("Top level variables:\n\n");
76
78 if (properties_sp)
79 return properties_sp->DumpAllDescriptions(interpreter, strm);
80}
81
83 Stream &strm,
84 llvm::StringRef property_path,
85 uint32_t dump_mask, bool is_json) {
87 if (properties_sp) {
88 return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
89 dump_mask, is_json);
90 }
91 return Status::FromErrorString("empty property list");
92}
93
94size_t
95Properties::Apropos(llvm::StringRef keyword,
96 std::vector<const Property *> &matching_properties) const {
98 if (properties_sp) {
99 properties_sp->Apropos(keyword, matching_properties);
100 }
101 return matching_properties.size();
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)
A uniqued constant string class.
Definition: ConstString.h:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
virtual void DumpAllDescriptions(CommandInterpreter &interpreter, Stream &strm) const
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)
size_t Apropos(llvm::StringRef keyword, std::vector< const Property * > &matching_properties) const
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 lldb::OptionValuePropertiesSP GetValueProperties() const
An error handling class.
Definition: Status.h:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::OptionValueProperties > OptionValuePropertiesSP
Definition: lldb-forward.h:387
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
Definition: lldb-forward.h:384