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) : |
| 28 | CommandObjectMultiword ("settings", |
| 29 | "A set of commands for manipulating internal settable debugger variables.", |
| 30 | "settings <command> [<command-options>]") |
| 31 | { |
| 32 | bool status; |
| 33 | |
| 34 | CommandObjectSP set_command_object (new CommandObjectSettingsSet ()); |
| 35 | CommandObjectSP show_command_object (new CommandObjectSettingsShow ()); |
| 36 | CommandObjectSP list_command_object (new CommandObjectSettingsList ()); |
| 37 | CommandObjectSP remove_command_object (new CommandObjectSettingsRemove ()); |
| 38 | CommandObjectSP replace_command_object (new CommandObjectSettingsReplace ()); |
| 39 | CommandObjectSP insert_before_command_object (new CommandObjectSettingsInsertBefore ()); |
| 40 | CommandObjectSP insert_after_command_object (new CommandObjectSettingsInsertAfter()); |
| 41 | CommandObjectSP append_command_object (new CommandObjectSettingsAppend()); |
| 42 | CommandObjectSP clear_command_object (new CommandObjectSettingsClear()); |
| 43 | |
| 44 | status = LoadSubCommand (interpreter, "set", set_command_object); |
| 45 | status = LoadSubCommand (interpreter, "show", show_command_object); |
| 46 | status = LoadSubCommand (interpreter, "list", list_command_object); |
| 47 | status = LoadSubCommand (interpreter, "remove", remove_command_object); |
| 48 | status = LoadSubCommand (interpreter, "replace", replace_command_object); |
| 49 | status = LoadSubCommand (interpreter, "insert-before", insert_before_command_object); |
| 50 | status = LoadSubCommand (interpreter, "insert-after", insert_after_command_object); |
| 51 | status = LoadSubCommand (interpreter, "append", append_command_object); |
| 52 | status = LoadSubCommand (interpreter, "clear", clear_command_object); |
| 53 | } |
| 54 | |
| 55 | CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 59 | //------------------------------------------------------------------------- |
| 60 | // CommandObjectSettingsSet |
| 61 | //------------------------------------------------------------------------- |
| 62 | |
| 63 | CommandObjectSettingsSet::CommandObjectSettingsSet () : |
| 64 | CommandObject ("settings set", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 65 | "Set or change the value of a single debugger setting variable.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 66 | "settings set [<cmd-options>] <setting-variable-name> <value>"), |
| 67 | m_options () |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | CommandObjectSettingsSet::~CommandObjectSettingsSet() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | { |
| 73 | } |
| 74 | |
| 75 | |
| 76 | bool |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 77 | CommandObjectSettingsSet::Execute (CommandInterpreter &interpreter, |
| 78 | Args& command, |
| 79 | CommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | { |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 81 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 83 | const int argc = command.GetArgumentCount (); |
| 84 | |
Caroline Tice | 8709723 | 2010-09-07 18:35:40 +0000 | [diff] [blame] | 85 | if ((argc < 2) && (!m_options.m_reset)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | { |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 87 | result.AppendError ("'settings set' takes more arguments"); |
| 88 | result.SetStatus (eReturnStatusFailed); |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | const char *var_name = command.GetArgumentAtIndex (0); |
| 93 | std::string var_name_string; |
| 94 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 95 | { |
| 96 | result.AppendError ("'settings set' command requires a valid variable name; No value supplied"); |
| 97 | result.SetStatus (eReturnStatusFailed); |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | var_name_string = var_name; |
| 102 | command.Shift(); |
| 103 | |
| 104 | const char *var_value; |
| 105 | std::string value_string; |
| 106 | |
| 107 | command.GetCommandString (value_string); |
| 108 | var_value = value_string.c_str(); |
| 109 | |
| 110 | if (!m_options.m_reset |
| 111 | && var_value == NULL) |
| 112 | { |
| 113 | result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;" |
| 114 | " No value supplied"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | result.SetStatus (eReturnStatusFailed); |
| 116 | } |
| 117 | else |
| 118 | { |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 119 | Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationAssign, |
| 120 | m_options.m_override); |
| 121 | if (err.Fail ()) |
| 122 | { |
| 123 | result.AppendError (err.AsCString()); |
| 124 | result.SetStatus (eReturnStatusFailed); |
| 125 | } |
| 126 | else |
| 127 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 128 | } |
| 129 | |
| 130 | return result.Succeeded(); |
| 131 | } |
| 132 | |
| 133 | int |
| 134 | CommandObjectSettingsSet::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 135 | Args &input, |
| 136 | int &cursor_index, |
| 137 | int &cursor_char_position, |
| 138 | OptionElementVector &opt_element_vector, |
| 139 | int match_start_point, |
| 140 | int max_return_elements, |
| 141 | bool &word_complete, |
| 142 | StringList &matches) |
| 143 | { |
| 144 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 145 | completion_str.erase (cursor_char_position); |
| 146 | |
| 147 | // Attempting to complete variable name |
| 148 | if (cursor_index == 1) |
| 149 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 150 | CommandCompletions::eSettingsNameCompletion, |
| 151 | completion_str.c_str(), |
| 152 | match_start_point, |
| 153 | max_return_elements, |
| 154 | NULL, |
| 155 | word_complete, |
| 156 | matches); |
| 157 | |
| 158 | // Attempting to complete value |
| 159 | if ((cursor_index == 2) // Partly into the variable's value |
| 160 | || (cursor_index == 1 // Or at the end of a completed valid variable name |
| 161 | && matches.GetSize() == 1 |
| 162 | && completion_str.compare (matches.GetStringAtIndex(0)) == 0)) |
| 163 | { |
| 164 | matches.Clear(); |
| 165 | lldb::UserSettingsControllerSP root_settings = Debugger::GetSettingsController(); |
| 166 | if (cursor_index == 1) |
| 167 | { |
| 168 | // The user is at the end of the variable name, which is complete and valid. |
| 169 | UserSettingsController::CompleteSettingsValue (root_settings, |
| 170 | input.GetArgumentAtIndex (1), // variable name |
| 171 | NULL, // empty value string |
| 172 | word_complete, |
| 173 | matches); |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | // The user is partly into the variable value. |
| 178 | UserSettingsController::CompleteSettingsValue (root_settings, |
| 179 | input.GetArgumentAtIndex (1), // variable name |
| 180 | completion_str.c_str(), // partial value string |
| 181 | word_complete, |
| 182 | matches); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return matches.GetSize(); |
| 187 | } |
| 188 | |
| 189 | //------------------------------------------------------------------------- |
| 190 | // CommandObjectSettingsSet::CommandOptions |
| 191 | //------------------------------------------------------------------------- |
| 192 | |
| 193 | CommandObjectSettingsSet::CommandOptions::CommandOptions () : |
| 194 | Options (), |
| 195 | m_override (false), |
| 196 | m_reset (false) |
| 197 | { |
| 198 | } |
| 199 | |
| 200 | CommandObjectSettingsSet::CommandOptions::~CommandOptions () |
| 201 | { |
| 202 | } |
| 203 | |
| 204 | lldb::OptionDefinition |
| 205 | CommandObjectSettingsSet::CommandOptions::g_option_table[] = |
| 206 | { |
| 207 | { LLDB_OPT_SET_1, false, "override", 'o', no_argument, NULL, NULL, NULL, "Causes already existing instances and pending settings to use this new value. This option only makes sense when setting default values." }, |
| 208 | |
| 209 | { LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, NULL, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." }, |
| 210 | }; |
| 211 | |
| 212 | const lldb::OptionDefinition* |
| 213 | CommandObjectSettingsSet::CommandOptions::GetDefinitions () |
| 214 | { |
| 215 | return g_option_table; |
| 216 | } |
| 217 | |
| 218 | Error |
| 219 | CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) |
| 220 | { |
| 221 | Error error; |
| 222 | char short_option = (char) m_getopt_table[option_idx].val; |
| 223 | |
| 224 | switch (short_option) |
| 225 | { |
| 226 | case 'o': |
| 227 | m_override = true; |
| 228 | break; |
| 229 | case 'r': |
| 230 | m_reset = true; |
| 231 | break; |
| 232 | default: |
| 233 | error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option); |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | return error; |
| 238 | } |
| 239 | |
| 240 | void |
| 241 | CommandObjectSettingsSet::CommandOptions::ResetOptionValues () |
| 242 | { |
| 243 | Options::ResetOptionValues (); |
| 244 | |
| 245 | m_override = false; |
| 246 | m_reset = false; |
| 247 | } |
| 248 | |
| 249 | Options * |
| 250 | CommandObjectSettingsSet::GetOptions () |
| 251 | { |
| 252 | return &m_options; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | //------------------------------------------------------------------------- |
| 257 | // CommandObjectSettingsShow -- Show current values |
| 258 | //------------------------------------------------------------------------- |
| 259 | |
| 260 | CommandObjectSettingsShow::CommandObjectSettingsShow () : |
| 261 | CommandObject ("settings show", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 262 | "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 | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 263 | "settings show [<setting-variable-name>]") |
| 264 | { |
| 265 | } |
| 266 | |
| 267 | CommandObjectSettingsShow::~CommandObjectSettingsShow() |
| 268 | { |
| 269 | } |
| 270 | |
| 271 | |
| 272 | bool |
| 273 | CommandObjectSettingsShow::Execute (CommandInterpreter &interpreter, |
| 274 | Args& command, |
| 275 | CommandReturnObject &result) |
| 276 | { |
| 277 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 278 | std::string current_prefix = root_settings->GetLevelName().AsCString(); |
| 279 | |
| 280 | Error err; |
| 281 | |
| 282 | if (command.GetArgumentCount()) |
| 283 | { |
| 284 | // The user requested to see the value of a particular variable. |
| 285 | lldb::SettableVariableType var_type; |
| 286 | const char *variable_name = command.GetArgumentAtIndex (0); |
| 287 | StringList value = root_settings->GetVariable (variable_name, var_type); |
| 288 | |
| 289 | if (value.GetSize() == 0) |
| 290 | { |
| 291 | result.AppendErrorWithFormat ("Unable to find variable named '%s'. " |
| 292 | "Try 'show' to see all variable values.\n", variable_name); |
| 293 | result.SetStatus (eReturnStatusFailed); |
| 294 | |
| 295 | } |
| 296 | else |
| 297 | { |
| 298 | char *type_name = (char *) ""; |
| 299 | if (var_type != eSetVarTypeNone) |
| 300 | { |
| 301 | StreamString tmp_str; |
| 302 | tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type)); |
| 303 | type_name = (char *) tmp_str.GetData(); |
| 304 | } |
| 305 | |
| 306 | if (value.GetSize() == 1) |
| 307 | result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0)); |
| 308 | else |
| 309 | { |
| 310 | result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name); |
| 311 | for (int i = 0; i < value.GetSize(); ++i) |
| 312 | { |
| 313 | result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i)); |
| 314 | } |
| 315 | } |
| 316 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 317 | } |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | UserSettingsController::GetAllVariableValues (interpreter, root_settings, current_prefix, |
| 322 | result.GetOutputStream(), err); |
| 323 | if (err.Fail ()) |
| 324 | { |
| 325 | result.AppendError (err.AsCString()); |
| 326 | result.SetStatus (eReturnStatusFailed); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return result.Succeeded(); |
| 335 | } |
| 336 | |
| 337 | int |
| 338 | CommandObjectSettingsShow::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 339 | Args &input, |
| 340 | int &cursor_index, |
| 341 | int &cursor_char_position, |
| 342 | OptionElementVector &opt_element_vector, |
| 343 | int match_start_point, |
| 344 | int max_return_elements, |
| 345 | bool &word_complete, |
| 346 | StringList &matches) |
| 347 | { |
| 348 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 349 | completion_str.erase (cursor_char_position); |
| 350 | |
| 351 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 352 | CommandCompletions::eSettingsNameCompletion, |
| 353 | completion_str.c_str(), |
| 354 | match_start_point, |
| 355 | max_return_elements, |
| 356 | NULL, |
| 357 | word_complete, |
| 358 | matches); |
| 359 | return matches.GetSize(); |
| 360 | } |
| 361 | |
| 362 | //------------------------------------------------------------------------- |
| 363 | // CommandObjectSettingsList |
| 364 | //------------------------------------------------------------------------- |
| 365 | |
| 366 | CommandObjectSettingsList::CommandObjectSettingsList () : |
| 367 | CommandObject ("settings list", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 368 | "List all the internal debugger settings variables that are available to the user to 'set' or 'show'.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 369 | "settings list") |
| 370 | { |
| 371 | } |
| 372 | |
| 373 | CommandObjectSettingsList::~CommandObjectSettingsList() |
| 374 | { |
| 375 | } |
| 376 | |
| 377 | |
| 378 | bool |
| 379 | CommandObjectSettingsList::Execute (CommandInterpreter &interpreter, |
| 380 | Args& command, |
| 381 | CommandReturnObject &result) |
| 382 | { |
| 383 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 384 | std::string current_prefix = root_settings->GetLevelName().AsCString(); |
| 385 | |
| 386 | Error err; |
| 387 | |
| 388 | UserSettingsController::FindAllSettingsDescriptions (interpreter, root_settings, current_prefix, |
| 389 | result.GetOutputStream(), err); |
| 390 | |
| 391 | if (err.Fail ()) |
| 392 | { |
| 393 | result.AppendError (err.AsCString()); |
| 394 | result.SetStatus (eReturnStatusFailed); |
| 395 | } |
| 396 | else |
| 397 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 399 | } |
| 400 | |
| 401 | return result.Succeeded(); |
| 402 | } |
| 403 | |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 404 | //------------------------------------------------------------------------- |
| 405 | // CommandObjectSettingsRemove |
| 406 | //------------------------------------------------------------------------- |
| 407 | |
| 408 | CommandObjectSettingsRemove::CommandObjectSettingsRemove () : |
| 409 | CommandObject ("settings remove", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 410 | "Remove the specified element from an internal debugger settings array or dictionary variable.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 411 | "settings remove <setting-variable-name> [<index>|\"key\"]") |
| 412 | { |
| 413 | } |
| 414 | |
| 415 | CommandObjectSettingsRemove::~CommandObjectSettingsRemove () |
| 416 | { |
| 417 | } |
| 418 | |
| 419 | bool |
| 420 | CommandObjectSettingsRemove::Execute (CommandInterpreter &interpreter, |
| 421 | Args& command, |
| 422 | CommandReturnObject &result) |
| 423 | { |
| 424 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 425 | |
| 426 | const int argc = command.GetArgumentCount (); |
| 427 | |
| 428 | if (argc != 2) |
| 429 | { |
| 430 | result.AppendError ("'settings remove' takes two arguments"); |
| 431 | result.SetStatus (eReturnStatusFailed); |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | const char *var_name = command.GetArgumentAtIndex (0); |
| 436 | std::string var_name_string; |
| 437 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 438 | { |
| 439 | result.AppendError ("'settings remove' command requires a valid variable name; No value supplied"); |
| 440 | result.SetStatus (eReturnStatusFailed); |
| 441 | return false; |
| 442 | } |
| 443 | |
| 444 | var_name_string = var_name; |
| 445 | command.Shift(); |
| 446 | |
| 447 | const char *index_value = command.GetArgumentAtIndex (0); |
| 448 | std::string index_value_string; |
| 449 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 450 | { |
| 451 | result.AppendError ("'settings remove' command requires an index or key value; no value supplied"); |
| 452 | result.SetStatus (eReturnStatusFailed); |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | index_value_string = index_value; |
| 457 | |
| 458 | Error err = root_settings->SetVariable (var_name_string.c_str(), NULL, lldb::eVarSetOperationRemove, |
| 459 | false, index_value_string.c_str()); |
| 460 | if (err.Fail ()) |
| 461 | { |
| 462 | result.AppendError (err.AsCString()); |
| 463 | result.SetStatus (eReturnStatusFailed); |
| 464 | } |
| 465 | else |
| 466 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 467 | |
| 468 | return result.Succeeded(); |
| 469 | } |
| 470 | |
| 471 | int |
| 472 | CommandObjectSettingsRemove::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 473 | Args &input, |
| 474 | int &cursor_index, |
| 475 | int &cursor_char_position, |
| 476 | OptionElementVector &opt_element_vector, |
| 477 | int match_start_point, |
| 478 | int max_return_elements, |
| 479 | bool &word_complete, |
| 480 | StringList &matches) |
| 481 | { |
| 482 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 483 | completion_str.erase (cursor_char_position); |
| 484 | |
| 485 | // Attempting to complete variable name |
| 486 | if (cursor_index < 2) |
| 487 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 488 | CommandCompletions::eSettingsNameCompletion, |
| 489 | completion_str.c_str(), |
| 490 | match_start_point, |
| 491 | max_return_elements, |
| 492 | NULL, |
| 493 | word_complete, |
| 494 | matches); |
| 495 | |
| 496 | return matches.GetSize(); |
| 497 | } |
| 498 | |
| 499 | //------------------------------------------------------------------------- |
| 500 | // CommandObjectSettingsReplace |
| 501 | //------------------------------------------------------------------------- |
| 502 | |
| 503 | CommandObjectSettingsReplace::CommandObjectSettingsReplace () : |
| 504 | CommandObject ("settings replace", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 505 | "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 506 | "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>") |
| 507 | { |
| 508 | } |
| 509 | |
| 510 | CommandObjectSettingsReplace::~CommandObjectSettingsReplace () |
| 511 | { |
| 512 | } |
| 513 | |
| 514 | bool |
| 515 | CommandObjectSettingsReplace::Execute (CommandInterpreter &interpreter, |
| 516 | Args& command, |
| 517 | CommandReturnObject &result) |
| 518 | { |
| 519 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 520 | |
| 521 | const int argc = command.GetArgumentCount (); |
| 522 | |
| 523 | if (argc < 3) |
| 524 | { |
| 525 | result.AppendError ("'settings replace' takes more arguments"); |
| 526 | result.SetStatus (eReturnStatusFailed); |
| 527 | return false; |
| 528 | } |
| 529 | |
| 530 | const char *var_name = command.GetArgumentAtIndex (0); |
| 531 | std::string var_name_string; |
| 532 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 533 | { |
| 534 | result.AppendError ("'settings replace' command requires a valid variable name; No value supplied"); |
| 535 | result.SetStatus (eReturnStatusFailed); |
| 536 | return false; |
| 537 | } |
| 538 | |
| 539 | var_name_string = var_name; |
| 540 | command.Shift(); |
| 541 | |
| 542 | const char *index_value = command.GetArgumentAtIndex (0); |
| 543 | std::string index_value_string; |
| 544 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 545 | { |
| 546 | result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); |
| 547 | result.SetStatus (eReturnStatusFailed); |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | index_value_string = index_value; |
| 552 | command.Shift(); |
| 553 | |
| 554 | const char *var_value; |
| 555 | std::string value_string; |
| 556 | |
| 557 | command.GetCommandString (value_string); |
| 558 | var_value = value_string.c_str(); |
| 559 | |
| 560 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 561 | { |
| 562 | result.AppendError ("'settings replace' command requires a valid variable value; no value supplied"); |
| 563 | result.SetStatus (eReturnStatusFailed); |
| 564 | } |
| 565 | else |
| 566 | { |
| 567 | Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationReplace, |
| 568 | false, index_value_string.c_str()); |
| 569 | if (err.Fail ()) |
| 570 | { |
| 571 | result.AppendError (err.AsCString()); |
| 572 | result.SetStatus (eReturnStatusFailed); |
| 573 | } |
| 574 | else |
| 575 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 576 | } |
| 577 | |
| 578 | return result.Succeeded(); |
| 579 | } |
| 580 | |
| 581 | int |
| 582 | CommandObjectSettingsReplace::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 583 | Args &input, |
| 584 | int &cursor_index, |
| 585 | int &cursor_char_position, |
| 586 | OptionElementVector &opt_element_vector, |
| 587 | int match_start_point, |
| 588 | int max_return_elements, |
| 589 | bool &word_complete, |
| 590 | StringList &matches) |
| 591 | { |
| 592 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 593 | completion_str.erase (cursor_char_position); |
| 594 | |
| 595 | // Attempting to complete variable name |
| 596 | if (cursor_index < 2) |
| 597 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 598 | CommandCompletions::eSettingsNameCompletion, |
| 599 | completion_str.c_str(), |
| 600 | match_start_point, |
| 601 | max_return_elements, |
| 602 | NULL, |
| 603 | word_complete, |
| 604 | matches); |
| 605 | |
| 606 | return matches.GetSize(); |
| 607 | } |
| 608 | |
| 609 | //------------------------------------------------------------------------- |
| 610 | // CommandObjectSettingsInsertBefore |
| 611 | //------------------------------------------------------------------------- |
| 612 | |
| 613 | CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore () : |
| 614 | CommandObject ("settings insert-before", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 615 | "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 616 | "settings insert-before <setting-variable-name> [<index>] <new-value>") |
| 617 | { |
| 618 | } |
| 619 | |
| 620 | CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore () |
| 621 | { |
| 622 | } |
| 623 | |
| 624 | bool |
| 625 | CommandObjectSettingsInsertBefore::Execute (CommandInterpreter &interpreter, |
| 626 | Args& command, |
| 627 | CommandReturnObject &result) |
| 628 | { |
| 629 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 630 | |
| 631 | const int argc = command.GetArgumentCount (); |
| 632 | |
| 633 | if (argc < 3) |
| 634 | { |
| 635 | result.AppendError ("'settings insert-before' takes more arguments"); |
| 636 | result.SetStatus (eReturnStatusFailed); |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | const char *var_name = command.GetArgumentAtIndex (0); |
| 641 | std::string var_name_string; |
| 642 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 643 | { |
| 644 | result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied"); |
| 645 | result.SetStatus (eReturnStatusFailed); |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | var_name_string = var_name; |
| 650 | command.Shift(); |
| 651 | |
| 652 | const char *index_value = command.GetArgumentAtIndex (0); |
| 653 | std::string index_value_string; |
| 654 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 655 | { |
| 656 | result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); |
| 657 | result.SetStatus (eReturnStatusFailed); |
| 658 | return false; |
| 659 | } |
| 660 | |
| 661 | index_value_string = index_value; |
| 662 | command.Shift(); |
| 663 | |
| 664 | const char *var_value; |
| 665 | std::string value_string; |
| 666 | |
| 667 | command.GetCommandString (value_string); |
| 668 | var_value = value_string.c_str(); |
| 669 | |
| 670 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 671 | { |
| 672 | result.AppendError ("'settings insert-before' command requires a valid variable value;" |
| 673 | " No value supplied"); |
| 674 | result.SetStatus (eReturnStatusFailed); |
| 675 | } |
| 676 | else |
| 677 | { |
| 678 | Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertBefore, |
| 679 | false, index_value_string.c_str()); |
| 680 | if (err.Fail ()) |
| 681 | { |
| 682 | result.AppendError (err.AsCString()); |
| 683 | result.SetStatus (eReturnStatusFailed); |
| 684 | } |
| 685 | else |
| 686 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 687 | } |
| 688 | |
| 689 | return result.Succeeded(); |
| 690 | } |
| 691 | |
| 692 | |
| 693 | int |
| 694 | CommandObjectSettingsInsertBefore::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 695 | Args &input, |
| 696 | int &cursor_index, |
| 697 | int &cursor_char_position, |
| 698 | OptionElementVector &opt_element_vector, |
| 699 | int match_start_point, |
| 700 | int max_return_elements, |
| 701 | bool &word_complete, |
| 702 | StringList &matches) |
| 703 | { |
| 704 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 705 | completion_str.erase (cursor_char_position); |
| 706 | |
| 707 | // Attempting to complete variable name |
| 708 | if (cursor_index < 2) |
| 709 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 710 | CommandCompletions::eSettingsNameCompletion, |
| 711 | completion_str.c_str(), |
| 712 | match_start_point, |
| 713 | max_return_elements, |
| 714 | NULL, |
| 715 | word_complete, |
| 716 | matches); |
| 717 | |
| 718 | return matches.GetSize(); |
| 719 | } |
| 720 | |
| 721 | //------------------------------------------------------------------------- |
| 722 | // CommandObjectSettingInsertAfter |
| 723 | //------------------------------------------------------------------------- |
| 724 | |
| 725 | CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter () : |
| 726 | CommandObject ("settings insert-after", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 727 | "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 728 | "settings insert-after <setting-variable-name> [<index>] <new-value>") |
| 729 | { |
| 730 | } |
| 731 | |
| 732 | CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter () |
| 733 | { |
| 734 | } |
| 735 | |
| 736 | bool |
| 737 | CommandObjectSettingsInsertAfter::Execute (CommandInterpreter &interpreter, |
| 738 | Args& command, |
| 739 | CommandReturnObject &result) |
| 740 | { |
| 741 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 742 | |
| 743 | const int argc = command.GetArgumentCount (); |
| 744 | |
| 745 | if (argc < 3) |
| 746 | { |
| 747 | result.AppendError ("'settings insert-after' takes more arguments"); |
| 748 | result.SetStatus (eReturnStatusFailed); |
| 749 | return false; |
| 750 | } |
| 751 | |
| 752 | const char *var_name = command.GetArgumentAtIndex (0); |
| 753 | std::string var_name_string; |
| 754 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 755 | { |
| 756 | result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied"); |
| 757 | result.SetStatus (eReturnStatusFailed); |
| 758 | return false; |
| 759 | } |
| 760 | |
| 761 | var_name_string = var_name; |
| 762 | command.Shift(); |
| 763 | |
| 764 | const char *index_value = command.GetArgumentAtIndex (0); |
| 765 | std::string index_value_string; |
| 766 | if ((index_value == NULL) || (index_value[0] == '\0')) |
| 767 | { |
| 768 | result.AppendError ("'settings insert-after' command requires an index value; no value supplied"); |
| 769 | result.SetStatus (eReturnStatusFailed); |
| 770 | return false; |
| 771 | } |
| 772 | |
| 773 | index_value_string = index_value; |
| 774 | command.Shift(); |
| 775 | |
| 776 | const char *var_value; |
| 777 | std::string value_string; |
| 778 | |
| 779 | command.GetCommandString (value_string); |
| 780 | var_value = value_string.c_str(); |
| 781 | |
| 782 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 783 | { |
| 784 | result.AppendError ("'settings insert-after' command requires a valid variable value;" |
| 785 | " No value supplied"); |
| 786 | result.SetStatus (eReturnStatusFailed); |
| 787 | } |
| 788 | else |
| 789 | { |
| 790 | Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationInsertAfter, |
| 791 | false, index_value_string.c_str()); |
| 792 | if (err.Fail ()) |
| 793 | { |
| 794 | result.AppendError (err.AsCString()); |
| 795 | result.SetStatus (eReturnStatusFailed); |
| 796 | } |
| 797 | else |
| 798 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 799 | } |
| 800 | |
| 801 | return result.Succeeded(); |
| 802 | } |
| 803 | |
| 804 | |
| 805 | int |
| 806 | CommandObjectSettingsInsertAfter::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 807 | Args &input, |
| 808 | int &cursor_index, |
| 809 | int &cursor_char_position, |
| 810 | OptionElementVector &opt_element_vector, |
| 811 | int match_start_point, |
| 812 | int max_return_elements, |
| 813 | bool &word_complete, |
| 814 | StringList &matches) |
| 815 | { |
| 816 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 817 | completion_str.erase (cursor_char_position); |
| 818 | |
| 819 | // Attempting to complete variable name |
| 820 | if (cursor_index < 2) |
| 821 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 822 | CommandCompletions::eSettingsNameCompletion, |
| 823 | completion_str.c_str(), |
| 824 | match_start_point, |
| 825 | max_return_elements, |
| 826 | NULL, |
| 827 | word_complete, |
| 828 | matches); |
| 829 | |
| 830 | return matches.GetSize(); |
| 831 | } |
| 832 | |
| 833 | //------------------------------------------------------------------------- |
| 834 | // CommandObjectSettingsAppend |
| 835 | //------------------------------------------------------------------------- |
| 836 | |
| 837 | CommandObjectSettingsAppend::CommandObjectSettingsAppend () : |
| 838 | CommandObject ("settings append", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 839 | "Append a new value to the end of an internal debugger settings array, dictionary or string variable.", |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 840 | "settings append <setting-variable-name> <new-value>") |
| 841 | { |
| 842 | } |
| 843 | |
| 844 | CommandObjectSettingsAppend::~CommandObjectSettingsAppend () |
| 845 | { |
| 846 | } |
| 847 | |
| 848 | bool |
| 849 | CommandObjectSettingsAppend::Execute (CommandInterpreter &interpreter, |
| 850 | Args& command, |
| 851 | CommandReturnObject &result) |
| 852 | { |
| 853 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 854 | |
| 855 | const int argc = command.GetArgumentCount (); |
| 856 | |
| 857 | if (argc < 2) |
| 858 | { |
| 859 | result.AppendError ("'settings append' takes more arguments"); |
| 860 | result.SetStatus (eReturnStatusFailed); |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | const char *var_name = command.GetArgumentAtIndex (0); |
| 865 | std::string var_name_string; |
| 866 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 867 | { |
| 868 | result.AppendError ("'settings append' command requires a valid variable name; No value supplied"); |
| 869 | result.SetStatus (eReturnStatusFailed); |
| 870 | return false; |
| 871 | } |
| 872 | |
| 873 | var_name_string = var_name; |
| 874 | command.Shift(); |
| 875 | |
| 876 | const char *var_value; |
| 877 | std::string value_string; |
| 878 | |
| 879 | command.GetCommandString (value_string); |
| 880 | var_value = value_string.c_str(); |
| 881 | |
| 882 | if ((var_value == NULL) || (var_value[0] == '\0')) |
| 883 | { |
| 884 | result.AppendError ("'settings append' command requires a valid variable value;" |
| 885 | " No value supplied"); |
| 886 | result.SetStatus (eReturnStatusFailed); |
| 887 | } |
| 888 | else |
| 889 | { |
| 890 | Error err = root_settings->SetVariable (var_name_string.c_str(), var_value, lldb::eVarSetOperationAppend, |
| 891 | false); |
| 892 | if (err.Fail ()) |
| 893 | { |
| 894 | result.AppendError (err.AsCString()); |
| 895 | result.SetStatus (eReturnStatusFailed); |
| 896 | } |
| 897 | else |
| 898 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 899 | } |
| 900 | |
| 901 | return result.Succeeded(); |
| 902 | } |
| 903 | |
| 904 | |
| 905 | int |
| 906 | CommandObjectSettingsAppend::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 907 | Args &input, |
| 908 | int &cursor_index, |
| 909 | int &cursor_char_position, |
| 910 | OptionElementVector &opt_element_vector, |
| 911 | int match_start_point, |
| 912 | int max_return_elements, |
| 913 | bool &word_complete, |
| 914 | StringList &matches) |
| 915 | { |
| 916 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 917 | completion_str.erase (cursor_char_position); |
| 918 | |
| 919 | // Attempting to complete variable name |
| 920 | if (cursor_index < 2) |
| 921 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 922 | CommandCompletions::eSettingsNameCompletion, |
| 923 | completion_str.c_str(), |
| 924 | match_start_point, |
| 925 | max_return_elements, |
| 926 | NULL, |
| 927 | word_complete, |
| 928 | matches); |
| 929 | |
| 930 | return matches.GetSize(); |
| 931 | } |
| 932 | |
| 933 | //------------------------------------------------------------------------- |
| 934 | // CommandObjectSettingsClear |
| 935 | //------------------------------------------------------------------------- |
| 936 | |
| 937 | CommandObjectSettingsClear::CommandObjectSettingsClear () : |
| 938 | CommandObject ("settings clear", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame^] | 939 | "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 | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 940 | "settings clear") |
| 941 | { |
| 942 | } |
| 943 | |
| 944 | CommandObjectSettingsClear::~CommandObjectSettingsClear () |
| 945 | { |
| 946 | } |
| 947 | |
| 948 | bool |
| 949 | CommandObjectSettingsClear::Execute (CommandInterpreter &interpreter, |
| 950 | Args& command, |
| 951 | CommandReturnObject &result) |
| 952 | { |
| 953 | UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); |
| 954 | |
| 955 | const int argc = command.GetArgumentCount (); |
| 956 | |
| 957 | if (argc != 1) |
| 958 | { |
| 959 | result.AppendError ("'setttings clear' takes exactly one argument"); |
| 960 | result.SetStatus (eReturnStatusFailed); |
| 961 | return false; |
| 962 | } |
| 963 | |
| 964 | const char *var_name = command.GetArgumentAtIndex (0); |
| 965 | if ((var_name == NULL) || (var_name[0] == '\0')) |
| 966 | { |
| 967 | result.AppendError ("'settings clear' command requires a valid variable name; No value supplied"); |
| 968 | result.SetStatus (eReturnStatusFailed); |
| 969 | return false; |
| 970 | } |
| 971 | |
| 972 | Error err = root_settings->SetVariable (var_name, NULL, lldb::eVarSetOperationClear, false); |
| 973 | |
| 974 | if (err.Fail ()) |
| 975 | { |
| 976 | result.AppendError (err.AsCString()); |
| 977 | result.SetStatus (eReturnStatusFailed); |
| 978 | } |
| 979 | else |
| 980 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 981 | |
| 982 | return result.Succeeded(); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | int |
| 987 | CommandObjectSettingsClear::HandleArgumentCompletion (CommandInterpreter &interpreter, |
| 988 | Args &input, |
| 989 | int &cursor_index, |
| 990 | int &cursor_char_position, |
| 991 | OptionElementVector &opt_element_vector, |
| 992 | int match_start_point, |
| 993 | int max_return_elements, |
| 994 | bool &word_complete, |
| 995 | StringList &matches) |
| 996 | { |
| 997 | std::string completion_str (input.GetArgumentAtIndex (cursor_index)); |
| 998 | completion_str.erase (cursor_char_position); |
| 999 | |
| 1000 | // Attempting to complete variable name |
| 1001 | if (cursor_index < 2) |
| 1002 | CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, |
| 1003 | CommandCompletions::eSettingsNameCompletion, |
| 1004 | completion_str.c_str(), |
| 1005 | match_start_point, |
| 1006 | max_return_elements, |
| 1007 | NULL, |
| 1008 | word_complete, |
| 1009 | matches); |
| 1010 | |
| 1011 | return matches.GetSize(); |
| 1012 | } |