File: lldbcommand.cpp

package info (click to toggle)
kdevelop 4%3A5.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 52,544 kB
  • sloc: cpp: 254,897; python: 3,380; sh: 1,271; ansic: 657; xml: 221; php: 95; makefile: 36; lisp: 13; sed: 12
file content (229 lines) | stat: -rw-r--r-- 7,704 bytes parent folder | download | duplicates (2)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
165
166
167
168
169
170
171
172
173
174
175
176
177
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * LLDB specific version of MI command
 * 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
{
    if (!overrideCmd.isEmpty()) {
        return overrideCmd;
    }

    QString command;
    bool isMI = false;

    // TODO: find alternatives to the following command which are not supported in lldb-mi
    switch(type()) {
        case BreakCommands:
            // empty command
            break;
        case BreakInfo:
            // empty command
            break;
        case BreakInsert: // in lldb-mi, '-f' must be the last option switch right before location
            command = QStringLiteral("break-insert");
            isMI = true;
            break;
        case BreakList:
            // empty command
            break;
        case BreakWatch:
            command = QStringLiteral("break set var");
            break;

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

        case EnableTimings:
            command = QStringLiteral("enable-timings");
            break;

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

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

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

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

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

        case SignalHandle:
            command = QStringLiteral("process handle");
            break;

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

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

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

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

    if (isMI) {
        command.prepend(QLatin1Char('-'));
    }
    return command;
}

QString LldbCommand::cmdToSend()
{
    switch (type()) {
        // -gdb-set is only partially implemented
        case GdbSet: {
            QString env_name = QStringLiteral("environment ");
            QString disassembly_flavor = QStringLiteral("disassembly-flavor ");
            if (command_.startsWith(env_name)) {
                command_.remove(0, env_name.length());
                overrideCmd = QStringLiteral("settings set target.env-vars");
            } else if (command_.startsWith(disassembly_flavor)) {
                command_.remove(0, disassembly_flavor.length());
                overrideCmd = QStringLiteral("settings set target.x86-disassembly-flavor");
            }
            break;
        }
        // find the position to insert '-f'
        case BreakInsert: {
            if (!overrideCmd.isEmpty()) {
                // already done
                break;
            }
            int p = command_.length() - 1;
            bool quoted = false;
            if (command_[p] == QLatin1Char('"')) {
                quoted = true; // should always be the case
            }
            --p;
            for (; p >= 0; --p) {
                // find next '"' or ' '
                if (quoted) {
                    if (command_[p] == QLatin1Char('"') && (p == 0 || command_[p-1] != QLatin1Char('\\')))
                        break;
                } else {
                    if (command_[p] == QLatin1Char(' '))
                        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() + QLatin1Char(' ') + command_.leftRef(p);
            command_ = QLatin1String("-f ") + command_.midRef(p, command_.length());
            break;
        }
        case BreakWatch:
            if (command_.startsWith(QLatin1String("-r "))) {
                command_ = QLatin1String("-w read ") + command_.midRef(3);
            } else if (command_.startsWith(QLatin1String("-a "))) {
                command_ = QLatin1String("-w read_write ") + command_.midRef(3);
            }
            break;
        case StackListArguments:
            // some times when adding the command, the current frame is invalid,
            // but is valid at sending time
            if (command_.endsWith(QLatin1String("-1 -1"))) {
                command_.replace(QLatin1String("-1 -1"), QStringLiteral("%1 %1").arg(frame()));
            }
            break;
        default:
            break;
    }
    return MICommand::cmdToSend();
}