LLDB mainline
UserSettingsController.h
Go to the documentation of this file.
1//====-- UserSettingsController.h --------------------------------*- C++-*-===//
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#ifndef LLDB_CORE_USERSETTINGSCONTROLLER_H
10#define LLDB_CORE_USERSETTINGSCONTROLLER_H
11
13#include "lldb/Utility/Status.h"
14#include "lldb/lldb-forward.h"
16
17#include "llvm/ADT/StringRef.h"
18
19#include <vector>
20
21#include <cstddef>
22#include <cstdint>
23
24namespace lldb_private {
25class CommandInterpreter;
26class ExecutionContext;
27class Property;
28class Stream;
29}
30
31namespace lldb_private {
32
34public:
36
37 Properties(const lldb::OptionValuePropertiesSP &collection_sp);
38
39 virtual ~Properties();
40
42 // This function is virtual in case subclasses want to lazily implement
43 // creating the properties.
44 return m_collection_sp;
45 }
46
48 llvm::StringRef property_path,
49 Status &error) const;
50
51 virtual Status SetPropertyValue(const ExecutionContext *exe_ctx,
53 llvm::StringRef property_path,
54 llvm::StringRef value);
55
56 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
57 Stream &strm, llvm::StringRef property_path,
58 uint32_t dump_mask, bool is_json = false);
59
60 virtual void DumpAllPropertyValues(const ExecutionContext *exe_ctx,
61 Stream &strm, uint32_t dump_mask,
62 bool is_json = false);
63
64 virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
65 Stream &strm) const;
66
67 size_t Apropos(llvm::StringRef keyword,
68 std::vector<const Property *> &matching_properties) const;
69
70 // We sometimes need to introduce a setting to enable experimental features,
71 // but then we don't want the setting for these to cause errors when the
72 // setting goes away. Add a sub-topic of the settings using this
73 // experimental name, and two things will happen. One is that settings that
74 // don't find the name will not be treated as errors. Also, if you decide to
75 // keep the settings just move them into the containing properties, and we
76 // will auto-forward the experimental settings to the real one.
77 static llvm::StringRef GetExperimentalSettingsName();
78
79 static bool IsSettingExperimental(llvm::StringRef setting);
80
81 template <typename T>
82 T GetPropertyAtIndexAs(uint32_t idx, T default_value,
83 const ExecutionContext *exe_ctx = nullptr) const {
84 return m_collection_sp->GetPropertyAtIndexAs<T>(idx, exe_ctx)
85 .value_or(default_value);
86 }
87
88 template <typename T, typename U = typename std::remove_pointer<T>::type,
89 std::enable_if_t<std::is_pointer_v<T>, bool> = true>
90 const U *
92 const ExecutionContext *exe_ctx = nullptr) const {
93 return m_collection_sp->GetPropertyAtIndexAs<T>(idx, exe_ctx);
94 }
95
96 template <typename T>
97 bool SetPropertyAtIndex(uint32_t idx, T t,
98 const ExecutionContext *exe_ctx = nullptr) const {
99 return m_collection_sp->SetPropertyAtIndex<T>(idx, t, exe_ctx);
100 }
101
102protected:
104};
105
106} // namespace lldb_private
107
108#endif // LLDB_CORE_USERSETTINGSCONTROLLER_H
static llvm::raw_ostream & error(Stream &strm)
"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
const U * GetPropertyAtIndexAs(uint32_t idx, const ExecutionContext *exe_ctx=nullptr) 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
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
static bool IsSettingExperimental(llvm::StringRef setting)
static llvm::StringRef GetExperimentalSettingsName()
bool SetPropertyAtIndex(uint32_t idx, T t, const ExecutionContext *exe_ctx=nullptr) const
virtual lldb::OptionValuePropertiesSP GetValueProperties() const
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
std::shared_ptr< lldb_private::OptionValueProperties > OptionValuePropertiesSP
Definition: lldb-forward.h:385
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
Definition: lldb-forward.h:382