16#include "llvm/ADT/StringRef.h"
36 collection::iterator pos, end =
m_values.end();
41 for (pos =
m_values.begin(); pos != end; ++pos) {
49 strm.
Indent(pos->first.GetStringRef());
60 option_value->
DumpValue(exe_ctx, strm, dump_mask | extra_dump_options);
88 llvm::json::Object dict;
90 dict.try_emplace(value.first.GetCString(), value.second->ToJSON(exe_ctx));
97 collection::const_iterator pos, end =
m_values.end();
98 for (pos =
m_values.begin(); pos != end; ++pos) {
100 strm.
Printf(
"%s=", pos->first.GetCString());
120 error.SetErrorString(
121 "assign operation takes one or more key=value arguments");
124 for (
const auto &entry : args) {
125 if (entry.ref().empty()) {
126 error.SetErrorString(
"empty argument");
129 if (!entry.ref().contains(
'=')) {
130 error.SetErrorString(
131 "assign operation takes one or more key=value arguments");
135 llvm::StringRef key, value;
136 std::tie(key, value) = entry.ref().split(
'=');
137 bool key_valid =
false;
139 error.SetErrorString(
"empty dictionary key");
143 if (key.front() ==
'[') {
146 if ((key.size() > 2) && (key.back() ==
']')) {
148 key = key.substr(1, key.size() - 2);
149 const char quote_char = key.front();
150 if ((quote_char ==
'\'') || (quote_char ==
'"')) {
151 if ((key.size() > 2) && (key.back() == quote_char)) {
153 key = key.substr(1, key.size() - 2);
166 error.SetErrorStringWithFormat(
167 "invalid key \"%s\", the key must be a bare string or "
168 "surrounded by brackets with optional quotes: [<key>] or "
169 "['<key>'] or [\"<key>\"]",
177 error = enum_value->SetValueFromString(value);
191 error.SetErrorString(
"dictionaries that can contain multiple types "
192 "must subclass OptionValueArray");
200 for (
size_t i = 0; i < argc; ++i) {
203 error.SetErrorStringWithFormat(
204 "no value found named '%s', aborting remove operation",
210 error.SetErrorString(
"remove operation takes one or more key arguments");
225 Args args(value.str());
234 llvm::StringRef name,
bool will_modify,
236 lldb::OptionValueSP value_sp;
240 llvm::StringRef left, temp;
241 std::tie(left, temp) = name.split(
'[');
242 if (left.size() == name.size()) {
243 error.SetErrorStringWithFormat(
"invalid value path '%s', %s values only "
244 "support '[<key>]' subvalues where <key> "
245 "a string value optionally delimited by "
246 "single or double quotes",
250 assert(!temp.empty());
252 llvm::StringRef key, quote_char;
254 if (temp[0] ==
'\"' || temp[0] ==
'\'') {
255 quote_char = temp.take_front();
256 temp = temp.drop_front();
259 llvm::StringRef sub_name;
260 std::tie(key, sub_name) = temp.split(
']');
262 if (!key.consume_back(quote_char) || key.empty()) {
263 error.SetErrorStringWithFormat(
"invalid value path '%s', "
264 "key names must be formatted as ['<key>'] where <key> "
265 "is a string that doesn't contain quotes and the quote"
266 " char is optional", name.str().c_str());
272 error.SetErrorStringWithFormat(
273 "dictionary does not contain a value for the key name '%s'",
278 if (sub_name.empty())
280 return value_sp->GetSubValue(exe_ctx, sub_name, will_modify,
error);
285 llvm::StringRef name,
286 llvm::StringRef value) {
288 const bool will_modify =
true;
289 lldb::OptionValueSP value_sp(
GetSubValue(exe_ctx, name, will_modify,
error));
291 error = value_sp->SetValueFromString(value, op);
293 if (
error.AsCString() ==
nullptr)
294 error.SetErrorStringWithFormat(
"invalid value path '%s'", name.str().c_str());
301 lldb::OptionValueSP value_sp;
302 collection::const_iterator pos =
m_values.find(key);
304 value_sp = pos->second;
309 const lldb::OptionValueSP &value_sp,
313 if (value_sp && (
m_type_mask & value_sp->GetTypeAsMask())) {
315 collection::const_iterator pos =
m_values.find(key);
326 collection::iterator pos =
m_values.find(key);
342 for (
auto &value : dict_value_ptr->m_values)
343 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.
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
"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
bool SetValueForKey(ConstString key, const lldb::OptionValueSP &value_sp, bool can_replace=true)
bool DeleteValueForKey(ConstString key)
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 GetSubValue(const ExecutionContext *exe_ctx, llvm::StringRef name, bool will_modify, Status &error) const override
lldb::OptionValueSP GetValueForKey(ConstString key) const
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