blob: 2421af5e882a696f420bb9bbb61bdb909afa467e [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\
86(lldb) settings set target.process.run-args value1 value2 value3 \n\
87(lldb) settings set target.process.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\
88\n\
89(lldb) settings show target.process.run-args \n\
90 [0]: 'value1' \n\
91 [1]: 'value2' \n\
92 [3]: 'value3' \n\
93(lldb) settings show target.process.env-vars \n\
94 '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
111bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000112CommandObjectSettingsSet::Execute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000113{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000114 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Chris Lattner24943d22010-06-08 16:52:24 +0000115
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000116 const int argc = command.GetArgumentCount ();
117
Caroline Tice87097232010-09-07 18:35:40 +0000118 if ((argc < 2) && (!m_options.m_reset))
Chris Lattner24943d22010-06-08 16:52:24 +0000119 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000120 result.AppendError ("'settings set' takes more arguments");
121 result.SetStatus (eReturnStatusFailed);
122 return false;
123 }
124
125 const char *var_name = command.GetArgumentAtIndex (0);
126 std::string var_name_string;
127 if ((var_name == NULL) || (var_name[0] == '\0'))
128 {
129 result.AppendError ("'settings set' command requires a valid variable name; No value supplied");
130 result.SetStatus (eReturnStatusFailed);
131 return false;
132 }
133
134 var_name_string = var_name;
135 command.Shift();
136
137 const char *var_value;
138 std::string value_string;
139
Caroline Ticed9105c22010-12-10 00:26:54 +0000140 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000141 var_value = value_string.c_str();
142
143 if (!m_options.m_reset
144 && var_value == NULL)
145 {
146 result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;"
147 " No value supplied");
Chris Lattner24943d22010-06-08 16:52:24 +0000148 result.SetStatus (eReturnStatusFailed);
149 }
150 else
151 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000152 Error err = usc_sp->SetVariable (var_name_string.c_str(),
153 var_value,
154 eVarSetOperationAssign,
155 m_options.m_override,
156 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000157 if (err.Fail ())
158 {
159 result.AppendError (err.AsCString());
160 result.SetStatus (eReturnStatusFailed);
161 }
162 else
163 result.SetStatus (eReturnStatusSuccessFinishNoResult);
164 }
165
166 return result.Succeeded();
167}
168
169int
Greg Clayton238c0a12010-09-18 01:14:36 +0000170CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000171 int &cursor_index,
172 int &cursor_char_position,
173 OptionElementVector &opt_element_vector,
174 int match_start_point,
175 int max_return_elements,
176 bool &word_complete,
177 StringList &matches)
178{
179 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
180 completion_str.erase (cursor_char_position);
181
182 // Attempting to complete variable name
183 if (cursor_index == 1)
Greg Clayton238c0a12010-09-18 01:14:36 +0000184 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000185 CommandCompletions::eSettingsNameCompletion,
186 completion_str.c_str(),
187 match_start_point,
188 max_return_elements,
189 NULL,
190 word_complete,
191 matches);
192
193 // Attempting to complete value
194 if ((cursor_index == 2) // Partly into the variable's value
195 || (cursor_index == 1 // Or at the end of a completed valid variable name
196 && matches.GetSize() == 1
197 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
198 {
199 matches.Clear();
Greg Clayton41c56fa2011-04-19 22:32:36 +0000200 UserSettingsControllerSP usc_sp = Debugger::GetSettingsController();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000201 if (cursor_index == 1)
202 {
203 // The user is at the end of the variable name, which is complete and valid.
Greg Clayton41c56fa2011-04-19 22:32:36 +0000204 UserSettingsController::CompleteSettingsValue (usc_sp,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000205 input.GetArgumentAtIndex (1), // variable name
206 NULL, // empty value string
207 word_complete,
208 matches);
209 }
210 else
211 {
212 // The user is partly into the variable value.
Greg Clayton41c56fa2011-04-19 22:32:36 +0000213 UserSettingsController::CompleteSettingsValue (usc_sp,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000214 input.GetArgumentAtIndex (1), // variable name
215 completion_str.c_str(), // partial value string
216 word_complete,
217 matches);
218 }
219 }
220
221 return matches.GetSize();
222}
223
224//-------------------------------------------------------------------------
225// CommandObjectSettingsSet::CommandOptions
226//-------------------------------------------------------------------------
227
Greg Claytonf15996e2011-04-07 22:46:35 +0000228CommandObjectSettingsSet::CommandOptions::CommandOptions (CommandInterpreter &interpreter) :
229 Options (interpreter),
Caroline Tice1ebef442010-09-27 00:30:10 +0000230 m_override (true),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000231 m_reset (false)
232{
233}
234
235CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
236{
237}
238
Greg Claytonb3448432011-03-24 21:19:54 +0000239OptionDefinition
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000240CommandObjectSettingsSet::CommandOptions::g_option_table[] =
241{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000242 { 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." },
243 { 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." },
244 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000245};
246
Greg Claytonb3448432011-03-24 21:19:54 +0000247const OptionDefinition*
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000248CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
249{
250 return g_option_table;
251}
252
253Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000254CommandObjectSettingsSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000255{
256 Error error;
257 char short_option = (char) m_getopt_table[option_idx].val;
258
259 switch (short_option)
260 {
Caroline Tice1ebef442010-09-27 00:30:10 +0000261 case 'n':
262 m_override = false;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000263 break;
264 case 'r':
265 m_reset = true;
266 break;
267 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000268 error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000269 break;
270 }
271
272 return error;
273}
274
275void
Greg Clayton143fcc32011-04-13 00:18:08 +0000276CommandObjectSettingsSet::CommandOptions::OptionParsingStarting ()
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000277{
Caroline Tice1ebef442010-09-27 00:30:10 +0000278 m_override = true;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000279 m_reset = false;
280}
281
282Options *
283CommandObjectSettingsSet::GetOptions ()
284{
285 return &m_options;
286}
287
288
289//-------------------------------------------------------------------------
290// CommandObjectSettingsShow -- Show current values
291//-------------------------------------------------------------------------
292
Greg Clayton238c0a12010-09-18 01:14:36 +0000293CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
294 CommandObject (interpreter,
295 "settings show",
296 "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 +0000297 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000298{
Caroline Tice43b014a2010-10-04 22:28:36 +0000299 CommandArgumentEntry arg1;
300 CommandArgumentData var_name_arg;
301
302 // Define the first (and only) variant of this arg.
303 var_name_arg.arg_type = eArgTypeSettingVariableName;
304 var_name_arg.arg_repetition = eArgRepeatOptional;
305
306 // There is only one variant this argument could be; put it into the argument entry.
307 arg1.push_back (var_name_arg);
308
309 // Push the data for the first argument into the m_arguments vector.
310 m_arguments.push_back (arg1);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000311}
312
313CommandObjectSettingsShow::~CommandObjectSettingsShow()
314{
315}
316
317
318bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000319CommandObjectSettingsShow::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000320{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000321 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
322 const char *current_prefix = usc_sp->GetLevelName().GetCString();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000323
324 Error err;
325
326 if (command.GetArgumentCount())
327 {
328 // The user requested to see the value of a particular variable.
Greg Claytonb3448432011-03-24 21:19:54 +0000329 SettableVariableType var_type;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000330 const char *variable_name = command.GetArgumentAtIndex (0);
Greg Clayton41c56fa2011-04-19 22:32:36 +0000331 StringList value = usc_sp->GetVariable (variable_name,
332 var_type,
333 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
334 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000335
Caroline Tice5bc8c972010-09-20 20:44:43 +0000336 if (err.Fail ())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000337 {
Caroline Tice5bc8c972010-09-20 20:44:43 +0000338 result.AppendError (err.AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000339 result.SetStatus (eReturnStatusFailed);
340
Greg Clayton41c56fa2011-04-19 22:32:36 +0000341 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000342 else
343 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000344 UserSettingsController::DumpValue(m_interpreter, usc_sp, variable_name, result.GetOutputStream());
345 result.SetStatus (eReturnStatusSuccessFinishResult);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000346 }
347 }
348 else
349 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000350 UserSettingsController::GetAllVariableValues (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000351 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000352 current_prefix,
353 result.GetOutputStream(),
354 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000355 if (err.Fail ())
356 {
357 result.AppendError (err.AsCString());
358 result.SetStatus (eReturnStatusFailed);
359 }
360 else
361 {
362 result.SetStatus (eReturnStatusSuccessFinishNoResult);
363 }
364 }
365
366 return result.Succeeded();
367}
368
369int
Greg Clayton238c0a12010-09-18 01:14:36 +0000370CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000371 int &cursor_index,
372 int &cursor_char_position,
373 OptionElementVector &opt_element_vector,
374 int match_start_point,
375 int max_return_elements,
376 bool &word_complete,
377 StringList &matches)
378{
379 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
380 completion_str.erase (cursor_char_position);
381
Greg Clayton238c0a12010-09-18 01:14:36 +0000382 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000383 CommandCompletions::eSettingsNameCompletion,
384 completion_str.c_str(),
385 match_start_point,
386 max_return_elements,
387 NULL,
388 word_complete,
389 matches);
390 return matches.GetSize();
391}
392
393//-------------------------------------------------------------------------
394// CommandObjectSettingsList
395//-------------------------------------------------------------------------
396
Greg Clayton238c0a12010-09-18 01:14:36 +0000397CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
398 CommandObject (interpreter,
399 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000400 "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 +0000401 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000402{
Caroline Tice43b014a2010-10-04 22:28:36 +0000403 CommandArgumentEntry arg;
404 CommandArgumentData var_name_arg;
405 CommandArgumentData prefix_name_arg;
406
407 // Define the first variant of this arg.
408 var_name_arg.arg_type = eArgTypeSettingVariableName;
409 var_name_arg.arg_repetition = eArgRepeatOptional;
410
411 // Define the second variant of this arg.
412 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
413 prefix_name_arg.arg_repetition = eArgRepeatOptional;
414
415 arg.push_back (var_name_arg);
416 arg.push_back (prefix_name_arg);
417
418 // Push the data for the first argument into the m_arguments vector.
419 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000420}
421
422CommandObjectSettingsList::~CommandObjectSettingsList()
423{
424}
425
426
427bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000428CommandObjectSettingsList::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000429{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000430 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
431 const char *current_prefix = usc_sp->GetLevelName().GetCString();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000432
433 Error err;
434
Caroline Tice41ae2172010-09-15 06:56:39 +0000435 if (command.GetArgumentCount() == 0)
436 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000437 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000438 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000439 current_prefix,
440 result.GetOutputStream(),
441 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000442 }
443 else if (command.GetArgumentCount() == 1)
444 {
445 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000446 UserSettingsController::FindSettingsDescriptions (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000447 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000448 current_prefix,
449 search_name,
450 result.GetOutputStream(),
451 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000452 }
453 else
454 {
455 result.AppendError ("Too many aguments for 'settings list' command.\n");
456 result.SetStatus (eReturnStatusFailed);
457 return false;
458 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000459
460 if (err.Fail ())
461 {
462 result.AppendError (err.AsCString());
463 result.SetStatus (eReturnStatusFailed);
464 }
465 else
466 {
Chris Lattner24943d22010-06-08 16:52:24 +0000467 result.SetStatus (eReturnStatusSuccessFinishNoResult);
468 }
469
470 return result.Succeeded();
471}
472
Caroline Tice41ae2172010-09-15 06:56:39 +0000473int
Greg Clayton238c0a12010-09-18 01:14:36 +0000474CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000475 int &cursor_index,
476 int &cursor_char_position,
477 OptionElementVector &opt_element_vector,
478 int match_start_point,
479 int max_return_elements,
480 bool &word_complete,
481 StringList &matches)
482{
483 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
484 completion_str.erase (cursor_char_position);
485
Greg Clayton238c0a12010-09-18 01:14:36 +0000486 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000487 CommandCompletions::eSettingsNameCompletion,
488 completion_str.c_str(),
489 match_start_point,
490 max_return_elements,
491 NULL,
492 word_complete,
493 matches);
494 return matches.GetSize();
495}
496
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000497//-------------------------------------------------------------------------
498// CommandObjectSettingsRemove
499//-------------------------------------------------------------------------
500
Greg Clayton238c0a12010-09-18 01:14:36 +0000501CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
502 CommandObject (interpreter,
503 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000504 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000505 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000506{
Caroline Tice43b014a2010-10-04 22:28:36 +0000507 CommandArgumentEntry arg1;
508 CommandArgumentEntry arg2;
509 CommandArgumentData var_name_arg;
510 CommandArgumentData index_arg;
511 CommandArgumentData key_arg;
512
513 // Define the first (and only) variant of this arg.
514 var_name_arg.arg_type = eArgTypeSettingVariableName;
515 var_name_arg.arg_repetition = eArgRepeatPlain;
516
517 // There is only one variant this argument could be; put it into the argument entry.
518 arg1.push_back (var_name_arg);
519
520 // Define the first variant of this arg.
521 index_arg.arg_type = eArgTypeSettingIndex;
522 index_arg.arg_repetition = eArgRepeatPlain;
523
524 // Define the second variant of this arg.
525 key_arg.arg_type = eArgTypeSettingKey;
526 key_arg.arg_repetition = eArgRepeatPlain;
527
528 // Push both variants into this arg
529 arg2.push_back (index_arg);
530 arg2.push_back (key_arg);
531
532 // Push the data for the first argument into the m_arguments vector.
533 m_arguments.push_back (arg1);
534 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000535}
536
537CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
538{
539}
540
541bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000542CommandObjectSettingsRemove::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000543{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000544 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000545
546 const int argc = command.GetArgumentCount ();
547
548 if (argc != 2)
549 {
550 result.AppendError ("'settings remove' takes two arguments");
551 result.SetStatus (eReturnStatusFailed);
552 return false;
553 }
554
555 const char *var_name = command.GetArgumentAtIndex (0);
556 std::string var_name_string;
557 if ((var_name == NULL) || (var_name[0] == '\0'))
558 {
559 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
560 result.SetStatus (eReturnStatusFailed);
561 return false;
562 }
563
564 var_name_string = var_name;
565 command.Shift();
566
567 const char *index_value = command.GetArgumentAtIndex (0);
568 std::string index_value_string;
569 if ((index_value == NULL) || (index_value[0] == '\0'))
570 {
571 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
572 result.SetStatus (eReturnStatusFailed);
573 return false;
574 }
575
576 index_value_string = index_value;
577
Greg Clayton41c56fa2011-04-19 22:32:36 +0000578 Error err = usc_sp->SetVariable (var_name_string.c_str(),
579 NULL,
580 eVarSetOperationRemove,
581 true,
582 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
583 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000584 if (err.Fail ())
585 {
586 result.AppendError (err.AsCString());
587 result.SetStatus (eReturnStatusFailed);
588 }
589 else
590 result.SetStatus (eReturnStatusSuccessFinishNoResult);
591
592 return result.Succeeded();
593}
594
595int
Greg Clayton238c0a12010-09-18 01:14:36 +0000596CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000597 int &cursor_index,
598 int &cursor_char_position,
599 OptionElementVector &opt_element_vector,
600 int match_start_point,
601 int max_return_elements,
602 bool &word_complete,
603 StringList &matches)
604{
605 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
606 completion_str.erase (cursor_char_position);
607
608 // Attempting to complete variable name
609 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000610 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000611 CommandCompletions::eSettingsNameCompletion,
612 completion_str.c_str(),
613 match_start_point,
614 max_return_elements,
615 NULL,
616 word_complete,
617 matches);
618
619 return matches.GetSize();
620}
621
622//-------------------------------------------------------------------------
623// CommandObjectSettingsReplace
624//-------------------------------------------------------------------------
625
Greg Clayton238c0a12010-09-18 01:14:36 +0000626CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
627 CommandObject (interpreter,
628 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000629 "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 +0000630 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000631{
Caroline Tice43b014a2010-10-04 22:28:36 +0000632 CommandArgumentEntry arg1;
633 CommandArgumentEntry arg2;
634 CommandArgumentEntry arg3;
635 CommandArgumentData var_name_arg;
636 CommandArgumentData index_arg;
637 CommandArgumentData key_arg;
638 CommandArgumentData value_arg;
639
640 // Define the first (and only) variant of this arg.
641 var_name_arg.arg_type = eArgTypeSettingVariableName;
642 var_name_arg.arg_repetition = eArgRepeatPlain;
643
644 // There is only one variant this argument could be; put it into the argument entry.
645 arg1.push_back (var_name_arg);
646
647 // Define the first (variant of this arg.
648 index_arg.arg_type = eArgTypeSettingIndex;
649 index_arg.arg_repetition = eArgRepeatPlain;
650
651 // Define the second (variant of this arg.
652 key_arg.arg_type = eArgTypeSettingKey;
653 key_arg.arg_repetition = eArgRepeatPlain;
654
655 // Put both variants into this arg
656 arg2.push_back (index_arg);
657 arg2.push_back (key_arg);
658
659 // Define the first (and only) variant of this arg.
660 value_arg.arg_type = eArgTypeValue;
661 value_arg.arg_repetition = eArgRepeatPlain;
662
663 // There is only one variant this argument could be; put it into the argument entry.
664 arg3.push_back (value_arg);
665
666 // Push the data for the first argument into the m_arguments vector.
667 m_arguments.push_back (arg1);
668 m_arguments.push_back (arg2);
669 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000670}
671
672CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
673{
674}
675
676bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000677CommandObjectSettingsReplace::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000678{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000679 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000680
681 const int argc = command.GetArgumentCount ();
682
683 if (argc < 3)
684 {
685 result.AppendError ("'settings replace' takes more arguments");
686 result.SetStatus (eReturnStatusFailed);
687 return false;
688 }
689
690 const char *var_name = command.GetArgumentAtIndex (0);
691 std::string var_name_string;
692 if ((var_name == NULL) || (var_name[0] == '\0'))
693 {
694 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
695 result.SetStatus (eReturnStatusFailed);
696 return false;
697 }
698
699 var_name_string = var_name;
700 command.Shift();
701
702 const char *index_value = command.GetArgumentAtIndex (0);
703 std::string index_value_string;
704 if ((index_value == NULL) || (index_value[0] == '\0'))
705 {
706 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
707 result.SetStatus (eReturnStatusFailed);
708 return false;
709 }
710
711 index_value_string = index_value;
712 command.Shift();
713
714 const char *var_value;
715 std::string value_string;
716
Caroline Ticed9105c22010-12-10 00:26:54 +0000717 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000718 var_value = value_string.c_str();
719
720 if ((var_value == NULL) || (var_value[0] == '\0'))
721 {
722 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
723 result.SetStatus (eReturnStatusFailed);
724 }
725 else
726 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000727 Error err = usc_sp->SetVariable (var_name_string.c_str(),
728 var_value,
729 eVarSetOperationReplace,
730 true,
731 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
732 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000733 if (err.Fail ())
734 {
735 result.AppendError (err.AsCString());
736 result.SetStatus (eReturnStatusFailed);
737 }
738 else
739 result.SetStatus (eReturnStatusSuccessFinishNoResult);
740 }
741
742 return result.Succeeded();
743}
744
745int
Greg Clayton238c0a12010-09-18 01:14:36 +0000746CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000747 int &cursor_index,
748 int &cursor_char_position,
749 OptionElementVector &opt_element_vector,
750 int match_start_point,
751 int max_return_elements,
752 bool &word_complete,
753 StringList &matches)
754{
755 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
756 completion_str.erase (cursor_char_position);
757
758 // Attempting to complete variable name
759 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000760 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000761 CommandCompletions::eSettingsNameCompletion,
762 completion_str.c_str(),
763 match_start_point,
764 max_return_elements,
765 NULL,
766 word_complete,
767 matches);
768
769 return matches.GetSize();
770}
771
772//-------------------------------------------------------------------------
773// CommandObjectSettingsInsertBefore
774//-------------------------------------------------------------------------
775
Greg Clayton238c0a12010-09-18 01:14:36 +0000776CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
777 CommandObject (interpreter,
778 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000779 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000780 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000781{
Caroline Tice43b014a2010-10-04 22:28:36 +0000782 CommandArgumentEntry arg1;
783 CommandArgumentEntry arg2;
784 CommandArgumentEntry arg3;
785 CommandArgumentData var_name_arg;
786 CommandArgumentData index_arg;
787 CommandArgumentData value_arg;
788
789 // Define the first (and only) variant of this arg.
790 var_name_arg.arg_type = eArgTypeSettingVariableName;
791 var_name_arg.arg_repetition = eArgRepeatPlain;
792
793 // There is only one variant this argument could be; put it into the argument entry.
794 arg1.push_back (var_name_arg);
795
796 // Define the first (variant of this arg.
797 index_arg.arg_type = eArgTypeSettingIndex;
798 index_arg.arg_repetition = eArgRepeatPlain;
799
800 // There is only one variant this argument could be; put it into the argument entry.
801 arg2.push_back (index_arg);
802
803 // Define the first (and only) variant of this arg.
804 value_arg.arg_type = eArgTypeValue;
805 value_arg.arg_repetition = eArgRepeatPlain;
806
807 // There is only one variant this argument could be; put it into the argument entry.
808 arg3.push_back (value_arg);
809
810 // Push the data for the first argument into the m_arguments vector.
811 m_arguments.push_back (arg1);
812 m_arguments.push_back (arg2);
813 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000814}
815
816CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
817{
818}
819
820bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000821CommandObjectSettingsInsertBefore::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000822{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000823 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000824
825 const int argc = command.GetArgumentCount ();
826
827 if (argc < 3)
828 {
829 result.AppendError ("'settings insert-before' takes more arguments");
830 result.SetStatus (eReturnStatusFailed);
831 return false;
832 }
833
834 const char *var_name = command.GetArgumentAtIndex (0);
835 std::string var_name_string;
836 if ((var_name == NULL) || (var_name[0] == '\0'))
837 {
838 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
839 result.SetStatus (eReturnStatusFailed);
840 return false;
841 }
842
843 var_name_string = var_name;
844 command.Shift();
845
846 const char *index_value = command.GetArgumentAtIndex (0);
847 std::string index_value_string;
848 if ((index_value == NULL) || (index_value[0] == '\0'))
849 {
850 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
851 result.SetStatus (eReturnStatusFailed);
852 return false;
853 }
854
855 index_value_string = index_value;
856 command.Shift();
857
858 const char *var_value;
859 std::string value_string;
860
Caroline Ticed9105c22010-12-10 00:26:54 +0000861 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000862 var_value = value_string.c_str();
863
864 if ((var_value == NULL) || (var_value[0] == '\0'))
865 {
866 result.AppendError ("'settings insert-before' command requires a valid variable value;"
867 " No value supplied");
868 result.SetStatus (eReturnStatusFailed);
869 }
870 else
871 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000872 Error err = usc_sp->SetVariable (var_name_string.c_str(),
873 var_value,
874 eVarSetOperationInsertBefore,
875 true,
876 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
877 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000878 if (err.Fail ())
879 {
880 result.AppendError (err.AsCString());
881 result.SetStatus (eReturnStatusFailed);
882 }
883 else
884 result.SetStatus (eReturnStatusSuccessFinishNoResult);
885 }
886
887 return result.Succeeded();
888}
889
890
891int
Greg Clayton238c0a12010-09-18 01:14:36 +0000892CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000893 int &cursor_index,
894 int &cursor_char_position,
895 OptionElementVector &opt_element_vector,
896 int match_start_point,
897 int max_return_elements,
898 bool &word_complete,
899 StringList &matches)
900{
901 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
902 completion_str.erase (cursor_char_position);
903
904 // Attempting to complete variable name
905 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000906 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000907 CommandCompletions::eSettingsNameCompletion,
908 completion_str.c_str(),
909 match_start_point,
910 max_return_elements,
911 NULL,
912 word_complete,
913 matches);
914
915 return matches.GetSize();
916}
917
918//-------------------------------------------------------------------------
919// CommandObjectSettingInsertAfter
920//-------------------------------------------------------------------------
921
Greg Clayton238c0a12010-09-18 01:14:36 +0000922CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
923 CommandObject (interpreter,
924 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000925 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000926 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000927{
Caroline Tice43b014a2010-10-04 22:28:36 +0000928 CommandArgumentEntry arg1;
929 CommandArgumentEntry arg2;
930 CommandArgumentEntry arg3;
931 CommandArgumentData var_name_arg;
932 CommandArgumentData index_arg;
933 CommandArgumentData value_arg;
934
935 // Define the first (and only) variant of this arg.
936 var_name_arg.arg_type = eArgTypeSettingVariableName;
937 var_name_arg.arg_repetition = eArgRepeatPlain;
938
939 // There is only one variant this argument could be; put it into the argument entry.
940 arg1.push_back (var_name_arg);
941
942 // Define the first (variant of this arg.
943 index_arg.arg_type = eArgTypeSettingIndex;
944 index_arg.arg_repetition = eArgRepeatPlain;
945
946 // There is only one variant this argument could be; put it into the argument entry.
947 arg2.push_back (index_arg);
948
949 // Define the first (and only) variant of this arg.
950 value_arg.arg_type = eArgTypeValue;
951 value_arg.arg_repetition = eArgRepeatPlain;
952
953 // There is only one variant this argument could be; put it into the argument entry.
954 arg3.push_back (value_arg);
955
956 // Push the data for the first argument into the m_arguments vector.
957 m_arguments.push_back (arg1);
958 m_arguments.push_back (arg2);
959 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000960}
961
962CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
963{
964}
965
966bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000967CommandObjectSettingsInsertAfter::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000968{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000969 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000970
971 const int argc = command.GetArgumentCount ();
972
973 if (argc < 3)
974 {
975 result.AppendError ("'settings insert-after' takes more arguments");
976 result.SetStatus (eReturnStatusFailed);
977 return false;
978 }
979
980 const char *var_name = command.GetArgumentAtIndex (0);
981 std::string var_name_string;
982 if ((var_name == NULL) || (var_name[0] == '\0'))
983 {
984 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
985 result.SetStatus (eReturnStatusFailed);
986 return false;
987 }
988
989 var_name_string = var_name;
990 command.Shift();
991
992 const char *index_value = command.GetArgumentAtIndex (0);
993 std::string index_value_string;
994 if ((index_value == NULL) || (index_value[0] == '\0'))
995 {
996 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
997 result.SetStatus (eReturnStatusFailed);
998 return false;
999 }
1000
1001 index_value_string = index_value;
1002 command.Shift();
1003
1004 const char *var_value;
1005 std::string value_string;
1006
Caroline Ticed9105c22010-12-10 00:26:54 +00001007 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001008 var_value = value_string.c_str();
1009
1010 if ((var_value == NULL) || (var_value[0] == '\0'))
1011 {
1012 result.AppendError ("'settings insert-after' command requires a valid variable value;"
1013 " No value supplied");
1014 result.SetStatus (eReturnStatusFailed);
1015 }
1016 else
1017 {
Greg Clayton41c56fa2011-04-19 22:32:36 +00001018 Error err = usc_sp->SetVariable (var_name_string.c_str(),
1019 var_value,
1020 eVarSetOperationInsertAfter,
1021 true,
1022 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
1023 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001024 if (err.Fail ())
1025 {
1026 result.AppendError (err.AsCString());
1027 result.SetStatus (eReturnStatusFailed);
1028 }
1029 else
1030 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1031 }
1032
1033 return result.Succeeded();
1034}
1035
1036
1037int
Greg Clayton238c0a12010-09-18 01:14:36 +00001038CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001039 int &cursor_index,
1040 int &cursor_char_position,
1041 OptionElementVector &opt_element_vector,
1042 int match_start_point,
1043 int max_return_elements,
1044 bool &word_complete,
1045 StringList &matches)
1046{
1047 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1048 completion_str.erase (cursor_char_position);
1049
1050 // Attempting to complete variable name
1051 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001052 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001053 CommandCompletions::eSettingsNameCompletion,
1054 completion_str.c_str(),
1055 match_start_point,
1056 max_return_elements,
1057 NULL,
1058 word_complete,
1059 matches);
1060
1061 return matches.GetSize();
1062}
1063
1064//-------------------------------------------------------------------------
1065// CommandObjectSettingsAppend
1066//-------------------------------------------------------------------------
1067
Greg Clayton238c0a12010-09-18 01:14:36 +00001068CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
1069 CommandObject (interpreter,
1070 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001071 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001072 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001073{
Caroline Tice43b014a2010-10-04 22:28:36 +00001074 CommandArgumentEntry arg1;
1075 CommandArgumentEntry arg2;
1076 CommandArgumentData var_name_arg;
1077 CommandArgumentData value_arg;
1078
1079 // Define the first (and only) variant of this arg.
1080 var_name_arg.arg_type = eArgTypeSettingVariableName;
1081 var_name_arg.arg_repetition = eArgRepeatPlain;
1082
1083 // There is only one variant this argument could be; put it into the argument entry.
1084 arg1.push_back (var_name_arg);
1085
1086 // Define the first (and only) variant of this arg.
1087 value_arg.arg_type = eArgTypeValue;
1088 value_arg.arg_repetition = eArgRepeatPlain;
1089
1090 // There is only one variant this argument could be; put it into the argument entry.
1091 arg2.push_back (value_arg);
1092
1093 // Push the data for the first argument into the m_arguments vector.
1094 m_arguments.push_back (arg1);
1095 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001096}
1097
1098CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
1099{
1100}
1101
1102bool
Greg Clayton41c56fa2011-04-19 22:32:36 +00001103CommandObjectSettingsAppend::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001104{
Greg Clayton41c56fa2011-04-19 22:32:36 +00001105 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001106
1107 const int argc = command.GetArgumentCount ();
1108
1109 if (argc < 2)
1110 {
1111 result.AppendError ("'settings append' takes more arguments");
1112 result.SetStatus (eReturnStatusFailed);
1113 return false;
1114 }
1115
1116 const char *var_name = command.GetArgumentAtIndex (0);
1117 std::string var_name_string;
1118 if ((var_name == NULL) || (var_name[0] == '\0'))
1119 {
1120 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1121 result.SetStatus (eReturnStatusFailed);
1122 return false;
1123 }
1124
1125 var_name_string = var_name;
1126 command.Shift();
1127
1128 const char *var_value;
1129 std::string value_string;
1130
Caroline Ticed9105c22010-12-10 00:26:54 +00001131 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001132 var_value = value_string.c_str();
1133
1134 if ((var_value == NULL) || (var_value[0] == '\0'))
1135 {
1136 result.AppendError ("'settings append' command requires a valid variable value;"
1137 " No value supplied");
1138 result.SetStatus (eReturnStatusFailed);
1139 }
1140 else
1141 {
Greg Clayton41c56fa2011-04-19 22:32:36 +00001142 Error err = usc_sp->SetVariable (var_name_string.c_str(),
1143 var_value,
1144 eVarSetOperationAppend,
1145 true,
1146 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001147 if (err.Fail ())
1148 {
1149 result.AppendError (err.AsCString());
1150 result.SetStatus (eReturnStatusFailed);
1151 }
1152 else
1153 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1154 }
1155
1156 return result.Succeeded();
1157}
1158
1159
1160int
Greg Clayton238c0a12010-09-18 01:14:36 +00001161CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001162 int &cursor_index,
1163 int &cursor_char_position,
1164 OptionElementVector &opt_element_vector,
1165 int match_start_point,
1166 int max_return_elements,
1167 bool &word_complete,
1168 StringList &matches)
1169{
1170 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1171 completion_str.erase (cursor_char_position);
1172
1173 // Attempting to complete variable name
1174 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001175 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001176 CommandCompletions::eSettingsNameCompletion,
1177 completion_str.c_str(),
1178 match_start_point,
1179 max_return_elements,
1180 NULL,
1181 word_complete,
1182 matches);
1183
1184 return matches.GetSize();
1185}
1186
1187//-------------------------------------------------------------------------
1188// CommandObjectSettingsClear
1189//-------------------------------------------------------------------------
1190
Greg Clayton238c0a12010-09-18 01:14:36 +00001191CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1192 CommandObject (interpreter,
1193 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001194 "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 +00001195 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001196{
Caroline Tice43b014a2010-10-04 22:28:36 +00001197 CommandArgumentEntry arg;
1198 CommandArgumentData var_name_arg;
1199
1200 // Define the first (and only) variant of this arg.
1201 var_name_arg.arg_type = eArgTypeSettingVariableName;
1202 var_name_arg.arg_repetition = eArgRepeatPlain;
1203
1204 // There is only one variant this argument could be; put it into the argument entry.
1205 arg.push_back (var_name_arg);
1206
1207 // Push the data for the first argument into the m_arguments vector.
1208 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001209}
1210
1211CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1212{
1213}
1214
1215bool
Greg Clayton41c56fa2011-04-19 22:32:36 +00001216CommandObjectSettingsClear::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001217{
Greg Clayton41c56fa2011-04-19 22:32:36 +00001218 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001219
1220 const int argc = command.GetArgumentCount ();
1221
1222 if (argc != 1)
1223 {
1224 result.AppendError ("'setttings clear' takes exactly one argument");
1225 result.SetStatus (eReturnStatusFailed);
1226 return false;
1227 }
1228
1229 const char *var_name = command.GetArgumentAtIndex (0);
1230 if ((var_name == NULL) || (var_name[0] == '\0'))
1231 {
1232 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1233 result.SetStatus (eReturnStatusFailed);
1234 return false;
1235 }
1236
Greg Clayton41c56fa2011-04-19 22:32:36 +00001237 Error err = usc_sp->SetVariable (var_name,
1238 NULL,
1239 eVarSetOperationClear,
1240 false,
1241 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001242
1243 if (err.Fail ())
1244 {
1245 result.AppendError (err.AsCString());
1246 result.SetStatus (eReturnStatusFailed);
1247 }
1248 else
1249 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1250
1251 return result.Succeeded();
1252}
1253
1254
1255int
Greg Clayton238c0a12010-09-18 01:14:36 +00001256CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001257 int &cursor_index,
1258 int &cursor_char_position,
1259 OptionElementVector &opt_element_vector,
1260 int match_start_point,
1261 int max_return_elements,
1262 bool &word_complete,
1263 StringList &matches)
1264{
1265 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1266 completion_str.erase (cursor_char_position);
1267
1268 // Attempting to complete variable name
1269 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001270 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001271 CommandCompletions::eSettingsNameCompletion,
1272 completion_str.c_str(),
1273 match_start_point,
1274 max_return_elements,
1275 NULL,
1276 word_complete,
1277 matches);
1278
1279 return matches.GetSize();
1280}