Chris Lattner | 24943d2 | 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 |
| 15 | // Project includes |
| 16 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 17 | #include "lldb/Interpreter/CommandReturnObject.h" |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandCompletions.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | //------------------------------------------------------------------------- |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 24 | // CommandObjectMultiwordSettings |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | //------------------------------------------------------------------------- |
| 26 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 27 | CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 28 | CommandObjectMultiword (interpreter, |
| 29 | "settings", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 30 | "A set of commands for manipulating internal settable debugger variables.", |
| 31 | "settings <command> [<command-options>]") |
| 32 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 33 | LoadSubCommand ("set", CommandObjectSP (new CommandObjectSettingsSet (interpreter))); |
| 34 | LoadSubCommand ("show", CommandObjectSP (new CommandObjectSettingsShow (interpreter))); |
| 35 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectSettingsList (interpreter))); |
| 36 | LoadSubCommand ("remove", CommandObjectSP (new CommandObjectSettingsRemove (interpreter))); |
| 37 | LoadSubCommand ("replace", CommandObjectSP (new CommandObjectSettingsReplace (interpreter))); |
| 38 | LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter))); |
| 39 | LoadSubCommand ("insert-after", CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter))); |
| 40 | LoadSubCommand ("append", CommandObjectSP (new CommandObjectSettingsAppend (interpreter))); |
| 41 | LoadSubCommand ("clear", CommandObjectSP (new CommandObjectSettingsClear (interpreter))); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 48 | //------------------------------------------------------------------------- |
| 49 | // CommandObjectSettingsSet |
| 50 | //------------------------------------------------------------------------- |
| 51 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 52 | CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpreter) : |
| 53 | CommandObject (interpreter, |
| 54 | "settings set", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 55 | "Set or change the value of a single debugger setting variable.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 56 | NULL), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 57 | m_options (interpreter) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 58 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 59 | CommandArgumentEntry arg1; |
| 60 | CommandArgumentEntry arg2; |
| 61 | CommandArgumentData var_name_arg; |
| 62 | CommandArgumentData value_arg; |
| 63 | |
| 64 | // Define the first (and only) variant of this arg. |
| 65 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 66 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 67 | |
| 68 | // There is only one variant this argument could be; put it into the argument entry. |
| 69 | arg1.push_back (var_name_arg); |
| 70 | |
| 71 | // Define the first (and only) variant of this arg. |
| 72 | value_arg.arg_type = eArgTypeValue; |
| 73 | value_arg.arg_repetition = eArgRepeatPlain; |
| 74 | |
| 75 | // There is only one variant this argument could be; put it into the argument entry. |
| 76 | arg2.push_back (value_arg); |
| 77 | |
| 78 | // Push the data for the first argument into the m_arguments vector. |
| 79 | m_arguments.push_back (arg1); |
| 80 | m_arguments.push_back (arg2); |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 81 | |
| 82 | SetHelpLong ( |
| 83 | "When setting a dictionary or array variable, you can set multiple entries \n\ |
| 84 | at once by giving the values to the set command. For example: \n\ |
| 85 | \n\ |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 86 | (lldb) settings set target.run-args value1 value2 value3 \n\ |
| 87 | (lldb) settings set target.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\ |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 88 | \n\ |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 89 | (lldb) settings show target.run-args \n\ |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 90 | [0]: 'value1' \n\ |
| 91 | [1]: 'value2' \n\ |
| 92 | [3]: 'value3' \n\ |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 93 | (lldb) settings show target.env-vars \n\ |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 94 | 'MYPATH=~/.:/usr/bin'\n\ |
| 95 | 'SOME_ENV_VAR=12345' \n\ |
| 96 | \n\ |
| 97 | Note the special syntax for setting a dictionary element: [\"<key>\"]=<value> \n\ |
| 98 | \n\ |
| 99 | Warning: The 'set' command re-sets the entire array or dictionary. If you \n\ |
| 100 | just want to add, remove or update individual values (or add something to \n\ |
| 101 | the end), use one of the other settings sub-commands: append, replace, \n\ |
| 102 | insert-before or insert-after.\n"); |
| 103 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | CommandObjectSettingsSet::~CommandObjectSettingsSet() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | { |
| 108 | } |
| 109 | |
| 110 | |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 111 | #include "llvm/ADT/StringRef.h" |
| 112 | static inline void StripLeadingSpaces(llvm::StringRef &Str) |
| 113 | { |
| 114 | while (!Str.empty() && isspace(Str[0])) |
| 115 | Str = Str.substr(1); |
| 116 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 117 | bool |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 118 | CommandObjectSettingsSet::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 120 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 122 | Args cmd_args(raw_command); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 123 | |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 124 | // Process possible options. |
| 125 | if (!ParseOptions (cmd_args, result)) |
| 126 | return false; |
| 127 | |
| 128 | const int argc = cmd_args.GetArgumentCount (); |
Caroline Tice | 8709723 | 2010-09-07 18:35:40 +0000 | [diff] [blame] | 129 | if ((argc < 2) && (!m_options.m_reset)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | { |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 131 | result.AppendError ("'settings set' takes more arguments"); |
| 132 | result.SetStatus (eReturnStatusFailed); |
| 133 | return false; |
| 134 | } |
| 135 | |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 136 | const char *var_name = cmd_args.GetArgumentAtIndex (0); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 137 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 138 | { |
| 139 | result.AppendError ("'settings set' command requires a valid variable name; No value supplied"); |
| 140 | result.SetStatus (eReturnStatusFailed); |
| 141 | return false; |
| 142 | } |
| 143 | |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 144 | // Split the raw command into var_name and value pair. |
| 145 | std::string var_name_string = var_name; |
| 146 | llvm::StringRef raw_str(raw_command); |
| 147 | llvm::StringRef value_str = raw_str.split(var_name_string).second; |
| 148 | StripLeadingSpaces(value_str); |
| 149 | std::string value_string = value_str.str(); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 150 | |
| 151 | if (!m_options.m_reset |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 152 | && value_string.empty()) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 153 | { |
| 154 | result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;" |
| 155 | " No value supplied"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | result.SetStatus (eReturnStatusFailed); |
| 157 | } |
| 158 | else |
| 159 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 160 | Error err = usc_sp->SetVariable (var_name_string.c_str(), |
Johnny Chen | a1b0ce1 | 2012-01-19 19:22:41 +0000 | [diff] [blame] | 161 | value_string.c_str(), |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 162 | eVarSetOperationAssign, |
| 163 | m_options.m_override, |
| 164 | m_interpreter.GetDebugger().GetInstanceName().AsCString()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 165 | if (err.Fail ()) |
| 166 | { |
| 167 | result.AppendError (err.AsCString()); |
| 168 | result.SetStatus (eReturnStatusFailed); |
| 169 | } |
| 170 | else |
| 171 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 172 | } |
| 173 | |
| 174 | return result.Succeeded(); |
| 175 | } |
| 176 | |
| 177 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 178 | CommandObjectSettingsSet::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 179 | int &cursor_index, |
| 180 | int &cursor_char_position, |
| 181 | OptionElementVector &opt_element_vector, |
| 182 | int match_start_point, |
| 183 | int max_return_elements, |
| 184 | bool &word_complete, |
| 185 | StringList &matches) |
| 186 | { |
| 187 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 188 | completion_str.erase (cursor_char_position); |
| 189 | |
| 190 | // Attempting to complete variable name |
| 191 | if (cursor_index == 1) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 192 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 193 | CommandCompletions::eSettingsNameCompletion, |
| 194 | completion_str.c_str(), |
| 195 | match_start_point, |
| 196 | max_return_elements, |
| 197 | NULL, |
| 198 | word_complete, |
| 199 | matches); |
| 200 | |
| 201 | // Attempting to complete value |
| 202 | if ((cursor_index == 2) // Partly into the variable's value |
| 203 | || (cursor_index == 1 // Or at the end of a completed valid variable name |
| 204 | && matches.GetSize() == 1 |
| 205 | && completion_str.compare (matches.GetStringAtIndex(0)) == 0)) |
| 206 | { |
| 207 | matches.Clear(); |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 208 | UserSettingsControllerSP usc_sp = Debugger::GetSettingsController(); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 209 | if (cursor_index == 1) |
| 210 | { |
| 211 | // The user is at the end of the variable name, which is complete and valid. |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 212 | UserSettingsController::CompleteSettingsValue (usc_sp, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 213 | input.GetArgumentAtIndex (1), // variable name |
| 214 | NULL, // empty value string |
| 215 | word_complete, |
| 216 | matches); |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | // The user is partly into the variable value. |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 221 | UserSettingsController::CompleteSettingsValue (usc_sp, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 222 | input.GetArgumentAtIndex (1), // variable name |
| 223 | completion_str.c_str(), // partial value string |
| 224 | word_complete, |
| 225 | matches); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return matches.GetSize(); |
| 230 | } |
| 231 | |
| 232 | //------------------------------------------------------------------------- |
| 233 | // CommandObjectSettingsSet::CommandOptions |
| 234 | //------------------------------------------------------------------------- |
| 235 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 236 | CommandObjectSettingsSet::CommandOptions::CommandOptions (CommandInterpreter &interpreter) : |
| 237 | Options (interpreter), |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 238 | m_override (true), |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 239 | m_reset (false) |
| 240 | { |
| 241 | } |
| 242 | |
| 243 | CommandObjectSettingsSet::CommandOptions::~CommandOptions () |
| 244 | { |
| 245 | } |
| 246 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 247 | OptionDefinition |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 248 | CommandObjectSettingsSet::CommandOptions::g_option_table[] = |
| 249 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 250 | { LLDB_OPT_SET_1, false, "no-override", 'n', no_argument, NULL, NULL, eArgTypeNone, "Prevents already existing instances and pending settings from being assigned this new value. Using this option means that only the default or specified instance setting values will be updated." }, |
| 251 | { LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, eArgTypeNone, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." }, |
| 252 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 255 | const OptionDefinition* |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 256 | CommandObjectSettingsSet::CommandOptions::GetDefinitions () |
| 257 | { |
| 258 | return g_option_table; |
| 259 | } |
| 260 | |
| 261 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 262 | CommandObjectSettingsSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 263 | { |
| 264 | Error error; |
| 265 | char short_option = (char) m_getopt_table[option_idx].val; |
| 266 | |
| 267 | switch (short_option) |
| 268 | { |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 269 | case 'n': |
| 270 | m_override = false; |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 271 | break; |
| 272 | case 'r': |
| 273 | m_reset = true; |
| 274 | break; |
| 275 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 276 | error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 277 | break; |
| 278 | } |
| 279 | |
| 280 | return error; |
| 281 | } |
| 282 | |
| 283 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 284 | CommandObjectSettingsSet::CommandOptions::OptionParsingStarting () |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 285 | { |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 286 | m_override = true; |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 287 | m_reset = false; |
| 288 | } |
| 289 | |
| 290 | Options * |
| 291 | CommandObjectSettingsSet::GetOptions () |
| 292 | { |
| 293 | return &m_options; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | //------------------------------------------------------------------------- |
| 298 | // CommandObjectSettingsShow -- Show current values |
| 299 | //------------------------------------------------------------------------- |
| 300 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 301 | CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) : |
| 302 | CommandObject (interpreter, |
| 303 | "settings show", |
| 304 | "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 305 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 306 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 307 | CommandArgumentEntry arg1; |
| 308 | CommandArgumentData var_name_arg; |
| 309 | |
| 310 | // Define the first (and only) variant of this arg. |
| 311 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 312 | var_name_arg.arg_repetition = eArgRepeatOptional; |
| 313 | |
| 314 | // There is only one variant this argument could be; put it into the argument entry. |
| 315 | arg1.push_back (var_name_arg); |
| 316 | |
| 317 | // Push the data for the first argument into the m_arguments vector. |
| 318 | m_arguments.push_back (arg1); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | CommandObjectSettingsShow::~CommandObjectSettingsShow() |
| 322 | { |
| 323 | } |
| 324 | |
| 325 | |
| 326 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 327 | CommandObjectSettingsShow::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 328 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 329 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
| 330 | const char *current_prefix = usc_sp->GetLevelName().GetCString(); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 331 | |
| 332 | Error err; |
| 333 | |
| 334 | if (command.GetArgumentCount()) |
| 335 | { |
| 336 | // The user requested to see the value of a particular variable. |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 337 | SettableVariableType var_type; |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 338 | const char *variable_name = command.GetArgumentAtIndex (0); |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 339 | StringList value = usc_sp->GetVariable (variable_name, |
| 340 | var_type, |
| 341 | m_interpreter.GetDebugger().GetInstanceName().AsCString(), |
| 342 | err); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 343 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 344 | if (err.Fail ()) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 345 | { |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 346 | result.AppendError (err.AsCString()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 347 | result.SetStatus (eReturnStatusFailed); |
| 348 | |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 349 | } |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 350 | else |
| 351 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 352 | UserSettingsController::DumpValue(m_interpreter, usc_sp, variable_name, result.GetOutputStream()); |
| 353 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | else |
| 357 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 358 | UserSettingsController::GetAllVariableValues (m_interpreter, |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 359 | usc_sp, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 360 | current_prefix, |
| 361 | result.GetOutputStream(), |
| 362 | err); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 363 | if (err.Fail ()) |
| 364 | { |
| 365 | result.AppendError (err.AsCString()); |
| 366 | result.SetStatus (eReturnStatusFailed); |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return result.Succeeded(); |
| 375 | } |
| 376 | |
| 377 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 378 | CommandObjectSettingsShow::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 379 | int &cursor_index, |
| 380 | int &cursor_char_position, |
| 381 | OptionElementVector &opt_element_vector, |
| 382 | int match_start_point, |
| 383 | int max_return_elements, |
| 384 | bool &word_complete, |
| 385 | StringList &matches) |
| 386 | { |
| 387 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 388 | completion_str.erase (cursor_char_position); |
| 389 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 390 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 391 | CommandCompletions::eSettingsNameCompletion, |
| 392 | completion_str.c_str(), |
| 393 | match_start_point, |
| 394 | max_return_elements, |
| 395 | NULL, |
| 396 | word_complete, |
| 397 | matches); |
| 398 | return matches.GetSize(); |
| 399 | } |
| 400 | |
| 401 | //------------------------------------------------------------------------- |
| 402 | // CommandObjectSettingsList |
| 403 | //------------------------------------------------------------------------- |
| 404 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 405 | CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) : |
| 406 | CommandObject (interpreter, |
| 407 | "settings list", |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 408 | "List and describe all the internal debugger settings variables that are available to the user to 'set' or 'show', or describe a particular variable or set of variables (by specifying the variable name or a common prefix).", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 409 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 410 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 411 | CommandArgumentEntry arg; |
| 412 | CommandArgumentData var_name_arg; |
| 413 | CommandArgumentData prefix_name_arg; |
| 414 | |
| 415 | // Define the first variant of this arg. |
| 416 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 417 | var_name_arg.arg_repetition = eArgRepeatOptional; |
| 418 | |
| 419 | // Define the second variant of this arg. |
| 420 | prefix_name_arg.arg_type = eArgTypeSettingPrefix; |
| 421 | prefix_name_arg.arg_repetition = eArgRepeatOptional; |
| 422 | |
| 423 | arg.push_back (var_name_arg); |
| 424 | arg.push_back (prefix_name_arg); |
| 425 | |
| 426 | // Push the data for the first argument into the m_arguments vector. |
| 427 | m_arguments.push_back (arg); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | CommandObjectSettingsList::~CommandObjectSettingsList() |
| 431 | { |
| 432 | } |
| 433 | |
| 434 | |
| 435 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 436 | CommandObjectSettingsList::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 437 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 438 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
| 439 | const char *current_prefix = usc_sp->GetLevelName().GetCString(); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 440 | |
| 441 | Error err; |
| 442 | |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 443 | if (command.GetArgumentCount() == 0) |
| 444 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 445 | UserSettingsController::FindAllSettingsDescriptions (m_interpreter, |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 446 | usc_sp, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 447 | current_prefix, |
| 448 | result.GetOutputStream(), |
| 449 | err); |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 450 | } |
| 451 | else if (command.GetArgumentCount() == 1) |
| 452 | { |
| 453 | const char *search_name = command.GetArgumentAtIndex (0); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 454 | UserSettingsController::FindSettingsDescriptions (m_interpreter, |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 455 | usc_sp, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 456 | current_prefix, |
| 457 | search_name, |
| 458 | result.GetOutputStream(), |
| 459 | err); |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 460 | } |
| 461 | else |
| 462 | { |
| 463 | result.AppendError ("Too many aguments for 'settings list' command.\n"); |
| 464 | result.SetStatus (eReturnStatusFailed); |
| 465 | return false; |
| 466 | } |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 467 | |
| 468 | if (err.Fail ()) |
| 469 | { |
| 470 | result.AppendError (err.AsCString()); |
| 471 | result.SetStatus (eReturnStatusFailed); |
| 472 | } |
| 473 | else |
| 474 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 475 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 476 | } |
| 477 | |
| 478 | return result.Succeeded(); |
| 479 | } |
| 480 | |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 481 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 482 | CommandObjectSettingsList::HandleArgumentCompletion (Args &input, |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 483 | int &cursor_index, |
| 484 | int &cursor_char_position, |
| 485 | OptionElementVector &opt_element_vector, |
| 486 | int match_start_point, |
| 487 | int max_return_elements, |
| 488 | bool &word_complete, |
| 489 | StringList &matches) |
| 490 | { |
| 491 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 492 | completion_str.erase (cursor_char_position); |
| 493 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 494 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 41ae217 | 2010-09-15 06:56:39 +0000 | [diff] [blame] | 495 | CommandCompletions::eSettingsNameCompletion, |
| 496 | completion_str.c_str(), |
| 497 | match_start_point, |
| 498 | max_return_elements, |
| 499 | NULL, |
| 500 | word_complete, |
| 501 | matches); |
| 502 | return matches.GetSize(); |
| 503 | } |
| 504 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 505 | //------------------------------------------------------------------------- |
| 506 | // CommandObjectSettingsRemove |
| 507 | //------------------------------------------------------------------------- |
| 508 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 509 | CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) : |
| 510 | CommandObject (interpreter, |
| 511 | "settings remove", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 512 | "Remove the specified element from an internal debugger settings array or dictionary variable.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 513 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 514 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 515 | CommandArgumentEntry arg1; |
| 516 | CommandArgumentEntry arg2; |
| 517 | CommandArgumentData var_name_arg; |
| 518 | CommandArgumentData index_arg; |
| 519 | CommandArgumentData key_arg; |
| 520 | |
| 521 | // Define the first (and only) variant of this arg. |
| 522 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 523 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 524 | |
| 525 | // There is only one variant this argument could be; put it into the argument entry. |
| 526 | arg1.push_back (var_name_arg); |
| 527 | |
| 528 | // Define the first variant of this arg. |
| 529 | index_arg.arg_type = eArgTypeSettingIndex; |
| 530 | index_arg.arg_repetition = eArgRepeatPlain; |
| 531 | |
| 532 | // Define the second variant of this arg. |
| 533 | key_arg.arg_type = eArgTypeSettingKey; |
| 534 | key_arg.arg_repetition = eArgRepeatPlain; |
| 535 | |
| 536 | // Push both variants into this arg |
| 537 | arg2.push_back (index_arg); |
| 538 | arg2.push_back (key_arg); |
| 539 | |
| 540 | // Push the data for the first argument into the m_arguments vector. |
| 541 | m_arguments.push_back (arg1); |
| 542 | m_arguments.push_back (arg2); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | CommandObjectSettingsRemove::~CommandObjectSettingsRemove () |
| 546 | { |
| 547 | } |
| 548 | |
| 549 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 550 | CommandObjectSettingsRemove::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 551 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 552 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 553 | |
| 554 | const int argc = command.GetArgumentCount (); |
| 555 | |
| 556 | if (argc != 2) |
| 557 | { |
| 558 | result.AppendError ("'settings remove' takes two arguments"); |
| 559 | result.SetStatus (eReturnStatusFailed); |
| 560 | return false; |
| 561 | } |
| 562 | |
| 563 | const char *var_name = command.GetArgumentAtIndex (0); |
| 564 | std::string var_name_string; |
| 565 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 566 | { |
| 567 | result.AppendError ("'settings remove' command requires a valid variable name; No value supplied"); |
| 568 | result.SetStatus (eReturnStatusFailed); |
| 569 | return false; |
| 570 | } |
| 571 | |
| 572 | var_name_string = var_name; |
| 573 | command.Shift(); |
| 574 | |
| 575 | const char *index_value = command.GetArgumentAtIndex (0); |
| 576 | std::string index_value_string; |
| 577 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 578 | { |
| 579 | result.AppendError ("'settings remove' command requires an index or key value; no value supplied"); |
| 580 | result.SetStatus (eReturnStatusFailed); |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | index_value_string = index_value; |
| 585 | |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 586 | Error err = usc_sp->SetVariable (var_name_string.c_str(), |
| 587 | NULL, |
| 588 | eVarSetOperationRemove, |
| 589 | true, |
| 590 | m_interpreter.GetDebugger().GetInstanceName().AsCString(), |
| 591 | index_value_string.c_str()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 592 | if (err.Fail ()) |
| 593 | { |
| 594 | result.AppendError (err.AsCString()); |
| 595 | result.SetStatus (eReturnStatusFailed); |
| 596 | } |
| 597 | else |
| 598 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 599 | |
| 600 | return result.Succeeded(); |
| 601 | } |
| 602 | |
| 603 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 604 | CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 605 | int &cursor_index, |
| 606 | int &cursor_char_position, |
| 607 | OptionElementVector &opt_element_vector, |
| 608 | int match_start_point, |
| 609 | int max_return_elements, |
| 610 | bool &word_complete, |
| 611 | StringList &matches) |
| 612 | { |
| 613 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 614 | completion_str.erase (cursor_char_position); |
| 615 | |
| 616 | // Attempting to complete variable name |
| 617 | if (cursor_index < 2) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 618 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 619 | CommandCompletions::eSettingsNameCompletion, |
| 620 | completion_str.c_str(), |
| 621 | match_start_point, |
| 622 | max_return_elements, |
| 623 | NULL, |
| 624 | word_complete, |
| 625 | matches); |
| 626 | |
| 627 | return matches.GetSize(); |
| 628 | } |
| 629 | |
| 630 | //------------------------------------------------------------------------- |
| 631 | // CommandObjectSettingsReplace |
| 632 | //------------------------------------------------------------------------- |
| 633 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 634 | CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) : |
| 635 | CommandObject (interpreter, |
| 636 | "settings replace", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 637 | "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 638 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 639 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 640 | CommandArgumentEntry arg1; |
| 641 | CommandArgumentEntry arg2; |
| 642 | CommandArgumentEntry arg3; |
| 643 | CommandArgumentData var_name_arg; |
| 644 | CommandArgumentData index_arg; |
| 645 | CommandArgumentData key_arg; |
| 646 | CommandArgumentData value_arg; |
| 647 | |
| 648 | // Define the first (and only) variant of this arg. |
| 649 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 650 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 651 | |
| 652 | // There is only one variant this argument could be; put it into the argument entry. |
| 653 | arg1.push_back (var_name_arg); |
| 654 | |
| 655 | // Define the first (variant of this arg. |
| 656 | index_arg.arg_type = eArgTypeSettingIndex; |
| 657 | index_arg.arg_repetition = eArgRepeatPlain; |
| 658 | |
| 659 | // Define the second (variant of this arg. |
| 660 | key_arg.arg_type = eArgTypeSettingKey; |
| 661 | key_arg.arg_repetition = eArgRepeatPlain; |
| 662 | |
| 663 | // Put both variants into this arg |
| 664 | arg2.push_back (index_arg); |
| 665 | arg2.push_back (key_arg); |
| 666 | |
| 667 | // Define the first (and only) variant of this arg. |
| 668 | value_arg.arg_type = eArgTypeValue; |
| 669 | value_arg.arg_repetition = eArgRepeatPlain; |
| 670 | |
| 671 | // There is only one variant this argument could be; put it into the argument entry. |
| 672 | arg3.push_back (value_arg); |
| 673 | |
| 674 | // Push the data for the first argument into the m_arguments vector. |
| 675 | m_arguments.push_back (arg1); |
| 676 | m_arguments.push_back (arg2); |
| 677 | m_arguments.push_back (arg3); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | CommandObjectSettingsReplace::~CommandObjectSettingsReplace () |
| 681 | { |
| 682 | } |
| 683 | |
| 684 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 685 | CommandObjectSettingsReplace::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 686 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 687 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 688 | |
| 689 | const int argc = command.GetArgumentCount (); |
| 690 | |
| 691 | if (argc < 3) |
| 692 | { |
| 693 | result.AppendError ("'settings replace' takes more arguments"); |
| 694 | result.SetStatus (eReturnStatusFailed); |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | const char *var_name = command.GetArgumentAtIndex (0); |
| 699 | std::string var_name_string; |
| 700 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 701 | { |
| 702 | result.AppendError ("'settings replace' command requires a valid variable name; No value supplied"); |
| 703 | result.SetStatus (eReturnStatusFailed); |
| 704 | return false; |
| 705 | } |
| 706 | |
| 707 | var_name_string = var_name; |
| 708 | command.Shift(); |
| 709 | |
| 710 | const char *index_value = command.GetArgumentAtIndex (0); |
| 711 | std::string index_value_string; |
| 712 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 713 | { |
| 714 | result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); |
| 715 | result.SetStatus (eReturnStatusFailed); |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | index_value_string = index_value; |
| 720 | command.Shift(); |
| 721 | |
| 722 | const char *var_value; |
| 723 | std::string value_string; |
| 724 | |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 725 | command.GetQuotedCommandString (value_string); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 726 | var_value = value_string.c_str(); |
| 727 | |
| 728 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 729 | { |
| 730 | result.AppendError ("'settings replace' command requires a valid variable value; no value supplied"); |
| 731 | result.SetStatus (eReturnStatusFailed); |
| 732 | } |
| 733 | else |
| 734 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 735 | Error err = usc_sp->SetVariable (var_name_string.c_str(), |
| 736 | var_value, |
| 737 | eVarSetOperationReplace, |
| 738 | true, |
| 739 | m_interpreter.GetDebugger().GetInstanceName().AsCString(), |
| 740 | index_value_string.c_str()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 741 | if (err.Fail ()) |
| 742 | { |
| 743 | result.AppendError (err.AsCString()); |
| 744 | result.SetStatus (eReturnStatusFailed); |
| 745 | } |
| 746 | else |
| 747 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 748 | } |
| 749 | |
| 750 | return result.Succeeded(); |
| 751 | } |
| 752 | |
| 753 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 754 | CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 755 | int &cursor_index, |
| 756 | int &cursor_char_position, |
| 757 | OptionElementVector &opt_element_vector, |
| 758 | int match_start_point, |
| 759 | int max_return_elements, |
| 760 | bool &word_complete, |
| 761 | StringList &matches) |
| 762 | { |
| 763 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 764 | completion_str.erase (cursor_char_position); |
| 765 | |
| 766 | // Attempting to complete variable name |
| 767 | if (cursor_index < 2) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 768 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 769 | CommandCompletions::eSettingsNameCompletion, |
| 770 | completion_str.c_str(), |
| 771 | match_start_point, |
| 772 | max_return_elements, |
| 773 | NULL, |
| 774 | word_complete, |
| 775 | matches); |
| 776 | |
| 777 | return matches.GetSize(); |
| 778 | } |
| 779 | |
| 780 | //------------------------------------------------------------------------- |
| 781 | // CommandObjectSettingsInsertBefore |
| 782 | //------------------------------------------------------------------------- |
| 783 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 784 | CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) : |
| 785 | CommandObject (interpreter, |
| 786 | "settings insert-before", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 787 | "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 788 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 789 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 790 | CommandArgumentEntry arg1; |
| 791 | CommandArgumentEntry arg2; |
| 792 | CommandArgumentEntry arg3; |
| 793 | CommandArgumentData var_name_arg; |
| 794 | CommandArgumentData index_arg; |
| 795 | CommandArgumentData value_arg; |
| 796 | |
| 797 | // Define the first (and only) variant of this arg. |
| 798 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 799 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 800 | |
| 801 | // There is only one variant this argument could be; put it into the argument entry. |
| 802 | arg1.push_back (var_name_arg); |
| 803 | |
| 804 | // Define the first (variant of this arg. |
| 805 | index_arg.arg_type = eArgTypeSettingIndex; |
| 806 | index_arg.arg_repetition = eArgRepeatPlain; |
| 807 | |
| 808 | // There is only one variant this argument could be; put it into the argument entry. |
| 809 | arg2.push_back (index_arg); |
| 810 | |
| 811 | // Define the first (and only) variant of this arg. |
| 812 | value_arg.arg_type = eArgTypeValue; |
| 813 | value_arg.arg_repetition = eArgRepeatPlain; |
| 814 | |
| 815 | // There is only one variant this argument could be; put it into the argument entry. |
| 816 | arg3.push_back (value_arg); |
| 817 | |
| 818 | // Push the data for the first argument into the m_arguments vector. |
| 819 | m_arguments.push_back (arg1); |
| 820 | m_arguments.push_back (arg2); |
| 821 | m_arguments.push_back (arg3); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore () |
| 825 | { |
| 826 | } |
| 827 | |
| 828 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 829 | CommandObjectSettingsInsertBefore::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 830 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 831 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 832 | |
| 833 | const int argc = command.GetArgumentCount (); |
| 834 | |
| 835 | if (argc < 3) |
| 836 | { |
| 837 | result.AppendError ("'settings insert-before' takes more arguments"); |
| 838 | result.SetStatus (eReturnStatusFailed); |
| 839 | return false; |
| 840 | } |
| 841 | |
| 842 | const char *var_name = command.GetArgumentAtIndex (0); |
| 843 | std::string var_name_string; |
| 844 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 845 | { |
| 846 | result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied"); |
| 847 | result.SetStatus (eReturnStatusFailed); |
| 848 | return false; |
| 849 | } |
| 850 | |
| 851 | var_name_string = var_name; |
| 852 | command.Shift(); |
| 853 | |
| 854 | const char *index_value = command.GetArgumentAtIndex (0); |
| 855 | std::string index_value_string; |
| 856 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 857 | { |
| 858 | result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); |
| 859 | result.SetStatus (eReturnStatusFailed); |
| 860 | return false; |
| 861 | } |
| 862 | |
| 863 | index_value_string = index_value; |
| 864 | command.Shift(); |
| 865 | |
| 866 | const char *var_value; |
| 867 | std::string value_string; |
| 868 | |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 869 | command.GetQuotedCommandString (value_string); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 870 | var_value = value_string.c_str(); |
| 871 | |
| 872 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 873 | { |
| 874 | result.AppendError ("'settings insert-before' command requires a valid variable value;" |
| 875 | " No value supplied"); |
| 876 | result.SetStatus (eReturnStatusFailed); |
| 877 | } |
| 878 | else |
| 879 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 880 | Error err = usc_sp->SetVariable (var_name_string.c_str(), |
| 881 | var_value, |
| 882 | eVarSetOperationInsertBefore, |
| 883 | true, |
| 884 | m_interpreter.GetDebugger().GetInstanceName().AsCString(), |
| 885 | index_value_string.c_str()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 886 | if (err.Fail ()) |
| 887 | { |
| 888 | result.AppendError (err.AsCString()); |
| 889 | result.SetStatus (eReturnStatusFailed); |
| 890 | } |
| 891 | else |
| 892 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 893 | } |
| 894 | |
| 895 | return result.Succeeded(); |
| 896 | } |
| 897 | |
| 898 | |
| 899 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 900 | CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 901 | int &cursor_index, |
| 902 | int &cursor_char_position, |
| 903 | OptionElementVector &opt_element_vector, |
| 904 | int match_start_point, |
| 905 | int max_return_elements, |
| 906 | bool &word_complete, |
| 907 | StringList &matches) |
| 908 | { |
| 909 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 910 | completion_str.erase (cursor_char_position); |
| 911 | |
| 912 | // Attempting to complete variable name |
| 913 | if (cursor_index < 2) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 914 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 915 | CommandCompletions::eSettingsNameCompletion, |
| 916 | completion_str.c_str(), |
| 917 | match_start_point, |
| 918 | max_return_elements, |
| 919 | NULL, |
| 920 | word_complete, |
| 921 | matches); |
| 922 | |
| 923 | return matches.GetSize(); |
| 924 | } |
| 925 | |
| 926 | //------------------------------------------------------------------------- |
| 927 | // CommandObjectSettingInsertAfter |
| 928 | //------------------------------------------------------------------------- |
| 929 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 930 | CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) : |
| 931 | CommandObject (interpreter, |
| 932 | "settings insert-after", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 933 | "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 934 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 935 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 936 | CommandArgumentEntry arg1; |
| 937 | CommandArgumentEntry arg2; |
| 938 | CommandArgumentEntry arg3; |
| 939 | CommandArgumentData var_name_arg; |
| 940 | CommandArgumentData index_arg; |
| 941 | CommandArgumentData value_arg; |
| 942 | |
| 943 | // Define the first (and only) variant of this arg. |
| 944 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 945 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 946 | |
| 947 | // There is only one variant this argument could be; put it into the argument entry. |
| 948 | arg1.push_back (var_name_arg); |
| 949 | |
| 950 | // Define the first (variant of this arg. |
| 951 | index_arg.arg_type = eArgTypeSettingIndex; |
| 952 | index_arg.arg_repetition = eArgRepeatPlain; |
| 953 | |
| 954 | // There is only one variant this argument could be; put it into the argument entry. |
| 955 | arg2.push_back (index_arg); |
| 956 | |
| 957 | // Define the first (and only) variant of this arg. |
| 958 | value_arg.arg_type = eArgTypeValue; |
| 959 | value_arg.arg_repetition = eArgRepeatPlain; |
| 960 | |
| 961 | // There is only one variant this argument could be; put it into the argument entry. |
| 962 | arg3.push_back (value_arg); |
| 963 | |
| 964 | // Push the data for the first argument into the m_arguments vector. |
| 965 | m_arguments.push_back (arg1); |
| 966 | m_arguments.push_back (arg2); |
| 967 | m_arguments.push_back (arg3); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter () |
| 971 | { |
| 972 | } |
| 973 | |
| 974 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 975 | CommandObjectSettingsInsertAfter::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 976 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 977 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 978 | |
| 979 | const int argc = command.GetArgumentCount (); |
| 980 | |
| 981 | if (argc < 3) |
| 982 | { |
| 983 | result.AppendError ("'settings insert-after' takes more arguments"); |
| 984 | result.SetStatus (eReturnStatusFailed); |
| 985 | return false; |
| 986 | } |
| 987 | |
| 988 | const char *var_name = command.GetArgumentAtIndex (0); |
| 989 | std::string var_name_string; |
| 990 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 991 | { |
| 992 | result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied"); |
| 993 | result.SetStatus (eReturnStatusFailed); |
| 994 | return false; |
| 995 | } |
| 996 | |
| 997 | var_name_string = var_name; |
| 998 | command.Shift(); |
| 999 | |
| 1000 | const char *index_value = command.GetArgumentAtIndex (0); |
| 1001 | std::string index_value_string; |
| 1002 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 1003 | { |
| 1004 | result.AppendError ("'settings insert-after' command requires an index value; no value supplied"); |
| 1005 | result.SetStatus (eReturnStatusFailed); |
| 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | index_value_string = index_value; |
| 1010 | command.Shift(); |
| 1011 | |
| 1012 | const char *var_value; |
| 1013 | std::string value_string; |
| 1014 | |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 1015 | command.GetQuotedCommandString (value_string); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1016 | var_value = value_string.c_str(); |
| 1017 | |
| 1018 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 1019 | { |
| 1020 | result.AppendError ("'settings insert-after' command requires a valid variable value;" |
| 1021 | " No value supplied"); |
| 1022 | result.SetStatus (eReturnStatusFailed); |
| 1023 | } |
| 1024 | else |
| 1025 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1026 | Error err = usc_sp->SetVariable (var_name_string.c_str(), |
| 1027 | var_value, |
| 1028 | eVarSetOperationInsertAfter, |
| 1029 | true, |
| 1030 | m_interpreter.GetDebugger().GetInstanceName().AsCString(), |
| 1031 | index_value_string.c_str()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1032 | if (err.Fail ()) |
| 1033 | { |
| 1034 | result.AppendError (err.AsCString()); |
| 1035 | result.SetStatus (eReturnStatusFailed); |
| 1036 | } |
| 1037 | else |
| 1038 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1039 | } |
| 1040 | |
| 1041 | return result.Succeeded(); |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1046 | CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1047 | int &cursor_index, |
| 1048 | int &cursor_char_position, |
| 1049 | OptionElementVector &opt_element_vector, |
| 1050 | int match_start_point, |
| 1051 | int max_return_elements, |
| 1052 | bool &word_complete, |
| 1053 | StringList &matches) |
| 1054 | { |
| 1055 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 1056 | completion_str.erase (cursor_char_position); |
| 1057 | |
| 1058 | // Attempting to complete variable name |
| 1059 | if (cursor_index < 2) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1060 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1061 | CommandCompletions::eSettingsNameCompletion, |
| 1062 | completion_str.c_str(), |
| 1063 | match_start_point, |
| 1064 | max_return_elements, |
| 1065 | NULL, |
| 1066 | word_complete, |
| 1067 | matches); |
| 1068 | |
| 1069 | return matches.GetSize(); |
| 1070 | } |
| 1071 | |
| 1072 | //------------------------------------------------------------------------- |
| 1073 | // CommandObjectSettingsAppend |
| 1074 | //------------------------------------------------------------------------- |
| 1075 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1076 | CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) : |
| 1077 | CommandObject (interpreter, |
| 1078 | "settings append", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 1079 | "Append a new value to the end of an internal debugger settings array, dictionary or string variable.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1080 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1081 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1082 | CommandArgumentEntry arg1; |
| 1083 | CommandArgumentEntry arg2; |
| 1084 | CommandArgumentData var_name_arg; |
| 1085 | CommandArgumentData value_arg; |
| 1086 | |
| 1087 | // Define the first (and only) variant of this arg. |
| 1088 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 1089 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 1090 | |
| 1091 | // There is only one variant this argument could be; put it into the argument entry. |
| 1092 | arg1.push_back (var_name_arg); |
| 1093 | |
| 1094 | // Define the first (and only) variant of this arg. |
| 1095 | value_arg.arg_type = eArgTypeValue; |
| 1096 | value_arg.arg_repetition = eArgRepeatPlain; |
| 1097 | |
| 1098 | // There is only one variant this argument could be; put it into the argument entry. |
| 1099 | arg2.push_back (value_arg); |
| 1100 | |
| 1101 | // Push the data for the first argument into the m_arguments vector. |
| 1102 | m_arguments.push_back (arg1); |
| 1103 | m_arguments.push_back (arg2); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | CommandObjectSettingsAppend::~CommandObjectSettingsAppend () |
| 1107 | { |
| 1108 | } |
| 1109 | |
| 1110 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1111 | CommandObjectSettingsAppend::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1112 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1113 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1114 | |
| 1115 | const int argc = command.GetArgumentCount (); |
| 1116 | |
| 1117 | if (argc < 2) |
| 1118 | { |
| 1119 | result.AppendError ("'settings append' takes more arguments"); |
| 1120 | result.SetStatus (eReturnStatusFailed); |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
| 1124 | const char *var_name = command.GetArgumentAtIndex (0); |
| 1125 | std::string var_name_string; |
| 1126 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 1127 | { |
| 1128 | result.AppendError ("'settings append' command requires a valid variable name; No value supplied"); |
| 1129 | result.SetStatus (eReturnStatusFailed); |
| 1130 | return false; |
| 1131 | } |
| 1132 | |
| 1133 | var_name_string = var_name; |
| 1134 | command.Shift(); |
| 1135 | |
| 1136 | const char *var_value; |
| 1137 | std::string value_string; |
| 1138 | |
Caroline Tice | d9105c2 | 2010-12-10 00:26:54 +0000 | [diff] [blame] | 1139 | command.GetQuotedCommandString (value_string); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1140 | var_value = value_string.c_str(); |
| 1141 | |
| 1142 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 1143 | { |
| 1144 | result.AppendError ("'settings append' command requires a valid variable value;" |
| 1145 | " No value supplied"); |
| 1146 | result.SetStatus (eReturnStatusFailed); |
| 1147 | } |
| 1148 | else |
| 1149 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1150 | Error err = usc_sp->SetVariable (var_name_string.c_str(), |
| 1151 | var_value, |
| 1152 | eVarSetOperationAppend, |
| 1153 | true, |
| 1154 | m_interpreter.GetDebugger().GetInstanceName().AsCString()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1155 | if (err.Fail ()) |
| 1156 | { |
| 1157 | result.AppendError (err.AsCString()); |
| 1158 | result.SetStatus (eReturnStatusFailed); |
| 1159 | } |
| 1160 | else |
| 1161 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1162 | } |
| 1163 | |
| 1164 | return result.Succeeded(); |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1169 | CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1170 | int &cursor_index, |
| 1171 | int &cursor_char_position, |
| 1172 | OptionElementVector &opt_element_vector, |
| 1173 | int match_start_point, |
| 1174 | int max_return_elements, |
| 1175 | bool &word_complete, |
| 1176 | StringList &matches) |
| 1177 | { |
| 1178 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 1179 | completion_str.erase (cursor_char_position); |
| 1180 | |
| 1181 | // Attempting to complete variable name |
| 1182 | if (cursor_index < 2) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1183 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1184 | CommandCompletions::eSettingsNameCompletion, |
| 1185 | completion_str.c_str(), |
| 1186 | match_start_point, |
| 1187 | max_return_elements, |
| 1188 | NULL, |
| 1189 | word_complete, |
| 1190 | matches); |
| 1191 | |
| 1192 | return matches.GetSize(); |
| 1193 | } |
| 1194 | |
| 1195 | //------------------------------------------------------------------------- |
| 1196 | // CommandObjectSettingsClear |
| 1197 | //------------------------------------------------------------------------- |
| 1198 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1199 | CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) : |
| 1200 | CommandObject (interpreter, |
| 1201 | "settings clear", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 1202 | "Erase all the contents of an internal debugger settings variables; this is only valid for variables with clearable types, i.e. strings, arrays or dictionaries.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1203 | NULL) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1204 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1205 | CommandArgumentEntry arg; |
| 1206 | CommandArgumentData var_name_arg; |
| 1207 | |
| 1208 | // Define the first (and only) variant of this arg. |
| 1209 | var_name_arg.arg_type = eArgTypeSettingVariableName; |
| 1210 | var_name_arg.arg_repetition = eArgRepeatPlain; |
| 1211 | |
| 1212 | // There is only one variant this argument could be; put it into the argument entry. |
| 1213 | arg.push_back (var_name_arg); |
| 1214 | |
| 1215 | // Push the data for the first argument into the m_arguments vector. |
| 1216 | m_arguments.push_back (arg); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | CommandObjectSettingsClear::~CommandObjectSettingsClear () |
| 1220 | { |
| 1221 | } |
| 1222 | |
| 1223 | bool |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1224 | CommandObjectSettingsClear::Execute (Args& command, CommandReturnObject &result) |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1225 | { |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1226 | UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1227 | |
| 1228 | const int argc = command.GetArgumentCount (); |
| 1229 | |
| 1230 | if (argc != 1) |
| 1231 | { |
| 1232 | result.AppendError ("'setttings clear' takes exactly one argument"); |
| 1233 | result.SetStatus (eReturnStatusFailed); |
| 1234 | return false; |
| 1235 | } |
| 1236 | |
| 1237 | const char *var_name = command.GetArgumentAtIndex (0); |
| 1238 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 1239 | { |
| 1240 | result.AppendError ("'settings clear' command requires a valid variable name; No value supplied"); |
| 1241 | result.SetStatus (eReturnStatusFailed); |
| 1242 | return false; |
| 1243 | } |
| 1244 | |
Greg Clayton | 41c56fa | 2011-04-19 22:32:36 +0000 | [diff] [blame] | 1245 | Error err = usc_sp->SetVariable (var_name, |
| 1246 | NULL, |
| 1247 | eVarSetOperationClear, |
| 1248 | false, |
| 1249 | m_interpreter.GetDebugger().GetInstanceName().AsCString()); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1250 | |
| 1251 | if (err.Fail ()) |
| 1252 | { |
| 1253 | result.AppendError (err.AsCString()); |
| 1254 | result.SetStatus (eReturnStatusFailed); |
| 1255 | } |
| 1256 | else |
| 1257 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1258 | |
| 1259 | return result.Succeeded(); |
| 1260 | } |
| 1261 | |
| 1262 | |
| 1263 | int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1264 | CommandObjectSettingsClear::HandleArgumentCompletion (Args &input, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1265 | int &cursor_index, |
| 1266 | int &cursor_char_position, |
| 1267 | OptionElementVector &opt_element_vector, |
| 1268 | int match_start_point, |
| 1269 | int max_return_elements, |
| 1270 | bool &word_complete, |
| 1271 | StringList &matches) |
| 1272 | { |
| 1273 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 1274 | completion_str.erase (cursor_char_position); |
| 1275 | |
| 1276 | // Attempting to complete variable name |
| 1277 | if (cursor_index < 2) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1278 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1279 | CommandCompletions::eSettingsNameCompletion, |
| 1280 | completion_str.c_str(), |
| 1281 | match_start_point, |
| 1282 | max_return_elements, |
| 1283 | NULL, |
| 1284 | word_complete, |
| 1285 | matches); |
| 1286 | |
| 1287 | return matches.GetSize(); |
| 1288 | } |