From: hjk Date: Tue, 14 Dec 2010 11:21:29 +0000 (+0100) Subject: debugger: make location markers engine-specific X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b90bb97fa9782ab65107331878d08484f2330e14;p=qt-creator-jp%2Fqt-creator-jp.git debugger: make location markers engine-specific --- diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index ad0f971b72..f7bb60320b 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -852,16 +852,17 @@ void BreakHandler::gotoLocation(BreakpointId id) const { ConstIterator it = m_storage.find(id); QTC_ASSERT(it != m_storage.end(), return); + DebuggerEngine *engine = debuggerCore()->currentEngine(); if (it->data.type == BreakpointByAddress) { StackFrame frame; frame.address = it->data.address; - DebuggerEngine *engine = debuggerCore()->currentEngine(); if (engine) engine->gotoLocation(frame, false); } else { const QString fileName = it->markerFileName(); const int lineNumber = it->markerLineNumber(); - debuggerCore()->gotoLocation(fileName, lineNumber, false); + if (engine) + engine->gotoLocation(fileName, lineNumber, false); } } diff --git a/src/plugins/debugger/debuggercore.h b/src/plugins/debugger/debuggercore.h index 3b1ff3914c..5f5470edfd 100644 --- a/src/plugins/debugger/debuggercore.h +++ b/src/plugins/debugger/debuggercore.h @@ -93,11 +93,6 @@ public: // void runTest(const QString &fileName); virtual void showMessage(const QString &msg, int channel, int timeout = -1) = 0; - virtual void gotoLocation(const QString &fileName, int lineNumber = -1, - bool setMarker = false) = 0; - - virtual void resetLocation() = 0; - virtual void removeLocationMark() = 0; virtual bool isReverseDebugging() const = 0; virtual void runControlStarted(DebuggerEngine *engine) = 0; diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index f27833d809..56ede78f55 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -56,6 +56,8 @@ #include #include +#include +#include #include #include @@ -165,6 +167,28 @@ const char *DebuggerEngine::stateName(int s) } +/////////////////////////////////////////////////////////////////////// +// +// LocationMark +// +/////////////////////////////////////////////////////////////////////// + +// Used in "real" editors +class LocationMark : public TextEditor::BaseTextMark +{ +public: + LocationMark(const QString &fileName, int linenumber) + : BaseTextMark(fileName, linenumber) + {} + + QIcon icon() const { return debuggerCore()->locationMarkIcon(); } + void updateLineNumber(int /*lineNumber*/) {} + void updateBlock(const QTextBlock & /*block*/) {} + void removedFromEditor() {} +}; + + + ////////////////////////////////////////////////////////////////////// // // DebuggerEnginePrivate @@ -192,7 +216,9 @@ public: m_isSlaveEngine(false), m_disassemblerViewAgent(engine), m_memoryViewAgent(engine) - {} + { + connect(&m_locationTimer, SIGNAL(timeout()), SLOT(doRemoveLocationMark())); + } ~DebuggerEnginePrivate() {} @@ -240,6 +266,18 @@ public slots: m_runControl->bringApplicationToForeground(m_inferiorPid); } + void removeLocationMark() + { + m_locationTimer.setSingleShot(true); + m_locationTimer.start(80); + } + + void doRemoveLocationMark() + { + m_locationTimer.stop(); + m_locationMark.reset(); + } + public: DebuggerState state() const { return m_state; } @@ -270,6 +308,8 @@ public: bool m_isSlaveEngine; DisassemblerViewAgent m_disassemblerViewAgent; MemoryViewAgent m_memoryViewAgent; + QScopedPointer m_locationMark; + QTimer m_locationTimer; }; @@ -493,12 +533,27 @@ void DebuggerEngine::breakByFunction(const QString &functionName) void DebuggerEngine::resetLocation() { d->m_disassemblerViewAgent.resetLocation(); - debuggerCore()->removeLocationMark(); + d->removeLocationMark(); } -void DebuggerEngine::gotoLocation(const QString &fileName, int lineNumber, bool setMarker) +void DebuggerEngine::gotoLocation(const QString &file, int line, bool setMarker) { - debuggerCore()->gotoLocation(fileName, lineNumber, setMarker); + // CDB might hit on breakpoints while shutting down. + //if (m_shuttingDown) + // return; + + d->doRemoveLocationMark(); + + bool newEditor = false; + ITextEditor *editor = + BaseTextEditor::openEditorAt(file, line, 0, QString(), + EditorManager::IgnoreNavigationHistory, &newEditor); + if (!editor) + return; + if (newEditor) + editor->setProperty(Constants::OPENED_BY_DEBUGGER, true); + if (setMarker) + d->m_locationMark.reset(new LocationMark(file, line)); } void DebuggerEngine::gotoLocation(const StackFrame &frame, bool setMarker) @@ -506,7 +561,7 @@ void DebuggerEngine::gotoLocation(const StackFrame &frame, bool setMarker) if (debuggerCore()->boolSetting(OperateByInstruction) || !frame.isUsable()) d->m_disassemblerViewAgent.setFrame(frame, true, setMarker); else - debuggerCore()->gotoLocation(frame.file, frame.line, setMarker); + gotoLocation(frame.file, frame.line, setMarker); } // Called from RunControl. diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h index cabeccc5f2..9306ad6a6c 100644 --- a/src/plugins/debugger/debuggerengine.h +++ b/src/plugins/debugger/debuggerengine.h @@ -279,11 +279,13 @@ public: void handleCommand(int role, const QVariant &value); // Convenience - Q_SLOT void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1) const; + Q_SLOT void showMessage(const QString &msg, int channel = LogDebug, + int timeout = -1) const; Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const; void resetLocation(); - virtual void gotoLocation(const QString &fileName, int lineNumber, bool setMarker); + virtual void gotoLocation(const QString &fileName, int lineNumber = -1, + bool setMarker = false); virtual void gotoLocation(const Internal::StackFrame &frame, bool setMarker); virtual void quitDebugger(); // called by DebuggerRunControl diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 08a8bd268d..05818f5e3a 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -95,7 +95,6 @@ #include #include -#include #include #include @@ -533,27 +532,6 @@ private: /////////////////////////////////////////////////////////////////////// // -// LocationMark -// -/////////////////////////////////////////////////////////////////////// - -// Used in "real" editors -class LocationMark : public TextEditor::BaseTextMark -{ -public: - LocationMark(const QString &fileName, int linenumber) - : BaseTextMark(fileName, linenumber) - {} - - QIcon icon() const { return debuggerCore()->locationMarkIcon(); } - void updateLineNumber(int /*lineNumber*/) {} - void updateBlock(const QTextBlock & /*block*/) {} - void removedFromEditor() {} -}; - - -/////////////////////////////////////////////////////////////////////// -// // CommonOptionsPage // /////////////////////////////////////////////////////////////////////// @@ -1068,8 +1046,6 @@ public slots: void updateWatchersWindow(); void onCurrentProjectChanged(ProjectExplorer::Project *project); - void gotoLocation(const QString &file, int line, bool setMarker); - void clearStatusMessage(); void sessionLoaded(); @@ -1085,31 +1061,31 @@ public slots: void handleExecDetach() { - resetLocation(); + currentEngine()->resetLocation(); currentEngine()->detachDebugger(); } void handleExecContinue() { - resetLocation(); + currentEngine()->resetLocation(); currentEngine()->continueInferior(); } void handleExecInterrupt() { - resetLocation(); + currentEngine()->resetLocation(); currentEngine()->requestInterruptInferior(); } void handleExecReset() { - resetLocation(); + currentEngine()->resetLocation(); currentEngine()->notifyEngineIll(); // FIXME: Check. } void handleExecStep() { - resetLocation(); + currentEngine()->resetLocation(); if (boolSetting(OperateByInstruction)) currentEngine()->executeStepI(); else @@ -1118,7 +1094,7 @@ public slots: void handleExecNext() { - resetLocation(); + currentEngine()->resetLocation(); if (boolSetting(OperateByInstruction)) currentEngine()->executeNextI(); else @@ -1127,20 +1103,20 @@ public slots: void handleExecStepOut() { - resetLocation(); + currentEngine()->resetLocation(); currentEngine()->executeStepOut(); } void handleExecReturn() { - resetLocation(); + currentEngine()->resetLocation(); currentEngine()->executeReturn(); } void handleExecJumpToLine() { //removeTooltip(); - resetLocation(); + currentEngine()->resetLocation(); QString fileName; int lineNumber; if (currentTextEditorPosition(&fileName, &lineNumber)) @@ -1150,7 +1126,7 @@ public slots: void handleExecRunToLine() { //removeTooltip(); - resetLocation(); + currentEngine()->resetLocation(); QString fileName; int lineNumber; if (currentTextEditorPosition(&fileName, &lineNumber)) @@ -1159,7 +1135,7 @@ public slots: void handleExecRunToFunction() { - resetLocation(); + currentEngine()->resetLocation(); ITextEditor *textEditor = currentTextEditor(); QTC_ASSERT(textEditor, return); QPlainTextEdit *ed = qobject_cast(textEditor->widget()); @@ -1274,9 +1250,6 @@ public slots: return m_mainWindow->activeDebugLanguages() & lang; } - void resetLocation(); - void removeLocationMark(); - void doRemoveLocationMark(); QVariant sessionValue(const QString &name); void setSessionValue(const QString &name, const QVariant &value); QIcon locationMarkIcon() const { return m_locationMarkIcon; } @@ -1297,7 +1270,6 @@ public: DebuggerRunControlFactory *m_debuggerRunControlFactory; QString m_previousMode; - QScopedPointer m_locationMark; Context m_continuableContext; Context m_interruptibleContext; Context m_undisturbableContext; @@ -1344,7 +1316,6 @@ public: bool m_busy; QTimer m_statusTimer; - QTimer m_locationTimer; QString m_lastPermanentStatusMessage; mutable CPlusPlus::Snapshot m_codeModelSnapshot; @@ -1999,6 +1970,8 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine) if (m_currentEngine == engine) return; + if (m_currentEngine) + m_currentEngine->resetLocation(); m_currentEngine = engine; m_localsWindow->setModel(engine->localsModel()); @@ -2284,26 +2257,6 @@ void DebuggerPluginPrivate::updateDebugActions() m_debugAction->setEnabled(pe->canRun(project, Constants::DEBUGMODE)); } -void DebuggerPluginPrivate::gotoLocation(const QString &file, int line, bool setMarker) -{ - // CDB might hit on breakpoints while shutting down. - if (m_shuttingDown) - return; - - doRemoveLocationMark(); - - bool newEditor = false; - ITextEditor *editor = - BaseTextEditor::openEditorAt(file, line, 0, QString(), - EditorManager::IgnoreNavigationHistory, &newEditor); - if (!editor) - return; - if (newEditor) - editor->setProperty(Constants::OPENED_BY_DEBUGGER, true); - if (setMarker) - m_locationMark.reset(new LocationMark(file, line)); -} - void DebuggerPluginPrivate::onModeChanged(IMode *mode) { // FIXME: This one gets always called, even if switching between modes @@ -2438,23 +2391,6 @@ const CPlusPlus::Snapshot &DebuggerPluginPrivate::cppCodeModelSnapshot() const return m_codeModelSnapshot; } -void DebuggerPluginPrivate::resetLocation() -{ - currentEngine()->resetLocation(); -} - -void DebuggerPluginPrivate::removeLocationMark() -{ - m_locationTimer.setSingleShot(true); - m_locationTimer.start(80); -} - -void DebuggerPluginPrivate::doRemoveLocationMark() -{ - m_locationTimer.stop(); - m_locationMark.reset(); -} - void DebuggerPluginPrivate::setSessionValue(const QString &name, const QVariant &value) { QTC_ASSERT(sessionManager(), return); @@ -3180,10 +3116,6 @@ void DebuggerPluginPrivate::extensionsInitialized() SIGNAL(startupProjectChanged(ProjectExplorer::Project*)), SLOT(onCurrentProjectChanged(ProjectExplorer::Project*))); - connect(&m_locationTimer, - SIGNAL(timeout()), - SLOT(doRemoveLocationMark())); - QTC_ASSERT(m_coreSettings, /**/); m_watchersWindow->setVisible(false); m_returnWindow->setVisible(false); diff --git a/src/plugins/debugger/moduleswindow.cpp b/src/plugins/debugger/moduleswindow.cpp index 566a7c459a..c4f0b02359 100644 --- a/src/plugins/debugger/moduleswindow.cpp +++ b/src/plugins/debugger/moduleswindow.cpp @@ -72,7 +72,9 @@ ModulesWindow::ModulesWindow(QWidget *parent) void ModulesWindow::moduleActivated(const QModelIndex &index) { - debuggerCore()->gotoLocation(index.data().toString()); + DebuggerEngine *engine = debuggerCore()->currentEngine(); + QTC_ASSERT(engine, return); + engine->gotoLocation(index.data().toString()); } void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev) @@ -85,6 +87,7 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev) name = index.data().toString(); DebuggerEngine *engine = debuggerCore()->currentEngine(); + QTC_ASSERT(engine, return); const bool enabled = engine->debuggerActionsEnabled(); const unsigned capabilities = engine->debuggerCapabilities(); @@ -167,7 +170,7 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev) else if (act == actLoadSymbolsForModule) engine->loadSymbols(name); else if (act == actEditFile) - debuggerCore()->gotoLocation(name); + engine->gotoLocation(name); else if (act == actShowModuleSymbols) engine->requestModuleSymbols(name); } diff --git a/src/plugins/debugger/sourcefileswindow.cpp b/src/plugins/debugger/sourcefileswindow.cpp index 55e075c317..53bc807867 100644 --- a/src/plugins/debugger/sourcefileswindow.cpp +++ b/src/plugins/debugger/sourcefileswindow.cpp @@ -81,15 +81,19 @@ SourceFilesWindow::SourceFilesWindow(QWidget *parent) void SourceFilesWindow::sourceFileActivated(const QModelIndex &index) { - debuggerCore()->gotoLocation(index.data().toString()); + DebuggerEngine *engine = currentEngine(); + QTC_ASSERT(engine, return); + engine->gotoLocation(index.data().toString()); } void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev) { + DebuggerEngine *engine = currentEngine(); + QTC_ASSERT(engine, return); QModelIndex index = indexAt(ev->pos()); index = index.sibling(index.row(), 0); QString name = index.data().toString(); - bool engineActionsEnabled = currentEngine()->debuggerActionsEnabled(); + bool engineActionsEnabled = engine->debuggerActionsEnabled(); QMenu menu; QAction *act1 = new QAction(tr("Reload Data"), &menu); @@ -113,9 +117,9 @@ void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev) QAction *act = menu.exec(ev->globalPos()); if (act == act1) - currentEngine()->reloadSourceFiles(); + engine->reloadSourceFiles(); else if (act == act2) - debuggerCore()->gotoLocation(name); + engine->gotoLocation(name); } } // namespace Internal