blob: b1bdaaa1b0d1aae851b474eecca7682acdf3a308 [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." },
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 {
227 case 'o':
228 m_override = true;
229 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
246 m_override = false;
247 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
Greg Clayton238c0a12010-09-18 01:14:36 +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 Tice1d2aefd2010-09-09 06:25:08 +0000288 StringList value = root_settings->GetVariable (variable_name, var_type,
Greg Clayton238c0a12010-09-18 01:14:36 +0000289 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000290
291 if (value.GetSize() == 0)
292 {
293 result.AppendErrorWithFormat ("Unable to find variable named '%s'. "
294 "Try 'show' to see all variable values.\n", variable_name);
295 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 }
307
308 if (value.GetSize() == 1)
309 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
310 else
311 {
312 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
Chris Lattner0f6fa732010-09-08 22:55:31 +0000313 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000314 {
315 result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
316 }
317 }
318 result.SetStatus (eReturnStatusSuccessFinishNoResult);
319 }
320 }
321 else
322 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000323 UserSettingsController::GetAllVariableValues (m_interpreter,
324 root_settings,
325 current_prefix,
326 result.GetOutputStream(),
327 err);
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000328 if (err.Fail ())
329 {
330 result.AppendError (err.AsCString());
331 result.SetStatus (eReturnStatusFailed);
332 }
333 else
334 {
335 result.SetStatus (eReturnStatusSuccessFinishNoResult);
336 }
337 }
338
339 return result.Succeeded();
340}
341
342int
Greg Clayton238c0a12010-09-18 01:14:36 +0000343CommandObjectSettingsShow::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000344 int &cursor_index,
345 int &cursor_char_position,
346 OptionElementVector &opt_element_vector,
347 int match_start_point,
348 int max_return_elements,
349 bool &word_complete,
350 StringList &matches)
351{
352 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
353 completion_str.erase (cursor_char_position);
354
Greg Clayton238c0a12010-09-18 01:14:36 +0000355 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000356 CommandCompletions::eSettingsNameCompletion,
357 completion_str.c_str(),
358 match_start_point,
359 max_return_elements,
360 NULL,
361 word_complete,
362 matches);
363 return matches.GetSize();
364}
365
366//-------------------------------------------------------------------------
367// CommandObjectSettingsList
368//-------------------------------------------------------------------------
369
Greg Clayton238c0a12010-09-18 01:14:36 +0000370CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) :
371 CommandObject (interpreter,
372 "settings list",
Caroline Tice41ae2172010-09-15 06:56:39 +0000373 "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).",
374 "settings list [<setting-name> | <setting-name-prefix>]")
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000375{
376}
377
378CommandObjectSettingsList::~CommandObjectSettingsList()
379{
380}
381
382
383bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000384CommandObjectSettingsList::Execute ( Args& command,
Caroline Tice41ae2172010-09-15 06:56:39 +0000385 CommandReturnObject &result)
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000386{
387 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
388 std::string current_prefix = root_settings->GetLevelName().AsCString();
389
390 Error err;
391
Caroline Tice41ae2172010-09-15 06:56:39 +0000392 if (command.GetArgumentCount() == 0)
393 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000394 UserSettingsController::FindAllSettingsDescriptions (m_interpreter,
395 root_settings,
396 current_prefix,
397 result.GetOutputStream(),
398 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000399 }
400 else if (command.GetArgumentCount() == 1)
401 {
402 const char *search_name = command.GetArgumentAtIndex (0);
Greg Clayton238c0a12010-09-18 01:14:36 +0000403 UserSettingsController::FindSettingsDescriptions (m_interpreter,
404 root_settings,
405 current_prefix,
406 search_name,
407 result.GetOutputStream(),
408 err);
Caroline Tice41ae2172010-09-15 06:56:39 +0000409 }
410 else
411 {
412 result.AppendError ("Too many aguments for 'settings list' command.\n");
413 result.SetStatus (eReturnStatusFailed);
414 return false;
415 }
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000416
417 if (err.Fail ())
418 {
419 result.AppendError (err.AsCString());
420 result.SetStatus (eReturnStatusFailed);
421 }
422 else
423 {
Chris Lattner24943d22010-06-08 16:52:24 +0000424 result.SetStatus (eReturnStatusSuccessFinishNoResult);
425 }
426
427 return result.Succeeded();
428}
429
Caroline Tice41ae2172010-09-15 06:56:39 +0000430int
Greg Clayton238c0a12010-09-18 01:14:36 +0000431CommandObjectSettingsList::HandleArgumentCompletion (Args &input,
Caroline Tice41ae2172010-09-15 06:56:39 +0000432 int &cursor_index,
433 int &cursor_char_position,
434 OptionElementVector &opt_element_vector,
435 int match_start_point,
436 int max_return_elements,
437 bool &word_complete,
438 StringList &matches)
439{
440 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
441 completion_str.erase (cursor_char_position);
442
Greg Clayton238c0a12010-09-18 01:14:36 +0000443 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice41ae2172010-09-15 06:56:39 +0000444 CommandCompletions::eSettingsNameCompletion,
445 completion_str.c_str(),
446 match_start_point,
447 max_return_elements,
448 NULL,
449 word_complete,
450 matches);
451 return matches.GetSize();
452}
453
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000454//-------------------------------------------------------------------------
455// CommandObjectSettingsRemove
456//-------------------------------------------------------------------------
457
Greg Clayton238c0a12010-09-18 01:14:36 +0000458CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
459 CommandObject (interpreter,
460 "settings remove",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000461 "Remove the specified element from an internal debugger settings array or dictionary variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000462 "settings remove <setting-variable-name> [<index>|\"key\"]")
463{
464}
465
466CommandObjectSettingsRemove::~CommandObjectSettingsRemove ()
467{
468}
469
470bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000471CommandObjectSettingsRemove::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000472 CommandReturnObject &result)
473{
474 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
475
476 const int argc = command.GetArgumentCount ();
477
478 if (argc != 2)
479 {
480 result.AppendError ("'settings remove' takes two arguments");
481 result.SetStatus (eReturnStatusFailed);
482 return false;
483 }
484
485 const char *var_name = command.GetArgumentAtIndex (0);
486 std::string var_name_string;
487 if ((var_name == NULL) || (var_name[0] == '\0'))
488 {
489 result.AppendError ("'settings remove' command requires a valid variable name; No value supplied");
490 result.SetStatus (eReturnStatusFailed);
491 return false;
492 }
493
494 var_name_string = var_name;
495 command.Shift();
496
497 const char *index_value = command.GetArgumentAtIndex (0);
498 std::string index_value_string;
499 if ((index_value == NULL) || (index_value[0] == '\0'))
500 {
501 result.AppendError ("'settings remove' command requires an index or key value; no value supplied");
502 result.SetStatus (eReturnStatusFailed);
503 return false;
504 }
505
506 index_value_string = index_value;
507
Greg Clayton238c0a12010-09-18 01:14:36 +0000508 Error err = root_settings->SetVariable (var_name_string.c_str(),
509 NULL,
510 lldb::eVarSetOperationRemove,
511 false,
512 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000513 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000514 if (err.Fail ())
515 {
516 result.AppendError (err.AsCString());
517 result.SetStatus (eReturnStatusFailed);
518 }
519 else
520 result.SetStatus (eReturnStatusSuccessFinishNoResult);
521
522 return result.Succeeded();
523}
524
525int
Greg Clayton238c0a12010-09-18 01:14:36 +0000526CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000527 int &cursor_index,
528 int &cursor_char_position,
529 OptionElementVector &opt_element_vector,
530 int match_start_point,
531 int max_return_elements,
532 bool &word_complete,
533 StringList &matches)
534{
535 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
536 completion_str.erase (cursor_char_position);
537
538 // Attempting to complete variable name
539 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000540 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000541 CommandCompletions::eSettingsNameCompletion,
542 completion_str.c_str(),
543 match_start_point,
544 max_return_elements,
545 NULL,
546 word_complete,
547 matches);
548
549 return matches.GetSize();
550}
551
552//-------------------------------------------------------------------------
553// CommandObjectSettingsReplace
554//-------------------------------------------------------------------------
555
Greg Clayton238c0a12010-09-18 01:14:36 +0000556CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
557 CommandObject (interpreter,
558 "settings replace",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000559 "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 +0000560 "settings replace <setting-variable-name> [<index>|\"<key>\"] <new-value>")
561{
562}
563
564CommandObjectSettingsReplace::~CommandObjectSettingsReplace ()
565{
566}
567
568bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000569CommandObjectSettingsReplace::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000570 CommandReturnObject &result)
571{
572 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
573
574 const int argc = command.GetArgumentCount ();
575
576 if (argc < 3)
577 {
578 result.AppendError ("'settings replace' takes more arguments");
579 result.SetStatus (eReturnStatusFailed);
580 return false;
581 }
582
583 const char *var_name = command.GetArgumentAtIndex (0);
584 std::string var_name_string;
585 if ((var_name == NULL) || (var_name[0] == '\0'))
586 {
587 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
588 result.SetStatus (eReturnStatusFailed);
589 return false;
590 }
591
592 var_name_string = var_name;
593 command.Shift();
594
595 const char *index_value = command.GetArgumentAtIndex (0);
596 std::string index_value_string;
597 if ((index_value == NULL) || (index_value[0] == '\0'))
598 {
599 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
600 result.SetStatus (eReturnStatusFailed);
601 return false;
602 }
603
604 index_value_string = index_value;
605 command.Shift();
606
607 const char *var_value;
608 std::string value_string;
609
610 command.GetCommandString (value_string);
611 var_value = value_string.c_str();
612
613 if ((var_value == NULL) || (var_value[0] == '\0'))
614 {
615 result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
616 result.SetStatus (eReturnStatusFailed);
617 }
618 else
619 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000620 Error err = root_settings->SetVariable (var_name_string.c_str(),
621 var_value,
622 lldb::eVarSetOperationReplace,
623 false,
624 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000625 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000626 if (err.Fail ())
627 {
628 result.AppendError (err.AsCString());
629 result.SetStatus (eReturnStatusFailed);
630 }
631 else
632 result.SetStatus (eReturnStatusSuccessFinishNoResult);
633 }
634
635 return result.Succeeded();
636}
637
638int
Greg Clayton238c0a12010-09-18 01:14:36 +0000639CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000640 int &cursor_index,
641 int &cursor_char_position,
642 OptionElementVector &opt_element_vector,
643 int match_start_point,
644 int max_return_elements,
645 bool &word_complete,
646 StringList &matches)
647{
648 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
649 completion_str.erase (cursor_char_position);
650
651 // Attempting to complete variable name
652 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000653 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000654 CommandCompletions::eSettingsNameCompletion,
655 completion_str.c_str(),
656 match_start_point,
657 max_return_elements,
658 NULL,
659 word_complete,
660 matches);
661
662 return matches.GetSize();
663}
664
665//-------------------------------------------------------------------------
666// CommandObjectSettingsInsertBefore
667//-------------------------------------------------------------------------
668
Greg Clayton238c0a12010-09-18 01:14:36 +0000669CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
670 CommandObject (interpreter,
671 "settings insert-before",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000672 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000673 "settings insert-before <setting-variable-name> [<index>] <new-value>")
674{
675}
676
677CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore ()
678{
679}
680
681bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000682CommandObjectSettingsInsertBefore::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000683 CommandReturnObject &result)
684{
685 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
686
687 const int argc = command.GetArgumentCount ();
688
689 if (argc < 3)
690 {
691 result.AppendError ("'settings insert-before' takes more arguments");
692 result.SetStatus (eReturnStatusFailed);
693 return false;
694 }
695
696 const char *var_name = command.GetArgumentAtIndex (0);
697 std::string var_name_string;
698 if ((var_name == NULL) || (var_name[0] == '\0'))
699 {
700 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
701 result.SetStatus (eReturnStatusFailed);
702 return false;
703 }
704
705 var_name_string = var_name;
706 command.Shift();
707
708 const char *index_value = command.GetArgumentAtIndex (0);
709 std::string index_value_string;
710 if ((index_value == NULL) || (index_value[0] == '\0'))
711 {
712 result.AppendError ("'settings insert-before' command requires an index value; no value supplied");
713 result.SetStatus (eReturnStatusFailed);
714 return false;
715 }
716
717 index_value_string = index_value;
718 command.Shift();
719
720 const char *var_value;
721 std::string value_string;
722
723 command.GetCommandString (value_string);
724 var_value = value_string.c_str();
725
726 if ((var_value == NULL) || (var_value[0] == '\0'))
727 {
728 result.AppendError ("'settings insert-before' command requires a valid variable value;"
729 " No value supplied");
730 result.SetStatus (eReturnStatusFailed);
731 }
732 else
733 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000734 Error err = root_settings->SetVariable (var_name_string.c_str(),
735 var_value,
736 lldb::eVarSetOperationInsertBefore,
737 false,
738 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000739 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000740 if (err.Fail ())
741 {
742 result.AppendError (err.AsCString());
743 result.SetStatus (eReturnStatusFailed);
744 }
745 else
746 result.SetStatus (eReturnStatusSuccessFinishNoResult);
747 }
748
749 return result.Succeeded();
750}
751
752
753int
Greg Clayton238c0a12010-09-18 01:14:36 +0000754CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000755 int &cursor_index,
756 int &cursor_char_position,
757 OptionElementVector &opt_element_vector,
758 int match_start_point,
759 int max_return_elements,
760 bool &word_complete,
761 StringList &matches)
762{
763 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
764 completion_str.erase (cursor_char_position);
765
766 // Attempting to complete variable name
767 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000768 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000769 CommandCompletions::eSettingsNameCompletion,
770 completion_str.c_str(),
771 match_start_point,
772 max_return_elements,
773 NULL,
774 word_complete,
775 matches);
776
777 return matches.GetSize();
778}
779
780//-------------------------------------------------------------------------
781// CommandObjectSettingInsertAfter
782//-------------------------------------------------------------------------
783
Greg Clayton238c0a12010-09-18 01:14:36 +0000784CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
785 CommandObject (interpreter,
786 "settings insert-after",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000787 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000788 "settings insert-after <setting-variable-name> [<index>] <new-value>")
789{
790}
791
792CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter ()
793{
794}
795
796bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000797CommandObjectSettingsInsertAfter::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000798 CommandReturnObject &result)
799{
800 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
801
802 const int argc = command.GetArgumentCount ();
803
804 if (argc < 3)
805 {
806 result.AppendError ("'settings insert-after' takes more arguments");
807 result.SetStatus (eReturnStatusFailed);
808 return false;
809 }
810
811 const char *var_name = command.GetArgumentAtIndex (0);
812 std::string var_name_string;
813 if ((var_name == NULL) || (var_name[0] == '\0'))
814 {
815 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
816 result.SetStatus (eReturnStatusFailed);
817 return false;
818 }
819
820 var_name_string = var_name;
821 command.Shift();
822
823 const char *index_value = command.GetArgumentAtIndex (0);
824 std::string index_value_string;
825 if ((index_value == NULL) || (index_value[0] == '\0'))
826 {
827 result.AppendError ("'settings insert-after' command requires an index value; no value supplied");
828 result.SetStatus (eReturnStatusFailed);
829 return false;
830 }
831
832 index_value_string = index_value;
833 command.Shift();
834
835 const char *var_value;
836 std::string value_string;
837
838 command.GetCommandString (value_string);
839 var_value = value_string.c_str();
840
841 if ((var_value == NULL) || (var_value[0] == '\0'))
842 {
843 result.AppendError ("'settings insert-after' command requires a valid variable value;"
844 " No value supplied");
845 result.SetStatus (eReturnStatusFailed);
846 }
847 else
848 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000849 Error err = root_settings->SetVariable (var_name_string.c_str(),
850 var_value,
851 lldb::eVarSetOperationInsertAfter,
852 false,
853 m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Caroline Tice1d2aefd2010-09-09 06:25:08 +0000854 index_value_string.c_str());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000855 if (err.Fail ())
856 {
857 result.AppendError (err.AsCString());
858 result.SetStatus (eReturnStatusFailed);
859 }
860 else
861 result.SetStatus (eReturnStatusSuccessFinishNoResult);
862 }
863
864 return result.Succeeded();
865}
866
867
868int
Greg Clayton238c0a12010-09-18 01:14:36 +0000869CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000870 int &cursor_index,
871 int &cursor_char_position,
872 OptionElementVector &opt_element_vector,
873 int match_start_point,
874 int max_return_elements,
875 bool &word_complete,
876 StringList &matches)
877{
878 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
879 completion_str.erase (cursor_char_position);
880
881 // Attempting to complete variable name
882 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000883 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000884 CommandCompletions::eSettingsNameCompletion,
885 completion_str.c_str(),
886 match_start_point,
887 max_return_elements,
888 NULL,
889 word_complete,
890 matches);
891
892 return matches.GetSize();
893}
894
895//-------------------------------------------------------------------------
896// CommandObjectSettingsAppend
897//-------------------------------------------------------------------------
898
Greg Clayton238c0a12010-09-18 01:14:36 +0000899CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
900 CommandObject (interpreter,
901 "settings append",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000902 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000903 "settings append <setting-variable-name> <new-value>")
904{
905}
906
907CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
908{
909}
910
911bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000912CommandObjectSettingsAppend::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000913 CommandReturnObject &result)
914{
915 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
916
917 const int argc = command.GetArgumentCount ();
918
919 if (argc < 2)
920 {
921 result.AppendError ("'settings append' takes more arguments");
922 result.SetStatus (eReturnStatusFailed);
923 return false;
924 }
925
926 const char *var_name = command.GetArgumentAtIndex (0);
927 std::string var_name_string;
928 if ((var_name == NULL) || (var_name[0] == '\0'))
929 {
930 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
931 result.SetStatus (eReturnStatusFailed);
932 return false;
933 }
934
935 var_name_string = var_name;
936 command.Shift();
937
938 const char *var_value;
939 std::string value_string;
940
941 command.GetCommandString (value_string);
942 var_value = value_string.c_str();
943
944 if ((var_value == NULL) || (var_value[0] == '\0'))
945 {
946 result.AppendError ("'settings append' command requires a valid variable value;"
947 " No value supplied");
948 result.SetStatus (eReturnStatusFailed);
949 }
950 else
951 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000952 Error err = root_settings->SetVariable (var_name_string.c_str(),
953 var_value,
954 lldb::eVarSetOperationAppend,
955 false,
956 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000957 if (err.Fail ())
958 {
959 result.AppendError (err.AsCString());
960 result.SetStatus (eReturnStatusFailed);
961 }
962 else
963 result.SetStatus (eReturnStatusSuccessFinishNoResult);
964 }
965
966 return result.Succeeded();
967}
968
969
970int
Greg Clayton238c0a12010-09-18 01:14:36 +0000971CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000972 int &cursor_index,
973 int &cursor_char_position,
974 OptionElementVector &opt_element_vector,
975 int match_start_point,
976 int max_return_elements,
977 bool &word_complete,
978 StringList &matches)
979{
980 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
981 completion_str.erase (cursor_char_position);
982
983 // Attempting to complete variable name
984 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +0000985 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +0000986 CommandCompletions::eSettingsNameCompletion,
987 completion_str.c_str(),
988 match_start_point,
989 max_return_elements,
990 NULL,
991 word_complete,
992 matches);
993
994 return matches.GetSize();
995}
996
997//-------------------------------------------------------------------------
998// CommandObjectSettingsClear
999//-------------------------------------------------------------------------
1000
Greg Clayton238c0a12010-09-18 01:14:36 +00001001CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1002 CommandObject (interpreter,
1003 "settings clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001004 "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 +00001005 "settings clear")
1006{
1007}
1008
1009CommandObjectSettingsClear::~CommandObjectSettingsClear ()
1010{
1011}
1012
1013bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001014CommandObjectSettingsClear::Execute ( Args& command,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001015 CommandReturnObject &result)
1016{
1017 UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
1018
1019 const int argc = command.GetArgumentCount ();
1020
1021 if (argc != 1)
1022 {
1023 result.AppendError ("'setttings clear' takes exactly one argument");
1024 result.SetStatus (eReturnStatusFailed);
1025 return false;
1026 }
1027
1028 const char *var_name = command.GetArgumentAtIndex (0);
1029 if ((var_name == NULL) || (var_name[0] == '\0'))
1030 {
1031 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1032 result.SetStatus (eReturnStatusFailed);
1033 return false;
1034 }
1035
Greg Clayton238c0a12010-09-18 01:14:36 +00001036 Error err = root_settings->SetVariable (var_name,
1037 NULL,
1038 lldb::eVarSetOperationClear,
1039 false,
1040 m_interpreter.GetDebugger().GetInstanceName().AsCString());
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001041
1042 if (err.Fail ())
1043 {
1044 result.AppendError (err.AsCString());
1045 result.SetStatus (eReturnStatusFailed);
1046 }
1047 else
1048 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1049
1050 return result.Succeeded();
1051}
1052
1053
1054int
Greg Clayton238c0a12010-09-18 01:14:36 +00001055CommandObjectSettingsClear::HandleArgumentCompletion (Args &input,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001056 int &cursor_index,
1057 int &cursor_char_position,
1058 OptionElementVector &opt_element_vector,
1059 int match_start_point,
1060 int max_return_elements,
1061 bool &word_complete,
1062 StringList &matches)
1063{
1064 std::string completion_str (input.GetArgumentAtIndex (cursor_index));
1065 completion_str.erase (cursor_char_position);
1066
1067 // Attempting to complete variable name
1068 if (cursor_index < 2)
Greg Clayton238c0a12010-09-18 01:14:36 +00001069 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Caroline Tice6e4c5ce2010-09-04 00:03:46 +00001070 CommandCompletions::eSettingsNameCompletion,
1071 completion_str.c_str(),
1072 match_start_point,
1073 max_return_elements,
1074 NULL,
1075 word_complete,
1076 matches);
1077
1078 return matches.GetSize();
1079}