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 |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandCompletions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 20 | #include "lldb/Interpreter/CommandReturnObject.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 21 | #include "lldb/Interpreter/OptionValueProperties.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 25 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 26 | //------------------------------------------------------------------------- |
| 27 | // CommandObjectSettingsSet |
| 28 | //------------------------------------------------------------------------- |
| 29 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 30 | static OptionDefinition g_settings_set_options[] = { |
| 31 | // clang-format off |
| 32 | { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Apply the new value to the global default value." } |
| 33 | // clang-format on |
| 34 | }; |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | class CommandObjectSettingsSet : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 37 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | CommandObjectSettingsSet(CommandInterpreter &interpreter) |
| 39 | : CommandObjectRaw(interpreter, "settings set", |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 40 | "Set the value of the specified debugger setting."), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | m_options() { |
| 42 | CommandArgumentEntry arg1; |
| 43 | CommandArgumentEntry arg2; |
| 44 | CommandArgumentData var_name_arg; |
| 45 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | // Define the first (and only) variant of this arg. |
| 48 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 49 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | // There is only one variant this argument could be; put it into the |
| 52 | // argument entry. |
| 53 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | // Define the first (and only) variant of this arg. |
| 56 | value_arg.arg_type = eArgTypeValue; |
| 57 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | // There is only one variant this argument could be; put it into the |
| 60 | // argument entry. |
| 61 | arg2.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | // Push the data for the first argument into the m_arguments vector. |
| 64 | m_arguments.push_back(arg1); |
| 65 | m_arguments.push_back(arg2); |
| 66 | |
| 67 | SetHelpLong( |
| 68 | "\nWhen setting a dictionary or array variable, you can set multiple entries \ |
| 69 | at once by giving the values to the set command. For example:" |
| 70 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 71 | |
| 72 | (lldb) settings set target.run-args value1 value2 value3 |
| 73 | (lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345 |
| 74 | |
| 75 | (lldb) settings show target.run-args |
| 76 | [0]: 'value1' |
| 77 | [1]: 'value2' |
| 78 | [3]: 'value3' |
| 79 | (lldb) settings show target.env-vars |
| 80 | 'MYPATH=~/.:/usr/bin' |
| 81 | 'SOME_ENV_VAR=12345' |
| 82 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 83 | )" |
| 84 | "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] | 85 | just want to add, remove or update individual values (or add something to \ |
| 86 | the end), use one of the other settings sub-commands: append, replace, \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | insert-before or insert-after."); |
| 88 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | ~CommandObjectSettingsSet() override = default; |
| 91 | |
| 92 | // Overrides base class's behavior where WantsCompletion = |
| 93 | // !WantsRawCommandString. |
| 94 | bool WantsCompletion() override { return true; } |
| 95 | |
| 96 | Options *GetOptions() override { return &m_options; } |
| 97 | |
| 98 | class CommandOptions : public Options { |
| 99 | public: |
| 100 | CommandOptions() : Options(), m_global(false) {} |
| 101 | |
| 102 | ~CommandOptions() override = default; |
| 103 | |
| 104 | Error SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 105 | ExecutionContext *execution_context) override { |
| 106 | Error error; |
| 107 | const int short_option = m_getopt_table[option_idx].val; |
| 108 | |
| 109 | switch (short_option) { |
| 110 | case 'g': |
| 111 | m_global = true; |
| 112 | break; |
| 113 | default: |
| 114 | error.SetErrorStringWithFormat("unrecognized options '%c'", |
| 115 | short_option); |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | return error; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 123 | m_global = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 124 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 125 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 126 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 127 | return llvm::makeArrayRef(g_settings_set_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 128 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | // Instance variables to hold the values for command options. |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | bool m_global; |
| 133 | }; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 134 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 136 | int &cursor_char_position, |
| 137 | OptionElementVector &opt_element_vector, |
| 138 | int match_start_point, int max_return_elements, |
| 139 | bool &word_complete, |
| 140 | StringList &matches) override { |
| 141 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 142 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 143 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | const size_t argc = input.GetArgumentCount(); |
| 145 | const char *arg = nullptr; |
| 146 | int setting_var_idx; |
| 147 | for (setting_var_idx = 1; setting_var_idx < static_cast<int>(argc); |
| 148 | ++setting_var_idx) { |
| 149 | arg = input.GetArgumentAtIndex(setting_var_idx); |
| 150 | if (arg && arg[0] != '-') |
| 151 | break; // We found our setting variable name index |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 152 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | if (cursor_index == setting_var_idx) { |
| 154 | // Attempting to complete setting variable name |
| 155 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 156 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 157 | completion_str.c_str(), match_start_point, max_return_elements, |
| 158 | nullptr, word_complete, matches); |
| 159 | } else { |
| 160 | arg = input.GetArgumentAtIndex(cursor_index); |
| 161 | |
| 162 | if (arg) { |
| 163 | if (arg[0] == '-') { |
| 164 | // Complete option name |
| 165 | } else { |
| 166 | // Complete setting value |
| 167 | const char *setting_var_name = |
| 168 | input.GetArgumentAtIndex(setting_var_idx); |
| 169 | Error error; |
| 170 | lldb::OptionValueSP value_sp( |
| 171 | m_interpreter.GetDebugger().GetPropertyValue( |
| 172 | &m_exe_ctx, setting_var_name, false, error)); |
| 173 | if (value_sp) { |
| 174 | value_sp->AutoComplete(m_interpreter, completion_str.c_str(), |
| 175 | match_start_point, max_return_elements, |
| 176 | word_complete, matches); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | return matches.GetSize(); |
| 182 | } |
| 183 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 184 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 185 | bool DoExecute(const char *command, CommandReturnObject &result) override { |
| 186 | Args cmd_args(command); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 187 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 188 | // Process possible options. |
| 189 | if (!ParseOptions(cmd_args, result)) |
| 190 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | const size_t argc = cmd_args.GetArgumentCount(); |
| 193 | if ((argc < 2) && (!m_options.m_global)) { |
| 194 | result.AppendError("'settings set' takes more arguments"); |
| 195 | result.SetStatus(eReturnStatusFailed); |
| 196 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 197 | } |
Eugene Zelenko | 3f18ea0 | 2016-02-24 02:05:55 +0000 | [diff] [blame] | 198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 199 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 200 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 201 | result.AppendError( |
| 202 | "'settings set' command requires a valid variable name"); |
| 203 | result.SetStatus(eReturnStatusFailed); |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | // Split the raw command into var_name and value pair. |
| 208 | llvm::StringRef raw_str(command); |
| 209 | std::string var_value_string = raw_str.split(var_name).second.str(); |
| 210 | const char *var_value_cstr = |
| 211 | Args::StripSpaces(var_value_string, true, false, false); |
| 212 | |
| 213 | Error error; |
| 214 | if (m_options.m_global) { |
| 215 | error = m_interpreter.GetDebugger().SetPropertyValue( |
| 216 | nullptr, eVarSetOperationAssign, var_name, var_value_cstr); |
| 217 | } |
| 218 | |
| 219 | if (error.Success()) { |
| 220 | // FIXME this is the same issue as the one in commands script import |
| 221 | // we could be setting target.load-script-from-symbol-file which would |
| 222 | // cause |
| 223 | // Python scripts to be loaded, which could run LLDB commands |
| 224 | // (e.g. settings set target.process.python-os-plugin-path) and cause a |
| 225 | // crash |
| 226 | // if we did not clear the command's exe_ctx first |
| 227 | ExecutionContext exe_ctx(m_exe_ctx); |
| 228 | m_exe_ctx.Clear(); |
| 229 | error = m_interpreter.GetDebugger().SetPropertyValue( |
| 230 | &exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr); |
| 231 | } |
| 232 | |
| 233 | if (error.Fail()) { |
| 234 | result.AppendError(error.AsCString()); |
| 235 | result.SetStatus(eReturnStatusFailed); |
| 236 | return false; |
| 237 | } else { |
| 238 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 239 | } |
| 240 | |
| 241 | return result.Succeeded(); |
| 242 | } |
| 243 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 244 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | CommandOptions m_options; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 248 | //------------------------------------------------------------------------- |
| 249 | // CommandObjectSettingsShow -- Show current values |
| 250 | //------------------------------------------------------------------------- |
| 251 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 252 | class CommandObjectSettingsShow : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 253 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | CommandObjectSettingsShow(CommandInterpreter &interpreter) |
| 255 | : CommandObjectParsed(interpreter, "settings show", |
| 256 | "Show matching debugger settings and their current " |
| 257 | "values. Defaults to showing all settings.", |
| 258 | nullptr) { |
| 259 | CommandArgumentEntry arg1; |
| 260 | CommandArgumentData var_name_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 261 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 262 | // Define the first (and only) variant of this arg. |
| 263 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 264 | var_name_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 265 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 266 | // There is only one variant this argument could be; put it into the |
| 267 | // argument entry. |
| 268 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 269 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | // Push the data for the first argument into the m_arguments vector. |
| 271 | m_arguments.push_back(arg1); |
| 272 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | ~CommandObjectSettingsShow() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 275 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 277 | int &cursor_char_position, |
| 278 | OptionElementVector &opt_element_vector, |
| 279 | int match_start_point, int max_return_elements, |
| 280 | bool &word_complete, |
| 281 | StringList &matches) override { |
| 282 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 283 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 284 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 285 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 286 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 287 | completion_str.c_str(), match_start_point, max_return_elements, nullptr, |
| 288 | word_complete, matches); |
| 289 | return matches.GetSize(); |
| 290 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 291 | |
| 292 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 293 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 294 | result.SetStatus(eReturnStatusSuccessFinishResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 295 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | const size_t argc = args.GetArgumentCount(); |
| 297 | if (argc > 0) { |
| 298 | for (size_t i = 0; i < argc; ++i) { |
| 299 | const char *property_path = args.GetArgumentAtIndex(i); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 300 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 301 | Error error(m_interpreter.GetDebugger().DumpPropertyValue( |
| 302 | &m_exe_ctx, result.GetOutputStream(), property_path, |
| 303 | OptionValue::eDumpGroupValue)); |
| 304 | if (error.Success()) { |
| 305 | result.GetOutputStream().EOL(); |
| 306 | } else { |
| 307 | result.AppendError(error.AsCString()); |
| 308 | result.SetStatus(eReturnStatusFailed); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 309 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 310 | } |
| 311 | } else { |
| 312 | m_interpreter.GetDebugger().DumpAllPropertyValues( |
| 313 | &m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 314 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 315 | |
| 316 | return result.Succeeded(); |
| 317 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | //------------------------------------------------------------------------- |
| 321 | // CommandObjectSettingsList -- List settable variables |
| 322 | //------------------------------------------------------------------------- |
| 323 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 324 | class CommandObjectSettingsList : public CommandObjectParsed { |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 325 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | CommandObjectSettingsList(CommandInterpreter &interpreter) |
| 327 | : CommandObjectParsed(interpreter, "settings list", |
| 328 | "List and describe matching debugger settings. " |
| 329 | "Defaults to all listing all settings.", |
| 330 | nullptr) { |
| 331 | CommandArgumentEntry arg; |
| 332 | CommandArgumentData var_name_arg; |
| 333 | CommandArgumentData prefix_name_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 334 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | // Define the first variant of this arg. |
| 336 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 337 | var_name_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 338 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 339 | // Define the second variant of this arg. |
| 340 | prefix_name_arg.arg_type = eArgTypeSettingPrefix; |
| 341 | prefix_name_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 342 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 343 | arg.push_back(var_name_arg); |
| 344 | arg.push_back(prefix_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 345 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 346 | // Push the data for the first argument into the m_arguments vector. |
| 347 | m_arguments.push_back(arg); |
| 348 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 349 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | ~CommandObjectSettingsList() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 351 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 352 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 353 | int &cursor_char_position, |
| 354 | OptionElementVector &opt_element_vector, |
| 355 | int match_start_point, int max_return_elements, |
| 356 | bool &word_complete, |
| 357 | StringList &matches) override { |
| 358 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 359 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 360 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 362 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 363 | completion_str.c_str(), match_start_point, max_return_elements, nullptr, |
| 364 | word_complete, matches); |
| 365 | return matches.GetSize(); |
| 366 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 367 | |
| 368 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 369 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 370 | result.SetStatus(eReturnStatusSuccessFinishResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 371 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 372 | const bool will_modify = false; |
| 373 | const size_t argc = args.GetArgumentCount(); |
| 374 | if (argc > 0) { |
| 375 | const bool dump_qualified_name = true; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 376 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 377 | for (size_t i = 0; i < argc; ++i) { |
| 378 | const char *property_path = args.GetArgumentAtIndex(i); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 379 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 380 | const Property *property = |
| 381 | m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath( |
| 382 | &m_exe_ctx, will_modify, property_path); |
| 383 | |
| 384 | if (property) { |
| 385 | property->DumpDescription(m_interpreter, result.GetOutputStream(), 0, |
| 386 | dump_qualified_name); |
| 387 | } else { |
| 388 | result.AppendErrorWithFormat("invalid property path '%s'", |
| 389 | property_path); |
| 390 | result.SetStatus(eReturnStatusFailed); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 391 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 392 | } |
| 393 | } else { |
| 394 | m_interpreter.GetDebugger().DumpAllDescriptions(m_interpreter, |
| 395 | result.GetOutputStream()); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 396 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 397 | |
| 398 | return result.Succeeded(); |
| 399 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | //------------------------------------------------------------------------- |
| 403 | // CommandObjectSettingsRemove |
| 404 | //------------------------------------------------------------------------- |
| 405 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 406 | class CommandObjectSettingsRemove : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 407 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 408 | CommandObjectSettingsRemove(CommandInterpreter &interpreter) |
| 409 | : CommandObjectRaw(interpreter, "settings remove", |
| 410 | "Remove a value from a setting, specified by array " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 411 | "index or dictionary key.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | CommandArgumentEntry arg1; |
| 413 | CommandArgumentEntry arg2; |
| 414 | CommandArgumentData var_name_arg; |
| 415 | CommandArgumentData index_arg; |
| 416 | CommandArgumentData key_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 417 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | // Define the first (and only) variant of this arg. |
| 419 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 420 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 421 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 422 | // There is only one variant this argument could be; put it into the |
| 423 | // argument entry. |
| 424 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 425 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 426 | // Define the first variant of this arg. |
| 427 | index_arg.arg_type = eArgTypeSettingIndex; |
| 428 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 429 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 430 | // Define the second variant of this arg. |
| 431 | key_arg.arg_type = eArgTypeSettingKey; |
| 432 | key_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 433 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 434 | // Push both variants into this arg |
| 435 | arg2.push_back(index_arg); |
| 436 | arg2.push_back(key_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 437 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 438 | // Push the data for the first argument into the m_arguments vector. |
| 439 | m_arguments.push_back(arg1); |
| 440 | m_arguments.push_back(arg2); |
| 441 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 442 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | ~CommandObjectSettingsRemove() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 444 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 446 | int &cursor_char_position, |
| 447 | OptionElementVector &opt_element_vector, |
| 448 | int match_start_point, int max_return_elements, |
| 449 | bool &word_complete, |
| 450 | StringList &matches) override { |
| 451 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 452 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 453 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 454 | // Attempting to complete variable name |
| 455 | if (cursor_index < 2) |
| 456 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 457 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 458 | completion_str.c_str(), match_start_point, max_return_elements, |
| 459 | nullptr, word_complete, matches); |
| 460 | return matches.GetSize(); |
| 461 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 462 | |
| 463 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 464 | bool DoExecute(const char *command, CommandReturnObject &result) override { |
| 465 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 466 | |
| 467 | Args cmd_args(command); |
| 468 | |
| 469 | // Process possible options. |
| 470 | if (!ParseOptions(cmd_args, result)) |
| 471 | return false; |
| 472 | |
| 473 | const size_t argc = cmd_args.GetArgumentCount(); |
| 474 | if (argc == 0) { |
| 475 | result.AppendError("'settings set' takes an array or dictionary item, or " |
| 476 | "an array followed by one or more indexes, or a " |
| 477 | "dictionary followed by one or more key names to " |
| 478 | "remove"); |
| 479 | result.SetStatus(eReturnStatusFailed); |
| 480 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 481 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | |
| 483 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 484 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 485 | result.AppendError( |
| 486 | "'settings set' command requires a valid variable name"); |
| 487 | result.SetStatus(eReturnStatusFailed); |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | // Split the raw command into var_name and value pair. |
| 492 | llvm::StringRef raw_str(command); |
| 493 | std::string var_value_string = raw_str.split(var_name).second.str(); |
| 494 | const char *var_value_cstr = |
| 495 | Args::StripSpaces(var_value_string, true, true, false); |
| 496 | |
| 497 | Error error(m_interpreter.GetDebugger().SetPropertyValue( |
| 498 | &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr)); |
| 499 | if (error.Fail()) { |
| 500 | result.AppendError(error.AsCString()); |
| 501 | result.SetStatus(eReturnStatusFailed); |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | return result.Succeeded(); |
| 506 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | //------------------------------------------------------------------------- |
| 510 | // CommandObjectSettingsReplace |
| 511 | //------------------------------------------------------------------------- |
| 512 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | class CommandObjectSettingsReplace : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 514 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 515 | CommandObjectSettingsReplace(CommandInterpreter &interpreter) |
| 516 | : CommandObjectRaw(interpreter, "settings replace", |
| 517 | "Replace the debugger setting value specified by " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 518 | "array index or dictionary key.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 519 | CommandArgumentEntry arg1; |
| 520 | CommandArgumentEntry arg2; |
| 521 | CommandArgumentEntry arg3; |
| 522 | CommandArgumentData var_name_arg; |
| 523 | CommandArgumentData index_arg; |
| 524 | CommandArgumentData key_arg; |
| 525 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 526 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 527 | // Define the first (and only) variant of this arg. |
| 528 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 529 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 530 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 531 | // There is only one variant this argument could be; put it into the |
| 532 | // argument entry. |
| 533 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 534 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 535 | // Define the first (variant of this arg. |
| 536 | index_arg.arg_type = eArgTypeSettingIndex; |
| 537 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 538 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 539 | // Define the second (variant of this arg. |
| 540 | key_arg.arg_type = eArgTypeSettingKey; |
| 541 | key_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 542 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | // Put both variants into this arg |
| 544 | arg2.push_back(index_arg); |
| 545 | arg2.push_back(key_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 546 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 547 | // Define the first (and only) variant of this arg. |
| 548 | value_arg.arg_type = eArgTypeValue; |
| 549 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 550 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 551 | // There is only one variant this argument could be; put it into the |
| 552 | // argument entry. |
| 553 | arg3.push_back(value_arg); |
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 | // Push the data for the first argument into the m_arguments vector. |
| 556 | m_arguments.push_back(arg1); |
| 557 | m_arguments.push_back(arg2); |
| 558 | m_arguments.push_back(arg3); |
| 559 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 560 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 561 | ~CommandObjectSettingsReplace() override = default; |
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 | // Overrides base class's behavior where WantsCompletion = |
| 564 | // !WantsRawCommandString. |
| 565 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 566 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 568 | int &cursor_char_position, |
| 569 | OptionElementVector &opt_element_vector, |
| 570 | int match_start_point, int max_return_elements, |
| 571 | bool &word_complete, |
| 572 | StringList &matches) override { |
| 573 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 574 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 575 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 576 | // Attempting to complete variable name |
| 577 | if (cursor_index < 2) |
| 578 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 579 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 580 | completion_str.c_str(), match_start_point, max_return_elements, |
| 581 | nullptr, word_complete, matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 582 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 583 | return matches.GetSize(); |
| 584 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 585 | |
| 586 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 587 | bool DoExecute(const char *command, CommandReturnObject &result) override { |
| 588 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 589 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 590 | Args cmd_args(command); |
| 591 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 592 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 593 | result.AppendError("'settings replace' command requires a valid variable " |
| 594 | "name; No value supplied"); |
| 595 | result.SetStatus(eReturnStatusFailed); |
| 596 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 597 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 598 | |
| 599 | // Split the raw command into var_name, index_value, and value triple. |
| 600 | llvm::StringRef raw_str(command); |
| 601 | std::string var_value_string = raw_str.split(var_name).second.str(); |
| 602 | const char *var_value_cstr = |
| 603 | Args::StripSpaces(var_value_string, true, true, false); |
| 604 | |
| 605 | Error error(m_interpreter.GetDebugger().SetPropertyValue( |
| 606 | &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr)); |
| 607 | if (error.Fail()) { |
| 608 | result.AppendError(error.AsCString()); |
| 609 | result.SetStatus(eReturnStatusFailed); |
| 610 | return false; |
| 611 | } else { |
| 612 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 613 | } |
| 614 | |
| 615 | return result.Succeeded(); |
| 616 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 617 | }; |
| 618 | |
| 619 | //------------------------------------------------------------------------- |
| 620 | // CommandObjectSettingsInsertBefore |
| 621 | //------------------------------------------------------------------------- |
| 622 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 623 | class CommandObjectSettingsInsertBefore : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 624 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 625 | CommandObjectSettingsInsertBefore(CommandInterpreter &interpreter) |
| 626 | : CommandObjectRaw(interpreter, "settings insert-before", |
| 627 | "Insert one or more values into an debugger array " |
| 628 | "setting immediately before the specified element " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 629 | "index.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 630 | CommandArgumentEntry arg1; |
| 631 | CommandArgumentEntry arg2; |
| 632 | CommandArgumentEntry arg3; |
| 633 | CommandArgumentData var_name_arg; |
| 634 | CommandArgumentData index_arg; |
| 635 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 637 | // Define the first (and only) variant of this arg. |
| 638 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 639 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 640 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 641 | // There is only one variant this argument could be; put it into the |
| 642 | // argument entry. |
| 643 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 644 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 645 | // Define the first (variant of this arg. |
| 646 | index_arg.arg_type = eArgTypeSettingIndex; |
| 647 | index_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 648 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 649 | // There is only one variant this argument could be; put it into the |
| 650 | // argument entry. |
| 651 | arg2.push_back(index_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 652 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 653 | // Define the first (and only) variant of this arg. |
| 654 | value_arg.arg_type = eArgTypeValue; |
| 655 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 656 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 657 | // There is only one variant this argument could be; put it into the |
| 658 | // argument entry. |
| 659 | arg3.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 660 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 661 | // Push the data for the first argument into the m_arguments vector. |
| 662 | m_arguments.push_back(arg1); |
| 663 | m_arguments.push_back(arg2); |
| 664 | m_arguments.push_back(arg3); |
| 665 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 666 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 667 | ~CommandObjectSettingsInsertBefore() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 668 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 669 | // Overrides base class's behavior where WantsCompletion = |
| 670 | // !WantsRawCommandString. |
| 671 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 672 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 673 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 674 | int &cursor_char_position, |
| 675 | OptionElementVector &opt_element_vector, |
| 676 | int match_start_point, int max_return_elements, |
| 677 | bool &word_complete, |
| 678 | StringList &matches) override { |
| 679 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 680 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 681 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 682 | // Attempting to complete variable name |
| 683 | if (cursor_index < 2) |
| 684 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 685 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 686 | completion_str.c_str(), match_start_point, max_return_elements, |
| 687 | nullptr, word_complete, matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 688 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 689 | return matches.GetSize(); |
| 690 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 691 | |
| 692 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 693 | bool DoExecute(const char *command, CommandReturnObject &result) override { |
| 694 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | Args cmd_args(command); |
| 697 | const size_t argc = cmd_args.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 698 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 699 | if (argc < 3) { |
| 700 | result.AppendError("'settings insert-before' takes more arguments"); |
| 701 | result.SetStatus(eReturnStatusFailed); |
| 702 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 703 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 704 | |
| 705 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 706 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 707 | result.AppendError("'settings insert-before' command requires a valid " |
| 708 | "variable name; No value supplied"); |
| 709 | result.SetStatus(eReturnStatusFailed); |
| 710 | return false; |
| 711 | } |
| 712 | |
| 713 | // Split the raw command into var_name, index_value, and value triple. |
| 714 | llvm::StringRef raw_str(command); |
| 715 | std::string var_value_string = raw_str.split(var_name).second.str(); |
| 716 | const char *var_value_cstr = |
| 717 | Args::StripSpaces(var_value_string, true, true, false); |
| 718 | |
| 719 | Error error(m_interpreter.GetDebugger().SetPropertyValue( |
| 720 | &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr)); |
| 721 | if (error.Fail()) { |
| 722 | result.AppendError(error.AsCString()); |
| 723 | result.SetStatus(eReturnStatusFailed); |
| 724 | return false; |
| 725 | } |
| 726 | |
| 727 | return result.Succeeded(); |
| 728 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | //------------------------------------------------------------------------- |
| 732 | // CommandObjectSettingInsertAfter |
| 733 | //------------------------------------------------------------------------- |
| 734 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 735 | class CommandObjectSettingsInsertAfter : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 736 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 737 | CommandObjectSettingsInsertAfter(CommandInterpreter &interpreter) |
| 738 | : CommandObjectRaw(interpreter, "settings insert-after", |
| 739 | "Insert one or more values into a debugger array " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 740 | "settings after the specified element index.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 741 | CommandArgumentEntry arg1; |
| 742 | CommandArgumentEntry arg2; |
| 743 | CommandArgumentEntry arg3; |
| 744 | CommandArgumentData var_name_arg; |
| 745 | CommandArgumentData index_arg; |
| 746 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 747 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 748 | // Define the first (and only) variant of this arg. |
| 749 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 750 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 751 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 752 | // There is only one variant this argument could be; put it into the |
| 753 | // argument entry. |
| 754 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 755 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 756 | // Define the first (variant of this arg. |
| 757 | index_arg.arg_type = eArgTypeSettingIndex; |
| 758 | index_arg.arg_repetition = eArgRepeatPlain; |
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 | // There is only one variant this argument could be; put it into the |
| 761 | // argument entry. |
| 762 | arg2.push_back(index_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 763 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 764 | // Define the first (and only) variant of this arg. |
| 765 | value_arg.arg_type = eArgTypeValue; |
| 766 | value_arg.arg_repetition = eArgRepeatPlain; |
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 | // There is only one variant this argument could be; put it into the |
| 769 | // argument entry. |
| 770 | arg3.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 771 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 772 | // Push the data for the first argument into the m_arguments vector. |
| 773 | m_arguments.push_back(arg1); |
| 774 | m_arguments.push_back(arg2); |
| 775 | m_arguments.push_back(arg3); |
| 776 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 777 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 778 | ~CommandObjectSettingsInsertAfter() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 779 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 780 | // Overrides base class's behavior where WantsCompletion = |
| 781 | // !WantsRawCommandString. |
| 782 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 783 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 784 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 785 | int &cursor_char_position, |
| 786 | OptionElementVector &opt_element_vector, |
| 787 | int match_start_point, int max_return_elements, |
| 788 | bool &word_complete, |
| 789 | StringList &matches) override { |
| 790 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 791 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 792 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 793 | // Attempting to complete variable name |
| 794 | if (cursor_index < 2) |
| 795 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 796 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 797 | completion_str.c_str(), match_start_point, max_return_elements, |
| 798 | nullptr, word_complete, matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 799 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 800 | return matches.GetSize(); |
| 801 | } |
| 802 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 803 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 804 | bool DoExecute(const char *command, CommandReturnObject &result) override { |
| 805 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 806 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 807 | Args cmd_args(command); |
| 808 | const size_t argc = cmd_args.GetArgumentCount(); |
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 | if (argc < 3) { |
| 811 | result.AppendError("'settings insert-after' takes more arguments"); |
| 812 | result.SetStatus(eReturnStatusFailed); |
| 813 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 814 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 815 | |
| 816 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 817 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 818 | result.AppendError("'settings insert-after' command requires a valid " |
| 819 | "variable name; No value supplied"); |
| 820 | result.SetStatus(eReturnStatusFailed); |
| 821 | return false; |
| 822 | } |
| 823 | |
| 824 | // Split the raw command into var_name, index_value, and value triple. |
| 825 | llvm::StringRef raw_str(command); |
| 826 | std::string var_value_string = raw_str.split(var_name).second.str(); |
| 827 | const char *var_value_cstr = |
| 828 | Args::StripSpaces(var_value_string, true, true, false); |
| 829 | |
| 830 | Error error(m_interpreter.GetDebugger().SetPropertyValue( |
| 831 | &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr)); |
| 832 | if (error.Fail()) { |
| 833 | result.AppendError(error.AsCString()); |
| 834 | result.SetStatus(eReturnStatusFailed); |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | return result.Succeeded(); |
| 839 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 840 | }; |
| 841 | |
| 842 | //------------------------------------------------------------------------- |
| 843 | // CommandObjectSettingsAppend |
| 844 | //------------------------------------------------------------------------- |
| 845 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 846 | class CommandObjectSettingsAppend : public CommandObjectRaw { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 847 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 848 | CommandObjectSettingsAppend(CommandInterpreter &interpreter) |
| 849 | : CommandObjectRaw(interpreter, "settings append", |
| 850 | "Append one or more values to a debugger array, " |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 851 | "dictionary, or string setting.") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 852 | CommandArgumentEntry arg1; |
| 853 | CommandArgumentEntry arg2; |
| 854 | CommandArgumentData var_name_arg; |
| 855 | CommandArgumentData value_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 856 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 857 | // Define the first (and only) variant of this arg. |
| 858 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 859 | var_name_arg.arg_repetition = eArgRepeatPlain; |
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 | // There is only one variant this argument could be; put it into the |
| 862 | // argument entry. |
| 863 | arg1.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 864 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 865 | // Define the first (and only) variant of this arg. |
| 866 | value_arg.arg_type = eArgTypeValue; |
| 867 | value_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 868 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 869 | // There is only one variant this argument could be; put it into the |
| 870 | // argument entry. |
| 871 | arg2.push_back(value_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 872 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 873 | // Push the data for the first argument into the m_arguments vector. |
| 874 | m_arguments.push_back(arg1); |
| 875 | m_arguments.push_back(arg2); |
| 876 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 877 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 878 | ~CommandObjectSettingsAppend() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 879 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 880 | // Overrides base class's behavior where WantsCompletion = |
| 881 | // !WantsRawCommandString. |
| 882 | bool WantsCompletion() override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 883 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 885 | int &cursor_char_position, |
| 886 | OptionElementVector &opt_element_vector, |
| 887 | int match_start_point, int max_return_elements, |
| 888 | bool &word_complete, |
| 889 | StringList &matches) override { |
| 890 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 891 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 892 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 893 | // Attempting to complete variable name |
| 894 | if (cursor_index < 2) |
| 895 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 896 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 897 | completion_str.c_str(), match_start_point, max_return_elements, |
| 898 | nullptr, word_complete, matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 899 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 900 | return matches.GetSize(); |
| 901 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 902 | |
| 903 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | bool DoExecute(const char *command, CommandReturnObject &result) override { |
| 905 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 906 | Args cmd_args(command); |
| 907 | const size_t argc = cmd_args.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 908 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 909 | if (argc < 2) { |
| 910 | result.AppendError("'settings append' takes more arguments"); |
| 911 | result.SetStatus(eReturnStatusFailed); |
| 912 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 913 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 914 | |
| 915 | const char *var_name = cmd_args.GetArgumentAtIndex(0); |
| 916 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 917 | result.AppendError("'settings append' command requires a valid variable " |
| 918 | "name; No value supplied"); |
| 919 | result.SetStatus(eReturnStatusFailed); |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | // Do not perform cmd_args.Shift() since StringRef is manipulating the |
| 924 | // raw character string later on. |
| 925 | |
| 926 | // Split the raw command into var_name and value pair. |
| 927 | llvm::StringRef raw_str(command); |
| 928 | std::string var_value_string = raw_str.split(var_name).second.str(); |
| 929 | const char *var_value_cstr = |
| 930 | Args::StripSpaces(var_value_string, true, true, false); |
| 931 | |
| 932 | Error error(m_interpreter.GetDebugger().SetPropertyValue( |
| 933 | &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr)); |
| 934 | if (error.Fail()) { |
| 935 | result.AppendError(error.AsCString()); |
| 936 | result.SetStatus(eReturnStatusFailed); |
| 937 | return false; |
| 938 | } |
| 939 | |
| 940 | return result.Succeeded(); |
| 941 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 942 | }; |
| 943 | |
| 944 | //------------------------------------------------------------------------- |
| 945 | // CommandObjectSettingsClear |
| 946 | //------------------------------------------------------------------------- |
| 947 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 948 | class CommandObjectSettingsClear : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 949 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 950 | CommandObjectSettingsClear(CommandInterpreter &interpreter) |
| 951 | : CommandObjectParsed( |
| 952 | interpreter, "settings clear", |
| 953 | "Clear a debugger setting array, dictionary, or string.", nullptr) { |
| 954 | CommandArgumentEntry arg; |
| 955 | CommandArgumentData var_name_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 956 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 957 | // Define the first (and only) variant of this arg. |
| 958 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 959 | var_name_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 960 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 961 | // There is only one variant this argument could be; put it into the |
| 962 | // argument entry. |
| 963 | arg.push_back(var_name_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 964 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 965 | // Push the data for the first argument into the m_arguments vector. |
| 966 | m_arguments.push_back(arg); |
| 967 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 968 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 969 | ~CommandObjectSettingsClear() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 970 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 971 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 972 | int &cursor_char_position, |
| 973 | OptionElementVector &opt_element_vector, |
| 974 | int match_start_point, int max_return_elements, |
| 975 | bool &word_complete, |
| 976 | StringList &matches) override { |
| 977 | std::string completion_str(input.GetArgumentAtIndex(cursor_index), |
| 978 | cursor_char_position); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 979 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 980 | // Attempting to complete variable name |
| 981 | if (cursor_index < 2) |
| 982 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 983 | GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, |
| 984 | completion_str.c_str(), match_start_point, max_return_elements, |
| 985 | nullptr, word_complete, matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 986 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 987 | return matches.GetSize(); |
| 988 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 989 | |
| 990 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 991 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 992 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 993 | const size_t argc = command.GetArgumentCount(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 994 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | if (argc != 1) { |
| 996 | result.AppendError("'settings clear' takes exactly one argument"); |
| 997 | result.SetStatus(eReturnStatusFailed); |
| 998 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 999 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1000 | |
| 1001 | const char *var_name = command.GetArgumentAtIndex(0); |
| 1002 | if ((var_name == nullptr) || (var_name[0] == '\0')) { |
| 1003 | result.AppendError("'settings clear' command requires a valid variable " |
| 1004 | "name; No value supplied"); |
| 1005 | result.SetStatus(eReturnStatusFailed); |
| 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | Error error(m_interpreter.GetDebugger().SetPropertyValue( |
| 1010 | &m_exe_ctx, eVarSetOperationClear, var_name, nullptr)); |
| 1011 | if (error.Fail()) { |
| 1012 | result.AppendError(error.AsCString()); |
| 1013 | result.SetStatus(eReturnStatusFailed); |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
| 1017 | return result.Succeeded(); |
| 1018 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1019 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1020 | |
| 1021 | //------------------------------------------------------------------------- |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1022 | // CommandObjectMultiwordSettings |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | //------------------------------------------------------------------------- |
| 1024 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1025 | CommandObjectMultiwordSettings::CommandObjectMultiwordSettings( |
| 1026 | CommandInterpreter &interpreter) |
| 1027 | : CommandObjectMultiword(interpreter, "settings", |
| 1028 | "Commands for managing LLDB settings.", |
| 1029 | "settings <subcommand> [<command-options>]") { |
| 1030 | LoadSubCommand("set", |
| 1031 | CommandObjectSP(new CommandObjectSettingsSet(interpreter))); |
| 1032 | LoadSubCommand("show", |
| 1033 | CommandObjectSP(new CommandObjectSettingsShow(interpreter))); |
| 1034 | LoadSubCommand("list", |
| 1035 | CommandObjectSP(new CommandObjectSettingsList(interpreter))); |
| 1036 | LoadSubCommand("remove", |
| 1037 | CommandObjectSP(new CommandObjectSettingsRemove(interpreter))); |
| 1038 | LoadSubCommand("replace", CommandObjectSP( |
| 1039 | new CommandObjectSettingsReplace(interpreter))); |
| 1040 | LoadSubCommand( |
| 1041 | "insert-before", |
| 1042 | CommandObjectSP(new CommandObjectSettingsInsertBefore(interpreter))); |
| 1043 | LoadSubCommand( |
| 1044 | "insert-after", |
| 1045 | CommandObjectSP(new CommandObjectSettingsInsertAfter(interpreter))); |
| 1046 | LoadSubCommand("append", |
| 1047 | CommandObjectSP(new CommandObjectSettingsAppend(interpreter))); |
| 1048 | LoadSubCommand("clear", |
| 1049 | CommandObjectSP(new CommandObjectSettingsClear(interpreter))); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Eugene Zelenko | 3f18ea0 | 2016-02-24 02:05:55 +0000 | [diff] [blame] | 1052 | CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings() = default; |