blob: 8e6a5b1184c19507681334f16b5004a3fed56e74 [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) :
28 CommandObjectMultiword ("settings",
29 "A set of commands for manipulating internal settable debugger variables.",
30 "settings <command> [<command-options>]")
31{
32 bool status;
33
34 CommandObjectSP set_command_object (new CommandObjectSettingsSet ());
35 CommandObjectSP show_command_object (new CommandObjectSettingsShow ());
36 CommandObjectSP list_command_object (new CommandObjectSettingsList ());
37 CommandObjectSP remove_command_object (new CommandObjectSettingsRemove ());
38 CommandObjectSP replace_command_object (new CommandObjectSettingsReplace ());
39 CommandObjectSP insert_before_command_object (new CommandObjectSettingsInsertBefore ());
40 CommandObjectSP insert_after_command_object (new CommandObjectSettingsInsertAfter());
41 CommandObjectSP append_command_object (new CommandObjectSettingsAppend());
42 CommandObjectSP clear_command_object (new CommandObjectSettingsClear());
43
44 status = LoadSubCommand (interpreter, "set", set_command_object);
45 status = LoadSubCommand (interpreter, "show", show_command_object);
46 status = LoadSubCommand (interpreter, "list", list_command_object);
47 status = LoadSubCommand (interpreter, "remove", remove_command_object);
48 status = LoadSubCommand (interpreter, "replace", replace_command_object);
49 status = LoadSubCommand (interpreter, "insert-before", insert_before_command_object);
50 status = LoadSubCommand (interpreter, "insert-after", insert_after_command_object);
51 status = LoadSubCommand (interpreter, "append", append_command_object);
52 status = LoadSubCommand (interpreter, "clear", clear_command_object);
53}
54
55CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57}
58
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000059//-------------------------------------------------------------------------
60// CommandObjectSettingsSet
61//-------------------------------------------------------------------------
62
63CommandObjectSettingsSet::CommandObjectSettingsSet () :
64 CommandObject ("settings set",
Caroline Ticeabb507a2010-09-08 21:06:11 +000065 "Set or change the value of a single debugger setting variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000066 "settings set [<cmd-options>] <setting-variable-name> <value>"),
67 m_options ()
68{
69}
70
71CommandObjectSettingsSet::~CommandObjectSettingsSet()
Chris Lattner24943d22010-06-08 16:52:24 +000072{
73}
74
75
76bool
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000077CommandObjectSettingsSet::Execute (CommandInterpreter &interpreter,
78 Args& command,
79 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 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000119 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationAssign,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000120 m_options.m_override,
121 interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000122 if (err.Fail ())
123 {
124 result.AppendError (err.AsCString());
125 result.SetStatus (eReturnStatusFailed);
126 }
127 else
128 result.SetStatus (eReturnStatusSuccessFinishNoResult);
129 }
130
131 return result.Succeeded();
132}
133
134int
135CommandObjectSettingsSet::HandleArgumentCompletion (CommandInterpreter &interpreter,
136 Args &input,
137 int &cursor_index,
138 int &cursor_char_position,
139 OptionElementVector &opt_element_vector,
140 int match_start_point,
141 int max_return_elements,
142 bool &word_complete,
143 StringList &matches)
144{
145 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
146 completion_str.erase (cursor_char_position);
147
148 // Attempting to complete variable name
149 if (cursor_index == 1)
150 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
151 CommandCompletions::eSettingsNameCompletion,
152 completion_str.c_str(),
153 match_start_point,
154 max_return_elements,
155 NULL,
156 word_complete,
157 matches);
158
159 // Attempting to complete value
160 if ((cursor_index == 2) // Partly into the variable's value
161 || (cursor_index == 1 // Or at the end of a completed valid variable name
162 && matches.GetSize() == 1
163 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
164 {
165 matches.Clear();
166 lldb::UserSettingsControllerSP root_settings = Debugger::GetSettingsController();
167 if (cursor_index == 1)
168 {
169 // The user is at the end of the variable name, which is complete and valid.
170 UserSettingsController::CompleteSettingsValue (root_settings,
171 input.GetArgumentAtIndex (1), // variable name
172 NULL, // empty value string
173 word_complete,
174 matches);
175 }
176 else
177 {
178 // The user is partly into the variable value.
179 UserSettingsController::CompleteSettingsValue (root_settings,
180 input.GetArgumentAtIndex (1), // variable name
181 completion_str.c_str(), // partial value string
182 word_complete,
183 matches);
184 }
185 }
186
187 return matches.GetSize();
188}
189
190//-------------------------------------------------------------------------
191// CommandObjectSettingsSet::CommandOptions
192//-------------------------------------------------------------------------
193
194CommandObjectSettingsSet::CommandOptions::CommandOptions () :
195 Options (),
196 m_override (false),
197 m_reset (false)
198{
199}
200
201CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
202{
203}
204
205lldb::OptionDefinition
206CommandObjectSettingsSet::CommandOptions::g_option_table[] =
207{
208 { LLDB_OPT_SET_1, false, "override", 'o', no_argument, NULL, NULL, NULL, "Causes already existing instances and pending settings to use this new value. This option only makes sense when setting default values." },
209
210 { LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, NULL, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." },
211};
212
213const lldb::OptionDefinition*
214CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
215{
216 return g_option_table;
217}
218
219Error
220CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
221{
222 Error error;
223 char short_option = (char) m_getopt_table[option_idx].val;
224
225 switch (short_option)
226 {
227 case 'o':
228 m_override = true;
229 break;
230 case 'r':
231 m_reset = true;
232 break;
233 default:
234 error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option);
235 break;
236 }
237
238 return error;
239}
240
241void
242CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
243{
244 Options::ResetOptionValues ();
245
246 m_override = false;
247 m_reset = false;
248}
249
250Options *
251CommandObjectSettingsSet::GetOptions ()
252{
253 return &m_options;
254}
255
256
257//-------------------------------------------------------------------------
258// CommandObjectSettingsShow -- Show current values
259//-------------------------------------------------------------------------
260
261CommandObjectSettingsShow::CommandObjectSettingsShow () :
262 CommandObject ("settings show",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000263 "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 Tice6e4c5ce2010-09-04 00:03:46 +0000264 "settings show [<setting-variable-name>]")
265{
266}
267
268CommandObjectSettingsShow::~CommandObjectSettingsShow()
269{
270}
271
272
273bool
274CommandObjectSettingsShow::Execute (CommandInterpreter &interpreter,
275 Args& command,
276 CommandReturnObject &result)
277{
278 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
279 std::string current_prefix = root_settings->GetLevelName().AsCString();
280
281 Error err;
282
283 if (command.GetArgumentCount())
284 {
285 // The user requested to see the value of a particular variable.
286 lldb::SettableVariableType var_type;
287 const char *variable_name = command.GetArgumentAtIndex (0);
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000288 StringList value = root_settings->GetVariable (variable_name, var_type,
289 interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000290
291 if (value.GetSize() == 0)
292 {
293 result.AppendErrorWithFormat ("Unable to find variable named '%s'. "
294 "Try 'show' to see all variable values.\n", variable_name);
295 result.SetStatus (eReturnStatusFailed);
296
297 }
298 else
299 {
300 char *type_name = (char *) "";
301 if (var_type != eSetVarTypeNone)
302 {
303 StreamString tmp_str;
304 tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type));
305 type_name = (char *) tmp_str.GetData();
306 }
307
308 if (value.GetSize() == 1)
309 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
310 else
311 {
312 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
Chris Lattner0f6fa732010-09-08 22:55:31 +0000313 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000314 {
315 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
316 }
317 }
318 result.SetStatus (eReturnStatusSuccessFinishNoResult);
319 }
320 }
321 else
322 {
323 UserSettingsController::GetAllVariableValues (interpreter, root_settings, current_prefix,
324 result.GetOutputStream(), err);
325 if (err.Fail ())
326 {
327 result.AppendError (err.AsCString());
328 result.SetStatus (eReturnStatusFailed);
329 }
330 else
331 {
332 result.SetStatus (eReturnStatusSuccessFinishNoResult);
333 }
334 }
335
336 return result.Succeeded();
337}
338
339int
340CommandObjectSettingsShow::HandleArgumentCompletion (CommandInterpreter &interpreter,
341 Args &input,
342 int &cursor_index,
343 int &cursor_char_position,
344 OptionElementVector &opt_element_vector,
345 int match_start_point,
346 int max_return_elements,
347 bool &word_complete,
348 StringList &matches)
349{
350 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
351 completion_str.erase (cursor_char_position);
352
353 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
354 CommandCompletions::eSettingsNameCompletion,
355 completion_str.c_str(),
356 match_start_point,
357 max_return_elements,
358 NULL,
359 word_complete,
360 matches);
361 return matches.GetSize();
362}
363
364//-------------------------------------------------------------------------
365// CommandObjectSettingsList
366//-------------------------------------------------------------------------
367
368CommandObjectSettingsList::CommandObjectSettingsList () :
369 CommandObject ("settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000370 "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).",
371 "settings list [<setting-name> | <setting-name-prefix>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000372{
373}
374
375CommandObjectSettingsList::~CommandObjectSettingsList()
376{
377}
378
379
380bool
381CommandObjectSettingsList::Execute (CommandInterpreter &interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000382 Args& command,
383 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000384{
385 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
386 std::string current_prefix = root_settings->GetLevelName().AsCString();
387
388 Error err;
389
Caroline Tice41ae2172010-09-15 06:56:39 +0000390 if (command.GetArgumentCount() == 0)
391 {
392 UserSettingsController::FindAllSettingsDescriptions (interpreter, root_settings, current_prefix,
393 result.GetOutputStream(), err);
394 }
395 else if (command.GetArgumentCount() == 1)
396 {
397 const char *search_name = command.GetArgumentAtIndex (0);
398 UserSettingsController::FindSettingsDescriptions (interpreter, root_settings, current_prefix,
399 search_name, result.GetOutputStream(), err);
400 }
401 else
402 {
403 result.AppendError ("Too many aguments for 'settings list' command.\n");
404 result.SetStatus (eReturnStatusFailed);
405 return false;
406 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000407
408 if (err.Fail ())
409 {
410 result.AppendError (err.AsCString());
411 result.SetStatus (eReturnStatusFailed);
412 }
413 else
414 {
Chris Lattner24943d22010-06-08 16:52:24 +0000415 result.SetStatus (eReturnStatusSuccessFinishNoResult);
416 }
417
418 return result.Succeeded();
419}
420
Caroline Tice41ae2172010-09-15 06:56:39 +0000421int
422CommandObjectSettingsList::HandleArgumentCompletion (CommandInterpreter &interpreter,
423 Args &input,
424 int &cursor_index,
425 int &cursor_char_position,
426 OptionElementVector &opt_element_vector,
427 int match_start_point,
428 int max_return_elements,
429 bool &word_complete,
430 StringList &matches)
431{
432 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
433 completion_str.erase (cursor_char_position);
434
435 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
436 CommandCompletions::eSettingsNameCompletion,
437 completion_str.c_str(),
438 match_start_point,
439 max_return_elements,
440 NULL,
441 word_complete,
442 matches);
443 return matches.GetSize();
444}
445
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000446//-------------------------------------------------------------------------
447// CommandObjectSettingsRemove
448//-------------------------------------------------------------------------
449
450CommandObjectSettingsRemove::CommandObjectSettingsRemove () :
451 CommandObject ("settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000452 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000453 "settings remove <setting-variable-name> [<index>|\"key\"]")
454{
455}
456
457CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
458{
459}
460
461bool
462CommandObjectSettingsRemove::Execute (CommandInterpreter &interpreter,
463 Args& command,
464 CommandReturnObject &result)
465{
466 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
467
468 const int argc = command.GetArgumentCount ();
469
470 if (argc != 2)
471 {
472 result.AppendError ("'settings remove' takes two arguments");
473 result.SetStatus (eReturnStatusFailed);
474 return false;
475 }
476
477 const char *var_name = command.GetArgumentAtIndex (0);
478 std::string var_name_string;
479 if ((var_name == NULL) || (var_name[0] == '\0'))
480 {
481 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
482 result.SetStatus (eReturnStatusFailed);
483 return false;
484 }
485
486 var_name_string = var_name;
487 command.Shift();
488
489 const char *index_value = command.GetArgumentAtIndex (0);
490 std::string index_value_string;
491 if ((index_value == NULL) || (index_value[0] == '\0'))
492 {
493 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
494 result.SetStatus (eReturnStatusFailed);
495 return false;
496 }
497
498 index_value_string = index_value;
499
500 Error err = root_settings->SetVariable (var_name_string.c_str(), NULL, lldb::eVarSetOperationRemove,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000501 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
502 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000503 if (err.Fail ())
504 {
505 result.AppendError (err.AsCString());
506 result.SetStatus (eReturnStatusFailed);
507 }
508 else
509 result.SetStatus (eReturnStatusSuccessFinishNoResult);
510
511 return result.Succeeded();
512}
513
514int
515CommandObjectSettingsRemove::HandleArgumentCompletion (CommandInterpreter &interpreter,
516 Args &input,
517 int &cursor_index,
518 int &cursor_char_position,
519 OptionElementVector &opt_element_vector,
520 int match_start_point,
521 int max_return_elements,
522 bool &word_complete,
523 StringList &matches)
524{
525 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
526 completion_str.erase (cursor_char_position);
527
528 // Attempting to complete variable name
529 if (cursor_index < 2)
530 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
531 CommandCompletions::eSettingsNameCompletion,
532 completion_str.c_str(),
533 match_start_point,
534 max_return_elements,
535 NULL,
536 word_complete,
537 matches);
538
539 return matches.GetSize();
540}
541
542//-------------------------------------------------------------------------
543// CommandObjectSettingsReplace
544//-------------------------------------------------------------------------
545
546CommandObjectSettingsReplace::CommandObjectSettingsReplace () :
547 CommandObject ("settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000548 "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 +0000549 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
550{
551}
552
553CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
554{
555}
556
557bool
558CommandObjectSettingsReplace::Execute (CommandInterpreter &interpreter,
559 Args& command,
560 CommandReturnObject &result)
561{
562 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
563
564 const int argc = command.GetArgumentCount ();
565
566 if (argc < 3)
567 {
568 result.AppendError ("'settings replace' takes more arguments");
569 result.SetStatus (eReturnStatusFailed);
570 return false;
571 }
572
573 const char *var_name = command.GetArgumentAtIndex (0);
574 std::string var_name_string;
575 if ((var_name == NULL) || (var_name[0] == '\0'))
576 {
577 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
578 result.SetStatus (eReturnStatusFailed);
579 return false;
580 }
581
582 var_name_string = var_name;
583 command.Shift();
584
585 const char *index_value = command.GetArgumentAtIndex (0);
586 std::string index_value_string;
587 if ((index_value == NULL) || (index_value[0] == '\0'))
588 {
589 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
590 result.SetStatus (eReturnStatusFailed);
591 return false;
592 }
593
594 index_value_string = index_value;
595 command.Shift();
596
597 const char *var_value;
598 std::string value_string;
599
600 command.GetCommandString (value_string);
601 var_value = value_string.c_str();
602
603 if ((var_value == NULL) || (var_value[0] == '\0'))
604 {
605 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
606 result.SetStatus (eReturnStatusFailed);
607 }
608 else
609 {
610 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationReplace,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000611 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
612 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000613 if (err.Fail ())
614 {
615 result.AppendError (err.AsCString());
616 result.SetStatus (eReturnStatusFailed);
617 }
618 else
619 result.SetStatus (eReturnStatusSuccessFinishNoResult);
620 }
621
622 return result.Succeeded();
623}
624
625int
626CommandObjectSettingsReplace::HandleArgumentCompletion (CommandInterpreter &interpreter,
627 Args &input,
628 int &cursor_index,
629 int &cursor_char_position,
630 OptionElementVector &opt_element_vector,
631 int match_start_point,
632 int max_return_elements,
633 bool &word_complete,
634 StringList &matches)
635{
636 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
637 completion_str.erase (cursor_char_position);
638
639 // Attempting to complete variable name
640 if (cursor_index < 2)
641 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
642 CommandCompletions::eSettingsNameCompletion,
643 completion_str.c_str(),
644 match_start_point,
645 max_return_elements,
646 NULL,
647 word_complete,
648 matches);
649
650 return matches.GetSize();
651}
652
653//-------------------------------------------------------------------------
654// CommandObjectSettingsInsertBefore
655//-------------------------------------------------------------------------
656
657CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore () :
658 CommandObject ("settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000659 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000660 "settings insert-before <setting-variable-name> [<index>] <new-value>")
661{
662}
663
664CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
665{
666}
667
668bool
669CommandObjectSettingsInsertBefore::Execute (CommandInterpreter &interpreter,
670 Args& command,
671 CommandReturnObject &result)
672{
673 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
674
675 const int argc = command.GetArgumentCount ();
676
677 if (argc < 3)
678 {
679 result.AppendError ("'settings insert-before' takes more arguments");
680 result.SetStatus (eReturnStatusFailed);
681 return false;
682 }
683
684 const char *var_name = command.GetArgumentAtIndex (0);
685 std::string var_name_string;
686 if ((var_name == NULL) || (var_name[0] == '\0'))
687 {
688 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
689 result.SetStatus (eReturnStatusFailed);
690 return false;
691 }
692
693 var_name_string = var_name;
694 command.Shift();
695
696 const char *index_value = command.GetArgumentAtIndex (0);
697 std::string index_value_string;
698 if ((index_value == NULL) || (index_value[0] == '\0'))
699 {
700 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
701 result.SetStatus (eReturnStatusFailed);
702 return false;
703 }
704
705 index_value_string = index_value;
706 command.Shift();
707
708 const char *var_value;
709 std::string value_string;
710
711 command.GetCommandString (value_string);
712 var_value = value_string.c_str();
713
714 if ((var_value == NULL) || (var_value[0] == '\0'))
715 {
716 result.AppendError ("'settings insert-before' command requires a valid variable value;"
717 " No value supplied");
718 result.SetStatus (eReturnStatusFailed);
719 }
720 else
721 {
722 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertBefore,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000723 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
724 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000725 if (err.Fail ())
726 {
727 result.AppendError (err.AsCString());
728 result.SetStatus (eReturnStatusFailed);
729 }
730 else
731 result.SetStatus (eReturnStatusSuccessFinishNoResult);
732 }
733
734 return result.Succeeded();
735}
736
737
738int
739CommandObjectSettingsInsertBefore::HandleArgumentCompletion (CommandInterpreter &interpreter,
740 Args &input,
741 int &cursor_index,
742 int &cursor_char_position,
743 OptionElementVector &opt_element_vector,
744 int match_start_point,
745 int max_return_elements,
746 bool &word_complete,
747 StringList &matches)
748{
749 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
750 completion_str.erase (cursor_char_position);
751
752 // Attempting to complete variable name
753 if (cursor_index < 2)
754 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
755 CommandCompletions::eSettingsNameCompletion,
756 completion_str.c_str(),
757 match_start_point,
758 max_return_elements,
759 NULL,
760 word_complete,
761 matches);
762
763 return matches.GetSize();
764}
765
766//-------------------------------------------------------------------------
767// CommandObjectSettingInsertAfter
768//-------------------------------------------------------------------------
769
770CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter () :
771 CommandObject ("settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000772 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000773 "settings insert-after <setting-variable-name> [<index>] <new-value>")
774{
775}
776
777CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
778{
779}
780
781bool
782CommandObjectSettingsInsertAfter::Execute (CommandInterpreter &interpreter,
783 Args& command,
784 CommandReturnObject &result)
785{
786 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
787
788 const int argc = command.GetArgumentCount ();
789
790 if (argc < 3)
791 {
792 result.AppendError ("'settings insert-after' takes more arguments");
793 result.SetStatus (eReturnStatusFailed);
794 return false;
795 }
796
797 const char *var_name = command.GetArgumentAtIndex (0);
798 std::string var_name_string;
799 if ((var_name == NULL) || (var_name[0] == '\0'))
800 {
801 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
802 result.SetStatus (eReturnStatusFailed);
803 return false;
804 }
805
806 var_name_string = var_name;
807 command.Shift();
808
809 const char *index_value = command.GetArgumentAtIndex (0);
810 std::string index_value_string;
811 if ((index_value == NULL) || (index_value[0] == '\0'))
812 {
813 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
814 result.SetStatus (eReturnStatusFailed);
815 return false;
816 }
817
818 index_value_string = index_value;
819 command.Shift();
820
821 const char *var_value;
822 std::string value_string;
823
824 command.GetCommandString (value_string);
825 var_value = value_string.c_str();
826
827 if ((var_value == NULL) || (var_value[0] == '\0'))
828 {
829 result.AppendError ("'settings insert-after' command requires a valid variable value;"
830 " No value supplied");
831 result.SetStatus (eReturnStatusFailed);
832 }
833 else
834 {
835 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertAfter,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000836 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
837 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000838 if (err.Fail ())
839 {
840 result.AppendError (err.AsCString());
841 result.SetStatus (eReturnStatusFailed);
842 }
843 else
844 result.SetStatus (eReturnStatusSuccessFinishNoResult);
845 }
846
847 return result.Succeeded();
848}
849
850
851int
852CommandObjectSettingsInsertAfter::HandleArgumentCompletion (CommandInterpreter &interpreter,
853 Args &input,
854 int &cursor_index,
855 int &cursor_char_position,
856 OptionElementVector &opt_element_vector,
857 int match_start_point,
858 int max_return_elements,
859 bool &word_complete,
860 StringList &matches)
861{
862 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
863 completion_str.erase (cursor_char_position);
864
865 // Attempting to complete variable name
866 if (cursor_index < 2)
867 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
868 CommandCompletions::eSettingsNameCompletion,
869 completion_str.c_str(),
870 match_start_point,
871 max_return_elements,
872 NULL,
873 word_complete,
874 matches);
875
876 return matches.GetSize();
877}
878
879//-------------------------------------------------------------------------
880// CommandObjectSettingsAppend
881//-------------------------------------------------------------------------
882
883CommandObjectSettingsAppend::CommandObjectSettingsAppend () :
884 CommandObject ("settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000885 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000886 "settings append <setting-variable-name> <new-value>")
887{
888}
889
890CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
891{
892}
893
894bool
895CommandObjectSettingsAppend::Execute (CommandInterpreter &interpreter,
896 Args& command,
897 CommandReturnObject &result)
898{
899 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
900
901 const int argc = command.GetArgumentCount ();
902
903 if (argc < 2)
904 {
905 result.AppendError ("'settings append' takes more arguments");
906 result.SetStatus (eReturnStatusFailed);
907 return false;
908 }
909
910 const char *var_name = command.GetArgumentAtIndex (0);
911 std::string var_name_string;
912 if ((var_name == NULL) || (var_name[0] == '\0'))
913 {
914 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
915 result.SetStatus (eReturnStatusFailed);
916 return false;
917 }
918
919 var_name_string = var_name;
920 command.Shift();
921
922 const char *var_value;
923 std::string value_string;
924
925 command.GetCommandString (value_string);
926 var_value = value_string.c_str();
927
928 if ((var_value == NULL) || (var_value[0] == '\0'))
929 {
930 result.AppendError ("'settings append' command requires a valid variable value;"
931 " No value supplied");
932 result.SetStatus (eReturnStatusFailed);
933 }
934 else
935 {
936 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationAppend,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000937 false, interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000938 if (err.Fail ())
939 {
940 result.AppendError (err.AsCString());
941 result.SetStatus (eReturnStatusFailed);
942 }
943 else
944 result.SetStatus (eReturnStatusSuccessFinishNoResult);
945 }
946
947 return result.Succeeded();
948}
949
950
951int
952CommandObjectSettingsAppend::HandleArgumentCompletion (CommandInterpreter &interpreter,
953 Args &input,
954 int &cursor_index,
955 int &cursor_char_position,
956 OptionElementVector &opt_element_vector,
957 int match_start_point,
958 int max_return_elements,
959 bool &word_complete,
960 StringList &matches)
961{
962 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
963 completion_str.erase (cursor_char_position);
964
965 // Attempting to complete variable name
966 if (cursor_index < 2)
967 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
968 CommandCompletions::eSettingsNameCompletion,
969 completion_str.c_str(),
970 match_start_point,
971 max_return_elements,
972 NULL,
973 word_complete,
974 matches);
975
976 return matches.GetSize();
977}
978
979//-------------------------------------------------------------------------
980// CommandObjectSettingsClear
981//-------------------------------------------------------------------------
982
983CommandObjectSettingsClear::CommandObjectSettingsClear () :
984 CommandObject ("settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000985 "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 +0000986 "settings clear")
987{
988}
989
990CommandObjectSettingsClear::~CommandObjectSettingsClear ()
991{
992}
993
994bool
995CommandObjectSettingsClear::Execute (CommandInterpreter &interpreter,
996 Args& command,
997 CommandReturnObject &result)
998{
999 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1000
1001 const int argc = command.GetArgumentCount ();
1002
1003 if (argc != 1)
1004 {
1005 result.AppendError ("'setttings clear' takes exactly one argument");
1006 result.SetStatus (eReturnStatusFailed);
1007 return false;
1008 }
1009
1010 const char *var_name = command.GetArgumentAtIndex (0);
1011 if ((var_name == NULL) || (var_name[0] == '\0'))
1012 {
1013 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1014 result.SetStatus (eReturnStatusFailed);
1015 return false;
1016 }
1017
Caroline Tice1d2aefd2010-09-09 06:25:08 +00001018 Error err = root_settings->SetVariable (var_name, NULL, lldb::eVarSetOperationClear, false,
1019 interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001020
1021 if (err.Fail ())
1022 {
1023 result.AppendError (err.AsCString());
1024 result.SetStatus (eReturnStatusFailed);
1025 }
1026 else
1027 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1028
1029 return result.Succeeded();
1030}
1031
1032
1033int
1034CommandObjectSettingsClear::HandleArgumentCompletion (CommandInterpreter &interpreter,
1035 Args &input,
1036 int &cursor_index,
1037 int &cursor_char_position,
1038 OptionElementVector &opt_element_vector,
1039 int match_start_point,
1040 int max_return_elements,
1041 bool &word_complete,
1042 StringList &matches)
1043{
1044 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1045 completion_str.erase (cursor_char_position);
1046
1047 // Attempting to complete variable name
1048 if (cursor_index < 2)
1049 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
1050 CommandCompletions::eSettingsNameCompletion,
1051 completion_str.c_str(),
1052 match_start_point,
1053 max_return_elements,
1054 NULL,
1055 word_complete,
1056 matches);
1057
1058 return matches.GetSize();
1059}