blob: b0db6373a07d58b2f69d40a38fd1232a1422f3e7 [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 Ticeabb507a2010-09-08 21:06:11 +0000370 "List all the internal debugger settings variables that are available to the user to 'set' or 'show'.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000371 "settings list")
372{
373}
374
375CommandObjectSettingsList::~CommandObjectSettingsList()
376{
377}
378
379
380bool
381CommandObjectSettingsList::Execute (CommandInterpreter &interpreter,
382 Args& command,
383 CommandReturnObject &result)
384{
385 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
386 std::string current_prefix = root_settings->GetLevelName().AsCString();
387
388 Error err;
389
390 UserSettingsController::FindAllSettingsDescriptions (interpreter, root_settings, current_prefix,
391 result.GetOutputStream(), err);
392
393 if (err.Fail ())
394 {
395 result.AppendError (err.AsCString());
396 result.SetStatus (eReturnStatusFailed);
397 }
398 else
399 {
Chris Lattner24943d22010-06-08 16:52:24 +0000400 result.SetStatus (eReturnStatusSuccessFinishNoResult);
401 }
402
403 return result.Succeeded();
404}
405
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000406//-------------------------------------------------------------------------
407// CommandObjectSettingsRemove
408//-------------------------------------------------------------------------
409
410CommandObjectSettingsRemove::CommandObjectSettingsRemove () :
411 CommandObject ("settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000412 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000413 "settings remove <setting-variable-name> [<index>|\"key\"]")
414{
415}
416
417CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
418{
419}
420
421bool
422CommandObjectSettingsRemove::Execute (CommandInterpreter &interpreter,
423 Args& command,
424 CommandReturnObject &result)
425{
426 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
427
428 const int argc = command.GetArgumentCount ();
429
430 if (argc != 2)
431 {
432 result.AppendError ("'settings remove' takes two arguments");
433 result.SetStatus (eReturnStatusFailed);
434 return false;
435 }
436
437 const char *var_name = command.GetArgumentAtIndex (0);
438 std::string var_name_string;
439 if ((var_name == NULL) || (var_name[0] == '\0'))
440 {
441 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
442 result.SetStatus (eReturnStatusFailed);
443 return false;
444 }
445
446 var_name_string = var_name;
447 command.Shift();
448
449 const char *index_value = command.GetArgumentAtIndex (0);
450 std::string index_value_string;
451 if ((index_value == NULL) || (index_value[0] == '\0'))
452 {
453 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
454 result.SetStatus (eReturnStatusFailed);
455 return false;
456 }
457
458 index_value_string = index_value;
459
460 Error err = root_settings->SetVariable (var_name_string.c_str(), NULL, lldb::eVarSetOperationRemove,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000461 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
462 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000463 if (err.Fail ())
464 {
465 result.AppendError (err.AsCString());
466 result.SetStatus (eReturnStatusFailed);
467 }
468 else
469 result.SetStatus (eReturnStatusSuccessFinishNoResult);
470
471 return result.Succeeded();
472}
473
474int
475CommandObjectSettingsRemove::HandleArgumentCompletion (CommandInterpreter &interpreter,
476 Args &input,
477 int &cursor_index,
478 int &cursor_char_position,
479 OptionElementVector &opt_element_vector,
480 int match_start_point,
481 int max_return_elements,
482 bool &word_complete,
483 StringList &matches)
484{
485 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
486 completion_str.erase (cursor_char_position);
487
488 // Attempting to complete variable name
489 if (cursor_index < 2)
490 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
491 CommandCompletions::eSettingsNameCompletion,
492 completion_str.c_str(),
493 match_start_point,
494 max_return_elements,
495 NULL,
496 word_complete,
497 matches);
498
499 return matches.GetSize();
500}
501
502//-------------------------------------------------------------------------
503// CommandObjectSettingsReplace
504//-------------------------------------------------------------------------
505
506CommandObjectSettingsReplace::CommandObjectSettingsReplace () :
507 CommandObject ("settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000508 "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 +0000509 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
510{
511}
512
513CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
514{
515}
516
517bool
518CommandObjectSettingsReplace::Execute (CommandInterpreter &interpreter,
519 Args& command,
520 CommandReturnObject &result)
521{
522 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
523
524 const int argc = command.GetArgumentCount ();
525
526 if (argc < 3)
527 {
528 result.AppendError ("'settings replace' takes more arguments");
529 result.SetStatus (eReturnStatusFailed);
530 return false;
531 }
532
533 const char *var_name = command.GetArgumentAtIndex (0);
534 std::string var_name_string;
535 if ((var_name == NULL) || (var_name[0] == '\0'))
536 {
537 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
538 result.SetStatus (eReturnStatusFailed);
539 return false;
540 }
541
542 var_name_string = var_name;
543 command.Shift();
544
545 const char *index_value = command.GetArgumentAtIndex (0);
546 std::string index_value_string;
547 if ((index_value == NULL) || (index_value[0] == '\0'))
548 {
549 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
550 result.SetStatus (eReturnStatusFailed);
551 return false;
552 }
553
554 index_value_string = index_value;
555 command.Shift();
556
557 const char *var_value;
558 std::string value_string;
559
560 command.GetCommandString (value_string);
561 var_value = value_string.c_str();
562
563 if ((var_value == NULL) || (var_value[0] == '\0'))
564 {
565 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
566 result.SetStatus (eReturnStatusFailed);
567 }
568 else
569 {
570 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationReplace,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000571 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
572 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000573 if (err.Fail ())
574 {
575 result.AppendError (err.AsCString());
576 result.SetStatus (eReturnStatusFailed);
577 }
578 else
579 result.SetStatus (eReturnStatusSuccessFinishNoResult);
580 }
581
582 return result.Succeeded();
583}
584
585int
586CommandObjectSettingsReplace::HandleArgumentCompletion (CommandInterpreter &interpreter,
587 Args &input,
588 int &cursor_index,
589 int &cursor_char_position,
590 OptionElementVector &opt_element_vector,
591 int match_start_point,
592 int max_return_elements,
593 bool &word_complete,
594 StringList &matches)
595{
596 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
597 completion_str.erase (cursor_char_position);
598
599 // Attempting to complete variable name
600 if (cursor_index < 2)
601 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
602 CommandCompletions::eSettingsNameCompletion,
603 completion_str.c_str(),
604 match_start_point,
605 max_return_elements,
606 NULL,
607 word_complete,
608 matches);
609
610 return matches.GetSize();
611}
612
613//-------------------------------------------------------------------------
614// CommandObjectSettingsInsertBefore
615//-------------------------------------------------------------------------
616
617CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore () :
618 CommandObject ("settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000619 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000620 "settings insert-before <setting-variable-name> [<index>] <new-value>")
621{
622}
623
624CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
625{
626}
627
628bool
629CommandObjectSettingsInsertBefore::Execute (CommandInterpreter &interpreter,
630 Args& command,
631 CommandReturnObject &result)
632{
633 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
634
635 const int argc = command.GetArgumentCount ();
636
637 if (argc < 3)
638 {
639 result.AppendError ("'settings insert-before' takes more arguments");
640 result.SetStatus (eReturnStatusFailed);
641 return false;
642 }
643
644 const char *var_name = command.GetArgumentAtIndex (0);
645 std::string var_name_string;
646 if ((var_name == NULL) || (var_name[0] == '\0'))
647 {
648 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
649 result.SetStatus (eReturnStatusFailed);
650 return false;
651 }
652
653 var_name_string = var_name;
654 command.Shift();
655
656 const char *index_value = command.GetArgumentAtIndex (0);
657 std::string index_value_string;
658 if ((index_value == NULL) || (index_value[0] == '\0'))
659 {
660 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
661 result.SetStatus (eReturnStatusFailed);
662 return false;
663 }
664
665 index_value_string = index_value;
666 command.Shift();
667
668 const char *var_value;
669 std::string value_string;
670
671 command.GetCommandString (value_string);
672 var_value = value_string.c_str();
673
674 if ((var_value == NULL) || (var_value[0] == '\0'))
675 {
676 result.AppendError ("'settings insert-before' command requires a valid variable value;"
677 " No value supplied");
678 result.SetStatus (eReturnStatusFailed);
679 }
680 else
681 {
682 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertBefore,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000683 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
684 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000685 if (err.Fail ())
686 {
687 result.AppendError (err.AsCString());
688 result.SetStatus (eReturnStatusFailed);
689 }
690 else
691 result.SetStatus (eReturnStatusSuccessFinishNoResult);
692 }
693
694 return result.Succeeded();
695}
696
697
698int
699CommandObjectSettingsInsertBefore::HandleArgumentCompletion (CommandInterpreter &interpreter,
700 Args &input,
701 int &cursor_index,
702 int &cursor_char_position,
703 OptionElementVector &opt_element_vector,
704 int match_start_point,
705 int max_return_elements,
706 bool &word_complete,
707 StringList &matches)
708{
709 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
710 completion_str.erase (cursor_char_position);
711
712 // Attempting to complete variable name
713 if (cursor_index < 2)
714 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
715 CommandCompletions::eSettingsNameCompletion,
716 completion_str.c_str(),
717 match_start_point,
718 max_return_elements,
719 NULL,
720 word_complete,
721 matches);
722
723 return matches.GetSize();
724}
725
726//-------------------------------------------------------------------------
727// CommandObjectSettingInsertAfter
728//-------------------------------------------------------------------------
729
730CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter () :
731 CommandObject ("settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000732 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000733 "settings insert-after <setting-variable-name> [<index>] <new-value>")
734{
735}
736
737CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
738{
739}
740
741bool
742CommandObjectSettingsInsertAfter::Execute (CommandInterpreter &interpreter,
743 Args& command,
744 CommandReturnObject &result)
745{
746 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
747
748 const int argc = command.GetArgumentCount ();
749
750 if (argc < 3)
751 {
752 result.AppendError ("'settings insert-after' takes more arguments");
753 result.SetStatus (eReturnStatusFailed);
754 return false;
755 }
756
757 const char *var_name = command.GetArgumentAtIndex (0);
758 std::string var_name_string;
759 if ((var_name == NULL) || (var_name[0] == '\0'))
760 {
761 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
762 result.SetStatus (eReturnStatusFailed);
763 return false;
764 }
765
766 var_name_string = var_name;
767 command.Shift();
768
769 const char *index_value = command.GetArgumentAtIndex (0);
770 std::string index_value_string;
771 if ((index_value == NULL) || (index_value[0] == '\0'))
772 {
773 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
774 result.SetStatus (eReturnStatusFailed);
775 return false;
776 }
777
778 index_value_string = index_value;
779 command.Shift();
780
781 const char *var_value;
782 std::string value_string;
783
784 command.GetCommandString (value_string);
785 var_value = value_string.c_str();
786
787 if ((var_value == NULL) || (var_value[0] == '\0'))
788 {
789 result.AppendError ("'settings insert-after' command requires a valid variable value;"
790 " No value supplied");
791 result.SetStatus (eReturnStatusFailed);
792 }
793 else
794 {
795 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertAfter,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000796 false, interpreter.GetDebugger().GetInstanceName().AsCString(),
797 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000798 if (err.Fail ())
799 {
800 result.AppendError (err.AsCString());
801 result.SetStatus (eReturnStatusFailed);
802 }
803 else
804 result.SetStatus (eReturnStatusSuccessFinishNoResult);
805 }
806
807 return result.Succeeded();
808}
809
810
811int
812CommandObjectSettingsInsertAfter::HandleArgumentCompletion (CommandInterpreter &interpreter,
813 Args &input,
814 int &cursor_index,
815 int &cursor_char_position,
816 OptionElementVector &opt_element_vector,
817 int match_start_point,
818 int max_return_elements,
819 bool &word_complete,
820 StringList &matches)
821{
822 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
823 completion_str.erase (cursor_char_position);
824
825 // Attempting to complete variable name
826 if (cursor_index < 2)
827 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
828 CommandCompletions::eSettingsNameCompletion,
829 completion_str.c_str(),
830 match_start_point,
831 max_return_elements,
832 NULL,
833 word_complete,
834 matches);
835
836 return matches.GetSize();
837}
838
839//-------------------------------------------------------------------------
840// CommandObjectSettingsAppend
841//-------------------------------------------------------------------------
842
843CommandObjectSettingsAppend::CommandObjectSettingsAppend () :
844 CommandObject ("settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000845 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000846 "settings append <setting-variable-name> <new-value>")
847{
848}
849
850CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
851{
852}
853
854bool
855CommandObjectSettingsAppend::Execute (CommandInterpreter &interpreter,
856 Args& command,
857 CommandReturnObject &result)
858{
859 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
860
861 const int argc = command.GetArgumentCount ();
862
863 if (argc < 2)
864 {
865 result.AppendError ("'settings append' takes more arguments");
866 result.SetStatus (eReturnStatusFailed);
867 return false;
868 }
869
870 const char *var_name = command.GetArgumentAtIndex (0);
871 std::string var_name_string;
872 if ((var_name == NULL) || (var_name[0] == '\0'))
873 {
874 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
875 result.SetStatus (eReturnStatusFailed);
876 return false;
877 }
878
879 var_name_string = var_name;
880 command.Shift();
881
882 const char *var_value;
883 std::string value_string;
884
885 command.GetCommandString (value_string);
886 var_value = value_string.c_str();
887
888 if ((var_value == NULL) || (var_value[0] == '\0'))
889 {
890 result.AppendError ("'settings append' command requires a valid variable value;"
891 " No value supplied");
892 result.SetStatus (eReturnStatusFailed);
893 }
894 else
895 {
896 Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationAppend,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000897 false, interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000898 if (err.Fail ())
899 {
900 result.AppendError (err.AsCString());
901 result.SetStatus (eReturnStatusFailed);
902 }
903 else
904 result.SetStatus (eReturnStatusSuccessFinishNoResult);
905 }
906
907 return result.Succeeded();
908}
909
910
911int
912CommandObjectSettingsAppend::HandleArgumentCompletion (CommandInterpreter &interpreter,
913 Args &input,
914 int &cursor_index,
915 int &cursor_char_position,
916 OptionElementVector &opt_element_vector,
917 int match_start_point,
918 int max_return_elements,
919 bool &word_complete,
920 StringList &matches)
921{
922 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
923 completion_str.erase (cursor_char_position);
924
925 // Attempting to complete variable name
926 if (cursor_index < 2)
927 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
928 CommandCompletions::eSettingsNameCompletion,
929 completion_str.c_str(),
930 match_start_point,
931 max_return_elements,
932 NULL,
933 word_complete,
934 matches);
935
936 return matches.GetSize();
937}
938
939//-------------------------------------------------------------------------
940// CommandObjectSettingsClear
941//-------------------------------------------------------------------------
942
943CommandObjectSettingsClear::CommandObjectSettingsClear () :
944 CommandObject ("settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000945 "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 +0000946 "settings clear")
947{
948}
949
950CommandObjectSettingsClear::~CommandObjectSettingsClear ()
951{
952}
953
954bool
955CommandObjectSettingsClear::Execute (CommandInterpreter &interpreter,
956 Args& command,
957 CommandReturnObject &result)
958{
959 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
960
961 const int argc = command.GetArgumentCount ();
962
963 if (argc != 1)
964 {
965 result.AppendError ("'setttings clear' takes exactly one argument");
966 result.SetStatus (eReturnStatusFailed);
967 return false;
968 }
969
970 const char *var_name = command.GetArgumentAtIndex (0);
971 if ((var_name == NULL) || (var_name[0] == '\0'))
972 {
973 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
974 result.SetStatus (eReturnStatusFailed);
975 return false;
976 }
977
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000978 Error err = root_settings->SetVariable (var_name, NULL, lldb::eVarSetOperationClear, false,
979 interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000980
981 if (err.Fail ())
982 {
983 result.AppendError (err.AsCString());
984 result.SetStatus (eReturnStatusFailed);
985 }
986 else
987 result.SetStatus (eReturnStatusSuccessFinishNoResult);
988
989 return result.Succeeded();
990}
991
992
993int
994CommandObjectSettingsClear::HandleArgumentCompletion (CommandInterpreter &interpreter,
995 Args &input,
996 int &cursor_index,
997 int &cursor_char_position,
998 OptionElementVector &opt_element_vector,
999 int match_start_point,
1000 int max_return_elements,
1001 bool &word_complete,
1002 StringList &matches)
1003{
1004 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1005 completion_str.erase (cursor_char_position);
1006
1007 // Attempting to complete variable name
1008 if (cursor_index < 2)
1009 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
1010 CommandCompletions::eSettingsNameCompletion,
1011 completion_str.c_str(),
1012 match_start_point,
1013 max_return_elements,
1014 NULL,
1015 word_complete,
1016 matches);
1017
1018 return matches.GetSize();
1019}