Path: blob/main/contrib/llvm-project/lldb/source/Core/UserSettingsController.cpp
39587 views
//===-- UserSettingsController.cpp ----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Core/UserSettingsController.h"910#include "lldb/Interpreter/OptionValueProperties.h"11#include "lldb/Utility/Status.h"12#include "lldb/Utility/Stream.h"1314#include <memory>1516namespace lldb_private {17class CommandInterpreter;18}19namespace lldb_private {20class ConstString;21}22namespace lldb_private {23class ExecutionContext;24}25namespace lldb_private {26class Property;27}2829using namespace lldb;30using namespace lldb_private;3132Properties::Properties() = default;3334Properties::Properties(const lldb::OptionValuePropertiesSP &collection_sp)35: m_collection_sp(collection_sp) {}3637Properties::~Properties() = default;3839lldb::OptionValueSP40Properties::GetPropertyValue(const ExecutionContext *exe_ctx,41llvm::StringRef path, Status &error) const {42OptionValuePropertiesSP properties_sp(GetValueProperties());43if (properties_sp)44return properties_sp->GetSubValue(exe_ctx, path, error);45return lldb::OptionValueSP();46}4748Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,49VarSetOperationType op,50llvm::StringRef path,51llvm::StringRef value) {52OptionValuePropertiesSP properties_sp(GetValueProperties());53if (properties_sp)54return properties_sp->SetSubValue(exe_ctx, op, path, value);55Status error;56error.SetErrorString("no properties");57return error;58}5960void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,61Stream &strm, uint32_t dump_mask,62bool is_json) {63OptionValuePropertiesSP properties_sp(GetValueProperties());64if (!properties_sp)65return;6667if (is_json) {68llvm::json::Value json = properties_sp->ToJSON(exe_ctx);69strm.Printf("%s", llvm::formatv("{0:2}", json).str().c_str());70} else71properties_sp->DumpValue(exe_ctx, strm, dump_mask);72}7374void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,75Stream &strm) const {76strm.PutCString("Top level variables:\n\n");7778OptionValuePropertiesSP properties_sp(GetValueProperties());79if (properties_sp)80return properties_sp->DumpAllDescriptions(interpreter, strm);81}8283Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,84Stream &strm,85llvm::StringRef property_path,86uint32_t dump_mask, bool is_json) {87OptionValuePropertiesSP properties_sp(GetValueProperties());88if (properties_sp) {89return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,90dump_mask, is_json);91}92Status error;93error.SetErrorString("empty property list");94return error;95}9697size_t98Properties::Apropos(llvm::StringRef keyword,99std::vector<const Property *> &matching_properties) const {100OptionValuePropertiesSP properties_sp(GetValueProperties());101if (properties_sp) {102properties_sp->Apropos(keyword, matching_properties);103}104return matching_properties.size();105}106107llvm::StringRef Properties::GetExperimentalSettingsName() {108static constexpr llvm::StringLiteral g_experimental("experimental");109return g_experimental;110}111112bool Properties::IsSettingExperimental(llvm::StringRef setting) {113if (setting.empty())114return false;115116llvm::StringRef experimental = GetExperimentalSettingsName();117size_t dot_pos = setting.find_first_of('.');118return setting.take_front(dot_pos) == experimental;119}120121122