From a8e8c5fe1d2a3fdee02ad4f05f43bcccfbc3f09d Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 28 Jan 2014 11:27:13 +0100 Subject: [PATCH] Debugger: Move Python setup closer to debugger startup It's unconditional nowadays, so we don't gain anything but code path complexity from defering it. Change-Id: Icc7d65835d1b2b76ecb64601822e0d70fd8f9f6e Reviewed-by: hjk --- src/plugins/debugger/gdb/attachgdbadapter.cpp | 1 - src/plugins/debugger/gdb/coregdbadapter.cpp | 2 - src/plugins/debugger/gdb/gdbengine.cpp | 56 +++++++------------ src/plugins/debugger/gdb/gdbengine.h | 4 -- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp index 1291689219c..210a00a738c 100644 --- a/src/plugins/debugger/gdb/attachgdbadapter.cpp +++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp @@ -92,7 +92,6 @@ void GdbAttachEngine::handleAttach(const GdbResponse &response) case GdbResultRunning: showMessage(_("INFERIOR ATTACHED")); showMessage(msgAttachedToStoppedInferior(), StatusBar); - tryLoadPythonDumpers(); handleInferiorPrepared(); break; case GdbResultError: diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index 1e2ba36a919..7d9140d98bc 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -200,8 +200,6 @@ void GdbCoreEngine::handleTargetCore(const GdbResponse &response) { QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state()); if (response.resultClass == GdbResultDone) { - // HACK: The namespace is not accessible in the initial run. - tryLoadPythonDumpers(); showMessage(tr("Attached to core."), StatusBar); handleInferiorPrepared(); // Due to the auto-solib-add off setting, we don't have any diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index c0bf8ac1725..f8ef1af82e7 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -1365,8 +1365,6 @@ void GdbEngine::handleStopResponse(const GdbMi &data) return; } - tryLoadPythonDumpers(); - bool gotoHandleStop1 = true; if (!m_fullStartDone) { m_fullStartDone = true; @@ -1723,9 +1721,7 @@ void GdbEngine::handleShowVersion(const GdbResponse &response) if (startParameters().multiProcess) postCommand("set detach-on-fork off", ConsoleCommand); - //postCommand("set build-id-verbose 2", ConsoleCommand); - postCommand("python print(sys.version)", ConsoleCommand, CB(handleHasPython)); } } @@ -1734,13 +1730,9 @@ void GdbEngine::handleListFeatures(const GdbResponse &response) showMessage(_("FEATURES: " + response.toString())); } -void GdbEngine::handleHasPython(const GdbResponse &response) -{ - Q_UNUSED(response); -} - void GdbEngine::handlePythonSetup(const GdbResponse &response) { + QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); if (response.resultClass == GdbResultDone) { const QString commands = debuggerCore()->stringSetting(GdbCustomDumperCommands); if (!commands.isEmpty()) { @@ -1765,6 +1757,13 @@ void GdbEngine::handlePythonSetup(const GdbResponse &response) } watchHandler()->addTypeFormats(type, formats); } + + loadInitScript(); + QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); + showMessage(_("ENGINE SUCCESSFULLY STARTED")); + notifyEngineSetupOk(); + } else { + notifyEngineSetupFailed(); } } @@ -4338,19 +4337,21 @@ void GdbEngine::startGdb(const QStringList &args) postCommand("set detach-on-fork off"); } - // Dummy command to guarantee a roundtrip before the adapter proceed. + // Finally, set up Python. + // We need to guarantee a roundtrip before the adapter proceeds. // Make sure this stays the last command in startGdb(). // Don't use ConsoleCommand, otherwise Mac won't markup the output. - postCommand("pwd", CB(reportEngineSetupOk)); -} + const QByteArray dumperSourcePath = + Core::ICore::resourcePath().toLocal8Bit() + "/debugger/"; -void GdbEngine::reportEngineSetupOk(const GdbResponse &response) -{ - loadInitScript(); - Q_UNUSED(response); - QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); - showMessage(_("ENGINE SUCCESSFULLY STARTED")); - notifyEngineSetupOk(); + const QFileInfo gdbBinaryFile(m_gdb); + const QByteArray uninstalledData = gdbBinaryFile.absolutePath().toLocal8Bit() + + "/data-directory/python"; + + const GdbCommandFlags flags = ConsoleCommand | Immediate; + postCommand("python sys.path.insert(1, '" + dumperSourcePath + "')", flags); + postCommand("python sys.path.append('" + uninstalledData + "')", flags); + postCommand("python from gdbbridge import *", flags, CB(handlePythonSetup)); } void GdbEngine::handleGdbStartFailed() @@ -4379,24 +4380,9 @@ void GdbEngine::loadInitScript() } } -void GdbEngine::tryLoadPythonDumpers() -{ - const QByteArray dumperSourcePath = - Core::ICore::resourcePath().toLocal8Bit() + "/debugger/"; - - const QFileInfo gdbBinaryFile(m_gdb); - const QByteArray uninstalledData = gdbBinaryFile.absolutePath().toLocal8Bit() - + "/data-directory/python"; - - const GdbCommandFlags flags = ConsoleCommand | Immediate; - postCommand("python sys.path.insert(1, '" + dumperSourcePath + "')", flags); - postCommand("python sys.path.append('" + uninstalledData + "')", flags); - postCommand("python from gdbbridge import *", flags, CB(handlePythonSetup)); -} - void GdbEngine::reloadDebuggingHelpers() { - tryLoadPythonDumpers(); + postCommand("bbsetup"); } void GdbEngine::handleGdbError(QProcess::ProcessError error) diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index c4f3a78fa1d..bc8c46a6dfb 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -94,14 +94,11 @@ private: ////////// General State ////////// protected: ////////// Gdb Process Management ////////// void startGdb(const QStringList &args = QStringList()); - void reportEngineSetupOk(const GdbResponse &response); - void handleCheckForPython(const GdbResponse &response); void handleInferiorShutdown(const GdbResponse &response); void handleGdbExit(const GdbResponse &response); void handleNamespaceExtraction(const GdbResponse &response); void loadInitScript(); - void tryLoadPythonDumpers(); // Something went wrong with the adapter *before* adapterStarted() was emitted. // Make sure to clean up everything before emitting this signal. @@ -251,7 +248,6 @@ protected: // Gdb initialization sequence void handleShowVersion(const GdbResponse &response); void handleListFeatures(const GdbResponse &response); - void handleHasPython(const GdbResponse &response); void handlePythonSetup(const GdbResponse &response); int m_gdbVersion; // 7.6.1 is 70601