blob: 82a49299cbed5d30c6fbbccd0da26af2a7ded953 [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{
33 bool status;
34
Greg Clayton238c0a12010-09-18 01:14:36 +000035 CommandObjectSP set_command_object (new CommandObjectSettingsSet (interpreter));
36 CommandObjectSP show_command_object (new CommandObjectSettingsShow (interpreter));
37 CommandObjectSP list_command_object (new CommandObjectSettingsList (interpreter));
38 CommandObjectSP remove_command_object (new CommandObjectSettingsRemove (interpreter));
39 CommandObjectSP replace_command_object (new CommandObjectSettingsReplace (interpreter));
40 CommandObjectSP insert_before_command_object (new CommandObjectSettingsInsertBefore (interpreter));
41 CommandObjectSP insert_after_command_object (new CommandObjectSettingsInsertAfter(interpreter));
42 CommandObjectSP append_command_object (new CommandObjectSettingsAppend(interpreter));
43 CommandObjectSP clear_command_object (new CommandObjectSettingsClear(interpreter));
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000044
Greg Clayton238c0a12010-09-18 01:14:36 +000045 status = LoadSubCommand ("set", set_command_object);
46 status = LoadSubCommand ("show", show_command_object);
47 status = LoadSubCommand ("list", list_command_object);
48 status = LoadSubCommand ("remove", remove_command_object);
49 status = LoadSubCommand ("replace", replace_command_object);
50 status = LoadSubCommand ("insert-before", insert_before_command_object);
51 status = LoadSubCommand ("insert-after", insert_after_command_object);
52 status = LoadSubCommand ("append", append_command_object);
53 status = LoadSubCommand ("clear", clear_command_object);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000054}
55
56CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
Chris Lattner24943d22010-06-08 16:52:24 +000057{
58}
59
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000060//-------------------------------------------------------------------------
61// CommandObjectSettingsSet
62//-------------------------------------------------------------------------
63
Greg Clayton238c0a12010-09-18 01:14:36 +000064CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpreter) :
65 CommandObject (interpreter,
66 "settings set",
Caroline Ticeabb507a2010-09-08 21:06:11 +000067 "Set or change the value of a single debugger setting variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +000068 NULL),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000069 m_options ()
70{
Caroline Tice43b014a2010-10-04 22:28:36 +000071 CommandArgumentEntry arg1;
72 CommandArgumentEntry arg2;
73 CommandArgumentData var_name_arg;
74 CommandArgumentData value_arg;
75
76 // Define the first (and only) variant of this arg.
77 var_name_arg.arg_type = eArgTypeSettingVariableName;
78 var_name_arg.arg_repetition = eArgRepeatPlain;
79
80 // There is only one variant this argument could be; put it into the argument entry.
81 arg1.push_back (var_name_arg);
82
83 // Define the first (and only) variant of this arg.
84 value_arg.arg_type = eArgTypeValue;
85 value_arg.arg_repetition = eArgRepeatPlain;
86
87 // There is only one variant this argument could be; put it into the argument entry.
88 arg2.push_back (value_arg);
89
90 // Push the data for the first argument into the m_arguments vector.
91 m_arguments.push_back (arg1);
92 m_arguments.push_back (arg2);
Caroline Ticed9105c22010-12-10 00:26:54 +000093
94 SetHelpLong (
95"When setting a dictionary or array variable, you can set multiple entries \n\
96at once by giving the values to the set command. For example: \n\
97\n\
98(lldb) settings set target.process.run-args value1 value2 value3 \n\
99(lldb) settings set target.process.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\
100\n\
101(lldb) settings show target.process.run-args \n\
102 [0]: 'value1' \n\
103 [1]: 'value2' \n\
104 [3]: 'value3' \n\
105(lldb) settings show target.process.env-vars \n\
106 'MYPATH=~/.:/usr/bin'\n\
107 'SOME_ENV_VAR=12345' \n\
108\n\
109Note the special syntax for setting a dictionary element: [\"<key>\"]=<value> \n\
110\n\
111Warning: The 'set' command re-sets the entire array or dictionary. If you \n\
112just want to add, remove or update individual values (or add something to \n\
113the end), use one of the other settings sub-commands: append, replace, \n\
114insert-before or insert-after.\n");
115
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000116}
117
118CommandObjectSettingsSet::~CommandObjectSettingsSet()
Chris Lattner24943d22010-06-08 16:52:24 +0000119{
120}
121
122
123bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000124CommandObjectSettingsSet::Execute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000125{
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000126 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
Chris Lattner24943d22010-06-08 16:52:24 +0000127
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000128 const int argc = command.GetArgumentCount ();
129
Caroline Tice87097232010-09-07 18:35:40 +0000130 if ((argc < 2) && (!m_options.m_reset))
Chris Lattner24943d22010-06-08 16:52:24 +0000131 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000132 result.AppendError ("'settings set' takes more arguments");
133 result.SetStatus (eReturnStatusFailed);
134 return false;
135 }
136
137 const char *var_name = command.GetArgumentAtIndex (0);
138 std::string var_name_string;
139 if ((var_name == NULL) || (var_name[0] == '\0'))
140 {
141 result.AppendError ("'settings set' command requires a valid variable name; No value supplied");
142 result.SetStatus (eReturnStatusFailed);
143 return false;
144 }
145
146 var_name_string = var_name;
147 command.Shift();
148
149 const char *var_value;
150 std::string value_string;
151
Caroline Ticed9105c22010-12-10 00:26:54 +0000152 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000153 var_value = value_string.c_str();
154
155 if (!m_options.m_reset
156 && var_value == NULL)
157 {
158 result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;"
159 " No value supplied");
Chris Lattner24943d22010-06-08 16:52:24 +0000160 result.SetStatus (eReturnStatusFailed);
161 }
162 else
163 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000164 Error err = root_settings->SetVariable (var_name_string.c_str(),
165 var_value,
Greg Claytonb3448432011-03-24 21:19:54 +0000166 eVarSetOperationAssign,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000167 m_options.m_override,
Greg Clayton238c0a12010-09-18 01:14:36 +0000168 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000169 if (err.Fail ())
170 {
171 result.AppendError (err.AsCString());
172 result.SetStatus (eReturnStatusFailed);
173 }
174 else
175 result.SetStatus (eReturnStatusSuccessFinishNoResult);
176 }
177
178 return result.Succeeded();
179}
180
181int
Greg Clayton238c0a12010-09-18 01:14:36 +0000182CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000183 int &cursor_index,
184 int &cursor_char_position,
185 OptionElementVector &opt_element_vector,
186 int match_start_point,
187 int max_return_elements,
188 bool &word_complete,
189 StringList &matches)
190{
191 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
192 completion_str.erase (cursor_char_position);
193
194 // Attempting to complete variable name
195 if (cursor_index == 1)
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);
204
205 // Attempting to complete value
206 if ((cursor_index == 2) // Partly into the variable's value
207 || (cursor_index == 1 // Or at the end of a completed valid variable name
208 && matches.GetSize() == 1
209 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
210 {
211 matches.Clear();
Greg Claytonb3448432011-03-24 21:19:54 +0000212 UserSettingsControllerSP root_settings = Debugger::GetSettingsController();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000213 if (cursor_index == 1)
214 {
215 // The user is at the end of the variable name, which is complete and valid.
216 UserSettingsController::CompleteSettingsValue (root_settings,
217 input.GetArgumentAtIndex (1), // variable name
218 NULL, // empty value string
219 word_complete,
220 matches);
221 }
222 else
223 {
224 // The user is partly into the variable value.
225 UserSettingsController::CompleteSettingsValue (root_settings,
226 input.GetArgumentAtIndex (1), // variable name
227 completion_str.c_str(), // partial value string
228 word_complete,
229 matches);
230 }
231 }
232
233 return matches.GetSize();
234}
235
236//-------------------------------------------------------------------------
237// CommandObjectSettingsSet::CommandOptions
238//-------------------------------------------------------------------------
239
240CommandObjectSettingsSet::CommandOptions::CommandOptions () :
241 Options (),
Caroline Tice1ebef442010-09-27 00:30:10 +0000242 m_override (true),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000243 m_reset (false)
244{
245}
246
247CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
248{
249}
250
Greg Claytonb3448432011-03-24 21:19:54 +0000251OptionDefinition
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000252CommandObjectSettingsSet::CommandOptions::g_option_table[] =
253{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000254 { 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." },
255 { 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." },
256 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000257};
258
Greg Claytonb3448432011-03-24 21:19:54 +0000259const OptionDefinition*
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000260CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
261{
262 return g_option_table;
263}
264
265Error
266CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
267{
268 Error error;
269 char short_option = (char) m_getopt_table[option_idx].val;
270
271 switch (short_option)
272 {
Caroline Tice1ebef442010-09-27 00:30:10 +0000273 case 'n':
274 m_override = false;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000275 break;
276 case 'r':
277 m_reset = true;
278 break;
279 default:
280 error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option);
281 break;
282 }
283
284 return error;
285}
286
287void
288CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
289{
Caroline Tice1ebef442010-09-27 00:30:10 +0000290 m_override = true;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000291 m_reset = false;
292}
293
294Options *
295CommandObjectSettingsSet::GetOptions ()
296{
297 return &m_options;
298}
299
300
301//-------------------------------------------------------------------------
302// CommandObjectSettingsShow -- Show current values
303//-------------------------------------------------------------------------
304
Greg Clayton238c0a12010-09-18 01:14:36 +0000305CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
306 CommandObject (interpreter,
307 "settings show",
308 "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 +0000309 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000310{
Caroline Tice43b014a2010-10-04 22:28:36 +0000311 CommandArgumentEntry arg1;
312 CommandArgumentData var_name_arg;
313
314 // Define the first (and only) variant of this arg.
315 var_name_arg.arg_type = eArgTypeSettingVariableName;
316 var_name_arg.arg_repetition = eArgRepeatOptional;
317
318 // There is only one variant this argument could be; put it into the argument entry.
319 arg1.push_back (var_name_arg);
320
321 // Push the data for the first argument into the m_arguments vector.
322 m_arguments.push_back (arg1);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000323}
324
325CommandObjectSettingsShow::~CommandObjectSettingsShow()
326{
327}
328
329
330bool
Caroline Tice5bc8c972010-09-20 20:44:43 +0000331CommandObjectSettingsShow::Execute (Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000332 CommandReturnObject &result)
333{
334 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
335 std::string current_prefix = root_settings->GetLevelName().AsCString();
336
337 Error err;
338
339 if (command.GetArgumentCount())
340 {
341 // The user requested to see the value of a particular variable.
Greg Claytonb3448432011-03-24 21:19:54 +0000342 SettableVariableType var_type;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000343 const char *variable_name = command.GetArgumentAtIndex (0);
Caroline Tice5bc8c972010-09-20 20:44:43 +0000344 StringList value = root_settings->GetVariable (variable_name, var_type,
345 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
346 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000347
Caroline Tice5bc8c972010-09-20 20:44:43 +0000348 if (err.Fail ())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000349 {
Caroline Tice5bc8c972010-09-20 20:44:43 +0000350 result.AppendError (err.AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000351 result.SetStatus (eReturnStatusFailed);
352
353 }
354 else
355 {
Caroline Tice4a461da2011-01-14 21:09:29 +0000356 StreamString tmp_str;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000357 char *type_name = (char *) "";
358 if (var_type != eSetVarTypeNone)
359 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000360 tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type));
361 type_name = (char *) tmp_str.GetData();
362 }
Caroline Tice5bc8c972010-09-20 20:44:43 +0000363
364 if (value.GetSize() == 0)
365 result.AppendMessageWithFormat ("%s%s = ''\n", variable_name, type_name);
Greg Claytonb3448432011-03-24 21:19:54 +0000366 else if ((var_type != eSetVarTypeArray) && (var_type != eSetVarTypeDictionary))
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000367 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
368 else
369 {
370 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
Chris Lattner0f6fa732010-09-08 22:55:31 +0000371 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000372 {
Greg Claytonb3448432011-03-24 21:19:54 +0000373 if (var_type == eSetVarTypeArray)
Caroline Ticed9105c22010-12-10 00:26:54 +0000374 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
Greg Claytonb3448432011-03-24 21:19:54 +0000375 else if (var_type == eSetVarTypeDictionary)
Caroline Ticed9105c22010-12-10 00:26:54 +0000376 result.AppendMessageWithFormat (" '%s'\n", value.GetStringAtIndex (i));
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000377 }
378 }
379 result.SetStatus (eReturnStatusSuccessFinishNoResult);
380 }
381 }
382 else
383 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000384 UserSettingsController::GetAllVariableValues (m_interpreter,
385 root_settings,
386 current_prefix,
387 result.GetOutputStream(),
388 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000389 if (err.Fail ())
390 {
391 result.AppendError (err.AsCString());
392 result.SetStatus (eReturnStatusFailed);
393 }
394 else
395 {
396 result.SetStatus (eReturnStatusSuccessFinishNoResult);
397 }
398 }
399
400 return result.Succeeded();
401}
402
403int
Greg Clayton238c0a12010-09-18 01:14:36 +0000404CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000405 int &cursor_index,
406 int &cursor_char_position,
407 OptionElementVector &opt_element_vector,
408 int match_start_point,
409 int max_return_elements,
410 bool &word_complete,
411 StringList &matches)
412{
413 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
414 completion_str.erase (cursor_char_position);
415
Greg Clayton238c0a12010-09-18 01:14:36 +0000416 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000417 CommandCompletions::eSettingsNameCompletion,
418 completion_str.c_str(),
419 match_start_point,
420 max_return_elements,
421 NULL,
422 word_complete,
423 matches);
424 return matches.GetSize();
425}
426
427//-------------------------------------------------------------------------
428// CommandObjectSettingsList
429//-------------------------------------------------------------------------
430
Greg Clayton238c0a12010-09-18 01:14:36 +0000431CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
432 CommandObject (interpreter,
433 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000434 "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 +0000435 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000436{
Caroline Tice43b014a2010-10-04 22:28:36 +0000437 CommandArgumentEntry arg;
438 CommandArgumentData var_name_arg;
439 CommandArgumentData prefix_name_arg;
440
441 // Define the first variant of this arg.
442 var_name_arg.arg_type = eArgTypeSettingVariableName;
443 var_name_arg.arg_repetition = eArgRepeatOptional;
444
445 // Define the second variant of this arg.
446 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
447 prefix_name_arg.arg_repetition = eArgRepeatOptional;
448
449 arg.push_back (var_name_arg);
450 arg.push_back (prefix_name_arg);
451
452 // Push the data for the first argument into the m_arguments vector.
453 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000454}
455
456CommandObjectSettingsList::~CommandObjectSettingsList()
457{
458}
459
460
461bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000462CommandObjectSettingsList::Execute ( Args& command,
Caroline Tice41ae2172010-09-15 06:56:39 +0000463 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000464{
465 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
466 std::string current_prefix = root_settings->GetLevelName().AsCString();
467
468 Error err;
469
Caroline Tice41ae2172010-09-15 06:56:39 +0000470 if (command.GetArgumentCount() == 0)
471 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000472 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
473 root_settings,
474 current_prefix,
475 result.GetOutputStream(),
476 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000477 }
478 else if (command.GetArgumentCount() == 1)
479 {
480 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000481 UserSettingsController::FindSettingsDescriptions (m_interpreter,
482 root_settings,
483 current_prefix,
484 search_name,
485 result.GetOutputStream(),
486 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000487 }
488 else
489 {
490 result.AppendError ("Too many aguments for 'settings list' command.\n");
491 result.SetStatus (eReturnStatusFailed);
492 return false;
493 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000494
495 if (err.Fail ())
496 {
497 result.AppendError (err.AsCString());
498 result.SetStatus (eReturnStatusFailed);
499 }
500 else
501 {
Chris Lattner24943d22010-06-08 16:52:24 +0000502 result.SetStatus (eReturnStatusSuccessFinishNoResult);
503 }
504
505 return result.Succeeded();
506}
507
Caroline Tice41ae2172010-09-15 06:56:39 +0000508int
Greg Clayton238c0a12010-09-18 01:14:36 +0000509CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000510 int &cursor_index,
511 int &cursor_char_position,
512 OptionElementVector &opt_element_vector,
513 int match_start_point,
514 int max_return_elements,
515 bool &word_complete,
516 StringList &matches)
517{
518 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
519 completion_str.erase (cursor_char_position);
520
Greg Clayton238c0a12010-09-18 01:14:36 +0000521 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000522 CommandCompletions::eSettingsNameCompletion,
523 completion_str.c_str(),
524 match_start_point,
525 max_return_elements,
526 NULL,
527 word_complete,
528 matches);
529 return matches.GetSize();
530}
531
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000532//-------------------------------------------------------------------------
533// CommandObjectSettingsRemove
534//-------------------------------------------------------------------------
535
Greg Clayton238c0a12010-09-18 01:14:36 +0000536CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
537 CommandObject (interpreter,
538 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000539 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000540 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000541{
Caroline Tice43b014a2010-10-04 22:28:36 +0000542 CommandArgumentEntry arg1;
543 CommandArgumentEntry arg2;
544 CommandArgumentData var_name_arg;
545 CommandArgumentData index_arg;
546 CommandArgumentData key_arg;
547
548 // Define the first (and only) variant of this arg.
549 var_name_arg.arg_type = eArgTypeSettingVariableName;
550 var_name_arg.arg_repetition = eArgRepeatPlain;
551
552 // There is only one variant this argument could be; put it into the argument entry.
553 arg1.push_back (var_name_arg);
554
555 // Define the first variant of this arg.
556 index_arg.arg_type = eArgTypeSettingIndex;
557 index_arg.arg_repetition = eArgRepeatPlain;
558
559 // Define the second variant of this arg.
560 key_arg.arg_type = eArgTypeSettingKey;
561 key_arg.arg_repetition = eArgRepeatPlain;
562
563 // Push both variants into this arg
564 arg2.push_back (index_arg);
565 arg2.push_back (key_arg);
566
567 // Push the data for the first argument into the m_arguments vector.
568 m_arguments.push_back (arg1);
569 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000570}
571
572CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
573{
574}
575
576bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000577CommandObjectSettingsRemove::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000578 CommandReturnObject &result)
579{
580 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
581
582 const int argc = command.GetArgumentCount ();
583
584 if (argc != 2)
585 {
586 result.AppendError ("'settings remove' takes two arguments");
587 result.SetStatus (eReturnStatusFailed);
588 return false;
589 }
590
591 const char *var_name = command.GetArgumentAtIndex (0);
592 std::string var_name_string;
593 if ((var_name == NULL) || (var_name[0] == '\0'))
594 {
595 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
596 result.SetStatus (eReturnStatusFailed);
597 return false;
598 }
599
600 var_name_string = var_name;
601 command.Shift();
602
603 const char *index_value = command.GetArgumentAtIndex (0);
604 std::string index_value_string;
605 if ((index_value == NULL) || (index_value[0] == '\0'))
606 {
607 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
608 result.SetStatus (eReturnStatusFailed);
609 return false;
610 }
611
612 index_value_string = index_value;
613
Greg Clayton238c0a12010-09-18 01:14:36 +0000614 Error err = root_settings->SetVariable (var_name_string.c_str(),
615 NULL,
Greg Claytonb3448432011-03-24 21:19:54 +0000616 eVarSetOperationRemove,
Caroline Tice1ebef442010-09-27 00:30:10 +0000617 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000618 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000619 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000620 if (err.Fail ())
621 {
622 result.AppendError (err.AsCString());
623 result.SetStatus (eReturnStatusFailed);
624 }
625 else
626 result.SetStatus (eReturnStatusSuccessFinishNoResult);
627
628 return result.Succeeded();
629}
630
631int
Greg Clayton238c0a12010-09-18 01:14:36 +0000632CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000633 int &cursor_index,
634 int &cursor_char_position,
635 OptionElementVector &opt_element_vector,
636 int match_start_point,
637 int max_return_elements,
638 bool &word_complete,
639 StringList &matches)
640{
641 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
642 completion_str.erase (cursor_char_position);
643
644 // Attempting to complete variable name
645 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000646 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000647 CommandCompletions::eSettingsNameCompletion,
648 completion_str.c_str(),
649 match_start_point,
650 max_return_elements,
651 NULL,
652 word_complete,
653 matches);
654
655 return matches.GetSize();
656}
657
658//-------------------------------------------------------------------------
659// CommandObjectSettingsReplace
660//-------------------------------------------------------------------------
661
Greg Clayton238c0a12010-09-18 01:14:36 +0000662CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
663 CommandObject (interpreter,
664 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000665 "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 +0000666 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000667{
Caroline Tice43b014a2010-10-04 22:28:36 +0000668 CommandArgumentEntry arg1;
669 CommandArgumentEntry arg2;
670 CommandArgumentEntry arg3;
671 CommandArgumentData var_name_arg;
672 CommandArgumentData index_arg;
673 CommandArgumentData key_arg;
674 CommandArgumentData value_arg;
675
676 // Define the first (and only) variant of this arg.
677 var_name_arg.arg_type = eArgTypeSettingVariableName;
678 var_name_arg.arg_repetition = eArgRepeatPlain;
679
680 // There is only one variant this argument could be; put it into the argument entry.
681 arg1.push_back (var_name_arg);
682
683 // Define the first (variant of this arg.
684 index_arg.arg_type = eArgTypeSettingIndex;
685 index_arg.arg_repetition = eArgRepeatPlain;
686
687 // Define the second (variant of this arg.
688 key_arg.arg_type = eArgTypeSettingKey;
689 key_arg.arg_repetition = eArgRepeatPlain;
690
691 // Put both variants into this arg
692 arg2.push_back (index_arg);
693 arg2.push_back (key_arg);
694
695 // Define the first (and only) variant of this arg.
696 value_arg.arg_type = eArgTypeValue;
697 value_arg.arg_repetition = eArgRepeatPlain;
698
699 // There is only one variant this argument could be; put it into the argument entry.
700 arg3.push_back (value_arg);
701
702 // Push the data for the first argument into the m_arguments vector.
703 m_arguments.push_back (arg1);
704 m_arguments.push_back (arg2);
705 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000706}
707
708CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
709{
710}
711
712bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000713CommandObjectSettingsReplace::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000714 CommandReturnObject &result)
715{
716 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
717
718 const int argc = command.GetArgumentCount ();
719
720 if (argc < 3)
721 {
722 result.AppendError ("'settings replace' takes more arguments");
723 result.SetStatus (eReturnStatusFailed);
724 return false;
725 }
726
727 const char *var_name = command.GetArgumentAtIndex (0);
728 std::string var_name_string;
729 if ((var_name == NULL) || (var_name[0] == '\0'))
730 {
731 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
732 result.SetStatus (eReturnStatusFailed);
733 return false;
734 }
735
736 var_name_string = var_name;
737 command.Shift();
738
739 const char *index_value = command.GetArgumentAtIndex (0);
740 std::string index_value_string;
741 if ((index_value == NULL) || (index_value[0] == '\0'))
742 {
743 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
744 result.SetStatus (eReturnStatusFailed);
745 return false;
746 }
747
748 index_value_string = index_value;
749 command.Shift();
750
751 const char *var_value;
752 std::string value_string;
753
Caroline Ticed9105c22010-12-10 00:26:54 +0000754 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000755 var_value = value_string.c_str();
756
757 if ((var_value == NULL) || (var_value[0] == '\0'))
758 {
759 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
760 result.SetStatus (eReturnStatusFailed);
761 }
762 else
763 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000764 Error err = root_settings->SetVariable (var_name_string.c_str(),
765 var_value,
Greg Claytonb3448432011-03-24 21:19:54 +0000766 eVarSetOperationReplace,
Caroline Tice1ebef442010-09-27 00:30:10 +0000767 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000768 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000769 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000770 if (err.Fail ())
771 {
772 result.AppendError (err.AsCString());
773 result.SetStatus (eReturnStatusFailed);
774 }
775 else
776 result.SetStatus (eReturnStatusSuccessFinishNoResult);
777 }
778
779 return result.Succeeded();
780}
781
782int
Greg Clayton238c0a12010-09-18 01:14:36 +0000783CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000784 int &cursor_index,
785 int &cursor_char_position,
786 OptionElementVector &opt_element_vector,
787 int match_start_point,
788 int max_return_elements,
789 bool &word_complete,
790 StringList &matches)
791{
792 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
793 completion_str.erase (cursor_char_position);
794
795 // Attempting to complete variable name
796 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000797 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000798 CommandCompletions::eSettingsNameCompletion,
799 completion_str.c_str(),
800 match_start_point,
801 max_return_elements,
802 NULL,
803 word_complete,
804 matches);
805
806 return matches.GetSize();
807}
808
809//-------------------------------------------------------------------------
810// CommandObjectSettingsInsertBefore
811//-------------------------------------------------------------------------
812
Greg Clayton238c0a12010-09-18 01:14:36 +0000813CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
814 CommandObject (interpreter,
815 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000816 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000817 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000818{
Caroline Tice43b014a2010-10-04 22:28:36 +0000819 CommandArgumentEntry arg1;
820 CommandArgumentEntry arg2;
821 CommandArgumentEntry arg3;
822 CommandArgumentData var_name_arg;
823 CommandArgumentData index_arg;
824 CommandArgumentData value_arg;
825
826 // Define the first (and only) variant of this arg.
827 var_name_arg.arg_type = eArgTypeSettingVariableName;
828 var_name_arg.arg_repetition = eArgRepeatPlain;
829
830 // There is only one variant this argument could be; put it into the argument entry.
831 arg1.push_back (var_name_arg);
832
833 // Define the first (variant of this arg.
834 index_arg.arg_type = eArgTypeSettingIndex;
835 index_arg.arg_repetition = eArgRepeatPlain;
836
837 // There is only one variant this argument could be; put it into the argument entry.
838 arg2.push_back (index_arg);
839
840 // Define the first (and only) variant of this arg.
841 value_arg.arg_type = eArgTypeValue;
842 value_arg.arg_repetition = eArgRepeatPlain;
843
844 // There is only one variant this argument could be; put it into the argument entry.
845 arg3.push_back (value_arg);
846
847 // Push the data for the first argument into the m_arguments vector.
848 m_arguments.push_back (arg1);
849 m_arguments.push_back (arg2);
850 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000851}
852
853CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
854{
855}
856
857bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000858CommandObjectSettingsInsertBefore::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000859 CommandReturnObject &result)
860{
861 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
862
863 const int argc = command.GetArgumentCount ();
864
865 if (argc < 3)
866 {
867 result.AppendError ("'settings insert-before' takes more arguments");
868 result.SetStatus (eReturnStatusFailed);
869 return false;
870 }
871
872 const char *var_name = command.GetArgumentAtIndex (0);
873 std::string var_name_string;
874 if ((var_name == NULL) || (var_name[0] == '\0'))
875 {
876 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
877 result.SetStatus (eReturnStatusFailed);
878 return false;
879 }
880
881 var_name_string = var_name;
882 command.Shift();
883
884 const char *index_value = command.GetArgumentAtIndex (0);
885 std::string index_value_string;
886 if ((index_value == NULL) || (index_value[0] == '\0'))
887 {
888 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
889 result.SetStatus (eReturnStatusFailed);
890 return false;
891 }
892
893 index_value_string = index_value;
894 command.Shift();
895
896 const char *var_value;
897 std::string value_string;
898
Caroline Ticed9105c22010-12-10 00:26:54 +0000899 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000900 var_value = value_string.c_str();
901
902 if ((var_value == NULL) || (var_value[0] == '\0'))
903 {
904 result.AppendError ("'settings insert-before' command requires a valid variable value;"
905 " No value supplied");
906 result.SetStatus (eReturnStatusFailed);
907 }
908 else
909 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000910 Error err = root_settings->SetVariable (var_name_string.c_str(),
911 var_value,
Greg Claytonb3448432011-03-24 21:19:54 +0000912 eVarSetOperationInsertBefore,
Caroline Tice1ebef442010-09-27 00:30:10 +0000913 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000914 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000915 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000916 if (err.Fail ())
917 {
918 result.AppendError (err.AsCString());
919 result.SetStatus (eReturnStatusFailed);
920 }
921 else
922 result.SetStatus (eReturnStatusSuccessFinishNoResult);
923 }
924
925 return result.Succeeded();
926}
927
928
929int
Greg Clayton238c0a12010-09-18 01:14:36 +0000930CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000931 int &cursor_index,
932 int &cursor_char_position,
933 OptionElementVector &opt_element_vector,
934 int match_start_point,
935 int max_return_elements,
936 bool &word_complete,
937 StringList &matches)
938{
939 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
940 completion_str.erase (cursor_char_position);
941
942 // Attempting to complete variable name
943 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000944 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000945 CommandCompletions::eSettingsNameCompletion,
946 completion_str.c_str(),
947 match_start_point,
948 max_return_elements,
949 NULL,
950 word_complete,
951 matches);
952
953 return matches.GetSize();
954}
955
956//-------------------------------------------------------------------------
957// CommandObjectSettingInsertAfter
958//-------------------------------------------------------------------------
959
Greg Clayton238c0a12010-09-18 01:14:36 +0000960CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
961 CommandObject (interpreter,
962 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000963 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000964 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000965{
Caroline Tice43b014a2010-10-04 22:28:36 +0000966 CommandArgumentEntry arg1;
967 CommandArgumentEntry arg2;
968 CommandArgumentEntry arg3;
969 CommandArgumentData var_name_arg;
970 CommandArgumentData index_arg;
971 CommandArgumentData value_arg;
972
973 // Define the first (and only) variant of this arg.
974 var_name_arg.arg_type = eArgTypeSettingVariableName;
975 var_name_arg.arg_repetition = eArgRepeatPlain;
976
977 // There is only one variant this argument could be; put it into the argument entry.
978 arg1.push_back (var_name_arg);
979
980 // Define the first (variant of this arg.
981 index_arg.arg_type = eArgTypeSettingIndex;
982 index_arg.arg_repetition = eArgRepeatPlain;
983
984 // There is only one variant this argument could be; put it into the argument entry.
985 arg2.push_back (index_arg);
986
987 // Define the first (and only) variant of this arg.
988 value_arg.arg_type = eArgTypeValue;
989 value_arg.arg_repetition = eArgRepeatPlain;
990
991 // There is only one variant this argument could be; put it into the argument entry.
992 arg3.push_back (value_arg);
993
994 // Push the data for the first argument into the m_arguments vector.
995 m_arguments.push_back (arg1);
996 m_arguments.push_back (arg2);
997 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000998}
999
1000CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
1001{
1002}
1003
1004bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001005CommandObjectSettingsInsertAfter::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001006 CommandReturnObject &result)
1007{
1008 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1009
1010 const int argc = command.GetArgumentCount ();
1011
1012 if (argc < 3)
1013 {
1014 result.AppendError ("'settings insert-after' takes more arguments");
1015 result.SetStatus (eReturnStatusFailed);
1016 return false;
1017 }
1018
1019 const char *var_name = command.GetArgumentAtIndex (0);
1020 std::string var_name_string;
1021 if ((var_name == NULL) || (var_name[0] == '\0'))
1022 {
1023 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
1024 result.SetStatus (eReturnStatusFailed);
1025 return false;
1026 }
1027
1028 var_name_string = var_name;
1029 command.Shift();
1030
1031 const char *index_value = command.GetArgumentAtIndex (0);
1032 std::string index_value_string;
1033 if ((index_value == NULL) || (index_value[0] == '\0'))
1034 {
1035 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
1036 result.SetStatus (eReturnStatusFailed);
1037 return false;
1038 }
1039
1040 index_value_string = index_value;
1041 command.Shift();
1042
1043 const char *var_value;
1044 std::string value_string;
1045
Caroline Ticed9105c22010-12-10 00:26:54 +00001046 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001047 var_value = value_string.c_str();
1048
1049 if ((var_value == NULL) || (var_value[0] == '\0'))
1050 {
1051 result.AppendError ("'settings insert-after' command requires a valid variable value;"
1052 " No value supplied");
1053 result.SetStatus (eReturnStatusFailed);
1054 }
1055 else
1056 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001057 Error err = root_settings->SetVariable (var_name_string.c_str(),
1058 var_value,
Greg Claytonb3448432011-03-24 21:19:54 +00001059 eVarSetOperationInsertAfter,
Caroline Tice1ebef442010-09-27 00:30:10 +00001060 true,
Greg Clayton238c0a12010-09-18 01:14:36 +00001061 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +00001062 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001063 if (err.Fail ())
1064 {
1065 result.AppendError (err.AsCString());
1066 result.SetStatus (eReturnStatusFailed);
1067 }
1068 else
1069 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1070 }
1071
1072 return result.Succeeded();
1073}
1074
1075
1076int
Greg Clayton238c0a12010-09-18 01:14:36 +00001077CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001078 int &cursor_index,
1079 int &cursor_char_position,
1080 OptionElementVector &opt_element_vector,
1081 int match_start_point,
1082 int max_return_elements,
1083 bool &word_complete,
1084 StringList &matches)
1085{
1086 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1087 completion_str.erase (cursor_char_position);
1088
1089 // Attempting to complete variable name
1090 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001091 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001092 CommandCompletions::eSettingsNameCompletion,
1093 completion_str.c_str(),
1094 match_start_point,
1095 max_return_elements,
1096 NULL,
1097 word_complete,
1098 matches);
1099
1100 return matches.GetSize();
1101}
1102
1103//-------------------------------------------------------------------------
1104// CommandObjectSettingsAppend
1105//-------------------------------------------------------------------------
1106
Greg Clayton238c0a12010-09-18 01:14:36 +00001107CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
1108 CommandObject (interpreter,
1109 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001110 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001111 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001112{
Caroline Tice43b014a2010-10-04 22:28:36 +00001113 CommandArgumentEntry arg1;
1114 CommandArgumentEntry arg2;
1115 CommandArgumentData var_name_arg;
1116 CommandArgumentData value_arg;
1117
1118 // Define the first (and only) variant of this arg.
1119 var_name_arg.arg_type = eArgTypeSettingVariableName;
1120 var_name_arg.arg_repetition = eArgRepeatPlain;
1121
1122 // There is only one variant this argument could be; put it into the argument entry.
1123 arg1.push_back (var_name_arg);
1124
1125 // Define the first (and only) variant of this arg.
1126 value_arg.arg_type = eArgTypeValue;
1127 value_arg.arg_repetition = eArgRepeatPlain;
1128
1129 // There is only one variant this argument could be; put it into the argument entry.
1130 arg2.push_back (value_arg);
1131
1132 // Push the data for the first argument into the m_arguments vector.
1133 m_arguments.push_back (arg1);
1134 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001135}
1136
1137CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
1138{
1139}
1140
1141bool
Caroline Tice1ebef442010-09-27 00:30:10 +00001142CommandObjectSettingsAppend::Execute (Args& command,
1143 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001144{
1145 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1146
1147 const int argc = command.GetArgumentCount ();
1148
1149 if (argc < 2)
1150 {
1151 result.AppendError ("'settings append' takes more arguments");
1152 result.SetStatus (eReturnStatusFailed);
1153 return false;
1154 }
1155
1156 const char *var_name = command.GetArgumentAtIndex (0);
1157 std::string var_name_string;
1158 if ((var_name == NULL) || (var_name[0] == '\0'))
1159 {
1160 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1161 result.SetStatus (eReturnStatusFailed);
1162 return false;
1163 }
1164
1165 var_name_string = var_name;
1166 command.Shift();
1167
1168 const char *var_value;
1169 std::string value_string;
1170
Caroline Ticed9105c22010-12-10 00:26:54 +00001171 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001172 var_value = value_string.c_str();
1173
1174 if ((var_value == NULL) || (var_value[0] == '\0'))
1175 {
1176 result.AppendError ("'settings append' command requires a valid variable value;"
1177 " No value supplied");
1178 result.SetStatus (eReturnStatusFailed);
1179 }
1180 else
1181 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001182 Error err = root_settings->SetVariable (var_name_string.c_str(),
1183 var_value,
Greg Claytonb3448432011-03-24 21:19:54 +00001184 eVarSetOperationAppend,
Caroline Tice1ebef442010-09-27 00:30:10 +00001185 true,
Greg Clayton238c0a12010-09-18 01:14:36 +00001186 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001187 if (err.Fail ())
1188 {
1189 result.AppendError (err.AsCString());
1190 result.SetStatus (eReturnStatusFailed);
1191 }
1192 else
1193 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1194 }
1195
1196 return result.Succeeded();
1197}
1198
1199
1200int
Greg Clayton238c0a12010-09-18 01:14:36 +00001201CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001202 int &cursor_index,
1203 int &cursor_char_position,
1204 OptionElementVector &opt_element_vector,
1205 int match_start_point,
1206 int max_return_elements,
1207 bool &word_complete,
1208 StringList &matches)
1209{
1210 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1211 completion_str.erase (cursor_char_position);
1212
1213 // Attempting to complete variable name
1214 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001215 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001216 CommandCompletions::eSettingsNameCompletion,
1217 completion_str.c_str(),
1218 match_start_point,
1219 max_return_elements,
1220 NULL,
1221 word_complete,
1222 matches);
1223
1224 return matches.GetSize();
1225}
1226
1227//-------------------------------------------------------------------------
1228// CommandObjectSettingsClear
1229//-------------------------------------------------------------------------
1230
Greg Clayton238c0a12010-09-18 01:14:36 +00001231CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1232 CommandObject (interpreter,
1233 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001234 "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 +00001235 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001236{
Caroline Tice43b014a2010-10-04 22:28:36 +00001237 CommandArgumentEntry arg;
1238 CommandArgumentData var_name_arg;
1239
1240 // Define the first (and only) variant of this arg.
1241 var_name_arg.arg_type = eArgTypeSettingVariableName;
1242 var_name_arg.arg_repetition = eArgRepeatPlain;
1243
1244 // There is only one variant this argument could be; put it into the argument entry.
1245 arg.push_back (var_name_arg);
1246
1247 // Push the data for the first argument into the m_arguments vector.
1248 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001249}
1250
1251CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1252{
1253}
1254
1255bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001256CommandObjectSettingsClear::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001257 CommandReturnObject &result)
1258{
1259 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1260
1261 const int argc = command.GetArgumentCount ();
1262
1263 if (argc != 1)
1264 {
1265 result.AppendError ("'setttings clear' takes exactly one argument");
1266 result.SetStatus (eReturnStatusFailed);
1267 return false;
1268 }
1269
1270 const char *var_name = command.GetArgumentAtIndex (0);
1271 if ((var_name == NULL) || (var_name[0] == '\0'))
1272 {
1273 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1274 result.SetStatus (eReturnStatusFailed);
1275 return false;
1276 }
1277
Greg Clayton238c0a12010-09-18 01:14:36 +00001278 Error err = root_settings->SetVariable (var_name,
1279 NULL,
Greg Claytonb3448432011-03-24 21:19:54 +00001280 eVarSetOperationClear,
Greg Clayton238c0a12010-09-18 01:14:36 +00001281 false,
1282 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001283
1284 if (err.Fail ())
1285 {
1286 result.AppendError (err.AsCString());
1287 result.SetStatus (eReturnStatusFailed);
1288 }
1289 else
1290 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1291
1292 return result.Succeeded();
1293}
1294
1295
1296int
Greg Clayton238c0a12010-09-18 01:14:36 +00001297CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001298 int &cursor_index,
1299 int &cursor_char_position,
1300 OptionElementVector &opt_element_vector,
1301 int match_start_point,
1302 int max_return_elements,
1303 bool &word_complete,
1304 StringList &matches)
1305{
1306 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1307 completion_str.erase (cursor_char_position);
1308
1309 // Attempting to complete variable name
1310 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001311 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001312 CommandCompletions::eSettingsNameCompletion,
1313 completion_str.c_str(),
1314 match_start_point,
1315 max_return_elements,
1316 NULL,
1317 word_complete,
1318 matches);
1319
1320 return matches.GetSize();
1321}