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 < argc; ++setting_var_idx)
169 arg = input.GetArgumentAtIndex(setting_var_idx);
170 if (arg && arg[0] != '-')
171 break; // We found our setting variable name index
173 if (cursor_index == setting_var_idx)
175 // Attempting to complete setting variable name
176 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
177 CommandCompletions::eSettingsNameCompletion,
178 completion_str.c_str(),
187 arg = input.GetArgumentAtIndex(cursor_index);
193 // Complete option name
197 // Complete setting value
198 const char *setting_var_name = input.GetArgumentAtIndex(setting_var_idx);
200 lldb::OptionValueSP value_sp (m_interpreter.GetDebugger().GetPropertyValue(&m_exe_ctx, setting_var_name, false, error));
203 value_sp->AutoComplete (m_interpreter,
204 completion_str.c_str(),
213 return matches.GetSize();
218 DoExecute (const char *command, CommandReturnObject &result)
220 Args cmd_args(command);
222 // Process possible options.
223 if (!ParseOptions (cmd_args, result))
226 const size_t argc = cmd_args.GetArgumentCount ();
227 if ((argc < 2) && (!m_options.m_global))
229 result.AppendError ("'settings set' takes more arguments");
230 result.SetStatus (eReturnStatusFailed);
234 const char *var_name = cmd_args.GetArgumentAtIndex (0);
235 if ((var_name == NULL) || (var_name[0] == '\0'))
237 result.AppendError ("'settings set' command requires a valid variable name");
238 result.SetStatus (eReturnStatusFailed);
242 // Split the raw command into var_name and value pair.
243 llvm::StringRef raw_str(command);
244 std::string var_value_string = raw_str.split(var_name).second.str();
245 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
248 if (m_options.m_global)
250 error = m_interpreter.GetDebugger().SetPropertyValue (NULL,
251 eVarSetOperationAssign,
258 // FIXME this is the same issue as the one in commands script import
259 // we could be setting target.load-script-from-symbol-file which would cause
260 // Python scripts to be loaded, which could run LLDB commands
261 // (e.g. settings set target.process.python-os-plugin-path) and cause a crash
262 // if we did not clear the command's exe_ctx first
263 ExecutionContext exe_ctx(m_exe_ctx);
265 error = m_interpreter.GetDebugger().SetPropertyValue (&exe_ctx,
266 eVarSetOperationAssign,
273 result.AppendError (error.AsCString());
274 result.SetStatus (eReturnStatusFailed);
279 result.SetStatus (eReturnStatusSuccessFinishResult);
282 return result.Succeeded();
285 CommandOptions m_options;
289 CommandObjectSettingsSet::CommandOptions::g_option_table[] =
291 { LLDB_OPT_SET_2, false, "global", 'g', no_argument, NULL, 0, eArgTypeNone, "Apply the new value to the global default value." },
292 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
296 //-------------------------------------------------------------------------
297 // CommandObjectSettingsShow -- Show current values
298 //-------------------------------------------------------------------------
300 class CommandObjectSettingsShow : public CommandObjectParsed
303 CommandObjectSettingsShow (CommandInterpreter &interpreter) :
304 CommandObjectParsed (interpreter,
306 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
309 CommandArgumentEntry arg1;
310 CommandArgumentData var_name_arg;
312 // Define the first (and only) variant of this arg.
313 var_name_arg.arg_type = eArgTypeSettingVariableName;
314 var_name_arg.arg_repetition = eArgRepeatOptional;
316 // There is only one variant this argument could be; put it into the argument entry.
317 arg1.push_back (var_name_arg);
319 // Push the data for the first argument into the m_arguments vector.
320 m_arguments.push_back (arg1);
324 ~CommandObjectSettingsShow () {}
328 HandleArgumentCompletion (Args &input,
330 int &cursor_char_position,
331 OptionElementVector &opt_element_vector,
332 int match_start_point,
333 int max_return_elements,
337 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
339 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
340 CommandCompletions::eSettingsNameCompletion,
341 completion_str.c_str(),
347 return matches.GetSize();
352 DoExecute (Args& args, CommandReturnObject &result)
354 result.SetStatus (eReturnStatusSuccessFinishResult);
356 const size_t argc = args.GetArgumentCount ();
359 for (size_t i=0; i<argc; ++i)
361 const char *property_path = args.GetArgumentAtIndex (i);
363 Error error(m_interpreter.GetDebugger().DumpPropertyValue (&m_exe_ctx, result.GetOutputStream(), property_path, OptionValue::eDumpGroupValue));
366 result.GetOutputStream().EOL();
370 result.AppendError (error.AsCString());
371 result.SetStatus (eReturnStatusFailed);
377 m_interpreter.GetDebugger().DumpAllPropertyValues (&m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
380 return result.Succeeded();
384 //-------------------------------------------------------------------------
385 // CommandObjectSettingsList -- List settable variables
386 //-------------------------------------------------------------------------
388 class CommandObjectSettingsList : public CommandObjectParsed
391 CommandObjectSettingsList (CommandInterpreter &interpreter) :
392 CommandObjectParsed (interpreter,
394 "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).",
397 CommandArgumentEntry arg;
398 CommandArgumentData var_name_arg;
399 CommandArgumentData prefix_name_arg;
401 // Define the first variant of this arg.
402 var_name_arg.arg_type = eArgTypeSettingVariableName;
403 var_name_arg.arg_repetition = eArgRepeatOptional;
405 // Define the second variant of this arg.
406 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
407 prefix_name_arg.arg_repetition = eArgRepeatOptional;
409 arg.push_back (var_name_arg);
410 arg.push_back (prefix_name_arg);
412 // Push the data for the first argument into the m_arguments vector.
413 m_arguments.push_back (arg);
417 ~CommandObjectSettingsList () {}
420 HandleArgumentCompletion (Args &input,
422 int &cursor_char_position,
423 OptionElementVector &opt_element_vector,
424 int match_start_point,
425 int max_return_elements,
429 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
431 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
432 CommandCompletions::eSettingsNameCompletion,
433 completion_str.c_str(),
439 return matches.GetSize();
444 DoExecute (Args& args, CommandReturnObject &result)
446 result.SetStatus (eReturnStatusSuccessFinishResult);
448 const bool will_modify = false;
449 const size_t argc = args.GetArgumentCount ();
452 const bool dump_qualified_name = true;
454 for (size_t i=0; i<argc; ++i)
456 const char *property_path = args.GetArgumentAtIndex (i);
458 const Property *property = m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath (&m_exe_ctx, will_modify, property_path);
462 property->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
466 result.AppendErrorWithFormat ("invalid property path '%s'", property_path);
467 result.SetStatus (eReturnStatusFailed);
473 m_interpreter.GetDebugger().DumpAllDescriptions (m_interpreter, result.GetOutputStream());
476 return result.Succeeded();
480 //-------------------------------------------------------------------------
481 // CommandObjectSettingsRemove
482 //-------------------------------------------------------------------------
484 class CommandObjectSettingsRemove : public CommandObjectRaw
487 CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
488 CommandObjectRaw (interpreter,
490 "Remove the specified element from an array or dictionary settings variable.",
493 CommandArgumentEntry arg1;
494 CommandArgumentEntry arg2;
495 CommandArgumentData var_name_arg;
496 CommandArgumentData index_arg;
497 CommandArgumentData key_arg;
499 // Define the first (and only) variant of this arg.
500 var_name_arg.arg_type = eArgTypeSettingVariableName;
501 var_name_arg.arg_repetition = eArgRepeatPlain;
503 // There is only one variant this argument could be; put it into the argument entry.
504 arg1.push_back (var_name_arg);
506 // Define the first variant of this arg.
507 index_arg.arg_type = eArgTypeSettingIndex;
508 index_arg.arg_repetition = eArgRepeatPlain;
510 // Define the second variant of this arg.
511 key_arg.arg_type = eArgTypeSettingKey;
512 key_arg.arg_repetition = eArgRepeatPlain;
514 // Push both variants into this arg
515 arg2.push_back (index_arg);
516 arg2.push_back (key_arg);
518 // Push the data for the first argument into the m_arguments vector.
519 m_arguments.push_back (arg1);
520 m_arguments.push_back (arg2);
524 ~CommandObjectSettingsRemove () {}
527 HandleArgumentCompletion (Args &input,
529 int &cursor_char_position,
530 OptionElementVector &opt_element_vector,
531 int match_start_point,
532 int max_return_elements,
536 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
538 // Attempting to complete variable name
539 if (cursor_index < 2)
540 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
541 CommandCompletions::eSettingsNameCompletion,
542 completion_str.c_str(),
549 return matches.GetSize();
554 DoExecute (const char *command, CommandReturnObject &result)
556 result.SetStatus (eReturnStatusSuccessFinishNoResult);
558 Args cmd_args(command);
560 // Process possible options.
561 if (!ParseOptions (cmd_args, result))
564 const size_t argc = cmd_args.GetArgumentCount ();
567 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");
568 result.SetStatus (eReturnStatusFailed);
572 const char *var_name = cmd_args.GetArgumentAtIndex (0);
573 if ((var_name == NULL) || (var_name[0] == '\0'))
575 result.AppendError ("'settings set' command requires a valid variable name");
576 result.SetStatus (eReturnStatusFailed);
580 // Split the raw command into var_name and value pair.
581 llvm::StringRef raw_str(command);
582 std::string var_value_string = raw_str.split(var_name).second.str();
583 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
585 Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
586 eVarSetOperationRemove,
591 result.AppendError (error.AsCString());
592 result.SetStatus (eReturnStatusFailed);
596 return result.Succeeded();
600 //-------------------------------------------------------------------------
601 // CommandObjectSettingsReplace
602 //-------------------------------------------------------------------------
604 class CommandObjectSettingsReplace : public CommandObjectRaw
607 CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
608 CommandObjectRaw (interpreter,
610 "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
613 CommandArgumentEntry arg1;
614 CommandArgumentEntry arg2;
615 CommandArgumentEntry arg3;
616 CommandArgumentData var_name_arg;
617 CommandArgumentData index_arg;
618 CommandArgumentData key_arg;
619 CommandArgumentData value_arg;
621 // Define the first (and only) variant of this arg.
622 var_name_arg.arg_type = eArgTypeSettingVariableName;
623 var_name_arg.arg_repetition = eArgRepeatPlain;
625 // There is only one variant this argument could be; put it into the argument entry.
626 arg1.push_back (var_name_arg);
628 // Define the first (variant of this arg.
629 index_arg.arg_type = eArgTypeSettingIndex;
630 index_arg.arg_repetition = eArgRepeatPlain;
632 // Define the second (variant of this arg.
633 key_arg.arg_type = eArgTypeSettingKey;
634 key_arg.arg_repetition = eArgRepeatPlain;
636 // Put both variants into this arg
637 arg2.push_back (index_arg);
638 arg2.push_back (key_arg);
640 // Define the first (and only) variant of this arg.
641 value_arg.arg_type = eArgTypeValue;
642 value_arg.arg_repetition = eArgRepeatPlain;
644 // There is only one variant this argument could be; put it into the argument entry.
645 arg3.push_back (value_arg);
647 // Push the data for the first argument into the m_arguments vector.
648 m_arguments.push_back (arg1);
649 m_arguments.push_back (arg2);
650 m_arguments.push_back (arg3);
655 ~CommandObjectSettingsReplace () {}
657 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
659 WantsCompletion() { return true; }
662 HandleArgumentCompletion (Args &input,
664 int &cursor_char_position,
665 OptionElementVector &opt_element_vector,
666 int match_start_point,
667 int max_return_elements,
671 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
673 // Attempting to complete variable name
674 if (cursor_index < 2)
675 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
676 CommandCompletions::eSettingsNameCompletion,
677 completion_str.c_str(),
684 return matches.GetSize();
689 DoExecute (const char *command, CommandReturnObject &result)
691 result.SetStatus (eReturnStatusSuccessFinishNoResult);
693 Args cmd_args(command);
694 const char *var_name = cmd_args.GetArgumentAtIndex (0);
695 if ((var_name == NULL) || (var_name[0] == '\0'))
697 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
698 result.SetStatus (eReturnStatusFailed);
703 // Split the raw command into var_name, index_value, and value triple.
704 llvm::StringRef raw_str(command);
705 std::string var_value_string = raw_str.split(var_name).second.str();
706 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
708 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
709 eVarSetOperationReplace,
714 result.AppendError (error.AsCString());
715 result.SetStatus (eReturnStatusFailed);
720 result.SetStatus (eReturnStatusSuccessFinishNoResult);
724 return result.Succeeded();
728 //-------------------------------------------------------------------------
729 // CommandObjectSettingsInsertBefore
730 //-------------------------------------------------------------------------
732 class CommandObjectSettingsInsertBefore : public CommandObjectRaw
735 CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
736 CommandObjectRaw (interpreter,
737 "settings insert-before",
738 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
741 CommandArgumentEntry arg1;
742 CommandArgumentEntry arg2;
743 CommandArgumentEntry arg3;
744 CommandArgumentData var_name_arg;
745 CommandArgumentData index_arg;
746 CommandArgumentData value_arg;
748 // Define the first (and only) variant of this arg.
749 var_name_arg.arg_type = eArgTypeSettingVariableName;
750 var_name_arg.arg_repetition = eArgRepeatPlain;
752 // There is only one variant this argument could be; put it into the argument entry.
753 arg1.push_back (var_name_arg);
755 // Define the first (variant of this arg.
756 index_arg.arg_type = eArgTypeSettingIndex;
757 index_arg.arg_repetition = eArgRepeatPlain;
759 // There is only one variant this argument could be; put it into the argument entry.
760 arg2.push_back (index_arg);
762 // Define the first (and only) variant of this arg.
763 value_arg.arg_type = eArgTypeValue;
764 value_arg.arg_repetition = eArgRepeatPlain;
766 // There is only one variant this argument could be; put it into the argument entry.
767 arg3.push_back (value_arg);
769 // Push the data for the first argument into the m_arguments vector.
770 m_arguments.push_back (arg1);
771 m_arguments.push_back (arg2);
772 m_arguments.push_back (arg3);
776 ~CommandObjectSettingsInsertBefore () {}
778 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
780 WantsCompletion() { return true; }
783 HandleArgumentCompletion (Args &input,
785 int &cursor_char_position,
786 OptionElementVector &opt_element_vector,
787 int match_start_point,
788 int max_return_elements,
792 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
794 // Attempting to complete variable name
795 if (cursor_index < 2)
796 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
797 CommandCompletions::eSettingsNameCompletion,
798 completion_str.c_str(),
805 return matches.GetSize();
810 DoExecute (const char *command, CommandReturnObject &result)
812 result.SetStatus (eReturnStatusSuccessFinishNoResult);
814 Args cmd_args(command);
815 const size_t argc = cmd_args.GetArgumentCount ();
819 result.AppendError ("'settings insert-before' takes more arguments");
820 result.SetStatus (eReturnStatusFailed);
824 const char *var_name = cmd_args.GetArgumentAtIndex (0);
825 if ((var_name == NULL) || (var_name[0] == '\0'))
827 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
828 result.SetStatus (eReturnStatusFailed);
832 // Split the raw command into var_name, index_value, and value triple.
833 llvm::StringRef raw_str(command);
834 std::string var_value_string = raw_str.split(var_name).second.str();
835 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
837 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
838 eVarSetOperationInsertBefore,
843 result.AppendError (error.AsCString());
844 result.SetStatus (eReturnStatusFailed);
848 return result.Succeeded();
852 //-------------------------------------------------------------------------
853 // CommandObjectSettingInsertAfter
854 //-------------------------------------------------------------------------
856 class CommandObjectSettingsInsertAfter : public CommandObjectRaw
859 CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
860 CommandObjectRaw (interpreter,
861 "settings insert-after",
862 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
865 CommandArgumentEntry arg1;
866 CommandArgumentEntry arg2;
867 CommandArgumentEntry arg3;
868 CommandArgumentData var_name_arg;
869 CommandArgumentData index_arg;
870 CommandArgumentData value_arg;
872 // Define the first (and only) variant of this arg.
873 var_name_arg.arg_type = eArgTypeSettingVariableName;
874 var_name_arg.arg_repetition = eArgRepeatPlain;
876 // There is only one variant this argument could be; put it into the argument entry.
877 arg1.push_back (var_name_arg);
879 // Define the first (variant of this arg.
880 index_arg.arg_type = eArgTypeSettingIndex;
881 index_arg.arg_repetition = eArgRepeatPlain;
883 // There is only one variant this argument could be; put it into the argument entry.
884 arg2.push_back (index_arg);
886 // Define the first (and only) variant of this arg.
887 value_arg.arg_type = eArgTypeValue;
888 value_arg.arg_repetition = eArgRepeatPlain;
890 // There is only one variant this argument could be; put it into the argument entry.
891 arg3.push_back (value_arg);
893 // Push the data for the first argument into the m_arguments vector.
894 m_arguments.push_back (arg1);
895 m_arguments.push_back (arg2);
896 m_arguments.push_back (arg3);
900 ~CommandObjectSettingsInsertAfter () {}
902 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
904 WantsCompletion() { return true; }
907 HandleArgumentCompletion (Args &input,
909 int &cursor_char_position,
910 OptionElementVector &opt_element_vector,
911 int match_start_point,
912 int max_return_elements,
916 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
918 // Attempting to complete variable name
919 if (cursor_index < 2)
920 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
921 CommandCompletions::eSettingsNameCompletion,
922 completion_str.c_str(),
929 return matches.GetSize();
934 DoExecute (const char *command, CommandReturnObject &result)
936 result.SetStatus (eReturnStatusSuccessFinishNoResult);
938 Args cmd_args(command);
939 const size_t argc = cmd_args.GetArgumentCount ();
943 result.AppendError ("'settings insert-after' takes more arguments");
944 result.SetStatus (eReturnStatusFailed);
948 const char *var_name = cmd_args.GetArgumentAtIndex (0);
949 if ((var_name == NULL) || (var_name[0] == '\0'))
951 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
952 result.SetStatus (eReturnStatusFailed);
956 // Split the raw command into var_name, index_value, and value triple.
957 llvm::StringRef raw_str(command);
958 std::string var_value_string = raw_str.split(var_name).second.str();
959 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
961 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
962 eVarSetOperationInsertAfter,
967 result.AppendError (error.AsCString());
968 result.SetStatus (eReturnStatusFailed);
972 return result.Succeeded();
976 //-------------------------------------------------------------------------
977 // CommandObjectSettingsAppend
978 //-------------------------------------------------------------------------
980 class CommandObjectSettingsAppend : public CommandObjectRaw
983 CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
984 CommandObjectRaw (interpreter,
986 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
989 CommandArgumentEntry arg1;
990 CommandArgumentEntry arg2;
991 CommandArgumentData var_name_arg;
992 CommandArgumentData value_arg;
994 // Define the first (and only) variant of this arg.
995 var_name_arg.arg_type = eArgTypeSettingVariableName;
996 var_name_arg.arg_repetition = eArgRepeatPlain;
998 // There is only one variant this argument could be; put it into the argument entry.
999 arg1.push_back (var_name_arg);
1001 // Define the first (and only) variant of this arg.
1002 value_arg.arg_type = eArgTypeValue;
1003 value_arg.arg_repetition = eArgRepeatPlain;
1005 // There is only one variant this argument could be; put it into the argument entry.
1006 arg2.push_back (value_arg);
1008 // Push the data for the first argument into the m_arguments vector.
1009 m_arguments.push_back (arg1);
1010 m_arguments.push_back (arg2);
1014 ~CommandObjectSettingsAppend () {}
1016 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
1018 WantsCompletion() { return true; }
1021 HandleArgumentCompletion (Args &input,
1023 int &cursor_char_position,
1024 OptionElementVector &opt_element_vector,
1025 int match_start_point,
1026 int max_return_elements,
1027 bool &word_complete,
1028 StringList &matches)
1030 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
1032 // Attempting to complete variable name
1033 if (cursor_index < 2)
1034 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1035 CommandCompletions::eSettingsNameCompletion,
1036 completion_str.c_str(),
1038 max_return_elements,
1043 return matches.GetSize();
1048 DoExecute (const char *command, CommandReturnObject &result)
1050 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1051 Args cmd_args(command);
1052 const size_t argc = cmd_args.GetArgumentCount ();
1056 result.AppendError ("'settings append' takes more arguments");
1057 result.SetStatus (eReturnStatusFailed);
1061 const char *var_name = cmd_args.GetArgumentAtIndex (0);
1062 if ((var_name == NULL) || (var_name[0] == '\0'))
1064 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1065 result.SetStatus (eReturnStatusFailed);
1069 // Do not perform cmd_args.Shift() since StringRef is manipulating the
1070 // raw character string later on.
1072 // Split the raw command into var_name and value pair.
1073 llvm::StringRef raw_str(command);
1074 std::string var_value_string = raw_str.split(var_name).second.str();
1075 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
1077 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
1078 eVarSetOperationAppend,
1083 result.AppendError (error.AsCString());
1084 result.SetStatus (eReturnStatusFailed);
1088 return result.Succeeded();
1092 //-------------------------------------------------------------------------
1093 // CommandObjectSettingsClear
1094 //-------------------------------------------------------------------------
1096 class CommandObjectSettingsClear : public CommandObjectParsed
1099 CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1100 CommandObjectParsed (interpreter,
1102 "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.",
1105 CommandArgumentEntry arg;
1106 CommandArgumentData var_name_arg;
1108 // Define the first (and only) variant of this arg.
1109 var_name_arg.arg_type = eArgTypeSettingVariableName;
1110 var_name_arg.arg_repetition = eArgRepeatPlain;
1112 // There is only one variant this argument could be; put it into the argument entry.
1113 arg.push_back (var_name_arg);
1115 // Push the data for the first argument into the m_arguments vector.
1116 m_arguments.push_back (arg);
1120 ~CommandObjectSettingsClear () {}
1123 HandleArgumentCompletion (Args &input,
1125 int &cursor_char_position,
1126 OptionElementVector &opt_element_vector,
1127 int match_start_point,
1128 int max_return_elements,
1129 bool &word_complete,
1130 StringList &matches)
1132 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
1134 // Attempting to complete variable name
1135 if (cursor_index < 2)
1136 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1137 CommandCompletions::eSettingsNameCompletion,
1138 completion_str.c_str(),
1140 max_return_elements,
1145 return matches.GetSize();
1150 DoExecute (Args& command, CommandReturnObject &result)
1152 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1153 const size_t argc = command.GetArgumentCount ();
1157 result.AppendError ("'setttings clear' takes exactly one argument");
1158 result.SetStatus (eReturnStatusFailed);
1162 const char *var_name = command.GetArgumentAtIndex (0);
1163 if ((var_name == NULL) || (var_name[0] == '\0'))
1165 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1166 result.SetStatus (eReturnStatusFailed);
1170 Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
1171 eVarSetOperationClear,
1176 result.AppendError (error.AsCString());
1177 result.SetStatus (eReturnStatusFailed);
1181 return result.Succeeded();
1185 //-------------------------------------------------------------------------
1186 // CommandObjectMultiwordSettings
1187 //-------------------------------------------------------------------------
1189 CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
1190 CommandObjectMultiword (interpreter,
1192 "A set of commands for manipulating internal settable debugger variables.",
1193 "settings <command> [<command-options>]")
1195 LoadSubCommand ("set", CommandObjectSP (new CommandObjectSettingsSet (interpreter)));
1196 LoadSubCommand ("show", CommandObjectSP (new CommandObjectSettingsShow (interpreter)));
1197 LoadSubCommand ("list", CommandObjectSP (new CommandObjectSettingsList (interpreter)));
1198 LoadSubCommand ("remove", CommandObjectSP (new CommandObjectSettingsRemove (interpreter)));
1199 LoadSubCommand ("replace", CommandObjectSP (new CommandObjectSettingsReplace (interpreter)));
1200 LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter)));
1201 LoadSubCommand ("insert-after", CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter)));
1202 LoadSubCommand ("append", CommandObjectSP (new CommandObjectSettingsAppend (interpreter)));
1203 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectSettingsClear (interpreter)));
1206 CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()