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
|
/*
SPDX-FileCopyrightText: 2016 Aetf <aetf@unlimitedcodeworks.xyz>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#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_.at(p) == QLatin1Char('"')) {
quoted = true; // should always be the case
}
--p;
for (; p >= 0; --p) {
// find next '"' or ' '
if (quoted) {
if (command_.at(p) == QLatin1Char('"') && (p == 0 || command_.at(p - 1) != QLatin1Char('\\')))
break;
} else {
if (command_.at(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
const QStringView commandView = command_;
overrideCmd = miCommand() + QLatin1Char(' ') + commandView.first(p);
command_ = QLatin1String("-f ") + commandView.sliced(p);
break;
}
case BreakWatch:
if (command_.startsWith(QLatin1String("-r "))) {
command_ = QLatin1String("-w read ") + QStringView{command_}.sliced(3);
} else if (command_.startsWith(QLatin1String("-a "))) {
command_ = QLatin1String("-w read_write ") + QStringView{command_}.sliced(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();
}
|