Debugger: Use Qt's JSON encoder for debugger protocol

The V4 debug service expects correct JSON as input and gdb, lldb, and
pdb expect Python object literals. There is a subset of JSON that is
also valid as Python object literals and we use that for the protocol
spoken with gdb, lldb, and pdb. The strings passed to CDB are tunneled
through JSON strings and converted to byte arrays before sending them.

Change-Id: I87319b5450e5c3c3b29c565b75cddaa612767611
Task-number: QTCREATORBUG-14931
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2015-09-14 13:40:35 +02:00
parent 7d3bb6fdee
commit d5707e0e32
8 changed files with 99 additions and 119 deletions

View File

@@ -1174,7 +1174,7 @@ void CdbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages
// Post command to the cdb process
void CdbEngine::runCommand(const DebuggerCommand &dbgCmd, int flags)
{
QByteArray cmd = dbgCmd.function + dbgCmd.arguments();
QByteArray cmd = dbgCmd.function + dbgCmd.argsToString();
if (!m_accessible) {
const QString msg = QString::fromLatin1("Attempt to issue command \"%1\" to non-accessible session (%2)")
.arg(QString::fromLocal8Bit(cmd), QString::fromLatin1(stateName(state())));
@@ -1197,8 +1197,8 @@ void CdbEngine::runCommand(const DebuggerCommand &dbgCmd, int flags)
// pass along token for identification in hash.
const int token = m_nextCommandToken++;
str << m_extensionCommandPrefixBA << dbgCmd.function << " -t " << token;
if (!dbgCmd.args.isEmpty())
str << ' ' << dbgCmd.args;
if (dbgCmd.args.isString())
str << ' ' << dbgCmd.argsToString();
m_commandForToken.insert(token, dbgCmd);
} else {
str << cmd;
@@ -1332,7 +1332,7 @@ void CdbEngine::doUpdateLocals(const UpdateParameters &updateParameters)
str << blankSeparator << updateParameters.partialVariable;
DebuggerCommand cmd("locals");
cmd.args = arguments;
cmd.args = QLatin1String(arguments);
cmd.callback = [this, partialUpdate](const DebuggerResponse &r) { handleLocals(r, partialUpdate); };
runCommand(cmd, ExtensionCommand);
}
@@ -1557,8 +1557,10 @@ void CdbEngine::fetchMemory(MemoryAgent *agent, QObject *editor, quint64 addr, q
void CdbEngine::postFetchMemory(const MemoryViewCookie &cookie)
{
DebuggerCommand cmd("memory");
ByteArrayInputStream str(cmd.args);
QByteArray args;
ByteArrayInputStream str(args);
str << cookie.address << ' ' << cookie.length;
cmd.args = QLatin1String(args);
cmd.callback = [this, cookie](const DebuggerResponse &response) {
if (response.resultClass == ResultDone && cookie.agent) {
const QByteArray data = QByteArray::fromBase64(response.data.data());
@@ -1619,7 +1621,7 @@ void CdbEngine::reloadFullStack()
if (debug)
qDebug("%s", Q_FUNC_INFO);
DebuggerCommand cmd("stack");
cmd.args = "unlimited";
cmd.args = QStringLiteral("unlimited");
cmd.callback = CB(handleStackTrace);
runCommand(cmd, ExtensionCommand);
}
@@ -1627,7 +1629,7 @@ void CdbEngine::reloadFullStack()
void CdbEngine::listBreakpoints()
{
DebuggerCommand cmd("breakpoints");
cmd.args = "-v";
cmd.args = QStringLiteral("-v");
cmd.callback = CB(handleBreakPoints);
runCommand(cmd, ExtensionCommand);
}
@@ -1845,11 +1847,12 @@ unsigned CdbEngine::examineStopReason(const GdbMi &stopReason,
QString::number(threadId));
DebuggerCommand cmd("expression");
cmd.args = parameters.condition;
if (cmd.args.contains(' ') && !cmd.args.startsWith('"')) {
cmd.args.prepend('"');
cmd.args.append('"');
QByteArray args = parameters.condition;
if (args.contains(' ') && !args.startsWith('"')) {
args.prepend('"');
args.append('"');
}
cmd.args = QLatin1String(args);
cmd.callback = [this, id, stopReason](const DebuggerResponse &response) {
handleExpression(response, id, stopReason);
};
@@ -3092,7 +3095,7 @@ void CdbEngine::watchPoint(const QPoint &p)
void CdbEngine::postWidgetAtCommand()
{
DebuggerCommand cmd("widgetat");
cmd.args = QByteArray::number(m_watchPointX) + ' ' + QByteArray::number(m_watchPointY);
cmd.args = QString::fromLatin1("%1 %2").arg(m_watchPointX, m_watchPointY);
cmd.callback = CB(handleWidgetAt);
runCommand(cmd, ExtensionCommand);
}