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 "CommandObjectSettings.h"
14 // Other libraries and framework includes
15 #include "llvm/ADT/StringRef.h"
18 #include "lldb/Host/OptionParser.h"
19 #include "lldb/Interpreter/CommandCompletions.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Interpreter/CommandReturnObject.h"
22 #include "lldb/Interpreter/OptionValueProperties.h"
25 using namespace lldb_private;
27 //-------------------------------------------------------------------------
28 // CommandObjectSettingsSet
29 //-------------------------------------------------------------------------
31 static OptionDefinition g_settings_set_options[] = {
33 { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Apply the new value to the global default value." }
37 class CommandObjectSettingsSet : public CommandObjectRaw {
39 CommandObjectSettingsSet(CommandInterpreter &interpreter)
40 : CommandObjectRaw(interpreter, "settings set",
41 "Set the value of the specified debugger setting."),
43 CommandArgumentEntry arg1;
44 CommandArgumentEntry arg2;
45 CommandArgumentData var_name_arg;
46 CommandArgumentData value_arg;
48 // Define the first (and only) variant of this arg.
49 var_name_arg.arg_type = eArgTypeSettingVariableName;
50 var_name_arg.arg_repetition = eArgRepeatPlain;
52 // There is only one variant this argument could be; put it into the
54 arg1.push_back(var_name_arg);
56 // Define the first (and only) variant of this arg.
57 value_arg.arg_type = eArgTypeValue;
58 value_arg.arg_repetition = eArgRepeatPlain;
60 // There is only one variant this argument could be; put it into the
62 arg2.push_back(value_arg);
64 // Push the data for the first argument into the m_arguments vector.
65 m_arguments.push_back(arg1);
66 m_arguments.push_back(arg2);
69 "\nWhen setting a dictionary or array variable, you can set multiple entries \
70 at once by giving the values to the set command. For example:"
73 (lldb) settings set target.run-args value1 value2 value3
74 (lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345
76 (lldb) settings show target.run-args
80 (lldb) settings show target.env-vars
85 "Warning: The 'set' command re-sets the entire array or dictionary. If you \
86 just want to add, remove or update individual values (or add something to \
87 the end), use one of the other settings sub-commands: append, replace, \
88 insert-before or insert-after.");
91 ~CommandObjectSettingsSet() override = default;
93 // Overrides base class's behavior where WantsCompletion =
94 // !WantsRawCommandString.
95 bool WantsCompletion() override { return true; }
97 Options *GetOptions() override { return &m_options; }
99 class CommandOptions : public Options {
101 CommandOptions() : Options(), m_global(false) {}
103 ~CommandOptions() override = default;
105 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
106 ExecutionContext *execution_context) override {
108 const int short_option = m_getopt_table[option_idx].val;
110 switch (short_option) {
115 error.SetErrorStringWithFormat("unrecognized options '%c'",
123 void OptionParsingStarting(ExecutionContext *execution_context) override {
127 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
128 return llvm::makeArrayRef(g_settings_set_options);
131 // Instance variables to hold the values for command options.
136 int HandleArgumentCompletion(
137 CompletionRequest &request,
138 OptionElementVector &opt_element_vector) override {
140 const size_t argc = request.GetParsedLine().GetArgumentCount();
141 const char *arg = nullptr;
143 for (setting_var_idx = 0; setting_var_idx < static_cast<int>(argc);
145 arg = request.GetParsedLine().GetArgumentAtIndex(setting_var_idx);
146 if (arg && arg[0] != '-')
147 break; // We found our setting variable name index
149 if (request.GetCursorIndex() == setting_var_idx) {
150 // Attempting to complete setting variable name
151 CommandCompletions::InvokeCommonCompletionCallbacks(
152 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
156 request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex());
160 // Complete option name
162 // Complete setting value
163 const char *setting_var_name =
164 request.GetParsedLine().GetArgumentAtIndex(setting_var_idx);
166 lldb::OptionValueSP value_sp(
167 m_interpreter.GetDebugger().GetPropertyValue(
168 &m_exe_ctx, setting_var_name, false, error));
170 value_sp->AutoComplete(m_interpreter, request);
175 return request.GetNumberOfMatches();
179 bool DoExecute(llvm::StringRef command,
180 CommandReturnObject &result) override {
181 Args cmd_args(command);
183 // Process possible options.
184 if (!ParseOptions(cmd_args, result))
187 const size_t argc = cmd_args.GetArgumentCount();
188 if ((argc < 2) && (!m_options.m_global)) {
189 result.AppendError("'settings set' takes more arguments");
190 result.SetStatus(eReturnStatusFailed);
194 const char *var_name = cmd_args.GetArgumentAtIndex(0);
195 if ((var_name == nullptr) || (var_name[0] == '\0')) {
197 "'settings set' command requires a valid variable name");
198 result.SetStatus(eReturnStatusFailed);
202 // Split the raw command into var_name and value pair.
203 llvm::StringRef raw_str(command);
204 std::string var_value_string = raw_str.split(var_name).second.str();
205 const char *var_value_cstr =
206 Args::StripSpaces(var_value_string, true, false, false);
209 if (m_options.m_global) {
210 error = m_interpreter.GetDebugger().SetPropertyValue(
211 nullptr, eVarSetOperationAssign, var_name, var_value_cstr);
214 if (error.Success()) {
215 // FIXME this is the same issue as the one in commands script import
216 // we could be setting target.load-script-from-symbol-file which would
217 // cause Python scripts to be loaded, which could run LLDB commands (e.g.
218 // settings set target.process.python-os-plugin-path) and cause a crash
219 // if we did not clear the command's exe_ctx first
220 ExecutionContext exe_ctx(m_exe_ctx);
222 error = m_interpreter.GetDebugger().SetPropertyValue(
223 &exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr);
227 result.AppendError(error.AsCString());
228 result.SetStatus(eReturnStatusFailed);
231 result.SetStatus(eReturnStatusSuccessFinishResult);
234 return result.Succeeded();
238 CommandOptions m_options;
241 //-------------------------------------------------------------------------
242 // CommandObjectSettingsShow -- Show current values
243 //-------------------------------------------------------------------------
245 class CommandObjectSettingsShow : public CommandObjectParsed {
247 CommandObjectSettingsShow(CommandInterpreter &interpreter)
248 : CommandObjectParsed(interpreter, "settings show",
249 "Show matching debugger settings and their current "
250 "values. Defaults to showing all settings.",
252 CommandArgumentEntry arg1;
253 CommandArgumentData var_name_arg;
255 // Define the first (and only) variant of this arg.
256 var_name_arg.arg_type = eArgTypeSettingVariableName;
257 var_name_arg.arg_repetition = eArgRepeatOptional;
259 // There is only one variant this argument could be; put it into the
261 arg1.push_back(var_name_arg);
263 // Push the data for the first argument into the m_arguments vector.
264 m_arguments.push_back(arg1);
267 ~CommandObjectSettingsShow() override = default;
269 int HandleArgumentCompletion(
270 CompletionRequest &request,
271 OptionElementVector &opt_element_vector) override {
272 CommandCompletions::InvokeCommonCompletionCallbacks(
273 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
275 return request.GetNumberOfMatches();
279 bool DoExecute(Args &args, CommandReturnObject &result) override {
280 result.SetStatus(eReturnStatusSuccessFinishResult);
283 for (const auto &arg : args) {
284 Status error(m_interpreter.GetDebugger().DumpPropertyValue(
285 &m_exe_ctx, result.GetOutputStream(), arg.ref,
286 OptionValue::eDumpGroupValue));
287 if (error.Success()) {
288 result.GetOutputStream().EOL();
290 result.AppendError(error.AsCString());
291 result.SetStatus(eReturnStatusFailed);
295 m_interpreter.GetDebugger().DumpAllPropertyValues(
296 &m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
299 return result.Succeeded();
303 //-------------------------------------------------------------------------
304 // CommandObjectSettingsList -- List settable variables
305 //-------------------------------------------------------------------------
307 class CommandObjectSettingsList : public CommandObjectParsed {
309 CommandObjectSettingsList(CommandInterpreter &interpreter)
310 : CommandObjectParsed(interpreter, "settings list",
311 "List and describe matching debugger settings. "
312 "Defaults to all listing all settings.",
314 CommandArgumentEntry arg;
315 CommandArgumentData var_name_arg;
316 CommandArgumentData prefix_name_arg;
318 // Define the first variant of this arg.
319 var_name_arg.arg_type = eArgTypeSettingVariableName;
320 var_name_arg.arg_repetition = eArgRepeatOptional;
322 // Define the second variant of this arg.
323 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
324 prefix_name_arg.arg_repetition = eArgRepeatOptional;
326 arg.push_back(var_name_arg);
327 arg.push_back(prefix_name_arg);
329 // Push the data for the first argument into the m_arguments vector.
330 m_arguments.push_back(arg);
333 ~CommandObjectSettingsList() override = default;
335 int HandleArgumentCompletion(
336 CompletionRequest &request,
337 OptionElementVector &opt_element_vector) override {
338 CommandCompletions::InvokeCommonCompletionCallbacks(
339 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
341 return request.GetNumberOfMatches();
345 bool DoExecute(Args &args, CommandReturnObject &result) override {
346 result.SetStatus(eReturnStatusSuccessFinishResult);
348 const bool will_modify = false;
349 const size_t argc = args.GetArgumentCount();
351 const bool dump_qualified_name = true;
353 // TODO: Convert to StringRef based enumeration. Requires converting
354 // GetPropertyAtPath first.
355 for (size_t i = 0; i < argc; ++i) {
356 const char *property_path = args.GetArgumentAtIndex(i);
358 const Property *property =
359 m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath(
360 &m_exe_ctx, will_modify, property_path);
363 property->DumpDescription(m_interpreter, result.GetOutputStream(), 0,
364 dump_qualified_name);
366 result.AppendErrorWithFormat("invalid property path '%s'",
368 result.SetStatus(eReturnStatusFailed);
372 m_interpreter.GetDebugger().DumpAllDescriptions(m_interpreter,
373 result.GetOutputStream());
376 return result.Succeeded();
380 //-------------------------------------------------------------------------
381 // CommandObjectSettingsRemove
382 //-------------------------------------------------------------------------
384 class CommandObjectSettingsRemove : public CommandObjectRaw {
386 CommandObjectSettingsRemove(CommandInterpreter &interpreter)
387 : CommandObjectRaw(interpreter, "settings remove",
388 "Remove a value from a setting, specified by array "
389 "index or dictionary key.") {
390 CommandArgumentEntry arg1;
391 CommandArgumentEntry arg2;
392 CommandArgumentData var_name_arg;
393 CommandArgumentData index_arg;
394 CommandArgumentData key_arg;
396 // Define the first (and only) variant of this arg.
397 var_name_arg.arg_type = eArgTypeSettingVariableName;
398 var_name_arg.arg_repetition = eArgRepeatPlain;
400 // There is only one variant this argument could be; put it into the
402 arg1.push_back(var_name_arg);
404 // Define the first variant of this arg.
405 index_arg.arg_type = eArgTypeSettingIndex;
406 index_arg.arg_repetition = eArgRepeatPlain;
408 // Define the second variant of this arg.
409 key_arg.arg_type = eArgTypeSettingKey;
410 key_arg.arg_repetition = eArgRepeatPlain;
412 // Push both variants into this arg
413 arg2.push_back(index_arg);
414 arg2.push_back(key_arg);
416 // Push the data for the first argument into the m_arguments vector.
417 m_arguments.push_back(arg1);
418 m_arguments.push_back(arg2);
421 ~CommandObjectSettingsRemove() override = default;
423 int HandleArgumentCompletion(
424 CompletionRequest &request,
425 OptionElementVector &opt_element_vector) override {
426 if (request.GetCursorIndex() < 2)
427 CommandCompletions::InvokeCommonCompletionCallbacks(
428 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
430 return request.GetNumberOfMatches();
434 bool DoExecute(llvm::StringRef command,
435 CommandReturnObject &result) override {
436 result.SetStatus(eReturnStatusSuccessFinishNoResult);
438 Args cmd_args(command);
440 // Process possible options.
441 if (!ParseOptions(cmd_args, result))
444 const size_t argc = cmd_args.GetArgumentCount();
446 result.AppendError("'settings set' takes an array or dictionary item, or "
447 "an array followed by one or more indexes, or a "
448 "dictionary followed by one or more key names to "
450 result.SetStatus(eReturnStatusFailed);
454 const char *var_name = cmd_args.GetArgumentAtIndex(0);
455 if ((var_name == nullptr) || (var_name[0] == '\0')) {
457 "'settings set' command requires a valid variable name");
458 result.SetStatus(eReturnStatusFailed);
462 // Split the raw command into var_name and value pair.
463 llvm::StringRef raw_str(command);
464 std::string var_value_string = raw_str.split(var_name).second.str();
465 const char *var_value_cstr =
466 Args::StripSpaces(var_value_string, true, true, false);
468 Status error(m_interpreter.GetDebugger().SetPropertyValue(
469 &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr));
471 result.AppendError(error.AsCString());
472 result.SetStatus(eReturnStatusFailed);
476 return result.Succeeded();
480 //-------------------------------------------------------------------------
481 // CommandObjectSettingsReplace
482 //-------------------------------------------------------------------------
484 class CommandObjectSettingsReplace : public CommandObjectRaw {
486 CommandObjectSettingsReplace(CommandInterpreter &interpreter)
487 : CommandObjectRaw(interpreter, "settings replace",
488 "Replace the debugger setting value specified by "
489 "array index or dictionary key.") {
490 CommandArgumentEntry arg1;
491 CommandArgumentEntry arg2;
492 CommandArgumentEntry arg3;
493 CommandArgumentData var_name_arg;
494 CommandArgumentData index_arg;
495 CommandArgumentData key_arg;
496 CommandArgumentData value_arg;
498 // Define the first (and only) variant of this arg.
499 var_name_arg.arg_type = eArgTypeSettingVariableName;
500 var_name_arg.arg_repetition = eArgRepeatPlain;
502 // There is only one variant this argument could be; put it into the
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 // Put both variants into this arg
515 arg2.push_back(index_arg);
516 arg2.push_back(key_arg);
518 // Define the first (and only) variant of this arg.
519 value_arg.arg_type = eArgTypeValue;
520 value_arg.arg_repetition = eArgRepeatPlain;
522 // There is only one variant this argument could be; put it into the
524 arg3.push_back(value_arg);
526 // Push the data for the first argument into the m_arguments vector.
527 m_arguments.push_back(arg1);
528 m_arguments.push_back(arg2);
529 m_arguments.push_back(arg3);
532 ~CommandObjectSettingsReplace() override = default;
534 // Overrides base class's behavior where WantsCompletion =
535 // !WantsRawCommandString.
536 bool WantsCompletion() override { return true; }
538 int HandleArgumentCompletion(
539 CompletionRequest &request,
540 OptionElementVector &opt_element_vector) override {
541 // Attempting to complete variable name
542 if (request.GetCursorIndex() < 2)
543 CommandCompletions::InvokeCommonCompletionCallbacks(
544 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
547 return request.GetNumberOfMatches();
551 bool DoExecute(llvm::StringRef command,
552 CommandReturnObject &result) override {
553 result.SetStatus(eReturnStatusSuccessFinishNoResult);
555 Args cmd_args(command);
556 const char *var_name = cmd_args.GetArgumentAtIndex(0);
557 if ((var_name == nullptr) || (var_name[0] == '\0')) {
558 result.AppendError("'settings replace' command requires a valid variable "
559 "name; No value supplied");
560 result.SetStatus(eReturnStatusFailed);
564 // Split the raw command into var_name, index_value, and value triple.
565 llvm::StringRef raw_str(command);
566 std::string var_value_string = raw_str.split(var_name).second.str();
567 const char *var_value_cstr =
568 Args::StripSpaces(var_value_string, true, true, false);
570 Status error(m_interpreter.GetDebugger().SetPropertyValue(
571 &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr));
573 result.AppendError(error.AsCString());
574 result.SetStatus(eReturnStatusFailed);
577 result.SetStatus(eReturnStatusSuccessFinishNoResult);
580 return result.Succeeded();
584 //-------------------------------------------------------------------------
585 // CommandObjectSettingsInsertBefore
586 //-------------------------------------------------------------------------
588 class CommandObjectSettingsInsertBefore : public CommandObjectRaw {
590 CommandObjectSettingsInsertBefore(CommandInterpreter &interpreter)
591 : CommandObjectRaw(interpreter, "settings insert-before",
592 "Insert one or more values into an debugger array "
593 "setting immediately before the specified element "
595 CommandArgumentEntry arg1;
596 CommandArgumentEntry arg2;
597 CommandArgumentEntry arg3;
598 CommandArgumentData var_name_arg;
599 CommandArgumentData index_arg;
600 CommandArgumentData value_arg;
602 // Define the first (and only) variant of this arg.
603 var_name_arg.arg_type = eArgTypeSettingVariableName;
604 var_name_arg.arg_repetition = eArgRepeatPlain;
606 // There is only one variant this argument could be; put it into the
608 arg1.push_back(var_name_arg);
610 // Define the first (variant of this arg.
611 index_arg.arg_type = eArgTypeSettingIndex;
612 index_arg.arg_repetition = eArgRepeatPlain;
614 // There is only one variant this argument could be; put it into the
616 arg2.push_back(index_arg);
618 // Define the first (and only) variant of this arg.
619 value_arg.arg_type = eArgTypeValue;
620 value_arg.arg_repetition = eArgRepeatPlain;
622 // There is only one variant this argument could be; put it into the
624 arg3.push_back(value_arg);
626 // Push the data for the first argument into the m_arguments vector.
627 m_arguments.push_back(arg1);
628 m_arguments.push_back(arg2);
629 m_arguments.push_back(arg3);
632 ~CommandObjectSettingsInsertBefore() override = default;
634 // Overrides base class's behavior where WantsCompletion =
635 // !WantsRawCommandString.
636 bool WantsCompletion() override { return true; }
638 int HandleArgumentCompletion(
639 CompletionRequest &request,
640 OptionElementVector &opt_element_vector) override {
641 // Attempting to complete variable name
642 if (request.GetCursorIndex() < 2)
643 CommandCompletions::InvokeCommonCompletionCallbacks(
644 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
647 return request.GetNumberOfMatches();
651 bool DoExecute(llvm::StringRef command,
652 CommandReturnObject &result) override {
653 result.SetStatus(eReturnStatusSuccessFinishNoResult);
655 Args cmd_args(command);
656 const size_t argc = cmd_args.GetArgumentCount();
659 result.AppendError("'settings insert-before' takes more arguments");
660 result.SetStatus(eReturnStatusFailed);
664 const char *var_name = cmd_args.GetArgumentAtIndex(0);
665 if ((var_name == nullptr) || (var_name[0] == '\0')) {
666 result.AppendError("'settings insert-before' command requires a valid "
667 "variable name; No value supplied");
668 result.SetStatus(eReturnStatusFailed);
672 // Split the raw command into var_name, index_value, and value triple.
673 llvm::StringRef raw_str(command);
674 std::string var_value_string = raw_str.split(var_name).second.str();
675 const char *var_value_cstr =
676 Args::StripSpaces(var_value_string, true, true, false);
678 Status error(m_interpreter.GetDebugger().SetPropertyValue(
679 &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr));
681 result.AppendError(error.AsCString());
682 result.SetStatus(eReturnStatusFailed);
686 return result.Succeeded();
690 //-------------------------------------------------------------------------
691 // CommandObjectSettingInsertAfter
692 //-------------------------------------------------------------------------
694 class CommandObjectSettingsInsertAfter : public CommandObjectRaw {
696 CommandObjectSettingsInsertAfter(CommandInterpreter &interpreter)
697 : CommandObjectRaw(interpreter, "settings insert-after",
698 "Insert one or more values into a debugger array "
699 "settings after the specified element index.") {
700 CommandArgumentEntry arg1;
701 CommandArgumentEntry arg2;
702 CommandArgumentEntry arg3;
703 CommandArgumentData var_name_arg;
704 CommandArgumentData index_arg;
705 CommandArgumentData value_arg;
707 // Define the first (and only) variant of this arg.
708 var_name_arg.arg_type = eArgTypeSettingVariableName;
709 var_name_arg.arg_repetition = eArgRepeatPlain;
711 // There is only one variant this argument could be; put it into the
713 arg1.push_back(var_name_arg);
715 // Define the first (variant of this arg.
716 index_arg.arg_type = eArgTypeSettingIndex;
717 index_arg.arg_repetition = eArgRepeatPlain;
719 // There is only one variant this argument could be; put it into the
721 arg2.push_back(index_arg);
723 // Define the first (and only) variant of this arg.
724 value_arg.arg_type = eArgTypeValue;
725 value_arg.arg_repetition = eArgRepeatPlain;
727 // There is only one variant this argument could be; put it into the
729 arg3.push_back(value_arg);
731 // Push the data for the first argument into the m_arguments vector.
732 m_arguments.push_back(arg1);
733 m_arguments.push_back(arg2);
734 m_arguments.push_back(arg3);
737 ~CommandObjectSettingsInsertAfter() override = default;
739 // Overrides base class's behavior where WantsCompletion =
740 // !WantsRawCommandString.
741 bool WantsCompletion() override { return true; }
743 int HandleArgumentCompletion(
744 CompletionRequest &request,
745 OptionElementVector &opt_element_vector) override {
746 // Attempting to complete variable name
747 if (request.GetCursorIndex() < 2)
748 CommandCompletions::InvokeCommonCompletionCallbacks(
749 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
752 return request.GetNumberOfMatches();
756 bool DoExecute(llvm::StringRef command,
757 CommandReturnObject &result) override {
758 result.SetStatus(eReturnStatusSuccessFinishNoResult);
760 Args cmd_args(command);
761 const size_t argc = cmd_args.GetArgumentCount();
764 result.AppendError("'settings insert-after' takes more arguments");
765 result.SetStatus(eReturnStatusFailed);
769 const char *var_name = cmd_args.GetArgumentAtIndex(0);
770 if ((var_name == nullptr) || (var_name[0] == '\0')) {
771 result.AppendError("'settings insert-after' command requires a valid "
772 "variable name; No value supplied");
773 result.SetStatus(eReturnStatusFailed);
777 // Split the raw command into var_name, index_value, and value triple.
778 llvm::StringRef raw_str(command);
779 std::string var_value_string = raw_str.split(var_name).second.str();
780 const char *var_value_cstr =
781 Args::StripSpaces(var_value_string, true, true, false);
783 Status error(m_interpreter.GetDebugger().SetPropertyValue(
784 &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr));
786 result.AppendError(error.AsCString());
787 result.SetStatus(eReturnStatusFailed);
791 return result.Succeeded();
795 //-------------------------------------------------------------------------
796 // CommandObjectSettingsAppend
797 //-------------------------------------------------------------------------
799 class CommandObjectSettingsAppend : public CommandObjectRaw {
801 CommandObjectSettingsAppend(CommandInterpreter &interpreter)
802 : CommandObjectRaw(interpreter, "settings append",
803 "Append one or more values to a debugger array, "
804 "dictionary, or string setting.") {
805 CommandArgumentEntry arg1;
806 CommandArgumentEntry arg2;
807 CommandArgumentData var_name_arg;
808 CommandArgumentData value_arg;
810 // Define the first (and only) variant of this arg.
811 var_name_arg.arg_type = eArgTypeSettingVariableName;
812 var_name_arg.arg_repetition = eArgRepeatPlain;
814 // There is only one variant this argument could be; put it into the
816 arg1.push_back(var_name_arg);
818 // Define the first (and only) variant of this arg.
819 value_arg.arg_type = eArgTypeValue;
820 value_arg.arg_repetition = eArgRepeatPlain;
822 // There is only one variant this argument could be; put it into the
824 arg2.push_back(value_arg);
826 // Push the data for the first argument into the m_arguments vector.
827 m_arguments.push_back(arg1);
828 m_arguments.push_back(arg2);
831 ~CommandObjectSettingsAppend() override = default;
833 // Overrides base class's behavior where WantsCompletion =
834 // !WantsRawCommandString.
835 bool WantsCompletion() override { return true; }
837 int HandleArgumentCompletion(
838 CompletionRequest &request,
839 OptionElementVector &opt_element_vector) override {
840 // Attempting to complete variable name
841 if (request.GetCursorIndex() < 2)
842 CommandCompletions::InvokeCommonCompletionCallbacks(
843 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
846 return request.GetNumberOfMatches();
850 bool DoExecute(llvm::StringRef command,
851 CommandReturnObject &result) override {
852 result.SetStatus(eReturnStatusSuccessFinishNoResult);
853 Args cmd_args(command);
854 const size_t argc = cmd_args.GetArgumentCount();
857 result.AppendError("'settings append' takes more arguments");
858 result.SetStatus(eReturnStatusFailed);
862 const char *var_name = cmd_args.GetArgumentAtIndex(0);
863 if ((var_name == nullptr) || (var_name[0] == '\0')) {
864 result.AppendError("'settings append' command requires a valid variable "
865 "name; No value supplied");
866 result.SetStatus(eReturnStatusFailed);
870 // Do not perform cmd_args.Shift() since StringRef is manipulating the raw
871 // character string later on.
873 // Split the raw command into var_name and value pair.
874 llvm::StringRef raw_str(command);
875 std::string var_value_string = raw_str.split(var_name).second.str();
876 const char *var_value_cstr =
877 Args::StripSpaces(var_value_string, true, true, false);
879 Status error(m_interpreter.GetDebugger().SetPropertyValue(
880 &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr));
882 result.AppendError(error.AsCString());
883 result.SetStatus(eReturnStatusFailed);
887 return result.Succeeded();
891 //-------------------------------------------------------------------------
892 // CommandObjectSettingsClear
893 //-------------------------------------------------------------------------
895 class CommandObjectSettingsClear : public CommandObjectParsed {
897 CommandObjectSettingsClear(CommandInterpreter &interpreter)
898 : CommandObjectParsed(
899 interpreter, "settings clear",
900 "Clear a debugger setting array, dictionary, or string.", nullptr) {
901 CommandArgumentEntry arg;
902 CommandArgumentData var_name_arg;
904 // Define the first (and only) variant of this arg.
905 var_name_arg.arg_type = eArgTypeSettingVariableName;
906 var_name_arg.arg_repetition = eArgRepeatPlain;
908 // There is only one variant this argument could be; put it into the
910 arg.push_back(var_name_arg);
912 // Push the data for the first argument into the m_arguments vector.
913 m_arguments.push_back(arg);
916 ~CommandObjectSettingsClear() override = default;
918 int HandleArgumentCompletion(
919 CompletionRequest &request,
920 OptionElementVector &opt_element_vector) override {
921 // Attempting to complete variable name
922 if (request.GetCursorIndex() < 2)
923 CommandCompletions::InvokeCommonCompletionCallbacks(
924 GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
927 return request.GetNumberOfMatches();
931 bool DoExecute(Args &command, CommandReturnObject &result) override {
932 result.SetStatus(eReturnStatusSuccessFinishNoResult);
933 const size_t argc = command.GetArgumentCount();
936 result.AppendError("'settings clear' takes exactly one argument");
937 result.SetStatus(eReturnStatusFailed);
941 const char *var_name = command.GetArgumentAtIndex(0);
942 if ((var_name == nullptr) || (var_name[0] == '\0')) {
943 result.AppendError("'settings clear' command requires a valid variable "
944 "name; No value supplied");
945 result.SetStatus(eReturnStatusFailed);
949 Status error(m_interpreter.GetDebugger().SetPropertyValue(
950 &m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef()));
952 result.AppendError(error.AsCString());
953 result.SetStatus(eReturnStatusFailed);
957 return result.Succeeded();
961 //-------------------------------------------------------------------------
962 // CommandObjectMultiwordSettings
963 //-------------------------------------------------------------------------
965 CommandObjectMultiwordSettings::CommandObjectMultiwordSettings(
966 CommandInterpreter &interpreter)
967 : CommandObjectMultiword(interpreter, "settings",
968 "Commands for managing LLDB settings.",
969 "settings <subcommand> [<command-options>]") {
970 LoadSubCommand("set",
971 CommandObjectSP(new CommandObjectSettingsSet(interpreter)));
972 LoadSubCommand("show",
973 CommandObjectSP(new CommandObjectSettingsShow(interpreter)));
974 LoadSubCommand("list",
975 CommandObjectSP(new CommandObjectSettingsList(interpreter)));
976 LoadSubCommand("remove",
977 CommandObjectSP(new CommandObjectSettingsRemove(interpreter)));
978 LoadSubCommand("replace", CommandObjectSP(
979 new CommandObjectSettingsReplace(interpreter)));
982 CommandObjectSP(new CommandObjectSettingsInsertBefore(interpreter)));
985 CommandObjectSP(new CommandObjectSettingsInsertAfter(interpreter)));
986 LoadSubCommand("append",
987 CommandObjectSP(new CommandObjectSettingsAppend(interpreter)));
988 LoadSubCommand("clear",
989 CommandObjectSP(new CommandObjectSettingsClear(interpreter)));
992 CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings() = default;