blob: 3b3cfa5ddb5a5bd6d2b0860ec25ccf54dda1efb9 [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
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000031static constexpr OptionDefinition g_settings_set_options[] = {
Zachary Turner1f0f5b52016-09-22 20:22:55 +000032 // clang-format off
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000033 { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Apply the new value to the global default value." }
Zachary Turner1f0f5b52016-09-22 20:22:55 +000034 // 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
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000136 int HandleArgumentCompletion(
137 CompletionRequest &request,
138 OptionElementVector &opt_element_vector) override {
Jim Ingham5a988412012-06-08 21:56:10 +0000139
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000140 const size_t argc = request.GetParsedLine().GetArgumentCount();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141 const char *arg = nullptr;
142 int setting_var_idx;
Pavel Labath5f56fca2018-03-09 10:39:40 +0000143 for (setting_var_idx = 0; setting_var_idx < static_cast<int>(argc);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 ++setting_var_idx) {
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000145 arg = request.GetParsedLine().GetArgumentAtIndex(setting_var_idx);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146 if (arg && arg[0] != '-')
147 break; // We found our setting variable name index
Jim Ingham5a988412012-06-08 21:56:10 +0000148 }
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000149 if (request.GetCursorIndex() == setting_var_idx) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 // Attempting to complete setting variable name
151 CommandCompletions::InvokeCommonCompletionCallbacks(
152 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000153 request, nullptr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 } else {
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000155 arg =
156 request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157
158 if (arg) {
159 if (arg[0] == '-') {
160 // Complete option name
161 } else {
162 // Complete setting value
163 const char *setting_var_name =
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000164 request.GetParsedLine().GetArgumentAtIndex(setting_var_idx);
Zachary Turner97206d52017-05-12 04:51:55 +0000165 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 lldb::OptionValueSP value_sp(
167 m_interpreter.GetDebugger().GetPropertyValue(
168 &m_exe_ctx, setting_var_name, false, error));
169 if (value_sp) {
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000170 value_sp->AutoComplete(m_interpreter, request);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171 }
172 }
173 }
174 }
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000175 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000176 }
177
Jim Ingham5a988412012-06-08 21:56:10 +0000178protected:
Raphael Isemann4d51a902018-07-12 22:28:52 +0000179 bool DoExecute(llvm::StringRef command,
180 CommandReturnObject &result) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000181 Args cmd_args(command);
Jim Ingham5a988412012-06-08 21:56:10 +0000182
Kate Stoneb9c1b512016-09-06 20:57:50 +0000183 // Process possible options.
184 if (!ParseOptions(cmd_args, result))
185 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000186
Kate Stoneb9c1b512016-09-06 20:57:50 +0000187 const size_t argc = cmd_args.GetArgumentCount();
188 if ((argc < 2) && (!m_options.m_global)) {
189 result.AppendError("'settings set' takes more arguments");
190 result.SetStatus(eReturnStatusFailed);
191 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000192 }
Eugene Zelenko3f18ea02016-02-24 02:05:55 +0000193
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194 const char *var_name = cmd_args.GetArgumentAtIndex(0);
195 if ((var_name == nullptr) || (var_name[0] == '\0')) {
196 result.AppendError(
197 "'settings set' command requires a valid variable name");
198 result.SetStatus(eReturnStatusFailed);
199 return false;
200 }
201
202 // Split the raw command into var_name and value pair.
203 llvm::StringRef raw_str(command);
204 std::string var_value_string = raw_str.split(var_name).second.str();
205 const char *var_value_cstr =
206 Args::StripSpaces(var_value_string, true, false, false);
207
Zachary Turner97206d52017-05-12 04:51:55 +0000208 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000209 if (m_options.m_global) {
210 error = m_interpreter.GetDebugger().SetPropertyValue(
211 nullptr, eVarSetOperationAssign, var_name, var_value_cstr);
212 }
213
214 if (error.Success()) {
215 // FIXME this is the same issue as the one in commands script import
216 // we could be setting target.load-script-from-symbol-file which would
Adrian Prantl05097242018-04-30 16:49:04 +0000217 // cause Python scripts to be loaded, which could run LLDB commands (e.g.
218 // settings set target.process.python-os-plugin-path) and cause a crash
Kate Stoneb9c1b512016-09-06 20:57:50 +0000219 // if we did not clear the command's exe_ctx first
220 ExecutionContext exe_ctx(m_exe_ctx);
221 m_exe_ctx.Clear();
222 error = m_interpreter.GetDebugger().SetPropertyValue(
223 &exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr);
224 }
225
226 if (error.Fail()) {
227 result.AppendError(error.AsCString());
228 result.SetStatus(eReturnStatusFailed);
229 return false;
230 } else {
231 result.SetStatus(eReturnStatusSuccessFinishResult);
232 }
233
234 return result.Succeeded();
235 }
236
Jim Ingham5a988412012-06-08 21:56:10 +0000237private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000238 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +0000239};
240
Jim Ingham5a988412012-06-08 21:56:10 +0000241//-------------------------------------------------------------------------
242// CommandObjectSettingsShow -- Show current values
243//-------------------------------------------------------------------------
244
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245class CommandObjectSettingsShow : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000246public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000247 CommandObjectSettingsShow(CommandInterpreter &interpreter)
248 : CommandObjectParsed(interpreter, "settings show",
249 "Show matching debugger settings and their current "
250 "values. Defaults to showing all settings.",
251 nullptr) {
252 CommandArgumentEntry arg1;
253 CommandArgumentData var_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000254
Kate Stoneb9c1b512016-09-06 20:57:50 +0000255 // Define the first (and only) variant of this arg.
256 var_name_arg.arg_type = eArgTypeSettingVariableName;
257 var_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000258
Kate Stoneb9c1b512016-09-06 20:57:50 +0000259 // There is only one variant this argument could be; put it into the
260 // argument entry.
261 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000262
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 // Push the data for the first argument into the m_arguments vector.
264 m_arguments.push_back(arg1);
265 }
Jim Ingham5a988412012-06-08 21:56:10 +0000266
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 ~CommandObjectSettingsShow() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000268
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000269 int HandleArgumentCompletion(
270 CompletionRequest &request,
271 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000272 CommandCompletions::InvokeCommonCompletionCallbacks(
273 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000274 request, nullptr);
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000275 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000276 }
Jim Ingham5a988412012-06-08 21:56:10 +0000277
278protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000279 bool DoExecute(Args &args, CommandReturnObject &result) override {
280 result.SetStatus(eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000281
Zachary Turner97d2c402016-10-05 23:40:23 +0000282 if (!args.empty()) {
Zachary Turnerd6a24752016-11-22 17:10:15 +0000283 for (const auto &arg : args) {
Zachary Turner97206d52017-05-12 04:51:55 +0000284 Status error(m_interpreter.GetDebugger().DumpPropertyValue(
Zachary Turnerd6a24752016-11-22 17:10:15 +0000285 &m_exe_ctx, result.GetOutputStream(), arg.ref,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000286 OptionValue::eDumpGroupValue));
287 if (error.Success()) {
288 result.GetOutputStream().EOL();
289 } else {
290 result.AppendError(error.AsCString());
291 result.SetStatus(eReturnStatusFailed);
Jim Ingham5a988412012-06-08 21:56:10 +0000292 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000293 }
294 } else {
295 m_interpreter.GetDebugger().DumpAllPropertyValues(
296 &m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
Jim Ingham5a988412012-06-08 21:56:10 +0000297 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000298
299 return result.Succeeded();
300 }
Jim Ingham5a988412012-06-08 21:56:10 +0000301};
302
303//-------------------------------------------------------------------------
304// CommandObjectSettingsList -- List settable variables
305//-------------------------------------------------------------------------
306
Kate Stoneb9c1b512016-09-06 20:57:50 +0000307class CommandObjectSettingsList : public CommandObjectParsed {
Kate Stone7428a182016-07-14 22:03:10 +0000308public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000309 CommandObjectSettingsList(CommandInterpreter &interpreter)
310 : CommandObjectParsed(interpreter, "settings list",
311 "List and describe matching debugger settings. "
312 "Defaults to all listing all settings.",
313 nullptr) {
314 CommandArgumentEntry arg;
315 CommandArgumentData var_name_arg;
316 CommandArgumentData prefix_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000317
Kate Stoneb9c1b512016-09-06 20:57:50 +0000318 // Define the first variant of this arg.
319 var_name_arg.arg_type = eArgTypeSettingVariableName;
320 var_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000321
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 // Define the second variant of this arg.
323 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
324 prefix_name_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 arg.push_back(var_name_arg);
327 arg.push_back(prefix_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000328
Kate Stoneb9c1b512016-09-06 20:57:50 +0000329 // Push the data for the first argument into the m_arguments vector.
330 m_arguments.push_back(arg);
331 }
Jim Ingham5a988412012-06-08 21:56:10 +0000332
Kate Stoneb9c1b512016-09-06 20:57:50 +0000333 ~CommandObjectSettingsList() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000334
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000335 int HandleArgumentCompletion(
336 CompletionRequest &request,
337 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000338 CommandCompletions::InvokeCommonCompletionCallbacks(
339 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000340 request, nullptr);
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000341 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000342 }
Jim Ingham5a988412012-06-08 21:56:10 +0000343
344protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 bool DoExecute(Args &args, CommandReturnObject &result) override {
346 result.SetStatus(eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000347
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 const bool will_modify = false;
349 const size_t argc = args.GetArgumentCount();
350 if (argc > 0) {
351 const bool dump_qualified_name = true;
Jim Ingham5a988412012-06-08 21:56:10 +0000352
Zachary Turner97d2c402016-10-05 23:40:23 +0000353 // TODO: Convert to StringRef based enumeration. Requires converting
354 // GetPropertyAtPath first.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000355 for (size_t i = 0; i < argc; ++i) {
356 const char *property_path = args.GetArgumentAtIndex(i);
Greg Clayton67cc0632012-08-22 17:17:09 +0000357
Kate Stoneb9c1b512016-09-06 20:57:50 +0000358 const Property *property =
359 m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath(
360 &m_exe_ctx, will_modify, property_path);
361
362 if (property) {
363 property->DumpDescription(m_interpreter, result.GetOutputStream(), 0,
364 dump_qualified_name);
365 } else {
366 result.AppendErrorWithFormat("invalid property path '%s'",
367 property_path);
368 result.SetStatus(eReturnStatusFailed);
Jim Ingham5a988412012-06-08 21:56:10 +0000369 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000370 }
371 } else {
372 m_interpreter.GetDebugger().DumpAllDescriptions(m_interpreter,
373 result.GetOutputStream());
Jim Ingham5a988412012-06-08 21:56:10 +0000374 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000375
376 return result.Succeeded();
377 }
Jim Ingham5a988412012-06-08 21:56:10 +0000378};
379
380//-------------------------------------------------------------------------
381// CommandObjectSettingsRemove
382//-------------------------------------------------------------------------
383
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384class CommandObjectSettingsRemove : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000385public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386 CommandObjectSettingsRemove(CommandInterpreter &interpreter)
387 : CommandObjectRaw(interpreter, "settings remove",
388 "Remove a value from a setting, specified by array "
Zachary Turnera4496982016-10-05 21:14:38 +0000389 "index or dictionary key.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000390 CommandArgumentEntry arg1;
391 CommandArgumentEntry arg2;
392 CommandArgumentData var_name_arg;
393 CommandArgumentData index_arg;
394 CommandArgumentData key_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000395
Kate Stoneb9c1b512016-09-06 20:57:50 +0000396 // Define the first (and only) variant of this arg.
397 var_name_arg.arg_type = eArgTypeSettingVariableName;
398 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000399
Kate Stoneb9c1b512016-09-06 20:57:50 +0000400 // There is only one variant this argument could be; put it into the
401 // argument entry.
402 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000403
Kate Stoneb9c1b512016-09-06 20:57:50 +0000404 // Define the first variant of this arg.
405 index_arg.arg_type = eArgTypeSettingIndex;
406 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 // Define the second variant of this arg.
409 key_arg.arg_type = eArgTypeSettingKey;
410 key_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000411
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412 // Push both variants into this arg
413 arg2.push_back(index_arg);
414 arg2.push_back(key_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000415
Kate Stoneb9c1b512016-09-06 20:57:50 +0000416 // Push the data for the first argument into the m_arguments vector.
417 m_arguments.push_back(arg1);
418 m_arguments.push_back(arg2);
419 }
Jim Ingham5a988412012-06-08 21:56:10 +0000420
Kate Stoneb9c1b512016-09-06 20:57:50 +0000421 ~CommandObjectSettingsRemove() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000422
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000423 int HandleArgumentCompletion(
424 CompletionRequest &request,
425 OptionElementVector &opt_element_vector) override {
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000426 if (request.GetCursorIndex() < 2)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000427 CommandCompletions::InvokeCommonCompletionCallbacks(
428 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000429 request, nullptr);
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000430 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000431 }
Jim Ingham5a988412012-06-08 21:56:10 +0000432
433protected:
Raphael Isemann4d51a902018-07-12 22:28:52 +0000434 bool DoExecute(llvm::StringRef command,
435 CommandReturnObject &result) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000436 result.SetStatus(eReturnStatusSuccessFinishNoResult);
437
438 Args cmd_args(command);
439
440 // Process possible options.
441 if (!ParseOptions(cmd_args, result))
442 return false;
443
444 const size_t argc = cmd_args.GetArgumentCount();
445 if (argc == 0) {
446 result.AppendError("'settings set' takes an array or dictionary item, or "
447 "an array followed by one or more indexes, or a "
448 "dictionary followed by one or more key names to "
449 "remove");
450 result.SetStatus(eReturnStatusFailed);
451 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000452 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000453
454 const char *var_name = cmd_args.GetArgumentAtIndex(0);
455 if ((var_name == nullptr) || (var_name[0] == '\0')) {
456 result.AppendError(
457 "'settings set' command requires a valid variable name");
458 result.SetStatus(eReturnStatusFailed);
459 return false;
460 }
461
462 // Split the raw command into var_name and value pair.
463 llvm::StringRef raw_str(command);
464 std::string var_value_string = raw_str.split(var_name).second.str();
465 const char *var_value_cstr =
466 Args::StripSpaces(var_value_string, true, true, false);
467
Zachary Turner97206d52017-05-12 04:51:55 +0000468 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000469 &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr));
470 if (error.Fail()) {
471 result.AppendError(error.AsCString());
472 result.SetStatus(eReturnStatusFailed);
473 return false;
474 }
475
476 return result.Succeeded();
477 }
Jim Ingham5a988412012-06-08 21:56:10 +0000478};
479
480//-------------------------------------------------------------------------
481// CommandObjectSettingsReplace
482//-------------------------------------------------------------------------
483
Kate Stoneb9c1b512016-09-06 20:57:50 +0000484class CommandObjectSettingsReplace : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000485public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000486 CommandObjectSettingsReplace(CommandInterpreter &interpreter)
487 : CommandObjectRaw(interpreter, "settings replace",
488 "Replace the debugger setting value specified by "
Zachary Turnera4496982016-10-05 21:14:38 +0000489 "array index or dictionary key.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490 CommandArgumentEntry arg1;
491 CommandArgumentEntry arg2;
492 CommandArgumentEntry arg3;
493 CommandArgumentData var_name_arg;
494 CommandArgumentData index_arg;
495 CommandArgumentData key_arg;
496 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000497
Kate Stoneb9c1b512016-09-06 20:57:50 +0000498 // Define the first (and only) variant of this arg.
499 var_name_arg.arg_type = eArgTypeSettingVariableName;
500 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000501
Kate Stoneb9c1b512016-09-06 20:57:50 +0000502 // There is only one variant this argument could be; put it into the
503 // argument entry.
504 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000505
Kate Stoneb9c1b512016-09-06 20:57:50 +0000506 // Define the first (variant of this arg.
507 index_arg.arg_type = eArgTypeSettingIndex;
508 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000509
Kate Stoneb9c1b512016-09-06 20:57:50 +0000510 // Define the second (variant of this arg.
511 key_arg.arg_type = eArgTypeSettingKey;
512 key_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000513
Kate Stoneb9c1b512016-09-06 20:57:50 +0000514 // Put both variants into this arg
515 arg2.push_back(index_arg);
516 arg2.push_back(key_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000517
Kate Stoneb9c1b512016-09-06 20:57:50 +0000518 // Define the first (and only) variant of this arg.
519 value_arg.arg_type = eArgTypeValue;
520 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000521
Kate Stoneb9c1b512016-09-06 20:57:50 +0000522 // There is only one variant this argument could be; put it into the
523 // argument entry.
524 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000525
Kate Stoneb9c1b512016-09-06 20:57:50 +0000526 // Push the data for the first argument into the m_arguments vector.
527 m_arguments.push_back(arg1);
528 m_arguments.push_back(arg2);
529 m_arguments.push_back(arg3);
530 }
Jim Ingham5a988412012-06-08 21:56:10 +0000531
Kate Stoneb9c1b512016-09-06 20:57:50 +0000532 ~CommandObjectSettingsReplace() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000533
Kate Stoneb9c1b512016-09-06 20:57:50 +0000534 // Overrides base class's behavior where WantsCompletion =
535 // !WantsRawCommandString.
536 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000537
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000538 int HandleArgumentCompletion(
539 CompletionRequest &request,
540 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000541 // Attempting to complete variable name
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000542 if (request.GetCursorIndex() < 2)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000543 CommandCompletions::InvokeCommonCompletionCallbacks(
544 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000545 request, nullptr);
Jim Ingham5a988412012-06-08 21:56:10 +0000546
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000547 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000548 }
Jim Ingham5a988412012-06-08 21:56:10 +0000549
550protected:
Raphael Isemann4d51a902018-07-12 22:28:52 +0000551 bool DoExecute(llvm::StringRef command,
552 CommandReturnObject &result) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000553 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000554
Kate Stoneb9c1b512016-09-06 20:57:50 +0000555 Args cmd_args(command);
556 const char *var_name = cmd_args.GetArgumentAtIndex(0);
557 if ((var_name == nullptr) || (var_name[0] == '\0')) {
558 result.AppendError("'settings replace' command requires a valid variable "
559 "name; No value supplied");
560 result.SetStatus(eReturnStatusFailed);
561 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000562 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000563
564 // Split the raw command into var_name, index_value, and value triple.
565 llvm::StringRef raw_str(command);
566 std::string var_value_string = raw_str.split(var_name).second.str();
567 const char *var_value_cstr =
568 Args::StripSpaces(var_value_string, true, true, false);
569
Zachary Turner97206d52017-05-12 04:51:55 +0000570 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000571 &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr));
572 if (error.Fail()) {
573 result.AppendError(error.AsCString());
574 result.SetStatus(eReturnStatusFailed);
575 return false;
576 } else {
577 result.SetStatus(eReturnStatusSuccessFinishNoResult);
578 }
579
580 return result.Succeeded();
581 }
Jim Ingham5a988412012-06-08 21:56:10 +0000582};
583
584//-------------------------------------------------------------------------
585// CommandObjectSettingsInsertBefore
586//-------------------------------------------------------------------------
587
Kate Stoneb9c1b512016-09-06 20:57:50 +0000588class CommandObjectSettingsInsertBefore : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000589public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000590 CommandObjectSettingsInsertBefore(CommandInterpreter &interpreter)
591 : CommandObjectRaw(interpreter, "settings insert-before",
592 "Insert one or more values into an debugger array "
593 "setting immediately before the specified element "
Zachary Turnera4496982016-10-05 21:14:38 +0000594 "index.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000595 CommandArgumentEntry arg1;
596 CommandArgumentEntry arg2;
597 CommandArgumentEntry arg3;
598 CommandArgumentData var_name_arg;
599 CommandArgumentData index_arg;
600 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000601
Kate Stoneb9c1b512016-09-06 20:57:50 +0000602 // Define the first (and only) variant of this arg.
603 var_name_arg.arg_type = eArgTypeSettingVariableName;
604 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000605
Kate Stoneb9c1b512016-09-06 20:57:50 +0000606 // There is only one variant this argument could be; put it into the
607 // argument entry.
608 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000609
Kate Stoneb9c1b512016-09-06 20:57:50 +0000610 // Define the first (variant of this arg.
611 index_arg.arg_type = eArgTypeSettingIndex;
612 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000613
Kate Stoneb9c1b512016-09-06 20:57:50 +0000614 // There is only one variant this argument could be; put it into the
615 // argument entry.
616 arg2.push_back(index_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000617
Kate Stoneb9c1b512016-09-06 20:57:50 +0000618 // Define the first (and only) variant of this arg.
619 value_arg.arg_type = eArgTypeValue;
620 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000621
Kate Stoneb9c1b512016-09-06 20:57:50 +0000622 // There is only one variant this argument could be; put it into the
623 // argument entry.
624 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000625
Kate Stoneb9c1b512016-09-06 20:57:50 +0000626 // Push the data for the first argument into the m_arguments vector.
627 m_arguments.push_back(arg1);
628 m_arguments.push_back(arg2);
629 m_arguments.push_back(arg3);
630 }
Jim Ingham5a988412012-06-08 21:56:10 +0000631
Kate Stoneb9c1b512016-09-06 20:57:50 +0000632 ~CommandObjectSettingsInsertBefore() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000633
Kate Stoneb9c1b512016-09-06 20:57:50 +0000634 // Overrides base class's behavior where WantsCompletion =
635 // !WantsRawCommandString.
636 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000637
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000638 int HandleArgumentCompletion(
639 CompletionRequest &request,
640 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000641 // Attempting to complete variable name
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000642 if (request.GetCursorIndex() < 2)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000643 CommandCompletions::InvokeCommonCompletionCallbacks(
644 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000645 request, nullptr);
Jim Ingham5a988412012-06-08 21:56:10 +0000646
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000647 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000648 }
Jim Ingham5a988412012-06-08 21:56:10 +0000649
650protected:
Raphael Isemann4d51a902018-07-12 22:28:52 +0000651 bool DoExecute(llvm::StringRef command,
652 CommandReturnObject &result) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000653 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000654
Kate Stoneb9c1b512016-09-06 20:57:50 +0000655 Args cmd_args(command);
656 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000657
Kate Stoneb9c1b512016-09-06 20:57:50 +0000658 if (argc < 3) {
659 result.AppendError("'settings insert-before' takes more arguments");
660 result.SetStatus(eReturnStatusFailed);
661 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000662 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000663
664 const char *var_name = cmd_args.GetArgumentAtIndex(0);
665 if ((var_name == nullptr) || (var_name[0] == '\0')) {
666 result.AppendError("'settings insert-before' command requires a valid "
667 "variable name; No value supplied");
668 result.SetStatus(eReturnStatusFailed);
669 return false;
670 }
671
672 // Split the raw command into var_name, index_value, and value triple.
673 llvm::StringRef raw_str(command);
674 std::string var_value_string = raw_str.split(var_name).second.str();
675 const char *var_value_cstr =
676 Args::StripSpaces(var_value_string, true, true, false);
677
Zachary Turner97206d52017-05-12 04:51:55 +0000678 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000679 &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr));
680 if (error.Fail()) {
681 result.AppendError(error.AsCString());
682 result.SetStatus(eReturnStatusFailed);
683 return false;
684 }
685
686 return result.Succeeded();
687 }
Jim Ingham5a988412012-06-08 21:56:10 +0000688};
689
690//-------------------------------------------------------------------------
691// CommandObjectSettingInsertAfter
692//-------------------------------------------------------------------------
693
Kate Stoneb9c1b512016-09-06 20:57:50 +0000694class CommandObjectSettingsInsertAfter : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000695public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000696 CommandObjectSettingsInsertAfter(CommandInterpreter &interpreter)
697 : CommandObjectRaw(interpreter, "settings insert-after",
698 "Insert one or more values into a debugger array "
Zachary Turnera4496982016-10-05 21:14:38 +0000699 "settings after the specified element index.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000700 CommandArgumentEntry arg1;
701 CommandArgumentEntry arg2;
702 CommandArgumentEntry arg3;
703 CommandArgumentData var_name_arg;
704 CommandArgumentData index_arg;
705 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000706
Kate Stoneb9c1b512016-09-06 20:57:50 +0000707 // Define the first (and only) variant of this arg.
708 var_name_arg.arg_type = eArgTypeSettingVariableName;
709 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000710
Kate Stoneb9c1b512016-09-06 20:57:50 +0000711 // There is only one variant this argument could be; put it into the
712 // argument entry.
713 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000714
Kate Stoneb9c1b512016-09-06 20:57:50 +0000715 // Define the first (variant of this arg.
716 index_arg.arg_type = eArgTypeSettingIndex;
717 index_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000718
Kate Stoneb9c1b512016-09-06 20:57:50 +0000719 // There is only one variant this argument could be; put it into the
720 // argument entry.
721 arg2.push_back(index_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000722
Kate Stoneb9c1b512016-09-06 20:57:50 +0000723 // Define the first (and only) variant of this arg.
724 value_arg.arg_type = eArgTypeValue;
725 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000726
Kate Stoneb9c1b512016-09-06 20:57:50 +0000727 // There is only one variant this argument could be; put it into the
728 // argument entry.
729 arg3.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000730
Kate Stoneb9c1b512016-09-06 20:57:50 +0000731 // Push the data for the first argument into the m_arguments vector.
732 m_arguments.push_back(arg1);
733 m_arguments.push_back(arg2);
734 m_arguments.push_back(arg3);
735 }
Jim Ingham5a988412012-06-08 21:56:10 +0000736
Kate Stoneb9c1b512016-09-06 20:57:50 +0000737 ~CommandObjectSettingsInsertAfter() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000738
Kate Stoneb9c1b512016-09-06 20:57:50 +0000739 // Overrides base class's behavior where WantsCompletion =
740 // !WantsRawCommandString.
741 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000742
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000743 int HandleArgumentCompletion(
744 CompletionRequest &request,
745 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000746 // Attempting to complete variable name
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000747 if (request.GetCursorIndex() < 2)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000748 CommandCompletions::InvokeCommonCompletionCallbacks(
749 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000750 request, nullptr);
Jim Ingham5a988412012-06-08 21:56:10 +0000751
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000752 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000753 }
754
Jim Ingham5a988412012-06-08 21:56:10 +0000755protected:
Raphael Isemann4d51a902018-07-12 22:28:52 +0000756 bool DoExecute(llvm::StringRef command,
757 CommandReturnObject &result) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000758 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000759
Kate Stoneb9c1b512016-09-06 20:57:50 +0000760 Args cmd_args(command);
761 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000762
Kate Stoneb9c1b512016-09-06 20:57:50 +0000763 if (argc < 3) {
764 result.AppendError("'settings insert-after' takes more arguments");
765 result.SetStatus(eReturnStatusFailed);
766 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000767 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000768
769 const char *var_name = cmd_args.GetArgumentAtIndex(0);
770 if ((var_name == nullptr) || (var_name[0] == '\0')) {
771 result.AppendError("'settings insert-after' command requires a valid "
772 "variable name; No value supplied");
773 result.SetStatus(eReturnStatusFailed);
774 return false;
775 }
776
777 // Split the raw command into var_name, index_value, and value triple.
778 llvm::StringRef raw_str(command);
779 std::string var_value_string = raw_str.split(var_name).second.str();
780 const char *var_value_cstr =
781 Args::StripSpaces(var_value_string, true, true, false);
782
Zachary Turner97206d52017-05-12 04:51:55 +0000783 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000784 &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr));
785 if (error.Fail()) {
786 result.AppendError(error.AsCString());
787 result.SetStatus(eReturnStatusFailed);
788 return false;
789 }
790
791 return result.Succeeded();
792 }
Jim Ingham5a988412012-06-08 21:56:10 +0000793};
794
795//-------------------------------------------------------------------------
796// CommandObjectSettingsAppend
797//-------------------------------------------------------------------------
798
Kate Stoneb9c1b512016-09-06 20:57:50 +0000799class CommandObjectSettingsAppend : public CommandObjectRaw {
Jim Ingham5a988412012-06-08 21:56:10 +0000800public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000801 CommandObjectSettingsAppend(CommandInterpreter &interpreter)
802 : CommandObjectRaw(interpreter, "settings append",
803 "Append one or more values to a debugger array, "
Zachary Turnera4496982016-10-05 21:14:38 +0000804 "dictionary, or string setting.") {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000805 CommandArgumentEntry arg1;
806 CommandArgumentEntry arg2;
807 CommandArgumentData var_name_arg;
808 CommandArgumentData value_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000809
Kate Stoneb9c1b512016-09-06 20:57:50 +0000810 // Define the first (and only) variant of this arg.
811 var_name_arg.arg_type = eArgTypeSettingVariableName;
812 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000813
Kate Stoneb9c1b512016-09-06 20:57:50 +0000814 // There is only one variant this argument could be; put it into the
815 // argument entry.
816 arg1.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000817
Kate Stoneb9c1b512016-09-06 20:57:50 +0000818 // Define the first (and only) variant of this arg.
819 value_arg.arg_type = eArgTypeValue;
820 value_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000821
Kate Stoneb9c1b512016-09-06 20:57:50 +0000822 // There is only one variant this argument could be; put it into the
823 // argument entry.
824 arg2.push_back(value_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000825
Kate Stoneb9c1b512016-09-06 20:57:50 +0000826 // Push the data for the first argument into the m_arguments vector.
827 m_arguments.push_back(arg1);
828 m_arguments.push_back(arg2);
829 }
Jim Ingham5a988412012-06-08 21:56:10 +0000830
Kate Stoneb9c1b512016-09-06 20:57:50 +0000831 ~CommandObjectSettingsAppend() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000832
Kate Stoneb9c1b512016-09-06 20:57:50 +0000833 // Overrides base class's behavior where WantsCompletion =
834 // !WantsRawCommandString.
835 bool WantsCompletion() override { return true; }
Jim Ingham5a988412012-06-08 21:56:10 +0000836
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000837 int HandleArgumentCompletion(
838 CompletionRequest &request,
839 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000840 // Attempting to complete variable name
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000841 if (request.GetCursorIndex() < 2)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000842 CommandCompletions::InvokeCommonCompletionCallbacks(
843 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000844 request, nullptr);
Jim Ingham5a988412012-06-08 21:56:10 +0000845
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000846 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000847 }
Jim Ingham5a988412012-06-08 21:56:10 +0000848
849protected:
Raphael Isemann4d51a902018-07-12 22:28:52 +0000850 bool DoExecute(llvm::StringRef command,
851 CommandReturnObject &result) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000852 result.SetStatus(eReturnStatusSuccessFinishNoResult);
853 Args cmd_args(command);
854 const size_t argc = cmd_args.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000855
Kate Stoneb9c1b512016-09-06 20:57:50 +0000856 if (argc < 2) {
857 result.AppendError("'settings append' takes more arguments");
858 result.SetStatus(eReturnStatusFailed);
859 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000860 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000861
862 const char *var_name = cmd_args.GetArgumentAtIndex(0);
863 if ((var_name == nullptr) || (var_name[0] == '\0')) {
864 result.AppendError("'settings append' command requires a valid variable "
865 "name; No value supplied");
866 result.SetStatus(eReturnStatusFailed);
867 return false;
868 }
869
Adrian Prantl05097242018-04-30 16:49:04 +0000870 // Do not perform cmd_args.Shift() since StringRef is manipulating the raw
871 // character string later on.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000872
873 // Split the raw command into var_name and value pair.
874 llvm::StringRef raw_str(command);
875 std::string var_value_string = raw_str.split(var_name).second.str();
876 const char *var_value_cstr =
877 Args::StripSpaces(var_value_string, true, true, false);
878
Zachary Turner97206d52017-05-12 04:51:55 +0000879 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000880 &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr));
881 if (error.Fail()) {
882 result.AppendError(error.AsCString());
883 result.SetStatus(eReturnStatusFailed);
884 return false;
885 }
886
887 return result.Succeeded();
888 }
Jim Ingham5a988412012-06-08 21:56:10 +0000889};
890
891//-------------------------------------------------------------------------
892// CommandObjectSettingsClear
893//-------------------------------------------------------------------------
894
Kate Stoneb9c1b512016-09-06 20:57:50 +0000895class CommandObjectSettingsClear : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000896public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000897 CommandObjectSettingsClear(CommandInterpreter &interpreter)
898 : CommandObjectParsed(
899 interpreter, "settings clear",
900 "Clear a debugger setting array, dictionary, or string.", nullptr) {
901 CommandArgumentEntry arg;
902 CommandArgumentData var_name_arg;
Jim Ingham5a988412012-06-08 21:56:10 +0000903
Kate Stoneb9c1b512016-09-06 20:57:50 +0000904 // Define the first (and only) variant of this arg.
905 var_name_arg.arg_type = eArgTypeSettingVariableName;
906 var_name_arg.arg_repetition = eArgRepeatPlain;
Jim Ingham5a988412012-06-08 21:56:10 +0000907
Kate Stoneb9c1b512016-09-06 20:57:50 +0000908 // There is only one variant this argument could be; put it into the
909 // argument entry.
910 arg.push_back(var_name_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000911
Kate Stoneb9c1b512016-09-06 20:57:50 +0000912 // Push the data for the first argument into the m_arguments vector.
913 m_arguments.push_back(arg);
914 }
Jim Ingham5a988412012-06-08 21:56:10 +0000915
Kate Stoneb9c1b512016-09-06 20:57:50 +0000916 ~CommandObjectSettingsClear() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000917
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000918 int HandleArgumentCompletion(
919 CompletionRequest &request,
920 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000921 // Attempting to complete variable name
Raphael Isemann2443bbd2018-07-02 21:29:56 +0000922 if (request.GetCursorIndex() < 2)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000923 CommandCompletions::InvokeCommonCompletionCallbacks(
924 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000925 request, nullptr);
Jim Ingham5a988412012-06-08 21:56:10 +0000926
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000927 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000928 }
Jim Ingham5a988412012-06-08 21:56:10 +0000929
930protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000931 bool DoExecute(Args &command, CommandReturnObject &result) override {
932 result.SetStatus(eReturnStatusSuccessFinishNoResult);
933 const size_t argc = command.GetArgumentCount();
Jim Ingham5a988412012-06-08 21:56:10 +0000934
Kate Stoneb9c1b512016-09-06 20:57:50 +0000935 if (argc != 1) {
936 result.AppendError("'settings clear' takes exactly one argument");
937 result.SetStatus(eReturnStatusFailed);
938 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000939 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000940
941 const char *var_name = command.GetArgumentAtIndex(0);
942 if ((var_name == nullptr) || (var_name[0] == '\0')) {
943 result.AppendError("'settings clear' command requires a valid variable "
944 "name; No value supplied");
945 result.SetStatus(eReturnStatusFailed);
946 return false;
947 }
948
Zachary Turner97206d52017-05-12 04:51:55 +0000949 Status error(m_interpreter.GetDebugger().SetPropertyValue(
Zachary Turner31d97a52016-11-17 18:08:12 +0000950 &m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef()));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000951 if (error.Fail()) {
952 result.AppendError(error.AsCString());
953 result.SetStatus(eReturnStatusFailed);
954 return false;
955 }
956
957 return result.Succeeded();
958 }
Jim Ingham5a988412012-06-08 21:56:10 +0000959};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960
961//-------------------------------------------------------------------------
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000962// CommandObjectMultiwordSettings
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000963//-------------------------------------------------------------------------
964
Kate Stoneb9c1b512016-09-06 20:57:50 +0000965CommandObjectMultiwordSettings::CommandObjectMultiwordSettings(
966 CommandInterpreter &interpreter)
967 : CommandObjectMultiword(interpreter, "settings",
968 "Commands for managing LLDB settings.",
969 "settings <subcommand> [<command-options>]") {
970 LoadSubCommand("set",
971 CommandObjectSP(new CommandObjectSettingsSet(interpreter)));
972 LoadSubCommand("show",
973 CommandObjectSP(new CommandObjectSettingsShow(interpreter)));
974 LoadSubCommand("list",
975 CommandObjectSP(new CommandObjectSettingsList(interpreter)));
976 LoadSubCommand("remove",
977 CommandObjectSP(new CommandObjectSettingsRemove(interpreter)));
978 LoadSubCommand("replace", CommandObjectSP(
979 new CommandObjectSettingsReplace(interpreter)));
980 LoadSubCommand(
981 "insert-before",
982 CommandObjectSP(new CommandObjectSettingsInsertBefore(interpreter)));
983 LoadSubCommand(
984 "insert-after",
985 CommandObjectSP(new CommandObjectSettingsInsertAfter(interpreter)));
986 LoadSubCommand("append",
987 CommandObjectSP(new CommandObjectSettingsAppend(interpreter)));
988 LoadSubCommand("clear",
989 CommandObjectSP(new CommandObjectSettingsClear(interpreter)));
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000990}
991
Eugene Zelenko3f18ea02016-02-24 02:05:55 +0000992CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings() = default;