blob: 703173cdf755cff357e280c9e1c87d5b107c1832 [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 Tice6e4c5ce2010-09-04 00:03:46 +000068 "settings set [<cmd-options>] <setting-variable-name> <value>"),
69 m_options ()
70{
71}
72
73CommandObjectSettingsSet::~CommandObjectSettingsSet()
Chris Lattner24943d22010-06-08 16:52:24 +000074{
75}
76
77
78bool
Greg Clayton238c0a12010-09-18 01:14:36 +000079CommandObjectSettingsSet::Execute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +000080{
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000081 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
Chris Lattner24943d22010-06-08 16:52:24 +000082
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000083 const int argc = command.GetArgumentCount ();
84
Caroline Tice87097232010-09-07 18:35:40 +000085 if ((argc < 2) && (!m_options.m_reset))
Chris Lattner24943d22010-06-08 16:52:24 +000086 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000087 result.AppendError ("'settings set' takes more arguments");
88 result.SetStatus (eReturnStatusFailed);
89 return false;
90 }
91
92 const char *var_name = command.GetArgumentAtIndex (0);
93 std::string var_name_string;
94 if ((var_name == NULL) || (var_name[0] == '\0'))
95 {
96 result.AppendError ("'settings set' command requires a valid variable name; No value supplied");
97 result.SetStatus (eReturnStatusFailed);
98 return false;
99 }
100
101 var_name_string = var_name;
102 command.Shift();
103
104 const char *var_value;
105 std::string value_string;
106
107 command.GetCommandString (value_string);
108 var_value = value_string.c_str();
109
110 if (!m_options.m_reset
111 && var_value == NULL)
112 {
113 result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;"
114 " No value supplied");
Chris Lattner24943d22010-06-08 16:52:24 +0000115 result.SetStatus (eReturnStatusFailed);
116 }
117 else
118 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000119 Error err = root_settings->SetVariable (var_name_string.c_str(),
120 var_value,
121 lldb::eVarSetOperationAssign,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000122 m_options.m_override,
Greg Clayton238c0a12010-09-18 01:14:36 +0000123 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000124 if (err.Fail ())
125 {
126 result.AppendError (err.AsCString());
127 result.SetStatus (eReturnStatusFailed);
128 }
129 else
130 result.SetStatus (eReturnStatusSuccessFinishNoResult);
131 }
132
133 return result.Succeeded();
134}
135
136int
Greg Clayton238c0a12010-09-18 01:14:36 +0000137CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000138 int &cursor_index,
139 int &cursor_char_position,
140 OptionElementVector &opt_element_vector,
141 int match_start_point,
142 int max_return_elements,
143 bool &word_complete,
144 StringList &matches)
145{
146 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
147 completion_str.erase (cursor_char_position);
148
149 // Attempting to complete variable name
150 if (cursor_index == 1)
Greg Clayton238c0a12010-09-18 01:14:36 +0000151 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000152 CommandCompletions::eSettingsNameCompletion,
153 completion_str.c_str(),
154 match_start_point,
155 max_return_elements,
156 NULL,
157 word_complete,
158 matches);
159
160 // Attempting to complete value
161 if ((cursor_index == 2) // Partly into the variable's value
162 || (cursor_index == 1 // Or at the end of a completed valid variable name
163 && matches.GetSize() == 1
164 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
165 {
166 matches.Clear();
167 lldb::UserSettingsControllerSP root_settings = Debugger::GetSettingsController();
168 if (cursor_index == 1)
169 {
170 // The user is at the end of the variable name, which is complete and valid.
171 UserSettingsController::CompleteSettingsValue (root_settings,
172 input.GetArgumentAtIndex (1), // variable name
173 NULL, // empty value string
174 word_complete,
175 matches);
176 }
177 else
178 {
179 // The user is partly into the variable value.
180 UserSettingsController::CompleteSettingsValue (root_settings,
181 input.GetArgumentAtIndex (1), // variable name
182 completion_str.c_str(), // partial value string
183 word_complete,
184 matches);
185 }
186 }
187
188 return matches.GetSize();
189}
190
191//-------------------------------------------------------------------------
192// CommandObjectSettingsSet::CommandOptions
193//-------------------------------------------------------------------------
194
195CommandObjectSettingsSet::CommandOptions::CommandOptions () :
196 Options (),
Caroline Tice1ebef442010-09-27 00:30:10 +0000197 m_override (true),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000198 m_reset (false)
199{
200}
201
202CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
203{
204}
205
206lldb::OptionDefinition
207CommandObjectSettingsSet::CommandOptions::g_option_table[] =
208{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000209 { 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." },
210 { 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." },
211 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000212};
213
214const lldb::OptionDefinition*
215CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
216{
217 return g_option_table;
218}
219
220Error
221CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
222{
223 Error error;
224 char short_option = (char) m_getopt_table[option_idx].val;
225
226 switch (short_option)
227 {
Caroline Tice1ebef442010-09-27 00:30:10 +0000228 case 'n':
229 m_override = false;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000230 break;
231 case 'r':
232 m_reset = true;
233 break;
234 default:
235 error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option);
236 break;
237 }
238
239 return error;
240}
241
242void
243CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
244{
245 Options::ResetOptionValues ();
246
Caroline Tice1ebef442010-09-27 00:30:10 +0000247 m_override = true;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000248 m_reset = false;
249}
250
251Options *
252CommandObjectSettingsSet::GetOptions ()
253{
254 return &m_options;
255}
256
257
258//-------------------------------------------------------------------------
259// CommandObjectSettingsShow -- Show current values
260//-------------------------------------------------------------------------
261
Greg Clayton238c0a12010-09-18 01:14:36 +0000262CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
263 CommandObject (interpreter,
264 "settings show",
265 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
266 "settings show [<setting-variable-name>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000267{
268}
269
270CommandObjectSettingsShow::~CommandObjectSettingsShow()
271{
272}
273
274
275bool
Caroline Tice5bc8c972010-09-20 20:44:43 +0000276CommandObjectSettingsShow::Execute (Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000277 CommandReturnObject &result)
278{
279 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
280 std::string current_prefix = root_settings->GetLevelName().AsCString();
281
282 Error err;
283
284 if (command.GetArgumentCount())
285 {
286 // The user requested to see the value of a particular variable.
287 lldb::SettableVariableType var_type;
288 const char *variable_name = command.GetArgumentAtIndex (0);
Caroline Tice5bc8c972010-09-20 20:44:43 +0000289 StringList value = root_settings->GetVariable (variable_name, var_type,
290 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
291 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000292
Caroline Tice5bc8c972010-09-20 20:44:43 +0000293 if (err.Fail ())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000294 {
Caroline Tice5bc8c972010-09-20 20:44:43 +0000295 result.AppendError (err.AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000296 result.SetStatus (eReturnStatusFailed);
297
298 }
299 else
300 {
301 char *type_name = (char *) "";
302 if (var_type != eSetVarTypeNone)
303 {
304 StreamString tmp_str;
305 tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type));
306 type_name = (char *) tmp_str.GetData();
307 }
Caroline Tice5bc8c972010-09-20 20:44:43 +0000308
309 if (value.GetSize() == 0)
310 result.AppendMessageWithFormat ("%s%s = ''\n", variable_name, type_name);
311 else if (value.GetSize() == 1)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000312 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
313 else
314 {
315 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
Chris Lattner0f6fa732010-09-08 22:55:31 +0000316 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000317 {
318 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
319 }
320 }
321 result.SetStatus (eReturnStatusSuccessFinishNoResult);
322 }
323 }
324 else
325 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000326 UserSettingsController::GetAllVariableValues (m_interpreter,
327 root_settings,
328 current_prefix,
329 result.GetOutputStream(),
330 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000331 if (err.Fail ())
332 {
333 result.AppendError (err.AsCString());
334 result.SetStatus (eReturnStatusFailed);
335 }
336 else
337 {
338 result.SetStatus (eReturnStatusSuccessFinishNoResult);
339 }
340 }
341
342 return result.Succeeded();
343}
344
345int
Greg Clayton238c0a12010-09-18 01:14:36 +0000346CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000347 int &cursor_index,
348 int &cursor_char_position,
349 OptionElementVector &opt_element_vector,
350 int match_start_point,
351 int max_return_elements,
352 bool &word_complete,
353 StringList &matches)
354{
355 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
356 completion_str.erase (cursor_char_position);
357
Greg Clayton238c0a12010-09-18 01:14:36 +0000358 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000359 CommandCompletions::eSettingsNameCompletion,
360 completion_str.c_str(),
361 match_start_point,
362 max_return_elements,
363 NULL,
364 word_complete,
365 matches);
366 return matches.GetSize();
367}
368
369//-------------------------------------------------------------------------
370// CommandObjectSettingsList
371//-------------------------------------------------------------------------
372
Greg Clayton238c0a12010-09-18 01:14:36 +0000373CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
374 CommandObject (interpreter,
375 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000376 "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).",
377 "settings list [<setting-name> | <setting-name-prefix>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000378{
379}
380
381CommandObjectSettingsList::~CommandObjectSettingsList()
382{
383}
384
385
386bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000387CommandObjectSettingsList::Execute ( Args& command,
Caroline Tice41ae2172010-09-15 06:56:39 +0000388 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000389{
390 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
391 std::string current_prefix = root_settings->GetLevelName().AsCString();
392
393 Error err;
394
Caroline Tice41ae2172010-09-15 06:56:39 +0000395 if (command.GetArgumentCount() == 0)
396 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000397 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
398 root_settings,
399 current_prefix,
400 result.GetOutputStream(),
401 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000402 }
403 else if (command.GetArgumentCount() == 1)
404 {
405 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000406 UserSettingsController::FindSettingsDescriptions (m_interpreter,
407 root_settings,
408 current_prefix,
409 search_name,
410 result.GetOutputStream(),
411 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000412 }
413 else
414 {
415 result.AppendError ("Too many aguments for 'settings list' command.\n");
416 result.SetStatus (eReturnStatusFailed);
417 return false;
418 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000419
420 if (err.Fail ())
421 {
422 result.AppendError (err.AsCString());
423 result.SetStatus (eReturnStatusFailed);
424 }
425 else
426 {
Chris Lattner24943d22010-06-08 16:52:24 +0000427 result.SetStatus (eReturnStatusSuccessFinishNoResult);
428 }
429
430 return result.Succeeded();
431}
432
Caroline Tice41ae2172010-09-15 06:56:39 +0000433int
Greg Clayton238c0a12010-09-18 01:14:36 +0000434CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000435 int &cursor_index,
436 int &cursor_char_position,
437 OptionElementVector &opt_element_vector,
438 int match_start_point,
439 int max_return_elements,
440 bool &word_complete,
441 StringList &matches)
442{
443 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
444 completion_str.erase (cursor_char_position);
445
Greg Clayton238c0a12010-09-18 01:14:36 +0000446 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000447 CommandCompletions::eSettingsNameCompletion,
448 completion_str.c_str(),
449 match_start_point,
450 max_return_elements,
451 NULL,
452 word_complete,
453 matches);
454 return matches.GetSize();
455}
456
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000457//-------------------------------------------------------------------------
458// CommandObjectSettingsRemove
459//-------------------------------------------------------------------------
460
Greg Clayton238c0a12010-09-18 01:14:36 +0000461CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
462 CommandObject (interpreter,
463 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000464 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000465 "settings remove <setting-variable-name> [<index>|\"key\"]")
466{
467}
468
469CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
470{
471}
472
473bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000474CommandObjectSettingsRemove::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000475 CommandReturnObject &result)
476{
477 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
478
479 const int argc = command.GetArgumentCount ();
480
481 if (argc != 2)
482 {
483 result.AppendError ("'settings remove' takes two arguments");
484 result.SetStatus (eReturnStatusFailed);
485 return false;
486 }
487
488 const char *var_name = command.GetArgumentAtIndex (0);
489 std::string var_name_string;
490 if ((var_name == NULL) || (var_name[0] == '\0'))
491 {
492 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
493 result.SetStatus (eReturnStatusFailed);
494 return false;
495 }
496
497 var_name_string = var_name;
498 command.Shift();
499
500 const char *index_value = command.GetArgumentAtIndex (0);
501 std::string index_value_string;
502 if ((index_value == NULL) || (index_value[0] == '\0'))
503 {
504 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
505 result.SetStatus (eReturnStatusFailed);
506 return false;
507 }
508
509 index_value_string = index_value;
510
Greg Clayton238c0a12010-09-18 01:14:36 +0000511 Error err = root_settings->SetVariable (var_name_string.c_str(),
512 NULL,
513 lldb::eVarSetOperationRemove,
Caroline Tice1ebef442010-09-27 00:30:10 +0000514 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000515 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000516 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000517 if (err.Fail ())
518 {
519 result.AppendError (err.AsCString());
520 result.SetStatus (eReturnStatusFailed);
521 }
522 else
523 result.SetStatus (eReturnStatusSuccessFinishNoResult);
524
525 return result.Succeeded();
526}
527
528int
Greg Clayton238c0a12010-09-18 01:14:36 +0000529CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000530 int &cursor_index,
531 int &cursor_char_position,
532 OptionElementVector &opt_element_vector,
533 int match_start_point,
534 int max_return_elements,
535 bool &word_complete,
536 StringList &matches)
537{
538 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
539 completion_str.erase (cursor_char_position);
540
541 // Attempting to complete variable name
542 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000543 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000544 CommandCompletions::eSettingsNameCompletion,
545 completion_str.c_str(),
546 match_start_point,
547 max_return_elements,
548 NULL,
549 word_complete,
550 matches);
551
552 return matches.GetSize();
553}
554
555//-------------------------------------------------------------------------
556// CommandObjectSettingsReplace
557//-------------------------------------------------------------------------
558
Greg Clayton238c0a12010-09-18 01:14:36 +0000559CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
560 CommandObject (interpreter,
561 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000562 "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000563 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
564{
565}
566
567CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
568{
569}
570
571bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000572CommandObjectSettingsReplace::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000573 CommandReturnObject &result)
574{
575 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
576
577 const int argc = command.GetArgumentCount ();
578
579 if (argc < 3)
580 {
581 result.AppendError ("'settings replace' takes more arguments");
582 result.SetStatus (eReturnStatusFailed);
583 return false;
584 }
585
586 const char *var_name = command.GetArgumentAtIndex (0);
587 std::string var_name_string;
588 if ((var_name == NULL) || (var_name[0] == '\0'))
589 {
590 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
591 result.SetStatus (eReturnStatusFailed);
592 return false;
593 }
594
595 var_name_string = var_name;
596 command.Shift();
597
598 const char *index_value = command.GetArgumentAtIndex (0);
599 std::string index_value_string;
600 if ((index_value == NULL) || (index_value[0] == '\0'))
601 {
602 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
603 result.SetStatus (eReturnStatusFailed);
604 return false;
605 }
606
607 index_value_string = index_value;
608 command.Shift();
609
610 const char *var_value;
611 std::string value_string;
612
613 command.GetCommandString (value_string);
614 var_value = value_string.c_str();
615
616 if ((var_value == NULL) || (var_value[0] == '\0'))
617 {
618 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
619 result.SetStatus (eReturnStatusFailed);
620 }
621 else
622 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000623 Error err = root_settings->SetVariable (var_name_string.c_str(),
624 var_value,
625 lldb::eVarSetOperationReplace,
Caroline Tice1ebef442010-09-27 00:30:10 +0000626 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000627 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000628 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000629 if (err.Fail ())
630 {
631 result.AppendError (err.AsCString());
632 result.SetStatus (eReturnStatusFailed);
633 }
634 else
635 result.SetStatus (eReturnStatusSuccessFinishNoResult);
636 }
637
638 return result.Succeeded();
639}
640
641int
Greg Clayton238c0a12010-09-18 01:14:36 +0000642CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000643 int &cursor_index,
644 int &cursor_char_position,
645 OptionElementVector &opt_element_vector,
646 int match_start_point,
647 int max_return_elements,
648 bool &word_complete,
649 StringList &matches)
650{
651 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
652 completion_str.erase (cursor_char_position);
653
654 // Attempting to complete variable name
655 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000656 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000657 CommandCompletions::eSettingsNameCompletion,
658 completion_str.c_str(),
659 match_start_point,
660 max_return_elements,
661 NULL,
662 word_complete,
663 matches);
664
665 return matches.GetSize();
666}
667
668//-------------------------------------------------------------------------
669// CommandObjectSettingsInsertBefore
670//-------------------------------------------------------------------------
671
Greg Clayton238c0a12010-09-18 01:14:36 +0000672CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
673 CommandObject (interpreter,
674 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000675 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000676 "settings insert-before <setting-variable-name> [<index>] <new-value>")
677{
678}
679
680CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
681{
682}
683
684bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000685CommandObjectSettingsInsertBefore::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000686 CommandReturnObject &result)
687{
688 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
689
690 const int argc = command.GetArgumentCount ();
691
692 if (argc < 3)
693 {
694 result.AppendError ("'settings insert-before' takes more arguments");
695 result.SetStatus (eReturnStatusFailed);
696 return false;
697 }
698
699 const char *var_name = command.GetArgumentAtIndex (0);
700 std::string var_name_string;
701 if ((var_name == NULL) || (var_name[0] == '\0'))
702 {
703 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
704 result.SetStatus (eReturnStatusFailed);
705 return false;
706 }
707
708 var_name_string = var_name;
709 command.Shift();
710
711 const char *index_value = command.GetArgumentAtIndex (0);
712 std::string index_value_string;
713 if ((index_value == NULL) || (index_value[0] == '\0'))
714 {
715 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
716 result.SetStatus (eReturnStatusFailed);
717 return false;
718 }
719
720 index_value_string = index_value;
721 command.Shift();
722
723 const char *var_value;
724 std::string value_string;
725
726 command.GetCommandString (value_string);
727 var_value = value_string.c_str();
728
729 if ((var_value == NULL) || (var_value[0] == '\0'))
730 {
731 result.AppendError ("'settings insert-before' command requires a valid variable value;"
732 " No value supplied");
733 result.SetStatus (eReturnStatusFailed);
734 }
735 else
736 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000737 Error err = root_settings->SetVariable (var_name_string.c_str(),
738 var_value,
739 lldb::eVarSetOperationInsertBefore,
Caroline Tice1ebef442010-09-27 00:30:10 +0000740 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000741 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000742 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000743 if (err.Fail ())
744 {
745 result.AppendError (err.AsCString());
746 result.SetStatus (eReturnStatusFailed);
747 }
748 else
749 result.SetStatus (eReturnStatusSuccessFinishNoResult);
750 }
751
752 return result.Succeeded();
753}
754
755
756int
Greg Clayton238c0a12010-09-18 01:14:36 +0000757CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000758 int &cursor_index,
759 int &cursor_char_position,
760 OptionElementVector &opt_element_vector,
761 int match_start_point,
762 int max_return_elements,
763 bool &word_complete,
764 StringList &matches)
765{
766 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
767 completion_str.erase (cursor_char_position);
768
769 // Attempting to complete variable name
770 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000771 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000772 CommandCompletions::eSettingsNameCompletion,
773 completion_str.c_str(),
774 match_start_point,
775 max_return_elements,
776 NULL,
777 word_complete,
778 matches);
779
780 return matches.GetSize();
781}
782
783//-------------------------------------------------------------------------
784// CommandObjectSettingInsertAfter
785//-------------------------------------------------------------------------
786
Greg Clayton238c0a12010-09-18 01:14:36 +0000787CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
788 CommandObject (interpreter,
789 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000790 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000791 "settings insert-after <setting-variable-name> [<index>] <new-value>")
792{
793}
794
795CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
796{
797}
798
799bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000800CommandObjectSettingsInsertAfter::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000801 CommandReturnObject &result)
802{
803 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
804
805 const int argc = command.GetArgumentCount ();
806
807 if (argc < 3)
808 {
809 result.AppendError ("'settings insert-after' takes more arguments");
810 result.SetStatus (eReturnStatusFailed);
811 return false;
812 }
813
814 const char *var_name = command.GetArgumentAtIndex (0);
815 std::string var_name_string;
816 if ((var_name == NULL) || (var_name[0] == '\0'))
817 {
818 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
819 result.SetStatus (eReturnStatusFailed);
820 return false;
821 }
822
823 var_name_string = var_name;
824 command.Shift();
825
826 const char *index_value = command.GetArgumentAtIndex (0);
827 std::string index_value_string;
828 if ((index_value == NULL) || (index_value[0] == '\0'))
829 {
830 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
831 result.SetStatus (eReturnStatusFailed);
832 return false;
833 }
834
835 index_value_string = index_value;
836 command.Shift();
837
838 const char *var_value;
839 std::string value_string;
840
841 command.GetCommandString (value_string);
842 var_value = value_string.c_str();
843
844 if ((var_value == NULL) || (var_value[0] == '\0'))
845 {
846 result.AppendError ("'settings insert-after' command requires a valid variable value;"
847 " No value supplied");
848 result.SetStatus (eReturnStatusFailed);
849 }
850 else
851 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000852 Error err = root_settings->SetVariable (var_name_string.c_str(),
853 var_value,
854 lldb::eVarSetOperationInsertAfter,
Caroline Tice1ebef442010-09-27 00:30:10 +0000855 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000856 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000857 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000858 if (err.Fail ())
859 {
860 result.AppendError (err.AsCString());
861 result.SetStatus (eReturnStatusFailed);
862 }
863 else
864 result.SetStatus (eReturnStatusSuccessFinishNoResult);
865 }
866
867 return result.Succeeded();
868}
869
870
871int
Greg Clayton238c0a12010-09-18 01:14:36 +0000872CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000873 int &cursor_index,
874 int &cursor_char_position,
875 OptionElementVector &opt_element_vector,
876 int match_start_point,
877 int max_return_elements,
878 bool &word_complete,
879 StringList &matches)
880{
881 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
882 completion_str.erase (cursor_char_position);
883
884 // Attempting to complete variable name
885 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000886 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000887 CommandCompletions::eSettingsNameCompletion,
888 completion_str.c_str(),
889 match_start_point,
890 max_return_elements,
891 NULL,
892 word_complete,
893 matches);
894
895 return matches.GetSize();
896}
897
898//-------------------------------------------------------------------------
899// CommandObjectSettingsAppend
900//-------------------------------------------------------------------------
901
Greg Clayton238c0a12010-09-18 01:14:36 +0000902CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
903 CommandObject (interpreter,
904 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000905 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000906 "settings append <setting-variable-name> <new-value>")
907{
908}
909
910CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
911{
912}
913
914bool
Caroline Tice1ebef442010-09-27 00:30:10 +0000915CommandObjectSettingsAppend::Execute (Args& command,
916 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000917{
918 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
919
920 const int argc = command.GetArgumentCount ();
921
922 if (argc < 2)
923 {
924 result.AppendError ("'settings append' takes more arguments");
925 result.SetStatus (eReturnStatusFailed);
926 return false;
927 }
928
929 const char *var_name = command.GetArgumentAtIndex (0);
930 std::string var_name_string;
931 if ((var_name == NULL) || (var_name[0] == '\0'))
932 {
933 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
934 result.SetStatus (eReturnStatusFailed);
935 return false;
936 }
937
938 var_name_string = var_name;
939 command.Shift();
940
941 const char *var_value;
942 std::string value_string;
943
944 command.GetCommandString (value_string);
945 var_value = value_string.c_str();
946
947 if ((var_value == NULL) || (var_value[0] == '\0'))
948 {
949 result.AppendError ("'settings append' command requires a valid variable value;"
950 " No value supplied");
951 result.SetStatus (eReturnStatusFailed);
952 }
953 else
954 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000955 Error err = root_settings->SetVariable (var_name_string.c_str(),
956 var_value,
957 lldb::eVarSetOperationAppend,
Caroline Tice1ebef442010-09-27 00:30:10 +0000958 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000959 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000960 if (err.Fail ())
961 {
962 result.AppendError (err.AsCString());
963 result.SetStatus (eReturnStatusFailed);
964 }
965 else
966 result.SetStatus (eReturnStatusSuccessFinishNoResult);
967 }
968
969 return result.Succeeded();
970}
971
972
973int
Greg Clayton238c0a12010-09-18 01:14:36 +0000974CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000975 int &cursor_index,
976 int &cursor_char_position,
977 OptionElementVector &opt_element_vector,
978 int match_start_point,
979 int max_return_elements,
980 bool &word_complete,
981 StringList &matches)
982{
983 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
984 completion_str.erase (cursor_char_position);
985
986 // Attempting to complete variable name
987 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000988 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000989 CommandCompletions::eSettingsNameCompletion,
990 completion_str.c_str(),
991 match_start_point,
992 max_return_elements,
993 NULL,
994 word_complete,
995 matches);
996
997 return matches.GetSize();
998}
999
1000//-------------------------------------------------------------------------
1001// CommandObjectSettingsClear
1002//-------------------------------------------------------------------------
1003
Greg Clayton238c0a12010-09-18 01:14:36 +00001004CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1005 CommandObject (interpreter,
1006 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001007 "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 Tice6e4c5ce2010-09-04 00:03:46 +00001008 "settings clear")
1009{
1010}
1011
1012CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1013{
1014}
1015
1016bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001017CommandObjectSettingsClear::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001018 CommandReturnObject &result)
1019{
1020 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1021
1022 const int argc = command.GetArgumentCount ();
1023
1024 if (argc != 1)
1025 {
1026 result.AppendError ("'setttings clear' takes exactly one argument");
1027 result.SetStatus (eReturnStatusFailed);
1028 return false;
1029 }
1030
1031 const char *var_name = command.GetArgumentAtIndex (0);
1032 if ((var_name == NULL) || (var_name[0] == '\0'))
1033 {
1034 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1035 result.SetStatus (eReturnStatusFailed);
1036 return false;
1037 }
1038
Greg Clayton238c0a12010-09-18 01:14:36 +00001039 Error err = root_settings->SetVariable (var_name,
1040 NULL,
1041 lldb::eVarSetOperationClear,
1042 false,
1043 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001044
1045 if (err.Fail ())
1046 {
1047 result.AppendError (err.AsCString());
1048 result.SetStatus (eReturnStatusFailed);
1049 }
1050 else
1051 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1052
1053 return result.Succeeded();
1054}
1055
1056
1057int
Greg Clayton238c0a12010-09-18 01:14:36 +00001058CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001059 int &cursor_index,
1060 int &cursor_char_position,
1061 OptionElementVector &opt_element_vector,
1062 int match_start_point,
1063 int max_return_elements,
1064 bool &word_complete,
1065 StringList &matches)
1066{
1067 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1068 completion_str.erase (cursor_char_position);
1069
1070 // Attempting to complete variable name
1071 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001072 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001073 CommandCompletions::eSettingsNameCompletion,
1074 completion_str.c_str(),
1075 match_start_point,
1076 max_return_elements,
1077 NULL,
1078 word_complete,
1079 matches);
1080
1081 return matches.GetSize();
1082}