blob: ccbf98c767f198267e78880b8068cbc5608826c6 [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Tice3df9a8d2010-09-04 00:03:46 +000018#include "lldb/Interpreter/CommandCompletions.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000019#include "lldb/Interpreter/OptionValueProperties.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
Jim Ingham5a988412012-06-08 21:56:10 +000023#include "llvm/ADT/StringRef.h"
24
Jim Ingham5a988412012-06-08 21:56:10 +000025//-------------------------------------------------------------------------
26// CommandObjectSettingsSet
27//-------------------------------------------------------------------------
28
29class CommandObjectSettingsSet : public CommandObjectRaw
30{
31public:
32 CommandObjectSettingsSet (CommandInterpreter &interpreter) :
33 CommandObjectRaw (interpreter,
34 "settings set",
35 "Set or change the value of a single debugger setting variable.",
36 NULL),
37 m_options (interpreter)
38 {
39 CommandArgumentEntry arg1;
40 CommandArgumentEntry arg2;
41 CommandArgumentData var_name_arg;
42 CommandArgumentData value_arg;
43
44 // Define the first (and only) variant of this arg.
45 var_name_arg.arg_type = eArgTypeSettingVariableName;
46 var_name_arg.arg_repetition = eArgRepeatPlain;
47
48 // There is only one variant this argument could be; put it into the argument entry.
49 arg1.push_back (var_name_arg);
50
51 // Define the first (and only) variant of this arg.
52 value_arg.arg_type = eArgTypeValue;
53 value_arg.arg_repetition = eArgRepeatPlain;
54
55 // There is only one variant this argument could be; put it into the argument entry.
56 arg2.push_back (value_arg);
57
58 // Push the data for the first argument into the m_arguments vector.
59 m_arguments.push_back (arg1);
60 m_arguments.push_back (arg2);
61
62 SetHelpLong (
63"When setting a dictionary or array variable, you can set multiple entries \n\
64at once by giving the values to the set command. For example: \n\
65\n\
Greg Clayton67cc0632012-08-22 17:17:09 +000066(lldb) settings set target.run-args value1 value2 value3 \n\
67(lldb) settings set target.env-vars MYPATH=~/.:/usr/bin SOME_ENV_VAR=12345 \n\
Jim Ingham5a988412012-06-08 21:56:10 +000068\n\
69(lldb) settings show target.run-args \n\
70 [0]: 'value1' \n\
71 [1]: 'value2' \n\
72 [3]: 'value3' \n\
73(lldb) settings show target.env-vars \n\
74 'MYPATH=~/.:/usr/bin'\n\
75 'SOME_ENV_VAR=12345' \n\
76\n\
Jim Ingham5a988412012-06-08 21:56:10 +000077Warning: The 'set' command re-sets the entire array or dictionary. If you \n\
78just want to add, remove or update individual values (or add something to \n\
79the end), use one of the other settings sub-commands: append, replace, \n\
80insert-before or insert-after.\n");
81
82 }
83
84
85 virtual
86 ~CommandObjectSettingsSet () {}
87
88 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
89 virtual bool
90 WantsCompletion() { return true; }
91
92 virtual Options *
93 GetOptions ()
94 {
95 return &m_options;
96 }
97
98 class CommandOptions : public Options
99 {
100 public:
101
102 CommandOptions (CommandInterpreter &interpreter) :
103 Options (interpreter),
Greg Clayton67cc0632012-08-22 17:17:09 +0000104 m_global (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000105 {
106 }
107
108 virtual
109 ~CommandOptions () {}
110
111 virtual Error
112 SetOptionValue (uint32_t option_idx, const char *option_arg)
113 {
114 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000115 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +0000116
117 switch (short_option)
118 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000119 case 'g':
120 m_global = true;
Jim Ingham5a988412012-06-08 21:56:10 +0000121 break;
122 default:
123 error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option);
124 break;
125 }
126
127 return error;
128 }
129
130 void
131 OptionParsingStarting ()
132 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000133 m_global = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000134 }
135
136 const OptionDefinition*
137 GetDefinitions ()
138 {
139 return g_option_table;
140 }
141
142 // Options table: Required for subclasses of Options.
143
144 static OptionDefinition g_option_table[];
145
146 // Instance variables to hold the values for command options.
147
Greg Clayton67cc0632012-08-22 17:17:09 +0000148 bool m_global;
Jim Ingham5a988412012-06-08 21:56:10 +0000149 };
150
151 virtual int
152 HandleArgumentCompletion (Args &input,
153 int &cursor_index,
154 int &cursor_char_position,
155 OptionElementVector &opt_element_vector,
156 int match_start_point,
157 int max_return_elements,
158 bool &word_complete,
159 StringList &matches)
160 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000161 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000162
Greg Clayton67cc0632012-08-22 17:17:09 +0000163 const size_t argc = input.GetArgumentCount();
164 const char *arg = NULL;
165 int setting_var_idx;
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000166 for (setting_var_idx = 1; setting_var_idx < static_cast<int>(argc);
167 ++setting_var_idx)
Jim Ingham5a988412012-06-08 21:56:10 +0000168 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000169 arg = input.GetArgumentAtIndex(setting_var_idx);
170 if (arg && arg[0] != '-')
171 break; // We found our setting variable name index
172 }
173 if (cursor_index == setting_var_idx)
174 {
175 // Attempting to complete setting variable name
Jim Ingham5a988412012-06-08 21:56:10 +0000176 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
177 CommandCompletions::eSettingsNameCompletion,
178 completion_str.c_str(),
179 match_start_point,
180 max_return_elements,
181 NULL,
182 word_complete,
183 matches);
Jim Ingham5a988412012-06-08 21:56:10 +0000184 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000185 else
Jim Ingham5a988412012-06-08 21:56:10 +0000186 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000187 arg = input.GetArgumentAtIndex(cursor_index);
188
189 if (arg)
Jim Ingham5a988412012-06-08 21:56:10 +0000190 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000191 if (arg[0] == '-')
192 {
193 // Complete option name
194 }
195 else
196 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000197 // Complete setting value
198 const char *setting_var_name = input.GetArgumentAtIndex(setting_var_idx);
199 Error error;
Greg Claytonf9fc6092013-01-09 19:44:40 +0000200 lldb::OptionValueSP value_sp (m_interpreter.GetDebugger().GetPropertyValue(&m_exe_ctx, setting_var_name, false, error));
Greg Clayton67cc0632012-08-22 17:17:09 +0000201 if (value_sp)
202 {
203 value_sp->AutoComplete (m_interpreter,
204 completion_str.c_str(),
205 match_start_point,
206 max_return_elements,
207 word_complete,
208 matches);
209 }
210 }
Jim Ingham5a988412012-06-08 21:56:10 +0000211 }
212 }
Jim Ingham5a988412012-06-08 21:56:10 +0000213 return matches.GetSize();
214 }
215
216protected:
217 virtual bool
218 DoExecute (const char *command, CommandReturnObject &result)
219 {
Jim Ingham5a988412012-06-08 21:56:10 +0000220 Args cmd_args(command);
221
222 // Process possible options.
223 if (!ParseOptions (cmd_args, result))
224 return false;
225
Greg Clayton67cc0632012-08-22 17:17:09 +0000226 const size_t argc = cmd_args.GetArgumentCount ();
227 if ((argc < 2) && (!m_options.m_global))
Jim Ingham5a988412012-06-08 21:56:10 +0000228 {
229 result.AppendError ("'settings set' takes more arguments");
230 result.SetStatus (eReturnStatusFailed);
231 return false;
232 }
233
234 const char *var_name = cmd_args.GetArgumentAtIndex (0);
235 if ((var_name == NULL) || (var_name[0] == '\0'))
236 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000237 result.AppendError ("'settings set' command requires a valid variable name");
Jim Ingham5a988412012-06-08 21:56:10 +0000238 result.SetStatus (eReturnStatusFailed);
239 return false;
240 }
241
242 // Split the raw command into var_name and value pair.
Jim Ingham5a988412012-06-08 21:56:10 +0000243 llvm::StringRef raw_str(command);
Greg Clayton30820f02013-03-05 23:52:49 +0000244 std::string var_value_string = raw_str.split(var_name).second.str();
Pavel Labathdf50f942015-02-16 13:13:39 +0000245 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, false, false);
Jim Ingham5a988412012-06-08 21:56:10 +0000246
Greg Clayton67cc0632012-08-22 17:17:09 +0000247 Error error;
248 if (m_options.m_global)
Jim Ingham5a988412012-06-08 21:56:10 +0000249 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000250 error = m_interpreter.GetDebugger().SetPropertyValue (NULL,
251 eVarSetOperationAssign,
252 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +0000253 var_value_cstr);
Greg Clayton67cc0632012-08-22 17:17:09 +0000254 }
255
256 if (error.Success())
257 {
Enrico Granata84a53df2013-05-20 22:29:23 +0000258 // FIXME this is the same issue as the one in commands script import
259 // we could be setting target.load-script-from-symbol-file which would cause
260 // Python scripts to be loaded, which could run LLDB commands
261 // (e.g. settings set target.process.python-os-plugin-path) and cause a crash
262 // if we did not clear the command's exe_ctx first
263 ExecutionContext exe_ctx(m_exe_ctx);
264 m_exe_ctx.Clear();
265 error = m_interpreter.GetDebugger().SetPropertyValue (&exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +0000266 eVarSetOperationAssign,
267 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +0000268 var_value_cstr);
Greg Clayton67cc0632012-08-22 17:17:09 +0000269 }
270
271 if (error.Fail())
272 {
273 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +0000274 result.SetStatus (eReturnStatusFailed);
Greg Clayton67cc0632012-08-22 17:17:09 +0000275 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000276 }
277 else
278 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000279 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000280 }
281
282 return result.Succeeded();
283 }
284private:
285 CommandOptions m_options;
286};
287
288OptionDefinition
289CommandObjectSettingsSet::CommandOptions::g_option_table[] =
290{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000291 { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Apply the new value to the global default value." },
292 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +0000293};
294
295
296//-------------------------------------------------------------------------
297// CommandObjectSettingsShow -- Show current values
298//-------------------------------------------------------------------------
299
300class CommandObjectSettingsShow : public CommandObjectParsed
301{
302public:
303 CommandObjectSettingsShow (CommandInterpreter &interpreter) :
304 CommandObjectParsed (interpreter,
305 "settings show",
306 "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
307 NULL)
308 {
309 CommandArgumentEntry arg1;
310 CommandArgumentData var_name_arg;
311
312 // Define the first (and only) variant of this arg.
313 var_name_arg.arg_type = eArgTypeSettingVariableName;
314 var_name_arg.arg_repetition = eArgRepeatOptional;
315
316 // There is only one variant this argument could be; put it into the argument entry.
317 arg1.push_back (var_name_arg);
318
319 // Push the data for the first argument into the m_arguments vector.
320 m_arguments.push_back (arg1);
321 }
322
323 virtual
324 ~CommandObjectSettingsShow () {}
325
326
327 virtual int
328 HandleArgumentCompletion (Args &input,
329 int &cursor_index,
330 int &cursor_char_position,
331 OptionElementVector &opt_element_vector,
332 int match_start_point,
333 int max_return_elements,
334 bool &word_complete,
335 StringList &matches)
336 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000337 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000338
339 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
340 CommandCompletions::eSettingsNameCompletion,
341 completion_str.c_str(),
342 match_start_point,
343 max_return_elements,
344 NULL,
345 word_complete,
346 matches);
347 return matches.GetSize();
348 }
349
350protected:
351 virtual bool
Greg Clayton67cc0632012-08-22 17:17:09 +0000352 DoExecute (Args& args, CommandReturnObject &result)
Jim Ingham5a988412012-06-08 21:56:10 +0000353 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000354 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000355
Greg Clayton67cc0632012-08-22 17:17:09 +0000356 const size_t argc = args.GetArgumentCount ();
357 if (argc > 0)
Jim Ingham5a988412012-06-08 21:56:10 +0000358 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000359 for (size_t i=0; i<argc; ++i)
Jim Ingham5a988412012-06-08 21:56:10 +0000360 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000361 const char *property_path = args.GetArgumentAtIndex (i);
362
Greg Claytonf9fc6092013-01-09 19:44:40 +0000363 Error error(m_interpreter.GetDebugger().DumpPropertyValue (&m_exe_ctx, result.GetOutputStream(), property_path, OptionValue::eDumpGroupValue));
Greg Clayton67cc0632012-08-22 17:17:09 +0000364 if (error.Success())
365 {
366 result.GetOutputStream().EOL();
367 }
368 else
369 {
370 result.AppendError (error.AsCString());
371 result.SetStatus (eReturnStatusFailed);
372 }
Jim Ingham5a988412012-06-08 21:56:10 +0000373 }
374 }
375 else
376 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000377 m_interpreter.GetDebugger().DumpAllPropertyValues (&m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
Jim Ingham5a988412012-06-08 21:56:10 +0000378 }
379
380 return result.Succeeded();
381 }
382};
383
384//-------------------------------------------------------------------------
385// CommandObjectSettingsList -- List settable variables
386//-------------------------------------------------------------------------
387
388class CommandObjectSettingsList : public CommandObjectParsed
389{
390public:
391 CommandObjectSettingsList (CommandInterpreter &interpreter) :
392 CommandObjectParsed (interpreter,
393 "settings list",
394 "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).",
395 NULL)
396 {
397 CommandArgumentEntry arg;
398 CommandArgumentData var_name_arg;
399 CommandArgumentData prefix_name_arg;
400
401 // Define the first variant of this arg.
402 var_name_arg.arg_type = eArgTypeSettingVariableName;
403 var_name_arg.arg_repetition = eArgRepeatOptional;
404
405 // Define the second variant of this arg.
406 prefix_name_arg.arg_type = eArgTypeSettingPrefix;
407 prefix_name_arg.arg_repetition = eArgRepeatOptional;
408
409 arg.push_back (var_name_arg);
410 arg.push_back (prefix_name_arg);
411
412 // Push the data for the first argument into the m_arguments vector.
413 m_arguments.push_back (arg);
414 }
415
416 virtual
417 ~CommandObjectSettingsList () {}
418
419 virtual int
420 HandleArgumentCompletion (Args &input,
421 int &cursor_index,
422 int &cursor_char_position,
423 OptionElementVector &opt_element_vector,
424 int match_start_point,
425 int max_return_elements,
426 bool &word_complete,
427 StringList &matches)
428 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000429 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000430
431 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
432 CommandCompletions::eSettingsNameCompletion,
433 completion_str.c_str(),
434 match_start_point,
435 max_return_elements,
436 NULL,
437 word_complete,
438 matches);
439 return matches.GetSize();
440 }
441
442protected:
443 virtual bool
Greg Clayton67cc0632012-08-22 17:17:09 +0000444 DoExecute (Args& args, CommandReturnObject &result)
Jim Ingham5a988412012-06-08 21:56:10 +0000445 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000446 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000447
Greg Clayton67cc0632012-08-22 17:17:09 +0000448 const bool will_modify = false;
449 const size_t argc = args.GetArgumentCount ();
450 if (argc > 0)
451 {
452 const bool dump_qualified_name = true;
Jim Ingham5a988412012-06-08 21:56:10 +0000453
Greg Clayton67cc0632012-08-22 17:17:09 +0000454 for (size_t i=0; i<argc; ++i)
455 {
456 const char *property_path = args.GetArgumentAtIndex (i);
457
Greg Claytonf9fc6092013-01-09 19:44:40 +0000458 const Property *property = m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath (&m_exe_ctx, will_modify, property_path);
Greg Clayton67cc0632012-08-22 17:17:09 +0000459
460 if (property)
461 {
462 property->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
463 }
464 else
465 {
466 result.AppendErrorWithFormat ("invalid property path '%s'", property_path);
467 result.SetStatus (eReturnStatusFailed);
468 }
469 }
Jim Ingham5a988412012-06-08 21:56:10 +0000470 }
471 else
472 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000473 m_interpreter.GetDebugger().DumpAllDescriptions (m_interpreter, result.GetOutputStream());
Jim Ingham5a988412012-06-08 21:56:10 +0000474 }
475
476 return result.Succeeded();
477 }
478};
479
480//-------------------------------------------------------------------------
481// CommandObjectSettingsRemove
482//-------------------------------------------------------------------------
483
Greg Clayton67cc0632012-08-22 17:17:09 +0000484class CommandObjectSettingsRemove : public CommandObjectRaw
Jim Ingham5a988412012-06-08 21:56:10 +0000485{
486public:
487 CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
Greg Clayton67cc0632012-08-22 17:17:09 +0000488 CommandObjectRaw (interpreter,
489 "settings remove",
490 "Remove the specified element from an array or dictionary settings variable.",
491 NULL)
Jim Ingham5a988412012-06-08 21:56:10 +0000492 {
493 CommandArgumentEntry arg1;
494 CommandArgumentEntry arg2;
495 CommandArgumentData var_name_arg;
496 CommandArgumentData index_arg;
497 CommandArgumentData key_arg;
498
499 // Define the first (and only) variant of this arg.
500 var_name_arg.arg_type = eArgTypeSettingVariableName;
501 var_name_arg.arg_repetition = eArgRepeatPlain;
502
503 // There is only one variant this argument could be; put it into the argument entry.
504 arg1.push_back (var_name_arg);
505
506 // Define the first variant of this arg.
507 index_arg.arg_type = eArgTypeSettingIndex;
508 index_arg.arg_repetition = eArgRepeatPlain;
509
510 // Define the second variant of this arg.
511 key_arg.arg_type = eArgTypeSettingKey;
512 key_arg.arg_repetition = eArgRepeatPlain;
513
514 // Push both variants into this arg
515 arg2.push_back (index_arg);
516 arg2.push_back (key_arg);
517
518 // Push the data for the first argument into the m_arguments vector.
519 m_arguments.push_back (arg1);
520 m_arguments.push_back (arg2);
521 }
522
523 virtual
524 ~CommandObjectSettingsRemove () {}
525
526 virtual int
527 HandleArgumentCompletion (Args &input,
528 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 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000536 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000537
538 // Attempting to complete variable name
539 if (cursor_index < 2)
540 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
541 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
552protected:
553 virtual bool
Greg Clayton67cc0632012-08-22 17:17:09 +0000554 DoExecute (const char *command, CommandReturnObject &result)
Jim Ingham5a988412012-06-08 21:56:10 +0000555 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000556 result.SetStatus (eReturnStatusSuccessFinishNoResult);
557
558 Args cmd_args(command);
559
560 // Process possible options.
561 if (!ParseOptions (cmd_args, result))
562 return false;
563
564 const size_t argc = cmd_args.GetArgumentCount ();
565 if (argc == 0)
Jim Ingham5a988412012-06-08 21:56:10 +0000566 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000567 result.AppendError ("'settings set' takes an array or dictionary item, or an array followed by one or more indexes, or a dictionary followed by one or more key names to remove");
Jim Ingham5a988412012-06-08 21:56:10 +0000568 result.SetStatus (eReturnStatusFailed);
569 return false;
570 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000571
572 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Jim Ingham5a988412012-06-08 21:56:10 +0000573 if ((var_name == NULL) || (var_name[0] == '\0'))
574 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000575 result.AppendError ("'settings set' command requires a valid variable name");
Jim Ingham5a988412012-06-08 21:56:10 +0000576 result.SetStatus (eReturnStatusFailed);
577 return false;
578 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000579
580 // Split the raw command into var_name and value pair.
Greg Clayton67cc0632012-08-22 17:17:09 +0000581 llvm::StringRef raw_str(command);
Greg Clayton30820f02013-03-05 23:52:49 +0000582 std::string var_value_string = raw_str.split(var_name).second.str();
583 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
Greg Clayton67cc0632012-08-22 17:17:09 +0000584
Greg Claytonf9fc6092013-01-09 19:44:40 +0000585 Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +0000586 eVarSetOperationRemove,
587 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +0000588 var_value_cstr));
Greg Clayton67cc0632012-08-22 17:17:09 +0000589 if (error.Fail())
Jim Ingham5a988412012-06-08 21:56:10 +0000590 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000591 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +0000592 result.SetStatus (eReturnStatusFailed);
593 return false;
594 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000595
Jim Ingham5a988412012-06-08 21:56:10 +0000596 return result.Succeeded();
597 }
598};
599
600//-------------------------------------------------------------------------
601// CommandObjectSettingsReplace
602//-------------------------------------------------------------------------
603
604class CommandObjectSettingsReplace : public CommandObjectRaw
605{
606public:
607 CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
608 CommandObjectRaw (interpreter,
609 "settings replace",
610 "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
611 NULL)
612 {
613 CommandArgumentEntry arg1;
614 CommandArgumentEntry arg2;
615 CommandArgumentEntry arg3;
616 CommandArgumentData var_name_arg;
617 CommandArgumentData index_arg;
618 CommandArgumentData key_arg;
619 CommandArgumentData value_arg;
620
621 // Define the first (and only) variant of this arg.
622 var_name_arg.arg_type = eArgTypeSettingVariableName;
623 var_name_arg.arg_repetition = eArgRepeatPlain;
624
625 // There is only one variant this argument could be; put it into the argument entry.
626 arg1.push_back (var_name_arg);
627
628 // Define the first (variant of this arg.
629 index_arg.arg_type = eArgTypeSettingIndex;
630 index_arg.arg_repetition = eArgRepeatPlain;
631
632 // Define the second (variant of this arg.
633 key_arg.arg_type = eArgTypeSettingKey;
634 key_arg.arg_repetition = eArgRepeatPlain;
635
636 // Put both variants into this arg
637 arg2.push_back (index_arg);
638 arg2.push_back (key_arg);
639
640 // Define the first (and only) variant of this arg.
641 value_arg.arg_type = eArgTypeValue;
642 value_arg.arg_repetition = eArgRepeatPlain;
643
644 // There is only one variant this argument could be; put it into the argument entry.
645 arg3.push_back (value_arg);
646
647 // Push the data for the first argument into the m_arguments vector.
648 m_arguments.push_back (arg1);
649 m_arguments.push_back (arg2);
650 m_arguments.push_back (arg3);
651 }
652
653
654 virtual
655 ~CommandObjectSettingsReplace () {}
656
657 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
658 virtual bool
659 WantsCompletion() { return true; }
660
661 virtual int
662 HandleArgumentCompletion (Args &input,
663 int &cursor_index,
664 int &cursor_char_position,
665 OptionElementVector &opt_element_vector,
666 int match_start_point,
667 int max_return_elements,
668 bool &word_complete,
669 StringList &matches)
670 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000671 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000672
673 // Attempting to complete variable name
674 if (cursor_index < 2)
675 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
676 CommandCompletions::eSettingsNameCompletion,
677 completion_str.c_str(),
678 match_start_point,
679 max_return_elements,
680 NULL,
681 word_complete,
682 matches);
683
684 return matches.GetSize();
685 }
686
687protected:
688 virtual bool
689 DoExecute (const char *command, CommandReturnObject &result)
690 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000691 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000692
693 Args cmd_args(command);
Jim Ingham5a988412012-06-08 21:56:10 +0000694 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Jim Ingham5a988412012-06-08 21:56:10 +0000695 if ((var_name == NULL) || (var_name[0] == '\0'))
696 {
697 result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
698 result.SetStatus (eReturnStatusFailed);
699 return false;
700 }
701
Jim Ingham5a988412012-06-08 21:56:10 +0000702
703 // Split the raw command into var_name, index_value, and value triple.
704 llvm::StringRef raw_str(command);
Greg Clayton30820f02013-03-05 23:52:49 +0000705 std::string var_value_string = raw_str.split(var_name).second.str();
706 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
Jim Ingham5a988412012-06-08 21:56:10 +0000707
Greg Claytonf9fc6092013-01-09 19:44:40 +0000708 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +0000709 eVarSetOperationReplace,
710 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +0000711 var_value_cstr));
Greg Clayton67cc0632012-08-22 17:17:09 +0000712 if (error.Fail())
Jim Ingham5a988412012-06-08 21:56:10 +0000713 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000714 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +0000715 result.SetStatus (eReturnStatusFailed);
Greg Clayton67cc0632012-08-22 17:17:09 +0000716 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000717 }
718 else
719 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000720 result.SetStatus (eReturnStatusSuccessFinishNoResult);
721
Jim Ingham5a988412012-06-08 21:56:10 +0000722 }
723
724 return result.Succeeded();
725 }
726};
727
728//-------------------------------------------------------------------------
729// CommandObjectSettingsInsertBefore
730//-------------------------------------------------------------------------
731
732class CommandObjectSettingsInsertBefore : public CommandObjectRaw
733{
734public:
735 CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
736 CommandObjectRaw (interpreter,
737 "settings insert-before",
738 "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
739 NULL)
740 {
741 CommandArgumentEntry arg1;
742 CommandArgumentEntry arg2;
743 CommandArgumentEntry arg3;
744 CommandArgumentData var_name_arg;
745 CommandArgumentData index_arg;
746 CommandArgumentData value_arg;
747
748 // Define the first (and only) variant of this arg.
749 var_name_arg.arg_type = eArgTypeSettingVariableName;
750 var_name_arg.arg_repetition = eArgRepeatPlain;
751
752 // There is only one variant this argument could be; put it into the argument entry.
753 arg1.push_back (var_name_arg);
754
755 // Define the first (variant of this arg.
756 index_arg.arg_type = eArgTypeSettingIndex;
757 index_arg.arg_repetition = eArgRepeatPlain;
758
759 // There is only one variant this argument could be; put it into the argument entry.
760 arg2.push_back (index_arg);
761
762 // Define the first (and only) variant of this arg.
763 value_arg.arg_type = eArgTypeValue;
764 value_arg.arg_repetition = eArgRepeatPlain;
765
766 // There is only one variant this argument could be; put it into the argument entry.
767 arg3.push_back (value_arg);
768
769 // Push the data for the first argument into the m_arguments vector.
770 m_arguments.push_back (arg1);
771 m_arguments.push_back (arg2);
772 m_arguments.push_back (arg3);
773 }
774
775 virtual
776 ~CommandObjectSettingsInsertBefore () {}
777
778 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
779 virtual bool
780 WantsCompletion() { return true; }
781
782 virtual int
783 HandleArgumentCompletion (Args &input,
784 int &cursor_index,
785 int &cursor_char_position,
786 OptionElementVector &opt_element_vector,
787 int match_start_point,
788 int max_return_elements,
789 bool &word_complete,
790 StringList &matches)
791 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000792 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000793
794 // Attempting to complete variable name
795 if (cursor_index < 2)
796 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
797 CommandCompletions::eSettingsNameCompletion,
798 completion_str.c_str(),
799 match_start_point,
800 max_return_elements,
801 NULL,
802 word_complete,
803 matches);
804
805 return matches.GetSize();
806 }
807
808protected:
809 virtual bool
810 DoExecute (const char *command, CommandReturnObject &result)
811 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000812 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000813
814 Args cmd_args(command);
Greg Clayton67cc0632012-08-22 17:17:09 +0000815 const size_t argc = cmd_args.GetArgumentCount ();
Jim Ingham5a988412012-06-08 21:56:10 +0000816
817 if (argc < 3)
818 {
819 result.AppendError ("'settings insert-before' takes more arguments");
820 result.SetStatus (eReturnStatusFailed);
821 return false;
822 }
823
824 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Jim Ingham5a988412012-06-08 21:56:10 +0000825 if ((var_name == NULL) || (var_name[0] == '\0'))
826 {
827 result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
828 result.SetStatus (eReturnStatusFailed);
829 return false;
830 }
831
Jim Ingham5a988412012-06-08 21:56:10 +0000832 // Split the raw command into var_name, index_value, and value triple.
833 llvm::StringRef raw_str(command);
Greg Clayton30820f02013-03-05 23:52:49 +0000834 std::string var_value_string = raw_str.split(var_name).second.str();
835 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
Jim Ingham5a988412012-06-08 21:56:10 +0000836
Greg Claytonf9fc6092013-01-09 19:44:40 +0000837 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +0000838 eVarSetOperationInsertBefore,
839 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +0000840 var_value_cstr));
Greg Clayton67cc0632012-08-22 17:17:09 +0000841 if (error.Fail())
Jim Ingham5a988412012-06-08 21:56:10 +0000842 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000843 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +0000844 result.SetStatus (eReturnStatusFailed);
Greg Clayton67cc0632012-08-22 17:17:09 +0000845 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000846 }
847
848 return result.Succeeded();
849 }
850};
851
852//-------------------------------------------------------------------------
853// CommandObjectSettingInsertAfter
854//-------------------------------------------------------------------------
855
856class CommandObjectSettingsInsertAfter : public CommandObjectRaw
857{
858public:
859 CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
860 CommandObjectRaw (interpreter,
861 "settings insert-after",
862 "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
863 NULL)
864 {
865 CommandArgumentEntry arg1;
866 CommandArgumentEntry arg2;
867 CommandArgumentEntry arg3;
868 CommandArgumentData var_name_arg;
869 CommandArgumentData index_arg;
870 CommandArgumentData value_arg;
871
872 // Define the first (and only) variant of this arg.
873 var_name_arg.arg_type = eArgTypeSettingVariableName;
874 var_name_arg.arg_repetition = eArgRepeatPlain;
875
876 // There is only one variant this argument could be; put it into the argument entry.
877 arg1.push_back (var_name_arg);
878
879 // Define the first (variant of this arg.
880 index_arg.arg_type = eArgTypeSettingIndex;
881 index_arg.arg_repetition = eArgRepeatPlain;
882
883 // There is only one variant this argument could be; put it into the argument entry.
884 arg2.push_back (index_arg);
885
886 // Define the first (and only) variant of this arg.
887 value_arg.arg_type = eArgTypeValue;
888 value_arg.arg_repetition = eArgRepeatPlain;
889
890 // There is only one variant this argument could be; put it into the argument entry.
891 arg3.push_back (value_arg);
892
893 // Push the data for the first argument into the m_arguments vector.
894 m_arguments.push_back (arg1);
895 m_arguments.push_back (arg2);
896 m_arguments.push_back (arg3);
897 }
898
899 virtual
900 ~CommandObjectSettingsInsertAfter () {}
901
902 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
903 virtual bool
904 WantsCompletion() { return true; }
905
906 virtual int
907 HandleArgumentCompletion (Args &input,
908 int &cursor_index,
909 int &cursor_char_position,
910 OptionElementVector &opt_element_vector,
911 int match_start_point,
912 int max_return_elements,
913 bool &word_complete,
914 StringList &matches)
915 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000916 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +0000917
918 // Attempting to complete variable name
919 if (cursor_index < 2)
920 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
921 CommandCompletions::eSettingsNameCompletion,
922 completion_str.c_str(),
923 match_start_point,
924 max_return_elements,
925 NULL,
926 word_complete,
927 matches);
928
929 return matches.GetSize();
930 }
931
932protected:
933 virtual bool
934 DoExecute (const char *command, CommandReturnObject &result)
935 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000936 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +0000937
938 Args cmd_args(command);
Greg Clayton67cc0632012-08-22 17:17:09 +0000939 const size_t argc = cmd_args.GetArgumentCount ();
Jim Ingham5a988412012-06-08 21:56:10 +0000940
941 if (argc < 3)
942 {
943 result.AppendError ("'settings insert-after' takes more arguments");
944 result.SetStatus (eReturnStatusFailed);
945 return false;
946 }
947
948 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Jim Ingham5a988412012-06-08 21:56:10 +0000949 if ((var_name == NULL) || (var_name[0] == '\0'))
950 {
951 result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
952 result.SetStatus (eReturnStatusFailed);
953 return false;
954 }
955
Jim Ingham5a988412012-06-08 21:56:10 +0000956 // Split the raw command into var_name, index_value, and value triple.
957 llvm::StringRef raw_str(command);
Greg Clayton30820f02013-03-05 23:52:49 +0000958 std::string var_value_string = raw_str.split(var_name).second.str();
959 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
Jim Ingham5a988412012-06-08 21:56:10 +0000960
Greg Claytonf9fc6092013-01-09 19:44:40 +0000961 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +0000962 eVarSetOperationInsertAfter,
963 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +0000964 var_value_cstr));
Greg Clayton67cc0632012-08-22 17:17:09 +0000965 if (error.Fail())
Jim Ingham5a988412012-06-08 21:56:10 +0000966 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000967 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +0000968 result.SetStatus (eReturnStatusFailed);
Greg Clayton67cc0632012-08-22 17:17:09 +0000969 return false;
Jim Ingham5a988412012-06-08 21:56:10 +0000970 }
971
972 return result.Succeeded();
973 }
974};
975
976//-------------------------------------------------------------------------
977// CommandObjectSettingsAppend
978//-------------------------------------------------------------------------
979
980class CommandObjectSettingsAppend : public CommandObjectRaw
981{
982public:
983 CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
984 CommandObjectRaw (interpreter,
985 "settings append",
986 "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
987 NULL)
988 {
989 CommandArgumentEntry arg1;
990 CommandArgumentEntry arg2;
991 CommandArgumentData var_name_arg;
992 CommandArgumentData value_arg;
993
994 // Define the first (and only) variant of this arg.
995 var_name_arg.arg_type = eArgTypeSettingVariableName;
996 var_name_arg.arg_repetition = eArgRepeatPlain;
997
998 // There is only one variant this argument could be; put it into the argument entry.
999 arg1.push_back (var_name_arg);
1000
1001 // Define the first (and only) variant of this arg.
1002 value_arg.arg_type = eArgTypeValue;
1003 value_arg.arg_repetition = eArgRepeatPlain;
1004
1005 // There is only one variant this argument could be; put it into the argument entry.
1006 arg2.push_back (value_arg);
1007
1008 // Push the data for the first argument into the m_arguments vector.
1009 m_arguments.push_back (arg1);
1010 m_arguments.push_back (arg2);
1011 }
1012
1013 virtual
1014 ~CommandObjectSettingsAppend () {}
1015
1016 // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
1017 virtual bool
1018 WantsCompletion() { return true; }
1019
1020 virtual int
1021 HandleArgumentCompletion (Args &input,
1022 int &cursor_index,
1023 int &cursor_char_position,
1024 OptionElementVector &opt_element_vector,
1025 int match_start_point,
1026 int max_return_elements,
1027 bool &word_complete,
1028 StringList &matches)
1029 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001030 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +00001031
1032 // Attempting to complete variable name
1033 if (cursor_index < 2)
1034 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1035 CommandCompletions::eSettingsNameCompletion,
1036 completion_str.c_str(),
1037 match_start_point,
1038 max_return_elements,
1039 NULL,
1040 word_complete,
1041 matches);
1042
1043 return matches.GetSize();
1044 }
1045
1046protected:
1047 virtual bool
1048 DoExecute (const char *command, CommandReturnObject &result)
1049 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001050 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Jim Ingham5a988412012-06-08 21:56:10 +00001051 Args cmd_args(command);
Greg Clayton67cc0632012-08-22 17:17:09 +00001052 const size_t argc = cmd_args.GetArgumentCount ();
Jim Ingham5a988412012-06-08 21:56:10 +00001053
1054 if (argc < 2)
1055 {
1056 result.AppendError ("'settings append' takes more arguments");
1057 result.SetStatus (eReturnStatusFailed);
1058 return false;
1059 }
1060
1061 const char *var_name = cmd_args.GetArgumentAtIndex (0);
Jim Ingham5a988412012-06-08 21:56:10 +00001062 if ((var_name == NULL) || (var_name[0] == '\0'))
1063 {
1064 result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1065 result.SetStatus (eReturnStatusFailed);
1066 return false;
1067 }
1068
Jim Ingham5a988412012-06-08 21:56:10 +00001069 // Do not perform cmd_args.Shift() since StringRef is manipulating the
1070 // raw character string later on.
1071
1072 // Split the raw command into var_name and value pair.
1073 llvm::StringRef raw_str(command);
Greg Clayton30820f02013-03-05 23:52:49 +00001074 std::string var_value_string = raw_str.split(var_name).second.str();
1075 const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
Jim Ingham5a988412012-06-08 21:56:10 +00001076
Greg Claytonf9fc6092013-01-09 19:44:40 +00001077 Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +00001078 eVarSetOperationAppend,
1079 var_name,
Greg Clayton30820f02013-03-05 23:52:49 +00001080 var_value_cstr));
Greg Clayton67cc0632012-08-22 17:17:09 +00001081 if (error.Fail())
Jim Ingham5a988412012-06-08 21:56:10 +00001082 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001083 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +00001084 result.SetStatus (eReturnStatusFailed);
Greg Clayton67cc0632012-08-22 17:17:09 +00001085 return false;
Jim Ingham5a988412012-06-08 21:56:10 +00001086 }
1087
1088 return result.Succeeded();
1089 }
1090};
1091
1092//-------------------------------------------------------------------------
1093// CommandObjectSettingsClear
1094//-------------------------------------------------------------------------
1095
1096class CommandObjectSettingsClear : public CommandObjectParsed
1097{
1098public:
1099 CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1100 CommandObjectParsed (interpreter,
1101 "settings clear",
1102 "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.",
1103 NULL)
1104 {
1105 CommandArgumentEntry arg;
1106 CommandArgumentData var_name_arg;
1107
1108 // Define the first (and only) variant of this arg.
1109 var_name_arg.arg_type = eArgTypeSettingVariableName;
1110 var_name_arg.arg_repetition = eArgRepeatPlain;
1111
1112 // There is only one variant this argument could be; put it into the argument entry.
1113 arg.push_back (var_name_arg);
1114
1115 // Push the data for the first argument into the m_arguments vector.
1116 m_arguments.push_back (arg);
1117 }
1118
1119 virtual
1120 ~CommandObjectSettingsClear () {}
1121
1122 virtual int
1123 HandleArgumentCompletion (Args &input,
1124 int &cursor_index,
1125 int &cursor_char_position,
1126 OptionElementVector &opt_element_vector,
1127 int match_start_point,
1128 int max_return_elements,
1129 bool &word_complete,
1130 StringList &matches)
1131 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001132 std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
Jim Ingham5a988412012-06-08 21:56:10 +00001133
1134 // Attempting to complete variable name
1135 if (cursor_index < 2)
1136 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1137 CommandCompletions::eSettingsNameCompletion,
1138 completion_str.c_str(),
1139 match_start_point,
1140 max_return_elements,
1141 NULL,
1142 word_complete,
1143 matches);
1144
1145 return matches.GetSize();
1146 }
1147
1148protected:
1149 virtual bool
1150 DoExecute (Args& command, CommandReturnObject &result)
1151 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001152 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1153 const size_t argc = command.GetArgumentCount ();
Jim Ingham5a988412012-06-08 21:56:10 +00001154
1155 if (argc != 1)
1156 {
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00001157 result.AppendError ("'settings clear' takes exactly one argument");
Jim Ingham5a988412012-06-08 21:56:10 +00001158 result.SetStatus (eReturnStatusFailed);
1159 return false;
1160 }
1161
1162 const char *var_name = command.GetArgumentAtIndex (0);
1163 if ((var_name == NULL) || (var_name[0] == '\0'))
1164 {
1165 result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1166 result.SetStatus (eReturnStatusFailed);
1167 return false;
1168 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001169
Greg Claytonf9fc6092013-01-09 19:44:40 +00001170 Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
Greg Clayton67cc0632012-08-22 17:17:09 +00001171 eVarSetOperationClear,
1172 var_name,
1173 NULL));
1174 if (error.Fail())
Jim Ingham5a988412012-06-08 21:56:10 +00001175 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001176 result.AppendError (error.AsCString());
Jim Ingham5a988412012-06-08 21:56:10 +00001177 result.SetStatus (eReturnStatusFailed);
Greg Clayton67cc0632012-08-22 17:17:09 +00001178 return false;
Jim Ingham5a988412012-06-08 21:56:10 +00001179 }
Jim Ingham5a988412012-06-08 21:56:10 +00001180
1181 return result.Succeeded();
1182 }
1183};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184
1185//-------------------------------------------------------------------------
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001186// CommandObjectMultiwordSettings
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187//-------------------------------------------------------------------------
1188
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001189CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00001190 CommandObjectMultiword (interpreter,
1191 "settings",
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001192 "A set of commands for manipulating internal settable debugger variables.",
1193 "settings <command> [<command-options>]")
1194{
Greg Clayton4c207172011-04-19 22:32:36 +00001195 LoadSubCommand ("set", CommandObjectSP (new CommandObjectSettingsSet (interpreter)));
1196 LoadSubCommand ("show", CommandObjectSP (new CommandObjectSettingsShow (interpreter)));
1197 LoadSubCommand ("list", CommandObjectSP (new CommandObjectSettingsList (interpreter)));
1198 LoadSubCommand ("remove", CommandObjectSP (new CommandObjectSettingsRemove (interpreter)));
1199 LoadSubCommand ("replace", CommandObjectSP (new CommandObjectSettingsReplace (interpreter)));
1200 LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter)));
1201 LoadSubCommand ("insert-after", CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter)));
1202 LoadSubCommand ("append", CommandObjectSP (new CommandObjectSettingsAppend (interpreter)));
1203 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectSettingsClear (interpreter)));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001204}
1205
1206CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207{
1208}