blob: 1a2ce9d835f39b62cf3a9add5d6155b6c5b2c8a0 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectSettings.cpp -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectSettings.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Interpreter/CommandInterpreter.h"
17#include "lldb/Interpreter/CommandReturnObject.h"
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000018#include "lldb/Interpreter/CommandCompletions.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019
20using namespace lldb;
21using namespace lldb_private;
22
23//-------------------------------------------------------------------------
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000024// CommandObjectMultiwordSettings
Chris Lattner24943d22010-06-08 16:52:24 +000025//-------------------------------------------------------------------------
26
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000027CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +000028 CommandObjectMultiword (interpreter,
29 "settings",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000030 "A set of commands for manipulating internal settable debugger variables.",
31 "settings <command> [<command-options>]")
32{
Greg Clayton41c56fa2011-04-19 22:32:36 +000033 LoadSubCommand ("set", CommandObjectSP (new CommandObjectSettingsSet (interpreter)));
34 LoadSubCommand ("show", CommandObjectSP (new CommandObjectSettingsShow (interpreter)));
35 LoadSubCommand ("list", CommandObjectSP (new CommandObjectSettingsList (interpreter)));
36 LoadSubCommand ("remove", CommandObjectSP (new CommandObjectSettingsRemove (interpreter)));
37 LoadSubCommand ("replace", CommandObjectSP (new CommandObjectSettingsReplace (interpreter)));
38 LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter)));
39 LoadSubCommand ("insert-after", CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter)));
40 LoadSubCommand ("append", CommandObjectSP (new CommandObjectSettingsAppend (interpreter)));
41 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectSettingsClear (interpreter)));
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000042}
43
44CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
Chris Lattner24943d22010-06-08 16:52:24 +000045{
46}
47
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000048//-------------------------------------------------------------------------
49// CommandObjectSettingsSet
50//-------------------------------------------------------------------------
51
Greg Clayton238c0a12010-09-18 01:14:36 +000052CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpreter) :
53 CommandObject (interpreter,
54 "settings set",
Caroline Ticeabb507a2010-09-08 21:06:11 +000055 "Set or change the value of a single debugger setting variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +000056 NULL),
Greg Claytonf15996e2011-04-07 22:46:35 +000057 m_options (interpreter)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000058{
Caroline Tice43b014a2010-10-04 22:28:36 +000059 CommandArgumentEntry arg1;
60 CommandArgumentEntry arg2;
61 CommandArgumentData var_name_arg;
62 CommandArgumentData value_arg;
63
64 // Define the first (and only) variant of this arg.
65 var_name_arg.arg_type = eArgTypeSettingVariableName;
66 var_name_arg.arg_repetition = eArgRepeatPlain;
67
68 // There is only one variant this argument could be; put it into the argument entry.
69 arg1.push_back (var_name_arg);
70
71 // Define the first (and only) variant of this arg.
72 value_arg.arg_type = eArgTypeValue;
73 value_arg.arg_repetition = eArgRepeatPlain;
74
75 // There is only one variant this argument could be; put it into the argument entry.
76 arg2.push_back (value_arg);
77
78 // Push the data for the first argument into the m_arguments vector.
79 m_arguments.push_back (arg1);
80 m_arguments.push_back (arg2);
Caroline Ticed9105c22010-12-10 00:26:54 +000081
82 SetHelpLong (
83"When setting a dictionary or array variable, you can set multiple entries \n\
84at once by giving the values to the set command. For example: \n\
85\n\
Greg Claytonabb33022011-11-08 02:43:13 +000086(lldb) settings set target.run-args value1 value2 value3 \n\
87(lldb) settings set target.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\
Caroline Ticed9105c22010-12-10 00:26:54 +000088\n\
Greg Claytonabb33022011-11-08 02:43:13 +000089(lldb) settings show target.run-args \n\
Caroline Ticed9105c22010-12-10 00:26:54 +000090 [0]: 'value1' \n\
91 [1]: 'value2' \n\
92 [3]: 'value3' \n\
Greg Claytonabb33022011-11-08 02:43:13 +000093(lldb) settings show target.env-vars \n\
Caroline Ticed9105c22010-12-10 00:26:54 +000094 'MYPATH=~/.:/usr/bin'\n\
95 'SOME_ENV_VAR=12345' \n\
96\n\
97Note the special syntax for setting a dictionary element: [\"<key>\"]=<value> \n\
98\n\
99Warning: The 'set' command re-sets the entire array or dictionary. If you \n\
100just want to add, remove or update individual values (or add something to \n\
101the end), use one of the other settings sub-commands: append, replace, \n\
102insert-before or insert-after.\n");
103
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000104}
105
106CommandObjectSettingsSet::~CommandObjectSettingsSet()
Chris Lattner24943d22010-06-08 16:52:24 +0000107{
108}
109
110
Johnny Chena1b0ce12012-01-19 19:22:41 +0000111#include "llvm/ADT/StringRef.h"
112static inline void StripLeadingSpaces(llvm::StringRef &Str)
113{
114 while (!Str.empty() && isspace(Str[0]))
115 Str = Str.substr(1);
116}
Chris Lattner24943d22010-06-08 16:52:24 +0000117bool
Johnny Chena1b0ce12012-01-19 19:22:41 +0000118CommandObjectSettingsSet::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000119{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000120 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Chris Lattner24943d22010-06-08 16:52:24 +0000121
Johnny Chena1b0ce12012-01-19 19:22:41 +0000122 Args cmd_args(raw_command);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000123
Johnny Chena1b0ce12012-01-19 19:22:41 +0000124 // Process possible options.
125 if (!ParseOptions (cmd_args, result))
126 return false;
127
128 const int argc = cmd_args.GetArgumentCount ();
Caroline Tice87097232010-09-07 18:35:40 +0000129 if ((argc < 2) && (!m_options.m_reset))
Chris Lattner24943d22010-06-08 16:52:24 +0000130 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000131 result.AppendError ("'settings set' takes more arguments");
132 result.SetStatus (eReturnStatusFailed);
133 return false;
134 }
135
Johnny Chena1b0ce12012-01-19 19:22:41 +0000136 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000137 if ((var_name == NULL) || (var_name[0] == '\0'))
138 {
139 result.AppendError ("'settings set' command requires a valid variable name; No value supplied");
140 result.SetStatus (eReturnStatusFailed);
141 return false;
142 }
143
Johnny Chena1b0ce12012-01-19 19:22:41 +0000144 // Split the raw command into var_name and value pair.
145 std::string var_name_string = var_name;
146 llvm::StringRef raw_str(raw_command);
147 llvm::StringRef value_str = raw_str.split(var_name_string).second;
148 StripLeadingSpaces(value_str);
149 std::string value_string = value_str.str();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000150
151 if (!m_options.m_reset
Johnny Chena1b0ce12012-01-19 19:22:41 +0000152 && value_string.empty())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000153 {
154 result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;"
155 " No value supplied");
Chris Lattner24943d22010-06-08 16:52:24 +0000156 result.SetStatus (eReturnStatusFailed);
157 }
158 else
159 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000160 Error err = usc_sp->SetVariable (var_name_string.c_str(),
Johnny Chena1b0ce12012-01-19 19:22:41 +0000161 value_string.c_str(),
Greg Clayton41c56fa2011-04-19 22:32:36 +0000162 eVarSetOperationAssign,
163 m_options.m_override,
164 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000165 if (err.Fail ())
166 {
167 result.AppendError (err.AsCString());
168 result.SetStatus (eReturnStatusFailed);
169 }
170 else
171 result.SetStatus (eReturnStatusSuccessFinishNoResult);
172 }
173
174 return result.Succeeded();
175}
176
177int
Greg Clayton238c0a12010-09-18 01:14:36 +0000178CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000179 int &cursor_index,
180 int &cursor_char_position,
181 OptionElementVector &opt_element_vector,
182 int match_start_point,
183 int max_return_elements,
184 bool &word_complete,
185 StringList &matches)
186{
187 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
188 completion_str.erase (cursor_char_position);
189
190 // Attempting to complete variable name
191 if (cursor_index == 1)
Greg Clayton238c0a12010-09-18 01:14:36 +0000192 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000193 CommandCompletions::eSettingsNameCompletion,
194 completion_str.c_str(),
195 match_start_point,
196 max_return_elements,
197 NULL,
198 word_complete,
199 matches);
200
201 // Attempting to complete value
202 if ((cursor_index == 2) // Partly into the variable's value
203 || (cursor_index == 1 // Or at the end of a completed valid variable name
204 && matches.GetSize() == 1
205 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
206 {
207 matches.Clear();
Greg Clayton41c56fa2011-04-19 22:32:36 +0000208 UserSettingsControllerSP usc_sp = Debugger::GetSettingsController();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000209 if (cursor_index == 1)
210 {
211 // The user is at the end of the variable name, which is complete and valid.
Greg Clayton41c56fa2011-04-19 22:32:36 +0000212 UserSettingsController::CompleteSettingsValue (usc_sp,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000213 input.GetArgumentAtIndex (1), // variable name
214 NULL, // empty value string
215 word_complete,
216 matches);
217 }
218 else
219 {
220 // The user is partly into the variable value.
Greg Clayton41c56fa2011-04-19 22:32:36 +0000221 UserSettingsController::CompleteSettingsValue (usc_sp,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000222 input.GetArgumentAtIndex (1), // variable name
223 completion_str.c_str(), // partial value string
224 word_complete,
225 matches);
226 }
227 }
228
229 return matches.GetSize();
230}
231
232//-------------------------------------------------------------------------
233// CommandObjectSettingsSet::CommandOptions
234//-------------------------------------------------------------------------
235
Greg Claytonf15996e2011-04-07 22:46:35 +0000236CommandObjectSettingsSet::CommandOptions::CommandOptions (CommandInterpreter &interpreter) :
237 Options (interpreter),
Caroline Tice1ebef442010-09-27 00:30:10 +0000238 m_override (true),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000239 m_reset (false)
240{
241}
242
243CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
244{
245}
246
Greg Claytonb3448432011-03-24 21:19:54 +0000247OptionDefinition
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000248CommandObjectSettingsSet::CommandOptions::g_option_table[] =
249{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000250 { 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." },
251 { 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." },
252 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000253};
254
Greg Claytonb3448432011-03-24 21:19:54 +0000255const OptionDefinition*
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000256CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
257{
258 return g_option_table;
259}
260
261Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000262CommandObjectSettingsSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000263{
264 Error error;
265 char short_option = (char) m_getopt_table[option_idx].val;
266
267 switch (short_option)
268 {
Caroline Tice1ebef442010-09-27 00:30:10 +0000269 case 'n':
270 m_override = false;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000271 break;
272 case 'r':
273 m_reset = true;
274 break;
275 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000276 error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000277 break;
278 }
279
280 return error;
281}
282
283void
Greg Clayton143fcc32011-04-13 00:18:08 +0000284CommandObjectSettingsSet::CommandOptions::OptionParsingStarting ()
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000285{
Caroline Tice1ebef442010-09-27 00:30:10 +0000286 m_override = true;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000287 m_reset = false;
288}
289
290Options *
291CommandObjectSettingsSet::GetOptions ()
292{
293 return &m_options;
294}
295
296
297//-------------------------------------------------------------------------
298// CommandObjectSettingsShow -- Show current values
299//-------------------------------------------------------------------------
300
Greg Clayton238c0a12010-09-18 01:14:36 +0000301CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
302 CommandObject (interpreter,
303 "settings show",
304 "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 +0000305 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000306{
Caroline Tice43b014a2010-10-04 22:28:36 +0000307 CommandArgumentEntry arg1;
308 CommandArgumentData var_name_arg;
309
310 // Define the first (and only) variant of this arg.
311 var_name_arg.arg_type = eArgTypeSettingVariableName;
312 var_name_arg.arg_repetition = eArgRepeatOptional;
313
314 // There is only one variant this argument could be; put it into the argument entry.
315 arg1.push_back (var_name_arg);
316
317 // Push the data for the first argument into the m_arguments vector.
318 m_arguments.push_back (arg1);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000319}
320
321CommandObjectSettingsShow::~CommandObjectSettingsShow()
322{
323}
324
325
326bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000327CommandObjectSettingsShow::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000328{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000329 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
330 const char *current_prefix = usc_sp->GetLevelName().GetCString();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000331
332 Error err;
333
334 if (command.GetArgumentCount())
335 {
336 // The user requested to see the value of a particular variable.
Greg Claytonb3448432011-03-24 21:19:54 +0000337 SettableVariableType var_type;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000338 const char *variable_name = command.GetArgumentAtIndex (0);
Greg Clayton41c56fa2011-04-19 22:32:36 +0000339 StringList value = usc_sp->GetVariable (variable_name,
340 var_type,
341 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
342 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000343
Caroline Tice5bc8c972010-09-20 20:44:43 +0000344 if (err.Fail ())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000345 {
Caroline Tice5bc8c972010-09-20 20:44:43 +0000346 result.AppendError (err.AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000347 result.SetStatus (eReturnStatusFailed);
348
Greg Clayton41c56fa2011-04-19 22:32:36 +0000349 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000350 else
351 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000352 UserSettingsController::DumpValue(m_interpreter, usc_sp, variable_name, result.GetOutputStream());
353 result.SetStatus (eReturnStatusSuccessFinishResult);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000354 }
355 }
356 else
357 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000358 UserSettingsController::GetAllVariableValues (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000359 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000360 current_prefix,
361 result.GetOutputStream(),
362 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000363 if (err.Fail ())
364 {
365 result.AppendError (err.AsCString());
366 result.SetStatus (eReturnStatusFailed);
367 }
368 else
369 {
370 result.SetStatus (eReturnStatusSuccessFinishNoResult);
371 }
372 }
373
374 return result.Succeeded();
375}
376
377int
Greg Clayton238c0a12010-09-18 01:14:36 +0000378CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000379 int &cursor_index,
380 int &cursor_char_position,
381 OptionElementVector &opt_element_vector,
382 int match_start_point,
383 int max_return_elements,
384 bool &word_complete,
385 StringList &matches)
386{
387 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
388 completion_str.erase (cursor_char_position);
389
Greg Clayton238c0a12010-09-18 01:14:36 +0000390 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000391 CommandCompletions::eSettingsNameCompletion,
392 completion_str.c_str(),
393 match_start_point,
394 max_return_elements,
395 NULL,
396 word_complete,
397 matches);
398 return matches.GetSize();
399}
400
401//-------------------------------------------------------------------------
402// CommandObjectSettingsList
403//-------------------------------------------------------------------------
404
Greg Clayton238c0a12010-09-18 01:14:36 +0000405CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
406 CommandObject (interpreter,
407 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000408 "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 +0000409 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000410{
Caroline Tice43b014a2010-10-04 22:28:36 +0000411 CommandArgumentEntry arg;
412 CommandArgumentData var_name_arg;
413 CommandArgumentData prefix_name_arg;
414
415 // Define the first variant of this arg.
416 var_name_arg.arg_type = eArgTypeSettingVariableName;
417 var_name_arg.arg_repetition = eArgRepeatOptional;
418
419 // Define the second variant of this arg.
420 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
421 prefix_name_arg.arg_repetition = eArgRepeatOptional;
422
423 arg.push_back (var_name_arg);
424 arg.push_back (prefix_name_arg);
425
426 // Push the data for the first argument into the m_arguments vector.
427 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000428}
429
430CommandObjectSettingsList::~CommandObjectSettingsList()
431{
432}
433
434
435bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000436CommandObjectSettingsList::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000437{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000438 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
439 const char *current_prefix = usc_sp->GetLevelName().GetCString();
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000440
441 Error err;
442
Caroline Tice41ae2172010-09-15 06:56:39 +0000443 if (command.GetArgumentCount() == 0)
444 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000445 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000446 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000447 current_prefix,
448 result.GetOutputStream(),
449 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000450 }
451 else if (command.GetArgumentCount() == 1)
452 {
453 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000454 UserSettingsController::FindSettingsDescriptions (m_interpreter,
Greg Clayton41c56fa2011-04-19 22:32:36 +0000455 usc_sp,
Greg Clayton238c0a12010-09-18 01:14:36 +0000456 current_prefix,
457 search_name,
458 result.GetOutputStream(),
459 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000460 }
461 else
462 {
463 result.AppendError ("Too many aguments for 'settings list' command.\n");
464 result.SetStatus (eReturnStatusFailed);
465 return false;
466 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000467
468 if (err.Fail ())
469 {
470 result.AppendError (err.AsCString());
471 result.SetStatus (eReturnStatusFailed);
472 }
473 else
474 {
Chris Lattner24943d22010-06-08 16:52:24 +0000475 result.SetStatus (eReturnStatusSuccessFinishNoResult);
476 }
477
478 return result.Succeeded();
479}
480
Caroline Tice41ae2172010-09-15 06:56:39 +0000481int
Greg Clayton238c0a12010-09-18 01:14:36 +0000482CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000483 int &cursor_index,
484 int &cursor_char_position,
485 OptionElementVector &opt_element_vector,
486 int match_start_point,
487 int max_return_elements,
488 bool &word_complete,
489 StringList &matches)
490{
491 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
492 completion_str.erase (cursor_char_position);
493
Greg Clayton238c0a12010-09-18 01:14:36 +0000494 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000495 CommandCompletions::eSettingsNameCompletion,
496 completion_str.c_str(),
497 match_start_point,
498 max_return_elements,
499 NULL,
500 word_complete,
501 matches);
502 return matches.GetSize();
503}
504
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000505//-------------------------------------------------------------------------
506// CommandObjectSettingsRemove
507//-------------------------------------------------------------------------
508
Greg Clayton238c0a12010-09-18 01:14:36 +0000509CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
510 CommandObject (interpreter,
511 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000512 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000513 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000514{
Caroline Tice43b014a2010-10-04 22:28:36 +0000515 CommandArgumentEntry arg1;
516 CommandArgumentEntry arg2;
517 CommandArgumentData var_name_arg;
518 CommandArgumentData index_arg;
519 CommandArgumentData key_arg;
520
521 // Define the first (and only) variant of this arg.
522 var_name_arg.arg_type = eArgTypeSettingVariableName;
523 var_name_arg.arg_repetition = eArgRepeatPlain;
524
525 // There is only one variant this argument could be; put it into the argument entry.
526 arg1.push_back (var_name_arg);
527
528 // Define the first variant of this arg.
529 index_arg.arg_type = eArgTypeSettingIndex;
530 index_arg.arg_repetition = eArgRepeatPlain;
531
532 // Define the second variant of this arg.
533 key_arg.arg_type = eArgTypeSettingKey;
534 key_arg.arg_repetition = eArgRepeatPlain;
535
536 // Push both variants into this arg
537 arg2.push_back (index_arg);
538 arg2.push_back (key_arg);
539
540 // Push the data for the first argument into the m_arguments vector.
541 m_arguments.push_back (arg1);
542 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000543}
544
545CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
546{
547}
548
549bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000550CommandObjectSettingsRemove::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000551{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000552 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000553
554 const int argc = command.GetArgumentCount ();
555
556 if (argc != 2)
557 {
558 result.AppendError ("'settings remove' takes two arguments");
559 result.SetStatus (eReturnStatusFailed);
560 return false;
561 }
562
563 const char *var_name = command.GetArgumentAtIndex (0);
564 std::string var_name_string;
565 if ((var_name == NULL) || (var_name[0] == '\0'))
566 {
567 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
568 result.SetStatus (eReturnStatusFailed);
569 return false;
570 }
571
572 var_name_string = var_name;
573 command.Shift();
574
575 const char *index_value = command.GetArgumentAtIndex (0);
576 std::string index_value_string;
577 if ((index_value == NULL) || (index_value[0] == '\0'))
578 {
579 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
580 result.SetStatus (eReturnStatusFailed);
581 return false;
582 }
583
584 index_value_string = index_value;
585
Greg Clayton41c56fa2011-04-19 22:32:36 +0000586 Error err = usc_sp->SetVariable (var_name_string.c_str(),
587 NULL,
588 eVarSetOperationRemove,
589 true,
590 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
591 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000592 if (err.Fail ())
593 {
594 result.AppendError (err.AsCString());
595 result.SetStatus (eReturnStatusFailed);
596 }
597 else
598 result.SetStatus (eReturnStatusSuccessFinishNoResult);
599
600 return result.Succeeded();
601}
602
603int
Greg Clayton238c0a12010-09-18 01:14:36 +0000604CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000605 int &cursor_index,
606 int &cursor_char_position,
607 OptionElementVector &opt_element_vector,
608 int match_start_point,
609 int max_return_elements,
610 bool &word_complete,
611 StringList &matches)
612{
613 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
614 completion_str.erase (cursor_char_position);
615
616 // Attempting to complete variable name
617 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000618 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000619 CommandCompletions::eSettingsNameCompletion,
620 completion_str.c_str(),
621 match_start_point,
622 max_return_elements,
623 NULL,
624 word_complete,
625 matches);
626
627 return matches.GetSize();
628}
629
630//-------------------------------------------------------------------------
631// CommandObjectSettingsReplace
632//-------------------------------------------------------------------------
633
Greg Clayton238c0a12010-09-18 01:14:36 +0000634CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
635 CommandObject (interpreter,
636 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000637 "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 +0000638 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000639{
Caroline Tice43b014a2010-10-04 22:28:36 +0000640 CommandArgumentEntry arg1;
641 CommandArgumentEntry arg2;
642 CommandArgumentEntry arg3;
643 CommandArgumentData var_name_arg;
644 CommandArgumentData index_arg;
645 CommandArgumentData key_arg;
646 CommandArgumentData value_arg;
647
648 // Define the first (and only) variant of this arg.
649 var_name_arg.arg_type = eArgTypeSettingVariableName;
650 var_name_arg.arg_repetition = eArgRepeatPlain;
651
652 // There is only one variant this argument could be; put it into the argument entry.
653 arg1.push_back (var_name_arg);
654
655 // Define the first (variant of this arg.
656 index_arg.arg_type = eArgTypeSettingIndex;
657 index_arg.arg_repetition = eArgRepeatPlain;
658
659 // Define the second (variant of this arg.
660 key_arg.arg_type = eArgTypeSettingKey;
661 key_arg.arg_repetition = eArgRepeatPlain;
662
663 // Put both variants into this arg
664 arg2.push_back (index_arg);
665 arg2.push_back (key_arg);
666
667 // Define the first (and only) variant of this arg.
668 value_arg.arg_type = eArgTypeValue;
669 value_arg.arg_repetition = eArgRepeatPlain;
670
671 // There is only one variant this argument could be; put it into the argument entry.
672 arg3.push_back (value_arg);
673
674 // Push the data for the first argument into the m_arguments vector.
675 m_arguments.push_back (arg1);
676 m_arguments.push_back (arg2);
677 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000678}
679
680CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
681{
682}
683
684bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000685CommandObjectSettingsReplace::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000686{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000687 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000688
689 const int argc = command.GetArgumentCount ();
690
691 if (argc < 3)
692 {
693 result.AppendError ("'settings replace' takes more arguments");
694 result.SetStatus (eReturnStatusFailed);
695 return false;
696 }
697
698 const char *var_name = command.GetArgumentAtIndex (0);
699 std::string var_name_string;
700 if ((var_name == NULL) || (var_name[0] == '\0'))
701 {
702 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
703 result.SetStatus (eReturnStatusFailed);
704 return false;
705 }
706
707 var_name_string = var_name;
708 command.Shift();
709
710 const char *index_value = command.GetArgumentAtIndex (0);
711 std::string index_value_string;
712 if ((index_value == NULL) || (index_value[0] == '\0'))
713 {
714 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
715 result.SetStatus (eReturnStatusFailed);
716 return false;
717 }
718
719 index_value_string = index_value;
720 command.Shift();
721
722 const char *var_value;
723 std::string value_string;
724
Caroline Ticed9105c22010-12-10 00:26:54 +0000725 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000726 var_value = value_string.c_str();
727
728 if ((var_value == NULL) || (var_value[0] == '\0'))
729 {
730 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
731 result.SetStatus (eReturnStatusFailed);
732 }
733 else
734 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000735 Error err = usc_sp->SetVariable (var_name_string.c_str(),
736 var_value,
737 eVarSetOperationReplace,
738 true,
739 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
740 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000741 if (err.Fail ())
742 {
743 result.AppendError (err.AsCString());
744 result.SetStatus (eReturnStatusFailed);
745 }
746 else
747 result.SetStatus (eReturnStatusSuccessFinishNoResult);
748 }
749
750 return result.Succeeded();
751}
752
753int
Greg Clayton238c0a12010-09-18 01:14:36 +0000754CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000755 int &cursor_index,
756 int &cursor_char_position,
757 OptionElementVector &opt_element_vector,
758 int match_start_point,
759 int max_return_elements,
760 bool &word_complete,
761 StringList &matches)
762{
763 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
764 completion_str.erase (cursor_char_position);
765
766 // Attempting to complete variable name
767 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000768 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000769 CommandCompletions::eSettingsNameCompletion,
770 completion_str.c_str(),
771 match_start_point,
772 max_return_elements,
773 NULL,
774 word_complete,
775 matches);
776
777 return matches.GetSize();
778}
779
780//-------------------------------------------------------------------------
781// CommandObjectSettingsInsertBefore
782//-------------------------------------------------------------------------
783
Greg Clayton238c0a12010-09-18 01:14:36 +0000784CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
785 CommandObject (interpreter,
786 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000787 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000788 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000789{
Caroline Tice43b014a2010-10-04 22:28:36 +0000790 CommandArgumentEntry arg1;
791 CommandArgumentEntry arg2;
792 CommandArgumentEntry arg3;
793 CommandArgumentData var_name_arg;
794 CommandArgumentData index_arg;
795 CommandArgumentData value_arg;
796
797 // Define the first (and only) variant of this arg.
798 var_name_arg.arg_type = eArgTypeSettingVariableName;
799 var_name_arg.arg_repetition = eArgRepeatPlain;
800
801 // There is only one variant this argument could be; put it into the argument entry.
802 arg1.push_back (var_name_arg);
803
804 // Define the first (variant of this arg.
805 index_arg.arg_type = eArgTypeSettingIndex;
806 index_arg.arg_repetition = eArgRepeatPlain;
807
808 // There is only one variant this argument could be; put it into the argument entry.
809 arg2.push_back (index_arg);
810
811 // Define the first (and only) variant of this arg.
812 value_arg.arg_type = eArgTypeValue;
813 value_arg.arg_repetition = eArgRepeatPlain;
814
815 // There is only one variant this argument could be; put it into the argument entry.
816 arg3.push_back (value_arg);
817
818 // Push the data for the first argument into the m_arguments vector.
819 m_arguments.push_back (arg1);
820 m_arguments.push_back (arg2);
821 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000822}
823
824CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
825{
826}
827
828bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000829CommandObjectSettingsInsertBefore::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000830{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000831 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000832
833 const int argc = command.GetArgumentCount ();
834
835 if (argc < 3)
836 {
837 result.AppendError ("'settings insert-before' takes more arguments");
838 result.SetStatus (eReturnStatusFailed);
839 return false;
840 }
841
842 const char *var_name = command.GetArgumentAtIndex (0);
843 std::string var_name_string;
844 if ((var_name == NULL) || (var_name[0] == '\0'))
845 {
846 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
847 result.SetStatus (eReturnStatusFailed);
848 return false;
849 }
850
851 var_name_string = var_name;
852 command.Shift();
853
854 const char *index_value = command.GetArgumentAtIndex (0);
855 std::string index_value_string;
856 if ((index_value == NULL) || (index_value[0] == '\0'))
857 {
858 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
859 result.SetStatus (eReturnStatusFailed);
860 return false;
861 }
862
863 index_value_string = index_value;
864 command.Shift();
865
866 const char *var_value;
867 std::string value_string;
868
Caroline Ticed9105c22010-12-10 00:26:54 +0000869 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000870 var_value = value_string.c_str();
871
872 if ((var_value == NULL) || (var_value[0] == '\0'))
873 {
874 result.AppendError ("'settings insert-before' command requires a valid variable value;"
875 " No value supplied");
876 result.SetStatus (eReturnStatusFailed);
877 }
878 else
879 {
Greg Clayton41c56fa2011-04-19 22:32:36 +0000880 Error err = usc_sp->SetVariable (var_name_string.c_str(),
881 var_value,
882 eVarSetOperationInsertBefore,
883 true,
884 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
885 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000886 if (err.Fail ())
887 {
888 result.AppendError (err.AsCString());
889 result.SetStatus (eReturnStatusFailed);
890 }
891 else
892 result.SetStatus (eReturnStatusSuccessFinishNoResult);
893 }
894
895 return result.Succeeded();
896}
897
898
899int
Greg Clayton238c0a12010-09-18 01:14:36 +0000900CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000901 int &cursor_index,
902 int &cursor_char_position,
903 OptionElementVector &opt_element_vector,
904 int match_start_point,
905 int max_return_elements,
906 bool &word_complete,
907 StringList &matches)
908{
909 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
910 completion_str.erase (cursor_char_position);
911
912 // Attempting to complete variable name
913 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000914 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000915 CommandCompletions::eSettingsNameCompletion,
916 completion_str.c_str(),
917 match_start_point,
918 max_return_elements,
919 NULL,
920 word_complete,
921 matches);
922
923 return matches.GetSize();
924}
925
926//-------------------------------------------------------------------------
927// CommandObjectSettingInsertAfter
928//-------------------------------------------------------------------------
929
Greg Clayton238c0a12010-09-18 01:14:36 +0000930CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
931 CommandObject (interpreter,
932 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000933 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000934 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000935{
Caroline Tice43b014a2010-10-04 22:28:36 +0000936 CommandArgumentEntry arg1;
937 CommandArgumentEntry arg2;
938 CommandArgumentEntry arg3;
939 CommandArgumentData var_name_arg;
940 CommandArgumentData index_arg;
941 CommandArgumentData value_arg;
942
943 // Define the first (and only) variant of this arg.
944 var_name_arg.arg_type = eArgTypeSettingVariableName;
945 var_name_arg.arg_repetition = eArgRepeatPlain;
946
947 // There is only one variant this argument could be; put it into the argument entry.
948 arg1.push_back (var_name_arg);
949
950 // Define the first (variant of this arg.
951 index_arg.arg_type = eArgTypeSettingIndex;
952 index_arg.arg_repetition = eArgRepeatPlain;
953
954 // There is only one variant this argument could be; put it into the argument entry.
955 arg2.push_back (index_arg);
956
957 // Define the first (and only) variant of this arg.
958 value_arg.arg_type = eArgTypeValue;
959 value_arg.arg_repetition = eArgRepeatPlain;
960
961 // There is only one variant this argument could be; put it into the argument entry.
962 arg3.push_back (value_arg);
963
964 // Push the data for the first argument into the m_arguments vector.
965 m_arguments.push_back (arg1);
966 m_arguments.push_back (arg2);
967 m_arguments.push_back (arg3);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000968}
969
970CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
971{
972}
973
974bool
Greg Clayton41c56fa2011-04-19 22:32:36 +0000975CommandObjectSettingsInsertAfter::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000976{
Greg Clayton41c56fa2011-04-19 22:32:36 +0000977 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000978
979 const int argc = command.GetArgumentCount ();
980
981 if (argc < 3)
982 {
983 result.AppendError ("'settings insert-after' takes more arguments");
984 result.SetStatus (eReturnStatusFailed);
985 return false;
986 }
987
988 const char *var_name = command.GetArgumentAtIndex (0);
989 std::string var_name_string;
990 if ((var_name == NULL) || (var_name[0] == '\0'))
991 {
992 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
993 result.SetStatus (eReturnStatusFailed);
994 return false;
995 }
996
997 var_name_string = var_name;
998 command.Shift();
999
1000 const char *index_value = command.GetArgumentAtIndex (0);
1001 std::string index_value_string;
1002 if ((index_value == NULL) || (index_value[0] == '\0'))
1003 {
1004 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
1005 result.SetStatus (eReturnStatusFailed);
1006 return false;
1007 }
1008
1009 index_value_string = index_value;
1010 command.Shift();
1011
1012 const char *var_value;
1013 std::string value_string;
1014
Caroline Ticed9105c22010-12-10 00:26:54 +00001015 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001016 var_value = value_string.c_str();
1017
1018 if ((var_value == NULL) || (var_value[0] == '\0'))
1019 {
1020 result.AppendError ("'settings insert-after' command requires a valid variable value;"
1021 " No value supplied");
1022 result.SetStatus (eReturnStatusFailed);
1023 }
1024 else
1025 {
Greg Clayton41c56fa2011-04-19 22:32:36 +00001026 Error err = usc_sp->SetVariable (var_name_string.c_str(),
1027 var_value,
1028 eVarSetOperationInsertAfter,
1029 true,
1030 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
1031 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001032 if (err.Fail ())
1033 {
1034 result.AppendError (err.AsCString());
1035 result.SetStatus (eReturnStatusFailed);
1036 }
1037 else
1038 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1039 }
1040
1041 return result.Succeeded();
1042}
1043
1044
1045int
Greg Clayton238c0a12010-09-18 01:14:36 +00001046CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001047 int &cursor_index,
1048 int &cursor_char_position,
1049 OptionElementVector &opt_element_vector,
1050 int match_start_point,
1051 int max_return_elements,
1052 bool &word_complete,
1053 StringList &matches)
1054{
1055 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1056 completion_str.erase (cursor_char_position);
1057
1058 // Attempting to complete variable name
1059 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001060 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001061 CommandCompletions::eSettingsNameCompletion,
1062 completion_str.c_str(),
1063 match_start_point,
1064 max_return_elements,
1065 NULL,
1066 word_complete,
1067 matches);
1068
1069 return matches.GetSize();
1070}
1071
1072//-------------------------------------------------------------------------
1073// CommandObjectSettingsAppend
1074//-------------------------------------------------------------------------
1075
Greg Clayton238c0a12010-09-18 01:14:36 +00001076CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
1077 CommandObject (interpreter,
1078 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001079 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001080 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001081{
Caroline Tice43b014a2010-10-04 22:28:36 +00001082 CommandArgumentEntry arg1;
1083 CommandArgumentEntry arg2;
1084 CommandArgumentData var_name_arg;
1085 CommandArgumentData value_arg;
1086
1087 // Define the first (and only) variant of this arg.
1088 var_name_arg.arg_type = eArgTypeSettingVariableName;
1089 var_name_arg.arg_repetition = eArgRepeatPlain;
1090
1091 // There is only one variant this argument could be; put it into the argument entry.
1092 arg1.push_back (var_name_arg);
1093
1094 // Define the first (and only) variant of this arg.
1095 value_arg.arg_type = eArgTypeValue;
1096 value_arg.arg_repetition = eArgRepeatPlain;
1097
1098 // There is only one variant this argument could be; put it into the argument entry.
1099 arg2.push_back (value_arg);
1100
1101 // Push the data for the first argument into the m_arguments vector.
1102 m_arguments.push_back (arg1);
1103 m_arguments.push_back (arg2);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001104}
1105
1106CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
1107{
1108}
1109
1110bool
Greg Clayton41c56fa2011-04-19 22:32:36 +00001111CommandObjectSettingsAppend::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001112{
Greg Clayton41c56fa2011-04-19 22:32:36 +00001113 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001114
1115 const int argc = command.GetArgumentCount ();
1116
1117 if (argc < 2)
1118 {
1119 result.AppendError ("'settings append' takes more arguments");
1120 result.SetStatus (eReturnStatusFailed);
1121 return false;
1122 }
1123
1124 const char *var_name = command.GetArgumentAtIndex (0);
1125 std::string var_name_string;
1126 if ((var_name == NULL) || (var_name[0] == '\0'))
1127 {
1128 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1129 result.SetStatus (eReturnStatusFailed);
1130 return false;
1131 }
1132
1133 var_name_string = var_name;
1134 command.Shift();
1135
1136 const char *var_value;
1137 std::string value_string;
1138
Caroline Ticed9105c22010-12-10 00:26:54 +00001139 command.GetQuotedCommandString (value_string);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001140 var_value = value_string.c_str();
1141
1142 if ((var_value == NULL) || (var_value[0] == '\0'))
1143 {
1144 result.AppendError ("'settings append' command requires a valid variable value;"
1145 " No value supplied");
1146 result.SetStatus (eReturnStatusFailed);
1147 }
1148 else
1149 {
Greg Clayton41c56fa2011-04-19 22:32:36 +00001150 Error err = usc_sp->SetVariable (var_name_string.c_str(),
1151 var_value,
1152 eVarSetOperationAppend,
1153 true,
1154 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001155 if (err.Fail ())
1156 {
1157 result.AppendError (err.AsCString());
1158 result.SetStatus (eReturnStatusFailed);
1159 }
1160 else
1161 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1162 }
1163
1164 return result.Succeeded();
1165}
1166
1167
1168int
Greg Clayton238c0a12010-09-18 01:14:36 +00001169CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001170 int &cursor_index,
1171 int &cursor_char_position,
1172 OptionElementVector &opt_element_vector,
1173 int match_start_point,
1174 int max_return_elements,
1175 bool &word_complete,
1176 StringList &matches)
1177{
1178 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1179 completion_str.erase (cursor_char_position);
1180
1181 // Attempting to complete variable name
1182 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001183 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001184 CommandCompletions::eSettingsNameCompletion,
1185 completion_str.c_str(),
1186 match_start_point,
1187 max_return_elements,
1188 NULL,
1189 word_complete,
1190 matches);
1191
1192 return matches.GetSize();
1193}
1194
1195//-------------------------------------------------------------------------
1196// CommandObjectSettingsClear
1197//-------------------------------------------------------------------------
1198
Greg Clayton238c0a12010-09-18 01:14:36 +00001199CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1200 CommandObject (interpreter,
1201 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001202 "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 +00001203 NULL)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001204{
Caroline Tice43b014a2010-10-04 22:28:36 +00001205 CommandArgumentEntry arg;
1206 CommandArgumentData var_name_arg;
1207
1208 // Define the first (and only) variant of this arg.
1209 var_name_arg.arg_type = eArgTypeSettingVariableName;
1210 var_name_arg.arg_repetition = eArgRepeatPlain;
1211
1212 // There is only one variant this argument could be; put it into the argument entry.
1213 arg.push_back (var_name_arg);
1214
1215 // Push the data for the first argument into the m_arguments vector.
1216 m_arguments.push_back (arg);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001217}
1218
1219CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1220{
1221}
1222
1223bool
Greg Clayton41c56fa2011-04-19 22:32:36 +00001224CommandObjectSettingsClear::Execute (Args& command, CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001225{
Greg Clayton41c56fa2011-04-19 22:32:36 +00001226 UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001227
1228 const int argc = command.GetArgumentCount ();
1229
1230 if (argc != 1)
1231 {
1232 result.AppendError ("'setttings clear' takes exactly one argument");
1233 result.SetStatus (eReturnStatusFailed);
1234 return false;
1235 }
1236
1237 const char *var_name = command.GetArgumentAtIndex (0);
1238 if ((var_name == NULL) || (var_name[0] == '\0'))
1239 {
1240 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1241 result.SetStatus (eReturnStatusFailed);
1242 return false;
1243 }
1244
Greg Clayton41c56fa2011-04-19 22:32:36 +00001245 Error err = usc_sp->SetVariable (var_name,
1246 NULL,
1247 eVarSetOperationClear,
1248 false,
1249 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001250
1251 if (err.Fail ())
1252 {
1253 result.AppendError (err.AsCString());
1254 result.SetStatus (eReturnStatusFailed);
1255 }
1256 else
1257 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1258
1259 return result.Succeeded();
1260}
1261
1262
1263int
Greg Clayton238c0a12010-09-18 01:14:36 +00001264CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001265 int &cursor_index,
1266 int &cursor_char_position,
1267 OptionElementVector &opt_element_vector,
1268 int match_start_point,
1269 int max_return_elements,
1270 bool &word_complete,
1271 StringList &matches)
1272{
1273 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1274 completion_str.erase (cursor_char_position);
1275
1276 // Attempting to complete variable name
1277 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001278 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001279 CommandCompletions::eSettingsNameCompletion,
1280 completion_str.c_str(),
1281 match_start_point,
1282 max_return_elements,
1283 NULL,
1284 word_complete,
1285 matches);
1286
1287 return matches.GetSize();
1288}