Commit 5c58293a authored by hjk's avatar hjk

Debugger: Some Python 3 support for PdbEngine

Change-Id: I052bc093086a5da0b2cbd4e99df32e42627ceaf5
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 5b5192d3
import pdb
import sys
import linecache
import inspect
import os
def qdebug(cmd, args): def qdebug(cmd, args):
import sys
import linecache
import inspect
import os
class Dumper: class Dumper:
def __init__(self): def __init__(self):
self.output = '' self.output = ''
...@@ -165,7 +165,11 @@ def qdebug(cmd, args): ...@@ -165,7 +165,11 @@ def qdebug(cmd, args):
self.putField("childnumchild", 2) self.putField("childnumchild", 2)
self.put("children=[") self.put("children=[")
i = 0 i = 0
for (k, v) in value.iteritems(): if sys.version_info[0] >= 3:
vals = value.iter()
else:
vals = value.iteritems()
for (k, v) in vals:
self.put("{") self.put("{")
self.putType(" ") self.putType(" ")
self.putValue("%s: %s" % (k, v)) self.putValue("%s: %s" % (k, v))
......
...@@ -401,7 +401,9 @@ DebuggerRunControl *DebuggerRunControlFactory::doCreate ...@@ -401,7 +401,9 @@ DebuggerRunControl *DebuggerRunControlFactory::doCreate
} }
if (sp.masterEngineType == NoEngineType) { if (sp.masterEngineType == NoEngineType) {
if (sp.executable.endsWith(_(".py")) || sp.executable == _("/usr/bin/python")) { if (sp.executable.endsWith(_(".py"))
|| sp.executable == _("/usr/bin/python")
|| sp.executable == _("/usr/bin/python3")) {
sp.masterEngineType = PdbEngineType; sp.masterEngineType = PdbEngineType;
} else { } else {
if (RunConfiguration *rc = sp.runConfiguration) { if (RunConfiguration *rc = sp.runConfiguration) {
......
...@@ -82,23 +82,23 @@ void PdbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages ...@@ -82,23 +82,23 @@ void PdbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages
showMessage(_("PDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: ") + command); showMessage(_("PDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: ") + command);
return; return;
} }
QTC_ASSERT(m_pdbProc.state() == QProcess::Running, notifyEngineIll()); QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
postDirectCommand(command.toLatin1()); postDirectCommand(command.toLatin1());
} }
void PdbEngine::postDirectCommand(const QByteArray &command) void PdbEngine::postDirectCommand(const QByteArray &command)
{ {
QTC_ASSERT(m_pdbProc.state() == QProcess::Running, notifyEngineIll()); QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
showMessage(_(command), LogInput); showMessage(_(command), LogInput);
m_pdbProc.write(command + '\n'); m_proc.write(command + '\n');
} }
void PdbEngine::runCommand(const DebuggerCommand &cmd) void PdbEngine::runCommand(const DebuggerCommand &cmd)
{ {
QTC_ASSERT(m_pdbProc.state() == QProcess::Running, notifyEngineIll()); QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
QByteArray command = "qdebug('" + cmd.function + "',{" + cmd.args + "})"; QByteArray command = "qdebug('" + cmd.function + "',{" + cmd.args + "})";
showMessage(_(command), LogInput); showMessage(_(command), LogInput);
m_pdbProc.write(command + '\n'); m_proc.write(command + '\n');
} }
void PdbEngine::shutdownInferior() void PdbEngine::shutdownInferior()
...@@ -110,30 +110,30 @@ void PdbEngine::shutdownInferior() ...@@ -110,30 +110,30 @@ void PdbEngine::shutdownInferior()
void PdbEngine::shutdownEngine() void PdbEngine::shutdownEngine()
{ {
QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state()); QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state());
m_pdbProc.kill(); m_proc.kill();
} }
void PdbEngine::setupEngine() void PdbEngine::setupEngine()
{ {
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
m_pdb = _("python"); QString python = pythonInterpreter();
showMessage(_("STARTING PDB ") + m_pdb); showMessage(_("STARTING PDB ") + python);
connect(&m_pdbProc, static_cast<void(QProcess::*)(QProcess::ProcessError)>(&QProcess::error), connect(&m_proc, static_cast<void(QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
this, &PdbEngine::handlePdbError); this, &PdbEngine::handlePdbError);
connect(&m_pdbProc, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), connect(&m_proc, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished),
this, &PdbEngine::handlePdbFinished); this, &PdbEngine::handlePdbFinished);
connect(&m_pdbProc, &QProcess::readyReadStandardOutput, connect(&m_proc, &QProcess::readyReadStandardOutput,
this, &PdbEngine::readPdbStandardOutput); this, &PdbEngine::readPdbStandardOutput);
connect(&m_pdbProc, &QProcess::readyReadStandardError, connect(&m_proc, &QProcess::readyReadStandardError,
this, &PdbEngine::readPdbStandardError); this, &PdbEngine::readPdbStandardError);
m_pdbProc.start(m_pdb, QStringList() << _("-i")); m_proc.start(python, QStringList() << _("-i"));
if (!m_pdbProc.waitForStarted()) { if (!m_proc.waitForStarted()) {
const QString msg = tr("Unable to start pdb \"%1\": %2") const QString msg = tr("Unable to start pdb \"%1\": %2")
.arg(m_pdb, m_pdbProc.errorString()); .arg(pythonInterpreter(), m_proc.errorString());
notifyEngineSetupFailed(); notifyEngineSetupFailed();
showMessage(_("ADAPTER START FAILED")); showMessage(_("ADAPTER START FAILED"));
if (!msg.isEmpty()) if (!msg.isEmpty())
...@@ -165,15 +165,23 @@ QString PdbEngine::mainPythonFile() const ...@@ -165,15 +165,23 @@ QString PdbEngine::mainPythonFile() const
return QFileInfo(startParameters().processArgs).absoluteFilePath(); return QFileInfo(startParameters().processArgs).absoluteFilePath();
} }
QString PdbEngine::pythonInterpreter() const
{
return startParameters().executable;
}
void PdbEngine::runEngine() void PdbEngine::runEngine()
{ {
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state()); QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
showStatusMessage(tr("Running requested..."), 5000); showStatusMessage(tr("Running requested..."), 5000);
const QByteArray dumperSourcePath = ICore::resourcePath().toLocal8Bit() + "/debugger/"; QByteArray bridge = ICore::resourcePath().toUtf8() + "/debugger/pdbbridge.py";
QByteArray pdb = "/usr/bin/pdb";
if (pythonInterpreter().endsWith(QLatin1Char('3')))
pdb += '3';
postDirectCommand("import sys"); postDirectCommand("import sys");
postDirectCommand("sys.argv.append('" + mainPythonFile().toLocal8Bit() + "')"); postDirectCommand("sys.argv.append('" + mainPythonFile().toLocal8Bit() + "')");
postDirectCommand("execfile('/usr/bin/pdb')"); postDirectCommand("exec(open('" + pdb + "').read())");
postDirectCommand("execfile('" + dumperSourcePath + "pdbbridge.py')"); postDirectCommand("exec(open('" + bridge + "').read())");
attemptBreakpointSynchronization(); attemptBreakpointSynchronization();
notifyEngineRunAndInferiorStopOk(); notifyEngineRunAndInferiorStopOk();
continueInferior(); continueInferior();
...@@ -412,7 +420,7 @@ void PdbEngine::handlePdbError(QProcess::ProcessError error) ...@@ -412,7 +420,7 @@ void PdbEngine::handlePdbError(QProcess::ProcessError error)
case QProcess::Timedout: case QProcess::Timedout:
default: default:
//setState(EngineShutdownRequested, true); //setState(EngineShutdownRequested, true);
m_pdbProc.kill(); m_proc.kill();
AsynchronousMessageBox::critical(tr("Pdb I/O Error"), errorMessage(error)); AsynchronousMessageBox::critical(tr("Pdb I/O Error"), errorMessage(error));
break; break;
} }
...@@ -425,7 +433,7 @@ QString PdbEngine::errorMessage(QProcess::ProcessError error) const ...@@ -425,7 +433,7 @@ QString PdbEngine::errorMessage(QProcess::ProcessError error) const
return tr("The Pdb process failed to start. Either the " return tr("The Pdb process failed to start. Either the "
"invoked program \"%1\" is missing, or you may have insufficient " "invoked program \"%1\" is missing, or you may have insufficient "
"permissions to invoke the program.") "permissions to invoke the program.")
.arg(m_pdb); .arg(pythonInterpreter());
case QProcess::Crashed: case QProcess::Crashed:
return tr("The Pdb process crashed some time after starting " return tr("The Pdb process crashed some time after starting "
"successfully."); "successfully.");
...@@ -454,7 +462,7 @@ void PdbEngine::handlePdbFinished(int code, QProcess::ExitStatus type) ...@@ -454,7 +462,7 @@ void PdbEngine::handlePdbFinished(int code, QProcess::ExitStatus type)
void PdbEngine::readPdbStandardError() void PdbEngine::readPdbStandardError()
{ {
QByteArray err = m_pdbProc.readAllStandardError(); QByteArray err = m_proc.readAllStandardError();
qDebug() << "\nPDB STDERR" << err; qDebug() << "\nPDB STDERR" << err;
//qWarning() << "Unexpected pdb stderr:" << err; //qWarning() << "Unexpected pdb stderr:" << err;
//showMessage(_("Unexpected pdb stderr: " + err)); //showMessage(_("Unexpected pdb stderr: " + err));
...@@ -463,7 +471,7 @@ void PdbEngine::readPdbStandardError() ...@@ -463,7 +471,7 @@ void PdbEngine::readPdbStandardError()
void PdbEngine::readPdbStandardOutput() void PdbEngine::readPdbStandardOutput()
{ {
QByteArray out = m_pdbProc.readAllStandardOutput(); QByteArray out = m_proc.readAllStandardOutput();
qDebug() << "\nPDB STDOUT" << out; qDebug() << "\nPDB STDOUT" << out;
handleOutput(out); handleOutput(out);
} }
......
...@@ -97,7 +97,9 @@ private: ...@@ -97,7 +97,9 @@ private:
bool supportsThreads() const { return true; } bool supportsThreads() const { return true; }
bool isSynchronous() const { return true; } bool isSynchronous() const { return true; }
void updateWatchItem(WatchItem *item); void updateWatchItem(WatchItem *item);
QString mainPythonFile() const; QString mainPythonFile() const;
QString pythonInterpreter() const;
void runCommand(const DebuggerCommand &cmd); void runCommand(const DebuggerCommand &cmd);
void postDirectCommand(const QByteArray &command); void postDirectCommand(const QByteArray &command);
...@@ -121,8 +123,7 @@ private: ...@@ -121,8 +123,7 @@ private:
void updateLocals(); void updateLocals();
QByteArray m_inbuffer; QByteArray m_inbuffer;
QProcess m_pdbProc; QProcess m_proc;
QString m_pdb;
}; };
} // namespace Internal } // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment