blob: ceb5d47579e09b4952ebb8619c2d06859bca19da [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 (),
197 m_override (false),
198 m_reset (false)
199{
200}
201
202CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
203{
204}
205
206lldb::OptionDefinition
207CommandObjectSettingsSet::CommandOptions::g_option_table[] =
208{
209 { 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." },
210
211 { 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." },
212};
213
214const lldb::OptionDefinition*
215CommandObjectSettingsSet::CommandOptions::GetDefinitions ()
216{
217 return g_option_table;
218}
219
220Error
221CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
222{
223 Error error;
224 char short_option = (char) m_getopt_table[option_idx].val;
225
226 switch (short_option)
227 {
228 case 'o':
229 m_override = true;
230 break;
231 case 'r':
232 m_reset = true;
233 break;
234 default:
235 error.SetErrorStringWithFormat ("Unrecognized options '%c'.\n", short_option);
236 break;
237 }
238
239 return error;
240}
241
242void
243CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
244{
245 Options::ResetOptionValues ();
246
247 m_override = false;
248 m_reset = false;
249}
250
251Options *
252CommandObjectSettingsSet::GetOptions ()
253{
254 return &m_options;
255}
256
257
258//-------------------------------------------------------------------------
259// CommandObjectSettingsShow -- Show current values
260//-------------------------------------------------------------------------
261
Greg Clayton238c0a12010-09-18 01:14:36 +0000262CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) :
263 CommandObject (interpreter,
264 "settings show",
265 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
266 "settings show [<setting-variable-name>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000267{
268}
269
270CommandObjectSettingsShow::~CommandObjectSettingsShow()
271{
272}
273
274
275bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000276CommandObjectSettingsShow::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000277 CommandReturnObject &result)
278{
279 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
280 std::string current_prefix = root_settings->GetLevelName().AsCString();
281
282 Error err;
283
284 if (command.GetArgumentCount())
285 {
286 // The user requested to see the value of a particular variable.
287 lldb::SettableVariableType var_type;
288 const char *variable_name = command.GetArgumentAtIndex (0);
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000289 StringList value = root_settings->GetVariable (variable_name, var_type,
Greg Clayton238c0a12010-09-18 01:14:36 +0000290 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000291
292 if (value.GetSize() == 0)
293 {
294 result.AppendErrorWithFormat ("Unable to find variable named '%s'. "
295 "Try 'show' to see all variable values.\n", variable_name);
296 result.SetStatus (eReturnStatusFailed);
297
298 }
299 else
300 {
301 char *type_name = (char *) "";
302 if (var_type != eSetVarTypeNone)
303 {
304 StreamString tmp_str;
305 tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type));
306 type_name = (char *) tmp_str.GetData();
307 }
308
309 if (value.GetSize() == 1)
310 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
311 else
312 {
313 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
Chris Lattner0f6fa732010-09-08 22:55:31 +0000314 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000315 {
316 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
317 }
318 }
319 result.SetStatus (eReturnStatusSuccessFinishNoResult);
320 }
321 }
322 else
323 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000324 UserSettingsController::GetAllVariableValues (m_interpreter,
325 root_settings,
326 current_prefix,
327 result.GetOutputStream(),
328 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000329 if (err.Fail ())
330 {
331 result.AppendError (err.AsCString());
332 result.SetStatus (eReturnStatusFailed);
333 }
334 else
335 {
336 result.SetStatus (eReturnStatusSuccessFinishNoResult);
337 }
338 }
339
340 return result.Succeeded();
341}
342
343int
Greg Clayton238c0a12010-09-18 01:14:36 +0000344CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000345 int &cursor_index,
346 int &cursor_char_position,
347 OptionElementVector &opt_element_vector,
348 int match_start_point,
349 int max_return_elements,
350 bool &word_complete,
351 StringList &matches)
352{
353 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
354 completion_str.erase (cursor_char_position);
355
Greg Clayton238c0a12010-09-18 01:14:36 +0000356 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000357 CommandCompletions::eSettingsNameCompletion,
358 completion_str.c_str(),
359 match_start_point,
360 max_return_elements,
361 NULL,
362 word_complete,
363 matches);
364 return matches.GetSize();
365}
366
367//-------------------------------------------------------------------------
368// CommandObjectSettingsList
369//-------------------------------------------------------------------------
370
Greg Clayton238c0a12010-09-18 01:14:36 +0000371CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
372 CommandObject (interpreter,
373 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000374 "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).",
375 "settings list [<setting-name> | <setting-name-prefix>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000376{
377}
378
379CommandObjectSettingsList::~CommandObjectSettingsList()
380{
381}
382
383
384bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000385CommandObjectSettingsList::Execute ( Args& command,
Caroline Tice41ae2172010-09-15 06:56:39 +0000386 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000387{
388 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
389 std::string current_prefix = root_settings->GetLevelName().AsCString();
390
391 Error err;
392
Caroline Tice41ae2172010-09-15 06:56:39 +0000393 if (command.GetArgumentCount() == 0)
394 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000395 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
396 root_settings,
397 current_prefix,
398 result.GetOutputStream(),
399 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000400 }
401 else if (command.GetArgumentCount() == 1)
402 {
403 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000404 UserSettingsController::FindSettingsDescriptions (m_interpreter,
405 root_settings,
406 current_prefix,
407 search_name,
408 result.GetOutputStream(),
409 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000410 }
411 else
412 {
413 result.AppendError ("Too many aguments for 'settings list' command.\n");
414 result.SetStatus (eReturnStatusFailed);
415 return false;
416 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000417
418 if (err.Fail ())
419 {
420 result.AppendError (err.AsCString());
421 result.SetStatus (eReturnStatusFailed);
422 }
423 else
424 {
Chris Lattner24943d22010-06-08 16:52:24 +0000425 result.SetStatus (eReturnStatusSuccessFinishNoResult);
426 }
427
428 return result.Succeeded();
429}
430
Caroline Tice41ae2172010-09-15 06:56:39 +0000431int
Greg Clayton238c0a12010-09-18 01:14:36 +0000432CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000433 int &cursor_index,
434 int &cursor_char_position,
435 OptionElementVector &opt_element_vector,
436 int match_start_point,
437 int max_return_elements,
438 bool &word_complete,
439 StringList &matches)
440{
441 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
442 completion_str.erase (cursor_char_position);
443
Greg Clayton238c0a12010-09-18 01:14:36 +0000444 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000445 CommandCompletions::eSettingsNameCompletion,
446 completion_str.c_str(),
447 match_start_point,
448 max_return_elements,
449 NULL,
450 word_complete,
451 matches);
452 return matches.GetSize();
453}
454
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000455//-------------------------------------------------------------------------
456// CommandObjectSettingsRemove
457//-------------------------------------------------------------------------
458
Greg Clayton238c0a12010-09-18 01:14:36 +0000459CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
460 CommandObject (interpreter,
461 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000462 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000463 "settings remove <setting-variable-name> [<index>|\"key\"]")
464{
465}
466
467CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
468{
469}
470
471bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000472CommandObjectSettingsRemove::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000473 CommandReturnObject &result)
474{
475 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
476
477 const int argc = command.GetArgumentCount ();
478
479 if (argc != 2)
480 {
481 result.AppendError ("'settings remove' takes two arguments");
482 result.SetStatus (eReturnStatusFailed);
483 return false;
484 }
485
486 const char *var_name = command.GetArgumentAtIndex (0);
487 std::string var_name_string;
488 if ((var_name == NULL) || (var_name[0] == '\0'))
489 {
490 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
491 result.SetStatus (eReturnStatusFailed);
492 return false;
493 }
494
495 var_name_string = var_name;
496 command.Shift();
497
498 const char *index_value = command.GetArgumentAtIndex (0);
499 std::string index_value_string;
500 if ((index_value == NULL) || (index_value[0] == '\0'))
501 {
502 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
503 result.SetStatus (eReturnStatusFailed);
504 return false;
505 }
506
507 index_value_string = index_value;
508
Greg Clayton238c0a12010-09-18 01:14:36 +0000509 Error err = root_settings->SetVariable (var_name_string.c_str(),
510 NULL,
511 lldb::eVarSetOperationRemove,
512 false,
513 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000514 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000515 if (err.Fail ())
516 {
517 result.AppendError (err.AsCString());
518 result.SetStatus (eReturnStatusFailed);
519 }
520 else
521 result.SetStatus (eReturnStatusSuccessFinishNoResult);
522
523 return result.Succeeded();
524}
525
526int
Greg Clayton238c0a12010-09-18 01:14:36 +0000527CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000528 int &cursor_index,
529 int &cursor_char_position,
530 OptionElementVector &opt_element_vector,
531 int match_start_point,
532 int max_return_elements,
533 bool &word_complete,
534 StringList &matches)
535{
536 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
537 completion_str.erase (cursor_char_position);
538
539 // Attempting to complete variable name
540 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000541 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000542 CommandCompletions::eSettingsNameCompletion,
543 completion_str.c_str(),
544 match_start_point,
545 max_return_elements,
546 NULL,
547 word_complete,
548 matches);
549
550 return matches.GetSize();
551}
552
553//-------------------------------------------------------------------------
554// CommandObjectSettingsReplace
555//-------------------------------------------------------------------------
556
Greg Clayton238c0a12010-09-18 01:14:36 +0000557CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
558 CommandObject (interpreter,
559 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000560 "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 +0000561 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
562{
563}
564
565CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
566{
567}
568
569bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000570CommandObjectSettingsReplace::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000571 CommandReturnObject &result)
572{
573 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
574
575 const int argc = command.GetArgumentCount ();
576
577 if (argc < 3)
578 {
579 result.AppendError ("'settings replace' takes more arguments");
580 result.SetStatus (eReturnStatusFailed);
581 return false;
582 }
583
584 const char *var_name = command.GetArgumentAtIndex (0);
585 std::string var_name_string;
586 if ((var_name == NULL) || (var_name[0] == '\0'))
587 {
588 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
589 result.SetStatus (eReturnStatusFailed);
590 return false;
591 }
592
593 var_name_string = var_name;
594 command.Shift();
595
596 const char *index_value = command.GetArgumentAtIndex (0);
597 std::string index_value_string;
598 if ((index_value == NULL) || (index_value[0] == '\0'))
599 {
600 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
601 result.SetStatus (eReturnStatusFailed);
602 return false;
603 }
604
605 index_value_string = index_value;
606 command.Shift();
607
608 const char *var_value;
609 std::string value_string;
610
611 command.GetCommandString (value_string);
612 var_value = value_string.c_str();
613
614 if ((var_value == NULL) || (var_value[0] == '\0'))
615 {
616 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
617 result.SetStatus (eReturnStatusFailed);
618 }
619 else
620 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000621 Error err = root_settings->SetVariable (var_name_string.c_str(),
622 var_value,
623 lldb::eVarSetOperationReplace,
624 false,
625 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000626 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000627 if (err.Fail ())
628 {
629 result.AppendError (err.AsCString());
630 result.SetStatus (eReturnStatusFailed);
631 }
632 else
633 result.SetStatus (eReturnStatusSuccessFinishNoResult);
634 }
635
636 return result.Succeeded();
637}
638
639int
Greg Clayton238c0a12010-09-18 01:14:36 +0000640CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000641 int &cursor_index,
642 int &cursor_char_position,
643 OptionElementVector &opt_element_vector,
644 int match_start_point,
645 int max_return_elements,
646 bool &word_complete,
647 StringList &matches)
648{
649 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
650 completion_str.erase (cursor_char_position);
651
652 // Attempting to complete variable name
653 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000654 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000655 CommandCompletions::eSettingsNameCompletion,
656 completion_str.c_str(),
657 match_start_point,
658 max_return_elements,
659 NULL,
660 word_complete,
661 matches);
662
663 return matches.GetSize();
664}
665
666//-------------------------------------------------------------------------
667// CommandObjectSettingsInsertBefore
668//-------------------------------------------------------------------------
669
Greg Clayton238c0a12010-09-18 01:14:36 +0000670CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
671 CommandObject (interpreter,
672 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000673 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000674 "settings insert-before <setting-variable-name> [<index>] <new-value>")
675{
676}
677
678CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
679{
680}
681
682bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000683CommandObjectSettingsInsertBefore::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000684 CommandReturnObject &result)
685{
686 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
687
688 const int argc = command.GetArgumentCount ();
689
690 if (argc < 3)
691 {
692 result.AppendError ("'settings insert-before' takes more arguments");
693 result.SetStatus (eReturnStatusFailed);
694 return false;
695 }
696
697 const char *var_name = command.GetArgumentAtIndex (0);
698 std::string var_name_string;
699 if ((var_name == NULL) || (var_name[0] == '\0'))
700 {
701 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
702 result.SetStatus (eReturnStatusFailed);
703 return false;
704 }
705
706 var_name_string = var_name;
707 command.Shift();
708
709 const char *index_value = command.GetArgumentAtIndex (0);
710 std::string index_value_string;
711 if ((index_value == NULL) || (index_value[0] == '\0'))
712 {
713 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
714 result.SetStatus (eReturnStatusFailed);
715 return false;
716 }
717
718 index_value_string = index_value;
719 command.Shift();
720
721 const char *var_value;
722 std::string value_string;
723
724 command.GetCommandString (value_string);
725 var_value = value_string.c_str();
726
727 if ((var_value == NULL) || (var_value[0] == '\0'))
728 {
729 result.AppendError ("'settings insert-before' command requires a valid variable value;"
730 " No value supplied");
731 result.SetStatus (eReturnStatusFailed);
732 }
733 else
734 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000735 Error err = root_settings->SetVariable (var_name_string.c_str(),
736 var_value,
737 lldb::eVarSetOperationInsertBefore,
738 false,
739 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000740 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000741 if (err.Fail ())
742 {
743 result.AppendError (err.AsCString());
744 result.SetStatus (eReturnStatusFailed);
745 }
746 else
747 result.SetStatus (eReturnStatusSuccessFinishNoResult);
748 }
749
750 return result.Succeeded();
751}
752
753
754int
Greg Clayton238c0a12010-09-18 01:14:36 +0000755CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000756 int &cursor_index,
757 int &cursor_char_position,
758 OptionElementVector &opt_element_vector,
759 int match_start_point,
760 int max_return_elements,
761 bool &word_complete,
762 StringList &matches)
763{
764 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
765 completion_str.erase (cursor_char_position);
766
767 // Attempting to complete variable name
768 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000769 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000770 CommandCompletions::eSettingsNameCompletion,
771 completion_str.c_str(),
772 match_start_point,
773 max_return_elements,
774 NULL,
775 word_complete,
776 matches);
777
778 return matches.GetSize();
779}
780
781//-------------------------------------------------------------------------
782// CommandObjectSettingInsertAfter
783//-------------------------------------------------------------------------
784
Greg Clayton238c0a12010-09-18 01:14:36 +0000785CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
786 CommandObject (interpreter,
787 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000788 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000789 "settings insert-after <setting-variable-name> [<index>] <new-value>")
790{
791}
792
793CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
794{
795}
796
797bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000798CommandObjectSettingsInsertAfter::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000799 CommandReturnObject &result)
800{
801 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
802
803 const int argc = command.GetArgumentCount ();
804
805 if (argc < 3)
806 {
807 result.AppendError ("'settings insert-after' takes more arguments");
808 result.SetStatus (eReturnStatusFailed);
809 return false;
810 }
811
812 const char *var_name = command.GetArgumentAtIndex (0);
813 std::string var_name_string;
814 if ((var_name == NULL) || (var_name[0] == '\0'))
815 {
816 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
817 result.SetStatus (eReturnStatusFailed);
818 return false;
819 }
820
821 var_name_string = var_name;
822 command.Shift();
823
824 const char *index_value = command.GetArgumentAtIndex (0);
825 std::string index_value_string;
826 if ((index_value == NULL) || (index_value[0] == '\0'))
827 {
828 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
829 result.SetStatus (eReturnStatusFailed);
830 return false;
831 }
832
833 index_value_string = index_value;
834 command.Shift();
835
836 const char *var_value;
837 std::string value_string;
838
839 command.GetCommandString (value_string);
840 var_value = value_string.c_str();
841
842 if ((var_value == NULL) || (var_value[0] == '\0'))
843 {
844 result.AppendError ("'settings insert-after' command requires a valid variable value;"
845 " No value supplied");
846 result.SetStatus (eReturnStatusFailed);
847 }
848 else
849 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000850 Error err = root_settings->SetVariable (var_name_string.c_str(),
851 var_value,
852 lldb::eVarSetOperationInsertAfter,
853 false,
854 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000855 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000856 if (err.Fail ())
857 {
858 result.AppendError (err.AsCString());
859 result.SetStatus (eReturnStatusFailed);
860 }
861 else
862 result.SetStatus (eReturnStatusSuccessFinishNoResult);
863 }
864
865 return result.Succeeded();
866}
867
868
869int
Greg Clayton238c0a12010-09-18 01:14:36 +0000870CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000871 int &cursor_index,
872 int &cursor_char_position,
873 OptionElementVector &opt_element_vector,
874 int match_start_point,
875 int max_return_elements,
876 bool &word_complete,
877 StringList &matches)
878{
879 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
880 completion_str.erase (cursor_char_position);
881
882 // Attempting to complete variable name
883 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000884 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000885 CommandCompletions::eSettingsNameCompletion,
886 completion_str.c_str(),
887 match_start_point,
888 max_return_elements,
889 NULL,
890 word_complete,
891 matches);
892
893 return matches.GetSize();
894}
895
896//-------------------------------------------------------------------------
897// CommandObjectSettingsAppend
898//-------------------------------------------------------------------------
899
Greg Clayton238c0a12010-09-18 01:14:36 +0000900CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
901 CommandObject (interpreter,
902 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000903 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000904 "settings append <setting-variable-name> <new-value>")
905{
906}
907
908CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
909{
910}
911
912bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000913CommandObjectSettingsAppend::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000914 CommandReturnObject &result)
915{
916 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
917
918 const int argc = command.GetArgumentCount ();
919
920 if (argc < 2)
921 {
922 result.AppendError ("'settings append' takes more arguments");
923 result.SetStatus (eReturnStatusFailed);
924 return false;
925 }
926
927 const char *var_name = command.GetArgumentAtIndex (0);
928 std::string var_name_string;
929 if ((var_name == NULL) || (var_name[0] == '\0'))
930 {
931 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
932 result.SetStatus (eReturnStatusFailed);
933 return false;
934 }
935
936 var_name_string = var_name;
937 command.Shift();
938
939 const char *var_value;
940 std::string value_string;
941
942 command.GetCommandString (value_string);
943 var_value = value_string.c_str();
944
945 if ((var_value == NULL) || (var_value[0] == '\0'))
946 {
947 result.AppendError ("'settings append' command requires a valid variable value;"
948 " No value supplied");
949 result.SetStatus (eReturnStatusFailed);
950 }
951 else
952 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000953 Error err = root_settings->SetVariable (var_name_string.c_str(),
954 var_value,
955 lldb::eVarSetOperationAppend,
956 false,
957 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000958 if (err.Fail ())
959 {
960 result.AppendError (err.AsCString());
961 result.SetStatus (eReturnStatusFailed);
962 }
963 else
964 result.SetStatus (eReturnStatusSuccessFinishNoResult);
965 }
966
967 return result.Succeeded();
968}
969
970
971int
Greg Clayton238c0a12010-09-18 01:14:36 +0000972CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000973 int &cursor_index,
974 int &cursor_char_position,
975 OptionElementVector &opt_element_vector,
976 int match_start_point,
977 int max_return_elements,
978 bool &word_complete,
979 StringList &matches)
980{
981 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
982 completion_str.erase (cursor_char_position);
983
984 // Attempting to complete variable name
985 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000986 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000987 CommandCompletions::eSettingsNameCompletion,
988 completion_str.c_str(),
989 match_start_point,
990 max_return_elements,
991 NULL,
992 word_complete,
993 matches);
994
995 return matches.GetSize();
996}
997
998//-------------------------------------------------------------------------
999// CommandObjectSettingsClear
1000//-------------------------------------------------------------------------
1001
Greg Clayton238c0a12010-09-18 01:14:36 +00001002CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1003 CommandObject (interpreter,
1004 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001005 "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 +00001006 "settings clear")
1007{
1008}
1009
1010CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1011{
1012}
1013
1014bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001015CommandObjectSettingsClear::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001016 CommandReturnObject &result)
1017{
1018 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1019
1020 const int argc = command.GetArgumentCount ();
1021
1022 if (argc != 1)
1023 {
1024 result.AppendError ("'setttings clear' takes exactly one argument");
1025 result.SetStatus (eReturnStatusFailed);
1026 return false;
1027 }
1028
1029 const char *var_name = command.GetArgumentAtIndex (0);
1030 if ((var_name == NULL) || (var_name[0] == '\0'))
1031 {
1032 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1033 result.SetStatus (eReturnStatusFailed);
1034 return false;
1035 }
1036
Greg Clayton238c0a12010-09-18 01:14:36 +00001037 Error err = root_settings->SetVariable (var_name,
1038 NULL,
1039 lldb::eVarSetOperationClear,
1040 false,
1041 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001042
1043 if (err.Fail ())
1044 {
1045 result.AppendError (err.AsCString());
1046 result.SetStatus (eReturnStatusFailed);
1047 }
1048 else
1049 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1050
1051 return result.Succeeded();
1052}
1053
1054
1055int
Greg Clayton238c0a12010-09-18 01:14:36 +00001056CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001057 int &cursor_index,
1058 int &cursor_char_position,
1059 OptionElementVector &opt_element_vector,
1060 int match_start_point,
1061 int max_return_elements,
1062 bool &word_complete,
1063 StringList &matches)
1064{
1065 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1066 completion_str.erase (cursor_char_position);
1067
1068 // Attempting to complete variable name
1069 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001070 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001071 CommandCompletions::eSettingsNameCompletion,
1072 completion_str.c_str(),
1073 match_start_point,
1074 max_return_elements,
1075 NULL,
1076 word_complete,
1077 matches);
1078
1079 return matches.GetSize();
1080}