blob: 54efead2070a9d1c4807a19fb62999ac5ac85625 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- CommandObjectSettings.cpp -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectSettings.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
Eugene Zelenko3f18ea02016-02-24 02:05:55 +000015#include "llvm/ADT/StringRef.h"
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// Project includes
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include "lldb/Interpreter/CommandCompletions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Interpreter/CommandInterpreter.h"
20#include "lldb/Interpreter/CommandReturnObject.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000021#include "lldb/Interpreter/OptionValueProperties.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022
23using namespace lldb;
24using namespace lldb_private;
Jim Ingham5a988412012-06-08 21:56:10 +000025
Jim Ingham5a988412012-06-08 21:56:10 +000026//-------------------------------------------------------------------------
27// CommandObjectSettingsSet
28//-------------------------------------------------------------------------
29
Zachary Turner1f0f5b52016-09-22 20:22:55 +000030static OptionDefinition g_settings_set_options[] = {
31 // clang-format off
32 { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Apply the new value to the global default value." }
33 // clang-format on
34};
35
Kate Stoneb9c1b512016-09-06 20:57:50 +000036class CommandObjectSettingsSet : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +000037public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 CommandObjectSettingsSet(CommandInterpreter &interpreter)
39 : CommandObjectRaw(interpreter, "settings set",
Zachary Turnera4496982016-10-05 21:14:38 +000040 "Set the value of the specified debugger setting."),
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 m_options() {
42 CommandArgumentEntry arg1;
43 CommandArgumentEntry arg2;
44 CommandArgumentData var_name_arg;
45 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 // Define the first (and only) variant of this arg.
48 var_name_arg.arg_type = eArgTypeSettingVariableName;
49 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 // There is only one variant this argument could be; put it into the
52 // argument entry.
53 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 // Define the first (and only) variant of this arg.
56 value_arg.arg_type = eArgTypeValue;
57 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 // There is only one variant this argument could be; put it into the
60 // argument entry.
61 arg2.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 // Push the data for the first argument into the m_arguments vector.
64 m_arguments.push_back(arg1);
65 m_arguments.push_back(arg2);
66
67 SetHelpLong(
68 "\nWhen setting a dictionary or array variable, you can set multiple entries \
69at once by giving the values to the set command. For example:"
70 R"(
Kate Stoneea671fb2015-07-14 05:48:36 +000071
72(lldb) settings set target.run-args value1 value2 value3
73(lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345
74
75(lldb) settings show target.run-args
76 [0]: 'value1'
77 [1]: 'value2'
78 [3]: 'value3'
79(lldb) settings show target.env-vars
80 'MYPATH=~/.:/usr/bin'
81 'SOME_ENV_VAR=12345'
82
Kate Stoneb9c1b512016-09-06 20:57:50 +000083)"
84 "Warning: The 'set' command re-sets the entire array or dictionary. If you \
Kate Stoneea671fb2015-07-14 05:48:36 +000085just want to add, remove or update individual values (or add something to \
86the end), use one of the other settings sub-commands: append, replace, \
Kate Stoneb9c1b512016-09-06 20:57:50 +000087insert-before or insert-after.");
88 }
Jim Ingham5a988412012-06-08 21:56:10 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 ~CommandObjectSettingsSet() override = default;
91
92 // Overrides base class's behavior where WantsCompletion =
93 // !WantsRawCommandString.
94 bool WantsCompletion() override { return true; }
95
96 Options *GetOptions() override { return &m_options; }
97
98 class CommandOptions : public Options {
99 public:
100 CommandOptions() : Options(), m_global(false) {}
101
102 ~CommandOptions() override = default;
103
Zachary Turnerfe114832016-11-12 16:56:47 +0000104 Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105 ExecutionContext *execution_context) override {
106 Error error;
107 const int short_option = m_getopt_table[option_idx].val;
108
109 switch (short_option) {
110 case 'g':
111 m_global = true;
112 break;
113 default:
114 error.SetErrorStringWithFormat("unrecognized options '%c'",
115 short_option);
116 break;
117 }
118
119 return error;
Jim Ingham5a988412012-06-08 21:56:10 +0000120 }
121
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 void OptionParsingStarting(ExecutionContext *execution_context) override {
123 m_global = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000124 }
Jim Ingham5a988412012-06-08 21:56:10 +0000125
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000126 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
Zachary Turner70602432016-09-22 21:06:13 +0000127 return llvm::makeArrayRef(g_settings_set_options);
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000128 }
Jim Ingham5a988412012-06-08 21:56:10 +0000129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 // Instance variables to hold the values for command options.
Jim Ingham5a988412012-06-08 21:56:10 +0000131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 bool m_global;
133 };
Jim Ingham5a988412012-06-08 21:56:10 +0000134
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135 int HandleArgumentCompletion(Args &input, int &cursor_index,
136 int &cursor_char_position,
137 OptionElementVector &opt_element_vector,
138 int match_start_point, int max_return_elements,
139 bool &word_complete,
140 StringList &matches) override {
141 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
142 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 const size_t argc = input.GetArgumentCount();
145 const char *arg = nullptr;
146 int setting_var_idx;
147 for (setting_var_idx = 1; setting_var_idx < static_cast<int>(argc);
148 ++setting_var_idx) {
149 arg = input.GetArgumentAtIndex(setting_var_idx);
150 if (arg && arg[0] != '-')
151 break; // We found our setting variable name index
Jim Ingham5a988412012-06-08 21:56:10 +0000152 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 if (cursor_index == setting_var_idx) {
154 // Attempting to complete setting variable name
155 CommandCompletions::InvokeCommonCompletionCallbacks(
156 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
157 completion_str.c_str(), match_start_point, max_return_elements,
158 nullptr, word_complete, matches);
159 } else {
160 arg = input.GetArgumentAtIndex(cursor_index);
161
162 if (arg) {
163 if (arg[0] == '-') {
164 // Complete option name
165 } else {
166 // Complete setting value
167 const char *setting_var_name =
168 input.GetArgumentAtIndex(setting_var_idx);
169 Error error;
170 lldb::OptionValueSP value_sp(
171 m_interpreter.GetDebugger().GetPropertyValue(
172 &m_exe_ctx, setting_var_name, false, error));
173 if (value_sp) {
174 value_sp->AutoComplete(m_interpreter, completion_str.c_str(),
175 match_start_point, max_return_elements,
176 word_complete, matches);
177 }
178 }
179 }
180 }
181 return matches.GetSize();
182 }
183
Jim Ingham5a988412012-06-08 21:56:10 +0000184protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000185 bool DoExecute(const char *command, CommandReturnObject &result) override {
186 Args cmd_args(command);
Jim Ingham5a988412012-06-08 21:56:10 +0000187
Kate Stoneb9c1b512016-09-06 20:57:50 +0000188 // Process possible options.
189 if (!ParseOptions(cmd_args, result))
190 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000191
Kate Stoneb9c1b512016-09-06 20:57:50 +0000192 const size_t argc = cmd_args.GetArgumentCount();
193 if ((argc < 2) && (!m_options.m_global)) {
194 result.AppendError("'settings set' takes more arguments");
195 result.SetStatus(eReturnStatusFailed);
196 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000197 }
Eugene Zelenko3f18ea02016-02-24 02:05:55 +0000198
Kate Stoneb9c1b512016-09-06 20:57:50 +0000199 const char *var_name = cmd_args.GetArgumentAtIndex(0);
200 if ((var_name == nullptr) || (var_name[0] == '\0')) {
201 result.AppendError(
202 "'settings set' command requires a valid variable name");
203 result.SetStatus(eReturnStatusFailed);
204 return false;
205 }
206
207 // Split the raw command into var_name and value pair.
208 llvm::StringRef raw_str(command);
209 std::string var_value_string = raw_str.split(var_name).second.str();
210 const char *var_value_cstr =
211 Args::StripSpaces(var_value_string, true, false, false);
212
213 Error error;
214 if (m_options.m_global) {
215 error = m_interpreter.GetDebugger().SetPropertyValue(
216 nullptr, eVarSetOperationAssign, var_name, var_value_cstr);
217 }
218
219 if (error.Success()) {
220 // FIXME this is the same issue as the one in commands script import
221 // we could be setting target.load-script-from-symbol-file which would
222 // cause
223 // Python scripts to be loaded, which could run LLDB commands
224 // (e.g. settings set target.process.python-os-plugin-path) and cause a
225 // crash
226 // if we did not clear the command's exe_ctx first
227 ExecutionContext exe_ctx(m_exe_ctx);
228 m_exe_ctx.Clear();
229 error = m_interpreter.GetDebugger().SetPropertyValue(
230 &exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr);
231 }
232
233 if (error.Fail()) {
234 result.AppendError(error.AsCString());
235 result.SetStatus(eReturnStatusFailed);
236 return false;
237 } else {
238 result.SetStatus(eReturnStatusSuccessFinishResult);
239 }
240
241 return result.Succeeded();
242 }
243
Jim Ingham5a988412012-06-08 21:56:10 +0000244private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +0000246};
247
Jim Ingham5a988412012-06-08 21:56:10 +0000248//-------------------------------------------------------------------------
249// CommandObjectSettingsShow -- Show current values
250//-------------------------------------------------------------------------
251
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252class CommandObjectSettingsShow : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000253public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254 CommandObjectSettingsShow(CommandInterpreter &interpreter)
255 : CommandObjectParsed(interpreter, "settings show",
256 "Show matching debugger settings and their current "
257 "values. Defaults to showing all settings.",
258 nullptr) {
259 CommandArgumentEntry arg1;
260 CommandArgumentData var_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000261
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262 // Define the first (and only) variant of this arg.
263 var_name_arg.arg_type = eArgTypeSettingVariableName;
264 var_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000265
Kate Stoneb9c1b512016-09-06 20:57:50 +0000266 // There is only one variant this argument could be; put it into the
267 // argument entry.
268 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000269
Kate Stoneb9c1b512016-09-06 20:57:50 +0000270 // Push the data for the first argument into the m_arguments vector.
271 m_arguments.push_back(arg1);
272 }
Jim Ingham5a988412012-06-08 21:56:10 +0000273
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274 ~CommandObjectSettingsShow() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000275
Kate Stoneb9c1b512016-09-06 20:57:50 +0000276 int HandleArgumentCompletion(Args &input, int &cursor_index,
277 int &cursor_char_position,
278 OptionElementVector &opt_element_vector,
279 int match_start_point, int max_return_elements,
280 bool &word_complete,
281 StringList &matches) override {
282 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
283 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000284
Kate Stoneb9c1b512016-09-06 20:57:50 +0000285 CommandCompletions::InvokeCommonCompletionCallbacks(
286 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
287 completion_str.c_str(), match_start_point, max_return_elements, nullptr,
288 word_complete, matches);
289 return matches.GetSize();
290 }
Jim Ingham5a988412012-06-08 21:56:10 +0000291
292protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000293 bool DoExecute(Args &args, CommandReturnObject &result) override {
294 result.SetStatus(eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000295
Kate Stoneb9c1b512016-09-06 20:57:50 +0000296 const size_t argc = args.GetArgumentCount();
Zachary Turner97d2c402016-10-05 23:40:23 +0000297 if (!args.empty()) {
298 // TODO: Convert this to StringRef based enumeration. Requires converting
299 // DumpPropertyValue first.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300 for (size_t i = 0; i < argc; ++i) {
301 const char *property_path = args.GetArgumentAtIndex(i);
Greg Clayton67cc0632012-08-22 17:17:09 +0000302
Kate Stoneb9c1b512016-09-06 20:57:50 +0000303 Error error(m_interpreter.GetDebugger().DumpPropertyValue(
304 &m_exe_ctx, result.GetOutputStream(), property_path,
305 OptionValue::eDumpGroupValue));
306 if (error.Success()) {
307 result.GetOutputStream().EOL();
308 } else {
309 result.AppendError(error.AsCString());
310 result.SetStatus(eReturnStatusFailed);
Jim Ingham5a988412012-06-08 21:56:10 +0000311 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312 }
313 } else {
314 m_interpreter.GetDebugger().DumpAllPropertyValues(
315 &m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
Jim Ingham5a988412012-06-08 21:56:10 +0000316 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000317
318 return result.Succeeded();
319 }
Jim Ingham5a988412012-06-08 21:56:10 +0000320};
321
322//-------------------------------------------------------------------------
323// CommandObjectSettingsList -- List settable variables
324//-------------------------------------------------------------------------
325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326class CommandObjectSettingsList : public CommandObjectParsed {
Kate Stone7428a182016-07-14 22:03:10 +0000327public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 CommandObjectSettingsList(CommandInterpreter &interpreter)
329 : CommandObjectParsed(interpreter, "settings list",
330 "List and describe matching debugger settings. "
331 "Defaults to all listing all settings.",
332 nullptr) {
333 CommandArgumentEntry arg;
334 CommandArgumentData var_name_arg;
335 CommandArgumentData prefix_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 // Define the first variant of this arg.
338 var_name_arg.arg_type = eArgTypeSettingVariableName;
339 var_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 // Define the second variant of this arg.
342 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
343 prefix_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 arg.push_back(var_name_arg);
346 arg.push_back(prefix_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000347
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 // Push the data for the first argument into the m_arguments vector.
349 m_arguments.push_back(arg);
350 }
Jim Ingham5a988412012-06-08 21:56:10 +0000351
Kate Stoneb9c1b512016-09-06 20:57:50 +0000352 ~CommandObjectSettingsList() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000353
Kate Stoneb9c1b512016-09-06 20:57:50 +0000354 int HandleArgumentCompletion(Args &input, int &cursor_index,
355 int &cursor_char_position,
356 OptionElementVector &opt_element_vector,
357 int match_start_point, int max_return_elements,
358 bool &word_complete,
359 StringList &matches) override {
360 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
361 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000362
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 CommandCompletions::InvokeCommonCompletionCallbacks(
364 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
365 completion_str.c_str(), match_start_point, max_return_elements, nullptr,
366 word_complete, matches);
367 return matches.GetSize();
368 }
Jim Ingham5a988412012-06-08 21:56:10 +0000369
370protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000371 bool DoExecute(Args &args, CommandReturnObject &result) override {
372 result.SetStatus(eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000373
Kate Stoneb9c1b512016-09-06 20:57:50 +0000374 const bool will_modify = false;
375 const size_t argc = args.GetArgumentCount();
376 if (argc > 0) {
377 const bool dump_qualified_name = true;
Jim Ingham5a988412012-06-08 21:56:10 +0000378
Zachary Turner97d2c402016-10-05 23:40:23 +0000379 // TODO: Convert to StringRef based enumeration. Requires converting
380 // GetPropertyAtPath first.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000381 for (size_t i = 0; i < argc; ++i) {
382 const char *property_path = args.GetArgumentAtIndex(i);
Greg Clayton67cc0632012-08-22 17:17:09 +0000383
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384 const Property *property =
385 m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath(
386 &m_exe_ctx, will_modify, property_path);
387
388 if (property) {
389 property->DumpDescription(m_interpreter, result.GetOutputStream(), 0,
390 dump_qualified_name);
391 } else {
392 result.AppendErrorWithFormat("invalid property path '%s'",
393 property_path);
394 result.SetStatus(eReturnStatusFailed);
Jim Ingham5a988412012-06-08 21:56:10 +0000395 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000396 }
397 } else {
398 m_interpreter.GetDebugger().DumpAllDescriptions(m_interpreter,
399 result.GetOutputStream());
Jim Ingham5a988412012-06-08 21:56:10 +0000400 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401
402 return result.Succeeded();
403 }
Jim Ingham5a988412012-06-08 21:56:10 +0000404};
405
406//-------------------------------------------------------------------------
407// CommandObjectSettingsRemove
408//-------------------------------------------------------------------------
409
Kate Stoneb9c1b512016-09-06 20:57:50 +0000410class CommandObjectSettingsRemove : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000411public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412 CommandObjectSettingsRemove(CommandInterpreter &interpreter)
413 : CommandObjectRaw(interpreter, "settings remove",
414 "Remove a value from a setting, specified by array "
Zachary Turnera4496982016-10-05 21:14:38 +0000415 "index or dictionary key.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000416 CommandArgumentEntry arg1;
417 CommandArgumentEntry arg2;
418 CommandArgumentData var_name_arg;
419 CommandArgumentData index_arg;
420 CommandArgumentData key_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000421
Kate Stoneb9c1b512016-09-06 20:57:50 +0000422 // Define the first (and only) variant of this arg.
423 var_name_arg.arg_type = eArgTypeSettingVariableName;
424 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000425
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426 // There is only one variant this argument could be; put it into the
427 // argument entry.
428 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000429
Kate Stoneb9c1b512016-09-06 20:57:50 +0000430 // Define the first variant of this arg.
431 index_arg.arg_type = eArgTypeSettingIndex;
432 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000433
Kate Stoneb9c1b512016-09-06 20:57:50 +0000434 // Define the second variant of this arg.
435 key_arg.arg_type = eArgTypeSettingKey;
436 key_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000437
Kate Stoneb9c1b512016-09-06 20:57:50 +0000438 // Push both variants into this arg
439 arg2.push_back(index_arg);
440 arg2.push_back(key_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000441
Kate Stoneb9c1b512016-09-06 20:57:50 +0000442 // Push the data for the first argument into the m_arguments vector.
443 m_arguments.push_back(arg1);
444 m_arguments.push_back(arg2);
445 }
Jim Ingham5a988412012-06-08 21:56:10 +0000446
Kate Stoneb9c1b512016-09-06 20:57:50 +0000447 ~CommandObjectSettingsRemove() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000448
Kate Stoneb9c1b512016-09-06 20:57:50 +0000449 int HandleArgumentCompletion(Args &input, int &cursor_index,
450 int &cursor_char_position,
451 OptionElementVector &opt_element_vector,
452 int match_start_point, int max_return_elements,
453 bool &word_complete,
454 StringList &matches) override {
455 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
456 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000457
Kate Stoneb9c1b512016-09-06 20:57:50 +0000458 // Attempting to complete variable name
459 if (cursor_index < 2)
460 CommandCompletions::InvokeCommonCompletionCallbacks(
461 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
462 completion_str.c_str(), match_start_point, max_return_elements,
463 nullptr, word_complete, matches);
464 return matches.GetSize();
465 }
Jim Ingham5a988412012-06-08 21:56:10 +0000466
467protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000468 bool DoExecute(const char *command, CommandReturnObject &result) override {
469 result.SetStatus(eReturnStatusSuccessFinishNoResult);
470
471 Args cmd_args(command);
472
473 // Process possible options.
474 if (!ParseOptions(cmd_args, result))
475 return false;
476
477 const size_t argc = cmd_args.GetArgumentCount();
478 if (argc == 0) {
479 result.AppendError("'settings set' takes an array or dictionary item, or "
480 "an array followed by one or more indexes, or a "
481 "dictionary followed by one or more key names to "
482 "remove");
483 result.SetStatus(eReturnStatusFailed);
484 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000485 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000486
487 const char *var_name = cmd_args.GetArgumentAtIndex(0);
488 if ((var_name == nullptr) || (var_name[0] == '\0')) {
489 result.AppendError(
490 "'settings set' command requires a valid variable name");
491 result.SetStatus(eReturnStatusFailed);
492 return false;
493 }
494
495 // Split the raw command into var_name and value pair.
496 llvm::StringRef raw_str(command);
497 std::string var_value_string = raw_str.split(var_name).second.str();
498 const char *var_value_cstr =
499 Args::StripSpaces(var_value_string, true, true, false);
500
501 Error error(m_interpreter.GetDebugger().SetPropertyValue(
502 &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr));
503 if (error.Fail()) {
504 result.AppendError(error.AsCString());
505 result.SetStatus(eReturnStatusFailed);
506 return false;
507 }
508
509 return result.Succeeded();
510 }
Jim Ingham5a988412012-06-08 21:56:10 +0000511};
512
513//-------------------------------------------------------------------------
514// CommandObjectSettingsReplace
515//-------------------------------------------------------------------------
516
Kate Stoneb9c1b512016-09-06 20:57:50 +0000517class CommandObjectSettingsReplace : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000518public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000519 CommandObjectSettingsReplace(CommandInterpreter &interpreter)
520 : CommandObjectRaw(interpreter, "settings replace",
521 "Replace the debugger setting value specified by "
Zachary Turnera4496982016-10-05 21:14:38 +0000522 "array index or dictionary key.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000523 CommandArgumentEntry arg1;
524 CommandArgumentEntry arg2;
525 CommandArgumentEntry arg3;
526 CommandArgumentData var_name_arg;
527 CommandArgumentData index_arg;
528 CommandArgumentData key_arg;
529 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000530
Kate Stoneb9c1b512016-09-06 20:57:50 +0000531 // Define the first (and only) variant of this arg.
532 var_name_arg.arg_type = eArgTypeSettingVariableName;
533 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000534
Kate Stoneb9c1b512016-09-06 20:57:50 +0000535 // There is only one variant this argument could be; put it into the
536 // argument entry.
537 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000538
Kate Stoneb9c1b512016-09-06 20:57:50 +0000539 // Define the first (variant of this arg.
540 index_arg.arg_type = eArgTypeSettingIndex;
541 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000542
Kate Stoneb9c1b512016-09-06 20:57:50 +0000543 // Define the second (variant of this arg.
544 key_arg.arg_type = eArgTypeSettingKey;
545 key_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000546
Kate Stoneb9c1b512016-09-06 20:57:50 +0000547 // Put both variants into this arg
548 arg2.push_back(index_arg);
549 arg2.push_back(key_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000550
Kate Stoneb9c1b512016-09-06 20:57:50 +0000551 // Define the first (and only) variant of this arg.
552 value_arg.arg_type = eArgTypeValue;
553 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000554
Kate Stoneb9c1b512016-09-06 20:57:50 +0000555 // There is only one variant this argument could be; put it into the
556 // argument entry.
557 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000558
Kate Stoneb9c1b512016-09-06 20:57:50 +0000559 // Push the data for the first argument into the m_arguments vector.
560 m_arguments.push_back(arg1);
561 m_arguments.push_back(arg2);
562 m_arguments.push_back(arg3);
563 }
Jim Ingham5a988412012-06-08 21:56:10 +0000564
Kate Stoneb9c1b512016-09-06 20:57:50 +0000565 ~CommandObjectSettingsReplace() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000566
Kate Stoneb9c1b512016-09-06 20:57:50 +0000567 // Overrides base class's behavior where WantsCompletion =
568 // !WantsRawCommandString.
569 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000570
Kate Stoneb9c1b512016-09-06 20:57:50 +0000571 int HandleArgumentCompletion(Args &input, int &cursor_index,
572 int &cursor_char_position,
573 OptionElementVector &opt_element_vector,
574 int match_start_point, int max_return_elements,
575 bool &word_complete,
576 StringList &matches) override {
577 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
578 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000579
Kate Stoneb9c1b512016-09-06 20:57:50 +0000580 // Attempting to complete variable name
581 if (cursor_index < 2)
582 CommandCompletions::InvokeCommonCompletionCallbacks(
583 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
584 completion_str.c_str(), match_start_point, max_return_elements,
585 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000586
Kate Stoneb9c1b512016-09-06 20:57:50 +0000587 return matches.GetSize();
588 }
Jim Ingham5a988412012-06-08 21:56:10 +0000589
590protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000591 bool DoExecute(const char *command, CommandReturnObject &result) override {
592 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000593
Kate Stoneb9c1b512016-09-06 20:57:50 +0000594 Args cmd_args(command);
595 const char *var_name = cmd_args.GetArgumentAtIndex(0);
596 if ((var_name == nullptr) || (var_name[0] == '\0')) {
597 result.AppendError("'settings replace' command requires a valid variable "
598 "name; No value supplied");
599 result.SetStatus(eReturnStatusFailed);
600 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000601 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000602
603 // Split the raw command into var_name, index_value, and value triple.
604 llvm::StringRef raw_str(command);
605 std::string var_value_string = raw_str.split(var_name).second.str();
606 const char *var_value_cstr =
607 Args::StripSpaces(var_value_string, true, true, false);
608
609 Error error(m_interpreter.GetDebugger().SetPropertyValue(
610 &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr));
611 if (error.Fail()) {
612 result.AppendError(error.AsCString());
613 result.SetStatus(eReturnStatusFailed);
614 return false;
615 } else {
616 result.SetStatus(eReturnStatusSuccessFinishNoResult);
617 }
618
619 return result.Succeeded();
620 }
Jim Ingham5a988412012-06-08 21:56:10 +0000621};
622
623//-------------------------------------------------------------------------
624// CommandObjectSettingsInsertBefore
625//-------------------------------------------------------------------------
626
Kate Stoneb9c1b512016-09-06 20:57:50 +0000627class CommandObjectSettingsInsertBefore : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000628public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000629 CommandObjectSettingsInsertBefore(CommandInterpreter &interpreter)
630 : CommandObjectRaw(interpreter, "settings insert-before",
631 "Insert one or more values into an debugger array "
632 "setting immediately before the specified element "
Zachary Turnera4496982016-10-05 21:14:38 +0000633 "index.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000634 CommandArgumentEntry arg1;
635 CommandArgumentEntry arg2;
636 CommandArgumentEntry arg3;
637 CommandArgumentData var_name_arg;
638 CommandArgumentData index_arg;
639 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000640
Kate Stoneb9c1b512016-09-06 20:57:50 +0000641 // Define the first (and only) variant of this arg.
642 var_name_arg.arg_type = eArgTypeSettingVariableName;
643 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000644
Kate Stoneb9c1b512016-09-06 20:57:50 +0000645 // There is only one variant this argument could be; put it into the
646 // argument entry.
647 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000648
Kate Stoneb9c1b512016-09-06 20:57:50 +0000649 // Define the first (variant of this arg.
650 index_arg.arg_type = eArgTypeSettingIndex;
651 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000652
Kate Stoneb9c1b512016-09-06 20:57:50 +0000653 // There is only one variant this argument could be; put it into the
654 // argument entry.
655 arg2.push_back(index_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000656
Kate Stoneb9c1b512016-09-06 20:57:50 +0000657 // Define the first (and only) variant of this arg.
658 value_arg.arg_type = eArgTypeValue;
659 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000660
Kate Stoneb9c1b512016-09-06 20:57:50 +0000661 // There is only one variant this argument could be; put it into the
662 // argument entry.
663 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000664
Kate Stoneb9c1b512016-09-06 20:57:50 +0000665 // Push the data for the first argument into the m_arguments vector.
666 m_arguments.push_back(arg1);
667 m_arguments.push_back(arg2);
668 m_arguments.push_back(arg3);
669 }
Jim Ingham5a988412012-06-08 21:56:10 +0000670
Kate Stoneb9c1b512016-09-06 20:57:50 +0000671 ~CommandObjectSettingsInsertBefore() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000672
Kate Stoneb9c1b512016-09-06 20:57:50 +0000673 // Overrides base class's behavior where WantsCompletion =
674 // !WantsRawCommandString.
675 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000676
Kate Stoneb9c1b512016-09-06 20:57:50 +0000677 int HandleArgumentCompletion(Args &input, int &cursor_index,
678 int &cursor_char_position,
679 OptionElementVector &opt_element_vector,
680 int match_start_point, int max_return_elements,
681 bool &word_complete,
682 StringList &matches) override {
683 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
684 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000685
Kate Stoneb9c1b512016-09-06 20:57:50 +0000686 // Attempting to complete variable name
687 if (cursor_index < 2)
688 CommandCompletions::InvokeCommonCompletionCallbacks(
689 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
690 completion_str.c_str(), match_start_point, max_return_elements,
691 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000692
Kate Stoneb9c1b512016-09-06 20:57:50 +0000693 return matches.GetSize();
694 }
Jim Ingham5a988412012-06-08 21:56:10 +0000695
696protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000697 bool DoExecute(const char *command, CommandReturnObject &result) override {
698 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000699
Kate Stoneb9c1b512016-09-06 20:57:50 +0000700 Args cmd_args(command);
701 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000702
Kate Stoneb9c1b512016-09-06 20:57:50 +0000703 if (argc < 3) {
704 result.AppendError("'settings insert-before' takes more arguments");
705 result.SetStatus(eReturnStatusFailed);
706 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000707 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000708
709 const char *var_name = cmd_args.GetArgumentAtIndex(0);
710 if ((var_name == nullptr) || (var_name[0] == '\0')) {
711 result.AppendError("'settings insert-before' command requires a valid "
712 "variable name; No value supplied");
713 result.SetStatus(eReturnStatusFailed);
714 return false;
715 }
716
717 // Split the raw command into var_name, index_value, and value triple.
718 llvm::StringRef raw_str(command);
719 std::string var_value_string = raw_str.split(var_name).second.str();
720 const char *var_value_cstr =
721 Args::StripSpaces(var_value_string, true, true, false);
722
723 Error error(m_interpreter.GetDebugger().SetPropertyValue(
724 &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr));
725 if (error.Fail()) {
726 result.AppendError(error.AsCString());
727 result.SetStatus(eReturnStatusFailed);
728 return false;
729 }
730
731 return result.Succeeded();
732 }
Jim Ingham5a988412012-06-08 21:56:10 +0000733};
734
735//-------------------------------------------------------------------------
736// CommandObjectSettingInsertAfter
737//-------------------------------------------------------------------------
738
Kate Stoneb9c1b512016-09-06 20:57:50 +0000739class CommandObjectSettingsInsertAfter : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000740public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000741 CommandObjectSettingsInsertAfter(CommandInterpreter &interpreter)
742 : CommandObjectRaw(interpreter, "settings insert-after",
743 "Insert one or more values into a debugger array "
Zachary Turnera4496982016-10-05 21:14:38 +0000744 "settings after the specified element index.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000745 CommandArgumentEntry arg1;
746 CommandArgumentEntry arg2;
747 CommandArgumentEntry arg3;
748 CommandArgumentData var_name_arg;
749 CommandArgumentData index_arg;
750 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000751
Kate Stoneb9c1b512016-09-06 20:57:50 +0000752 // Define the first (and only) variant of this arg.
753 var_name_arg.arg_type = eArgTypeSettingVariableName;
754 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000755
Kate Stoneb9c1b512016-09-06 20:57:50 +0000756 // There is only one variant this argument could be; put it into the
757 // argument entry.
758 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000759
Kate Stoneb9c1b512016-09-06 20:57:50 +0000760 // Define the first (variant of this arg.
761 index_arg.arg_type = eArgTypeSettingIndex;
762 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000763
Kate Stoneb9c1b512016-09-06 20:57:50 +0000764 // There is only one variant this argument could be; put it into the
765 // argument entry.
766 arg2.push_back(index_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000767
Kate Stoneb9c1b512016-09-06 20:57:50 +0000768 // Define the first (and only) variant of this arg.
769 value_arg.arg_type = eArgTypeValue;
770 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000771
Kate Stoneb9c1b512016-09-06 20:57:50 +0000772 // There is only one variant this argument could be; put it into the
773 // argument entry.
774 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000775
Kate Stoneb9c1b512016-09-06 20:57:50 +0000776 // Push the data for the first argument into the m_arguments vector.
777 m_arguments.push_back(arg1);
778 m_arguments.push_back(arg2);
779 m_arguments.push_back(arg3);
780 }
Jim Ingham5a988412012-06-08 21:56:10 +0000781
Kate Stoneb9c1b512016-09-06 20:57:50 +0000782 ~CommandObjectSettingsInsertAfter() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000783
Kate Stoneb9c1b512016-09-06 20:57:50 +0000784 // Overrides base class's behavior where WantsCompletion =
785 // !WantsRawCommandString.
786 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000787
Kate Stoneb9c1b512016-09-06 20:57:50 +0000788 int HandleArgumentCompletion(Args &input, int &cursor_index,
789 int &cursor_char_position,
790 OptionElementVector &opt_element_vector,
791 int match_start_point, int max_return_elements,
792 bool &word_complete,
793 StringList &matches) override {
794 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
795 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000796
Kate Stoneb9c1b512016-09-06 20:57:50 +0000797 // Attempting to complete variable name
798 if (cursor_index < 2)
799 CommandCompletions::InvokeCommonCompletionCallbacks(
800 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
801 completion_str.c_str(), match_start_point, max_return_elements,
802 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000803
Kate Stoneb9c1b512016-09-06 20:57:50 +0000804 return matches.GetSize();
805 }
806
Jim Ingham5a988412012-06-08 21:56:10 +0000807protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000808 bool DoExecute(const char *command, CommandReturnObject &result) override {
809 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000810
Kate Stoneb9c1b512016-09-06 20:57:50 +0000811 Args cmd_args(command);
812 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000813
Kate Stoneb9c1b512016-09-06 20:57:50 +0000814 if (argc < 3) {
815 result.AppendError("'settings insert-after' takes more arguments");
816 result.SetStatus(eReturnStatusFailed);
817 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000818 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000819
820 const char *var_name = cmd_args.GetArgumentAtIndex(0);
821 if ((var_name == nullptr) || (var_name[0] == '\0')) {
822 result.AppendError("'settings insert-after' command requires a valid "
823 "variable name; No value supplied");
824 result.SetStatus(eReturnStatusFailed);
825 return false;
826 }
827
828 // Split the raw command into var_name, index_value, and value triple.
829 llvm::StringRef raw_str(command);
830 std::string var_value_string = raw_str.split(var_name).second.str();
831 const char *var_value_cstr =
832 Args::StripSpaces(var_value_string, true, true, false);
833
834 Error error(m_interpreter.GetDebugger().SetPropertyValue(
835 &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr));
836 if (error.Fail()) {
837 result.AppendError(error.AsCString());
838 result.SetStatus(eReturnStatusFailed);
839 return false;
840 }
841
842 return result.Succeeded();
843 }
Jim Ingham5a988412012-06-08 21:56:10 +0000844};
845
846//-------------------------------------------------------------------------
847// CommandObjectSettingsAppend
848//-------------------------------------------------------------------------
849
Kate Stoneb9c1b512016-09-06 20:57:50 +0000850class CommandObjectSettingsAppend : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000851public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000852 CommandObjectSettingsAppend(CommandInterpreter &interpreter)
853 : CommandObjectRaw(interpreter, "settings append",
854 "Append one or more values to a debugger array, "
Zachary Turnera4496982016-10-05 21:14:38 +0000855 "dictionary, or string setting.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000856 CommandArgumentEntry arg1;
857 CommandArgumentEntry arg2;
858 CommandArgumentData var_name_arg;
859 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000860
Kate Stoneb9c1b512016-09-06 20:57:50 +0000861 // Define the first (and only) variant of this arg.
862 var_name_arg.arg_type = eArgTypeSettingVariableName;
863 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000864
Kate Stoneb9c1b512016-09-06 20:57:50 +0000865 // There is only one variant this argument could be; put it into the
866 // argument entry.
867 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000868
Kate Stoneb9c1b512016-09-06 20:57:50 +0000869 // Define the first (and only) variant of this arg.
870 value_arg.arg_type = eArgTypeValue;
871 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000872
Kate Stoneb9c1b512016-09-06 20:57:50 +0000873 // There is only one variant this argument could be; put it into the
874 // argument entry.
875 arg2.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000876
Kate Stoneb9c1b512016-09-06 20:57:50 +0000877 // Push the data for the first argument into the m_arguments vector.
878 m_arguments.push_back(arg1);
879 m_arguments.push_back(arg2);
880 }
Jim Ingham5a988412012-06-08 21:56:10 +0000881
Kate Stoneb9c1b512016-09-06 20:57:50 +0000882 ~CommandObjectSettingsAppend() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000883
Kate Stoneb9c1b512016-09-06 20:57:50 +0000884 // Overrides base class's behavior where WantsCompletion =
885 // !WantsRawCommandString.
886 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000887
Kate Stoneb9c1b512016-09-06 20:57:50 +0000888 int HandleArgumentCompletion(Args &input, int &cursor_index,
889 int &cursor_char_position,
890 OptionElementVector &opt_element_vector,
891 int match_start_point, int max_return_elements,
892 bool &word_complete,
893 StringList &matches) override {
894 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
895 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000896
Kate Stoneb9c1b512016-09-06 20:57:50 +0000897 // Attempting to complete variable name
898 if (cursor_index < 2)
899 CommandCompletions::InvokeCommonCompletionCallbacks(
900 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
901 completion_str.c_str(), match_start_point, max_return_elements,
902 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000903
Kate Stoneb9c1b512016-09-06 20:57:50 +0000904 return matches.GetSize();
905 }
Jim Ingham5a988412012-06-08 21:56:10 +0000906
907protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000908 bool DoExecute(const char *command, CommandReturnObject &result) override {
909 result.SetStatus(eReturnStatusSuccessFinishNoResult);
910 Args cmd_args(command);
911 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000912
Kate Stoneb9c1b512016-09-06 20:57:50 +0000913 if (argc < 2) {
914 result.AppendError("'settings append' takes more arguments");
915 result.SetStatus(eReturnStatusFailed);
916 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000917 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000918
919 const char *var_name = cmd_args.GetArgumentAtIndex(0);
920 if ((var_name == nullptr) || (var_name[0] == '\0')) {
921 result.AppendError("'settings append' command requires a valid variable "
922 "name; No value supplied");
923 result.SetStatus(eReturnStatusFailed);
924 return false;
925 }
926
927 // Do not perform cmd_args.Shift() since StringRef is manipulating the
928 // raw character string later on.
929
930 // Split the raw command into var_name and value pair.
931 llvm::StringRef raw_str(command);
932 std::string var_value_string = raw_str.split(var_name).second.str();
933 const char *var_value_cstr =
934 Args::StripSpaces(var_value_string, true, true, false);
935
936 Error error(m_interpreter.GetDebugger().SetPropertyValue(
937 &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr));
938 if (error.Fail()) {
939 result.AppendError(error.AsCString());
940 result.SetStatus(eReturnStatusFailed);
941 return false;
942 }
943
944 return result.Succeeded();
945 }
Jim Ingham5a988412012-06-08 21:56:10 +0000946};
947
948//-------------------------------------------------------------------------
949// CommandObjectSettingsClear
950//-------------------------------------------------------------------------
951
Kate Stoneb9c1b512016-09-06 20:57:50 +0000952class CommandObjectSettingsClear : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000953public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000954 CommandObjectSettingsClear(CommandInterpreter &interpreter)
955 : CommandObjectParsed(
956 interpreter, "settings clear",
957 "Clear a debugger setting array, dictionary, or string.", nullptr) {
958 CommandArgumentEntry arg;
959 CommandArgumentData var_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000960
Kate Stoneb9c1b512016-09-06 20:57:50 +0000961 // Define the first (and only) variant of this arg.
962 var_name_arg.arg_type = eArgTypeSettingVariableName;
963 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000964
Kate Stoneb9c1b512016-09-06 20:57:50 +0000965 // There is only one variant this argument could be; put it into the
966 // argument entry.
967 arg.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000968
Kate Stoneb9c1b512016-09-06 20:57:50 +0000969 // Push the data for the first argument into the m_arguments vector.
970 m_arguments.push_back(arg);
971 }
Jim Ingham5a988412012-06-08 21:56:10 +0000972
Kate Stoneb9c1b512016-09-06 20:57:50 +0000973 ~CommandObjectSettingsClear() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000974
Kate Stoneb9c1b512016-09-06 20:57:50 +0000975 int HandleArgumentCompletion(Args &input, int &cursor_index,
976 int &cursor_char_position,
977 OptionElementVector &opt_element_vector,
978 int match_start_point, int max_return_elements,
979 bool &word_complete,
980 StringList &matches) override {
981 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
982 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000983
Kate Stoneb9c1b512016-09-06 20:57:50 +0000984 // Attempting to complete variable name
985 if (cursor_index < 2)
986 CommandCompletions::InvokeCommonCompletionCallbacks(
987 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
988 completion_str.c_str(), match_start_point, max_return_elements,
989 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000990
Kate Stoneb9c1b512016-09-06 20:57:50 +0000991 return matches.GetSize();
992 }
Jim Ingham5a988412012-06-08 21:56:10 +0000993
994protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000995 bool DoExecute(Args &command, CommandReturnObject &result) override {
996 result.SetStatus(eReturnStatusSuccessFinishNoResult);
997 const size_t argc = command.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000998
Kate Stoneb9c1b512016-09-06 20:57:50 +0000999 if (argc != 1) {
1000 result.AppendError("'settings clear' takes exactly one argument");
1001 result.SetStatus(eReturnStatusFailed);
1002 return false;
Jim Ingham5a988412012-06-08 21:56:10 +00001003 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001004
1005 const char *var_name = command.GetArgumentAtIndex(0);
1006 if ((var_name == nullptr) || (var_name[0] == '\0')) {
1007 result.AppendError("'settings clear' command requires a valid variable "
1008 "name; No value supplied");
1009 result.SetStatus(eReturnStatusFailed);
1010 return false;
1011 }
1012
1013 Error error(m_interpreter.GetDebugger().SetPropertyValue(
1014 &m_exe_ctx, eVarSetOperationClear, var_name, nullptr));
1015 if (error.Fail()) {
1016 result.AppendError(error.AsCString());
1017 result.SetStatus(eReturnStatusFailed);
1018 return false;
1019 }
1020
1021 return result.Succeeded();
1022 }
Jim Ingham5a988412012-06-08 21:56:10 +00001023};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024
1025//-------------------------------------------------------------------------
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001026// CommandObjectMultiwordSettings
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027//-------------------------------------------------------------------------
1028
Kate Stoneb9c1b512016-09-06 20:57:50 +00001029CommandObjectMultiwordSettings::CommandObjectMultiwordSettings(
1030 CommandInterpreter &interpreter)
1031 : CommandObjectMultiword(interpreter, "settings",
1032 "Commands for managing LLDB settings.",
1033 "settings <subcommand> [<command-options>]") {
1034 LoadSubCommand("set",
1035 CommandObjectSP(new CommandObjectSettingsSet(interpreter)));
1036 LoadSubCommand("show",
1037 CommandObjectSP(new CommandObjectSettingsShow(interpreter)));
1038 LoadSubCommand("list",
1039 CommandObjectSP(new CommandObjectSettingsList(interpreter)));
1040 LoadSubCommand("remove",
1041 CommandObjectSP(new CommandObjectSettingsRemove(interpreter)));
1042 LoadSubCommand("replace", CommandObjectSP(
1043 new CommandObjectSettingsReplace(interpreter)));
1044 LoadSubCommand(
1045 "insert-before",
1046 CommandObjectSP(new CommandObjectSettingsInsertBefore(interpreter)));
1047 LoadSubCommand(
1048 "insert-after",
1049 CommandObjectSP(new CommandObjectSettingsInsertAfter(interpreter)));
1050 LoadSubCommand("append",
1051 CommandObjectSP(new CommandObjectSettingsAppend(interpreter)));
1052 LoadSubCommand("clear",
1053 CommandObjectSP(new CommandObjectSettingsClear(interpreter)));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001054}
1055
Eugene Zelenko3f18ea02016-02-24 02:05:55 +00001056CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings() = default;