From ad6ee1cafb5f496be3caeff871a9547adf885c30 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 22 Sep 2009 12:10:12 +0200 Subject: [PATCH 1/8] debugger: clean up gdbengine --- src/plugins/debugger/gdb/gdbengine.cpp | 76 +++---------------- src/plugins/debugger/gdb/gdbengine.h | 9 +-- src/plugins/debugger/gdb/remotegdbadapter.cpp | 19 ++++- 3 files changed, 32 insertions(+), 72 deletions(-) diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 092bdbce09d..5dea4690965 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -1457,9 +1457,7 @@ void GdbEngine::shutdown() void GdbEngine::detachDebugger() { - postCommand(_("detach")); - // FIXME: use postCommand(_("detach"), CB(handleExitHelper)) ? - postCommand(_("-gdb-exit"), CB(handleExit)); + postCommand(_("detach"), CB(handleDetach)); } void GdbEngine::exitDebugger() @@ -1469,36 +1467,11 @@ void GdbEngine::exitDebugger() m_gdbAdapter->shutdown(); } -void GdbEngine::handleExitHelper(const GdbResultRecord &, const QVariant &) +void GdbEngine::handleDetach(const GdbResultRecord &, const QVariant &) { - exitDebugger2(); + exitDebugger(); } -void GdbEngine::exitDebugger2() -{ -/* - postCommand(_("-gdb-exit"), CB(handleExit)); - // 20s can easily happen when loading webkit debug information - if (!m_gdbAdapter->waitForFinished(20000)) { - debugMessage(_("FORCING TERMINATION: %1") - .arg(m_gdbAdapter->state())); - m_gdbAdapter->terminate(); - m_gdbAdapter->waitForFinished(20000); - } - - if (m_gdbAdapter->state() != QProcess::NotRunning) { - debugMessage(_("PROBLEM STOPPING DEBUGGER: STATE %1") - .arg(m_gdbAdapter->state())); - m_gdbAdapter->kill(); - } -*/ - - m_outputCollector.shutdown(); - initializeVariables(); - //m_manager->settings()->m_debugDebuggingHelpers = false; -} - - int GdbEngine::currentFrame() const { return qq->stackHandler()->currentIndex(); @@ -1506,20 +1479,15 @@ int GdbEngine::currentFrame() const void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) { - m_startParameters = sp; - m_gdbAdapter->startAdapter(sp); -/* - // This should be set by the constructor or in exitDebugger(). + // This should be set by the constructor or in exitDebugger() + // via initializeVariables() QTC_ASSERT(m_debuggingHelperState == DebuggingHelperUninitialized, initializeVariables()); - if (m_gdbAdapter->state() != QProcess::NotRunning) { - debugMessage(_("GDB IS ALREADY RUNNING, STATE: %1").arg(m_gdbAdapter->state())); - m_gdbAdapter->kill(); - emitStartFailed(); - return; - } + m_startParameters = sp; + m_gdbAdapter->startAdapter(sp); +/* QStringList gdbArgs; gdbArgs.prepend(_("mi")); gdbArgs.prepend(_("-i")); @@ -1527,19 +1495,6 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) if (startMode() == AttachCore || startMode() == AttachExternal || startMode() == AttachCrashedExternal) { // nothing to do - } else if (startMode() == StartRemote) { - // Start the remote server - if (m_startParameters->serverStartScript.isEmpty()) { - showStatusMessage(_("No server start script given. " - "Assuming server runs already.")); - } else { - if (!m_startParameters->workingDir.isEmpty()) - m_uploadProc.setWorkingDirectory(m_startParameters->workingDir); - if (!m_startParameters->environment.isEmpty()) - m_uploadProc.setEnvironment(m_startParameters->environment); - m_uploadProc.start(_("/bin/sh ") + m_startParameters->serverStartScript); - m_uploadProc.waitForStarted(); - } } else if (m_startParameters->useTerminal) { m_stubProc.stop(); // We leave the console open, so recycle it now. @@ -1566,19 +1521,6 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) if (!m_startParameters->environment.isEmpty()) m_gdbAdapter->setEnvironment(m_startParameters->environment); } - - #if 0 - qDebug() << "Command:" << m_manager->settings()->m_gdbCmd; - qDebug() << "WorkingDirectory:" << m_gdbAdapter->workingDirectory(); - qDebug() << "ScriptFile:" << m_manager->settings()->m_scriptFile; - qDebug() << "Environment:" << m_gdbAdapter->environment(); - qDebug() << "Arguments:" << gdbArgs; - qDebug() << "BuildDir:" << m_startParameters->buildDir; - qDebug() << "ExeFile:" << m_startParameters->executable; - #endif - - QString loc = theDebuggerStringSetting(GdbLocation); - showStatusMessage(tr("Starting Debugger: ") + loc + _c(' ') + gdbArgs.join(_(" "))); m_gdbAdapter->start(loc, gdbArgs); */ } @@ -1591,6 +1533,7 @@ void GdbEngine::continueInferior() postCommand(_("-exec-continue"), CB(handleExecContinue)); } +#if 0 void GdbEngine::handleAttach(const GdbResultRecord &, const QVariant &) { qq->notifyInferiorStopped(); @@ -1648,6 +1591,7 @@ void GdbEngine::handleTargetRemote(const GdbResultRecord &record, const QVariant postCommand(_("-gdb-exit"), CB(handleExit)); } } +#endif void GdbEngine::handleExit(const GdbResultRecord &, const QVariant &) { diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index 58c7d64a75a..e26fe58fd53 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -107,7 +107,6 @@ private: void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); void startDebugger(const DebuggerStartParametersPtr &sp); void exitDebugger(); - void exitDebugger2(); void detachDebugger(); void continueInferior(); @@ -248,7 +247,7 @@ private: int terminationIndex(const QByteArray &buffer, int &length); void handleResponse(const QByteArray &buff); void handleStart(const GdbResultRecord &response, const QVariant &); - void handleAttach(const GdbResultRecord &, const QVariant &); + //void handleAttach(const GdbResultRecord &, const QVariant &); void handleAqcuiredInferior(); void handleAsyncOutput(const GdbMi &data); void handleStop1(const GdbResultRecord &, const QVariant &cookie); @@ -268,9 +267,9 @@ private: void handleQuerySources(const GdbResultRecord &response, const QVariant &); void handleTargetCore(const GdbResultRecord &, const QVariant &); void handleExit(const GdbResultRecord &, const QVariant &); - void handleExitHelper(const GdbResultRecord &, const QVariant &); - void handleSetTargetAsync(const GdbResultRecord &, const QVariant &); - void handleTargetRemote(const GdbResultRecord &, const QVariant &); + void handleDetach(const GdbResultRecord &, const QVariant &); + //void handleSetTargetAsync(const GdbResultRecord &, const QVariant &); + //void handleTargetRemote(const GdbResultRecord &, const QVariant &); void handleWatchPoint(const GdbResultRecord &, const QVariant &); bool showToolTip(); diff --git a/src/plugins/debugger/gdb/remotegdbadapter.cpp b/src/plugins/debugger/gdb/remotegdbadapter.cpp index e84eaf9180b..85aaaa31822 100644 --- a/src/plugins/debugger/gdb/remotegdbadapter.cpp +++ b/src/plugins/debugger/gdb/remotegdbadapter.cpp @@ -101,7 +101,24 @@ void RemoteGdbAdapter::startAdapter(const DebuggerStartParametersPtr &sp) setEnvironment(m_startParameters->environment); QString location = theDebuggerStringSetting(GdbLocation); - //showStatusMessage(tr("Starting Debugger: ") + loc + _c(' ') + gdbArgs.join(_(" "))); + +/* + // FIXME: make asynchroneouis + // Start the remote server + if (m_startParameters->serverStartScript.isEmpty()) { + showStatusMessage(_("No server start script given. " + "Assuming server runs already.")); + } else { + if (!m_startParameters->workingDir.isEmpty()) + m_uploadProc.setWorkingDirectory(m_startParameters->workingDir); + if (!m_startParameters->environment.isEmpty()) + m_uploadProc.setEnvironment(m_startParameters->environment); + m_uploadProc.start(_("/bin/sh ") + m_startParameters->serverStartScript); + m_uploadProc.waitForStarted(); + } +*/ + + // Start the debugger m_gdbProc.start(location, gdbArgs); } From e8be2acdb8102e7bdfad1c5a563a532935a00478 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 22 Sep 2009 12:36:36 +0200 Subject: [PATCH 2/8] debugger: refactoring --- src/plugins/debugger/gdb/gdbengine.cpp | 2 -- src/plugins/debugger/gdb/trkgdbadapter.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 5dea4690965..6a2d5a285c0 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -4242,8 +4242,6 @@ IDebuggerEngine *createSymbianEngine(DebuggerManager *parent, GdbEngine *engine = new GdbEngine(parent); TrkGdbAdapter *adapter = new TrkGdbAdapter(engine, options); engine->setGdbAdapter(adapter); - QObject::connect(adapter, SIGNAL(output(QString)), - parent, SLOT(showDebuggerOutput(QString))); return engine; } diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp index acb296d50e5..e73600edf89 100644 --- a/src/plugins/debugger/gdb/trkgdbadapter.cpp +++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp @@ -275,8 +275,13 @@ void TrkGdbAdapter::startInferiorEarly() void TrkGdbAdapter::logMessage(const QString &msg) { - if (m_verbose) + if (m_verbose) { +#ifdef STANDALONE_RUNNER emit output(msg); +#else + m_engine->debugMessage(msg); +#endif + } } // From 89861828ee61d8fe9af293ba9861cc7113bd93fb Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 23 Sep 2009 09:54:21 +0200 Subject: [PATCH 3/8] debugger: merge gdb engine and symbian engine. The trk parts are an 'adapter' in the gdb engine. --- src/plugins/debugger/debuggermanager.cpp | 37 ++-- src/plugins/debugger/debuggermanager.h | 5 +- src/plugins/debugger/gdb/gdbengine.cpp | 217 +++++++++++++-------- src/plugins/debugger/gdb/gdbengine.h | 16 +- src/plugins/debugger/gdb/trkgdbadapter.cpp | 2 +- src/plugins/debugger/gdb/trkgdbadapter.h | 1 + src/plugins/debugger/idebuggerengine.h | 6 + 7 files changed, 180 insertions(+), 104 deletions(-) diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 7779050817c..8c5c75fdb2d 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -101,9 +101,8 @@ IDebuggerEngine *createTcfEngine(DebuggerManager *parent, QList *); +IDebuggerEngine *createGdbEngine(DebuggerManager *parent); -IDebuggerEngine *createSymbianEngine(DebuggerManager *parent, QList *); QDebug operator<<(QDebug str, const DebuggerStartParameters &p) { @@ -185,7 +184,6 @@ void DebuggerStartParameters::clear() static IDebuggerEngine *gdbEngine = 0; static IDebuggerEngine *scriptEngine = 0; -static IDebuggerEngine *symbianEngine = 0; static IDebuggerEngine *tcfEngine = 0; static IDebuggerEngine *winEngine = 0; @@ -201,7 +199,6 @@ DebuggerManager::~DebuggerManager() #define doDelete(ptr) delete ptr; ptr = 0 doDelete(gdbEngine); doDelete(scriptEngine); - doDelete(symbianEngine); doDelete(tcfEngine); doDelete(winEngine); #undef doDelete @@ -446,10 +443,10 @@ void DebuggerManager::init() QList DebuggerManager::initializeEngines(unsigned enabledTypeFlags) { QList rc; - if (enabledTypeFlags & GdbEngineType) - gdbEngine = createGdbEngine(this, &rc); - if (enabledTypeFlags & SymbianEngineType) - symbianEngine = createSymbianEngine(this, &rc); + if (enabledTypeFlags & GdbEngineType) { + gdbEngine = createGdbEngine(this); + gdbEngine->addOptionPages(&rc); + } winEngine = createWinEngine(this, (enabledTypeFlags & CdbEngineType), &rc); if (enabledTypeFlags & ScriptEngineType) scriptEngine = createScriptEngine(this, &rc); @@ -565,7 +562,7 @@ void DebuggerManager::notifyInferiorRunning() void DebuggerManager::notifyInferiorExited() { setStatus(DebuggerProcessNotReady); - showStatusMessage(tr("Stopped."), 5000); + showStatusMessage(tr("Exited."), 5000); } void DebuggerManager::notifyInferiorPidChanged(qint64 pid) @@ -744,13 +741,15 @@ static IDebuggerEngine *determineDebuggerEngine(const QString &executable, return scriptEngine; } +/* if (executable.endsWith(_(".sym"))) { - if (!symbianEngine) { - *errorMessage = msgEngineNotAvailable("Symbian Engine"); + if (!gdbEngine) { + *errorMessage = msgEngineNotAvailable("Gdb Engine"); return 0; } - return symbianEngine; + return gdbEngine; } +*/ if (IDebuggerEngine *tce = debuggerEngineForToolChain( static_cast(toolChainType))) @@ -1114,7 +1113,7 @@ void DebuggerManager::setStatus(int status) if (status == m_status) return; - if (0 && !isAllowedTransition(m_status, status)) { + if (1 && !isAllowedTransition(m_status, status)) { const QString msg = QString::fromLatin1("%1: UNEXPECTED TRANSITION: %2 -> %3") .arg(_(Q_FUNC_INFO), _(stateName(m_status)), _(stateName(status))); qWarning("%s", qPrintable(msg)); @@ -1155,7 +1154,8 @@ void DebuggerManager::setStatus(int status) m_runToFunctionAction->setEnabled(ready); m_jumpToLineAction->setEnabled(ready); m_nextAction->setEnabled(ready); - //showStatusMessage(QString("started: %1, running: %2").arg(started).arg(running)); + //showStatusMessage(QString("started: %1, running: %2") + // .arg(started).arg(running)); emit statusChanged(m_status); const bool notbusy = ready || status == DebuggerProcessNotReady; setBusyCursor(!notbusy); @@ -1467,6 +1467,15 @@ void DebuggerManager::setSessionValue(const QString &name, const QVariant &value emit setSessionValueRequested(name, value); } +void DebuggerManager::showMessageBox(int icon, + const QString &title, const QString &text) +{ + QMessageBox *mb = new QMessageBox(QMessageBox::Icon(icon), + title, text, QMessageBox::NoButton, mainWindow()); + mb->setAttribute(Qt::WA_DeleteOnClose); + mb->show(); +} + ////////////////////////////////////////////////////////////////////// // // Testing diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h index 5db5c605715..29052449c9e 100644 --- a/src/plugins/debugger/debuggermanager.h +++ b/src/plugins/debugger/debuggermanager.h @@ -43,6 +43,7 @@ class QAction; class QAbstractItemModel; class QDockWidget; class QLabel; +class QMessageBox; class QModelIndex; class QPoint; class QTimer; @@ -183,12 +184,10 @@ enum DebuggerEngineTypeFlags ScriptEngineType = 0x02, CdbEngineType = 0x04, TcfEngineType = 0x08, - SymbianEngineType = 0x10, AllEngineTypes = GdbEngineType | ScriptEngineType | CdbEngineType | TcfEngineType - | SymbianEngineType }; // The construct below is not nice but enforces a bit of order. The @@ -279,6 +278,8 @@ public: virtual DebuggerStartParametersPtr startParameters() const; virtual qint64 inferiorPid() const; + void showMessageBox(int icon, const QString &title, const QString &text); + public slots: void startNewDebugger(const DebuggerStartParametersPtr &sp); void exitDebugger(); diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 6a2d5a285c0..a57b8e0180b 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -35,6 +35,7 @@ #include "trkoptionspage.h" #include "plaingdbadapter.h" #include "trkgdbadapter.h" +#include "remotegdbadapter.h" #include "watchutils.h" #include "debuggeractions.h" @@ -173,6 +174,33 @@ GdbEngine::GdbEngine(DebuggerManager *parent) : qq(parent->engineInterface()) { m_gdbAdapter = 0; + QSharedPointer options(new TrkOptions); + options->fromSettings(Core::ICore::instance()->settings()); + m_plainAdapter = new PlainGdbAdapter(this); + m_trkAdapter = new TrkGdbAdapter(this, options); + m_remoteAdapter = 0; // FIXME + + // Output + connect(&m_outputCollector, SIGNAL(byteDelivery(QByteArray)), + this, SLOT(readDebugeeOutput(QByteArray))); + + connect(this, SIGNAL(gdbOutputAvailable(int,QString)), + m_manager, SLOT(showDebuggerOutput(int,QString)), + Qt::QueuedConnection); + connect(this, SIGNAL(gdbInputAvailable(int,QString)), + m_manager, SLOT(showDebuggerInput(int,QString)), + Qt::QueuedConnection); + connect(this, SIGNAL(applicationOutputAvailable(QString)), + m_manager, SLOT(showApplicationOutput(QString)), + Qt::QueuedConnection); + + // FIXME: These trigger even if the engine is not active + connect(theDebuggerAction(UseDebuggingHelpers), SIGNAL(valueChanged(QVariant)), + this, SLOT(setUseDebuggingHelpers(QVariant))); + connect(theDebuggerAction(DebugDebuggingHelpers), SIGNAL(valueChanged(QVariant)), + this, SLOT(setDebugDebuggingHelpers(QVariant))); + connect(theDebuggerAction(RecheckDebuggingHelpers), SIGNAL(triggered()), + this, SLOT(recheckDebuggingHelperAvailability())); } GdbEngine::~GdbEngine() @@ -180,19 +208,15 @@ GdbEngine::~GdbEngine() // prevent sending error messages afterwards if (m_gdbAdapter) { m_gdbAdapter->disconnect(this); - delete m_gdbAdapter; + //delete m_gdbAdapter; m_gdbAdapter = 0; } + delete m_plainAdapter; + delete m_trkAdapter; + delete m_remoteAdapter; } -void GdbEngine::setGdbAdapter(AbstractGdbAdapter *gdbAdapter) -{ - m_gdbAdapter = gdbAdapter; - initializeVariables(); - initializeConnections(); -} - -void GdbEngine::initializeConnections() +void GdbEngine::connectAdapter() { // Gdb Process interaction connect(m_gdbAdapter, SIGNAL(error(QProcess::ProcessError)), @@ -227,28 +251,44 @@ void GdbEngine::initializeConnections() connect(m_gdbAdapter, SIGNAL(adapterCrashed()), m_manager, SLOT(exitDebugger())); +} - // Output - connect(&m_outputCollector, SIGNAL(byteDelivery(QByteArray)), - this, SLOT(readDebugeeOutput(QByteArray))); - connect(this, SIGNAL(gdbOutputAvailable(int,QString)), - m_manager, SLOT(showDebuggerOutput(int,QString)), - Qt::QueuedConnection); - connect(this, SIGNAL(gdbInputAvailable(int,QString)), - m_manager, SLOT(showDebuggerInput(int,QString)), - Qt::QueuedConnection); - connect(this, SIGNAL(applicationOutputAvailable(QString)), - m_manager, SLOT(showApplicationOutput(QString)), - Qt::QueuedConnection); +void GdbEngine::disconnectAdapter() +{ + // Gdb Process interaction + disconnect(m_gdbAdapter, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(gdbProcError(QProcess::ProcessError))); + disconnect(m_gdbAdapter, SIGNAL(readyReadStandardOutput()), + this, SLOT(readGdbStandardOutput())); + disconnect(m_gdbAdapter, SIGNAL(readyReadStandardError()), + this, SLOT(readGdbStandardError())); - // FIXME: These trigger even if the engine is not active - connect(theDebuggerAction(UseDebuggingHelpers), SIGNAL(valueChanged(QVariant)), - this, SLOT(setUseDebuggingHelpers(QVariant))); - connect(theDebuggerAction(DebugDebuggingHelpers), SIGNAL(valueChanged(QVariant)), - this, SLOT(setDebugDebuggingHelpers(QVariant))); - connect(theDebuggerAction(RecheckDebuggingHelpers), SIGNAL(triggered()), - this, SLOT(recheckDebuggingHelperAvailability())); + disconnect(m_gdbAdapter, SIGNAL(adapterStarted()), + this, SLOT(handleAdapterStarted())); + disconnect(m_gdbAdapter, SIGNAL(adapterStartFailed(QString)), + this, SLOT(handleAdapterStartFailed(QString))); + disconnect(m_gdbAdapter, SIGNAL(adapterShutDown()), + this, SLOT(handleAdapterShutDown())); + disconnect(m_gdbAdapter, SIGNAL(adapterShutdownFailed(QString)), + this, SLOT(handleAdapterShutdownFailed(QString))); + + disconnect(m_gdbAdapter, SIGNAL(inferiorPrepared()), + this, SLOT(handleInferiorPrepared())); + disconnect(m_gdbAdapter, SIGNAL(inferiorPreparationFailed(QString)), + this, SLOT(handleInferiorPreparationFailed(QString))); + + disconnect(m_gdbAdapter, SIGNAL(inferiorStarted()), + this, SLOT(handleInferiorStarted())); + disconnect(m_gdbAdapter, SIGNAL(inferiorStartFailed(QString)), + this, SLOT(handleInferiorStartFailed(QString))); + disconnect(m_gdbAdapter, SIGNAL(inferiorShutDown()), + this, SLOT(handleInferiorShutDown())); + disconnect(m_gdbAdapter, SIGNAL(inferiorShutdownFailed(QString)), + this, SLOT(handleInferiorShutdownFailed(QString))); + + disconnect(m_gdbAdapter, SIGNAL(adapterCrashed()), + m_manager, SLOT(exitDebugger())); } void GdbEngine::initializeVariables() @@ -292,13 +332,13 @@ void GdbEngine::gdbProcError(QProcess::ProcessError error) bool kill = true; switch (error) { case QProcess::FailedToStart: - kill = false; + //kill = false; msg = tr("The Gdb process failed to start. Either the " "invoked program '%1' is missing, or you may have insufficient " "permissions to invoke the program.") .arg(theDebuggerStringSetting(GdbLocation)); - emit startFailed(); - shutdown(); + //emit startFailed(); + //shutdown(); break; case QProcess::Crashed: kill = false; @@ -325,9 +365,9 @@ void GdbEngine::gdbProcError(QProcess::ProcessError error) } showStatusMessage(msg); - QMessageBox::critical(mainWindow(), tr("Error"), msg); + showMessageBox(QMessageBox::Critical, tr("Error"), msg); // act as if it was closed by the core - if (kill) + //if (kill) m_manager->exitDebugger(); } @@ -756,8 +796,8 @@ void GdbEngine::handleResultRecord(const GdbResultRecord &record) // msg="Cannot find new threads: generic error" if (record.resultClass == GdbResultError) { QByteArray msg = record.data.findChild("msg").data(); - QMessageBox::critical(mainWindow(), tr("Error"), - tr("Executable failed:\n") + QString::fromLocal8Bit(msg)); + showMessageBox(QMessageBox::Critical, + tr("Executable failed"), QString::fromLocal8Bit(msg)); showStatusMessage(tr("Process failed to start.")); exitDebugger(); //qq->notifyInferiorStopped(); @@ -775,7 +815,7 @@ void GdbEngine::handleResultRecord(const GdbResultRecord &record) if (record.token < m_oldestAcceptableToken && (cmd.flags & Discardable)) { //qDebug() << "### SKIPPING OLD RESULT" << record.toString(); - //QMessageBox::information(mainWindow(), tr("Skipped"), "xxx"); + //showMessageBox(QMessageBox::Information(tr("Skipped"), "xxx")); return; } @@ -1253,11 +1293,8 @@ void GdbEngine::handleStop1(const GdbResultRecord &, const QVariant &cookie) "Signal meaning : %2") .arg(name.isEmpty() ? tr(" ") : _(name)) .arg(meaning.isEmpty() ? tr(" ") : _(meaning)); - QMessageBox *mb = new QMessageBox(QMessageBox::Information, - tr("Signal received"), msg, QMessageBox::NoButton, - mainWindow()); - mb->setAttribute(Qt::WA_DeleteOnClose); - mb->show(); + showMessageBox(QMessageBox::Information, + tr("Signal received"), msg); } } @@ -1344,7 +1381,7 @@ void GdbEngine::handleShowVersion(const GdbResultRecord &response, const QVarian err->setMinimumSize(400, 300); err->showMessage(msg); #else - //QMessageBox::information(mainWindow(), tr("Warning"), msg); + //showMessageBox(QMessageBox::Information, tr("Warning"), msg); #endif } else { m_gdbVersion = 10000 * supported.cap(2).toInt() @@ -1364,8 +1401,7 @@ void GdbEngine::handleFileExecAndSymbols(const GdbResultRecord &response, const //m_breakHandler->clearBreakMarkers(); } else if (response.resultClass == GdbResultError) { QString msg = __(response.data.findChild("msg").data()); - QMessageBox::critical(mainWindow(), tr("Error"), - tr("Starting executable failed:\n") + msg); + showMessageBox(QMessageBox::Critical, tr("Starting executable failed"), msg); QTC_ASSERT(status() == DebuggerInferiorRunning, /**/); //interruptInferior(); qq->notifyInferiorExited(); @@ -1380,8 +1416,8 @@ void GdbEngine::handleExecRun(const GdbResultRecord &response, const QVariant &) } else { QTC_ASSERT(response.resultClass == GdbResultError, /**/); const QByteArray &msg = response.data.findChild("msg").data(); - QMessageBox::critical(mainWindow(), tr("Error"), - tr("Starting executable failed:\n") + QString::fromLocal8Bit(msg)); + showMessageBox(QMessageBox::Critical, tr("Starting executable failed", + QString::fromLocal8Bit(msg))); QTC_ASSERT(status() == DebuggerInferiorRunning, /**/); //interruptInferior(); qq->notifyInferiorExited(); @@ -1402,8 +1438,8 @@ void GdbEngine::handleExecContinue(const GdbResultRecord &response, const QVaria // "Leaving function...")); //stepOutExec(); } else { - QMessageBox::critical(mainWindow(), tr("Error"), - tr("Starting executable failed:\n") + QString::fromLocal8Bit(msg)); + showMessageBox(QMessageBox::Critical, tr("Starting executable failed"), + QString::fromLocal8Bit(msg)); QTC_ASSERT(status() == DebuggerInferiorRunning, /**/); //interruptInferior(); qq->notifyInferiorExited(); @@ -1481,10 +1517,23 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) { // This should be set by the constructor or in exitDebugger() // via initializeVariables() - QTC_ASSERT(m_debuggingHelperState == DebuggingHelperUninitialized, - initializeVariables()); + //QTC_ASSERT(m_debuggingHelperState == DebuggingHelperUninitialized, + // initializeVariables()); + //QTC_ASSERT(m_gdbAdapter == 0, delete m_gdbAdapter; m_gdbAdapter = 0); + + if (m_gdbAdapter) + disconnectAdapter(); + + if (sp->executable.endsWith(_(".sym"))) + m_gdbAdapter = m_trkAdapter; + else + m_gdbAdapter = m_plainAdapter; + + initializeVariables(); + connectAdapter(); m_startParameters = sp; + m_gdbAdapter->startAdapter(sp); /* @@ -1508,7 +1557,7 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) } } else { if (!m_outputCollector.listen()) { - QMessageBox::critical(mainWindow(), tr("Debugger Startup Failure"), + showMessageBox(QMessageBox::Critical, tr("Debugger Startup Failure"), tr("Cannot set up communication with child process: %1") .arg(m_outputCollector.errorString())); emitStartFailed(); @@ -1587,7 +1636,7 @@ void GdbEngine::handleTargetRemote(const GdbResultRecord &record, const QVariant QString msg = __(record.data.findChild("msg").data()); QString msg1 = tr("Connecting to remote server failed:"); showStatusMessage(msg1 + _c(' ') + msg); - QMessageBox::critical(mainWindow(), tr("Error"), msg1 + _c('\n') + msg); + showMessageBox(QMessageBox::Critical, tr("Error"), msg1 + _c('\n') + msg); postCommand(_("-gdb-exit"), CB(handleExit)); } } @@ -4025,10 +4074,9 @@ void GdbEngine::gotoLocation(const StackFrame &frame, bool setMarker) void GdbEngine::handleAdapterStartFailed(const QString &msg) { debugMessage(_("ADAPTER START FAILED")); - m_outputCollector.shutdown(); - QMessageBox::critical(mainWindow(), tr("Error"), msg); - QTC_ASSERT(status() == DebuggerInferiorRunning, /**/); - //interruptInferior(); + showMessageBox(QMessageBox::Critical, tr("Adapter start failed"), msg); + qq->notifyInferiorExited(); + m_manager->exitDebugger(); } void GdbEngine::handleAdapterStarted() @@ -4040,9 +4088,11 @@ void GdbEngine::handleAdapterStarted() void GdbEngine::handleInferiorPreparationFailed(const QString &msg) { debugMessage(_("INFERIOR PREPARATION FAILD")); - m_outputCollector.shutdown(); - QMessageBox::critical(mainWindow(), tr("Error"), - tr("Inferior start preparation failed:\n") + msg); + showMessageBox(QMessageBox::Critical, + tr("Inferior start preparation failed"), msg); + shutdown(); + qq->notifyInferiorExited(); + m_manager->exitDebugger(); } void GdbEngine::handleInferiorPrepared() @@ -4119,7 +4169,7 @@ void GdbEngine::handleInferiorPrepared() if (QFileInfo(scriptFileName).isReadable()) { postCommand(_("source ") + scriptFileName); } else { - QMessageBox::warning(mainWindow(), + showMessageBox(QMessageBox::Warning, tr("Cannot find debugger initialization script"), tr("The debugger settings point to a script file at '%1' " "which is not accessible. If a script file is not needed, " @@ -4182,9 +4232,10 @@ void GdbEngine::handleInitialBreakpointsSet() void GdbEngine::handleInferiorStartFailed(const QString &msg) { debugMessage(_("INFERIOR START FAILED")); - QMessageBox::critical(mainWindow(), tr("Error"), + showMessageBox(QMessageBox::Critical, tr("Error"), tr("Inferior start failed:\n") + msg); qq->notifyInferiorExited(); + m_manager->exitDebugger(); } void GdbEngine::handleInferiorStarted() @@ -4195,54 +4246,50 @@ void GdbEngine::handleInferiorStarted() void GdbEngine::handleInferiorShutDown() { debugMessage(_("INFERIOR SUCCESSFULLY SHUT DOWN")); - qq->notifyInferiorExited(); } void GdbEngine::handleInferiorShutdownFailed(const QString &msg) { debugMessage(_("INFERIOR SHUTDOWN FAILED")); - QMessageBox::critical(mainWindow(), tr("Error"), + showMessageBox(QMessageBox::Critical, tr("Error"), tr("Inferior shutdown failed:\n") + msg); + qq->notifyInferiorExited(); + m_manager->exitDebugger(); } void GdbEngine::handleAdapterShutDown() { debugMessage(_("ADAPTER SUCCESSFULLY SHUT DOWN")); + qq->notifyInferiorExited(); } void GdbEngine::handleAdapterShutdownFailed(const QString &msg) { debugMessage(_("ADAPTER SHUTDOWN FAILED")); - QMessageBox::critical(mainWindow(), tr("Error"), + showMessageBox(QMessageBox::Critical, tr("Error"), tr("Inferior shutdown failed:\n") + msg); + qq->notifyInferiorExited(); +} + +void GdbEngine::addOptionPages(QList *opts) const +{ + opts->push_back(new GdbOptionsPage); + if (!qgetenv("QTCREATOR_WITH_S60").isEmpty()) + opts->push_back(new TrkOptionsPage(m_trkAdapter->options())); +} + +void GdbEngine::showMessageBox(int icon, const QString &title, const QString &text) +{ + m_manager->showMessageBox(icon, title, text); } // // Factory // -IDebuggerEngine *createGdbEngine(DebuggerManager *parent, - QList *opts) +IDebuggerEngine *createGdbEngine(DebuggerManager *parent) { - opts->push_back(new GdbOptionsPage); - GdbEngine *engine = new GdbEngine(parent); - PlainGdbAdapter *adapter = new PlainGdbAdapter(engine); - engine->setGdbAdapter(adapter); - return engine; -} - -IDebuggerEngine *createSymbianEngine(DebuggerManager *parent, - QList *opts) -{ - QSharedPointer options(new TrkOptions); - options->fromSettings(Core::ICore::instance()->settings()); - - if (!qgetenv("QTCREATOR_WITH_S60").isEmpty()) - opts->push_back(new TrkOptionsPage(options)); - GdbEngine *engine = new GdbEngine(parent); - TrkGdbAdapter *adapter = new TrkGdbAdapter(engine, options); - engine->setGdbAdapter(adapter); - return engine; + return new GdbEngine(parent); } } // namespace Internal diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index e26fe58fd53..31959895e07 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -65,6 +65,10 @@ class GdbMi; class WatchData; class BreakpointData; +class PlainGdbAdapter; +class TrkGdbAdapter; +class RemoteGdbAdapter; + enum DebuggingHelperState { DebuggingHelperUninitialized, @@ -80,7 +84,6 @@ class GdbEngine : public IDebuggerEngine public: explicit GdbEngine(DebuggerManager *parent); ~GdbEngine(); - void setGdbAdapter(AbstractGdbAdapter *adapter); signals: void gdbInputAvailable(int channel, const QString &msg); @@ -155,7 +158,8 @@ private: bool supportsThreads() const; void gotoLocation(const StackFrame &frame, bool setLocationMarker); - void initializeConnections(); + void connectAdapter(); + void disconnectAdapter(); void initializeVariables(); QString fullName(const QString &fileName); // get one usable name out of these, try full names first @@ -439,8 +443,16 @@ private: DebuggerStartParametersPtr m_startParameters; // make sure to re-initialize new members in initializeVariables(); + // only one of those is active at a given time + PlainGdbAdapter *m_plainAdapter; + TrkGdbAdapter *m_trkAdapter; + RemoteGdbAdapter *m_remoteAdapter; + public: + void showMessageBox(int icon, const QString &title, const QString &text); void debugMessage(const QString &msg); + void addOptionPages(QList *opts) const; + OutputCollector m_outputCollector; }; diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp index e73600edf89..0b673abdb85 100644 --- a/src/plugins/debugger/gdb/trkgdbadapter.cpp +++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp @@ -240,7 +240,7 @@ void TrkGdbAdapter::startInferiorEarly() if (!m_trkDevice.open(device, &errorMessage)) { logMessage(QString::fromLatin1("Waiting on %1 (%2)").arg(device, errorMessage)); // Do not loop forever - if (m_waitCount++ < (m_options->mode == TrkOptions::BlueTooth ? 60 : 5)) { + if (m_waitCount++ < (m_options->mode == TrkOptions::BlueTooth ? 3 : 5)) { QTimer::singleShot(1000, this, SLOT(startInferiorEarly())); } else { QString msg = QString::fromLatin1("Failed to connect to %1 after " diff --git a/src/plugins/debugger/gdb/trkgdbadapter.h b/src/plugins/debugger/gdb/trkgdbadapter.h index 55896eb1d08..6359a428478 100644 --- a/src/plugins/debugger/gdb/trkgdbadapter.h +++ b/src/plugins/debugger/gdb/trkgdbadapter.h @@ -85,6 +85,7 @@ public: // Set a device (from the project) to override the settings. QString overrideTrkDevice() const; void setOverrideTrkDevice(const QString &); + const TrkOptionsPtr options() const { return m_options; } signals: void output(const QString &msg); diff --git a/src/plugins/debugger/idebuggerengine.h b/src/plugins/debugger/idebuggerengine.h index de2e7c5facc..6724d009351 100644 --- a/src/plugins/debugger/idebuggerengine.h +++ b/src/plugins/debugger/idebuggerengine.h @@ -43,6 +43,10 @@ namespace TextEditor { class ITextEditor; } +namespace Core { +class IOptionsPage; +} + namespace Debugger { namespace Internal { @@ -105,6 +109,8 @@ public: virtual void setRegisterValue(int regnr, const QString &value) { Q_UNUSED(regnr); Q_UNUSED(value); } + virtual void addOptionPages(QList *) const {} + signals: void startSuccessful(); void startFailed(); From d25066f8ad7d88505515d45bff9a9c1fe1564bee Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 23 Sep 2009 10:14:53 +0200 Subject: [PATCH 4/8] debugger: let the gdb adapters access the engines start parameter instead of keeping a copy --- src/plugins/debugger/gdb/abstractgdbadapter.h | 5 +++- src/plugins/debugger/gdb/gdbengine.cpp | 6 ++--- src/plugins/debugger/gdb/gdbengine.h | 4 +-- src/plugins/debugger/gdb/plaingdbadapter.cpp | 25 +++++++++---------- src/plugins/debugger/gdb/plaingdbadapter.h | 3 +-- src/plugins/debugger/gdb/trkgdbadapter.cpp | 3 +-- src/plugins/debugger/gdb/trkgdbadapter.h | 6 ++--- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/plugins/debugger/gdb/abstractgdbadapter.h b/src/plugins/debugger/gdb/abstractgdbadapter.h index ba32496c0db..5f055ddfcf3 100644 --- a/src/plugins/debugger/gdb/abstractgdbadapter.h +++ b/src/plugins/debugger/gdb/abstractgdbadapter.h @@ -81,12 +81,15 @@ public: virtual void setEnvironment(const QStringList &env) = 0; virtual bool isTrkAdapter() const = 0; - virtual void startAdapter(const DebuggerStartParametersPtr &sp) = 0; + virtual void startAdapter() = 0; virtual void prepareInferior() = 0; virtual void startInferior() = 0; virtual void interruptInferior() = 0; virtual void shutdown() = 0; + virtual const DebuggerStartParameters &startParameters() const + { return m_engine->startParameters(); } + signals: void adapterStarted(); void adapterStartFailed(const QString &msg); diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index a57b8e0180b..7f88fb9e036 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -1521,6 +1521,8 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) // initializeVariables()); //QTC_ASSERT(m_gdbAdapter == 0, delete m_gdbAdapter; m_gdbAdapter = 0); + m_startParameters = sp; + if (m_gdbAdapter) disconnectAdapter(); @@ -1532,9 +1534,7 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) initializeVariables(); connectAdapter(); - m_startParameters = sp; - - m_gdbAdapter->startAdapter(sp); + m_gdbAdapter->startAdapter(); /* QStringList gdbArgs; diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index 31959895e07..bc25ffbf3e8 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -95,8 +95,6 @@ private: friend class TrkGdbAdapter; friend class RemoteGdbAdapter; - const DebuggerStartParameters &startParameters() const - { return *m_startParameters; } // // IDebuggerEngine implementation // @@ -452,6 +450,8 @@ public: void showMessageBox(int icon, const QString &title, const QString &text); void debugMessage(const QString &msg); void addOptionPages(QList *opts) const; + const DebuggerStartParameters &startParameters() const + { return *m_startParameters; } OutputCollector m_outputCollector; }; diff --git a/src/plugins/debugger/gdb/plaingdbadapter.cpp b/src/plugins/debugger/gdb/plaingdbadapter.cpp index f29def0afdf..68630fff7a7 100644 --- a/src/plugins/debugger/gdb/plaingdbadapter.cpp +++ b/src/plugins/debugger/gdb/plaingdbadapter.cpp @@ -83,24 +83,23 @@ PlainGdbAdapter::PlainGdbAdapter(GdbEngine *engine, QObject *parent) // m_manager, SLOT(exitDebugger())); } -void PlainGdbAdapter::startAdapter(const DebuggerStartParametersPtr &sp) +void PlainGdbAdapter::startAdapter() { QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state()); setState(AdapterStarting); debugMessage(_("TRYING TO START ADAPTER")); - m_startParameters = sp; QStringList gdbArgs; gdbArgs.prepend(_("mi")); gdbArgs.prepend(_("-i")); - if (m_startParameters->useTerminal) { + if (startParameters().useTerminal) { m_stubProc.stop(); // We leave the console open, so recycle it now. - m_stubProc.setWorkingDirectory(m_startParameters->workingDir); - m_stubProc.setEnvironment(m_startParameters->environment); - if (!m_stubProc.start(m_startParameters->executable, - m_startParameters->processArgs)) { + m_stubProc.setWorkingDirectory(startParameters().workingDir); + m_stubProc.setEnvironment(startParameters().environment); + if (!m_stubProc.start(startParameters().executable, + startParameters().processArgs)) { // Error message for user is delivered via a signal. emitAdapterStartFailed(QString()); return; @@ -113,10 +112,10 @@ void PlainGdbAdapter::startAdapter(const DebuggerStartParametersPtr &sp) } gdbArgs.prepend(_("--tty=") + m_engine->m_outputCollector.serverName()); - if (!m_startParameters->workingDir.isEmpty()) - setWorkingDirectory(m_startParameters->workingDir); - if (!m_startParameters->environment.isEmpty()) - setEnvironment(m_startParameters->environment); + if (!startParameters().workingDir.isEmpty()) + setWorkingDirectory(startParameters().workingDir); + if (!startParameters().environment.isEmpty()) + setEnvironment(startParameters().environment); } QString location = theDebuggerStringSetting(GdbLocation); @@ -135,9 +134,9 @@ void PlainGdbAdapter::prepareInferior() { QTC_ASSERT(state() == AdapterStarted, qDebug() << state()); setState(InferiorPreparing); - if (!m_startParameters->processArgs.isEmpty()) + if (!startParameters().processArgs.isEmpty()) m_engine->postCommand(_("-exec-arguments ") - + m_startParameters->processArgs.join(_(" "))); + + startParameters().processArgs.join(_(" "))); QFileInfo fi(m_engine->startParameters().executable); m_engine->postCommand(_("-file-exec-and-symbols \"%1\"").arg(fi.absoluteFilePath()), CB(handleFileExecAndSymbols)); diff --git a/src/plugins/debugger/gdb/plaingdbadapter.h b/src/plugins/debugger/gdb/plaingdbadapter.h index 78fd23a70a1..f10d822da7f 100644 --- a/src/plugins/debugger/gdb/plaingdbadapter.h +++ b/src/plugins/debugger/gdb/plaingdbadapter.h @@ -61,7 +61,7 @@ public: void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); } bool isTrkAdapter() const { return false; } - void startAdapter(const DebuggerStartParametersPtr &sp); + void startAdapter(); void prepareInferior(); void startInferior(); void interruptInferior(); @@ -83,7 +83,6 @@ private: Q_SLOT void stubError(const QString &msg); QProcess m_gdbProc; - DebuggerStartParametersPtr m_startParameters; Core::Utils::ConsoleProcess m_stubProc; }; diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp index 0b673abdb85..05980ba90e5 100644 --- a/src/plugins/debugger/gdb/trkgdbadapter.cpp +++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp @@ -1344,12 +1344,11 @@ void TrkGdbAdapter::handleGdbStateChanged(QProcess::ProcessState newState) logMessage(_("GDB: Process State %1").arg(newState)); } -void TrkGdbAdapter::startAdapter(const DebuggerStartParametersPtr &sp) +void TrkGdbAdapter::startAdapter() { QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state()); setState(AdapterStarting); debugMessage(_("TRYING TO START ADAPTER")); - m_startParameters = sp; logMessage(QLatin1String("### Starting TrkGdbAdapter")); if (m_options->mode == TrkOptions::BlueTooth) { const QString device = effectiveTrkDevice(); diff --git a/src/plugins/debugger/gdb/trkgdbadapter.h b/src/plugins/debugger/gdb/trkgdbadapter.h index 6359a428478..7c6ecda322a 100644 --- a/src/plugins/debugger/gdb/trkgdbadapter.h +++ b/src/plugins/debugger/gdb/trkgdbadapter.h @@ -32,6 +32,7 @@ #include "trkutils.h" #include "trkdevice.h" +#include "trkoptions.h" #include "abstractgdbadapter.h" #include @@ -48,8 +49,6 @@ namespace Debugger { namespace Internal { -struct TrkOptions; - struct GdbResult { QByteArray data; @@ -101,7 +100,6 @@ private: QProcess m_gdbProc; QProcess m_rfcommProc; bool m_running; - DebuggerStartParametersPtr m_startParameters; void debugMessage(const QString &msg) { m_engine->debugMessage(msg); } public: @@ -117,7 +115,7 @@ public: void setEnvironment(const QStringList &env); bool isTrkAdapter() const { return true; } - void startAdapter(const DebuggerStartParametersPtr &sp); + void startAdapter(); void prepareInferior(); void startInferior(); void interruptInferior(); From 3215da914e67ed6fa9991c45c9416f7d774caabe Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 23 Sep 2009 12:04:25 +0200 Subject: [PATCH 5/8] Gdb: Parse out MinGW gdb process id correctly, connect dumper acts. --- src/plugins/debugger/gdb/gdbengine.cpp | 45 +++++++++++++++++++------- src/plugins/debugger/gdb/gdbengine.h | 3 +- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 7f88fb9e036..6483c2efd3f 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -193,14 +193,28 @@ GdbEngine::GdbEngine(DebuggerManager *parent) : connect(this, SIGNAL(applicationOutputAvailable(QString)), m_manager, SLOT(showApplicationOutput(QString)), Qt::QueuedConnection); +} - // FIXME: These trigger even if the engine is not active - connect(theDebuggerAction(UseDebuggingHelpers), SIGNAL(valueChanged(QVariant)), - this, SLOT(setUseDebuggingHelpers(QVariant))); - connect(theDebuggerAction(DebugDebuggingHelpers), SIGNAL(valueChanged(QVariant)), - this, SLOT(setDebugDebuggingHelpers(QVariant))); - connect(theDebuggerAction(RecheckDebuggingHelpers), SIGNAL(triggered()), - this, SLOT(recheckDebuggingHelperAvailability())); +void GdbEngine::connectDebuggingHelperActions(bool on) +{ + if (on) { + connect(theDebuggerAction(UseDebuggingHelpers), SIGNAL(valueChanged(QVariant)), + this, SLOT(setUseDebuggingHelpers(QVariant))); + connect(theDebuggerAction(DebugDebuggingHelpers), SIGNAL(valueChanged(QVariant)), + this, SLOT(setDebugDebuggingHelpers(QVariant))); + connect(theDebuggerAction(RecheckDebuggingHelpers), SIGNAL(triggered()), + this, SLOT(recheckDebuggingHelperAvailability())); + } else { + disconnect(theDebuggerAction(UseDebuggingHelpers), 0, this, 0); + disconnect(theDebuggerAction(DebugDebuggingHelpers), 0, this, 0); + disconnect(theDebuggerAction(RecheckDebuggingHelpers), 0, this, 0); + } +} + +DebuggerStartMode GdbEngine::startMode() const +{ + QTC_ASSERT(!m_startParameters.isNull(), return NoStartMode); + return m_startParameters->startMode; } GdbEngine::~GdbEngine() @@ -529,11 +543,18 @@ void GdbEngine::handleResponse(const QByteArray &buff) } case '~': { + // Linux/Mac gdb: [New [Tt]hread 0x545 (LWP 4554)] + // MinGW gdb 6.8: [New thread 2728.0x1034] static QRegExp re(_("New .hread 0x[0-9a-f]* \\(LWP ([0-9]*)\\)")); + static QRegExp re2(_("New .hread ([0-9]+)\\.0x[0-9a-f]+")); + QTC_ASSERT(re.isValid() && re2.isValid(), return); QByteArray data = GdbMi::parseCString(from, to); m_pendingConsoleStreamOutput += data; - if (re.indexIn(_(data)) != -1) + if (re.indexIn(_(data)) != -1) { maybeHandleInferiorPidChanged(re.cap(1)); + } else if (re2.indexIn(_(data)) != -1) { + maybeHandleInferiorPidChanged(re2.cap(1)); + } if (data.startsWith("Reading symbols from ")) showStatusMessage(tr("Reading %1...").arg(_(data.mid(21)))); break; @@ -1498,6 +1519,7 @@ void GdbEngine::detachDebugger() void GdbEngine::exitDebugger() { + connectDebuggingHelperActions(false); m_outputCollector.shutdown(); initializeVariables(); m_gdbAdapter->shutdown(); @@ -1522,6 +1544,8 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp) //QTC_ASSERT(m_gdbAdapter == 0, delete m_gdbAdapter; m_gdbAdapter = 0); m_startParameters = sp; + if (startModeAllowsDumpers()) + connectDebuggingHelperActions(true); if (m_gdbAdapter) disconnectAdapter(); @@ -3838,9 +3862,8 @@ void GdbEngine::recheckDebuggingHelperAvailability() bool GdbEngine::startModeAllowsDumpers() const { - return startMode() == StartInternal - || startMode() == StartExternal - || startMode() == AttachExternal; + const DebuggerStartMode m = startMode(); + return m == StartInternal || m == StartExternal || m == AttachExternal; } void GdbEngine::watchPoint(const QPoint &pnt) diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index bc25ffbf3e8..a71cede808c 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -281,7 +281,7 @@ private: { m_manager->showStatusMessage(msg, timeout); } int status() const { return m_manager->status(); } QMainWindow *mainWindow() const { return m_manager->mainWindow(); } - DebuggerStartMode startMode() const { return m_startParameters->startMode; } + DebuggerStartMode startMode() const; qint64 inferiorPid() const { return m_manager->inferiorPid(); } void handleChildren(const WatchData &parent, const GdbMi &child, @@ -412,6 +412,7 @@ private: void setWatchDataType(WatchData &data, const GdbMi &mi); void setWatchDataDisplayedType(WatchData &data, const GdbMi &mi); void setLocals(const QList &locals); + void connectDebuggingHelperActions(bool on); bool startModeAllowsDumpers() const; QString parseDisassembler(const GdbMi &lines); From c5f13cedf92b4a3cbbf54e661071d34fd853906f Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 23 Sep 2009 10:45:32 +0200 Subject: [PATCH 6/8] debugger: partial refactoring of debugger engine creation --- src/plugins/debugger/cdb/cdbdebugengine.cpp | 20 +++++----- src/plugins/debugger/cdb/cdbdebugengine.h | 1 + src/plugins/debugger/debuggermanager.cpp | 39 ++++++++++++-------- src/plugins/debugger/script/scriptengine.cpp | 14 ++++--- src/plugins/debugger/tcf/tcfengine.cpp | 18 ++++----- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/plugins/debugger/cdb/cdbdebugengine.cpp b/src/plugins/debugger/cdb/cdbdebugengine.cpp index 853a774bb2c..b4e9f6fd67b 100644 --- a/src/plugins/debugger/cdb/cdbdebugengine.cpp +++ b/src/plugins/debugger/cdb/cdbdebugengine.cpp @@ -1685,25 +1685,21 @@ bool CdbDebugEnginePrivate::setSymbolPaths(const QStringList &s, QString *errorM return true; } -} // namespace Internal -} // namespace Debugger - // Accessed by DebuggerManager -Debugger::Internal::IDebuggerEngine *createWinEngine(Debugger::Internal::DebuggerManager *parent, - bool cmdLineEnabled, - QList *opts) +IDebuggerEngine *createWinEngine(DebuggerManager *parent, + bool cmdLineEnabled, + QList *opts) { // Create options page - QSharedPointer options(new Debugger::Internal::CdbOptions); + QSharedPointer options(new CdbOptions); options->fromSettings(Core::ICore::instance()->settings()); - Debugger::Internal::CdbOptionsPage *optionsPage = new Debugger::Internal::CdbOptionsPage(options); + CdbOptionsPage *optionsPage = new CdbOptionsPage(options); opts->push_back(optionsPage); if (!cmdLineEnabled || !options->enabled) return 0; // Create engine QString errorMessage; - Debugger::Internal::IDebuggerEngine *engine = - Debugger::Internal::CdbDebugEngine::create(parent, options, &errorMessage); + IDebuggerEngine *engine = CdbDebugEngine::create(parent, options, &errorMessage); if (!engine) { optionsPage->setFailureMessage(errorMessage); qWarning("%s\n" ,qPrintable(errorMessage)); @@ -1711,3 +1707,7 @@ Debugger::Internal::IDebuggerEngine *createWinEngine(Debugger::Internal::Debugge QObject::connect(optionsPage, SIGNAL(debuggerPathsChanged()), engine, SLOT(syncDebuggerPaths())); return engine; } + +} // namespace Internal +} // namespace Debugger + diff --git a/src/plugins/debugger/cdb/cdbdebugengine.h b/src/plugins/debugger/cdb/cdbdebugengine.h index 18b66041652..6b57235fa34 100644 --- a/src/plugins/debugger/cdb/cdbdebugengine.h +++ b/src/plugins/debugger/cdb/cdbdebugengine.h @@ -99,6 +99,7 @@ public: virtual void reloadRegisters(); virtual void reloadSourceFiles(); virtual void reloadFullStack() {} + virtual void addOptionPages(QList *) const; public slots: void syncDebuggerPaths(); diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 8c5c75fdb2d..b581883f1d9 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -82,11 +82,17 @@ #include #include +namespace Debugger { +namespace Internal { -// The creation functions take a list of options pages they can add to. -// This allows for having a "enabled" toggle on the page indepently -// of the engine. -using namespace Debugger::Internal; +IDebuggerEngine *createGdbEngine(DebuggerManager *parent); +IDebuggerEngine *createScriptEngine(DebuggerManager *parent); +IDebuggerEngine *createTcfEngine(DebuggerManager *parent); + +// The createWinEngine function takes a list of options pages it can add to. +// This allows for having a "enabled" toggle on the page independently +// of the engine. That's good for not enabling the related ActiveX control +// unnecessarily. IDebuggerEngine *createWinEngine(DebuggerManager *, bool /* cmdLineEnabled */, QList *) #ifdef CDB_ENABLED @@ -94,14 +100,6 @@ IDebuggerEngine *createWinEngine(DebuggerManager *, bool /* cmdLineEnabled */, Q #else { return 0; } #endif -IDebuggerEngine *createScriptEngine(DebuggerManager *parent, QList *); -IDebuggerEngine *createTcfEngine(DebuggerManager *parent, QList *); - - -namespace Debugger { -namespace Internal { - -IDebuggerEngine *createGdbEngine(DebuggerManager *parent); QDebug operator<<(QDebug str, const DebuggerStartParameters &p) @@ -443,15 +441,24 @@ void DebuggerManager::init() QList DebuggerManager::initializeEngines(unsigned enabledTypeFlags) { QList rc; + if (enabledTypeFlags & GdbEngineType) { gdbEngine = createGdbEngine(this); gdbEngine->addOptionPages(&rc); } + winEngine = createWinEngine(this, (enabledTypeFlags & CdbEngineType), &rc); - if (enabledTypeFlags & ScriptEngineType) - scriptEngine = createScriptEngine(this, &rc); - if (enabledTypeFlags & TcfEngineType) - tcfEngine = createTcfEngine(this, &rc); + + if (enabledTypeFlags & ScriptEngineType) { + scriptEngine = createScriptEngine(this); + scriptEngine->addOptionPages(&rc); + } + + if (enabledTypeFlags & TcfEngineType) { + tcfEngine = createTcfEngine(this); + tcfEngine->addOptionPages(&rc); + } + m_engine = 0; if (Debugger::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << gdbEngine << winEngine << scriptEngine << rc.size(); diff --git a/src/plugins/debugger/script/scriptengine.cpp b/src/plugins/debugger/script/scriptengine.cpp index d73dc189b62..7f1caec3560 100644 --- a/src/plugins/debugger/script/scriptengine.cpp +++ b/src/plugins/debugger/script/scriptengine.cpp @@ -65,10 +65,6 @@ #include #include -using namespace Debugger; -using namespace Debugger::Internal; -using namespace Debugger::Constants; - //#define DEBUG_SCRIPT 1 #if DEBUG_SCRIPT # define SDEBUG(s) qDebug() << s @@ -77,13 +73,17 @@ using namespace Debugger::Constants; #endif # define XSDEBUG(s) qDebug() << s + +namespace Debugger { +namespace Internal { + /////////////////////////////////////////////////////////////////////// // // ScriptEngine // /////////////////////////////////////////////////////////////////////// -class Debugger::Internal::ScriptAgent : public QScriptEngineAgent +class ScriptAgent : public QScriptEngineAgent { public: ScriptAgent(ScriptEngine *debugger, QScriptEngine *script); @@ -733,8 +733,10 @@ void ScriptEngine::updateSubItem(const WatchData &data0) QTC_ASSERT(false, return); } -IDebuggerEngine *createScriptEngine(DebuggerManager *parent, QList *) +IDebuggerEngine *createScriptEngine(DebuggerManager *parent) { return new ScriptEngine(parent); } +} // namespace Internal +} // namespace Debugger diff --git a/src/plugins/debugger/tcf/tcfengine.cpp b/src/plugins/debugger/tcf/tcfengine.cpp index fe0eebf96a9..cc88654ee2d 100644 --- a/src/plugins/debugger/tcf/tcfengine.cpp +++ b/src/plugins/debugger/tcf/tcfengine.cpp @@ -57,11 +57,6 @@ #include - -using namespace Debugger; -using namespace Debugger::Internal; -using namespace Debugger::Constants; - #define DEBUG_TCF 1 #if DEBUG_TCF # define SDEBUG(s) qDebug() << s @@ -74,7 +69,9 @@ using namespace Debugger::Constants; #define STRINGIFY(x) STRINGIFY_INTERNAL(x) #define CB(callback) &TcfEngine::callback, STRINGIFY(callback) -QByteArray C(const QByteArray &ba1, +//#define USE_CONGESTION_CONTROL + +static QByteArray C(const QByteArray &ba1, const QByteArray &ba2 = QByteArray(), const QByteArray &ba3 = QByteArray(), const QByteArray &ba4 = QByteArray(), @@ -88,9 +85,8 @@ QByteArray C(const QByteArray &ba1, return result; } - -//#define USE_CONGESTION_CONTROL - +namespace Debugger { +namespace Internal { /////////////////////////////////////////////////////////////////////// // @@ -571,8 +567,10 @@ void TcfEngine::updateSubItem(const WatchData &data0) QTC_ASSERT(false, return); } -IDebuggerEngine *createTcfEngine(DebuggerManager *parent, QList *) +IDebuggerEngine *createTcfEngine(DebuggerManager *parent) { return new TcfEngine(parent); } +} // namespace Internal +} // namespace Debugger From bd65bd21f3eac730df4c14735db2724e0d40f369 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 23 Sep 2009 10:51:26 +0200 Subject: [PATCH 7/8] debugger: remove outdated comment --- src/plugins/debugger/debuggermanager.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index b581883f1d9..66e7bb4d547 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -367,10 +367,8 @@ void DebuggerManager::init() m_reverseDirectionAction->setChecked(false); //m_reverseDirectionAction->setIcon(QIcon(":/debugger/images/debugger_stepoverproc_small.png")); - // For usuage hints oin focus{In,Out} connect(m_continueAction, SIGNAL(triggered()), this, SLOT(continueExec())); - connect(m_stopAction, SIGNAL(triggered()), this, SLOT(interruptDebuggingRequest())); connect(m_resetAction, SIGNAL(triggered()), From 76d1de0b8792afab6fb7d3a2c8a8669c6053663f Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 23 Sep 2009 12:12:36 +0200 Subject: [PATCH 8/8] debugger: parse pid only once from output --- src/plugins/debugger/debuggermanager.cpp | 2 +- src/plugins/debugger/gdb/gdbengine.cpp | 43 ++++++++++++++---------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 66e7bb4d547..bc97bcdd84a 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -1100,7 +1100,7 @@ static bool isAllowedTransition(int from, int to) { return (from == -1) || (from == DebuggerProcessNotReady && to == DebuggerProcessStartingUp) - //|| (from == DebuggerProcessStartingUp && to == DebuggerInferiorStopped) + || (from == DebuggerProcessStartingUp && to == DebuggerInferiorStopped) || (from == DebuggerInferiorStopped && to == DebuggerInferiorRunningRequested) || (from == DebuggerInferiorRunningRequested && to == DebuggerInferiorRunning) || (from == DebuggerInferiorRunning && to == DebuggerInferiorStopRequested) diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 6483c2efd3f..2a835302fd7 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -543,20 +543,27 @@ void GdbEngine::handleResponse(const QByteArray &buff) } case '~': { - // Linux/Mac gdb: [New [Tt]hread 0x545 (LWP 4554)] - // MinGW gdb 6.8: [New thread 2728.0x1034] - static QRegExp re(_("New .hread 0x[0-9a-f]* \\(LWP ([0-9]*)\\)")); - static QRegExp re2(_("New .hread ([0-9]+)\\.0x[0-9a-f]+")); - QTC_ASSERT(re.isValid() && re2.isValid(), return); QByteArray data = GdbMi::parseCString(from, to); m_pendingConsoleStreamOutput += data; - if (re.indexIn(_(data)) != -1) { - maybeHandleInferiorPidChanged(re.cap(1)); - } else if (re2.indexIn(_(data)) != -1) { - maybeHandleInferiorPidChanged(re2.cap(1)); + + // Parse pid from noise. + if (!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] + static QRegExp re2(_("New .hread ([0-9]+)\\.0x[0-9a-f]*")); + QTC_ASSERT(re1.isValid() && re2.isValid(), return); + if (re1.indexIn(_(data)) != -1) + maybeHandleInferiorPidChanged(re1.cap(1)); + else if (re2.indexIn(_(data)) != -1) + maybeHandleInferiorPidChanged(re2.cap(1)); } + + // Show some messages to give the impression something happens. if (data.startsWith("Reading symbols from ")) - showStatusMessage(tr("Reading %1...").arg(_(data.mid(21)))); + showStatusMessage(tr("Reading %1...").arg(_(data.mid(21))), 1000); + if (data.startsWith("[New ")) + showStatusMessage(_(data), 1000); break; } @@ -4105,6 +4112,7 @@ void GdbEngine::handleAdapterStartFailed(const QString &msg) void GdbEngine::handleAdapterStarted() { debugMessage(_("ADAPTER SUCCESSFULLY STARTED, PREPARING INFERIOR")); + qq->notifyInferiorStopped(); m_gdbAdapter->prepareInferior(); } @@ -4120,6 +4128,7 @@ void GdbEngine::handleInferiorPreparationFailed(const QString &msg) void GdbEngine::handleInferiorPrepared() { + debugMessage(_("INFERIOR PREPARED")); // FIXME: Check that inferior is in "stopped" state qq->notifyInferiorStopped(); showStatusMessage(tr("Inferior prepared for startup.")); @@ -4247,7 +4256,7 @@ void GdbEngine::handleInferiorPrepared() void GdbEngine::handleInitialBreakpointsSet() { - showStatusMessage(tr("Finishing initial breakpoint setting.")); + showStatusMessage(tr("Initial breakpoint setting finished."), 1000); qq->notifyInferiorRunningRequested(); m_gdbAdapter->startInferior(); } @@ -4255,14 +4264,14 @@ void GdbEngine::handleInitialBreakpointsSet() void GdbEngine::handleInferiorStartFailed(const QString &msg) { debugMessage(_("INFERIOR START FAILED")); - showMessageBox(QMessageBox::Critical, tr("Error"), - tr("Inferior start failed:\n") + msg); + showMessageBox(QMessageBox::Critical, tr("Inferior start failed"), msg); qq->notifyInferiorExited(); m_manager->exitDebugger(); } void GdbEngine::handleInferiorStarted() { + debugMessage(_("INFERIOR STARTED")); qq->notifyInferiorRunning(); } @@ -4274,8 +4283,8 @@ void GdbEngine::handleInferiorShutDown() void GdbEngine::handleInferiorShutdownFailed(const QString &msg) { debugMessage(_("INFERIOR SHUTDOWN FAILED")); - showMessageBox(QMessageBox::Critical, tr("Error"), - tr("Inferior shutdown failed:\n") + msg); + showMessageBox(QMessageBox::Critical, + tr("Inferior shutdown failed"), msg); qq->notifyInferiorExited(); m_manager->exitDebugger(); } @@ -4289,8 +4298,8 @@ void GdbEngine::handleAdapterShutDown() void GdbEngine::handleAdapterShutdownFailed(const QString &msg) { debugMessage(_("ADAPTER SHUTDOWN FAILED")); - showMessageBox(QMessageBox::Critical, tr("Error"), - tr("Inferior shutdown failed:\n") + msg); + showMessageBox(QMessageBox::Critical, + tr("Inferior shutdown failed"), msg); qq->notifyInferiorExited(); }