lldbcommand.cpp 6.56 KB
Newer Older
1
/*
Peifeng Yu's avatar
Peifeng Yu committed
2
 * LLDB specific version of MI command
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
 * Copyright 2016  Aetf <aetf@unlimitedcodeworks.xyz>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "lldbcommand.h"

using namespace KDevMI::LLDB;
using namespace KDevMI::MI;

LldbCommand::LldbCommand(CommandType type, const QString& arguments, CommandFlags flags)
    : MICommand(type, arguments, flags)
{

}

LldbCommand::~LldbCommand()
{
}

QString LldbCommand::miCommand() const
{
40
41
42
43
    if (!overrideCmd.isEmpty()) {
        return overrideCmd;
    }

44
45
    QString command;
    bool isMI = false;
46

47
48
49
50
51
52
53
54
    // TODO: find alternatives to the following command which are not supported in lldb-mi
    switch(type()) {
        case BreakCommands:
            command = "";
            break;
        case BreakInfo:
            command = "";
            break;
55
56
57
58
        case BreakInsert: // in lldb-mi, '-f' must be the last option switch right before location
            command = "break-insert";
            isMI = true;
            break;
59
60
61
62
        case BreakList:
            command = "";
            break;
        case BreakWatch:
63
            command = "break set var";
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
            break;

        case DataListChangedRegisters:
            command = "data-list-changed-registers";
            break;
        case DataReadMemory: // not implemented, deprecated
            command = "data-read-memory";
            break;
        case DataWriteRegisterVariables:
            command = "data-write-register-values";
            break;

        case EnableTimings:
            command = "enable-timings";
            break;

        case EnvironmentDirectory:
            command = "environment-directory";
            break;
        case EnvironmentPath:
            command = "environment-path";
            break;
        case EnvironmentPwd:
            command = "environment-pwd";
            break;

        case ExecUntil:
            // TODO: write test case for this
            command = "thread until";
            break;

        case FileExecFile:
            command = "file-exec-file";//"exec-file"
            break;
        case FileListExecSourceFile:
            command = "file-list-exec-source-file";
            break;
        case FileListExecSourceFiles:
            command = "file-list-exec-source-files";
            break;
        case FileSymbolFile:
            command = "file-symbol-file";//"symbol-file"
            break;

        case GdbVersion:
            command = "gdb-version";//"show version"
            break;

        case InferiorTtyShow:
            command = "inferior-tty-show";
            break;

116
117
        case SignalHandle:
            command = "process handle";
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
            break;

        case TargetDisconnect:
            command = "target-disconnect";//"disconnect"
            break;
        case TargetDownload:
            command = "target-download";
            break;

        case ThreadListIds:
            command = "thread-list-ids";
            break;
        case ThreadSelect:
            command = "thread-select";
            break;

        case TraceFind:
            command = "trace-find";
            break;
        case TraceStart:
            command = "trace-start";
            break;
        case TraceStop:
            command = "trace-stop";
            break;

        case VarInfoNumChildren:
            command = "var-info-num-children";
            break;
        case VarInfoType:
            command = "var-info-type";
            break;
        case VarSetFrozen:
            command = "var-set-frozen";
            break;
        case VarShowFormat:
            command = "var-show-format";
            break;
        default:
            return MICommand::miCommand();
    }

    if (isMI) {
        command.prepend('-');
    }
    return command;
}
165
166
167
168
169
170
171
172
173
174
175
176
177

QString LldbCommand::cmdToSend()
{
    switch (type()) {
        // -gdb-set is only partially implemented
        case GdbSet: {
            QString env_name = "environment ";
            if (command_.startsWith(env_name)) {
                command_ = command_.mid(env_name.length());
                overrideCmd = "settings set target.env-vars";
            }
            break;
        }
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        // find the postion to insert '-f'
        case BreakInsert: {
            if (!overrideCmd.isEmpty()) {
                // already done
                break;
            }
            int p = command_.length() - 1;
            bool quoted = false;
            if (command_[p] == '"') {
                quoted = true; // should always be the case
            }
            --p;
            for (; p >= 0; --p) {
                // find next '"' or ' '
                if (quoted) {
                    if (command_[p] == '"' && (p == 0 || command_[p-1] != '\\'))
                        break;
                } else {
                    if (command_[p] == ' ')
                        break;
                }
            }
            if (p < 0) p = 0; // this means the command is malformated, we proceed anyway.

            // move other switches like '-d' '-c' into miCommand part
            overrideCmd = miCommand() + " " + command_.left(p);
            command_ = "-f " + command_.mid(p, command_.length());
            break;
        }
207
208
209
210
211
212
213
        case BreakWatch:
            if (command_.startsWith("-r ")) {
                command_ = "-w read " + command_.mid(3);
            } else if (command_.startsWith("-a ")) {
                command_ = "-w read_write " + command_.mid(3);
            }
            break;
214
215
216
217
218
219
220
        case StackListArguments:
            // some times when adding the command, the current frame is invalid,
            // but is valid at sending time
            if (command_.endsWith("-1 -1")) {
                command_.replace("-1 -1", QStringLiteral("%1 %1").arg(frame()));
            }
            break;
221
222
223
224
225
        default:
            break;
    }
    return MICommand::cmdToSend();
}