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