blob: d42466cd13b13869a43812f4a607b9da44df0347 [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
Zachary Turner3eb2b442017-03-22 23:33:16 +000018#include "lldb/Host/OptionParser.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/Interpreter/CommandCompletions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Interpreter/CommandInterpreter.h"
21#include "lldb/Interpreter/CommandReturnObject.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000022#include "lldb/Interpreter/OptionValueProperties.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023
24using namespace lldb;
25using namespace lldb_private;
Jim Ingham5a988412012-06-08 21:56:10 +000026
Jim Ingham5a988412012-06-08 21:56:10 +000027//-------------------------------------------------------------------------
28// CommandObjectSettingsSet
29//-------------------------------------------------------------------------
30
Zachary Turner1f0f5b52016-09-22 20:22:55 +000031static OptionDefinition g_settings_set_options[] = {
32 // clang-format off
33 { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Apply the new value to the global default value." }
34 // clang-format on
35};
36
Kate Stoneb9c1b512016-09-06 20:57:50 +000037class CommandObjectSettingsSet : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +000038public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 CommandObjectSettingsSet(CommandInterpreter &interpreter)
40 : CommandObjectRaw(interpreter, "settings set",
Zachary Turnera4496982016-10-05 21:14:38 +000041 "Set the value of the specified debugger setting."),
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 m_options() {
43 CommandArgumentEntry arg1;
44 CommandArgumentEntry arg2;
45 CommandArgumentData var_name_arg;
46 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 // Define the first (and only) variant of this arg.
49 var_name_arg.arg_type = eArgTypeSettingVariableName;
50 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 // There is only one variant this argument could be; put it into the
53 // argument entry.
54 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 // Define the first (and only) variant of this arg.
57 value_arg.arg_type = eArgTypeValue;
58 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 // There is only one variant this argument could be; put it into the
61 // argument entry.
62 arg2.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 // Push the data for the first argument into the m_arguments vector.
65 m_arguments.push_back(arg1);
66 m_arguments.push_back(arg2);
67
68 SetHelpLong(
69 "\nWhen setting a dictionary or array variable, you can set multiple entries \
70at once by giving the values to the set command. For example:"
71 R"(
Kate Stoneea671fb2015-07-14 05:48:36 +000072
73(lldb) settings set target.run-args value1 value2 value3
74(lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345
75
76(lldb) settings show target.run-args
77 [0]: 'value1'
78 [1]: 'value2'
79 [3]: 'value3'
80(lldb) settings show target.env-vars
81 'MYPATH=~/.:/usr/bin'
82 'SOME_ENV_VAR=12345'
83
Kate Stoneb9c1b512016-09-06 20:57:50 +000084)"
85 "Warning: The 'set' command re-sets the entire array or dictionary. If you \
Kate Stoneea671fb2015-07-14 05:48:36 +000086just want to add, remove or update individual values (or add something to \
87the end), use one of the other settings sub-commands: append, replace, \
Kate Stoneb9c1b512016-09-06 20:57:50 +000088insert-before or insert-after.");
89 }
Jim Ingham5a988412012-06-08 21:56:10 +000090
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 ~CommandObjectSettingsSet() override = default;
92
93 // Overrides base class's behavior where WantsCompletion =
94 // !WantsRawCommandString.
95 bool WantsCompletion() override { return true; }
96
97 Options *GetOptions() override { return &m_options; }
98
99 class CommandOptions : public Options {
100 public:
101 CommandOptions() : Options(), m_global(false) {}
102
103 ~CommandOptions() override = default;
104
Zachary Turner97206d52017-05-12 04:51:55 +0000105 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
106 ExecutionContext *execution_context) override {
107 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 const int short_option = m_getopt_table[option_idx].val;
109
110 switch (short_option) {
111 case 'g':
112 m_global = true;
113 break;
114 default:
115 error.SetErrorStringWithFormat("unrecognized options '%c'",
116 short_option);
117 break;
118 }
119
120 return error;
Jim Ingham5a988412012-06-08 21:56:10 +0000121 }
122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 void OptionParsingStarting(ExecutionContext *execution_context) override {
124 m_global = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000125 }
Jim Ingham5a988412012-06-08 21:56:10 +0000126
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000127 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
Zachary Turner70602432016-09-22 21:06:13 +0000128 return llvm::makeArrayRef(g_settings_set_options);
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000129 }
Jim Ingham5a988412012-06-08 21:56:10 +0000130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131 // Instance variables to hold the values for command options.
Jim Ingham5a988412012-06-08 21:56:10 +0000132
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 bool m_global;
134 };
Jim Ingham5a988412012-06-08 21:56:10 +0000135
Kate Stoneb9c1b512016-09-06 20:57:50 +0000136 int HandleArgumentCompletion(Args &input, int &cursor_index,
137 int &cursor_char_position,
138 OptionElementVector &opt_element_vector,
139 int match_start_point, int max_return_elements,
140 bool &word_complete,
141 StringList &matches) override {
142 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
143 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000144
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145 const size_t argc = input.GetArgumentCount();
146 const char *arg = nullptr;
147 int setting_var_idx;
148 for (setting_var_idx = 1; setting_var_idx < static_cast<int>(argc);
149 ++setting_var_idx) {
150 arg = input.GetArgumentAtIndex(setting_var_idx);
151 if (arg && arg[0] != '-')
152 break; // We found our setting variable name index
Jim Ingham5a988412012-06-08 21:56:10 +0000153 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 if (cursor_index == setting_var_idx) {
155 // Attempting to complete setting variable name
156 CommandCompletions::InvokeCommonCompletionCallbacks(
157 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
158 completion_str.c_str(), match_start_point, max_return_elements,
159 nullptr, word_complete, matches);
160 } else {
161 arg = input.GetArgumentAtIndex(cursor_index);
162
163 if (arg) {
164 if (arg[0] == '-') {
165 // Complete option name
166 } else {
167 // Complete setting value
168 const char *setting_var_name =
169 input.GetArgumentAtIndex(setting_var_idx);
Zachary Turner97206d52017-05-12 04:51:55 +0000170 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171 lldb::OptionValueSP value_sp(
172 m_interpreter.GetDebugger().GetPropertyValue(
173 &m_exe_ctx, setting_var_name, false, error));
174 if (value_sp) {
175 value_sp->AutoComplete(m_interpreter, completion_str.c_str(),
176 match_start_point, max_return_elements,
177 word_complete, matches);
178 }
179 }
180 }
181 }
182 return matches.GetSize();
183 }
184
Jim Ingham5a988412012-06-08 21:56:10 +0000185protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000186 bool DoExecute(const char *command, CommandReturnObject &result) override {
187 Args cmd_args(command);
Jim Ingham5a988412012-06-08 21:56:10 +0000188
Kate Stoneb9c1b512016-09-06 20:57:50 +0000189 // Process possible options.
190 if (!ParseOptions(cmd_args, result))
191 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000192
Kate Stoneb9c1b512016-09-06 20:57:50 +0000193 const size_t argc = cmd_args.GetArgumentCount();
194 if ((argc < 2) && (!m_options.m_global)) {
195 result.AppendError("'settings set' takes more arguments");
196 result.SetStatus(eReturnStatusFailed);
197 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000198 }
Eugene Zelenko3f18ea02016-02-24 02:05:55 +0000199
Kate Stoneb9c1b512016-09-06 20:57:50 +0000200 const char *var_name = cmd_args.GetArgumentAtIndex(0);
201 if ((var_name == nullptr) || (var_name[0] == '\0')) {
202 result.AppendError(
203 "'settings set' command requires a valid variable name");
204 result.SetStatus(eReturnStatusFailed);
205 return false;
206 }
207
208 // Split the raw command into var_name and value pair.
209 llvm::StringRef raw_str(command);
210 std::string var_value_string = raw_str.split(var_name).second.str();
211 const char *var_value_cstr =
212 Args::StripSpaces(var_value_string, true, false, false);
213
Zachary Turner97206d52017-05-12 04:51:55 +0000214 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215 if (m_options.m_global) {
216 error = m_interpreter.GetDebugger().SetPropertyValue(
217 nullptr, eVarSetOperationAssign, var_name, var_value_cstr);
218 }
219
220 if (error.Success()) {
221 // FIXME this is the same issue as the one in commands script import
222 // we could be setting target.load-script-from-symbol-file which would
223 // cause
224 // Python scripts to be loaded, which could run LLDB commands
225 // (e.g. settings set target.process.python-os-plugin-path) and cause a
226 // crash
227 // if we did not clear the command's exe_ctx first
228 ExecutionContext exe_ctx(m_exe_ctx);
229 m_exe_ctx.Clear();
230 error = m_interpreter.GetDebugger().SetPropertyValue(
231 &exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr);
232 }
233
234 if (error.Fail()) {
235 result.AppendError(error.AsCString());
236 result.SetStatus(eReturnStatusFailed);
237 return false;
238 } else {
239 result.SetStatus(eReturnStatusSuccessFinishResult);
240 }
241
242 return result.Succeeded();
243 }
244
Jim Ingham5a988412012-06-08 21:56:10 +0000245private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000246 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +0000247};
248
Jim Ingham5a988412012-06-08 21:56:10 +0000249//-------------------------------------------------------------------------
250// CommandObjectSettingsShow -- Show current values
251//-------------------------------------------------------------------------
252
Kate Stoneb9c1b512016-09-06 20:57:50 +0000253class CommandObjectSettingsShow : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000254public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000255 CommandObjectSettingsShow(CommandInterpreter &interpreter)
256 : CommandObjectParsed(interpreter, "settings show",
257 "Show matching debugger settings and their current "
258 "values. Defaults to showing all settings.",
259 nullptr) {
260 CommandArgumentEntry arg1;
261 CommandArgumentData var_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000262
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 // Define the first (and only) variant of this arg.
264 var_name_arg.arg_type = eArgTypeSettingVariableName;
265 var_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000266
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 // There is only one variant this argument could be; put it into the
268 // argument entry.
269 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000270
Kate Stoneb9c1b512016-09-06 20:57:50 +0000271 // Push the data for the first argument into the m_arguments vector.
272 m_arguments.push_back(arg1);
273 }
Jim Ingham5a988412012-06-08 21:56:10 +0000274
Kate Stoneb9c1b512016-09-06 20:57:50 +0000275 ~CommandObjectSettingsShow() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000276
Kate Stoneb9c1b512016-09-06 20:57:50 +0000277 int HandleArgumentCompletion(Args &input, int &cursor_index,
278 int &cursor_char_position,
279 OptionElementVector &opt_element_vector,
280 int match_start_point, int max_return_elements,
281 bool &word_complete,
282 StringList &matches) override {
283 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
284 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000285
Kate Stoneb9c1b512016-09-06 20:57:50 +0000286 CommandCompletions::InvokeCommonCompletionCallbacks(
287 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
288 completion_str.c_str(), match_start_point, max_return_elements, nullptr,
289 word_complete, matches);
290 return matches.GetSize();
291 }
Jim Ingham5a988412012-06-08 21:56:10 +0000292
293protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294 bool DoExecute(Args &args, CommandReturnObject &result) override {
295 result.SetStatus(eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000296
Zachary Turner97d2c402016-10-05 23:40:23 +0000297 if (!args.empty()) {
Zachary Turnerd6a24752016-11-22 17:10:15 +0000298 for (const auto &arg : args) {
Zachary Turner97206d52017-05-12 04:51:55 +0000299 Status error(m_interpreter.GetDebugger().DumpPropertyValue(
Zachary Turnerd6a24752016-11-22 17:10:15 +0000300 &m_exe_ctx, result.GetOutputStream(), arg.ref,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000301 OptionValue::eDumpGroupValue));
302 if (error.Success()) {
303 result.GetOutputStream().EOL();
304 } else {
305 result.AppendError(error.AsCString());
306 result.SetStatus(eReturnStatusFailed);
Jim Ingham5a988412012-06-08 21:56:10 +0000307 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000308 }
309 } else {
310 m_interpreter.GetDebugger().DumpAllPropertyValues(
311 &m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
Jim Ingham5a988412012-06-08 21:56:10 +0000312 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313
314 return result.Succeeded();
315 }
Jim Ingham5a988412012-06-08 21:56:10 +0000316};
317
318//-------------------------------------------------------------------------
319// CommandObjectSettingsList -- List settable variables
320//-------------------------------------------------------------------------
321
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322class CommandObjectSettingsList : public CommandObjectParsed {
Kate Stone7428a182016-07-14 22:03:10 +0000323public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 CommandObjectSettingsList(CommandInterpreter &interpreter)
325 : CommandObjectParsed(interpreter, "settings list",
326 "List and describe matching debugger settings. "
327 "Defaults to all listing all settings.",
328 nullptr) {
329 CommandArgumentEntry arg;
330 CommandArgumentData var_name_arg;
331 CommandArgumentData prefix_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000332
Kate Stoneb9c1b512016-09-06 20:57:50 +0000333 // Define the first variant of this arg.
334 var_name_arg.arg_type = eArgTypeSettingVariableName;
335 var_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 // Define the second variant of this arg.
338 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
339 prefix_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 arg.push_back(var_name_arg);
342 arg.push_back(prefix_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000343
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 // Push the data for the first argument into the m_arguments vector.
345 m_arguments.push_back(arg);
346 }
Jim Ingham5a988412012-06-08 21:56:10 +0000347
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 ~CommandObjectSettingsList() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000349
Kate Stoneb9c1b512016-09-06 20:57:50 +0000350 int HandleArgumentCompletion(Args &input, int &cursor_index,
351 int &cursor_char_position,
352 OptionElementVector &opt_element_vector,
353 int match_start_point, int max_return_elements,
354 bool &word_complete,
355 StringList &matches) override {
356 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
357 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 CommandCompletions::InvokeCommonCompletionCallbacks(
360 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
361 completion_str.c_str(), match_start_point, max_return_elements, nullptr,
362 word_complete, matches);
363 return matches.GetSize();
364 }
Jim Ingham5a988412012-06-08 21:56:10 +0000365
366protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 bool DoExecute(Args &args, CommandReturnObject &result) override {
368 result.SetStatus(eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000369
Kate Stoneb9c1b512016-09-06 20:57:50 +0000370 const bool will_modify = false;
371 const size_t argc = args.GetArgumentCount();
372 if (argc > 0) {
373 const bool dump_qualified_name = true;
Jim Ingham5a988412012-06-08 21:56:10 +0000374
Zachary Turner97d2c402016-10-05 23:40:23 +0000375 // TODO: Convert to StringRef based enumeration. Requires converting
376 // GetPropertyAtPath first.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000377 for (size_t i = 0; i < argc; ++i) {
378 const char *property_path = args.GetArgumentAtIndex(i);
Greg Clayton67cc0632012-08-22 17:17:09 +0000379
Kate Stoneb9c1b512016-09-06 20:57:50 +0000380 const Property *property =
381 m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath(
382 &m_exe_ctx, will_modify, property_path);
383
384 if (property) {
385 property->DumpDescription(m_interpreter, result.GetOutputStream(), 0,
386 dump_qualified_name);
387 } else {
388 result.AppendErrorWithFormat("invalid property path '%s'",
389 property_path);
390 result.SetStatus(eReturnStatusFailed);
Jim Ingham5a988412012-06-08 21:56:10 +0000391 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000392 }
393 } else {
394 m_interpreter.GetDebugger().DumpAllDescriptions(m_interpreter,
395 result.GetOutputStream());
Jim Ingham5a988412012-06-08 21:56:10 +0000396 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000397
398 return result.Succeeded();
399 }
Jim Ingham5a988412012-06-08 21:56:10 +0000400};
401
402//-------------------------------------------------------------------------
403// CommandObjectSettingsRemove
404//-------------------------------------------------------------------------
405
Kate Stoneb9c1b512016-09-06 20:57:50 +0000406class CommandObjectSettingsRemove : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000407public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 CommandObjectSettingsRemove(CommandInterpreter &interpreter)
409 : CommandObjectRaw(interpreter, "settings remove",
410 "Remove a value from a setting, specified by array "
Zachary Turnera4496982016-10-05 21:14:38 +0000411 "index or dictionary key.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412 CommandArgumentEntry arg1;
413 CommandArgumentEntry arg2;
414 CommandArgumentData var_name_arg;
415 CommandArgumentData index_arg;
416 CommandArgumentData key_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000417
Kate Stoneb9c1b512016-09-06 20:57:50 +0000418 // Define the first (and only) variant of this arg.
419 var_name_arg.arg_type = eArgTypeSettingVariableName;
420 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000421
Kate Stoneb9c1b512016-09-06 20:57:50 +0000422 // There is only one variant this argument could be; put it into the
423 // argument entry.
424 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000425
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426 // Define the first variant of this arg.
427 index_arg.arg_type = eArgTypeSettingIndex;
428 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000429
Kate Stoneb9c1b512016-09-06 20:57:50 +0000430 // Define the second variant of this arg.
431 key_arg.arg_type = eArgTypeSettingKey;
432 key_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000433
Kate Stoneb9c1b512016-09-06 20:57:50 +0000434 // Push both variants into this arg
435 arg2.push_back(index_arg);
436 arg2.push_back(key_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000437
Kate Stoneb9c1b512016-09-06 20:57:50 +0000438 // Push the data for the first argument into the m_arguments vector.
439 m_arguments.push_back(arg1);
440 m_arguments.push_back(arg2);
441 }
Jim Ingham5a988412012-06-08 21:56:10 +0000442
Kate Stoneb9c1b512016-09-06 20:57:50 +0000443 ~CommandObjectSettingsRemove() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000444
Kate Stoneb9c1b512016-09-06 20:57:50 +0000445 int HandleArgumentCompletion(Args &input, int &cursor_index,
446 int &cursor_char_position,
447 OptionElementVector &opt_element_vector,
448 int match_start_point, int max_return_elements,
449 bool &word_complete,
450 StringList &matches) override {
451 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
452 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000453
Kate Stoneb9c1b512016-09-06 20:57:50 +0000454 // Attempting to complete variable name
455 if (cursor_index < 2)
456 CommandCompletions::InvokeCommonCompletionCallbacks(
457 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
458 completion_str.c_str(), match_start_point, max_return_elements,
459 nullptr, word_complete, matches);
460 return matches.GetSize();
461 }
Jim Ingham5a988412012-06-08 21:56:10 +0000462
463protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000464 bool DoExecute(const char *command, CommandReturnObject &result) override {
465 result.SetStatus(eReturnStatusSuccessFinishNoResult);
466
467 Args cmd_args(command);
468
469 // Process possible options.
470 if (!ParseOptions(cmd_args, result))
471 return false;
472
473 const size_t argc = cmd_args.GetArgumentCount();
474 if (argc == 0) {
475 result.AppendError("'settings set' takes an array or dictionary item, or "
476 "an array followed by one or more indexes, or a "
477 "dictionary followed by one or more key names to "
478 "remove");
479 result.SetStatus(eReturnStatusFailed);
480 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000481 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000482
483 const char *var_name = cmd_args.GetArgumentAtIndex(0);
484 if ((var_name == nullptr) || (var_name[0] == '\0')) {
485 result.AppendError(
486 "'settings set' command requires a valid variable name");
487 result.SetStatus(eReturnStatusFailed);
488 return false;
489 }
490
491 // Split the raw command into var_name and value pair.
492 llvm::StringRef raw_str(command);
493 std::string var_value_string = raw_str.split(var_name).second.str();
494 const char *var_value_cstr =
495 Args::StripSpaces(var_value_string, true, true, false);
496
Zachary Turner97206d52017-05-12 04:51:55 +0000497 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000498 &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr));
499 if (error.Fail()) {
500 result.AppendError(error.AsCString());
501 result.SetStatus(eReturnStatusFailed);
502 return false;
503 }
504
505 return result.Succeeded();
506 }
Jim Ingham5a988412012-06-08 21:56:10 +0000507};
508
509//-------------------------------------------------------------------------
510// CommandObjectSettingsReplace
511//-------------------------------------------------------------------------
512
Kate Stoneb9c1b512016-09-06 20:57:50 +0000513class CommandObjectSettingsReplace : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000514public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000515 CommandObjectSettingsReplace(CommandInterpreter &interpreter)
516 : CommandObjectRaw(interpreter, "settings replace",
517 "Replace the debugger setting value specified by "
Zachary Turnera4496982016-10-05 21:14:38 +0000518 "array index or dictionary key.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000519 CommandArgumentEntry arg1;
520 CommandArgumentEntry arg2;
521 CommandArgumentEntry arg3;
522 CommandArgumentData var_name_arg;
523 CommandArgumentData index_arg;
524 CommandArgumentData key_arg;
525 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000526
Kate Stoneb9c1b512016-09-06 20:57:50 +0000527 // Define the first (and only) variant of this arg.
528 var_name_arg.arg_type = eArgTypeSettingVariableName;
529 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000530
Kate Stoneb9c1b512016-09-06 20:57:50 +0000531 // There is only one variant this argument could be; put it into the
532 // argument entry.
533 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000534
Kate Stoneb9c1b512016-09-06 20:57:50 +0000535 // Define the first (variant of this arg.
536 index_arg.arg_type = eArgTypeSettingIndex;
537 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000538
Kate Stoneb9c1b512016-09-06 20:57:50 +0000539 // Define the second (variant of this arg.
540 key_arg.arg_type = eArgTypeSettingKey;
541 key_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000542
Kate Stoneb9c1b512016-09-06 20:57:50 +0000543 // Put both variants into this arg
544 arg2.push_back(index_arg);
545 arg2.push_back(key_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000546
Kate Stoneb9c1b512016-09-06 20:57:50 +0000547 // Define the first (and only) variant of this arg.
548 value_arg.arg_type = eArgTypeValue;
549 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000550
Kate Stoneb9c1b512016-09-06 20:57:50 +0000551 // There is only one variant this argument could be; put it into the
552 // argument entry.
553 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000554
Kate Stoneb9c1b512016-09-06 20:57:50 +0000555 // Push the data for the first argument into the m_arguments vector.
556 m_arguments.push_back(arg1);
557 m_arguments.push_back(arg2);
558 m_arguments.push_back(arg3);
559 }
Jim Ingham5a988412012-06-08 21:56:10 +0000560
Kate Stoneb9c1b512016-09-06 20:57:50 +0000561 ~CommandObjectSettingsReplace() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000562
Kate Stoneb9c1b512016-09-06 20:57:50 +0000563 // Overrides base class's behavior where WantsCompletion =
564 // !WantsRawCommandString.
565 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000566
Kate Stoneb9c1b512016-09-06 20:57:50 +0000567 int HandleArgumentCompletion(Args &input, int &cursor_index,
568 int &cursor_char_position,
569 OptionElementVector &opt_element_vector,
570 int match_start_point, int max_return_elements,
571 bool &word_complete,
572 StringList &matches) override {
573 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
574 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000575
Kate Stoneb9c1b512016-09-06 20:57:50 +0000576 // Attempting to complete variable name
577 if (cursor_index < 2)
578 CommandCompletions::InvokeCommonCompletionCallbacks(
579 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
580 completion_str.c_str(), match_start_point, max_return_elements,
581 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000582
Kate Stoneb9c1b512016-09-06 20:57:50 +0000583 return matches.GetSize();
584 }
Jim Ingham5a988412012-06-08 21:56:10 +0000585
586protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000587 bool DoExecute(const char *command, CommandReturnObject &result) override {
588 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000589
Kate Stoneb9c1b512016-09-06 20:57:50 +0000590 Args cmd_args(command);
591 const char *var_name = cmd_args.GetArgumentAtIndex(0);
592 if ((var_name == nullptr) || (var_name[0] == '\0')) {
593 result.AppendError("'settings replace' command requires a valid variable "
594 "name; No value supplied");
595 result.SetStatus(eReturnStatusFailed);
596 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000597 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000598
599 // Split the raw command into var_name, index_value, and value triple.
600 llvm::StringRef raw_str(command);
601 std::string var_value_string = raw_str.split(var_name).second.str();
602 const char *var_value_cstr =
603 Args::StripSpaces(var_value_string, true, true, false);
604
Zachary Turner97206d52017-05-12 04:51:55 +0000605 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000606 &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr));
607 if (error.Fail()) {
608 result.AppendError(error.AsCString());
609 result.SetStatus(eReturnStatusFailed);
610 return false;
611 } else {
612 result.SetStatus(eReturnStatusSuccessFinishNoResult);
613 }
614
615 return result.Succeeded();
616 }
Jim Ingham5a988412012-06-08 21:56:10 +0000617};
618
619//-------------------------------------------------------------------------
620// CommandObjectSettingsInsertBefore
621//-------------------------------------------------------------------------
622
Kate Stoneb9c1b512016-09-06 20:57:50 +0000623class CommandObjectSettingsInsertBefore : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000624public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000625 CommandObjectSettingsInsertBefore(CommandInterpreter &interpreter)
626 : CommandObjectRaw(interpreter, "settings insert-before",
627 "Insert one or more values into an debugger array "
628 "setting immediately before the specified element "
Zachary Turnera4496982016-10-05 21:14:38 +0000629 "index.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000630 CommandArgumentEntry arg1;
631 CommandArgumentEntry arg2;
632 CommandArgumentEntry arg3;
633 CommandArgumentData var_name_arg;
634 CommandArgumentData index_arg;
635 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000636
Kate Stoneb9c1b512016-09-06 20:57:50 +0000637 // Define the first (and only) variant of this arg.
638 var_name_arg.arg_type = eArgTypeSettingVariableName;
639 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000640
Kate Stoneb9c1b512016-09-06 20:57:50 +0000641 // There is only one variant this argument could be; put it into the
642 // argument entry.
643 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000644
Kate Stoneb9c1b512016-09-06 20:57:50 +0000645 // Define the first (variant of this arg.
646 index_arg.arg_type = eArgTypeSettingIndex;
647 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000648
Kate Stoneb9c1b512016-09-06 20:57:50 +0000649 // There is only one variant this argument could be; put it into the
650 // argument entry.
651 arg2.push_back(index_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000652
Kate Stoneb9c1b512016-09-06 20:57:50 +0000653 // Define the first (and only) variant of this arg.
654 value_arg.arg_type = eArgTypeValue;
655 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000656
Kate Stoneb9c1b512016-09-06 20:57:50 +0000657 // There is only one variant this argument could be; put it into the
658 // argument entry.
659 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000660
Kate Stoneb9c1b512016-09-06 20:57:50 +0000661 // Push the data for the first argument into the m_arguments vector.
662 m_arguments.push_back(arg1);
663 m_arguments.push_back(arg2);
664 m_arguments.push_back(arg3);
665 }
Jim Ingham5a988412012-06-08 21:56:10 +0000666
Kate Stoneb9c1b512016-09-06 20:57:50 +0000667 ~CommandObjectSettingsInsertBefore() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000668
Kate Stoneb9c1b512016-09-06 20:57:50 +0000669 // Overrides base class's behavior where WantsCompletion =
670 // !WantsRawCommandString.
671 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000672
Kate Stoneb9c1b512016-09-06 20:57:50 +0000673 int HandleArgumentCompletion(Args &input, int &cursor_index,
674 int &cursor_char_position,
675 OptionElementVector &opt_element_vector,
676 int match_start_point, int max_return_elements,
677 bool &word_complete,
678 StringList &matches) override {
679 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
680 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000681
Kate Stoneb9c1b512016-09-06 20:57:50 +0000682 // Attempting to complete variable name
683 if (cursor_index < 2)
684 CommandCompletions::InvokeCommonCompletionCallbacks(
685 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
686 completion_str.c_str(), match_start_point, max_return_elements,
687 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000688
Kate Stoneb9c1b512016-09-06 20:57:50 +0000689 return matches.GetSize();
690 }
Jim Ingham5a988412012-06-08 21:56:10 +0000691
692protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000693 bool DoExecute(const char *command, CommandReturnObject &result) override {
694 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000695
Kate Stoneb9c1b512016-09-06 20:57:50 +0000696 Args cmd_args(command);
697 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000698
Kate Stoneb9c1b512016-09-06 20:57:50 +0000699 if (argc < 3) {
700 result.AppendError("'settings insert-before' takes more arguments");
701 result.SetStatus(eReturnStatusFailed);
702 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000703 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000704
705 const char *var_name = cmd_args.GetArgumentAtIndex(0);
706 if ((var_name == nullptr) || (var_name[0] == '\0')) {
707 result.AppendError("'settings insert-before' command requires a valid "
708 "variable name; No value supplied");
709 result.SetStatus(eReturnStatusFailed);
710 return false;
711 }
712
713 // Split the raw command into var_name, index_value, and value triple.
714 llvm::StringRef raw_str(command);
715 std::string var_value_string = raw_str.split(var_name).second.str();
716 const char *var_value_cstr =
717 Args::StripSpaces(var_value_string, true, true, false);
718
Zachary Turner97206d52017-05-12 04:51:55 +0000719 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000720 &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr));
721 if (error.Fail()) {
722 result.AppendError(error.AsCString());
723 result.SetStatus(eReturnStatusFailed);
724 return false;
725 }
726
727 return result.Succeeded();
728 }
Jim Ingham5a988412012-06-08 21:56:10 +0000729};
730
731//-------------------------------------------------------------------------
732// CommandObjectSettingInsertAfter
733//-------------------------------------------------------------------------
734
Kate Stoneb9c1b512016-09-06 20:57:50 +0000735class CommandObjectSettingsInsertAfter : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000736public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000737 CommandObjectSettingsInsertAfter(CommandInterpreter &interpreter)
738 : CommandObjectRaw(interpreter, "settings insert-after",
739 "Insert one or more values into a debugger array "
Zachary Turnera4496982016-10-05 21:14:38 +0000740 "settings after the specified element index.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000741 CommandArgumentEntry arg1;
742 CommandArgumentEntry arg2;
743 CommandArgumentEntry arg3;
744 CommandArgumentData var_name_arg;
745 CommandArgumentData index_arg;
746 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000747
Kate Stoneb9c1b512016-09-06 20:57:50 +0000748 // Define the first (and only) variant of this arg.
749 var_name_arg.arg_type = eArgTypeSettingVariableName;
750 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000751
Kate Stoneb9c1b512016-09-06 20:57:50 +0000752 // There is only one variant this argument could be; put it into the
753 // argument entry.
754 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000755
Kate Stoneb9c1b512016-09-06 20:57:50 +0000756 // Define the first (variant of this arg.
757 index_arg.arg_type = eArgTypeSettingIndex;
758 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000759
Kate Stoneb9c1b512016-09-06 20:57:50 +0000760 // There is only one variant this argument could be; put it into the
761 // argument entry.
762 arg2.push_back(index_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000763
Kate Stoneb9c1b512016-09-06 20:57:50 +0000764 // Define the first (and only) variant of this arg.
765 value_arg.arg_type = eArgTypeValue;
766 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000767
Kate Stoneb9c1b512016-09-06 20:57:50 +0000768 // There is only one variant this argument could be; put it into the
769 // argument entry.
770 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000771
Kate Stoneb9c1b512016-09-06 20:57:50 +0000772 // Push the data for the first argument into the m_arguments vector.
773 m_arguments.push_back(arg1);
774 m_arguments.push_back(arg2);
775 m_arguments.push_back(arg3);
776 }
Jim Ingham5a988412012-06-08 21:56:10 +0000777
Kate Stoneb9c1b512016-09-06 20:57:50 +0000778 ~CommandObjectSettingsInsertAfter() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000779
Kate Stoneb9c1b512016-09-06 20:57:50 +0000780 // Overrides base class's behavior where WantsCompletion =
781 // !WantsRawCommandString.
782 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000783
Kate Stoneb9c1b512016-09-06 20:57:50 +0000784 int HandleArgumentCompletion(Args &input, int &cursor_index,
785 int &cursor_char_position,
786 OptionElementVector &opt_element_vector,
787 int match_start_point, int max_return_elements,
788 bool &word_complete,
789 StringList &matches) override {
790 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
791 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000792
Kate Stoneb9c1b512016-09-06 20:57:50 +0000793 // Attempting to complete variable name
794 if (cursor_index < 2)
795 CommandCompletions::InvokeCommonCompletionCallbacks(
796 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
797 completion_str.c_str(), match_start_point, max_return_elements,
798 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000799
Kate Stoneb9c1b512016-09-06 20:57:50 +0000800 return matches.GetSize();
801 }
802
Jim Ingham5a988412012-06-08 21:56:10 +0000803protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000804 bool DoExecute(const char *command, CommandReturnObject &result) override {
805 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000806
Kate Stoneb9c1b512016-09-06 20:57:50 +0000807 Args cmd_args(command);
808 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000809
Kate Stoneb9c1b512016-09-06 20:57:50 +0000810 if (argc < 3) {
811 result.AppendError("'settings insert-after' takes more arguments");
812 result.SetStatus(eReturnStatusFailed);
813 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000814 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000815
816 const char *var_name = cmd_args.GetArgumentAtIndex(0);
817 if ((var_name == nullptr) || (var_name[0] == '\0')) {
818 result.AppendError("'settings insert-after' command requires a valid "
819 "variable name; No value supplied");
820 result.SetStatus(eReturnStatusFailed);
821 return false;
822 }
823
824 // Split the raw command into var_name, index_value, and value triple.
825 llvm::StringRef raw_str(command);
826 std::string var_value_string = raw_str.split(var_name).second.str();
827 const char *var_value_cstr =
828 Args::StripSpaces(var_value_string, true, true, false);
829
Zachary Turner97206d52017-05-12 04:51:55 +0000830 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000831 &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr));
832 if (error.Fail()) {
833 result.AppendError(error.AsCString());
834 result.SetStatus(eReturnStatusFailed);
835 return false;
836 }
837
838 return result.Succeeded();
839 }
Jim Ingham5a988412012-06-08 21:56:10 +0000840};
841
842//-------------------------------------------------------------------------
843// CommandObjectSettingsAppend
844//-------------------------------------------------------------------------
845
Kate Stoneb9c1b512016-09-06 20:57:50 +0000846class CommandObjectSettingsAppend : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000847public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000848 CommandObjectSettingsAppend(CommandInterpreter &interpreter)
849 : CommandObjectRaw(interpreter, "settings append",
850 "Append one or more values to a debugger array, "
Zachary Turnera4496982016-10-05 21:14:38 +0000851 "dictionary, or string setting.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000852 CommandArgumentEntry arg1;
853 CommandArgumentEntry arg2;
854 CommandArgumentData var_name_arg;
855 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000856
Kate Stoneb9c1b512016-09-06 20:57:50 +0000857 // Define the first (and only) variant of this arg.
858 var_name_arg.arg_type = eArgTypeSettingVariableName;
859 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000860
Kate Stoneb9c1b512016-09-06 20:57:50 +0000861 // There is only one variant this argument could be; put it into the
862 // argument entry.
863 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000864
Kate Stoneb9c1b512016-09-06 20:57:50 +0000865 // Define the first (and only) variant of this arg.
866 value_arg.arg_type = eArgTypeValue;
867 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000868
Kate Stoneb9c1b512016-09-06 20:57:50 +0000869 // There is only one variant this argument could be; put it into the
870 // argument entry.
871 arg2.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000872
Kate Stoneb9c1b512016-09-06 20:57:50 +0000873 // Push the data for the first argument into the m_arguments vector.
874 m_arguments.push_back(arg1);
875 m_arguments.push_back(arg2);
876 }
Jim Ingham5a988412012-06-08 21:56:10 +0000877
Kate Stoneb9c1b512016-09-06 20:57:50 +0000878 ~CommandObjectSettingsAppend() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000879
Kate Stoneb9c1b512016-09-06 20:57:50 +0000880 // Overrides base class's behavior where WantsCompletion =
881 // !WantsRawCommandString.
882 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000883
Kate Stoneb9c1b512016-09-06 20:57:50 +0000884 int HandleArgumentCompletion(Args &input, int &cursor_index,
885 int &cursor_char_position,
886 OptionElementVector &opt_element_vector,
887 int match_start_point, int max_return_elements,
888 bool &word_complete,
889 StringList &matches) override {
890 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
891 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000892
Kate Stoneb9c1b512016-09-06 20:57:50 +0000893 // Attempting to complete variable name
894 if (cursor_index < 2)
895 CommandCompletions::InvokeCommonCompletionCallbacks(
896 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
897 completion_str.c_str(), match_start_point, max_return_elements,
898 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000899
Kate Stoneb9c1b512016-09-06 20:57:50 +0000900 return matches.GetSize();
901 }
Jim Ingham5a988412012-06-08 21:56:10 +0000902
903protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000904 bool DoExecute(const char *command, CommandReturnObject &result) override {
905 result.SetStatus(eReturnStatusSuccessFinishNoResult);
906 Args cmd_args(command);
907 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000908
Kate Stoneb9c1b512016-09-06 20:57:50 +0000909 if (argc < 2) {
910 result.AppendError("'settings append' takes more arguments");
911 result.SetStatus(eReturnStatusFailed);
912 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000913 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000914
915 const char *var_name = cmd_args.GetArgumentAtIndex(0);
916 if ((var_name == nullptr) || (var_name[0] == '\0')) {
917 result.AppendError("'settings append' command requires a valid variable "
918 "name; No value supplied");
919 result.SetStatus(eReturnStatusFailed);
920 return false;
921 }
922
923 // Do not perform cmd_args.Shift() since StringRef is manipulating the
924 // raw character string later on.
925
926 // Split the raw command into var_name and value pair.
927 llvm::StringRef raw_str(command);
928 std::string var_value_string = raw_str.split(var_name).second.str();
929 const char *var_value_cstr =
930 Args::StripSpaces(var_value_string, true, true, false);
931
Zachary Turner97206d52017-05-12 04:51:55 +0000932 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000933 &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr));
934 if (error.Fail()) {
935 result.AppendError(error.AsCString());
936 result.SetStatus(eReturnStatusFailed);
937 return false;
938 }
939
940 return result.Succeeded();
941 }
Jim Ingham5a988412012-06-08 21:56:10 +0000942};
943
944//-------------------------------------------------------------------------
945// CommandObjectSettingsClear
946//-------------------------------------------------------------------------
947
Kate Stoneb9c1b512016-09-06 20:57:50 +0000948class CommandObjectSettingsClear : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000949public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000950 CommandObjectSettingsClear(CommandInterpreter &interpreter)
951 : CommandObjectParsed(
952 interpreter, "settings clear",
953 "Clear a debugger setting array, dictionary, or string.", nullptr) {
954 CommandArgumentEntry arg;
955 CommandArgumentData var_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000956
Kate Stoneb9c1b512016-09-06 20:57:50 +0000957 // Define the first (and only) variant of this arg.
958 var_name_arg.arg_type = eArgTypeSettingVariableName;
959 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000960
Kate Stoneb9c1b512016-09-06 20:57:50 +0000961 // There is only one variant this argument could be; put it into the
962 // argument entry.
963 arg.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000964
Kate Stoneb9c1b512016-09-06 20:57:50 +0000965 // Push the data for the first argument into the m_arguments vector.
966 m_arguments.push_back(arg);
967 }
Jim Ingham5a988412012-06-08 21:56:10 +0000968
Kate Stoneb9c1b512016-09-06 20:57:50 +0000969 ~CommandObjectSettingsClear() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000970
Kate Stoneb9c1b512016-09-06 20:57:50 +0000971 int HandleArgumentCompletion(Args &input, int &cursor_index,
972 int &cursor_char_position,
973 OptionElementVector &opt_element_vector,
974 int match_start_point, int max_return_elements,
975 bool &word_complete,
976 StringList &matches) override {
977 std::string completion_str(input.GetArgumentAtIndex(cursor_index),
978 cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000979
Kate Stoneb9c1b512016-09-06 20:57:50 +0000980 // Attempting to complete variable name
981 if (cursor_index < 2)
982 CommandCompletions::InvokeCommonCompletionCallbacks(
983 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
984 completion_str.c_str(), match_start_point, max_return_elements,
985 nullptr, word_complete, matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000986
Kate Stoneb9c1b512016-09-06 20:57:50 +0000987 return matches.GetSize();
988 }
Jim Ingham5a988412012-06-08 21:56:10 +0000989
990protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000991 bool DoExecute(Args &command, CommandReturnObject &result) override {
992 result.SetStatus(eReturnStatusSuccessFinishNoResult);
993 const size_t argc = command.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000994
Kate Stoneb9c1b512016-09-06 20:57:50 +0000995 if (argc != 1) {
996 result.AppendError("'settings clear' takes exactly one argument");
997 result.SetStatus(eReturnStatusFailed);
998 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000999 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001000
1001 const char *var_name = command.GetArgumentAtIndex(0);
1002 if ((var_name == nullptr) || (var_name[0] == '\0')) {
1003 result.AppendError("'settings clear' command requires a valid variable "
1004 "name; No value supplied");
1005 result.SetStatus(eReturnStatusFailed);
1006 return false;
1007 }
1008
Zachary Turner97206d52017-05-12 04:51:55 +00001009 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Zachary Turner31d97a52016-11-17 18:08:12 +00001010 &m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef()));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001011 if (error.Fail()) {
1012 result.AppendError(error.AsCString());
1013 result.SetStatus(eReturnStatusFailed);
1014 return false;
1015 }
1016
1017 return result.Succeeded();
1018 }
Jim Ingham5a988412012-06-08 21:56:10 +00001019};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020
1021//-------------------------------------------------------------------------
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001022// CommandObjectMultiwordSettings
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023//-------------------------------------------------------------------------
1024
Kate Stoneb9c1b512016-09-06 20:57:50 +00001025CommandObjectMultiwordSettings::CommandObjectMultiwordSettings(
1026 CommandInterpreter &interpreter)
1027 : CommandObjectMultiword(interpreter, "settings",
1028 "Commands for managing LLDB settings.",
1029 "settings <subcommand> [<command-options>]") {
1030 LoadSubCommand("set",
1031 CommandObjectSP(new CommandObjectSettingsSet(interpreter)));
1032 LoadSubCommand("show",
1033 CommandObjectSP(new CommandObjectSettingsShow(interpreter)));
1034 LoadSubCommand("list",
1035 CommandObjectSP(new CommandObjectSettingsList(interpreter)));
1036 LoadSubCommand("remove",
1037 CommandObjectSP(new CommandObjectSettingsRemove(interpreter)));
1038 LoadSubCommand("replace", CommandObjectSP(
1039 new CommandObjectSettingsReplace(interpreter)));
1040 LoadSubCommand(
1041 "insert-before",
1042 CommandObjectSP(new CommandObjectSettingsInsertBefore(interpreter)));
1043 LoadSubCommand(
1044 "insert-after",
1045 CommandObjectSP(new CommandObjectSettingsInsertAfter(interpreter)));
1046 LoadSubCommand("append",
1047 CommandObjectSP(new CommandObjectSettingsAppend(interpreter)));
1048 LoadSubCommand("clear",
1049 CommandObjectSP(new CommandObjectSettingsClear(interpreter)));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001050}
1051
Eugene Zelenko3f18ea02016-02-24 02:05:55 +00001052CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings() = default;