blob: dd60fd679335043cfa7366d12c2463059616a231 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Tice6e4c5ce2010-09-04 00:03:46 +000018#include "lldb/Interpreter/CommandCompletions.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019
20using namespace lldb;
21using namespace lldb_private;
22
23//-------------------------------------------------------------------------
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000024// CommandObjectMultiwordSettings
Chris Lattner24943d22010-06-08 16:52:24 +000025//-------------------------------------------------------------------------
26
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000027CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +000028 CommandObjectMultiword (interpreter,
29 "settings",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000030 "A set of commands for manipulating internal settable debugger variables.",
31 "settings <command> [<command-options>]")
32{
33 bool status;
34
Greg Clayton238c0a12010-09-18 01:14:36 +000035 CommandObjectSP set_command_object (new CommandObjectSettingsSet (interpreter));
36 CommandObjectSP show_command_object (new CommandObjectSettingsShow (interpreter));
37 CommandObjectSP list_command_object (new CommandObjectSettingsList (interpreter));
38 CommandObjectSP remove_command_object (new CommandObjectSettingsRemove (interpreter));
39 CommandObjectSP replace_command_object (new CommandObjectSettingsReplace (interpreter));
40 CommandObjectSP insert_before_command_object (new CommandObjectSettingsInsertBefore (interpreter));
41 CommandObjectSP insert_after_command_object (new CommandObjectSettingsInsertAfter(interpreter));
42 CommandObjectSP append_command_object (new CommandObjectSettingsAppend(interpreter));
43 CommandObjectSP clear_command_object (new CommandObjectSettingsClear(interpreter));
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000044
Greg Clayton238c0a12010-09-18 01:14:36 +000045 status = LoadSubCommand ("set", set_command_object);
46 status = LoadSubCommand ("show", show_command_object);
47 status = LoadSubCommand ("list", list_command_object);
48 status = LoadSubCommand ("remove", remove_command_object);
49 status = LoadSubCommand ("replace", replace_command_object);
50 status = LoadSubCommand ("insert-before", insert_before_command_object);
51 status = LoadSubCommand ("insert-after", insert_after_command_object);
52 status = LoadSubCommand ("append", append_command_object);
53 status = LoadSubCommand ("clear", clear_command_object);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000054}
55
56CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
Chris Lattner24943d22010-06-08 16:52:24 +000057{
58}
59
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000060//-------------------------------------------------------------------------
61// CommandObjectSettingsSet
62//-------------------------------------------------------------------------
63
Greg Clayton238c0a12010-09-18 01:14:36 +000064CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpreter) :
65 CommandObject (interpreter,
66 "settings set",
Caroline Ticeabb507a2010-09-08 21:06:11 +000067 "Set or change the value of a single debugger setting variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000068 "settings set [<cmd-options>] <setting-variable-name> <value>"),
69 m_options ()
70{
71}
72
73CommandObjectSettingsSet::~CommandObjectSettingsSet()
Chris Lattner24943d22010-06-08 16:52:24 +000074{
75}
76
77
78bool
Greg Clayton238c0a12010-09-18 01:14:36 +000079CommandObjectSettingsSet::Execute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +000080{
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000081 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
Chris Lattner24943d22010-06-08 16:52:24 +000082
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000083 const int argc = command.GetArgumentCount ();
84
Caroline Tice87097232010-09-07 18:35:40 +000085 if ((argc < 2) && (!m_options.m_reset))
Chris Lattner24943d22010-06-08 16:52:24 +000086 {
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000087 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 Lattner24943d22010-06-08 16:52:24 +0000115 result.SetStatus (eReturnStatusFailed);
116 }
117 else
118 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000119 Error err = root_settings->SetVariable (var_name_string.c_str(),
120 var_value,
121 lldb::eVarSetOperationAssign,
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000122 m_options.m_override,
Greg Clayton238c0a12010-09-18 01:14:36 +0000123 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000124 if (err.Fail ())
125 {
126 result.AppendError (err.AsCString());
127 result.SetStatus (eReturnStatusFailed);
128 }
129 else
130 result.SetStatus (eReturnStatusSuccessFinishNoResult);
131 }
132
133 return result.Succeeded();
134}
135
136int
Greg Clayton238c0a12010-09-18 01:14:36 +0000137CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000138 int &cursor_index,
139 int &cursor_char_position,
140 OptionElementVector &opt_element_vector,
141 int match_start_point,
142 int max_return_elements,
143 bool &word_complete,
144 StringList &matches)
145{
146 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
147 completion_str.erase (cursor_char_position);
148
149 // Attempting to complete variable name
150 if (cursor_index == 1)
Greg Clayton238c0a12010-09-18 01:14:36 +0000151 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000152 CommandCompletions::eSettingsNameCompletion,
153 completion_str.c_str(),
154 match_start_point,
155 max_return_elements,
156 NULL,
157 word_complete,
158 matches);
159
160 // Attempting to complete value
161 if ((cursor_index == 2) // Partly into the variable's value
162 || (cursor_index == 1 // Or at the end of a completed valid variable name
163 && matches.GetSize() == 1
164 && completion_str.compare (matches.GetStringAtIndex(0)) == 0))
165 {
166 matches.Clear();
167 lldb::UserSettingsControllerSP root_settings = Debugger::GetSettingsController();
168 if (cursor_index == 1)
169 {
170 // The user is at the end of the variable name, which is complete and valid.
171 UserSettingsController::CompleteSettingsValue (root_settings,
172 input.GetArgumentAtIndex (1), // variable name
173 NULL, // empty value string
174 word_complete,
175 matches);
176 }
177 else
178 {
179 // The user is partly into the variable value.
180 UserSettingsController::CompleteSettingsValue (root_settings,
181 input.GetArgumentAtIndex (1), // variable name
182 completion_str.c_str(), // partial value string
183 word_complete,
184 matches);
185 }
186 }
187
188 return matches.GetSize();
189}
190
191//-------------------------------------------------------------------------
192// CommandObjectSettingsSet::CommandOptions
193//-------------------------------------------------------------------------
194
195CommandObjectSettingsSet::CommandOptions::CommandOptions () :
196 Options (),
Caroline Tice1ebef442010-09-27 00:30:10 +0000197 m_override (true),
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000198 m_reset (false)
199{
200}
201
202CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
203{
204}
205
206lldb::OptionDefinition
207CommandObjectSettingsSet::CommandOptions::g_option_table[] =
208{
Caroline Tice1ebef442010-09-27 00:30:10 +0000209 { LLDB_OPT_SET_1, false, "no_override", 'n', no_argument, NULL, NULL, NULL, "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." },
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000210 { 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." },
211};
212
213const lldb::OptionDefinition*
214CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
215{
216 return g_option_table;
217}
218
219Error
220CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
221{
222 Error error;
223 char short_option = (char) m_getopt_table[option_idx].val;
224
225 switch (short_option)
226 {
Caroline Tice1ebef442010-09-27 00:30:10 +0000227 case 'n':
228 m_override = false;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000229 break;
230 case 'r':
231 m_reset = true;
232 break;
233 default:
234 error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option);
235 break;
236 }
237
238 return error;
239}
240
241void
242CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
243{
244 Options::ResetOptionValues ();
245
Caroline Tice1ebef442010-09-27 00:30:10 +0000246 m_override = true;
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000247 m_reset = false;
248}
249
250Options *
251CommandObjectSettingsSet::GetOptions ()
252{
253 return &m_options;
254}
255
256
257//-------------------------------------------------------------------------
258// CommandObjectSettingsShow -- Show current values
259//-------------------------------------------------------------------------
260
Greg Clayton238c0a12010-09-18 01:14:36 +0000261CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
262 CommandObject (interpreter,
263 "settings show",
264 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
265 "settings show [<setting-variable-name>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000266{
267}
268
269CommandObjectSettingsShow::~CommandObjectSettingsShow()
270{
271}
272
273
274bool
Caroline Tice5bc8c972010-09-20 20:44:43 +0000275CommandObjectSettingsShow::Execute (Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000276 CommandReturnObject &result)
277{
278 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
279 std::string current_prefix = root_settings->GetLevelName().AsCString();
280
281 Error err;
282
283 if (command.GetArgumentCount())
284 {
285 // The user requested to see the value of a particular variable.
286 lldb::SettableVariableType var_type;
287 const char *variable_name = command.GetArgumentAtIndex (0);
Caroline Tice5bc8c972010-09-20 20:44:43 +0000288 StringList value = root_settings->GetVariable (variable_name, var_type,
289 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
290 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000291
Caroline Tice5bc8c972010-09-20 20:44:43 +0000292 if (err.Fail ())
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000293 {
Caroline Tice5bc8c972010-09-20 20:44:43 +0000294 result.AppendError (err.AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000295 result.SetStatus (eReturnStatusFailed);
296
297 }
298 else
299 {
300 char *type_name = (char *) "";
301 if (var_type != eSetVarTypeNone)
302 {
303 StreamString tmp_str;
304 tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type));
305 type_name = (char *) tmp_str.GetData();
306 }
Caroline Tice5bc8c972010-09-20 20:44:43 +0000307
308 if (value.GetSize() == 0)
309 result.AppendMessageWithFormat ("%s%s = ''\n", variable_name, type_name);
310 else if (value.GetSize() == 1)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000311 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
312 else
313 {
314 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
Chris Lattner0f6fa732010-09-08 22:55:31 +0000315 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000316 {
317 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
318 }
319 }
320 result.SetStatus (eReturnStatusSuccessFinishNoResult);
321 }
322 }
323 else
324 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000325 UserSettingsController::GetAllVariableValues (m_interpreter,
326 root_settings,
327 current_prefix,
328 result.GetOutputStream(),
329 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000330 if (err.Fail ())
331 {
332 result.AppendError (err.AsCString());
333 result.SetStatus (eReturnStatusFailed);
334 }
335 else
336 {
337 result.SetStatus (eReturnStatusSuccessFinishNoResult);
338 }
339 }
340
341 return result.Succeeded();
342}
343
344int
Greg Clayton238c0a12010-09-18 01:14:36 +0000345CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000346 int &cursor_index,
347 int &cursor_char_position,
348 OptionElementVector &opt_element_vector,
349 int match_start_point,
350 int max_return_elements,
351 bool &word_complete,
352 StringList &matches)
353{
354 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
355 completion_str.erase (cursor_char_position);
356
Greg Clayton238c0a12010-09-18 01:14:36 +0000357 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000358 CommandCompletions::eSettingsNameCompletion,
359 completion_str.c_str(),
360 match_start_point,
361 max_return_elements,
362 NULL,
363 word_complete,
364 matches);
365 return matches.GetSize();
366}
367
368//-------------------------------------------------------------------------
369// CommandObjectSettingsList
370//-------------------------------------------------------------------------
371
Greg Clayton238c0a12010-09-18 01:14:36 +0000372CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
373 CommandObject (interpreter,
374 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000375 "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).",
376 "settings list [<setting-name> | <setting-name-prefix>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000377{
378}
379
380CommandObjectSettingsList::~CommandObjectSettingsList()
381{
382}
383
384
385bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000386CommandObjectSettingsList::Execute ( Args& command,
Caroline Tice41ae2172010-09-15 06:56:39 +0000387 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000388{
389 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
390 std::string current_prefix = root_settings->GetLevelName().AsCString();
391
392 Error err;
393
Caroline Tice41ae2172010-09-15 06:56:39 +0000394 if (command.GetArgumentCount() == 0)
395 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000396 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
397 root_settings,
398 current_prefix,
399 result.GetOutputStream(),
400 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000401 }
402 else if (command.GetArgumentCount() == 1)
403 {
404 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000405 UserSettingsController::FindSettingsDescriptions (m_interpreter,
406 root_settings,
407 current_prefix,
408 search_name,
409 result.GetOutputStream(),
410 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000411 }
412 else
413 {
414 result.AppendError ("Too many aguments for 'settings list' command.\n");
415 result.SetStatus (eReturnStatusFailed);
416 return false;
417 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000418
419 if (err.Fail ())
420 {
421 result.AppendError (err.AsCString());
422 result.SetStatus (eReturnStatusFailed);
423 }
424 else
425 {
Chris Lattner24943d22010-06-08 16:52:24 +0000426 result.SetStatus (eReturnStatusSuccessFinishNoResult);
427 }
428
429 return result.Succeeded();
430}
431
Caroline Tice41ae2172010-09-15 06:56:39 +0000432int
Greg Clayton238c0a12010-09-18 01:14:36 +0000433CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000434 int &cursor_index,
435 int &cursor_char_position,
436 OptionElementVector &opt_element_vector,
437 int match_start_point,
438 int max_return_elements,
439 bool &word_complete,
440 StringList &matches)
441{
442 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
443 completion_str.erase (cursor_char_position);
444
Greg Clayton238c0a12010-09-18 01:14:36 +0000445 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000446 CommandCompletions::eSettingsNameCompletion,
447 completion_str.c_str(),
448 match_start_point,
449 max_return_elements,
450 NULL,
451 word_complete,
452 matches);
453 return matches.GetSize();
454}
455
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000456//-------------------------------------------------------------------------
457// CommandObjectSettingsRemove
458//-------------------------------------------------------------------------
459
Greg Clayton238c0a12010-09-18 01:14:36 +0000460CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
461 CommandObject (interpreter,
462 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000463 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000464 "settings remove <setting-variable-name> [<index>|\"key\"]")
465{
466}
467
468CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
469{
470}
471
472bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000473CommandObjectSettingsRemove::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000474 CommandReturnObject &result)
475{
476 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
477
478 const int argc = command.GetArgumentCount ();
479
480 if (argc != 2)
481 {
482 result.AppendError ("'settings remove' takes two arguments");
483 result.SetStatus (eReturnStatusFailed);
484 return false;
485 }
486
487 const char *var_name = command.GetArgumentAtIndex (0);
488 std::string var_name_string;
489 if ((var_name == NULL) || (var_name[0] == '\0'))
490 {
491 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
492 result.SetStatus (eReturnStatusFailed);
493 return false;
494 }
495
496 var_name_string = var_name;
497 command.Shift();
498
499 const char *index_value = command.GetArgumentAtIndex (0);
500 std::string index_value_string;
501 if ((index_value == NULL) || (index_value[0] == '\0'))
502 {
503 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
504 result.SetStatus (eReturnStatusFailed);
505 return false;
506 }
507
508 index_value_string = index_value;
509
Greg Clayton238c0a12010-09-18 01:14:36 +0000510 Error err = root_settings->SetVariable (var_name_string.c_str(),
511 NULL,
512 lldb::eVarSetOperationRemove,
Caroline Tice1ebef442010-09-27 00:30:10 +0000513 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000514 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000515 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000516 if (err.Fail ())
517 {
518 result.AppendError (err.AsCString());
519 result.SetStatus (eReturnStatusFailed);
520 }
521 else
522 result.SetStatus (eReturnStatusSuccessFinishNoResult);
523
524 return result.Succeeded();
525}
526
527int
Greg Clayton238c0a12010-09-18 01:14:36 +0000528CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000529 int &cursor_index,
530 int &cursor_char_position,
531 OptionElementVector &opt_element_vector,
532 int match_start_point,
533 int max_return_elements,
534 bool &word_complete,
535 StringList &matches)
536{
537 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
538 completion_str.erase (cursor_char_position);
539
540 // Attempting to complete variable name
541 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000542 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000543 CommandCompletions::eSettingsNameCompletion,
544 completion_str.c_str(),
545 match_start_point,
546 max_return_elements,
547 NULL,
548 word_complete,
549 matches);
550
551 return matches.GetSize();
552}
553
554//-------------------------------------------------------------------------
555// CommandObjectSettingsReplace
556//-------------------------------------------------------------------------
557
Greg Clayton238c0a12010-09-18 01:14:36 +0000558CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
559 CommandObject (interpreter,
560 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000561 "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000562 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
563{
564}
565
566CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
567{
568}
569
570bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000571CommandObjectSettingsReplace::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000572 CommandReturnObject &result)
573{
574 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
575
576 const int argc = command.GetArgumentCount ();
577
578 if (argc < 3)
579 {
580 result.AppendError ("'settings replace' takes more arguments");
581 result.SetStatus (eReturnStatusFailed);
582 return false;
583 }
584
585 const char *var_name = command.GetArgumentAtIndex (0);
586 std::string var_name_string;
587 if ((var_name == NULL) || (var_name[0] == '\0'))
588 {
589 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
590 result.SetStatus (eReturnStatusFailed);
591 return false;
592 }
593
594 var_name_string = var_name;
595 command.Shift();
596
597 const char *index_value = command.GetArgumentAtIndex (0);
598 std::string index_value_string;
599 if ((index_value == NULL) || (index_value[0] == '\0'))
600 {
601 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
602 result.SetStatus (eReturnStatusFailed);
603 return false;
604 }
605
606 index_value_string = index_value;
607 command.Shift();
608
609 const char *var_value;
610 std::string value_string;
611
612 command.GetCommandString (value_string);
613 var_value = value_string.c_str();
614
615 if ((var_value == NULL) || (var_value[0] == '\0'))
616 {
617 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
618 result.SetStatus (eReturnStatusFailed);
619 }
620 else
621 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000622 Error err = root_settings->SetVariable (var_name_string.c_str(),
623 var_value,
624 lldb::eVarSetOperationReplace,
Caroline Tice1ebef442010-09-27 00:30:10 +0000625 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000626 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000627 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000628 if (err.Fail ())
629 {
630 result.AppendError (err.AsCString());
631 result.SetStatus (eReturnStatusFailed);
632 }
633 else
634 result.SetStatus (eReturnStatusSuccessFinishNoResult);
635 }
636
637 return result.Succeeded();
638}
639
640int
Greg Clayton238c0a12010-09-18 01:14:36 +0000641CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000642 int &cursor_index,
643 int &cursor_char_position,
644 OptionElementVector &opt_element_vector,
645 int match_start_point,
646 int max_return_elements,
647 bool &word_complete,
648 StringList &matches)
649{
650 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
651 completion_str.erase (cursor_char_position);
652
653 // Attempting to complete variable name
654 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000655 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000656 CommandCompletions::eSettingsNameCompletion,
657 completion_str.c_str(),
658 match_start_point,
659 max_return_elements,
660 NULL,
661 word_complete,
662 matches);
663
664 return matches.GetSize();
665}
666
667//-------------------------------------------------------------------------
668// CommandObjectSettingsInsertBefore
669//-------------------------------------------------------------------------
670
Greg Clayton238c0a12010-09-18 01:14:36 +0000671CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
672 CommandObject (interpreter,
673 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000674 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000675 "settings insert-before <setting-variable-name> [<index>] <new-value>")
676{
677}
678
679CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
680{
681}
682
683bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000684CommandObjectSettingsInsertBefore::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000685 CommandReturnObject &result)
686{
687 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
688
689 const int argc = command.GetArgumentCount ();
690
691 if (argc < 3)
692 {
693 result.AppendError ("'settings insert-before' takes more arguments");
694 result.SetStatus (eReturnStatusFailed);
695 return false;
696 }
697
698 const char *var_name = command.GetArgumentAtIndex (0);
699 std::string var_name_string;
700 if ((var_name == NULL) || (var_name[0] == '\0'))
701 {
702 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
703 result.SetStatus (eReturnStatusFailed);
704 return false;
705 }
706
707 var_name_string = var_name;
708 command.Shift();
709
710 const char *index_value = command.GetArgumentAtIndex (0);
711 std::string index_value_string;
712 if ((index_value == NULL) || (index_value[0] == '\0'))
713 {
714 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
715 result.SetStatus (eReturnStatusFailed);
716 return false;
717 }
718
719 index_value_string = index_value;
720 command.Shift();
721
722 const char *var_value;
723 std::string value_string;
724
725 command.GetCommandString (value_string);
726 var_value = value_string.c_str();
727
728 if ((var_value == NULL) || (var_value[0] == '\0'))
729 {
730 result.AppendError ("'settings insert-before' command requires a valid variable value;"
731 " No value supplied");
732 result.SetStatus (eReturnStatusFailed);
733 }
734 else
735 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000736 Error err = root_settings->SetVariable (var_name_string.c_str(),
737 var_value,
738 lldb::eVarSetOperationInsertBefore,
Caroline Tice1ebef442010-09-27 00:30:10 +0000739 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000740 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000741 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000742 if (err.Fail ())
743 {
744 result.AppendError (err.AsCString());
745 result.SetStatus (eReturnStatusFailed);
746 }
747 else
748 result.SetStatus (eReturnStatusSuccessFinishNoResult);
749 }
750
751 return result.Succeeded();
752}
753
754
755int
Greg Clayton238c0a12010-09-18 01:14:36 +0000756CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000757 int &cursor_index,
758 int &cursor_char_position,
759 OptionElementVector &opt_element_vector,
760 int match_start_point,
761 int max_return_elements,
762 bool &word_complete,
763 StringList &matches)
764{
765 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
766 completion_str.erase (cursor_char_position);
767
768 // Attempting to complete variable name
769 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000770 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000771 CommandCompletions::eSettingsNameCompletion,
772 completion_str.c_str(),
773 match_start_point,
774 max_return_elements,
775 NULL,
776 word_complete,
777 matches);
778
779 return matches.GetSize();
780}
781
782//-------------------------------------------------------------------------
783// CommandObjectSettingInsertAfter
784//-------------------------------------------------------------------------
785
Greg Clayton238c0a12010-09-18 01:14:36 +0000786CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
787 CommandObject (interpreter,
788 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000789 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000790 "settings insert-after <setting-variable-name> [<index>] <new-value>")
791{
792}
793
794CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
795{
796}
797
798bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000799CommandObjectSettingsInsertAfter::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000800 CommandReturnObject &result)
801{
802 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
803
804 const int argc = command.GetArgumentCount ();
805
806 if (argc < 3)
807 {
808 result.AppendError ("'settings insert-after' takes more arguments");
809 result.SetStatus (eReturnStatusFailed);
810 return false;
811 }
812
813 const char *var_name = command.GetArgumentAtIndex (0);
814 std::string var_name_string;
815 if ((var_name == NULL) || (var_name[0] == '\0'))
816 {
817 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
818 result.SetStatus (eReturnStatusFailed);
819 return false;
820 }
821
822 var_name_string = var_name;
823 command.Shift();
824
825 const char *index_value = command.GetArgumentAtIndex (0);
826 std::string index_value_string;
827 if ((index_value == NULL) || (index_value[0] == '\0'))
828 {
829 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
830 result.SetStatus (eReturnStatusFailed);
831 return false;
832 }
833
834 index_value_string = index_value;
835 command.Shift();
836
837 const char *var_value;
838 std::string value_string;
839
840 command.GetCommandString (value_string);
841 var_value = value_string.c_str();
842
843 if ((var_value == NULL) || (var_value[0] == '\0'))
844 {
845 result.AppendError ("'settings insert-after' command requires a valid variable value;"
846 " No value supplied");
847 result.SetStatus (eReturnStatusFailed);
848 }
849 else
850 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000851 Error err = root_settings->SetVariable (var_name_string.c_str(),
852 var_value,
853 lldb::eVarSetOperationInsertAfter,
Caroline Tice1ebef442010-09-27 00:30:10 +0000854 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000855 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000856 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000857 if (err.Fail ())
858 {
859 result.AppendError (err.AsCString());
860 result.SetStatus (eReturnStatusFailed);
861 }
862 else
863 result.SetStatus (eReturnStatusSuccessFinishNoResult);
864 }
865
866 return result.Succeeded();
867}
868
869
870int
Greg Clayton238c0a12010-09-18 01:14:36 +0000871CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000872 int &cursor_index,
873 int &cursor_char_position,
874 OptionElementVector &opt_element_vector,
875 int match_start_point,
876 int max_return_elements,
877 bool &word_complete,
878 StringList &matches)
879{
880 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
881 completion_str.erase (cursor_char_position);
882
883 // Attempting to complete variable name
884 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000885 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000886 CommandCompletions::eSettingsNameCompletion,
887 completion_str.c_str(),
888 match_start_point,
889 max_return_elements,
890 NULL,
891 word_complete,
892 matches);
893
894 return matches.GetSize();
895}
896
897//-------------------------------------------------------------------------
898// CommandObjectSettingsAppend
899//-------------------------------------------------------------------------
900
Greg Clayton238c0a12010-09-18 01:14:36 +0000901CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
902 CommandObject (interpreter,
903 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000904 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000905 "settings append <setting-variable-name> <new-value>")
906{
907}
908
909CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
910{
911}
912
913bool
Caroline Tice1ebef442010-09-27 00:30:10 +0000914CommandObjectSettingsAppend::Execute (Args& command,
915 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000916{
917 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
918
919 const int argc = command.GetArgumentCount ();
920
921 if (argc < 2)
922 {
923 result.AppendError ("'settings append' takes more arguments");
924 result.SetStatus (eReturnStatusFailed);
925 return false;
926 }
927
928 const char *var_name = command.GetArgumentAtIndex (0);
929 std::string var_name_string;
930 if ((var_name == NULL) || (var_name[0] == '\0'))
931 {
932 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
933 result.SetStatus (eReturnStatusFailed);
934 return false;
935 }
936
937 var_name_string = var_name;
938 command.Shift();
939
940 const char *var_value;
941 std::string value_string;
942
943 command.GetCommandString (value_string);
944 var_value = value_string.c_str();
945
946 if ((var_value == NULL) || (var_value[0] == '\0'))
947 {
948 result.AppendError ("'settings append' command requires a valid variable value;"
949 " No value supplied");
950 result.SetStatus (eReturnStatusFailed);
951 }
952 else
953 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000954 Error err = root_settings->SetVariable (var_name_string.c_str(),
955 var_value,
956 lldb::eVarSetOperationAppend,
Caroline Tice1ebef442010-09-27 00:30:10 +0000957 true,
Greg Clayton238c0a12010-09-18 01:14:36 +0000958 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000959 if (err.Fail ())
960 {
961 result.AppendError (err.AsCString());
962 result.SetStatus (eReturnStatusFailed);
963 }
964 else
965 result.SetStatus (eReturnStatusSuccessFinishNoResult);
966 }
967
968 return result.Succeeded();
969}
970
971
972int
Greg Clayton238c0a12010-09-18 01:14:36 +0000973CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000974 int &cursor_index,
975 int &cursor_char_position,
976 OptionElementVector &opt_element_vector,
977 int match_start_point,
978 int max_return_elements,
979 bool &word_complete,
980 StringList &matches)
981{
982 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
983 completion_str.erase (cursor_char_position);
984
985 // Attempting to complete variable name
986 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000987 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000988 CommandCompletions::eSettingsNameCompletion,
989 completion_str.c_str(),
990 match_start_point,
991 max_return_elements,
992 NULL,
993 word_complete,
994 matches);
995
996 return matches.GetSize();
997}
998
999//-------------------------------------------------------------------------
1000// CommandObjectSettingsClear
1001//-------------------------------------------------------------------------
1002
Greg Clayton238c0a12010-09-18 01:14:36 +00001003CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1004 CommandObject (interpreter,
1005 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001006 "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 Tice6e4c5ce2010-09-04 00:03:46 +00001007 "settings clear")
1008{
1009}
1010
1011CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1012{
1013}
1014
1015bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001016CommandObjectSettingsClear::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001017 CommandReturnObject &result)
1018{
1019 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1020
1021 const int argc = command.GetArgumentCount ();
1022
1023 if (argc != 1)
1024 {
1025 result.AppendError ("'setttings clear' takes exactly one argument");
1026 result.SetStatus (eReturnStatusFailed);
1027 return false;
1028 }
1029
1030 const char *var_name = command.GetArgumentAtIndex (0);
1031 if ((var_name == NULL) || (var_name[0] == '\0'))
1032 {
1033 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1034 result.SetStatus (eReturnStatusFailed);
1035 return false;
1036 }
1037
Greg Clayton238c0a12010-09-18 01:14:36 +00001038 Error err = root_settings->SetVariable (var_name,
1039 NULL,
1040 lldb::eVarSetOperationClear,
1041 false,
1042 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001043
1044 if (err.Fail ())
1045 {
1046 result.AppendError (err.AsCString());
1047 result.SetStatus (eReturnStatusFailed);
1048 }
1049 else
1050 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1051
1052 return result.Succeeded();
1053}
1054
1055
1056int
Greg Clayton238c0a12010-09-18 01:14:36 +00001057CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001058 int &cursor_index,
1059 int &cursor_char_position,
1060 OptionElementVector &opt_element_vector,
1061 int match_start_point,
1062 int max_return_elements,
1063 bool &word_complete,
1064 StringList &matches)
1065{
1066 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1067 completion_str.erase (cursor_char_position);
1068
1069 // Attempting to complete variable name
1070 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001071 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001072 CommandCompletions::eSettingsNameCompletion,
1073 completion_str.c_str(),
1074 match_start_point,
1075 max_return_elements,
1076 NULL,
1077 word_complete,
1078 matches);
1079
1080 return matches.GetSize();
1081}