From 885f8b34cf1e9e09c68ef7cbc7cd70f44fcb4339 Mon Sep 17 00:00:00 2001 From: hjk <qthjk@ovi.com> Date: Wed, 9 Jan 2013 14:51:49 +0100 Subject: [PATCH] Debugger: Move python initialization after first stop This enables access to object-specific plain gdb pretty printers which are not available before startup. Change-Id: Icc8cbec177825d4d1adb1957a618abb33cbbf319 Reviewed-by: hjk <qthjk@ovi.com> --- src/plugins/debugger/gdb/coregdbadapter.cpp | 2 +- src/plugins/debugger/gdb/gdbengine.cpp | 24 +++++++++++++++------ src/plugins/debugger/gdb/gdbengine.h | 4 +++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index 07d31f72b70..1586a65f963 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -185,7 +185,7 @@ 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. - loadPythonDumpers(); + 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 59741ba3051..265637d9c85 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -262,6 +262,7 @@ GdbEngine::GdbEngine(const DebuggerStartParameters &startParameters) m_terminalTrap = startParameters.useTerminal; m_fullStartDone = false; m_forceAsyncModel = false; + m_pythonAttemptedToLoad = false; invalidateSourcesList(); @@ -1433,11 +1434,12 @@ void GdbEngine::handleStopResponse(const GdbMi &data) return; } + tryLoadPythonDumpers(); + bool gotoHandleStop1 = true; if (!m_fullStartDone) { m_fullStartDone = true; postCommand("sharedlibrary .*"); - loadPythonDumpers(); postCommand("p 3", CB(handleStop1)); gotoHandleStop1 = false; } @@ -4842,16 +4844,19 @@ void GdbEngine::startGdb(const QStringList &args) } else { m_fullStartDone = true; postCommand("set auto-solib-add on", ConsoleCommand); - loadPythonDumpers(); } - // Dummy command to guarantee a roundtrip before the adapter proceed. - postCommand("pwd", ConsoleCommand, CB(reportEngineSetupOk)); - if (debuggerCore()->boolSetting(MultiInferior)) { //postCommand("set follow-exec-mode new"); postCommand("set detach-on-fork off"); } + + // Quick check whether we have python. + postCommand("python print 43", ConsoleCommand, CB(handleHasPython)); + + // Dummy command to guarantee a roundtrip before the adapter proceed. + // Make sure this stays the last command in startGdb(). + postCommand("pwd", ConsoleCommand, CB(reportEngineSetupOk)); } void GdbEngine::reportEngineSetupOk(const GdbResponse &response) @@ -4888,10 +4893,15 @@ void GdbEngine::loadInitScript() } } -void GdbEngine::loadPythonDumpers() +void GdbEngine::tryLoadPythonDumpers() { if (m_forceAsyncModel) return; + if (!m_hasPython) + return; + if (m_pythonAttemptedToLoad) + return; + m_pythonAttemptedToLoad = true; const QByteArray dumperSourcePath = Core::ICore::resourcePath().toLocal8Bit() + "/dumper/"; @@ -4909,7 +4919,7 @@ void GdbEngine::loadPythonDumpers() loadInitScript(); - postCommand("bbsetup", ConsoleCommand, CB(handleHasPython)); + postCommand("bbsetup", ConsoleCommand); } void GdbEngine::handleGdbError(QProcess::ProcessError error) diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index ee41888838d..d50755ad738 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -230,12 +230,13 @@ 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 loadPythonDumpers(); + void tryLoadPythonDumpers(); void pythonDumpersFailed(); // Something went wrong with the adapter *before* adapterStarted() was emitted. @@ -705,6 +706,7 @@ protected: // debug information. bool attemptQuickStart() const; bool m_fullStartDone; + bool m_pythonAttemptedToLoad; // Test bool m_forceAsyncModel; -- GitLab