blob: 62657bed2d0aa19c453aadabf4719b14dabd5c57 [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,
120 m_options.m_override);
121 if (err.Fail ())
122 {
123 result.AppendError (err.AsCString());
124 result.SetStatus (eReturnStatusFailed);
125 }
126 else
127 result.SetStatus (eReturnStatusSuccessFinishNoResult);
128 }
129
130 return result.Succeeded();
131}
132
133int
134CommandObjectSettingsSet::HandleArgumentCompletion (CommandInterpreter &interpreter,
135 Args &input,
136 int &cursor_index,
137 int &cursor_char_position,
138 OptionElementVector &opt_element_vector,
139 int match_start_point,
140 int max_return_elements,
141 bool &word_complete,
142 StringList &matches)
143{
144 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
145 completion_str.erase (cursor_char_position);
146
147 // Attempting to complete variable name
148 if (cursor_index == 1)
149 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
150 CommandCompletions::eSettingsNameCompletion,
151 completion_str.c_str(),
152 match_start_point,
153 max_return_elements,
154 NULL,
155 word_complete,
156 matches);
157
158 // Attempting to complete value
159 if ((cursor_index == 2) // Partly into the variable's value
160 || (cursor_index == 1 // Or at the end of a completed valid variable name
161 && matches.GetSize() == 1
162 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
163 {
164 matches.Clear();
165 lldb::UserSettingsControllerSP root_settings = Debugger::GetSettingsController();
166 if (cursor_index == 1)
167 {
168 // The user is at the end of the variable name, which is complete and valid.
169 UserSettingsController::CompleteSettingsValue (root_settings,
170 input.GetArgumentAtIndex (1), // variable name
171 NULL, // empty value string
172 word_complete,
173 matches);
174 }
175 else
176 {
177 // The user is partly into the variable value.
178 UserSettingsController::CompleteSettingsValue (root_settings,
179 input.GetArgumentAtIndex (1), // variable name
180 completion_str.c_str(), // partial value string
181 word_complete,
182 matches);
183 }
184 }
185
186 return matches.GetSize();
187}
188
189//-------------------------------------------------------------------------
190// CommandObjectSettingsSet::CommandOptions
191//-------------------------------------------------------------------------
192
193CommandObjectSettingsSet::CommandOptions::CommandOptions () :
194 Options (),
195 m_override (false),
196 m_reset (false)
197{
198}
199
200CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
201{
202}
203
204lldb::OptionDefinition
205CommandObjectSettingsSet::CommandOptions::g_option_table[] =
206{
207 { 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." },
208
209 { 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." },
210};
211
212const lldb::OptionDefinition*
213CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
214{
215 return g_option_table;
216}
217
218Error
219CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
220{
221 Error error;
222 char short_option = (char) m_getopt_table[option_idx].val;
223
224 switch (short_option)
225 {
226 case 'o':
227 m_override = true;
228 break;
229 case 'r':
230 m_reset = true;
231 break;
232 default:
233 error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option);
234 break;
235 }
236
237 return error;
238}
239
240void
241CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
242{
243 Options::ResetOptionValues ();
244
245 m_override = false;
246 m_reset = false;
247}
248
249Options *
250CommandObjectSettingsSet::GetOptions ()
251{
252 return &m_options;
253}
254
255
256//-------------------------------------------------------------------------
257// CommandObjectSettingsShow -- Show current values
258//-------------------------------------------------------------------------
259
260CommandObjectSettingsShow::CommandObjectSettingsShow () :
261 CommandObject ("settings show",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000262 "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 +0000263 "settings show [<setting-variable-name>]")
264{
265}
266
267CommandObjectSettingsShow::~CommandObjectSettingsShow()
268{
269}
270
271
272bool
273CommandObjectSettingsShow::Execute (CommandInterpreter &interpreter,
274 Args& command,
275 CommandReturnObject &result)
276{
277 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
278 std::string current_prefix = root_settings->GetLevelName().AsCString();
279
280 Error err;
281
282 if (command.GetArgumentCount())
283 {
284 // The user requested to see the value of a particular variable.
285 lldb::SettableVariableType var_type;
286 const char *variable_name = command.GetArgumentAtIndex (0);
287 StringList value = root_settings->GetVariable (variable_name, var_type);
288
289 if (value.GetSize() == 0)
290 {
291 result.AppendErrorWithFormat ("Unable to find variable named '%s'. "
292 "Try 'show' to see all variable values.\n", variable_name);
293 result.SetStatus (eReturnStatusFailed);
294
295 }
296 else
297 {
298 char *type_name = (char *) "";
299 if (var_type != eSetVarTypeNone)
300 {
301 StreamString tmp_str;
302 tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type));
303 type_name = (char *) tmp_str.GetData();
304 }
305
306 if (value.GetSize() == 1)
307 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
308 else
309 {
310 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
311 for (int i = 0; i < value.GetSize(); ++i)
312 {
313 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
314 }
315 }
316 result.SetStatus (eReturnStatusSuccessFinishNoResult);
317 }
318 }
319 else
320 {
321 UserSettingsController::GetAllVariableValues (interpreter, root_settings, current_prefix,
322 result.GetOutputStream(), err);
323 if (err.Fail ())
324 {
325 result.AppendError (err.AsCString());
326 result.SetStatus (eReturnStatusFailed);
327 }
328 else
329 {
330 result.SetStatus (eReturnStatusSuccessFinishNoResult);
331 }
332 }
333
334 return result.Succeeded();
335}
336
337int
338CommandObjectSettingsShow::HandleArgumentCompletion (CommandInterpreter &interpreter,
339 Args &input,
340 int &cursor_index,
341 int &cursor_char_position,
342 OptionElementVector &opt_element_vector,
343 int match_start_point,
344 int max_return_elements,
345 bool &word_complete,
346 StringList &matches)
347{
348 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
349 completion_str.erase (cursor_char_position);
350
351 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
352 CommandCompletions::eSettingsNameCompletion,
353 completion_str.c_str(),
354 match_start_point,
355 max_return_elements,
356 NULL,
357 word_complete,
358 matches);
359 return matches.GetSize();
360}
361
362//-------------------------------------------------------------------------
363// CommandObjectSettingsList
364//-------------------------------------------------------------------------
365
366CommandObjectSettingsList::CommandObjectSettingsList () :
367 CommandObject ("settings list",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000368 "List all the internal debugger settings variables that are available to the user to 'set' or 'show'.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000369 "settings list")
370{
371}
372
373CommandObjectSettingsList::~CommandObjectSettingsList()
374{
375}
376
377
378bool
379CommandObjectSettingsList::Execute (CommandInterpreter &interpreter,
380 Args& command,
381 CommandReturnObject &result)
382{
383 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
384 std::string current_prefix = root_settings->GetLevelName().AsCString();
385
386 Error err;
387
388 UserSettingsController::FindAllSettingsDescriptions (interpreter, root_settings, current_prefix,
389 result.GetOutputStream(), err);
390
391 if (err.Fail ())
392 {
393 result.AppendError (err.AsCString());
394 result.SetStatus (eReturnStatusFailed);
395 }
396 else
397 {
Chris Lattner24943d22010-06-08 16:52:24 +0000398 result.SetStatus (eReturnStatusSuccessFinishNoResult);
399 }
400
401 return result.Succeeded();
402}
403
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000404//-------------------------------------------------------------------------
405// CommandObjectSettingsRemove
406//-------------------------------------------------------------------------
407
408CommandObjectSettingsRemove::CommandObjectSettingsRemove () :
409 CommandObject ("settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000410 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000411 "settings remove <setting-variable-name> [<index>|\"key\"]")
412{
413}
414
415CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
416{
417}
418
419bool
420CommandObjectSettingsRemove::Execute (CommandInterpreter &interpreter,
421 Args& command,
422 CommandReturnObject &result)
423{
424 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
425
426 const int argc = command.GetArgumentCount ();
427
428 if (argc != 2)
429 {
430 result.AppendError ("'settings remove' takes two arguments");
431 result.SetStatus (eReturnStatusFailed);
432 return false;
433 }
434
435 const char *var_name = command.GetArgumentAtIndex (0);
436 std::string var_name_string;
437 if ((var_name == NULL) || (var_name[0] == '\0'))
438 {
439 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
440 result.SetStatus (eReturnStatusFailed);
441 return false;
442 }
443
444 var_name_string = var_name;
445 command.Shift();
446
447 const char *index_value = command.GetArgumentAtIndex (0);
448 std::string index_value_string;
449 if ((index_value == NULL) || (index_value[0] == '\0'))
450 {
451 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
452 result.SetStatus (eReturnStatusFailed);
453 return false;
454 }
455
456 index_value_string = index_value;
457
458 Error err = root_settings->SetVariable (var_name_string.c_str(), NULL, lldb::eVarSetOperationRemove,
459 false, index_value_string.c_str());
460 if (err.Fail ())
461 {
462 result.AppendError (err.AsCString());
463 result.SetStatus (eReturnStatusFailed);
464 }
465 else
466 result.SetStatus (eReturnStatusSuccessFinishNoResult);
467
468 return result.Succeeded();
469}
470
471int
472CommandObjectSettingsRemove::HandleArgumentCompletion (CommandInterpreter &interpreter,
473 Args &input,
474 int &cursor_index,
475 int &cursor_char_position,
476 OptionElementVector &opt_element_vector,
477 int match_start_point,
478 int max_return_elements,
479 bool &word_complete,
480 StringList &matches)
481{
482 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
483 completion_str.erase (cursor_char_position);
484
485 // Attempting to complete variable name
486 if (cursor_index < 2)
487 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
488 CommandCompletions::eSettingsNameCompletion,
489 completion_str.c_str(),
490 match_start_point,
491 max_return_elements,
492 NULL,
493 word_complete,
494 matches);
495
496 return matches.GetSize();
497}
498
499//-------------------------------------------------------------------------
500// CommandObjectSettingsReplace
501//-------------------------------------------------------------------------
502
503CommandObjectSettingsReplace::CommandObjectSettingsReplace () :
504 CommandObject ("settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000505 "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 +0000506 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
507{
508}
509
510CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
511{
512}
513
514bool
515CommandObjectSettingsReplace::Execute (CommandInterpreter &interpreter,
516 Args& command,
517 CommandReturnObject &result)
518{
519 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
520
521 const int argc = command.GetArgumentCount ();
522
523 if (argc < 3)
524 {
525 result.AppendError ("'settings replace' takes more arguments");
526 result.SetStatus (eReturnStatusFailed);
527 return false;
528 }
529
530 const char *var_name = command.GetArgumentAtIndex (0);
531 std::string var_name_string;
532 if ((var_name == NULL) || (var_name[0] == '\0'))
533 {
534 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
535 result.SetStatus (eReturnStatusFailed);
536 return false;
537 }
538
539 var_name_string = var_name;
540 command.Shift();
541
542 const char *index_value = command.GetArgumentAtIndex (0);
543 std::string index_value_string;
544 if ((index_value == NULL) || (index_value[0] == '\0'))
545 {
546 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
547 result.SetStatus (eReturnStatusFailed);
548 return false;
549 }
550
551 index_value_string = index_value;
552 command.Shift();
553
554 const char *var_value;
555 std::string value_string;
556
557 command.GetCommandString (value_string);
558 var_value = value_string.c_str();
559
560 if ((var_value == NULL) || (var_value[0] == '\0'))
561 {
562 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
563 result.SetStatus (eReturnStatusFailed);
564 }
565 else
566 {
567 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationReplace,
568 false, index_value_string.c_str());
569 if (err.Fail ())
570 {
571 result.AppendError (err.AsCString());
572 result.SetStatus (eReturnStatusFailed);
573 }
574 else
575 result.SetStatus (eReturnStatusSuccessFinishNoResult);
576 }
577
578 return result.Succeeded();
579}
580
581int
582CommandObjectSettingsReplace::HandleArgumentCompletion (CommandInterpreter &interpreter,
583 Args &input,
584 int &cursor_index,
585 int &cursor_char_position,
586 OptionElementVector &opt_element_vector,
587 int match_start_point,
588 int max_return_elements,
589 bool &word_complete,
590 StringList &matches)
591{
592 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
593 completion_str.erase (cursor_char_position);
594
595 // Attempting to complete variable name
596 if (cursor_index < 2)
597 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
598 CommandCompletions::eSettingsNameCompletion,
599 completion_str.c_str(),
600 match_start_point,
601 max_return_elements,
602 NULL,
603 word_complete,
604 matches);
605
606 return matches.GetSize();
607}
608
609//-------------------------------------------------------------------------
610// CommandObjectSettingsInsertBefore
611//-------------------------------------------------------------------------
612
613CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore () :
614 CommandObject ("settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000615 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000616 "settings insert-before <setting-variable-name> [<index>] <new-value>")
617{
618}
619
620CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
621{
622}
623
624bool
625CommandObjectSettingsInsertBefore::Execute (CommandInterpreter &interpreter,
626 Args& command,
627 CommandReturnObject &result)
628{
629 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
630
631 const int argc = command.GetArgumentCount ();
632
633 if (argc < 3)
634 {
635 result.AppendError ("'settings insert-before' takes more arguments");
636 result.SetStatus (eReturnStatusFailed);
637 return false;
638 }
639
640 const char *var_name = command.GetArgumentAtIndex (0);
641 std::string var_name_string;
642 if ((var_name == NULL) || (var_name[0] == '\0'))
643 {
644 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
645 result.SetStatus (eReturnStatusFailed);
646 return false;
647 }
648
649 var_name_string = var_name;
650 command.Shift();
651
652 const char *index_value = command.GetArgumentAtIndex (0);
653 std::string index_value_string;
654 if ((index_value == NULL) || (index_value[0] == '\0'))
655 {
656 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
657 result.SetStatus (eReturnStatusFailed);
658 return false;
659 }
660
661 index_value_string = index_value;
662 command.Shift();
663
664 const char *var_value;
665 std::string value_string;
666
667 command.GetCommandString (value_string);
668 var_value = value_string.c_str();
669
670 if ((var_value == NULL) || (var_value[0] == '\0'))
671 {
672 result.AppendError ("'settings insert-before' command requires a valid variable value;"
673 " No value supplied");
674 result.SetStatus (eReturnStatusFailed);
675 }
676 else
677 {
678 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertBefore,
679 false, index_value_string.c_str());
680 if (err.Fail ())
681 {
682 result.AppendError (err.AsCString());
683 result.SetStatus (eReturnStatusFailed);
684 }
685 else
686 result.SetStatus (eReturnStatusSuccessFinishNoResult);
687 }
688
689 return result.Succeeded();
690}
691
692
693int
694CommandObjectSettingsInsertBefore::HandleArgumentCompletion (CommandInterpreter &interpreter,
695 Args &input,
696 int &cursor_index,
697 int &cursor_char_position,
698 OptionElementVector &opt_element_vector,
699 int match_start_point,
700 int max_return_elements,
701 bool &word_complete,
702 StringList &matches)
703{
704 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
705 completion_str.erase (cursor_char_position);
706
707 // Attempting to complete variable name
708 if (cursor_index < 2)
709 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
710 CommandCompletions::eSettingsNameCompletion,
711 completion_str.c_str(),
712 match_start_point,
713 max_return_elements,
714 NULL,
715 word_complete,
716 matches);
717
718 return matches.GetSize();
719}
720
721//-------------------------------------------------------------------------
722// CommandObjectSettingInsertAfter
723//-------------------------------------------------------------------------
724
725CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter () :
726 CommandObject ("settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000727 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000728 "settings insert-after <setting-variable-name> [<index>] <new-value>")
729{
730}
731
732CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
733{
734}
735
736bool
737CommandObjectSettingsInsertAfter::Execute (CommandInterpreter &interpreter,
738 Args& command,
739 CommandReturnObject &result)
740{
741 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
742
743 const int argc = command.GetArgumentCount ();
744
745 if (argc < 3)
746 {
747 result.AppendError ("'settings insert-after' takes more arguments");
748 result.SetStatus (eReturnStatusFailed);
749 return false;
750 }
751
752 const char *var_name = command.GetArgumentAtIndex (0);
753 std::string var_name_string;
754 if ((var_name == NULL) || (var_name[0] == '\0'))
755 {
756 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
757 result.SetStatus (eReturnStatusFailed);
758 return false;
759 }
760
761 var_name_string = var_name;
762 command.Shift();
763
764 const char *index_value = command.GetArgumentAtIndex (0);
765 std::string index_value_string;
766 if ((index_value == NULL) || (index_value[0] == '\0'))
767 {
768 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
769 result.SetStatus (eReturnStatusFailed);
770 return false;
771 }
772
773 index_value_string = index_value;
774 command.Shift();
775
776 const char *var_value;
777 std::string value_string;
778
779 command.GetCommandString (value_string);
780 var_value = value_string.c_str();
781
782 if ((var_value == NULL) || (var_value[0] == '\0'))
783 {
784 result.AppendError ("'settings insert-after' command requires a valid variable value;"
785 " No value supplied");
786 result.SetStatus (eReturnStatusFailed);
787 }
788 else
789 {
790 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertAfter,
791 false, index_value_string.c_str());
792 if (err.Fail ())
793 {
794 result.AppendError (err.AsCString());
795 result.SetStatus (eReturnStatusFailed);
796 }
797 else
798 result.SetStatus (eReturnStatusSuccessFinishNoResult);
799 }
800
801 return result.Succeeded();
802}
803
804
805int
806CommandObjectSettingsInsertAfter::HandleArgumentCompletion (CommandInterpreter &interpreter,
807 Args &input,
808 int &cursor_index,
809 int &cursor_char_position,
810 OptionElementVector &opt_element_vector,
811 int match_start_point,
812 int max_return_elements,
813 bool &word_complete,
814 StringList &matches)
815{
816 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
817 completion_str.erase (cursor_char_position);
818
819 // Attempting to complete variable name
820 if (cursor_index < 2)
821 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
822 CommandCompletions::eSettingsNameCompletion,
823 completion_str.c_str(),
824 match_start_point,
825 max_return_elements,
826 NULL,
827 word_complete,
828 matches);
829
830 return matches.GetSize();
831}
832
833//-------------------------------------------------------------------------
834// CommandObjectSettingsAppend
835//-------------------------------------------------------------------------
836
837CommandObjectSettingsAppend::CommandObjectSettingsAppend () :
838 CommandObject ("settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000839 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000840 "settings append <setting-variable-name> <new-value>")
841{
842}
843
844CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
845{
846}
847
848bool
849CommandObjectSettingsAppend::Execute (CommandInterpreter &interpreter,
850 Args& command,
851 CommandReturnObject &result)
852{
853 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
854
855 const int argc = command.GetArgumentCount ();
856
857 if (argc < 2)
858 {
859 result.AppendError ("'settings append' takes more arguments");
860 result.SetStatus (eReturnStatusFailed);
861 return false;
862 }
863
864 const char *var_name = command.GetArgumentAtIndex (0);
865 std::string var_name_string;
866 if ((var_name == NULL) || (var_name[0] == '\0'))
867 {
868 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
869 result.SetStatus (eReturnStatusFailed);
870 return false;
871 }
872
873 var_name_string = var_name;
874 command.Shift();
875
876 const char *var_value;
877 std::string value_string;
878
879 command.GetCommandString (value_string);
880 var_value = value_string.c_str();
881
882 if ((var_value == NULL) || (var_value[0] == '\0'))
883 {
884 result.AppendError ("'settings append' command requires a valid variable value;"
885 " No value supplied");
886 result.SetStatus (eReturnStatusFailed);
887 }
888 else
889 {
890 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationAppend,
891 false);
892 if (err.Fail ())
893 {
894 result.AppendError (err.AsCString());
895 result.SetStatus (eReturnStatusFailed);
896 }
897 else
898 result.SetStatus (eReturnStatusSuccessFinishNoResult);
899 }
900
901 return result.Succeeded();
902}
903
904
905int
906CommandObjectSettingsAppend::HandleArgumentCompletion (CommandInterpreter &interpreter,
907 Args &input,
908 int &cursor_index,
909 int &cursor_char_position,
910 OptionElementVector &opt_element_vector,
911 int match_start_point,
912 int max_return_elements,
913 bool &word_complete,
914 StringList &matches)
915{
916 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
917 completion_str.erase (cursor_char_position);
918
919 // Attempting to complete variable name
920 if (cursor_index < 2)
921 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
922 CommandCompletions::eSettingsNameCompletion,
923 completion_str.c_str(),
924 match_start_point,
925 max_return_elements,
926 NULL,
927 word_complete,
928 matches);
929
930 return matches.GetSize();
931}
932
933//-------------------------------------------------------------------------
934// CommandObjectSettingsClear
935//-------------------------------------------------------------------------
936
937CommandObjectSettingsClear::CommandObjectSettingsClear () :
938 CommandObject ("settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000939 "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 +0000940 "settings clear")
941{
942}
943
944CommandObjectSettingsClear::~CommandObjectSettingsClear ()
945{
946}
947
948bool
949CommandObjectSettingsClear::Execute (CommandInterpreter &interpreter,
950 Args& command,
951 CommandReturnObject &result)
952{
953 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
954
955 const int argc = command.GetArgumentCount ();
956
957 if (argc != 1)
958 {
959 result.AppendError ("'setttings clear' takes exactly one argument");
960 result.SetStatus (eReturnStatusFailed);
961 return false;
962 }
963
964 const char *var_name = command.GetArgumentAtIndex (0);
965 if ((var_name == NULL) || (var_name[0] == '\0'))
966 {
967 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
968 result.SetStatus (eReturnStatusFailed);
969 return false;
970 }
971
972 Error err = root_settings->SetVariable (var_name, NULL, lldb::eVarSetOperationClear, false);
973
974 if (err.Fail ())
975 {
976 result.AppendError (err.AsCString());
977 result.SetStatus (eReturnStatusFailed);
978 }
979 else
980 result.SetStatus (eReturnStatusSuccessFinishNoResult);
981
982 return result.Succeeded();
983}
984
985
986int
987CommandObjectSettingsClear::HandleArgumentCompletion (CommandInterpreter &interpreter,
988 Args &input,
989 int &cursor_index,
990 int &cursor_char_position,
991 OptionElementVector &opt_element_vector,
992 int match_start_point,
993 int max_return_elements,
994 bool &word_complete,
995 StringList &matches)
996{
997 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
998 completion_str.erase (cursor_char_position);
999
1000 // Attempting to complete variable name
1001 if (cursor_index < 2)
1002 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
1003 CommandCompletions::eSettingsNameCompletion,
1004 completion_str.c_str(),
1005 match_start_point,
1006 max_return_elements,
1007 NULL,
1008 word_complete,
1009 matches);
1010
1011 return matches.GetSize();
1012}