summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectAppend.cpp
blob: 89d5cee71e4de78a8fbbacdd5b20d2acce39b7e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//===-- CommandObjectAppend.cpp ---------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "CommandObjectAppend.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"

using namespace lldb;
using namespace lldb_private;

//-----------------------------------------------------------------------------
// CommandObjectAppend
//-----------------------------------------------------------------------------

CommandObjectAppend::CommandObjectAppend () :
    CommandObject ("append",
                   "Allows the user to append a value to a single debugger setting variable, for settings that are of list types. Type 'settings' to see a list of debugger setting variables",
                   "append <var-name> <value-string>")
{
}

CommandObjectAppend::~CommandObjectAppend ()
{
}

bool
CommandObjectAppend::Execute
(
    CommandInterpreter &interpreter,
    Args& command,
    CommandReturnObject &result
)
{
    CommandInterpreter::VariableMap::iterator pos;

    const int argc = command.GetArgumentCount();
    if (argc < 2)
    {
        result.AppendError ("'append' requires at least two arguments");
        result.SetStatus (eReturnStatusFailed);
        return false;
    }

    const char *var_name = command.GetArgumentAtIndex(0);
    command.Shift();


    if (var_name == NULL || var_name[0] == '\0')
    {
        result.AppendError ("'set' command requires a valid variable name. No value supplied");
        result.SetStatus (eReturnStatusFailed);
    }
    else
    {
        StateVariable *var = interpreter.GetStateVariable(var_name);
        if (var == NULL)
        {
            result.AppendErrorWithFormat ("'%s' is not a settable internal variable.\n", var_name);
            result.SetStatus (eReturnStatusFailed);
        }
        else
        {
            if (var->GetType() == StateVariable::eTypeString)
            {
                for (size_t i = 0; i < command.GetArgumentCount(); ++i)
                    var->AppendStringValue (command.GetArgumentAtIndex(i));
                result.SetStatus (eReturnStatusSuccessFinishNoResult);
            }
            else if (var->GetType() == StateVariable::eTypeStringArray)
            {
                var->GetArgs().AppendArguments (command);
                result.SetStatus (eReturnStatusSuccessFinishNoResult);
            }
            else
            {
                result.AppendErrorWithFormat ("Values cannot be appended to variable '%s'.  Try 'set' instead.\n", var_name);
                result.SetStatus (eReturnStatusFailed);
            }
        }
    }
    return result.Succeeded();
}

OpenPOWER on IntegriCloud