1254721Semaste//===-- CommandObjectSettings.cpp -------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/lldb-python.h"
11254721Semaste
12254721Semaste#include "CommandObjectSettings.h"
13254721Semaste
14254721Semaste// C Includes
15254721Semaste// C++ Includes
16254721Semaste// Other libraries and framework includes
17254721Semaste// Project includes
18254721Semaste#include "lldb/Interpreter/CommandInterpreter.h"
19254721Semaste#include "lldb/Interpreter/CommandReturnObject.h"
20254721Semaste#include "lldb/Interpreter/CommandCompletions.h"
21254721Semaste
22254721Semasteusing namespace lldb;
23254721Semasteusing namespace lldb_private;
24254721Semaste#include "llvm/ADT/StringRef.h"
25254721Semaste
26254721Semaste//-------------------------------------------------------------------------
27254721Semaste// CommandObjectSettingsSet
28254721Semaste//-------------------------------------------------------------------------
29254721Semaste
30254721Semasteclass CommandObjectSettingsSet : public CommandObjectRaw
31254721Semaste{
32254721Semastepublic:
33254721Semaste    CommandObjectSettingsSet (CommandInterpreter &interpreter) :
34254721Semaste        CommandObjectRaw (interpreter,
35254721Semaste                          "settings set",
36254721Semaste                          "Set or change the value of a single debugger setting variable.",
37254721Semaste                          NULL),
38254721Semaste        m_options (interpreter)
39254721Semaste    {
40254721Semaste        CommandArgumentEntry arg1;
41254721Semaste        CommandArgumentEntry arg2;
42254721Semaste        CommandArgumentData var_name_arg;
43254721Semaste        CommandArgumentData value_arg;
44254721Semaste
45254721Semaste        // Define the first (and only) variant of this arg.
46254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
47254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
48254721Semaste
49254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
50254721Semaste        arg1.push_back (var_name_arg);
51254721Semaste
52254721Semaste        // Define the first (and only) variant of this arg.
53254721Semaste        value_arg.arg_type = eArgTypeValue;
54254721Semaste        value_arg.arg_repetition = eArgRepeatPlain;
55254721Semaste
56254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
57254721Semaste        arg2.push_back (value_arg);
58254721Semaste
59254721Semaste        // Push the data for the first argument into the m_arguments vector.
60254721Semaste        m_arguments.push_back (arg1);
61254721Semaste        m_arguments.push_back (arg2);
62254721Semaste
63254721Semaste        SetHelpLong (
64254721Semaste"When setting a dictionary or array variable, you can set multiple entries \n\
65254721Semasteat once by giving the values to the set command.  For example: \n\
66254721Semaste\n\
67254721Semaste(lldb) settings set target.run-args value1 value2 value3 \n\
68254721Semaste(lldb) settings set target.env-vars MYPATH=~/.:/usr/bin  SOME_ENV_VAR=12345 \n\
69254721Semaste\n\
70254721Semaste(lldb) settings show target.run-args \n\
71254721Semaste  [0]: 'value1' \n\
72254721Semaste  [1]: 'value2' \n\
73254721Semaste  [3]: 'value3' \n\
74254721Semaste(lldb) settings show target.env-vars \n\
75254721Semaste  'MYPATH=~/.:/usr/bin'\n\
76254721Semaste  'SOME_ENV_VAR=12345' \n\
77254721Semaste\n\
78254721SemasteWarning:  The 'set' command re-sets the entire array or dictionary.  If you \n\
79254721Semastejust want to add, remove or update individual values (or add something to \n\
80254721Semastethe end), use one of the other settings sub-commands: append, replace, \n\
81254721Semasteinsert-before or insert-after.\n");
82254721Semaste
83254721Semaste    }
84254721Semaste
85254721Semaste
86254721Semaste    virtual
87254721Semaste    ~CommandObjectSettingsSet () {}
88254721Semaste
89254721Semaste    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
90254721Semaste    virtual bool
91254721Semaste    WantsCompletion() { return true; }
92254721Semaste
93254721Semaste    virtual Options *
94254721Semaste    GetOptions ()
95254721Semaste    {
96254721Semaste        return &m_options;
97254721Semaste    }
98254721Semaste
99254721Semaste    class CommandOptions : public Options
100254721Semaste    {
101254721Semaste    public:
102254721Semaste
103254721Semaste        CommandOptions (CommandInterpreter &interpreter) :
104254721Semaste            Options (interpreter),
105254721Semaste            m_global (false)
106254721Semaste        {
107254721Semaste        }
108254721Semaste
109254721Semaste        virtual
110254721Semaste        ~CommandOptions () {}
111254721Semaste
112254721Semaste        virtual Error
113254721Semaste        SetOptionValue (uint32_t option_idx, const char *option_arg)
114254721Semaste        {
115254721Semaste            Error error;
116254721Semaste            const int short_option = m_getopt_table[option_idx].val;
117254721Semaste
118254721Semaste            switch (short_option)
119254721Semaste            {
120254721Semaste                case 'g':
121254721Semaste                    m_global = true;
122254721Semaste                    break;
123254721Semaste                default:
124254721Semaste                    error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option);
125254721Semaste                    break;
126254721Semaste            }
127254721Semaste
128254721Semaste            return error;
129254721Semaste        }
130254721Semaste
131254721Semaste        void
132254721Semaste        OptionParsingStarting ()
133254721Semaste        {
134254721Semaste            m_global = false;
135254721Semaste        }
136254721Semaste
137254721Semaste        const OptionDefinition*
138254721Semaste        GetDefinitions ()
139254721Semaste        {
140254721Semaste            return g_option_table;
141254721Semaste        }
142254721Semaste
143254721Semaste        // Options table: Required for subclasses of Options.
144254721Semaste
145254721Semaste        static OptionDefinition g_option_table[];
146254721Semaste
147254721Semaste        // Instance variables to hold the values for command options.
148254721Semaste
149254721Semaste        bool m_global;
150254721Semaste    };
151254721Semaste
152254721Semaste    virtual int
153254721Semaste    HandleArgumentCompletion (Args &input,
154254721Semaste                              int &cursor_index,
155254721Semaste                              int &cursor_char_position,
156254721Semaste                              OptionElementVector &opt_element_vector,
157254721Semaste                              int match_start_point,
158254721Semaste                              int max_return_elements,
159254721Semaste                              bool &word_complete,
160254721Semaste                              StringList &matches)
161254721Semaste    {
162254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
163254721Semaste
164254721Semaste        const size_t argc = input.GetArgumentCount();
165254721Semaste        const char *arg = NULL;
166254721Semaste        int setting_var_idx;
167254721Semaste        for (setting_var_idx = 1; setting_var_idx < argc; ++setting_var_idx)
168254721Semaste        {
169254721Semaste            arg = input.GetArgumentAtIndex(setting_var_idx);
170254721Semaste            if (arg && arg[0] != '-')
171254721Semaste                break; // We found our setting variable name index
172254721Semaste        }
173254721Semaste        if (cursor_index == setting_var_idx)
174254721Semaste        {
175254721Semaste            // Attempting to complete setting variable name
176254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
177254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
178254721Semaste                                                                 completion_str.c_str(),
179254721Semaste                                                                 match_start_point,
180254721Semaste                                                                 max_return_elements,
181254721Semaste                                                                 NULL,
182254721Semaste                                                                 word_complete,
183254721Semaste                                                                 matches);
184254721Semaste        }
185254721Semaste        else
186254721Semaste        {
187254721Semaste            arg = input.GetArgumentAtIndex(cursor_index);
188254721Semaste
189254721Semaste            if (arg)
190254721Semaste            {
191254721Semaste                if (arg[0] == '-')
192254721Semaste                {
193254721Semaste                    // Complete option name
194254721Semaste                }
195254721Semaste                else
196254721Semaste                {
197254721Semaste                    // Complete setting value
198254721Semaste                    const char *setting_var_name = input.GetArgumentAtIndex(setting_var_idx);
199254721Semaste                    Error error;
200254721Semaste                    lldb::OptionValueSP value_sp (m_interpreter.GetDebugger().GetPropertyValue(&m_exe_ctx, setting_var_name, false, error));
201254721Semaste                    if (value_sp)
202254721Semaste                    {
203254721Semaste                        value_sp->AutoComplete (m_interpreter,
204254721Semaste                                                completion_str.c_str(),
205254721Semaste                                                match_start_point,
206254721Semaste                                                max_return_elements,
207254721Semaste                                                word_complete,
208254721Semaste                                                matches);
209254721Semaste                    }
210254721Semaste                }
211254721Semaste            }
212254721Semaste        }
213254721Semaste        return matches.GetSize();
214254721Semaste    }
215254721Semaste
216254721Semasteprotected:
217254721Semaste    virtual bool
218254721Semaste    DoExecute (const char *command, CommandReturnObject &result)
219254721Semaste    {
220254721Semaste        Args cmd_args(command);
221254721Semaste
222254721Semaste        // Process possible options.
223254721Semaste        if (!ParseOptions (cmd_args, result))
224254721Semaste            return false;
225254721Semaste
226254721Semaste        const size_t argc = cmd_args.GetArgumentCount ();
227254721Semaste        if ((argc < 2) && (!m_options.m_global))
228254721Semaste        {
229254721Semaste            result.AppendError ("'settings set' takes more arguments");
230254721Semaste            result.SetStatus (eReturnStatusFailed);
231254721Semaste            return false;
232254721Semaste        }
233254721Semaste
234254721Semaste        const char *var_name = cmd_args.GetArgumentAtIndex (0);
235254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
236254721Semaste        {
237254721Semaste            result.AppendError ("'settings set' command requires a valid variable name");
238254721Semaste            result.SetStatus (eReturnStatusFailed);
239254721Semaste            return false;
240254721Semaste        }
241254721Semaste
242254721Semaste        // Split the raw command into var_name and value pair.
243254721Semaste        llvm::StringRef raw_str(command);
244254721Semaste        std::string var_value_string = raw_str.split(var_name).second.str();
245254721Semaste        const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
246254721Semaste
247254721Semaste        Error error;
248254721Semaste        if (m_options.m_global)
249254721Semaste        {
250254721Semaste            error = m_interpreter.GetDebugger().SetPropertyValue (NULL,
251254721Semaste                                                                  eVarSetOperationAssign,
252254721Semaste                                                                  var_name,
253254721Semaste                                                                  var_value_cstr);
254254721Semaste        }
255254721Semaste
256254721Semaste        if (error.Success())
257254721Semaste        {
258254721Semaste            // FIXME this is the same issue as the one in commands script import
259254721Semaste            // we could be setting target.load-script-from-symbol-file which would cause
260254721Semaste            // Python scripts to be loaded, which could run LLDB commands
261254721Semaste            // (e.g. settings set target.process.python-os-plugin-path) and cause a crash
262254721Semaste            // if we did not clear the command's exe_ctx first
263254721Semaste            ExecutionContext exe_ctx(m_exe_ctx);
264254721Semaste            m_exe_ctx.Clear();
265254721Semaste            error = m_interpreter.GetDebugger().SetPropertyValue (&exe_ctx,
266254721Semaste                                                                  eVarSetOperationAssign,
267254721Semaste                                                                  var_name,
268254721Semaste                                                                  var_value_cstr);
269254721Semaste        }
270254721Semaste
271254721Semaste        if (error.Fail())
272254721Semaste        {
273254721Semaste            result.AppendError (error.AsCString());
274254721Semaste            result.SetStatus (eReturnStatusFailed);
275254721Semaste            return false;
276254721Semaste        }
277254721Semaste        else
278254721Semaste        {
279254721Semaste            result.SetStatus (eReturnStatusSuccessFinishResult);
280254721Semaste        }
281254721Semaste
282254721Semaste        return result.Succeeded();
283254721Semaste    }
284254721Semasteprivate:
285254721Semaste    CommandOptions m_options;
286254721Semaste};
287254721Semaste
288254721SemasteOptionDefinition
289254721SemasteCommandObjectSettingsSet::CommandOptions::g_option_table[] =
290254721Semaste{
291263363Semaste    { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument,   NULL, 0, eArgTypeNone, "Apply the new value to the global default value." },
292254721Semaste    { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
293254721Semaste};
294254721Semaste
295254721Semaste
296254721Semaste//-------------------------------------------------------------------------
297254721Semaste// CommandObjectSettingsShow -- Show current values
298254721Semaste//-------------------------------------------------------------------------
299254721Semaste
300254721Semasteclass CommandObjectSettingsShow : public CommandObjectParsed
301254721Semaste{
302254721Semastepublic:
303254721Semaste    CommandObjectSettingsShow (CommandInterpreter &interpreter) :
304254721Semaste        CommandObjectParsed (interpreter,
305254721Semaste                             "settings show",
306254721Semaste                             "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.",
307254721Semaste                             NULL)
308254721Semaste    {
309254721Semaste        CommandArgumentEntry arg1;
310254721Semaste        CommandArgumentData var_name_arg;
311254721Semaste
312254721Semaste        // Define the first (and only) variant of this arg.
313254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
314254721Semaste        var_name_arg.arg_repetition = eArgRepeatOptional;
315254721Semaste
316254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
317254721Semaste        arg1.push_back (var_name_arg);
318254721Semaste
319254721Semaste        // Push the data for the first argument into the m_arguments vector.
320254721Semaste        m_arguments.push_back (arg1);
321254721Semaste    }
322254721Semaste
323254721Semaste    virtual
324254721Semaste    ~CommandObjectSettingsShow () {}
325254721Semaste
326254721Semaste
327254721Semaste    virtual int
328254721Semaste    HandleArgumentCompletion (Args &input,
329254721Semaste                              int &cursor_index,
330254721Semaste                              int &cursor_char_position,
331254721Semaste                              OptionElementVector &opt_element_vector,
332254721Semaste                              int match_start_point,
333254721Semaste                              int max_return_elements,
334254721Semaste                              bool &word_complete,
335254721Semaste                              StringList &matches)
336254721Semaste    {
337254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
338254721Semaste
339254721Semaste        CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
340254721Semaste                                                             CommandCompletions::eSettingsNameCompletion,
341254721Semaste                                                             completion_str.c_str(),
342254721Semaste                                                             match_start_point,
343254721Semaste                                                             max_return_elements,
344254721Semaste                                                             NULL,
345254721Semaste                                                             word_complete,
346254721Semaste                                                             matches);
347254721Semaste        return matches.GetSize();
348254721Semaste    }
349254721Semaste
350254721Semasteprotected:
351254721Semaste    virtual bool
352254721Semaste    DoExecute (Args& args, CommandReturnObject &result)
353254721Semaste    {
354254721Semaste        result.SetStatus (eReturnStatusSuccessFinishResult);
355254721Semaste
356254721Semaste        const size_t argc = args.GetArgumentCount ();
357254721Semaste        if (argc > 0)
358254721Semaste        {
359254721Semaste            for (size_t i=0; i<argc; ++i)
360254721Semaste            {
361254721Semaste                const char *property_path = args.GetArgumentAtIndex (i);
362254721Semaste
363254721Semaste                Error error(m_interpreter.GetDebugger().DumpPropertyValue (&m_exe_ctx, result.GetOutputStream(), property_path, OptionValue::eDumpGroupValue));
364254721Semaste                if (error.Success())
365254721Semaste                {
366254721Semaste                    result.GetOutputStream().EOL();
367254721Semaste                }
368254721Semaste                else
369254721Semaste                {
370254721Semaste                    result.AppendError (error.AsCString());
371254721Semaste                    result.SetStatus (eReturnStatusFailed);
372254721Semaste                }
373254721Semaste            }
374254721Semaste        }
375254721Semaste        else
376254721Semaste        {
377254721Semaste            m_interpreter.GetDebugger().DumpAllPropertyValues (&m_exe_ctx, result.GetOutputStream(), OptionValue::eDumpGroupValue);
378254721Semaste        }
379254721Semaste
380254721Semaste        return result.Succeeded();
381254721Semaste    }
382254721Semaste};
383254721Semaste
384254721Semaste//-------------------------------------------------------------------------
385254721Semaste// CommandObjectSettingsList -- List settable variables
386254721Semaste//-------------------------------------------------------------------------
387254721Semaste
388254721Semasteclass CommandObjectSettingsList : public CommandObjectParsed
389254721Semaste{
390254721Semastepublic:
391254721Semaste    CommandObjectSettingsList (CommandInterpreter &interpreter) :
392254721Semaste        CommandObjectParsed (interpreter,
393254721Semaste                             "settings list",
394254721Semaste                             "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).",
395254721Semaste                             NULL)
396254721Semaste    {
397254721Semaste        CommandArgumentEntry arg;
398254721Semaste        CommandArgumentData var_name_arg;
399254721Semaste        CommandArgumentData prefix_name_arg;
400254721Semaste
401254721Semaste        // Define the first variant of this arg.
402254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
403254721Semaste        var_name_arg.arg_repetition = eArgRepeatOptional;
404254721Semaste
405254721Semaste        // Define the second variant of this arg.
406254721Semaste        prefix_name_arg.arg_type = eArgTypeSettingPrefix;
407254721Semaste        prefix_name_arg.arg_repetition = eArgRepeatOptional;
408254721Semaste
409254721Semaste        arg.push_back (var_name_arg);
410254721Semaste        arg.push_back (prefix_name_arg);
411254721Semaste
412254721Semaste        // Push the data for the first argument into the m_arguments vector.
413254721Semaste        m_arguments.push_back (arg);
414254721Semaste    }
415254721Semaste
416254721Semaste    virtual
417254721Semaste    ~CommandObjectSettingsList () {}
418254721Semaste
419254721Semaste    virtual int
420254721Semaste    HandleArgumentCompletion (Args &input,
421254721Semaste                              int &cursor_index,
422254721Semaste                              int &cursor_char_position,
423254721Semaste                              OptionElementVector &opt_element_vector,
424254721Semaste                              int match_start_point,
425254721Semaste                              int max_return_elements,
426254721Semaste                              bool &word_complete,
427254721Semaste                              StringList &matches)
428254721Semaste    {
429254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
430254721Semaste
431254721Semaste        CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
432254721Semaste                                                             CommandCompletions::eSettingsNameCompletion,
433254721Semaste                                                             completion_str.c_str(),
434254721Semaste                                                             match_start_point,
435254721Semaste                                                             max_return_elements,
436254721Semaste                                                             NULL,
437254721Semaste                                                             word_complete,
438254721Semaste                                                             matches);
439254721Semaste        return matches.GetSize();
440254721Semaste    }
441254721Semaste
442254721Semasteprotected:
443254721Semaste    virtual bool
444254721Semaste    DoExecute (Args& args, CommandReturnObject &result)
445254721Semaste    {
446254721Semaste        result.SetStatus (eReturnStatusSuccessFinishResult);
447254721Semaste
448254721Semaste        const bool will_modify = false;
449254721Semaste        const size_t argc = args.GetArgumentCount ();
450254721Semaste        if (argc > 0)
451254721Semaste        {
452254721Semaste            const bool dump_qualified_name = true;
453254721Semaste
454254721Semaste            for (size_t i=0; i<argc; ++i)
455254721Semaste            {
456254721Semaste                const char *property_path = args.GetArgumentAtIndex (i);
457254721Semaste
458254721Semaste                const Property *property = m_interpreter.GetDebugger().GetValueProperties()->GetPropertyAtPath (&m_exe_ctx, will_modify, property_path);
459254721Semaste
460254721Semaste                if (property)
461254721Semaste                {
462254721Semaste                    property->DumpDescription (m_interpreter, result.GetOutputStream(), 0, dump_qualified_name);
463254721Semaste                }
464254721Semaste                else
465254721Semaste                {
466254721Semaste                    result.AppendErrorWithFormat ("invalid property path '%s'", property_path);
467254721Semaste                    result.SetStatus (eReturnStatusFailed);
468254721Semaste                }
469254721Semaste            }
470254721Semaste        }
471254721Semaste        else
472254721Semaste        {
473254721Semaste            m_interpreter.GetDebugger().DumpAllDescriptions (m_interpreter, result.GetOutputStream());
474254721Semaste        }
475254721Semaste
476254721Semaste        return result.Succeeded();
477254721Semaste    }
478254721Semaste};
479254721Semaste
480254721Semaste//-------------------------------------------------------------------------
481254721Semaste// CommandObjectSettingsRemove
482254721Semaste//-------------------------------------------------------------------------
483254721Semaste
484254721Semasteclass CommandObjectSettingsRemove : public CommandObjectRaw
485254721Semaste{
486254721Semastepublic:
487254721Semaste    CommandObjectSettingsRemove (CommandInterpreter &interpreter) :
488254721Semaste        CommandObjectRaw (interpreter,
489254721Semaste                          "settings remove",
490254721Semaste                          "Remove the specified element from an array or dictionary settings variable.",
491254721Semaste                          NULL)
492254721Semaste    {
493254721Semaste        CommandArgumentEntry arg1;
494254721Semaste        CommandArgumentEntry arg2;
495254721Semaste        CommandArgumentData var_name_arg;
496254721Semaste        CommandArgumentData index_arg;
497254721Semaste        CommandArgumentData key_arg;
498254721Semaste
499254721Semaste        // Define the first (and only) variant of this arg.
500254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
501254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
502254721Semaste
503254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
504254721Semaste        arg1.push_back (var_name_arg);
505254721Semaste
506254721Semaste        // Define the first variant of this arg.
507254721Semaste        index_arg.arg_type = eArgTypeSettingIndex;
508254721Semaste        index_arg.arg_repetition = eArgRepeatPlain;
509254721Semaste
510254721Semaste        // Define the second variant of this arg.
511254721Semaste        key_arg.arg_type = eArgTypeSettingKey;
512254721Semaste        key_arg.arg_repetition = eArgRepeatPlain;
513254721Semaste
514254721Semaste        // Push both variants into this arg
515254721Semaste        arg2.push_back (index_arg);
516254721Semaste        arg2.push_back (key_arg);
517254721Semaste
518254721Semaste        // Push the data for the first argument into the m_arguments vector.
519254721Semaste        m_arguments.push_back (arg1);
520254721Semaste        m_arguments.push_back (arg2);
521254721Semaste    }
522254721Semaste
523254721Semaste    virtual
524254721Semaste    ~CommandObjectSettingsRemove () {}
525254721Semaste
526254721Semaste    virtual int
527254721Semaste    HandleArgumentCompletion (Args &input,
528254721Semaste                              int &cursor_index,
529254721Semaste                              int &cursor_char_position,
530254721Semaste                              OptionElementVector &opt_element_vector,
531254721Semaste                              int match_start_point,
532254721Semaste                              int max_return_elements,
533254721Semaste                              bool &word_complete,
534254721Semaste                              StringList &matches)
535254721Semaste    {
536254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
537254721Semaste
538254721Semaste        // Attempting to complete variable name
539254721Semaste        if (cursor_index < 2)
540254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
541254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
542254721Semaste                                                                 completion_str.c_str(),
543254721Semaste                                                                 match_start_point,
544254721Semaste                                                                 max_return_elements,
545254721Semaste                                                                 NULL,
546254721Semaste                                                                 word_complete,
547254721Semaste                                                                 matches);
548254721Semaste
549254721Semaste        return matches.GetSize();
550254721Semaste    }
551254721Semaste
552254721Semasteprotected:
553254721Semaste    virtual bool
554254721Semaste    DoExecute (const char *command, CommandReturnObject &result)
555254721Semaste    {
556254721Semaste        result.SetStatus (eReturnStatusSuccessFinishNoResult);
557254721Semaste
558254721Semaste        Args cmd_args(command);
559254721Semaste
560254721Semaste        // Process possible options.
561254721Semaste        if (!ParseOptions (cmd_args, result))
562254721Semaste            return false;
563254721Semaste
564254721Semaste        const size_t argc = cmd_args.GetArgumentCount ();
565254721Semaste        if (argc == 0)
566254721Semaste        {
567254721Semaste            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");
568254721Semaste            result.SetStatus (eReturnStatusFailed);
569254721Semaste            return false;
570254721Semaste        }
571254721Semaste
572254721Semaste        const char *var_name = cmd_args.GetArgumentAtIndex (0);
573254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
574254721Semaste        {
575254721Semaste            result.AppendError ("'settings set' command requires a valid variable name");
576254721Semaste            result.SetStatus (eReturnStatusFailed);
577254721Semaste            return false;
578254721Semaste        }
579254721Semaste
580254721Semaste        // Split the raw command into var_name and value pair.
581254721Semaste        llvm::StringRef raw_str(command);
582254721Semaste        std::string var_value_string = raw_str.split(var_name).second.str();
583254721Semaste        const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
584254721Semaste
585254721Semaste        Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
586254721Semaste                                                                   eVarSetOperationRemove,
587254721Semaste                                                                   var_name,
588254721Semaste                                                                   var_value_cstr));
589254721Semaste        if (error.Fail())
590254721Semaste        {
591254721Semaste            result.AppendError (error.AsCString());
592254721Semaste            result.SetStatus (eReturnStatusFailed);
593254721Semaste            return false;
594254721Semaste        }
595254721Semaste
596254721Semaste        return result.Succeeded();
597254721Semaste    }
598254721Semaste};
599254721Semaste
600254721Semaste//-------------------------------------------------------------------------
601254721Semaste// CommandObjectSettingsReplace
602254721Semaste//-------------------------------------------------------------------------
603254721Semaste
604254721Semasteclass CommandObjectSettingsReplace : public CommandObjectRaw
605254721Semaste{
606254721Semastepublic:
607254721Semaste    CommandObjectSettingsReplace (CommandInterpreter &interpreter) :
608254721Semaste        CommandObjectRaw (interpreter,
609254721Semaste                          "settings replace",
610254721Semaste                          "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.",
611254721Semaste                          NULL)
612254721Semaste    {
613254721Semaste        CommandArgumentEntry arg1;
614254721Semaste        CommandArgumentEntry arg2;
615254721Semaste        CommandArgumentEntry arg3;
616254721Semaste        CommandArgumentData var_name_arg;
617254721Semaste        CommandArgumentData index_arg;
618254721Semaste        CommandArgumentData key_arg;
619254721Semaste        CommandArgumentData value_arg;
620254721Semaste
621254721Semaste        // Define the first (and only) variant of this arg.
622254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
623254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
624254721Semaste
625254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
626254721Semaste        arg1.push_back (var_name_arg);
627254721Semaste
628254721Semaste        // Define the first (variant of this arg.
629254721Semaste        index_arg.arg_type = eArgTypeSettingIndex;
630254721Semaste        index_arg.arg_repetition = eArgRepeatPlain;
631254721Semaste
632254721Semaste        // Define the second (variant of this arg.
633254721Semaste        key_arg.arg_type = eArgTypeSettingKey;
634254721Semaste        key_arg.arg_repetition = eArgRepeatPlain;
635254721Semaste
636254721Semaste        // Put both variants into this arg
637254721Semaste        arg2.push_back (index_arg);
638254721Semaste        arg2.push_back (key_arg);
639254721Semaste
640254721Semaste        // Define the first (and only) variant of this arg.
641254721Semaste        value_arg.arg_type = eArgTypeValue;
642254721Semaste        value_arg.arg_repetition = eArgRepeatPlain;
643254721Semaste
644254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
645254721Semaste        arg3.push_back (value_arg);
646254721Semaste
647254721Semaste        // Push the data for the first argument into the m_arguments vector.
648254721Semaste        m_arguments.push_back (arg1);
649254721Semaste        m_arguments.push_back (arg2);
650254721Semaste        m_arguments.push_back (arg3);
651254721Semaste    }
652254721Semaste
653254721Semaste
654254721Semaste    virtual
655254721Semaste    ~CommandObjectSettingsReplace () {}
656254721Semaste
657254721Semaste    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
658254721Semaste    virtual bool
659254721Semaste    WantsCompletion() { return true; }
660254721Semaste
661254721Semaste    virtual int
662254721Semaste    HandleArgumentCompletion (Args &input,
663254721Semaste                              int &cursor_index,
664254721Semaste                              int &cursor_char_position,
665254721Semaste                              OptionElementVector &opt_element_vector,
666254721Semaste                              int match_start_point,
667254721Semaste                              int max_return_elements,
668254721Semaste                              bool &word_complete,
669254721Semaste                              StringList &matches)
670254721Semaste    {
671254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
672254721Semaste
673254721Semaste        // Attempting to complete variable name
674254721Semaste        if (cursor_index < 2)
675254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
676254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
677254721Semaste                                                                 completion_str.c_str(),
678254721Semaste                                                                 match_start_point,
679254721Semaste                                                                 max_return_elements,
680254721Semaste                                                                 NULL,
681254721Semaste                                                                 word_complete,
682254721Semaste                                                                 matches);
683254721Semaste
684254721Semaste        return matches.GetSize();
685254721Semaste    }
686254721Semaste
687254721Semasteprotected:
688254721Semaste    virtual bool
689254721Semaste    DoExecute (const char *command, CommandReturnObject &result)
690254721Semaste    {
691254721Semaste        result.SetStatus (eReturnStatusSuccessFinishNoResult);
692254721Semaste
693254721Semaste        Args cmd_args(command);
694254721Semaste        const char *var_name = cmd_args.GetArgumentAtIndex (0);
695254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
696254721Semaste        {
697254721Semaste            result.AppendError ("'settings replace' command requires a valid variable name; No value supplied");
698254721Semaste            result.SetStatus (eReturnStatusFailed);
699254721Semaste            return false;
700254721Semaste        }
701254721Semaste
702254721Semaste
703254721Semaste        // Split the raw command into var_name, index_value, and value triple.
704254721Semaste        llvm::StringRef raw_str(command);
705254721Semaste        std::string var_value_string = raw_str.split(var_name).second.str();
706254721Semaste        const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
707254721Semaste
708254721Semaste        Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
709254721Semaste                                                                  eVarSetOperationReplace,
710254721Semaste                                                                  var_name,
711254721Semaste                                                                  var_value_cstr));
712254721Semaste        if (error.Fail())
713254721Semaste        {
714254721Semaste            result.AppendError (error.AsCString());
715254721Semaste            result.SetStatus (eReturnStatusFailed);
716254721Semaste            return false;
717254721Semaste        }
718254721Semaste        else
719254721Semaste        {
720254721Semaste            result.SetStatus (eReturnStatusSuccessFinishNoResult);
721254721Semaste
722254721Semaste        }
723254721Semaste
724254721Semaste        return result.Succeeded();
725254721Semaste    }
726254721Semaste};
727254721Semaste
728254721Semaste//-------------------------------------------------------------------------
729254721Semaste// CommandObjectSettingsInsertBefore
730254721Semaste//-------------------------------------------------------------------------
731254721Semaste
732254721Semasteclass CommandObjectSettingsInsertBefore : public CommandObjectRaw
733254721Semaste{
734254721Semastepublic:
735254721Semaste    CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) :
736254721Semaste        CommandObjectRaw (interpreter,
737254721Semaste                          "settings insert-before",
738254721Semaste                          "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.",
739254721Semaste                          NULL)
740254721Semaste    {
741254721Semaste        CommandArgumentEntry arg1;
742254721Semaste        CommandArgumentEntry arg2;
743254721Semaste        CommandArgumentEntry arg3;
744254721Semaste        CommandArgumentData var_name_arg;
745254721Semaste        CommandArgumentData index_arg;
746254721Semaste        CommandArgumentData value_arg;
747254721Semaste
748254721Semaste        // Define the first (and only) variant of this arg.
749254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
750254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
751254721Semaste
752254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
753254721Semaste        arg1.push_back (var_name_arg);
754254721Semaste
755254721Semaste        // Define the first (variant of this arg.
756254721Semaste        index_arg.arg_type = eArgTypeSettingIndex;
757254721Semaste        index_arg.arg_repetition = eArgRepeatPlain;
758254721Semaste
759254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
760254721Semaste        arg2.push_back (index_arg);
761254721Semaste
762254721Semaste        // Define the first (and only) variant of this arg.
763254721Semaste        value_arg.arg_type = eArgTypeValue;
764254721Semaste        value_arg.arg_repetition = eArgRepeatPlain;
765254721Semaste
766254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
767254721Semaste        arg3.push_back (value_arg);
768254721Semaste
769254721Semaste        // Push the data for the first argument into the m_arguments vector.
770254721Semaste        m_arguments.push_back (arg1);
771254721Semaste        m_arguments.push_back (arg2);
772254721Semaste        m_arguments.push_back (arg3);
773254721Semaste    }
774254721Semaste
775254721Semaste    virtual
776254721Semaste    ~CommandObjectSettingsInsertBefore () {}
777254721Semaste
778254721Semaste    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
779254721Semaste    virtual bool
780254721Semaste    WantsCompletion() { return true; }
781254721Semaste
782254721Semaste    virtual int
783254721Semaste    HandleArgumentCompletion (Args &input,
784254721Semaste                              int &cursor_index,
785254721Semaste                              int &cursor_char_position,
786254721Semaste                              OptionElementVector &opt_element_vector,
787254721Semaste                              int match_start_point,
788254721Semaste                              int max_return_elements,
789254721Semaste                              bool &word_complete,
790254721Semaste                              StringList &matches)
791254721Semaste    {
792254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
793254721Semaste
794254721Semaste        // Attempting to complete variable name
795254721Semaste        if (cursor_index < 2)
796254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
797254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
798254721Semaste                                                                 completion_str.c_str(),
799254721Semaste                                                                 match_start_point,
800254721Semaste                                                                 max_return_elements,
801254721Semaste                                                                 NULL,
802254721Semaste                                                                 word_complete,
803254721Semaste                                                                 matches);
804254721Semaste
805254721Semaste        return matches.GetSize();
806254721Semaste    }
807254721Semaste
808254721Semasteprotected:
809254721Semaste    virtual bool
810254721Semaste    DoExecute (const char *command, CommandReturnObject &result)
811254721Semaste    {
812254721Semaste        result.SetStatus (eReturnStatusSuccessFinishNoResult);
813254721Semaste
814254721Semaste        Args cmd_args(command);
815254721Semaste        const size_t argc = cmd_args.GetArgumentCount ();
816254721Semaste
817254721Semaste        if (argc < 3)
818254721Semaste        {
819254721Semaste            result.AppendError ("'settings insert-before' takes more arguments");
820254721Semaste            result.SetStatus (eReturnStatusFailed);
821254721Semaste            return false;
822254721Semaste        }
823254721Semaste
824254721Semaste        const char *var_name = cmd_args.GetArgumentAtIndex (0);
825254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
826254721Semaste        {
827254721Semaste            result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied");
828254721Semaste            result.SetStatus (eReturnStatusFailed);
829254721Semaste            return false;
830254721Semaste        }
831254721Semaste
832254721Semaste        // Split the raw command into var_name, index_value, and value triple.
833254721Semaste        llvm::StringRef raw_str(command);
834254721Semaste        std::string var_value_string = raw_str.split(var_name).second.str();
835254721Semaste        const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
836254721Semaste
837254721Semaste        Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
838254721Semaste                                                                  eVarSetOperationInsertBefore,
839254721Semaste                                                                  var_name,
840254721Semaste                                                                  var_value_cstr));
841254721Semaste        if (error.Fail())
842254721Semaste        {
843254721Semaste            result.AppendError (error.AsCString());
844254721Semaste            result.SetStatus (eReturnStatusFailed);
845254721Semaste            return false;
846254721Semaste        }
847254721Semaste
848254721Semaste        return result.Succeeded();
849254721Semaste    }
850254721Semaste};
851254721Semaste
852254721Semaste//-------------------------------------------------------------------------
853254721Semaste// CommandObjectSettingInsertAfter
854254721Semaste//-------------------------------------------------------------------------
855254721Semaste
856254721Semasteclass CommandObjectSettingsInsertAfter : public CommandObjectRaw
857254721Semaste{
858254721Semastepublic:
859254721Semaste    CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) :
860254721Semaste        CommandObjectRaw (interpreter,
861254721Semaste                          "settings insert-after",
862254721Semaste                          "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.",
863254721Semaste                          NULL)
864254721Semaste    {
865254721Semaste        CommandArgumentEntry arg1;
866254721Semaste        CommandArgumentEntry arg2;
867254721Semaste        CommandArgumentEntry arg3;
868254721Semaste        CommandArgumentData var_name_arg;
869254721Semaste        CommandArgumentData index_arg;
870254721Semaste        CommandArgumentData value_arg;
871254721Semaste
872254721Semaste        // Define the first (and only) variant of this arg.
873254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
874254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
875254721Semaste
876254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
877254721Semaste        arg1.push_back (var_name_arg);
878254721Semaste
879254721Semaste        // Define the first (variant of this arg.
880254721Semaste        index_arg.arg_type = eArgTypeSettingIndex;
881254721Semaste        index_arg.arg_repetition = eArgRepeatPlain;
882254721Semaste
883254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
884254721Semaste        arg2.push_back (index_arg);
885254721Semaste
886254721Semaste        // Define the first (and only) variant of this arg.
887254721Semaste        value_arg.arg_type = eArgTypeValue;
888254721Semaste        value_arg.arg_repetition = eArgRepeatPlain;
889254721Semaste
890254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
891254721Semaste        arg3.push_back (value_arg);
892254721Semaste
893254721Semaste        // Push the data for the first argument into the m_arguments vector.
894254721Semaste        m_arguments.push_back (arg1);
895254721Semaste        m_arguments.push_back (arg2);
896254721Semaste        m_arguments.push_back (arg3);
897254721Semaste    }
898254721Semaste
899254721Semaste    virtual
900254721Semaste    ~CommandObjectSettingsInsertAfter () {}
901254721Semaste
902254721Semaste    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
903254721Semaste    virtual bool
904254721Semaste    WantsCompletion() { return true; }
905254721Semaste
906254721Semaste    virtual int
907254721Semaste    HandleArgumentCompletion (Args &input,
908254721Semaste                              int &cursor_index,
909254721Semaste                              int &cursor_char_position,
910254721Semaste                              OptionElementVector &opt_element_vector,
911254721Semaste                              int match_start_point,
912254721Semaste                              int max_return_elements,
913254721Semaste                              bool &word_complete,
914254721Semaste                              StringList &matches)
915254721Semaste    {
916254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
917254721Semaste
918254721Semaste        // Attempting to complete variable name
919254721Semaste        if (cursor_index < 2)
920254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
921254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
922254721Semaste                                                                 completion_str.c_str(),
923254721Semaste                                                                 match_start_point,
924254721Semaste                                                                 max_return_elements,
925254721Semaste                                                                 NULL,
926254721Semaste                                                                 word_complete,
927254721Semaste                                                                 matches);
928254721Semaste
929254721Semaste        return matches.GetSize();
930254721Semaste    }
931254721Semaste
932254721Semasteprotected:
933254721Semaste    virtual bool
934254721Semaste    DoExecute (const char *command, CommandReturnObject &result)
935254721Semaste    {
936254721Semaste        result.SetStatus (eReturnStatusSuccessFinishNoResult);
937254721Semaste
938254721Semaste        Args cmd_args(command);
939254721Semaste        const size_t argc = cmd_args.GetArgumentCount ();
940254721Semaste
941254721Semaste        if (argc < 3)
942254721Semaste        {
943254721Semaste            result.AppendError ("'settings insert-after' takes more arguments");
944254721Semaste            result.SetStatus (eReturnStatusFailed);
945254721Semaste            return false;
946254721Semaste        }
947254721Semaste
948254721Semaste        const char *var_name = cmd_args.GetArgumentAtIndex (0);
949254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
950254721Semaste        {
951254721Semaste            result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied");
952254721Semaste            result.SetStatus (eReturnStatusFailed);
953254721Semaste            return false;
954254721Semaste        }
955254721Semaste
956254721Semaste        // Split the raw command into var_name, index_value, and value triple.
957254721Semaste        llvm::StringRef raw_str(command);
958254721Semaste        std::string var_value_string = raw_str.split(var_name).second.str();
959254721Semaste        const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
960254721Semaste
961254721Semaste        Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
962254721Semaste                                                                  eVarSetOperationInsertAfter,
963254721Semaste                                                                  var_name,
964254721Semaste                                                                  var_value_cstr));
965254721Semaste        if (error.Fail())
966254721Semaste        {
967254721Semaste            result.AppendError (error.AsCString());
968254721Semaste            result.SetStatus (eReturnStatusFailed);
969254721Semaste            return false;
970254721Semaste        }
971254721Semaste
972254721Semaste        return result.Succeeded();
973254721Semaste    }
974254721Semaste};
975254721Semaste
976254721Semaste//-------------------------------------------------------------------------
977254721Semaste// CommandObjectSettingsAppend
978254721Semaste//-------------------------------------------------------------------------
979254721Semaste
980254721Semasteclass CommandObjectSettingsAppend : public CommandObjectRaw
981254721Semaste{
982254721Semastepublic:
983254721Semaste    CommandObjectSettingsAppend (CommandInterpreter &interpreter) :
984254721Semaste        CommandObjectRaw (interpreter,
985254721Semaste                          "settings append",
986254721Semaste                          "Append a new value to the end of an internal debugger settings array, dictionary or string variable.",
987254721Semaste                          NULL)
988254721Semaste    {
989254721Semaste        CommandArgumentEntry arg1;
990254721Semaste        CommandArgumentEntry arg2;
991254721Semaste        CommandArgumentData var_name_arg;
992254721Semaste        CommandArgumentData value_arg;
993254721Semaste
994254721Semaste        // Define the first (and only) variant of this arg.
995254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
996254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
997254721Semaste
998254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
999254721Semaste        arg1.push_back (var_name_arg);
1000254721Semaste
1001254721Semaste        // Define the first (and only) variant of this arg.
1002254721Semaste        value_arg.arg_type = eArgTypeValue;
1003254721Semaste        value_arg.arg_repetition = eArgRepeatPlain;
1004254721Semaste
1005254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
1006254721Semaste        arg2.push_back (value_arg);
1007254721Semaste
1008254721Semaste        // Push the data for the first argument into the m_arguments vector.
1009254721Semaste        m_arguments.push_back (arg1);
1010254721Semaste        m_arguments.push_back (arg2);
1011254721Semaste    }
1012254721Semaste
1013254721Semaste    virtual
1014254721Semaste    ~CommandObjectSettingsAppend () {}
1015254721Semaste
1016254721Semaste    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
1017254721Semaste    virtual bool
1018254721Semaste    WantsCompletion() { return true; }
1019254721Semaste
1020254721Semaste    virtual int
1021254721Semaste    HandleArgumentCompletion (Args &input,
1022254721Semaste                              int &cursor_index,
1023254721Semaste                              int &cursor_char_position,
1024254721Semaste                              OptionElementVector &opt_element_vector,
1025254721Semaste                              int match_start_point,
1026254721Semaste                              int max_return_elements,
1027254721Semaste                              bool &word_complete,
1028254721Semaste                              StringList &matches)
1029254721Semaste    {
1030254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
1031254721Semaste
1032254721Semaste        // Attempting to complete variable name
1033254721Semaste        if (cursor_index < 2)
1034254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1035254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
1036254721Semaste                                                                 completion_str.c_str(),
1037254721Semaste                                                                 match_start_point,
1038254721Semaste                                                                 max_return_elements,
1039254721Semaste                                                                 NULL,
1040254721Semaste                                                                 word_complete,
1041254721Semaste                                                                 matches);
1042254721Semaste
1043254721Semaste        return matches.GetSize();
1044254721Semaste    }
1045254721Semaste
1046254721Semasteprotected:
1047254721Semaste    virtual bool
1048254721Semaste    DoExecute (const char *command, CommandReturnObject &result)
1049254721Semaste    {
1050254721Semaste        result.SetStatus (eReturnStatusSuccessFinishNoResult);
1051254721Semaste        Args cmd_args(command);
1052254721Semaste        const size_t argc = cmd_args.GetArgumentCount ();
1053254721Semaste
1054254721Semaste        if (argc < 2)
1055254721Semaste        {
1056254721Semaste            result.AppendError ("'settings append' takes more arguments");
1057254721Semaste            result.SetStatus (eReturnStatusFailed);
1058254721Semaste            return false;
1059254721Semaste        }
1060254721Semaste
1061254721Semaste        const char *var_name = cmd_args.GetArgumentAtIndex (0);
1062254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
1063254721Semaste        {
1064254721Semaste            result.AppendError ("'settings append' command requires a valid variable name; No value supplied");
1065254721Semaste            result.SetStatus (eReturnStatusFailed);
1066254721Semaste            return false;
1067254721Semaste        }
1068254721Semaste
1069254721Semaste        // Do not perform cmd_args.Shift() since StringRef is manipulating the
1070254721Semaste        // raw character string later on.
1071254721Semaste
1072254721Semaste        // Split the raw command into var_name and value pair.
1073254721Semaste        llvm::StringRef raw_str(command);
1074254721Semaste        std::string var_value_string = raw_str.split(var_name).second.str();
1075254721Semaste        const char *var_value_cstr = Args::StripSpaces(var_value_string, true, true, false);
1076254721Semaste
1077254721Semaste        Error error(m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
1078254721Semaste                                                                  eVarSetOperationAppend,
1079254721Semaste                                                                  var_name,
1080254721Semaste                                                                  var_value_cstr));
1081254721Semaste        if (error.Fail())
1082254721Semaste        {
1083254721Semaste            result.AppendError (error.AsCString());
1084254721Semaste            result.SetStatus (eReturnStatusFailed);
1085254721Semaste            return false;
1086254721Semaste        }
1087254721Semaste
1088254721Semaste        return result.Succeeded();
1089254721Semaste    }
1090254721Semaste};
1091254721Semaste
1092254721Semaste//-------------------------------------------------------------------------
1093254721Semaste// CommandObjectSettingsClear
1094254721Semaste//-------------------------------------------------------------------------
1095254721Semaste
1096254721Semasteclass CommandObjectSettingsClear : public CommandObjectParsed
1097254721Semaste{
1098254721Semastepublic:
1099254721Semaste    CommandObjectSettingsClear (CommandInterpreter &interpreter) :
1100254721Semaste        CommandObjectParsed (interpreter,
1101254721Semaste                             "settings clear",
1102254721Semaste                             "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.",
1103254721Semaste                             NULL)
1104254721Semaste    {
1105254721Semaste        CommandArgumentEntry arg;
1106254721Semaste        CommandArgumentData var_name_arg;
1107254721Semaste
1108254721Semaste        // Define the first (and only) variant of this arg.
1109254721Semaste        var_name_arg.arg_type = eArgTypeSettingVariableName;
1110254721Semaste        var_name_arg.arg_repetition = eArgRepeatPlain;
1111254721Semaste
1112254721Semaste        // There is only one variant this argument could be; put it into the argument entry.
1113254721Semaste        arg.push_back (var_name_arg);
1114254721Semaste
1115254721Semaste        // Push the data for the first argument into the m_arguments vector.
1116254721Semaste        m_arguments.push_back (arg);
1117254721Semaste    }
1118254721Semaste
1119254721Semaste    virtual
1120254721Semaste    ~CommandObjectSettingsClear () {}
1121254721Semaste
1122254721Semaste    virtual int
1123254721Semaste    HandleArgumentCompletion (Args &input,
1124254721Semaste                              int &cursor_index,
1125254721Semaste                              int &cursor_char_position,
1126254721Semaste                              OptionElementVector &opt_element_vector,
1127254721Semaste                              int match_start_point,
1128254721Semaste                              int max_return_elements,
1129254721Semaste                              bool &word_complete,
1130254721Semaste                              StringList &matches)
1131254721Semaste    {
1132254721Semaste        std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
1133254721Semaste
1134254721Semaste        // Attempting to complete variable name
1135254721Semaste        if (cursor_index < 2)
1136254721Semaste            CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1137254721Semaste                                                                 CommandCompletions::eSettingsNameCompletion,
1138254721Semaste                                                                 completion_str.c_str(),
1139254721Semaste                                                                 match_start_point,
1140254721Semaste                                                                 max_return_elements,
1141254721Semaste                                                                 NULL,
1142254721Semaste                                                                 word_complete,
1143254721Semaste                                                                 matches);
1144254721Semaste
1145254721Semaste        return matches.GetSize();
1146254721Semaste    }
1147254721Semaste
1148254721Semasteprotected:
1149254721Semaste    virtual bool
1150254721Semaste    DoExecute (Args& command, CommandReturnObject &result)
1151254721Semaste    {
1152254721Semaste        result.SetStatus (eReturnStatusSuccessFinishNoResult);
1153254721Semaste        const size_t argc = command.GetArgumentCount ();
1154254721Semaste
1155254721Semaste        if (argc != 1)
1156254721Semaste        {
1157254721Semaste            result.AppendError ("'setttings clear' takes exactly one argument");
1158254721Semaste            result.SetStatus (eReturnStatusFailed);
1159254721Semaste            return false;
1160254721Semaste        }
1161254721Semaste
1162254721Semaste        const char *var_name = command.GetArgumentAtIndex (0);
1163254721Semaste        if ((var_name == NULL) || (var_name[0] == '\0'))
1164254721Semaste        {
1165254721Semaste            result.AppendError ("'settings clear' command requires a valid variable name; No value supplied");
1166254721Semaste            result.SetStatus (eReturnStatusFailed);
1167254721Semaste            return false;
1168254721Semaste        }
1169254721Semaste
1170254721Semaste        Error error (m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx,
1171254721Semaste                                                                   eVarSetOperationClear,
1172254721Semaste                                                                   var_name,
1173254721Semaste                                                                   NULL));
1174254721Semaste        if (error.Fail())
1175254721Semaste        {
1176254721Semaste            result.AppendError (error.AsCString());
1177254721Semaste            result.SetStatus (eReturnStatusFailed);
1178254721Semaste            return false;
1179254721Semaste        }
1180254721Semaste
1181254721Semaste        return result.Succeeded();
1182254721Semaste    }
1183254721Semaste};
1184254721Semaste
1185254721Semaste//-------------------------------------------------------------------------
1186254721Semaste// CommandObjectMultiwordSettings
1187254721Semaste//-------------------------------------------------------------------------
1188254721Semaste
1189254721SemasteCommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpreter &interpreter) :
1190254721Semaste    CommandObjectMultiword (interpreter,
1191254721Semaste                            "settings",
1192254721Semaste                            "A set of commands for manipulating internal settable debugger variables.",
1193254721Semaste                            "settings <command> [<command-options>]")
1194254721Semaste{
1195254721Semaste    LoadSubCommand ("set",           CommandObjectSP (new CommandObjectSettingsSet (interpreter)));
1196254721Semaste    LoadSubCommand ("show",          CommandObjectSP (new CommandObjectSettingsShow (interpreter)));
1197254721Semaste    LoadSubCommand ("list",          CommandObjectSP (new CommandObjectSettingsList (interpreter)));
1198254721Semaste    LoadSubCommand ("remove",        CommandObjectSP (new CommandObjectSettingsRemove (interpreter)));
1199254721Semaste    LoadSubCommand ("replace",       CommandObjectSP (new CommandObjectSettingsReplace (interpreter)));
1200254721Semaste    LoadSubCommand ("insert-before", CommandObjectSP (new CommandObjectSettingsInsertBefore (interpreter)));
1201254721Semaste    LoadSubCommand ("insert-after",  CommandObjectSP (new CommandObjectSettingsInsertAfter (interpreter)));
1202254721Semaste    LoadSubCommand ("append",        CommandObjectSP (new CommandObjectSettingsAppend (interpreter)));
1203254721Semaste    LoadSubCommand ("clear",         CommandObjectSP (new CommandObjectSettingsClear (interpreter)));
1204254721Semaste}
1205254721Semaste
1206254721SemasteCommandObjectMultiwordSettings::~CommandObjectMultiwordSettings ()
1207254721Semaste{
1208254721Semaste}
1209