blob: b5e328b789c528c639de5238f5bdf3c75b635432 [file] [log] [blame]
Chris Lattner24943d22010-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
15// Project includes
16#include "lldb/Interpreter/CommandInterpreter.h"
17#include "lldb/Interpreter/CommandReturnObject.h"
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000018#include "lldb/Interpreter/CommandCompletions.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019
20using namespace lldb;
21using namespace lldb_private;
22
23//-------------------------------------------------------------------------
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000024// CommandObjectMultiwordSettings
Chris Lattner24943d22010-06-08 16:52:24 +000025//-------------------------------------------------------------------------
26
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000027CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +000028 CommandObjectMultiword (interpreter,
29 "settings",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000030 "A set of commands for manipulating internal settable debugger variables.",
31 "settings <command> [<command-options>]")
32{
Greg Clayton41c56fa2011-04-19 22:32:36 +000033 LoadSubCommand ("set", CommandObjectSP (new CommandObjectSettingsSet (interpreter)));
34 LoadSubCommand ("show", CommandObjectSP (new CommandObjectSettingsShow (interpreter)));
35 LoadSubCommand ("list", CommandObjectSP (new CommandObjectSettingsList (interpreter)));
36 LoadSubCommand ("remove", CommandObjectSP (new CommandObjectSettingsRemove (interpreter)));
37 LoadSubCommand ("replace", CommandObjectSP (new CommandObjectSettingsReplace (interpreter)));
38 LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter)));
39 LoadSubCommand ("insert-after", CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter)));
40 LoadSubCommand ("append", CommandObjectSP (new CommandObjectSettingsAppend (interpreter)));
41 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectSettingsClear (interpreter)));
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000042}
43
44CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
Chris Lattner24943d22010-06-08 16:52:24 +000045{
46}
47
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000048//-------------------------------------------------------------------------
49// CommandObjectSettingsSet
50//-------------------------------------------------------------------------
51
Greg Clayton238c0a12010-09-18 01:14:36 +000052CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpreter) :
53 CommandObject (interpreter,
54 "settings set",
Caroline Ticeabb507a2010-09-08 21:06:11 +000055 "Set or change the value of a single debugger setting variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +000056 NULL),
Greg Claytonf15996e2011-04-07 22:46:35 +000057 m_options (interpreter)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000058{
Caroline Tice43b014a2010-10-04 22:28:36 +000059 CommandArgumentEntry arg1;
60 CommandArgumentEntry arg2;
61 CommandArgumentData var_name_arg;
62 CommandArgumentData value_arg;
63
64 // Define the first (and only) variant of this arg.
65 var_name_arg.arg_type = eArgTypeSettingVariableName;
66 var_name_arg.arg_repetition = eArgRepeatPlain;
67
68 // There is only one variant this argument could be; put it into the argument entry.
69 arg1.push_back (var_name_arg);
70
71 // Define the first (and only) variant of this arg.
72 value_arg.arg_type = eArgTypeValue;
73 value_arg.arg_repetition = eArgRepeatPlain;
74
75 // There is only one variant this argument could be; put it into the argument entry.
76 arg2.push_back (value_arg);
77
78 // Push the data for the first argument into the m_arguments vector.
79 m_arguments.push_back (arg1);
80 m_arguments.push_back (arg2);
Caroline Ticed9105c22010-12-10 00:26:54 +000081
82 SetHelpLong (
83"When setting a dictionary or array variable, you can set multiple entries \n\
84at once by giving the values to the set command. For example: \n\
85\n\
Greg Claytonabb33022011-11-08 02:43:13 +000086(lldb) settings set target.run-args value1 value2 value3 \n\
87(lldb) settings set target.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\
Caroline Ticed9105c22010-12-10 00:26:54 +000088\n\
Greg Claytonabb33022011-11-08 02:43:13 +000089(lldb) settings show target.run-args \n\
Caroline Ticed9105c22010-12-10 00:26:54 +000090 [0]: 'value1' \n\
91 [1]: 'value2' \n\
92 [3]: 'value3' \n\
Greg Claytonabb33022011-11-08 02:43:13 +000093(lldb) settings show target.env-vars \n\
Caroline Ticed9105c22010-12-10 00:26:54 +000094 'MYPATH=~/.:/usr/bin'\n\
95 'SOME_ENV_VAR=12345' \n\
96\n\
97Note the special syntax for setting a dictionary element: [\"<key>\"]=<value> \n\
98\n\
99Warning: The 'set' command re-sets the entire array or dictionary. If you \n\
100just want to add, remove or update individual values (or add something to \n\
101the end), use one of the other settings sub-commands: append, replace, \n\
102insert-before or insert-after.\n");
103
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000104}
105
106CommandObjectSettingsSet::~CommandObjectSettingsSet()
Chris Lattner24943d22010-06-08 16:52:24 +0000107{
108}
109
110
Johnny Chena1b0ce12012-01-19 19:22:41 +0000111#include "llvm/ADT/StringRef.h"
112static inline void StripLeadingSpaces(llvm::StringRef &Str)
113{
114 while (!Str.empty() && isspace(Str[0]))
115 Str = Str.substr(1);
116}
Chris Lattner24943d22010-06-08 16:52:24 +0000117bool
Johnny Chena1b0ce12012-01-19 19:22:41 +0000118CommandObjectSettingsSet::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000119{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000120 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Chris Lattner24943d22010-06-08 16:52:24 +0000121
Johnny Chena1b0ce12012-01-19 19:22:41 +0000122 Args cmd_args(raw_command);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000123
Johnny Chena1b0ce12012-01-19 19:22:41 +0000124 // Process possible options.
125 if (!ParseOptions (cmd_args, result))
126 return false;
127
128 const int argc = cmd_args.GetArgumentCount ();
Caroline Tice87097232010-09-07 18:35:40 +0000129 if ((argc < 2) && (!m_options.m_reset))
Chris Lattner24943d22010-06-08 16:52:24 +0000130 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000131 result.AppendError ("'settings set' takes more arguments");
132 result.SetStatus (eReturnStatusFailed);
133 return false;
134 }
135
Johnny Chena1b0ce12012-01-19 19:22:41 +0000136 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000137 if ((var_name == NULL) || (var_name[0] == '\0'))
138 {
139 result.AppendError ("'settings set' command requires a valid variable name; No value supplied");
140 result.SetStatus (eReturnStatusFailed);
141 return false;
142 }
143
Johnny Chena1b0ce12012-01-19 19:22:41 +0000144 // Split the raw command into var_name and value pair.
145 std::string var_name_string = var_name;
146 llvm::StringRef raw_str(raw_command);
147 llvm::StringRef value_str = raw_str.split(var_name_string).second;
148 StripLeadingSpaces(value_str);
149 std::string value_string = value_str.str();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000150
151 if (!m_options.m_reset
Johnny Chena1b0ce12012-01-19 19:22:41 +0000152 && value_string.empty())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000153 {
154 result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;"
155 " No value supplied");
Chris Lattner24943d22010-06-08 16:52:24 +0000156 result.SetStatus (eReturnStatusFailed);
157 }
158 else
159 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000160 Error err = usc_sp->SetVariable (var_name_string.c_str(),
Johnny Chena1b0ce12012-01-19 19:22:41 +0000161 value_string.c_str(),
Greg Clayton41c56fa2011-04-19 22:32:36 +0000162 eVarSetOperationAssign,
163 m_options.m_override,
164 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000165 if (err.Fail ())
166 {
167 result.AppendError (err.AsCString());
168 result.SetStatus (eReturnStatusFailed);
169 }
170 else
171 result.SetStatus (eReturnStatusSuccessFinishNoResult);
172 }
173
174 return result.Succeeded();
175}
176
177int
Greg Clayton238c0a12010-09-18 01:14:36 +0000178CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000179 int &cursor_index,
180 int &cursor_char_position,
181 OptionElementVector &opt_element_vector,
182 int match_start_point,
183 int max_return_elements,
184 bool &word_complete,
185 StringList &matches)
186{
187 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
188 completion_str.erase (cursor_char_position);
189
190 // Attempting to complete variable name
Johnny Chenfbcad682012-01-20 23:02:51 +0000191 llvm::StringRef prev_str(cursor_index == 2 ? input.GetArgumentAtIndex(1) : "");
192 if (cursor_index == 1 ||
193 (cursor_index == 2 && prev_str.startswith("-")) // "settings set -r th", followed by Tab.
194 )
195 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000196 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000197 CommandCompletions::eSettingsNameCompletion,
198 completion_str.c_str(),
199 match_start_point,
200 max_return_elements,
201 NULL,
202 word_complete,
203 matches);
Johnny Chenfbcad682012-01-20 23:02:51 +0000204 // If there is only 1 match which fulfills the completion request, do an early return.
205 if (matches.GetSize() == 1 && completion_str.compare(matches.GetStringAtIndex(0)) != 0)
206 return 1;
207 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000208
209 // Attempting to complete value
210 if ((cursor_index == 2) // Partly into the variable's value
211 || (cursor_index == 1 // Or at the end of a completed valid variable name
212 && matches.GetSize() == 1
213 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
214 {
215 matches.Clear();
Greg Clayton41c56fa2011-04-19 22:32:36 +0000216 UserSettingsControllerSP usc_sp = Debugger::GetSettingsController();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000217 if (cursor_index == 1)
218 {
219 // The user is at the end of the variable name, which is complete and valid.
Greg Clayton41c56fa2011-04-19 22:32:36 +0000220 UserSettingsController::CompleteSettingsValue (usc_sp,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000221 input.GetArgumentAtIndex (1), // variable name
222 NULL, // empty value string
223 word_complete,
224 matches);
225 }
226 else
227 {
228 // The user is partly into the variable value.
Greg Clayton41c56fa2011-04-19 22:32:36 +0000229 UserSettingsController::CompleteSettingsValue (usc_sp,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000230 input.GetArgumentAtIndex (1), // variable name
231 completion_str.c_str(), // partial value string
232 word_complete,
233 matches);
234 }
235 }
236
237 return matches.GetSize();
238}
239
240//-------------------------------------------------------------------------
241// CommandObjectSettingsSet::CommandOptions
242//-------------------------------------------------------------------------
243
Greg Claytonf15996e2011-04-07 22:46:35 +0000244CommandObjectSettingsSet::CommandOptions::CommandOptions (CommandInterpreter &interpreter) :
245 Options (interpreter),
Caroline Tice1ebef442010-09-27 00:30:10 +0000246 m_override (true),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000247 m_reset (false)
248{
249}
250
251CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
252{
253}
254
Greg Claytonb3448432011-03-24 21:19:54 +0000255OptionDefinition
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000256CommandObjectSettingsSet::CommandOptions::g_option_table[] =
257{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000258 { LLDB_OPT_SET_1, false, "no-override", 'n', no_argument, NULL, NULL, eArgTypeNone, "Prevents already existing instances and pending settings from being assigned this new value. Using this option means that only the default or specified instance setting values will be updated." },
259 { LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, eArgTypeNone, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." },
260 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000261};
262
Greg Claytonb3448432011-03-24 21:19:54 +0000263const OptionDefinition*
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000264CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
265{
266 return g_option_table;
267}
268
269Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000270CommandObjectSettingsSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000271{
272 Error error;
273 char short_option = (char) m_getopt_table[option_idx].val;
274
275 switch (short_option)
276 {
Caroline Tice1ebef442010-09-27 00:30:10 +0000277 case 'n':
278 m_override = false;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000279 break;
280 case 'r':
281 m_reset = true;
282 break;
283 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000284 error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000285 break;
286 }
287
288 return error;
289}
290
291void
Greg Clayton143fcc32011-04-13 00:18:08 +0000292CommandObjectSettingsSet::CommandOptions::OptionParsingStarting ()
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000293{
Caroline Tice1ebef442010-09-27 00:30:10 +0000294 m_override = true;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000295 m_reset = false;
296}
297
298Options *
299CommandObjectSettingsSet::GetOptions ()
300{
301 return &m_options;
302}
303
304
305//-------------------------------------------------------------------------
306// CommandObjectSettingsShow -- Show current values
307//-------------------------------------------------------------------------
308
Greg Clayton238c0a12010-09-18 01:14:36 +0000309CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
310 CommandObject (interpreter,
311 "settings show",
312 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000313 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000314{
Caroline Tice43b014a2010-10-04 22:28:36 +0000315 CommandArgumentEntry arg1;
316 CommandArgumentData var_name_arg;
317
318 // Define the first (and only) variant of this arg.
319 var_name_arg.arg_type = eArgTypeSettingVariableName;
320 var_name_arg.arg_repetition = eArgRepeatOptional;
321
322 // There is only one variant this argument could be; put it into the argument entry.
323 arg1.push_back (var_name_arg);
324
325 // Push the data for the first argument into the m_arguments vector.
326 m_arguments.push_back (arg1);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000327}
328
329CommandObjectSettingsShow::~CommandObjectSettingsShow()
330{
331}
332
333
334bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000335CommandObjectSettingsShow::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000336{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000337 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
338 const char *current_prefix = usc_sp->GetLevelName().GetCString();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000339
340 Error err;
341
342 if (command.GetArgumentCount())
343 {
344 // The user requested to see the value of a particular variable.
Greg Claytonb3448432011-03-24 21:19:54 +0000345 SettableVariableType var_type;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000346 const char *variable_name = command.GetArgumentAtIndex (0);
Greg Clayton41c56fa2011-04-19 22:32:36 +0000347 StringList value = usc_sp->GetVariable (variable_name,
348 var_type,
349 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
350 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000351
Caroline Tice5bc8c972010-09-20 20:44:43 +0000352 if (err.Fail ())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000353 {
Caroline Tice5bc8c972010-09-20 20:44:43 +0000354 result.AppendError (err.AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000355 result.SetStatus (eReturnStatusFailed);
356
Greg Clayton41c56fa2011-04-19 22:32:36 +0000357 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000358 else
359 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000360 UserSettingsController::DumpValue(m_interpreter, usc_sp, variable_name, result.GetOutputStream());
361 result.SetStatus (eReturnStatusSuccessFinishResult);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000362 }
363 }
364 else
365 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000366 UserSettingsController::GetAllVariableValues (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000367 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000368 current_prefix,
369 result.GetOutputStream(),
370 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000371 if (err.Fail ())
372 {
373 result.AppendError (err.AsCString());
374 result.SetStatus (eReturnStatusFailed);
375 }
376 else
377 {
378 result.SetStatus (eReturnStatusSuccessFinishNoResult);
379 }
380 }
381
382 return result.Succeeded();
383}
384
385int
Greg Clayton238c0a12010-09-18 01:14:36 +0000386CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000387 int &cursor_index,
388 int &cursor_char_position,
389 OptionElementVector &opt_element_vector,
390 int match_start_point,
391 int max_return_elements,
392 bool &word_complete,
393 StringList &matches)
394{
395 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
396 completion_str.erase (cursor_char_position);
397
Greg Clayton238c0a12010-09-18 01:14:36 +0000398 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000399 CommandCompletions::eSettingsNameCompletion,
400 completion_str.c_str(),
401 match_start_point,
402 max_return_elements,
403 NULL,
404 word_complete,
405 matches);
406 return matches.GetSize();
407}
408
409//-------------------------------------------------------------------------
410// CommandObjectSettingsList
411//-------------------------------------------------------------------------
412
Greg Clayton238c0a12010-09-18 01:14:36 +0000413CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
414 CommandObject (interpreter,
415 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000416 "List and describe all the internal debugger settings variables that are available to the user to 'set' or 'show', or describe a particular variable or set of variables (by specifying the variable name or a common prefix).",
Caroline Tice43b014a2010-10-04 22:28:36 +0000417 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000418{
Caroline Tice43b014a2010-10-04 22:28:36 +0000419 CommandArgumentEntry arg;
420 CommandArgumentData var_name_arg;
421 CommandArgumentData prefix_name_arg;
422
423 // Define the first variant of this arg.
424 var_name_arg.arg_type = eArgTypeSettingVariableName;
425 var_name_arg.arg_repetition = eArgRepeatOptional;
426
427 // Define the second variant of this arg.
428 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
429 prefix_name_arg.arg_repetition = eArgRepeatOptional;
430
431 arg.push_back (var_name_arg);
432 arg.push_back (prefix_name_arg);
433
434 // Push the data for the first argument into the m_arguments vector.
435 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000436}
437
438CommandObjectSettingsList::~CommandObjectSettingsList()
439{
440}
441
442
443bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000444CommandObjectSettingsList::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000445{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000446 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
447 const char *current_prefix = usc_sp->GetLevelName().GetCString();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000448
449 Error err;
450
Caroline Tice41ae2172010-09-15 06:56:39 +0000451 if (command.GetArgumentCount() == 0)
452 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000453 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000454 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000455 current_prefix,
456 result.GetOutputStream(),
457 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000458 }
459 else if (command.GetArgumentCount() == 1)
460 {
461 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000462 UserSettingsController::FindSettingsDescriptions (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000463 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000464 current_prefix,
465 search_name,
466 result.GetOutputStream(),
467 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000468 }
469 else
470 {
471 result.AppendError ("Too many aguments for 'settings list' command.\n");
472 result.SetStatus (eReturnStatusFailed);
473 return false;
474 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000475
476 if (err.Fail ())
477 {
478 result.AppendError (err.AsCString());
479 result.SetStatus (eReturnStatusFailed);
480 }
481 else
482 {
Chris Lattner24943d22010-06-08 16:52:24 +0000483 result.SetStatus (eReturnStatusSuccessFinishNoResult);
484 }
485
486 return result.Succeeded();
487}
488
Caroline Tice41ae2172010-09-15 06:56:39 +0000489int
Greg Clayton238c0a12010-09-18 01:14:36 +0000490CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000491 int &cursor_index,
492 int &cursor_char_position,
493 OptionElementVector &opt_element_vector,
494 int match_start_point,
495 int max_return_elements,
496 bool &word_complete,
497 StringList &matches)
498{
499 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
500 completion_str.erase (cursor_char_position);
501
Greg Clayton238c0a12010-09-18 01:14:36 +0000502 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000503 CommandCompletions::eSettingsNameCompletion,
504 completion_str.c_str(),
505 match_start_point,
506 max_return_elements,
507 NULL,
508 word_complete,
509 matches);
510 return matches.GetSize();
511}
512
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000513//-------------------------------------------------------------------------
514// CommandObjectSettingsRemove
515//-------------------------------------------------------------------------
516
Greg Clayton238c0a12010-09-18 01:14:36 +0000517CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
518 CommandObject (interpreter,
519 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000520 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000521 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000522{
Caroline Tice43b014a2010-10-04 22:28:36 +0000523 CommandArgumentEntry arg1;
524 CommandArgumentEntry arg2;
525 CommandArgumentData var_name_arg;
526 CommandArgumentData index_arg;
527 CommandArgumentData key_arg;
528
529 // Define the first (and only) variant of this arg.
530 var_name_arg.arg_type = eArgTypeSettingVariableName;
531 var_name_arg.arg_repetition = eArgRepeatPlain;
532
533 // There is only one variant this argument could be; put it into the argument entry.
534 arg1.push_back (var_name_arg);
535
536 // Define the first variant of this arg.
537 index_arg.arg_type = eArgTypeSettingIndex;
538 index_arg.arg_repetition = eArgRepeatPlain;
539
540 // Define the second variant of this arg.
541 key_arg.arg_type = eArgTypeSettingKey;
542 key_arg.arg_repetition = eArgRepeatPlain;
543
544 // Push both variants into this arg
545 arg2.push_back (index_arg);
546 arg2.push_back (key_arg);
547
548 // Push the data for the first argument into the m_arguments vector.
549 m_arguments.push_back (arg1);
550 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000551}
552
553CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
554{
555}
556
557bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000558CommandObjectSettingsRemove::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000559{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000560 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000561
562 const int argc = command.GetArgumentCount ();
563
564 if (argc != 2)
565 {
566 result.AppendError ("'settings remove' takes two arguments");
567 result.SetStatus (eReturnStatusFailed);
568 return false;
569 }
570
571 const char *var_name = command.GetArgumentAtIndex (0);
572 std::string var_name_string;
573 if ((var_name == NULL) || (var_name[0] == '\0'))
574 {
575 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
576 result.SetStatus (eReturnStatusFailed);
577 return false;
578 }
579
580 var_name_string = var_name;
581 command.Shift();
582
583 const char *index_value = command.GetArgumentAtIndex (0);
584 std::string index_value_string;
585 if ((index_value == NULL) || (index_value[0] == '\0'))
586 {
587 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
588 result.SetStatus (eReturnStatusFailed);
589 return false;
590 }
591
592 index_value_string = index_value;
593
Greg Clayton41c56fa2011-04-19 22:32:36 +0000594 Error err = usc_sp->SetVariable (var_name_string.c_str(),
595 NULL,
596 eVarSetOperationRemove,
597 true,
598 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
599 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000600 if (err.Fail ())
601 {
602 result.AppendError (err.AsCString());
603 result.SetStatus (eReturnStatusFailed);
604 }
605 else
606 result.SetStatus (eReturnStatusSuccessFinishNoResult);
607
608 return result.Succeeded();
609}
610
611int
Greg Clayton238c0a12010-09-18 01:14:36 +0000612CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000613 int &cursor_index,
614 int &cursor_char_position,
615 OptionElementVector &opt_element_vector,
616 int match_start_point,
617 int max_return_elements,
618 bool &word_complete,
619 StringList &matches)
620{
621 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
622 completion_str.erase (cursor_char_position);
623
624 // Attempting to complete variable name
625 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000626 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000627 CommandCompletions::eSettingsNameCompletion,
628 completion_str.c_str(),
629 match_start_point,
630 max_return_elements,
631 NULL,
632 word_complete,
633 matches);
634
635 return matches.GetSize();
636}
637
638//-------------------------------------------------------------------------
639// CommandObjectSettingsReplace
640//-------------------------------------------------------------------------
641
Greg Clayton238c0a12010-09-18 01:14:36 +0000642CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
643 CommandObject (interpreter,
644 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000645 "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000646 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000647{
Caroline Tice43b014a2010-10-04 22:28:36 +0000648 CommandArgumentEntry arg1;
649 CommandArgumentEntry arg2;
650 CommandArgumentEntry arg3;
651 CommandArgumentData var_name_arg;
652 CommandArgumentData index_arg;
653 CommandArgumentData key_arg;
654 CommandArgumentData value_arg;
655
656 // Define the first (and only) variant of this arg.
657 var_name_arg.arg_type = eArgTypeSettingVariableName;
658 var_name_arg.arg_repetition = eArgRepeatPlain;
659
660 // There is only one variant this argument could be; put it into the argument entry.
661 arg1.push_back (var_name_arg);
662
663 // Define the first (variant of this arg.
664 index_arg.arg_type = eArgTypeSettingIndex;
665 index_arg.arg_repetition = eArgRepeatPlain;
666
667 // Define the second (variant of this arg.
668 key_arg.arg_type = eArgTypeSettingKey;
669 key_arg.arg_repetition = eArgRepeatPlain;
670
671 // Put both variants into this arg
672 arg2.push_back (index_arg);
673 arg2.push_back (key_arg);
674
675 // Define the first (and only) variant of this arg.
676 value_arg.arg_type = eArgTypeValue;
677 value_arg.arg_repetition = eArgRepeatPlain;
678
679 // There is only one variant this argument could be; put it into the argument entry.
680 arg3.push_back (value_arg);
681
682 // Push the data for the first argument into the m_arguments vector.
683 m_arguments.push_back (arg1);
684 m_arguments.push_back (arg2);
685 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000686}
687
688CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
689{
690}
691
692bool
Johnny Chenc8bba452012-01-21 01:45:18 +0000693CommandObjectSettingsReplace::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000694{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000695 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000696
Johnny Chenc8bba452012-01-21 01:45:18 +0000697 Args cmd_args(raw_command);
698 const int argc = cmd_args.GetArgumentCount ();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000699
700 if (argc < 3)
701 {
702 result.AppendError ("'settings replace' takes more arguments");
703 result.SetStatus (eReturnStatusFailed);
704 return false;
705 }
706
Johnny Chenc8bba452012-01-21 01:45:18 +0000707 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000708 std::string var_name_string;
709 if ((var_name == NULL) || (var_name[0] == '\0'))
710 {
711 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
712 result.SetStatus (eReturnStatusFailed);
713 return false;
714 }
715
716 var_name_string = var_name;
Johnny Chenc8bba452012-01-21 01:45:18 +0000717 cmd_args.Shift();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000718
Johnny Chenc8bba452012-01-21 01:45:18 +0000719 const char *index_value = cmd_args.GetArgumentAtIndex (0);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000720 std::string index_value_string;
721 if ((index_value == NULL) || (index_value[0] == '\0'))
722 {
723 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
724 result.SetStatus (eReturnStatusFailed);
725 return false;
726 }
727
728 index_value_string = index_value;
Johnny Chenc8bba452012-01-21 01:45:18 +0000729 cmd_args.Shift();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000730
Johnny Chenc8bba452012-01-21 01:45:18 +0000731 // Split the raw command into var_name, index_value, and value triple.
732 llvm::StringRef raw_str(raw_command);
733 llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second;
734 StripLeadingSpaces(var_value_str);
735 std::string var_value_string = var_value_str.str();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000736
Johnny Chenc8bba452012-01-21 01:45:18 +0000737 if (var_value_string.empty())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000738 {
739 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
740 result.SetStatus (eReturnStatusFailed);
741 }
742 else
743 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000744 Error err = usc_sp->SetVariable (var_name_string.c_str(),
Johnny Chenc8bba452012-01-21 01:45:18 +0000745 var_value_string.c_str(),
Greg Clayton41c56fa2011-04-19 22:32:36 +0000746 eVarSetOperationReplace,
747 true,
748 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
749 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000750 if (err.Fail ())
751 {
752 result.AppendError (err.AsCString());
753 result.SetStatus (eReturnStatusFailed);
754 }
755 else
756 result.SetStatus (eReturnStatusSuccessFinishNoResult);
757 }
758
759 return result.Succeeded();
760}
761
762int
Greg Clayton238c0a12010-09-18 01:14:36 +0000763CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000764 int &cursor_index,
765 int &cursor_char_position,
766 OptionElementVector &opt_element_vector,
767 int match_start_point,
768 int max_return_elements,
769 bool &word_complete,
770 StringList &matches)
771{
772 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
773 completion_str.erase (cursor_char_position);
774
775 // Attempting to complete variable name
776 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000777 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000778 CommandCompletions::eSettingsNameCompletion,
779 completion_str.c_str(),
780 match_start_point,
781 max_return_elements,
782 NULL,
783 word_complete,
784 matches);
785
786 return matches.GetSize();
787}
788
789//-------------------------------------------------------------------------
790// CommandObjectSettingsInsertBefore
791//-------------------------------------------------------------------------
792
Greg Clayton238c0a12010-09-18 01:14:36 +0000793CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
794 CommandObject (interpreter,
795 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000796 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000797 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000798{
Caroline Tice43b014a2010-10-04 22:28:36 +0000799 CommandArgumentEntry arg1;
800 CommandArgumentEntry arg2;
801 CommandArgumentEntry arg3;
802 CommandArgumentData var_name_arg;
803 CommandArgumentData index_arg;
804 CommandArgumentData value_arg;
805
806 // Define the first (and only) variant of this arg.
807 var_name_arg.arg_type = eArgTypeSettingVariableName;
808 var_name_arg.arg_repetition = eArgRepeatPlain;
809
810 // There is only one variant this argument could be; put it into the argument entry.
811 arg1.push_back (var_name_arg);
812
813 // Define the first (variant of this arg.
814 index_arg.arg_type = eArgTypeSettingIndex;
815 index_arg.arg_repetition = eArgRepeatPlain;
816
817 // There is only one variant this argument could be; put it into the argument entry.
818 arg2.push_back (index_arg);
819
820 // Define the first (and only) variant of this arg.
821 value_arg.arg_type = eArgTypeValue;
822 value_arg.arg_repetition = eArgRepeatPlain;
823
824 // There is only one variant this argument could be; put it into the argument entry.
825 arg3.push_back (value_arg);
826
827 // Push the data for the first argument into the m_arguments vector.
828 m_arguments.push_back (arg1);
829 m_arguments.push_back (arg2);
830 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000831}
832
833CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
834{
835}
836
837bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000838CommandObjectSettingsInsertBefore::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000839{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000840 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000841
842 const int argc = command.GetArgumentCount ();
843
844 if (argc < 3)
845 {
846 result.AppendError ("'settings insert-before' takes more arguments");
847 result.SetStatus (eReturnStatusFailed);
848 return false;
849 }
850
851 const char *var_name = command.GetArgumentAtIndex (0);
852 std::string var_name_string;
853 if ((var_name == NULL) || (var_name[0] == '\0'))
854 {
855 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
856 result.SetStatus (eReturnStatusFailed);
857 return false;
858 }
859
860 var_name_string = var_name;
861 command.Shift();
862
863 const char *index_value = command.GetArgumentAtIndex (0);
864 std::string index_value_string;
865 if ((index_value == NULL) || (index_value[0] == '\0'))
866 {
867 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
868 result.SetStatus (eReturnStatusFailed);
869 return false;
870 }
871
872 index_value_string = index_value;
873 command.Shift();
874
875 const char *var_value;
876 std::string value_string;
877
Caroline Ticed9105c22010-12-10 00:26:54 +0000878 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000879 var_value = value_string.c_str();
880
881 if ((var_value == NULL) || (var_value[0] == '\0'))
882 {
883 result.AppendError ("'settings insert-before' command requires a valid variable value;"
884 " No value supplied");
885 result.SetStatus (eReturnStatusFailed);
886 }
887 else
888 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000889 Error err = usc_sp->SetVariable (var_name_string.c_str(),
890 var_value,
891 eVarSetOperationInsertBefore,
892 true,
893 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
894 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000895 if (err.Fail ())
896 {
897 result.AppendError (err.AsCString());
898 result.SetStatus (eReturnStatusFailed);
899 }
900 else
901 result.SetStatus (eReturnStatusSuccessFinishNoResult);
902 }
903
904 return result.Succeeded();
905}
906
907
908int
Greg Clayton238c0a12010-09-18 01:14:36 +0000909CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000910 int &cursor_index,
911 int &cursor_char_position,
912 OptionElementVector &opt_element_vector,
913 int match_start_point,
914 int max_return_elements,
915 bool &word_complete,
916 StringList &matches)
917{
918 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
919 completion_str.erase (cursor_char_position);
920
921 // Attempting to complete variable name
922 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000923 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000924 CommandCompletions::eSettingsNameCompletion,
925 completion_str.c_str(),
926 match_start_point,
927 max_return_elements,
928 NULL,
929 word_complete,
930 matches);
931
932 return matches.GetSize();
933}
934
935//-------------------------------------------------------------------------
936// CommandObjectSettingInsertAfter
937//-------------------------------------------------------------------------
938
Greg Clayton238c0a12010-09-18 01:14:36 +0000939CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
940 CommandObject (interpreter,
941 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000942 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000943 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000944{
Caroline Tice43b014a2010-10-04 22:28:36 +0000945 CommandArgumentEntry arg1;
946 CommandArgumentEntry arg2;
947 CommandArgumentEntry arg3;
948 CommandArgumentData var_name_arg;
949 CommandArgumentData index_arg;
950 CommandArgumentData value_arg;
951
952 // Define the first (and only) variant of this arg.
953 var_name_arg.arg_type = eArgTypeSettingVariableName;
954 var_name_arg.arg_repetition = eArgRepeatPlain;
955
956 // There is only one variant this argument could be; put it into the argument entry.
957 arg1.push_back (var_name_arg);
958
959 // Define the first (variant of this arg.
960 index_arg.arg_type = eArgTypeSettingIndex;
961 index_arg.arg_repetition = eArgRepeatPlain;
962
963 // There is only one variant this argument could be; put it into the argument entry.
964 arg2.push_back (index_arg);
965
966 // Define the first (and only) variant of this arg.
967 value_arg.arg_type = eArgTypeValue;
968 value_arg.arg_repetition = eArgRepeatPlain;
969
970 // There is only one variant this argument could be; put it into the argument entry.
971 arg3.push_back (value_arg);
972
973 // Push the data for the first argument into the m_arguments vector.
974 m_arguments.push_back (arg1);
975 m_arguments.push_back (arg2);
976 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000977}
978
979CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
980{
981}
982
983bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000984CommandObjectSettingsInsertAfter::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000985{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000986 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000987
988 const int argc = command.GetArgumentCount ();
989
990 if (argc < 3)
991 {
992 result.AppendError ("'settings insert-after' takes more arguments");
993 result.SetStatus (eReturnStatusFailed);
994 return false;
995 }
996
997 const char *var_name = command.GetArgumentAtIndex (0);
998 std::string var_name_string;
999 if ((var_name == NULL) || (var_name[0] == '\0'))
1000 {
1001 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
1002 result.SetStatus (eReturnStatusFailed);
1003 return false;
1004 }
1005
1006 var_name_string = var_name;
1007 command.Shift();
1008
1009 const char *index_value = command.GetArgumentAtIndex (0);
1010 std::string index_value_string;
1011 if ((index_value == NULL) || (index_value[0] == '\0'))
1012 {
1013 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
1014 result.SetStatus (eReturnStatusFailed);
1015 return false;
1016 }
1017
1018 index_value_string = index_value;
1019 command.Shift();
1020
1021 const char *var_value;
1022 std::string value_string;
1023
Caroline Ticed9105c22010-12-10 00:26:54 +00001024 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001025 var_value = value_string.c_str();
1026
1027 if ((var_value == NULL) || (var_value[0] == '\0'))
1028 {
1029 result.AppendError ("'settings insert-after' command requires a valid variable value;"
1030 " No value supplied");
1031 result.SetStatus (eReturnStatusFailed);
1032 }
1033 else
1034 {
Greg Clayton41c56fa2011-04-19 22:32:36 +00001035 Error err = usc_sp->SetVariable (var_name_string.c_str(),
1036 var_value,
1037 eVarSetOperationInsertAfter,
1038 true,
1039 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
1040 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001041 if (err.Fail ())
1042 {
1043 result.AppendError (err.AsCString());
1044 result.SetStatus (eReturnStatusFailed);
1045 }
1046 else
1047 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1048 }
1049
1050 return result.Succeeded();
1051}
1052
1053
1054int
Greg Clayton238c0a12010-09-18 01:14:36 +00001055CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001056 int &cursor_index,
1057 int &cursor_char_position,
1058 OptionElementVector &opt_element_vector,
1059 int match_start_point,
1060 int max_return_elements,
1061 bool &word_complete,
1062 StringList &matches)
1063{
1064 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1065 completion_str.erase (cursor_char_position);
1066
1067 // Attempting to complete variable name
1068 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001069 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001070 CommandCompletions::eSettingsNameCompletion,
1071 completion_str.c_str(),
1072 match_start_point,
1073 max_return_elements,
1074 NULL,
1075 word_complete,
1076 matches);
1077
1078 return matches.GetSize();
1079}
1080
1081//-------------------------------------------------------------------------
1082// CommandObjectSettingsAppend
1083//-------------------------------------------------------------------------
1084
Greg Clayton238c0a12010-09-18 01:14:36 +00001085CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
1086 CommandObject (interpreter,
1087 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001088 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001089 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001090{
Caroline Tice43b014a2010-10-04 22:28:36 +00001091 CommandArgumentEntry arg1;
1092 CommandArgumentEntry arg2;
1093 CommandArgumentData var_name_arg;
1094 CommandArgumentData value_arg;
1095
1096 // Define the first (and only) variant of this arg.
1097 var_name_arg.arg_type = eArgTypeSettingVariableName;
1098 var_name_arg.arg_repetition = eArgRepeatPlain;
1099
1100 // There is only one variant this argument could be; put it into the argument entry.
1101 arg1.push_back (var_name_arg);
1102
1103 // Define the first (and only) variant of this arg.
1104 value_arg.arg_type = eArgTypeValue;
1105 value_arg.arg_repetition = eArgRepeatPlain;
1106
1107 // There is only one variant this argument could be; put it into the argument entry.
1108 arg2.push_back (value_arg);
1109
1110 // Push the data for the first argument into the m_arguments vector.
1111 m_arguments.push_back (arg1);
1112 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001113}
1114
1115CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
1116{
1117}
1118
1119bool
Greg Clayton41c56fa2011-04-19 22:32:36 +00001120CommandObjectSettingsAppend::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001121{
Greg Clayton41c56fa2011-04-19 22:32:36 +00001122 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001123
1124 const int argc = command.GetArgumentCount ();
1125
1126 if (argc < 2)
1127 {
1128 result.AppendError ("'settings append' takes more arguments");
1129 result.SetStatus (eReturnStatusFailed);
1130 return false;
1131 }
1132
1133 const char *var_name = command.GetArgumentAtIndex (0);
1134 std::string var_name_string;
1135 if ((var_name == NULL) || (var_name[0] == '\0'))
1136 {
1137 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1138 result.SetStatus (eReturnStatusFailed);
1139 return false;
1140 }
1141
1142 var_name_string = var_name;
1143 command.Shift();
1144
1145 const char *var_value;
1146 std::string value_string;
1147
Caroline Ticed9105c22010-12-10 00:26:54 +00001148 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001149 var_value = value_string.c_str();
1150
1151 if ((var_value == NULL) || (var_value[0] == '\0'))
1152 {
1153 result.AppendError ("'settings append' command requires a valid variable value;"
1154 " No value supplied");
1155 result.SetStatus (eReturnStatusFailed);
1156 }
1157 else
1158 {
Greg Clayton41c56fa2011-04-19 22:32:36 +00001159 Error err = usc_sp->SetVariable (var_name_string.c_str(),
1160 var_value,
1161 eVarSetOperationAppend,
1162 true,
1163 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001164 if (err.Fail ())
1165 {
1166 result.AppendError (err.AsCString());
1167 result.SetStatus (eReturnStatusFailed);
1168 }
1169 else
1170 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1171 }
1172
1173 return result.Succeeded();
1174}
1175
1176
1177int
Greg Clayton238c0a12010-09-18 01:14:36 +00001178CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001179 int &cursor_index,
1180 int &cursor_char_position,
1181 OptionElementVector &opt_element_vector,
1182 int match_start_point,
1183 int max_return_elements,
1184 bool &word_complete,
1185 StringList &matches)
1186{
1187 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1188 completion_str.erase (cursor_char_position);
1189
1190 // Attempting to complete variable name
1191 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001192 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001193 CommandCompletions::eSettingsNameCompletion,
1194 completion_str.c_str(),
1195 match_start_point,
1196 max_return_elements,
1197 NULL,
1198 word_complete,
1199 matches);
1200
1201 return matches.GetSize();
1202}
1203
1204//-------------------------------------------------------------------------
1205// CommandObjectSettingsClear
1206//-------------------------------------------------------------------------
1207
Greg Clayton238c0a12010-09-18 01:14:36 +00001208CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1209 CommandObject (interpreter,
1210 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001211 "Erase all the contents of an internal debugger settings variables; this is only valid for variables with clearable types, i.e. strings, arrays or dictionaries.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001212 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001213{
Caroline Tice43b014a2010-10-04 22:28:36 +00001214 CommandArgumentEntry arg;
1215 CommandArgumentData var_name_arg;
1216
1217 // Define the first (and only) variant of this arg.
1218 var_name_arg.arg_type = eArgTypeSettingVariableName;
1219 var_name_arg.arg_repetition = eArgRepeatPlain;
1220
1221 // There is only one variant this argument could be; put it into the argument entry.
1222 arg.push_back (var_name_arg);
1223
1224 // Push the data for the first argument into the m_arguments vector.
1225 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001226}
1227
1228CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1229{
1230}
1231
1232bool
Greg Clayton41c56fa2011-04-19 22:32:36 +00001233CommandObjectSettingsClear::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001234{
Greg Clayton41c56fa2011-04-19 22:32:36 +00001235 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001236
1237 const int argc = command.GetArgumentCount ();
1238
1239 if (argc != 1)
1240 {
1241 result.AppendError ("'setttings clear' takes exactly one argument");
1242 result.SetStatus (eReturnStatusFailed);
1243 return false;
1244 }
1245
1246 const char *var_name = command.GetArgumentAtIndex (0);
1247 if ((var_name == NULL) || (var_name[0] == '\0'))
1248 {
1249 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1250 result.SetStatus (eReturnStatusFailed);
1251 return false;
1252 }
1253
Greg Clayton41c56fa2011-04-19 22:32:36 +00001254 Error err = usc_sp->SetVariable (var_name,
1255 NULL,
1256 eVarSetOperationClear,
1257 false,
1258 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001259
1260 if (err.Fail ())
1261 {
1262 result.AppendError (err.AsCString());
1263 result.SetStatus (eReturnStatusFailed);
1264 }
1265 else
1266 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1267
1268 return result.Succeeded();
1269}
1270
1271
1272int
Greg Clayton238c0a12010-09-18 01:14:36 +00001273CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001274 int &cursor_index,
1275 int &cursor_char_position,
1276 OptionElementVector &opt_element_vector,
1277 int match_start_point,
1278 int max_return_elements,
1279 bool &word_complete,
1280 StringList &matches)
1281{
1282 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1283 completion_str.erase (cursor_char_position);
1284
1285 // Attempting to complete variable name
1286 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001287 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001288 CommandCompletions::eSettingsNameCompletion,
1289 completion_str.c_str(),
1290 match_start_point,
1291 max_return_elements,
1292 NULL,
1293 word_complete,
1294 matches);
1295
1296 return matches.GetSize();
1297}