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