Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectSettings.cpp -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectSettings.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
Eugene Zelenko | 3f18ea0 | 2016-02-24 02:05:55 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringRef.h" |
| 16 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | // Project includes |
Zachary Turner | 3eb2b44 | 2017-03-22 23:33:16 +0000 | [diff] [blame] | 18 | #include "lldb/Host/OptionParser.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/Interpreter/CommandCompletions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 21 | #include "lldb/Interpreter/CommandReturnObject.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/OptionValueProperties.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 26 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 27 | //------------------------------------------------------------------------- |
| 28 | // CommandObjectSettingsSet |
| 29 | //------------------------------------------------------------------------- |
| 30 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 31 | static constexpr OptionDefinition g_settings_set_options[] = { |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 32 | // clang-format off |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 33 | { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Apply the new value to the global default value." } |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 34 | // clang-format on |
| 35 | }; |
| 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | class CommandObjectSettingsSet : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 38 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | CommandObjectSettingsSet(CommandInterpreter &interpreter) |
| 40 | : CommandObjectRaw(interpreter, "settings set", |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 41 | "Set the value of the specified debugger setting."), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | m_options() { |
| 43 | CommandArgumentEntry arg1; |
| 44 | CommandArgumentEntry arg2; |
| 45 | CommandArgumentData var_name_arg; |
| 46 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | // Define the first (and only) variant of this arg. |
| 49 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 50 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | // There is only one variant this argument could be; put it into the |
| 53 | // argument entry. |
| 54 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | // Define the first (and only) variant of this arg. |
| 57 | value_arg.arg_type = eArgTypeValue; |
| 58 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | // There is only one variant this argument could be; put it into the |
| 61 | // argument entry. |
| 62 | arg2.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 67 | |
| 68 | SetHelpLong( |
| 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:" |
| 71 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 72 | |
| 73 | (lldb) settings set target.run-args value1 value2 value3 |
| 74 | (lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345 |
| 75 | |
| 76 | (lldb) settings show target.run-args |
| 77 | [0]: 'value1' |
| 78 | [1]: 'value2' |
| 79 | [3]: 'value3' |
| 80 | (lldb) settings show target.env-vars |
| 81 | 'MYPATH=~/.:/usr/bin' |
| 82 | 'SOME_ENV_VAR=12345' |
| 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | )" |
| 85 | "Warning: The 'set' command re-sets the entire array or dictionary. If you \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 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, \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | insert-before or insert-after."); |
| 89 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 90 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | ~CommandObjectSettingsSet() override = default; |
| 92 | |
| 93 | // Overrides base class's behavior where WantsCompletion = |
| 94 | // !WantsRawCommandString. |
| 95 | bool WantsCompletion() override { return true; } |
| 96 | |
| 97 | Options *GetOptions() override { return &m_options; } |
| 98 | |
| 99 | class CommandOptions : public Options { |
| 100 | public: |
| 101 | CommandOptions() : Options(), m_global(false) {} |
| 102 | |
| 103 | ~CommandOptions() override = default; |
| 104 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 105 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
| 106 | ExecutionContext *execution_context) override { |
| 107 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | const int short_option = m_getopt_table[option_idx].val; |
| 109 | |
| 110 | switch (short_option) { |
| 111 | case 'g': |
| 112 | m_global = true; |
| 113 | break; |
| 114 | default: |
| 115 | error.SetErrorStringWithFormat("unrecognized options '%c'", |
| 116 | short_option); |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | return error; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 124 | m_global = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 125 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 126 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 127 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 128 | return llvm::makeArrayRef(g_settings_set_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 129 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 130 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 131 | // Instance variables to hold the values for command options. |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | bool m_global; |
| 134 | }; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 135 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 136 | int HandleArgumentCompletion( |
| 137 | CompletionRequest &request, |
| 138 | OptionElementVector &opt_element_vector) override { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 139 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 140 | const size_t argc = request.GetParsedLine().GetArgumentCount(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | const char *arg = nullptr; |
| 142 | int setting_var_idx; |
Pavel Labath | 5f56fca | 2018-03-09 10:39:40 +0000 | [diff] [blame] | 143 | for (setting_var_idx = 0; setting_var_idx < static_cast<int>(argc); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | ++setting_var_idx) { |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 145 | arg = request.GetParsedLine().GetArgumentAtIndex(setting_var_idx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | if (arg && arg[0] != '-') |
| 147 | break; // We found our setting variable name index |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 148 | } |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 149 | if (request.GetCursorIndex() == setting_var_idx) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | // Attempting to complete setting variable name |
| 151 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 152 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 153 | request, nullptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | } else { |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 155 | arg = |
| 156 | request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | |
| 158 | if (arg) { |
| 159 | if (arg[0] == '-') { |
| 160 | // Complete option name |
| 161 | } else { |
| 162 | // Complete setting value |
| 163 | const char *setting_var_name = |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 164 | request.GetParsedLine().GetArgumentAtIndex(setting_var_idx); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 165 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | lldb::OptionValueSP value_sp( |
| 167 | m_interpreter.GetDebugger().GetPropertyValue( |
| 168 | &m_exe_ctx, setting_var_name, false, error)); |
| 169 | if (value_sp) { |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 170 | value_sp->AutoComplete(m_interpreter, request); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 175 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 178 | protected: |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 179 | bool DoExecute(llvm::StringRef command, |
| 180 | CommandReturnObject &result) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 181 | Args cmd_args(command); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 182 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | // Process possible options. |
| 184 | if (!ParseOptions(cmd_args, result)) |
| 185 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 186 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 191 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 192 | } |
Eugene Zelenko | 3f18ea0 | 2016-02-24 02:05:55 +0000 | [diff] [blame] | 193 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 195 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 196 | result.AppendError( |
| 197 | "'settings set' command requires a valid variable name"); |
| 198 | result.SetStatus(eReturnStatusFailed); |
| 199 | return false; |
| 200 | } |
| 201 | |
| 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); |
| 207 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 208 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | if (m_options.m_global) { |
| 210 | error = m_interpreter.GetDebugger().SetPropertyValue( |
| 211 | nullptr, eVarSetOperationAssign, var_name, var_value_cstr); |
| 212 | } |
| 213 | |
| 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 |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 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 |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 219 | // if we did not clear the command's exe_ctx first |
| 220 | ExecutionContext exe_ctx(m_exe_ctx); |
| 221 | m_exe_ctx.Clear(); |
| 222 | error = m_interpreter.GetDebugger().SetPropertyValue( |
| 223 | &exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr); |
| 224 | } |
| 225 | |
| 226 | if (error.Fail()) { |
| 227 | result.AppendError(error.AsCString()); |
| 228 | result.SetStatus(eReturnStatusFailed); |
| 229 | return false; |
| 230 | } else { |
| 231 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 232 | } |
| 233 | |
| 234 | return result.Succeeded(); |
| 235 | } |
| 236 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 237 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 238 | CommandOptions m_options; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 241 | //------------------------------------------------------------------------- |
| 242 | // CommandObjectSettingsShow -- Show current values |
| 243 | //------------------------------------------------------------------------- |
| 244 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | class CommandObjectSettingsShow : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 246 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | CommandObjectSettingsShow(CommandInterpreter &interpreter) |
| 248 | : CommandObjectParsed(interpreter, "settings show", |
| 249 | "Show matching debugger settings and their current " |
| 250 | "values. Defaults to showing all settings.", |
| 251 | nullptr) { |
| 252 | CommandArgumentEntry arg1; |
| 253 | CommandArgumentData var_name_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 254 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 255 | // Define the first (and only) variant of this arg. |
| 256 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 257 | var_name_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 258 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 259 | // There is only one variant this argument could be; put it into the |
| 260 | // argument entry. |
| 261 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 262 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | // Push the data for the first argument into the m_arguments vector. |
| 264 | m_arguments.push_back(arg1); |
| 265 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 266 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | ~CommandObjectSettingsShow() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 268 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 269 | int HandleArgumentCompletion( |
| 270 | CompletionRequest &request, |
| 271 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 273 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 274 | request, nullptr); |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 275 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 277 | |
| 278 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 279 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 280 | result.SetStatus(eReturnStatusSuccessFinishResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 281 | |
Zachary Turner | 97d2c40 | 2016-10-05 23:40:23 +0000 | [diff] [blame] | 282 | if (!args.empty()) { |
Zachary Turner | d6a2475 | 2016-11-22 17:10:15 +0000 | [diff] [blame] | 283 | for (const auto &arg : args) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 284 | Status error(m_interpreter.GetDebugger().DumpPropertyValue( |
Zachary Turner | d6a2475 | 2016-11-22 17:10:15 +0000 | [diff] [blame] | 285 | &m_exe_ctx, result.GetOutputStream(), arg.ref, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 286 | OptionValue::eDumpGroupValue)); |
| 287 | if (error.Success()) { |
| 288 | result.GetOutputStream().EOL(); |
| 289 | } else { |
| 290 | result.AppendError(error.AsCString()); |
| 291 | result.SetStatus(eReturnStatusFailed); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 292 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 293 | } |
| 294 | } else { |
| 295 | m_interpreter.GetDebugger().DumpAllPropertyValues( |
| 296 | &m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 297 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | |
| 299 | return result.Succeeded(); |
| 300 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | //------------------------------------------------------------------------- |
| 304 | // CommandObjectSettingsList -- List settable variables |
| 305 | //------------------------------------------------------------------------- |
| 306 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 307 | class CommandObjectSettingsList : public CommandObjectParsed { |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 308 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 309 | CommandObjectSettingsList(CommandInterpreter &interpreter) |
| 310 | : CommandObjectParsed(interpreter, "settings list", |
| 311 | "List and describe matching debugger settings. " |
| 312 | "Defaults to all listing all settings.", |
| 313 | nullptr) { |
| 314 | CommandArgumentEntry arg; |
| 315 | CommandArgumentData var_name_arg; |
| 316 | CommandArgumentData prefix_name_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 317 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 318 | // Define the first variant of this arg. |
| 319 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 320 | var_name_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 321 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 322 | // Define the second variant of this arg. |
| 323 | prefix_name_arg.arg_type = eArgTypeSettingPrefix; |
| 324 | prefix_name_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 325 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | arg.push_back(var_name_arg); |
| 327 | arg.push_back(prefix_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 328 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 329 | // Push the data for the first argument into the m_arguments vector. |
| 330 | m_arguments.push_back(arg); |
| 331 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 332 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 333 | ~CommandObjectSettingsList() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 334 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 335 | int HandleArgumentCompletion( |
| 336 | CompletionRequest &request, |
| 337 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 339 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 340 | request, nullptr); |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 341 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 343 | |
| 344 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 345 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 346 | result.SetStatus(eReturnStatusSuccessFinishResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 347 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | const bool will_modify = false; |
| 349 | const size_t argc = args.GetArgumentCount(); |
| 350 | if (argc > 0) { |
| 351 | const bool dump_qualified_name = true; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 352 | |
Zachary Turner | 97d2c40 | 2016-10-05 23:40:23 +0000 | [diff] [blame] | 353 | // TODO: Convert to StringRef based enumeration. Requires converting |
| 354 | // GetPropertyAtPath first. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 355 | for (size_t i = 0; i < argc; ++i) { |
| 356 | const char *property_path = args.GetArgumentAtIndex(i); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 357 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | const Property *property = |
| 359 | m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath( |
| 360 | &m_exe_ctx, will_modify, property_path); |
| 361 | |
| 362 | if (property) { |
| 363 | property->DumpDescription(m_interpreter, result.GetOutputStream(), 0, |
| 364 | dump_qualified_name); |
| 365 | } else { |
| 366 | result.AppendErrorWithFormat("invalid property path '%s'", |
| 367 | property_path); |
| 368 | result.SetStatus(eReturnStatusFailed); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 369 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 370 | } |
| 371 | } else { |
| 372 | m_interpreter.GetDebugger().DumpAllDescriptions(m_interpreter, |
| 373 | result.GetOutputStream()); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 374 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | |
| 376 | return result.Succeeded(); |
| 377 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | //------------------------------------------------------------------------- |
| 381 | // CommandObjectSettingsRemove |
| 382 | //------------------------------------------------------------------------- |
| 383 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 384 | class CommandObjectSettingsRemove : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 385 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 386 | CommandObjectSettingsRemove(CommandInterpreter &interpreter) |
| 387 | : CommandObjectRaw(interpreter, "settings remove", |
| 388 | "Remove a value from a setting, specified by array " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 389 | "index or dictionary key.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | CommandArgumentEntry arg1; |
| 391 | CommandArgumentEntry arg2; |
| 392 | CommandArgumentData var_name_arg; |
| 393 | CommandArgumentData index_arg; |
| 394 | CommandArgumentData key_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 395 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 396 | // Define the first (and only) variant of this arg. |
| 397 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 398 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 399 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 400 | // There is only one variant this argument could be; put it into the |
| 401 | // argument entry. |
| 402 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 403 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | // Define the first variant of this arg. |
| 405 | index_arg.arg_type = eArgTypeSettingIndex; |
| 406 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 407 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 408 | // Define the second variant of this arg. |
| 409 | key_arg.arg_type = eArgTypeSettingKey; |
| 410 | key_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 411 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | // Push both variants into this arg |
| 413 | arg2.push_back(index_arg); |
| 414 | arg2.push_back(key_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 415 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 419 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 420 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 421 | ~CommandObjectSettingsRemove() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 422 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 423 | int HandleArgumentCompletion( |
| 424 | CompletionRequest &request, |
| 425 | OptionElementVector &opt_element_vector) override { |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 426 | if (request.GetCursorIndex() < 2) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 427 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 428 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 429 | request, nullptr); |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 430 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 431 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 432 | |
| 433 | protected: |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 434 | bool DoExecute(llvm::StringRef command, |
| 435 | CommandReturnObject &result) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 436 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 437 | |
| 438 | Args cmd_args(command); |
| 439 | |
| 440 | // Process possible options. |
| 441 | if (!ParseOptions(cmd_args, result)) |
| 442 | return false; |
| 443 | |
| 444 | const size_t argc = cmd_args.GetArgumentCount(); |
| 445 | if (argc == 0) { |
| 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 " |
| 449 | "remove"); |
| 450 | result.SetStatus(eReturnStatusFailed); |
| 451 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 452 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 453 | |
| 454 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 455 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 456 | result.AppendError( |
| 457 | "'settings set' command requires a valid variable name"); |
| 458 | result.SetStatus(eReturnStatusFailed); |
| 459 | return false; |
| 460 | } |
| 461 | |
| 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); |
| 467 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 468 | Status error(m_interpreter.GetDebugger().SetPropertyValue( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 469 | &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr)); |
| 470 | if (error.Fail()) { |
| 471 | result.AppendError(error.AsCString()); |
| 472 | result.SetStatus(eReturnStatusFailed); |
| 473 | return false; |
| 474 | } |
| 475 | |
| 476 | return result.Succeeded(); |
| 477 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 478 | }; |
| 479 | |
| 480 | //------------------------------------------------------------------------- |
| 481 | // CommandObjectSettingsReplace |
| 482 | //------------------------------------------------------------------------- |
| 483 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 484 | class CommandObjectSettingsReplace : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 485 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 486 | CommandObjectSettingsReplace(CommandInterpreter &interpreter) |
| 487 | : CommandObjectRaw(interpreter, "settings replace", |
| 488 | "Replace the debugger setting value specified by " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 489 | "array index or dictionary key.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 497 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 498 | // Define the first (and only) variant of this arg. |
| 499 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 500 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 501 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | // There is only one variant this argument could be; put it into the |
| 503 | // argument entry. |
| 504 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 505 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 506 | // Define the first (variant of this arg. |
| 507 | index_arg.arg_type = eArgTypeSettingIndex; |
| 508 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 509 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 510 | // Define the second (variant of this arg. |
| 511 | key_arg.arg_type = eArgTypeSettingKey; |
| 512 | key_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 513 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 514 | // Put both variants into this arg |
| 515 | arg2.push_back(index_arg); |
| 516 | arg2.push_back(key_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 517 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 518 | // Define the first (and only) variant of this arg. |
| 519 | value_arg.arg_type = eArgTypeValue; |
| 520 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 522 | // There is only one variant this argument could be; put it into the |
| 523 | // argument entry. |
| 524 | arg3.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 525 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 530 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 531 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 532 | ~CommandObjectSettingsReplace() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 533 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | // Overrides base class's behavior where WantsCompletion = |
| 535 | // !WantsRawCommandString. |
| 536 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 537 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 538 | int HandleArgumentCompletion( |
| 539 | CompletionRequest &request, |
| 540 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 541 | // Attempting to complete variable name |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 542 | if (request.GetCursorIndex() < 2) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 544 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 545 | request, nullptr); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 546 | |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 547 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 548 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 549 | |
| 550 | protected: |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 551 | bool DoExecute(llvm::StringRef command, |
| 552 | CommandReturnObject &result) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 553 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 554 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 561 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 562 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 563 | |
| 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); |
| 569 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 570 | Status error(m_interpreter.GetDebugger().SetPropertyValue( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 571 | &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr)); |
| 572 | if (error.Fail()) { |
| 573 | result.AppendError(error.AsCString()); |
| 574 | result.SetStatus(eReturnStatusFailed); |
| 575 | return false; |
| 576 | } else { |
| 577 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 578 | } |
| 579 | |
| 580 | return result.Succeeded(); |
| 581 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 582 | }; |
| 583 | |
| 584 | //------------------------------------------------------------------------- |
| 585 | // CommandObjectSettingsInsertBefore |
| 586 | //------------------------------------------------------------------------- |
| 587 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 588 | class CommandObjectSettingsInsertBefore : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 589 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 594 | "index.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 595 | CommandArgumentEntry arg1; |
| 596 | CommandArgumentEntry arg2; |
| 597 | CommandArgumentEntry arg3; |
| 598 | CommandArgumentData var_name_arg; |
| 599 | CommandArgumentData index_arg; |
| 600 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 601 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 602 | // Define the first (and only) variant of this arg. |
| 603 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 604 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 605 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 606 | // There is only one variant this argument could be; put it into the |
| 607 | // argument entry. |
| 608 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 609 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 610 | // Define the first (variant of this arg. |
| 611 | index_arg.arg_type = eArgTypeSettingIndex; |
| 612 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 613 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 614 | // There is only one variant this argument could be; put it into the |
| 615 | // argument entry. |
| 616 | arg2.push_back(index_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 617 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 618 | // Define the first (and only) variant of this arg. |
| 619 | value_arg.arg_type = eArgTypeValue; |
| 620 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 621 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 622 | // There is only one variant this argument could be; put it into the |
| 623 | // argument entry. |
| 624 | arg3.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 625 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 630 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 631 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 632 | ~CommandObjectSettingsInsertBefore() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 633 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 634 | // Overrides base class's behavior where WantsCompletion = |
| 635 | // !WantsRawCommandString. |
| 636 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 637 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 638 | int HandleArgumentCompletion( |
| 639 | CompletionRequest &request, |
| 640 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 641 | // Attempting to complete variable name |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 642 | if (request.GetCursorIndex() < 2) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 643 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 644 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 645 | request, nullptr); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 646 | |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 647 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 648 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 649 | |
| 650 | protected: |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 651 | bool DoExecute(llvm::StringRef command, |
| 652 | CommandReturnObject &result) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 653 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 654 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 655 | Args cmd_args(command); |
| 656 | const size_t argc = cmd_args.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 657 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 658 | if (argc < 3) { |
| 659 | result.AppendError("'settings insert-before' takes more arguments"); |
| 660 | result.SetStatus(eReturnStatusFailed); |
| 661 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 662 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 663 | |
| 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); |
| 669 | return false; |
| 670 | } |
| 671 | |
| 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); |
| 677 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 678 | Status error(m_interpreter.GetDebugger().SetPropertyValue( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 679 | &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr)); |
| 680 | if (error.Fail()) { |
| 681 | result.AppendError(error.AsCString()); |
| 682 | result.SetStatus(eReturnStatusFailed); |
| 683 | return false; |
| 684 | } |
| 685 | |
| 686 | return result.Succeeded(); |
| 687 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | //------------------------------------------------------------------------- |
| 691 | // CommandObjectSettingInsertAfter |
| 692 | //------------------------------------------------------------------------- |
| 693 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 694 | class CommandObjectSettingsInsertAfter : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 695 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | CommandObjectSettingsInsertAfter(CommandInterpreter &interpreter) |
| 697 | : CommandObjectRaw(interpreter, "settings insert-after", |
| 698 | "Insert one or more values into a debugger array " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 699 | "settings after the specified element index.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 700 | CommandArgumentEntry arg1; |
| 701 | CommandArgumentEntry arg2; |
| 702 | CommandArgumentEntry arg3; |
| 703 | CommandArgumentData var_name_arg; |
| 704 | CommandArgumentData index_arg; |
| 705 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 706 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 707 | // Define the first (and only) variant of this arg. |
| 708 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 709 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 710 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 711 | // There is only one variant this argument could be; put it into the |
| 712 | // argument entry. |
| 713 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 714 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 715 | // Define the first (variant of this arg. |
| 716 | index_arg.arg_type = eArgTypeSettingIndex; |
| 717 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 718 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 719 | // There is only one variant this argument could be; put it into the |
| 720 | // argument entry. |
| 721 | arg2.push_back(index_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 722 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 723 | // Define the first (and only) variant of this arg. |
| 724 | value_arg.arg_type = eArgTypeValue; |
| 725 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 726 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 727 | // There is only one variant this argument could be; put it into the |
| 728 | // argument entry. |
| 729 | arg3.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 730 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 735 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 736 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 737 | ~CommandObjectSettingsInsertAfter() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 738 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 739 | // Overrides base class's behavior where WantsCompletion = |
| 740 | // !WantsRawCommandString. |
| 741 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 742 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 743 | int HandleArgumentCompletion( |
| 744 | CompletionRequest &request, |
| 745 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 746 | // Attempting to complete variable name |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 747 | if (request.GetCursorIndex() < 2) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 748 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 749 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 750 | request, nullptr); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 751 | |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 752 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 755 | protected: |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 756 | bool DoExecute(llvm::StringRef command, |
| 757 | CommandReturnObject &result) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 758 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 759 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 760 | Args cmd_args(command); |
| 761 | const size_t argc = cmd_args.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 762 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 763 | if (argc < 3) { |
| 764 | result.AppendError("'settings insert-after' takes more arguments"); |
| 765 | result.SetStatus(eReturnStatusFailed); |
| 766 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 767 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 768 | |
| 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); |
| 774 | return false; |
| 775 | } |
| 776 | |
| 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); |
| 782 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 783 | Status error(m_interpreter.GetDebugger().SetPropertyValue( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 784 | &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr)); |
| 785 | if (error.Fail()) { |
| 786 | result.AppendError(error.AsCString()); |
| 787 | result.SetStatus(eReturnStatusFailed); |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | return result.Succeeded(); |
| 792 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 793 | }; |
| 794 | |
| 795 | //------------------------------------------------------------------------- |
| 796 | // CommandObjectSettingsAppend |
| 797 | //------------------------------------------------------------------------- |
| 798 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 799 | class CommandObjectSettingsAppend : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 800 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 801 | CommandObjectSettingsAppend(CommandInterpreter &interpreter) |
| 802 | : CommandObjectRaw(interpreter, "settings append", |
| 803 | "Append one or more values to a debugger array, " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 804 | "dictionary, or string setting.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 805 | CommandArgumentEntry arg1; |
| 806 | CommandArgumentEntry arg2; |
| 807 | CommandArgumentData var_name_arg; |
| 808 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 809 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 810 | // Define the first (and only) variant of this arg. |
| 811 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 812 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 813 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 814 | // There is only one variant this argument could be; put it into the |
| 815 | // argument entry. |
| 816 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 817 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 818 | // Define the first (and only) variant of this arg. |
| 819 | value_arg.arg_type = eArgTypeValue; |
| 820 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 821 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 822 | // There is only one variant this argument could be; put it into the |
| 823 | // argument entry. |
| 824 | arg2.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 825 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
| 829 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 830 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 831 | ~CommandObjectSettingsAppend() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 832 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 833 | // Overrides base class's behavior where WantsCompletion = |
| 834 | // !WantsRawCommandString. |
| 835 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 836 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 837 | int HandleArgumentCompletion( |
| 838 | CompletionRequest &request, |
| 839 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 840 | // Attempting to complete variable name |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 841 | if (request.GetCursorIndex() < 2) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 842 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 843 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 844 | request, nullptr); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 845 | |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 846 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 847 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 848 | |
| 849 | protected: |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 850 | bool DoExecute(llvm::StringRef command, |
| 851 | CommandReturnObject &result) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 852 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 853 | Args cmd_args(command); |
| 854 | const size_t argc = cmd_args.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 855 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 856 | if (argc < 2) { |
| 857 | result.AppendError("'settings append' takes more arguments"); |
| 858 | result.SetStatus(eReturnStatusFailed); |
| 859 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 860 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 861 | |
| 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); |
| 867 | return false; |
| 868 | } |
| 869 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 870 | // Do not perform cmd_args.Shift() since StringRef is manipulating the raw |
| 871 | // character string later on. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 872 | |
| 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); |
| 878 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 879 | Status error(m_interpreter.GetDebugger().SetPropertyValue( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 880 | &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr)); |
| 881 | if (error.Fail()) { |
| 882 | result.AppendError(error.AsCString()); |
| 883 | result.SetStatus(eReturnStatusFailed); |
| 884 | return false; |
| 885 | } |
| 886 | |
| 887 | return result.Succeeded(); |
| 888 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 889 | }; |
| 890 | |
| 891 | //------------------------------------------------------------------------- |
| 892 | // CommandObjectSettingsClear |
| 893 | //------------------------------------------------------------------------- |
| 894 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 895 | class CommandObjectSettingsClear : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 896 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 903 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | // Define the first (and only) variant of this arg. |
| 905 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 906 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 907 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 908 | // There is only one variant this argument could be; put it into the |
| 909 | // argument entry. |
| 910 | arg.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 911 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 912 | // Push the data for the first argument into the m_arguments vector. |
| 913 | m_arguments.push_back(arg); |
| 914 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 915 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 916 | ~CommandObjectSettingsClear() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 917 | |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 918 | int HandleArgumentCompletion( |
| 919 | CompletionRequest &request, |
| 920 | OptionElementVector &opt_element_vector) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 921 | // Attempting to complete variable name |
Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 922 | if (request.GetCursorIndex() < 2) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 923 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 924 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 925 | request, nullptr); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 926 | |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 927 | return request.GetNumberOfMatches(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 928 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 929 | |
| 930 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 931 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 932 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 933 | const size_t argc = command.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 934 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 935 | if (argc != 1) { |
| 936 | result.AppendError("'settings clear' takes exactly one argument"); |
| 937 | result.SetStatus(eReturnStatusFailed); |
| 938 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 939 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 940 | |
| 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); |
| 946 | return false; |
| 947 | } |
| 948 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 949 | Status error(m_interpreter.GetDebugger().SetPropertyValue( |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 950 | &m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 951 | if (error.Fail()) { |
| 952 | result.AppendError(error.AsCString()); |
| 953 | result.SetStatus(eReturnStatusFailed); |
| 954 | return false; |
| 955 | } |
| 956 | |
| 957 | return result.Succeeded(); |
| 958 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 959 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 960 | |
| 961 | //------------------------------------------------------------------------- |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 962 | // CommandObjectMultiwordSettings |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 963 | //------------------------------------------------------------------------- |
| 964 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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))); |
| 980 | LoadSubCommand( |
| 981 | "insert-before", |
| 982 | CommandObjectSP(new CommandObjectSettingsInsertBefore(interpreter))); |
| 983 | LoadSubCommand( |
| 984 | "insert-after", |
| 985 | CommandObjectSP(new CommandObjectSettingsInsertAfter(interpreter))); |
| 986 | LoadSubCommand("append", |
| 987 | CommandObjectSP(new CommandObjectSettingsAppend(interpreter))); |
| 988 | LoadSubCommand("clear", |
| 989 | CommandObjectSP(new CommandObjectSettingsClear(interpreter))); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Eugene Zelenko | 3f18ea0 | 2016-02-24 02:05:55 +0000 | [diff] [blame] | 992 | CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings() = default; |