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