1 //===-- CommandObjectSettings.cpp -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "CommandObjectSettings.h"
16 // Other libraries and framework includes
18 #include "lldb/Interpreter/CommandInterpreter.h"
19 #include "lldb/Interpreter/CommandReturnObject.h"
20 #include "lldb/Interpreter/CommandCompletions.h"
23 using namespace lldb_private;
24 #include "llvm/ADT/StringRef.h"
26 //-------------------------------------------------------------------------
27 // CommandObjectSettingsSet
28 //-------------------------------------------------------------------------
30 class CommandObjectSettingsSet : public CommandObjectRaw
33 CommandObjectSettingsSet (CommandInterpreter &interpreter) :
34 CommandObjectRaw (interpreter,
36 "Set or change the value of a single debugger setting variable.",
38 m_options (interpreter)
40 CommandArgumentEntry arg1;
41 CommandArgumentEntry arg2;
42 CommandArgumentData var_name_arg;
43 CommandArgumentData value_arg;
45 // Define the first (and only) variant of this arg.
46 var_name_arg.arg_type = eArgTypeSettingVariableName;
47 var_name_arg.arg_repetition = eArgRepeatPlain;
49 // There is only one variant this argument could be; put it into the argument entry.
50 arg1.push_back (var_name_arg);
52 // Define the first (and only) variant of this arg.
53 value_arg.arg_type = eArgTypeValue;
54 value_arg.arg_repetition = eArgRepeatPlain;
56 // There is only one variant this argument could be; put it into the argument entry.
57 arg2.push_back (value_arg);
59 // Push the data for the first argument into the m_arguments vector.
60 m_arguments.push_back (arg1);
61 m_arguments.push_back (arg2);
64 "When setting a dictionary or array variable, you can set multiple entries \n\
65 at once by giving the values to the set command. For example: \n\
67 (lldb) settings set target.run-args value1 value2 value3 \n\
68 (lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345 \n\
70 (lldb) settings show target.run-args \n\
74 (lldb) settings show target.env-vars \n\
75 'MYPATH=~/.:/usr/bin'\n\
76 'SOME_ENV_VAR=12345' \n\
78 Warning: The 'set' command re-sets the entire array or dictionary. If you \n\
79 just want to add, remove or update individual values (or add something to \n\
80 the end), use one of the other settings sub-commands: append, replace, \n\
81 insert-before or insert-after.\n");
87 ~CommandObjectSettingsSet () {}
89 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
91 WantsCompletion() { return true; }
99 class CommandOptions : public Options
103 CommandOptions (CommandInterpreter &interpreter) :
104 Options (interpreter),
110 ~CommandOptions () {}
113 SetOptionValue (uint32_t option_idx, const char *option_arg)
116 const int short_option = m_getopt_table[option_idx].val;
118 switch (short_option)
124 error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option);
132 OptionParsingStarting ()
137 const OptionDefinition*
140 return g_option_table;
143 // Options table: Required for subclasses of Options.
145 static OptionDefinition g_option_table[];
147 // Instance variables to hold the values for command options.
153 HandleArgumentCompletion (Args &input,
155 int &cursor_char_position,
156 OptionElementVector &opt_element_vector,
157 int match_start_point,
158 int max_return_elements,
162 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
164 const size_t argc = input.GetArgumentCount();
165 const char *arg = NULL;
167 for (setting_var_idx = 1; setting_var_idx < static_cast<int>(argc);
170 arg = input.GetArgumentAtIndex(setting_var_idx);
171 if (arg && arg[0] != '-')
172 break; // We found our setting variable name index
174 if (cursor_index == setting_var_idx)
176 // Attempting to complete setting variable name
177 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
178 CommandCompletions::eSettingsNameCompletion,
179 completion_str.c_str(),
188 arg = input.GetArgumentAtIndex(cursor_index);
194 // Complete option name
198 // Complete setting value
199 const char *setting_var_name = input.GetArgumentAtIndex(setting_var_idx);
201 lldb::OptionValueSP value_sp (m_interpreter.GetDebugger().GetPropertyValue(&m_exe_ctx, setting_var_name, false, error));
204 value_sp->AutoComplete (m_interpreter,
205 completion_str.c_str(),
214 return matches.GetSize();
219 DoExecute (const char *command, CommandReturnObject &result)
221 Args cmd_args(command);
223 // Process possible options.
224 if (!ParseOptions (cmd_args, result))
227 const size_t argc = cmd_args.GetArgumentCount ();
228 if ((argc < 2) && (!m_options.m_global))
230 result.AppendError ("'settings set' takes more arguments");
231 result.SetStatus (eReturnStatusFailed);
235 const char *var_name = cmd_args.GetArgumentAtIndex (0);
236 if ((var_name == NULL) || (var_name[0] == '\0'))
238 result.AppendError ("'settings set' command requires a valid variable name");
239 result.SetStatus (eReturnStatusFailed);
243 // Split the raw command into var_name and value pair.
244 llvm::StringRef raw_str(command);
245 std::string var_value_string = raw_str.split(var_name).second.str();
246 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
249 if (m_options.m_global)
251 error = m_interpreter.GetDebugger().SetPropertyValue (NULL,
252 eVarSetOperationAssign,
259 // FIXME this is the same issue as the one in commands script import
260 // we could be setting target.load-script-from-symbol-file which would cause
261 // Python scripts to be loaded, which could run LLDB commands
262 // (e.g. settings set target.process.python-os-plugin-path) and cause a crash
263 // if we did not clear the command's exe_ctx first
264 ExecutionContext exe_ctx(m_exe_ctx);
266 error = m_interpreter.GetDebugger().SetPropertyValue (&exe_ctx,
267 eVarSetOperationAssign,
274 result.AppendError (error.AsCString());
275 result.SetStatus (eReturnStatusFailed);
280 result.SetStatus (eReturnStatusSuccessFinishResult);
283 return result.Succeeded();
286 CommandOptions m_options;
290 CommandObjectSettingsSet::CommandOptions::g_option_table[] =
292 { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Apply the new value to the global default value." },
293 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
297 //-------------------------------------------------------------------------
298 // CommandObjectSettingsShow -- Show current values
299 //-------------------------------------------------------------------------
301 class CommandObjectSettingsShow : public CommandObjectParsed
304 CommandObjectSettingsShow (CommandInterpreter &interpreter) :
305 CommandObjectParsed (interpreter,
307 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
310 CommandArgumentEntry arg1;
311 CommandArgumentData var_name_arg;
313 // Define the first (and only) variant of this arg.
314 var_name_arg.arg_type = eArgTypeSettingVariableName;
315 var_name_arg.arg_repetition = eArgRepeatOptional;
317 // There is only one variant this argument could be; put it into the argument entry.
318 arg1.push_back (var_name_arg);
320 // Push the data for the first argument into the m_arguments vector.
321 m_arguments.push_back (arg1);
325 ~CommandObjectSettingsShow () {}
329 HandleArgumentCompletion (Args &input,
331 int &cursor_char_position,
332 OptionElementVector &opt_element_vector,
333 int match_start_point,
334 int max_return_elements,
338 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
340 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
341 CommandCompletions::eSettingsNameCompletion,
342 completion_str.c_str(),
348 return matches.GetSize();
353 DoExecute (Args& args, CommandReturnObject &result)
355 result.SetStatus (eReturnStatusSuccessFinishResult);
357 const size_t argc = args.GetArgumentCount ();
360 for (size_t i=0; i<argc; ++i)
362 const char *property_path = args.GetArgumentAtIndex (i);
364 Error error(m_interpreter.GetDebugger().DumpPropertyValue (&m_exe_ctx, result.GetOutputStream(), property_path, OptionValue::eDumpGroupValue));
367 result.GetOutputStream().EOL();
371 result.AppendError (error.AsCString());
372 result.SetStatus (eReturnStatusFailed);
378 m_interpreter.GetDebugger().DumpAllPropertyValues (&m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
381 return result.Succeeded();
385 //-------------------------------------------------------------------------
386 // CommandObjectSettingsList -- List settable variables
387 //-------------------------------------------------------------------------
389 class CommandObjectSettingsList : public CommandObjectParsed
392 CommandObjectSettingsList (CommandInterpreter &interpreter) :
393 CommandObjectParsed (interpreter,
395 "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).",
398 CommandArgumentEntry arg;
399 CommandArgumentData var_name_arg;
400 CommandArgumentData prefix_name_arg;
402 // Define the first variant of this arg.
403 var_name_arg.arg_type = eArgTypeSettingVariableName;
404 var_name_arg.arg_repetition = eArgRepeatOptional;
406 // Define the second variant of this arg.
407 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
408 prefix_name_arg.arg_repetition = eArgRepeatOptional;
410 arg.push_back (var_name_arg);
411 arg.push_back (prefix_name_arg);
413 // Push the data for the first argument into the m_arguments vector.
414 m_arguments.push_back (arg);
418 ~CommandObjectSettingsList () {}
421 HandleArgumentCompletion (Args &input,
423 int &cursor_char_position,
424 OptionElementVector &opt_element_vector,
425 int match_start_point,
426 int max_return_elements,
430 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
432 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
433 CommandCompletions::eSettingsNameCompletion,
434 completion_str.c_str(),
440 return matches.GetSize();
445 DoExecute (Args& args, CommandReturnObject &result)
447 result.SetStatus (eReturnStatusSuccessFinishResult);
449 const bool will_modify = false;
450 const size_t argc = args.GetArgumentCount ();
453 const bool dump_qualified_name = true;
455 for (size_t i=0; i<argc; ++i)
457 const char *property_path = args.GetArgumentAtIndex (i);
459 const Property *property = m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath (&m_exe_ctx, will_modify, property_path);
463 property->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
467 result.AppendErrorWithFormat ("invalid property path '%s'", property_path);
468 result.SetStatus (eReturnStatusFailed);
474 m_interpreter.GetDebugger().DumpAllDescriptions (m_interpreter, result.GetOutputStream());
477 return result.Succeeded();
481 //-------------------------------------------------------------------------
482 // CommandObjectSettingsRemove
483 //-------------------------------------------------------------------------
485 class CommandObjectSettingsRemove : public CommandObjectRaw
488 CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
489 CommandObjectRaw (interpreter,
491 "Remove the specified element from an array or dictionary settings variable.",
494 CommandArgumentEntry arg1;
495 CommandArgumentEntry arg2;
496 CommandArgumentData var_name_arg;
497 CommandArgumentData index_arg;
498 CommandArgumentData key_arg;
500 // Define the first (and only) variant of this arg.
501 var_name_arg.arg_type = eArgTypeSettingVariableName;
502 var_name_arg.arg_repetition = eArgRepeatPlain;
504 // There is only one variant this argument could be; put it into the argument entry.
505 arg1.push_back (var_name_arg);
507 // Define the first variant of this arg.
508 index_arg.arg_type = eArgTypeSettingIndex;
509 index_arg.arg_repetition = eArgRepeatPlain;
511 // Define the second variant of this arg.
512 key_arg.arg_type = eArgTypeSettingKey;
513 key_arg.arg_repetition = eArgRepeatPlain;
515 // Push both variants into this arg
516 arg2.push_back (index_arg);
517 arg2.push_back (key_arg);
519 // Push the data for the first argument into the m_arguments vector.
520 m_arguments.push_back (arg1);
521 m_arguments.push_back (arg2);
525 ~CommandObjectSettingsRemove () {}
528 HandleArgumentCompletion (Args &input,
530 int &cursor_char_position,
531 OptionElementVector &opt_element_vector,
532 int match_start_point,
533 int max_return_elements,
537 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
539 // Attempting to complete variable name
540 if (cursor_index < 2)
541 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
542 CommandCompletions::eSettingsNameCompletion,
543 completion_str.c_str(),
550 return matches.GetSize();
555 DoExecute (const char *command, CommandReturnObject &result)
557 result.SetStatus (eReturnStatusSuccessFinishNoResult);
559 Args cmd_args(command);
561 // Process possible options.
562 if (!ParseOptions (cmd_args, result))
565 const size_t argc = cmd_args.GetArgumentCount ();
568 result.AppendError ("'settings set' takes an array or dictionary item, or an array followed by one or more indexes, or a dictionary followed by one or more key names to remove");
569 result.SetStatus (eReturnStatusFailed);
573 const char *var_name = cmd_args.GetArgumentAtIndex (0);
574 if ((var_name == NULL) || (var_name[0] == '\0'))
576 result.AppendError ("'settings set' command requires a valid variable name");
577 result.SetStatus (eReturnStatusFailed);
581 // Split the raw command into var_name and value pair.
582 llvm::StringRef raw_str(command);
583 std::string var_value_string = raw_str.split(var_name).second.str();
584 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
586 Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
587 eVarSetOperationRemove,
592 result.AppendError (error.AsCString());
593 result.SetStatus (eReturnStatusFailed);
597 return result.Succeeded();
601 //-------------------------------------------------------------------------
602 // CommandObjectSettingsReplace
603 //-------------------------------------------------------------------------
605 class CommandObjectSettingsReplace : public CommandObjectRaw
608 CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
609 CommandObjectRaw (interpreter,
611 "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
614 CommandArgumentEntry arg1;
615 CommandArgumentEntry arg2;
616 CommandArgumentEntry arg3;
617 CommandArgumentData var_name_arg;
618 CommandArgumentData index_arg;
619 CommandArgumentData key_arg;
620 CommandArgumentData value_arg;
622 // Define the first (and only) variant of this arg.
623 var_name_arg.arg_type = eArgTypeSettingVariableName;
624 var_name_arg.arg_repetition = eArgRepeatPlain;
626 // There is only one variant this argument could be; put it into the argument entry.
627 arg1.push_back (var_name_arg);
629 // Define the first (variant of this arg.
630 index_arg.arg_type = eArgTypeSettingIndex;
631 index_arg.arg_repetition = eArgRepeatPlain;
633 // Define the second (variant of this arg.
634 key_arg.arg_type = eArgTypeSettingKey;
635 key_arg.arg_repetition = eArgRepeatPlain;
637 // Put both variants into this arg
638 arg2.push_back (index_arg);
639 arg2.push_back (key_arg);
641 // Define the first (and only) variant of this arg.
642 value_arg.arg_type = eArgTypeValue;
643 value_arg.arg_repetition = eArgRepeatPlain;
645 // There is only one variant this argument could be; put it into the argument entry.
646 arg3.push_back (value_arg);
648 // Push the data for the first argument into the m_arguments vector.
649 m_arguments.push_back (arg1);
650 m_arguments.push_back (arg2);
651 m_arguments.push_back (arg3);
656 ~CommandObjectSettingsReplace () {}
658 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
660 WantsCompletion() { return true; }
663 HandleArgumentCompletion (Args &input,
665 int &cursor_char_position,
666 OptionElementVector &opt_element_vector,
667 int match_start_point,
668 int max_return_elements,
672 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
674 // Attempting to complete variable name
675 if (cursor_index < 2)
676 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
677 CommandCompletions::eSettingsNameCompletion,
678 completion_str.c_str(),
685 return matches.GetSize();
690 DoExecute (const char *command, CommandReturnObject &result)
692 result.SetStatus (eReturnStatusSuccessFinishNoResult);
694 Args cmd_args(command);
695 const char *var_name = cmd_args.GetArgumentAtIndex (0);
696 if ((var_name == NULL) || (var_name[0] == '\0'))
698 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
699 result.SetStatus (eReturnStatusFailed);
704 // Split the raw command into var_name, index_value, and value triple.
705 llvm::StringRef raw_str(command);
706 std::string var_value_string = raw_str.split(var_name).second.str();
707 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
709 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
710 eVarSetOperationReplace,
715 result.AppendError (error.AsCString());
716 result.SetStatus (eReturnStatusFailed);
721 result.SetStatus (eReturnStatusSuccessFinishNoResult);
725 return result.Succeeded();
729 //-------------------------------------------------------------------------
730 // CommandObjectSettingsInsertBefore
731 //-------------------------------------------------------------------------
733 class CommandObjectSettingsInsertBefore : public CommandObjectRaw
736 CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
737 CommandObjectRaw (interpreter,
738 "settings insert-before",
739 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
742 CommandArgumentEntry arg1;
743 CommandArgumentEntry arg2;
744 CommandArgumentEntry arg3;
745 CommandArgumentData var_name_arg;
746 CommandArgumentData index_arg;
747 CommandArgumentData value_arg;
749 // Define the first (and only) variant of this arg.
750 var_name_arg.arg_type = eArgTypeSettingVariableName;
751 var_name_arg.arg_repetition = eArgRepeatPlain;
753 // There is only one variant this argument could be; put it into the argument entry.
754 arg1.push_back (var_name_arg);
756 // Define the first (variant of this arg.
757 index_arg.arg_type = eArgTypeSettingIndex;
758 index_arg.arg_repetition = eArgRepeatPlain;
760 // There is only one variant this argument could be; put it into the argument entry.
761 arg2.push_back (index_arg);
763 // Define the first (and only) variant of this arg.
764 value_arg.arg_type = eArgTypeValue;
765 value_arg.arg_repetition = eArgRepeatPlain;
767 // There is only one variant this argument could be; put it into the argument entry.
768 arg3.push_back (value_arg);
770 // Push the data for the first argument into the m_arguments vector.
771 m_arguments.push_back (arg1);
772 m_arguments.push_back (arg2);
773 m_arguments.push_back (arg3);
777 ~CommandObjectSettingsInsertBefore () {}
779 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
781 WantsCompletion() { return true; }
784 HandleArgumentCompletion (Args &input,
786 int &cursor_char_position,
787 OptionElementVector &opt_element_vector,
788 int match_start_point,
789 int max_return_elements,
793 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
795 // Attempting to complete variable name
796 if (cursor_index < 2)
797 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
798 CommandCompletions::eSettingsNameCompletion,
799 completion_str.c_str(),
806 return matches.GetSize();
811 DoExecute (const char *command, CommandReturnObject &result)
813 result.SetStatus (eReturnStatusSuccessFinishNoResult);
815 Args cmd_args(command);
816 const size_t argc = cmd_args.GetArgumentCount ();
820 result.AppendError ("'settings insert-before' takes more arguments");
821 result.SetStatus (eReturnStatusFailed);
825 const char *var_name = cmd_args.GetArgumentAtIndex (0);
826 if ((var_name == NULL) || (var_name[0] == '\0'))
828 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
829 result.SetStatus (eReturnStatusFailed);
833 // Split the raw command into var_name, index_value, and value triple.
834 llvm::StringRef raw_str(command);
835 std::string var_value_string = raw_str.split(var_name).second.str();
836 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
838 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
839 eVarSetOperationInsertBefore,
844 result.AppendError (error.AsCString());
845 result.SetStatus (eReturnStatusFailed);
849 return result.Succeeded();
853 //-------------------------------------------------------------------------
854 // CommandObjectSettingInsertAfter
855 //-------------------------------------------------------------------------
857 class CommandObjectSettingsInsertAfter : public CommandObjectRaw
860 CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
861 CommandObjectRaw (interpreter,
862 "settings insert-after",
863 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
866 CommandArgumentEntry arg1;
867 CommandArgumentEntry arg2;
868 CommandArgumentEntry arg3;
869 CommandArgumentData var_name_arg;
870 CommandArgumentData index_arg;
871 CommandArgumentData value_arg;
873 // Define the first (and only) variant of this arg.
874 var_name_arg.arg_type = eArgTypeSettingVariableName;
875 var_name_arg.arg_repetition = eArgRepeatPlain;
877 // There is only one variant this argument could be; put it into the argument entry.
878 arg1.push_back (var_name_arg);
880 // Define the first (variant of this arg.
881 index_arg.arg_type = eArgTypeSettingIndex;
882 index_arg.arg_repetition = eArgRepeatPlain;
884 // There is only one variant this argument could be; put it into the argument entry.
885 arg2.push_back (index_arg);
887 // Define the first (and only) variant of this arg.
888 value_arg.arg_type = eArgTypeValue;
889 value_arg.arg_repetition = eArgRepeatPlain;
891 // There is only one variant this argument could be; put it into the argument entry.
892 arg3.push_back (value_arg);
894 // Push the data for the first argument into the m_arguments vector.
895 m_arguments.push_back (arg1);
896 m_arguments.push_back (arg2);
897 m_arguments.push_back (arg3);
901 ~CommandObjectSettingsInsertAfter () {}
903 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
905 WantsCompletion() { return true; }
908 HandleArgumentCompletion (Args &input,
910 int &cursor_char_position,
911 OptionElementVector &opt_element_vector,
912 int match_start_point,
913 int max_return_elements,
917 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
919 // Attempting to complete variable name
920 if (cursor_index < 2)
921 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
922 CommandCompletions::eSettingsNameCompletion,
923 completion_str.c_str(),
930 return matches.GetSize();
935 DoExecute (const char *command, CommandReturnObject &result)
937 result.SetStatus (eReturnStatusSuccessFinishNoResult);
939 Args cmd_args(command);
940 const size_t argc = cmd_args.GetArgumentCount ();
944 result.AppendError ("'settings insert-after' takes more arguments");
945 result.SetStatus (eReturnStatusFailed);
949 const char *var_name = cmd_args.GetArgumentAtIndex (0);
950 if ((var_name == NULL) || (var_name[0] == '\0'))
952 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
953 result.SetStatus (eReturnStatusFailed);
957 // Split the raw command into var_name, index_value, and value triple.
958 llvm::StringRef raw_str(command);
959 std::string var_value_string = raw_str.split(var_name).second.str();
960 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
962 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
963 eVarSetOperationInsertAfter,
968 result.AppendError (error.AsCString());
969 result.SetStatus (eReturnStatusFailed);
973 return result.Succeeded();
977 //-------------------------------------------------------------------------
978 // CommandObjectSettingsAppend
979 //-------------------------------------------------------------------------
981 class CommandObjectSettingsAppend : public CommandObjectRaw
984 CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
985 CommandObjectRaw (interpreter,
987 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
990 CommandArgumentEntry arg1;
991 CommandArgumentEntry arg2;
992 CommandArgumentData var_name_arg;
993 CommandArgumentData value_arg;
995 // Define the first (and only) variant of this arg.
996 var_name_arg.arg_type = eArgTypeSettingVariableName;
997 var_name_arg.arg_repetition = eArgRepeatPlain;
999 // There is only one variant this argument could be; put it into the argument entry.
1000 arg1.push_back (var_name_arg);
1002 // Define the first (and only) variant of this arg.
1003 value_arg.arg_type = eArgTypeValue;
1004 value_arg.arg_repetition = eArgRepeatPlain;
1006 // There is only one variant this argument could be; put it into the argument entry.
1007 arg2.push_back (value_arg);
1009 // Push the data for the first argument into the m_arguments vector.
1010 m_arguments.push_back (arg1);
1011 m_arguments.push_back (arg2);
1015 ~CommandObjectSettingsAppend () {}
1017 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
1019 WantsCompletion() { return true; }
1022 HandleArgumentCompletion (Args &input,
1024 int &cursor_char_position,
1025 OptionElementVector &opt_element_vector,
1026 int match_start_point,
1027 int max_return_elements,
1028 bool &word_complete,
1029 StringList &matches)
1031 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
1033 // Attempting to complete variable name
1034 if (cursor_index < 2)
1035 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1036 CommandCompletions::eSettingsNameCompletion,
1037 completion_str.c_str(),
1039 max_return_elements,
1044 return matches.GetSize();
1049 DoExecute (const char *command, CommandReturnObject &result)
1051 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1052 Args cmd_args(command);
1053 const size_t argc = cmd_args.GetArgumentCount ();
1057 result.AppendError ("'settings append' takes more arguments");
1058 result.SetStatus (eReturnStatusFailed);
1062 const char *var_name = cmd_args.GetArgumentAtIndex (0);
1063 if ((var_name == NULL) || (var_name[0] == '\0'))
1065 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1066 result.SetStatus (eReturnStatusFailed);
1070 // Do not perform cmd_args.Shift() since StringRef is manipulating the
1071 // raw character string later on.
1073 // Split the raw command into var_name and value pair.
1074 llvm::StringRef raw_str(command);
1075 std::string var_value_string = raw_str.split(var_name).second.str();
1076 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
1078 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
1079 eVarSetOperationAppend,
1084 result.AppendError (error.AsCString());
1085 result.SetStatus (eReturnStatusFailed);
1089 return result.Succeeded();
1093 //-------------------------------------------------------------------------
1094 // CommandObjectSettingsClear
1095 //-------------------------------------------------------------------------
1097 class CommandObjectSettingsClear : public CommandObjectParsed
1100 CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1101 CommandObjectParsed (interpreter,
1103 "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.",
1106 CommandArgumentEntry arg;
1107 CommandArgumentData var_name_arg;
1109 // Define the first (and only) variant of this arg.
1110 var_name_arg.arg_type = eArgTypeSettingVariableName;
1111 var_name_arg.arg_repetition = eArgRepeatPlain;
1113 // There is only one variant this argument could be; put it into the argument entry.
1114 arg.push_back (var_name_arg);
1116 // Push the data for the first argument into the m_arguments vector.
1117 m_arguments.push_back (arg);
1121 ~CommandObjectSettingsClear () {}
1124 HandleArgumentCompletion (Args &input,
1126 int &cursor_char_position,
1127 OptionElementVector &opt_element_vector,
1128 int match_start_point,
1129 int max_return_elements,
1130 bool &word_complete,
1131 StringList &matches)
1133 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
1135 // Attempting to complete variable name
1136 if (cursor_index < 2)
1137 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1138 CommandCompletions::eSettingsNameCompletion,
1139 completion_str.c_str(),
1141 max_return_elements,
1146 return matches.GetSize();
1151 DoExecute (Args& command, CommandReturnObject &result)
1153 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1154 const size_t argc = command.GetArgumentCount ();
1158 result.AppendError ("'settings clear' takes exactly one argument");
1159 result.SetStatus (eReturnStatusFailed);
1163 const char *var_name = command.GetArgumentAtIndex (0);
1164 if ((var_name == NULL) || (var_name[0] == '\0'))
1166 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1167 result.SetStatus (eReturnStatusFailed);
1171 Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
1172 eVarSetOperationClear,
1177 result.AppendError (error.AsCString());
1178 result.SetStatus (eReturnStatusFailed);
1182 return result.Succeeded();
1186 //-------------------------------------------------------------------------
1187 // CommandObjectMultiwordSettings
1188 //-------------------------------------------------------------------------
1190 CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
1191 CommandObjectMultiword (interpreter,
1193 "A set of commands for manipulating internal settable debugger variables.",
1194 "settings <command> [<command-options>]")
1196 LoadSubCommand ("set", CommandObjectSP (new CommandObjectSettingsSet (interpreter)));
1197 LoadSubCommand ("show", CommandObjectSP (new CommandObjectSettingsShow (interpreter)));
1198 LoadSubCommand ("list", CommandObjectSP (new CommandObjectSettingsList (interpreter)));
1199 LoadSubCommand ("remove", CommandObjectSP (new CommandObjectSettingsRemove (interpreter)));
1200 LoadSubCommand ("replace", CommandObjectSP (new CommandObjectSettingsReplace (interpreter)));
1201 LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter)));
1202 LoadSubCommand ("insert-after", CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter)));
1203 LoadSubCommand ("append", CommandObjectSP (new CommandObjectSettingsAppend (interpreter)));
1204 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectSettingsClear (interpreter)));
1207 CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()