16#include "llvm/ADT/StringRef.h"
22 Stream &strm, uint32_t dump_mask) {
41 std::map<llvm::StringRef, OptionValue *> sorted_values;
43 sorted_values[value.first()] = value.second.get();
45 for (
const auto &value : sorted_values) {
64 option_value->
DumpValue(exe_ctx, strm, dump_mask | extra_dump_options);
92 llvm::json::Object dict;
94 dict.try_emplace(value.first(), value.second->ToJSON(exe_ctx));
101 for (
const auto &value :
m_values) {
103 strm.
Printf(
"%s=", value.first().data());
123 error.SetErrorString(
124 "assign operation takes one or more key=value arguments");
127 for (
const auto &entry : args) {
128 if (entry.ref().empty()) {
129 error.SetErrorString(
"empty argument");
132 if (!entry.ref().contains(
'=')) {
133 error.SetErrorString(
134 "assign operation takes one or more key=value arguments");
138 llvm::StringRef key, value;
139 std::tie(key, value) = entry.ref().split(
'=');
140 bool key_valid =
false;
142 error.SetErrorString(
"empty dictionary key");
146 if (key.front() ==
'[') {
149 if ((key.size() > 2) && (key.back() ==
']')) {
151 key = key.substr(1, key.size() - 2);
152 const char quote_char = key.front();
153 if ((quote_char ==
'\'') || (quote_char ==
'"')) {
154 if ((key.size() > 2) && (key.back() == quote_char)) {
156 key = key.substr(1, key.size() - 2);
169 error.SetErrorStringWithFormat(
170 "invalid key \"%s\", the key must be a bare string or "
171 "surrounded by brackets with optional quotes: [<key>] or "
172 "['<key>'] or [\"<key>\"]",
180 error = enum_value->SetValueFromString(value);
194 error.SetErrorString(
"dictionaries that can contain multiple types "
195 "must subclass OptionValueArray");
203 for (
size_t i = 0; i < argc; ++i) {
204 llvm::StringRef key(args.GetArgumentAtIndex(i));
206 error.SetErrorStringWithFormat(
207 "no value found named '%s', aborting remove operation",
213 error.SetErrorString(
"remove operation takes one or more key arguments");
228 Args args(value.str());
242 llvm::StringRef left, temp;
243 std::tie(left, temp) = name.split(
'[');
244 if (left.size() == name.size()) {
245 error.SetErrorStringWithFormat(
"invalid value path '%s', %s values only "
246 "support '[<key>]' subvalues where <key> "
247 "a string value optionally delimited by "
248 "single or double quotes",
252 assert(!temp.empty());
254 llvm::StringRef key, quote_char;
256 if (temp[0] ==
'\"' || temp[0] ==
'\'') {
257 quote_char = temp.take_front();
258 temp = temp.drop_front();
261 llvm::StringRef sub_name;
262 std::tie(key, sub_name) = temp.split(
']');
264 if (!key.consume_back(quote_char) || key.empty()) {
265 error.SetErrorStringWithFormat(
"invalid value path '%s', "
266 "key names must be formatted as ['<key>'] where <key> "
267 "is a string that doesn't contain quotes and the quote"
268 " char is optional", name.str().c_str());
274 error.SetErrorStringWithFormat(
275 "dictionary does not contain a value for the key name '%s'",
280 if (sub_name.empty())
282 return value_sp->GetSubValue(exe_ctx, sub_name,
error);
287 llvm::StringRef name,
288 llvm::StringRef value) {
292 error = value_sp->SetValueFromString(value, op);
294 if (
error.AsCString() ==
nullptr)
295 error.SetErrorStringWithFormat(
"invalid value path '%s'", name.str().c_str());
305 value_sp = pos->second;
314 if (value_sp && (
m_type_mask & value_sp->GetTypeAsMask())) {
343 for (
auto &value : dict_value_ptr->m_values)
344 value.second = value.second->DeepCopy(copy_sp);
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
void Clear()
Clear the arguments.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
size_t GetArgs(Args &args) const
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
llvm::StringMap< lldb::OptionValueSP > m_values
lldb::OptionValueSP DeepCopy(const lldb::OptionValueSP &new_parent) const override
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef name, llvm::StringRef value) override
OptionEnumValues m_enum_values
Status SetArgs(const Args &args, VarSetOperationType op)
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override
lldb::OptionValueSP GetValueForKey(llvm::StringRef key) const
bool DeleteValueForKey(llvm::StringRef key)
lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx, llvm::StringRef name, Status &error) const override
bool SetValueForKey(llvm::StringRef key, const lldb::OptionValueSP &value_sp, bool can_replace=true)
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
static lldb::OptionValueSP CreateValueFromCStringForTypeMask(const char *value_cstr, uint32_t type_mask, Status &error)
virtual void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)=0
static OptionValue::Type ConvertTypeMaskToType(uint32_t type_mask)
virtual lldb::OptionValueSP DeepCopy(const lldb::OptionValueSP &new_parent) const
static const char * GetBuiltinTypeAsCString(Type t)
void NotifyValueChanged()
virtual const char * GetTypeAsCString() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
@ eVarSetOperationReplace
@ eVarSetOperationInvalid
@ eVarSetOperationInsertBefore
@ eVarSetOperationInsertAfter
std::shared_ptr< lldb_private::OptionValue > OptionValueSP