diff --git a/src/plugins/debugger/cdb/cdbdebugengine.cpp b/src/plugins/debugger/cdb/cdbdebugengine.cpp index 391c5bc1aef3b006012932bf8a14c46a1dcdffeb..05c1aab53ba5ff8d578888529dac995d96670f90 100644 --- a/src/plugins/debugger/cdb/cdbdebugengine.cpp +++ b/src/plugins/debugger/cdb/cdbdebugengine.cpp @@ -1259,11 +1259,11 @@ void CdbDebugEngine::slotConsoleStubStarted() const qint64 appPid = m_d->m_consoleStubProc.applicationPID(); if (debugCDB) qDebug() << Q_FUNC_INFO << appPid; - // Attach to console process + // Attach to console process. QString errorMessage; if (startAttachDebugger(appPid, AttachExternal, &errorMessage)) { m_d->startWatchTimer(); - manager()->notifyInferiorPidChanged(appPid); + runControl()->notifyInferiorPid(appPid); } else { QMessageBox::critical(DebuggerUISwitcher::instance()->mainWindow(), tr("Debugger Error"), errorMessage); } diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 4188507f8dc96b80a3cf9f39a0b1355ebe2b04a3..c46f667c5f7778dc9cbeb69e7687d18b45003605 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -268,7 +268,6 @@ struct DebuggerManagerPrivate // FIXME: Remove engine-specific state DebuggerRunControl *m_runControl; - qint64 m_inferiorPid; /// Views DebuggerMainWindow *m_mainWindow; @@ -324,7 +323,6 @@ DebuggerManagerPrivate::DebuggerManagerPrivate(DebuggerManager *manager) : m_stopIcon(QLatin1String(":/debugger/images/debugger_stop_small.png")), m_interruptIcon(QLatin1String(":/debugger/images/debugger_interrupt_small.png")), m_locationMarkIcon(QLatin1String(":/debugger/images/location_16.png")), - m_inferiorPid(0), m_disassemblerViewAgent(manager), m_engine(0) { @@ -809,16 +807,6 @@ void DebuggerManager::notifyInferiorExited() showStatusMessage(tr("Exited"), 5000); } -void DebuggerManager::notifyInferiorPidChanged(qint64 pid) -{ - STATE_DEBUG(d->m_inferiorPid << pid); - - if (d->m_inferiorPid != pid) { - d->m_inferiorPid = pid; - emit inferiorPidChanged(pid); - } -} - void DebuggerManager::aboutToShutdown() { STATE_DEBUG(d->m_engine); @@ -985,7 +973,6 @@ void DebuggerManager::startNewDebugger(DebuggerRunControl *runControl) return; d->m_runControl = runControl; const DebuggerStartParameters *sp = &runControl->sp(); - d->m_inferiorPid = sp->attachPID > 0 ? sp->attachPID : 0; const QString toolChainName = ProjectExplorer::ToolChain::toolChainName( ProjectExplorer::ToolChain::ToolChainType(sp->toolChainType)); @@ -1095,11 +1082,6 @@ void DebuggerManager::abortDebugger() d->m_codeModelSnapshot = CPlusPlus::Snapshot(); } -qint64 DebuggerManager::inferiorPid() const -{ - return d->m_inferiorPid; -} - void DebuggerManager::assignValueInDebugger() { if (QAction *action = qobject_cast<QAction *>(sender())) { diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h index 509b0d35cc692c443d7058a2e01acc1495c974c6..5c1eec2faf29430766e452e48eaca747a8a60cce 100644 --- a/src/plugins/debugger/debuggermanager.h +++ b/src/plugins/debugger/debuggermanager.h @@ -152,7 +152,6 @@ public: Internal::IDebuggerEngine *currentEngine() const; DebuggerRunControl *runControl() const; - qint64 inferiorPid() const; QMessageBox *showMessageBox(int icon, const QString &title, const QString &text, int buttons = 0); @@ -273,7 +272,6 @@ private: void notifyInferiorStopped(); void notifyInferiorRunning(); void notifyInferiorExited(); - void notifyInferiorPidChanged(qint64); void cleanupViews(); @@ -296,7 +294,6 @@ private: signals: void debuggingFinished(); - void inferiorPidChanged(qint64 pid); void stateChanged(int newstatus); void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever' void applicationOutputAvailable(const QString &output, bool onStdErr); diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index f98a11adfada2849fa038dfd4e01b24c237272a0..40686d8c1bc9e85979e680f3b3f7deca6da314a8 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -56,6 +56,7 @@ #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QFileInfo> +#include <QtCore/QTimer> #include <QtGui/QAbstractItemView> #include <QtGui/QTextDocument> @@ -166,6 +167,7 @@ public: DebuggerManager *m_manager; Internal::IDebuggerEngine *m_engine; bool m_running; + qint64 m_inferiorPid; ModulesHandler *m_modulesHandler; RegisterHandler *m_registerHandler; @@ -188,6 +190,7 @@ DebuggerRunControl::Private::Private(DebuggerRunControl *parent, m_engine(0) { m_running = false; + m_inferiorPid = m_startParameters.attachPID > 0 ? m_startParameters.attachPID : 0; m_modulesHandler = new ModulesHandler(q); m_registerHandler = new RegisterHandler(); m_snapshotHandler = new SnapshotHandler(q); @@ -219,9 +222,6 @@ DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager, Qt::QueuedConnection); connect(d->m_manager, SIGNAL(messageAvailable(QString, bool)), this, SLOT(slotMessageAvailable(QString, bool))); - connect(d->m_manager, SIGNAL(inferiorPidChanged(qint64)), - this, SLOT(bringApplicationToForeground(qint64)), - Qt::QueuedConnection); connect(this, SIGNAL(stopRequested()), d->m_manager, SLOT(exitDebugger())); @@ -383,6 +383,24 @@ void DebuggerRunControl::startDebugger(IDebuggerEngine *engine) d->m_engine->startDebugger(); } +void DebuggerRunControl::notifyInferiorPid(qint64 pid) +{ + //STATE_DEBUG(d->m_inferiorPid << pid); + if (d->m_inferiorPid == pid) + return; + d->m_inferiorPid = pid; + QTimer::singleShot(0, this, SLOT(raiseApplication())); +} + +qint64 DebuggerRunControl::inferiorPid() const +{ + return d->m_inferiorPid; +} + +void DebuggerRunControl::raiseApplication() +{ + bringApplicationToForeground(d->m_inferiorPid); +} ////////////////////////////////////////////////////////////////////// // diff --git a/src/plugins/debugger/debuggerrunner.h b/src/plugins/debugger/debuggerrunner.h index be9019cf94dda16c13633f2af0d0d1784c4a41f8..cc5ab4485b5ab71c407f4c330ab767abfd05da89 100644 --- a/src/plugins/debugger/debuggerrunner.h +++ b/src/plugins/debugger/debuggerrunner.h @@ -150,6 +150,9 @@ public: void cleanup(); void startDebugger(Internal::IDebuggerEngine *engine); + void notifyInferiorPid(qint64 pid); + qint64 inferiorPid() const; + Internal::IDebuggerEngine *engine(); signals: @@ -160,6 +163,7 @@ public slots: private slots: void slotMessageAvailable(const QString &data, bool isError); + void raiseApplication(); private: void init(); diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 7bb1ed0582950114ccf8fe2c5c8fb05bc837e548..e301d96c31339f32450a94d57ca42f752f6ad6b5 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -444,13 +444,12 @@ void GdbEngine::handleResponse(const QByteArray &buff) // Archer had only "{id="28902"}" at some point of 6.8.x. // *-started seems to be standard in 7.1, but in early // 7.0.x, there was a *-created instead. - int progress = m_progress->progressValue(); + const int progress = m_progress->progressValue(); m_progress->setProgressValue(qMin(70, progress + 1)); QByteArray id = result.findChild("id").data(); showStatusMessage(tr("Thread group %1 created").arg(_(id)), 1000); - int pid = id.toInt(); - if (pid != inferiorPid()) - handleInferiorPidChanged(pid); + const int pid = id.toInt(); + runControl()->notifyInferiorPid(pid); } else if (asyncClass == "thread-created") { //"{id="1",group-id="28902"}" QByteArray id = result.findChild("id").data(); @@ -503,7 +502,7 @@ void GdbEngine::handleResponse(const QByteArray &buff) m_pendingConsoleStreamOutput += data; // Parse pid from noise. - if (!inferiorPid()) { + if (!runControl()->inferiorPid()) { // Linux/Mac gdb: [New [Tt]hread 0x545 (LWP 4554)] static QRegExp re1(_("New .hread 0x[0-9a-f]+ \\(LWP ([0-9]*)\\)")); // MinGW 6.8: [New thread 2437.0x435345] @@ -693,11 +692,11 @@ void GdbEngine::maybeHandleInferiorPidChanged(const QString &pid0) showMessage(_("Cannot parse PID from %1").arg(pid0)); return; } - if (pid == inferiorPid()) + if (pid == runControl()->inferiorPid()) return; showMessage(_("FOUND PID %1").arg(pid)); - handleInferiorPidChanged(pid); + runControl()->notifyInferiorPid(pid); } void GdbEngine::postCommand(const QByteArray &command, AdapterCallback callback, @@ -1276,7 +1275,7 @@ void GdbEngine::handleStopResponse(const GdbMi &data) // Gdb <= 6.8 reports a frame but no reason, 6.8.50+ reports everything. // The case of the user really setting a breakpoint at _start is simply // unsupported. - if (!inferiorPid()) // For programs without -pthread under gdb <= 6.8. + if (!runControl()->inferiorPid()) // For programs without -pthread under gdb <= 6.8. postCommand("info proc", CB(handleInfoProc)); continueInferiorInternal(); return; diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index dd3de05c26fe7044cff5d0b9065ef2b9dc855b75..d69ee0c9e0d346c71e9f8b1e20cc39bfc09f3a48 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -321,8 +321,6 @@ private: ////////// Inferior Management ////////// void handleExecuteNext(const GdbResponse &response); void handleExecuteReturn(const GdbResponse &response); - qint64 inferiorPid() const { return m_manager->inferiorPid(); } - void handleInferiorPidChanged(qint64 pid) { manager()->notifyInferiorPidChanged(pid); } void maybeHandleInferiorPidChanged(const QString &pid); void handleInfoProc(const GdbResponse &response); diff --git a/src/plugins/debugger/gdb/localplaingdbadapter.cpp b/src/plugins/debugger/gdb/localplaingdbadapter.cpp index 225a8c3b03c2c4906bdd3a2fb588dcebd21d0f4d..7677e1bfc6bb128d1c8b15aa2ffdcde81b6c3379 100644 --- a/src/plugins/debugger/gdb/localplaingdbadapter.cpp +++ b/src/plugins/debugger/gdb/localplaingdbadapter.cpp @@ -123,7 +123,7 @@ void LocalPlainGdbAdapter::checkForReleaseBuild() void LocalPlainGdbAdapter::interruptInferior() { - const qint64 attachedPID = m_engine->inferiorPid(); + const qint64 attachedPID = runControl()->inferiorPid(); if (attachedPID <= 0) { showMessage(_("TRYING TO INTERRUPT INFERIOR BEFORE PID WAS OBTAINED")); return; diff --git a/src/plugins/debugger/gdb/termgdbadapter.cpp b/src/plugins/debugger/gdb/termgdbadapter.cpp index 19b77cdec74ca63755cd92e0f48cb1dce2881668..09b4176c4cc1f2580a8dc97235e2eaa8bb15b3b6 100644 --- a/src/plugins/debugger/gdb/termgdbadapter.cpp +++ b/src/plugins/debugger/gdb/termgdbadapter.cpp @@ -120,7 +120,7 @@ void TermGdbAdapter::startInferior() { QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); const qint64 attachedPID = m_stubProc.applicationPID(); - m_engine->handleInferiorPidChanged(attachedPID); + runControl()->notifyInferiorPid(attachedPID); m_engine->postCommand("attach " + QByteArray::number(attachedPID), CB(handleStubAttached)); } @@ -159,7 +159,7 @@ void TermGdbAdapter::handleEntryPoint(const GdbResponse &response) void TermGdbAdapter::interruptInferior() { - const qint64 attachedPID = m_engine->inferiorPid(); + const qint64 attachedPID = runControl()->inferiorPid(); QTC_ASSERT(attachedPID > 0, return); if (!interruptProcess(attachedPID)) showMessage(_("CANNOT INTERRUPT %1").arg(attachedPID));