debugger: make location markers engine-specific

This commit is contained in:
hjk
2010-12-14 12:21:29 +01:00
parent d31fcda258
commit b90bb97fa9
7 changed files with 93 additions and 101 deletions

View File

@@ -852,16 +852,17 @@ void BreakHandler::gotoLocation(BreakpointId id) const
{ {
ConstIterator it = m_storage.find(id); ConstIterator it = m_storage.find(id);
QTC_ASSERT(it != m_storage.end(), return); QTC_ASSERT(it != m_storage.end(), return);
DebuggerEngine *engine = debuggerCore()->currentEngine();
if (it->data.type == BreakpointByAddress) { if (it->data.type == BreakpointByAddress) {
StackFrame frame; StackFrame frame;
frame.address = it->data.address; frame.address = it->data.address;
DebuggerEngine *engine = debuggerCore()->currentEngine();
if (engine) if (engine)
engine->gotoLocation(frame, false); engine->gotoLocation(frame, false);
} else { } else {
const QString fileName = it->markerFileName(); const QString fileName = it->markerFileName();
const int lineNumber = it->markerLineNumber(); const int lineNumber = it->markerLineNumber();
debuggerCore()->gotoLocation(fileName, lineNumber, false); if (engine)
engine->gotoLocation(fileName, lineNumber, false);
} }
} }

View File

@@ -93,11 +93,6 @@ public:
// void runTest(const QString &fileName); // void runTest(const QString &fileName);
virtual void showMessage(const QString &msg, int channel, int timeout = -1) = 0; 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 bool isReverseDebugging() const = 0;
virtual void runControlStarted(DebuggerEngine *engine) = 0; virtual void runControlStarted(DebuggerEngine *engine) = 0;

View File

@@ -56,6 +56,8 @@
#include <projectexplorer/toolchaintype.h> #include <projectexplorer/toolchaintype.h>
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/basetextmark.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/savedaction.h> #include <utils/savedaction.h>
@@ -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 // DebuggerEnginePrivate
@@ -192,7 +216,9 @@ public:
m_isSlaveEngine(false), m_isSlaveEngine(false),
m_disassemblerViewAgent(engine), m_disassemblerViewAgent(engine),
m_memoryViewAgent(engine) m_memoryViewAgent(engine)
{} {
connect(&m_locationTimer, SIGNAL(timeout()), SLOT(doRemoveLocationMark()));
}
~DebuggerEnginePrivate() {} ~DebuggerEnginePrivate() {}
@@ -240,6 +266,18 @@ public slots:
m_runControl->bringApplicationToForeground(m_inferiorPid); m_runControl->bringApplicationToForeground(m_inferiorPid);
} }
void removeLocationMark()
{
m_locationTimer.setSingleShot(true);
m_locationTimer.start(80);
}
void doRemoveLocationMark()
{
m_locationTimer.stop();
m_locationMark.reset();
}
public: public:
DebuggerState state() const { return m_state; } DebuggerState state() const { return m_state; }
@@ -270,6 +308,8 @@ public:
bool m_isSlaveEngine; bool m_isSlaveEngine;
DisassemblerViewAgent m_disassemblerViewAgent; DisassemblerViewAgent m_disassemblerViewAgent;
MemoryViewAgent m_memoryViewAgent; MemoryViewAgent m_memoryViewAgent;
QScopedPointer<TextEditor::BaseTextMark> m_locationMark;
QTimer m_locationTimer;
}; };
@@ -493,12 +533,27 @@ void DebuggerEngine::breakByFunction(const QString &functionName)
void DebuggerEngine::resetLocation() void DebuggerEngine::resetLocation()
{ {
d->m_disassemblerViewAgent.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) 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()) if (debuggerCore()->boolSetting(OperateByInstruction) || !frame.isUsable())
d->m_disassemblerViewAgent.setFrame(frame, true, setMarker); d->m_disassemblerViewAgent.setFrame(frame, true, setMarker);
else else
debuggerCore()->gotoLocation(frame.file, frame.line, setMarker); gotoLocation(frame.file, frame.line, setMarker);
} }
// Called from RunControl. // Called from RunControl.

View File

@@ -279,11 +279,13 @@ public:
void handleCommand(int role, const QVariant &value); void handleCommand(int role, const QVariant &value);
// Convenience // 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; Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const;
void resetLocation(); 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 gotoLocation(const Internal::StackFrame &frame, bool setMarker);
virtual void quitDebugger(); // called by DebuggerRunControl virtual void quitDebugger(); // called by DebuggerRunControl

View File

@@ -95,7 +95,6 @@
#include <qt4projectmanager/qt4projectmanagerconstants.h> #include <qt4projectmanager/qt4projectmanagerconstants.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <texteditor/basetextmark.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
@@ -531,27 +530,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 // CommonOptionsPage
@@ -1068,8 +1046,6 @@ public slots:
void updateWatchersWindow(); void updateWatchersWindow();
void onCurrentProjectChanged(ProjectExplorer::Project *project); void onCurrentProjectChanged(ProjectExplorer::Project *project);
void gotoLocation(const QString &file, int line, bool setMarker);
void clearStatusMessage(); void clearStatusMessage();
void sessionLoaded(); void sessionLoaded();
@@ -1085,31 +1061,31 @@ public slots:
void handleExecDetach() void handleExecDetach()
{ {
resetLocation(); currentEngine()->resetLocation();
currentEngine()->detachDebugger(); currentEngine()->detachDebugger();
} }
void handleExecContinue() void handleExecContinue()
{ {
resetLocation(); currentEngine()->resetLocation();
currentEngine()->continueInferior(); currentEngine()->continueInferior();
} }
void handleExecInterrupt() void handleExecInterrupt()
{ {
resetLocation(); currentEngine()->resetLocation();
currentEngine()->requestInterruptInferior(); currentEngine()->requestInterruptInferior();
} }
void handleExecReset() void handleExecReset()
{ {
resetLocation(); currentEngine()->resetLocation();
currentEngine()->notifyEngineIll(); // FIXME: Check. currentEngine()->notifyEngineIll(); // FIXME: Check.
} }
void handleExecStep() void handleExecStep()
{ {
resetLocation(); currentEngine()->resetLocation();
if (boolSetting(OperateByInstruction)) if (boolSetting(OperateByInstruction))
currentEngine()->executeStepI(); currentEngine()->executeStepI();
else else
@@ -1118,7 +1094,7 @@ public slots:
void handleExecNext() void handleExecNext()
{ {
resetLocation(); currentEngine()->resetLocation();
if (boolSetting(OperateByInstruction)) if (boolSetting(OperateByInstruction))
currentEngine()->executeNextI(); currentEngine()->executeNextI();
else else
@@ -1127,20 +1103,20 @@ public slots:
void handleExecStepOut() void handleExecStepOut()
{ {
resetLocation(); currentEngine()->resetLocation();
currentEngine()->executeStepOut(); currentEngine()->executeStepOut();
} }
void handleExecReturn() void handleExecReturn()
{ {
resetLocation(); currentEngine()->resetLocation();
currentEngine()->executeReturn(); currentEngine()->executeReturn();
} }
void handleExecJumpToLine() void handleExecJumpToLine()
{ {
//removeTooltip(); //removeTooltip();
resetLocation(); currentEngine()->resetLocation();
QString fileName; QString fileName;
int lineNumber; int lineNumber;
if (currentTextEditorPosition(&fileName, &lineNumber)) if (currentTextEditorPosition(&fileName, &lineNumber))
@@ -1150,7 +1126,7 @@ public slots:
void handleExecRunToLine() void handleExecRunToLine()
{ {
//removeTooltip(); //removeTooltip();
resetLocation(); currentEngine()->resetLocation();
QString fileName; QString fileName;
int lineNumber; int lineNumber;
if (currentTextEditorPosition(&fileName, &lineNumber)) if (currentTextEditorPosition(&fileName, &lineNumber))
@@ -1159,7 +1135,7 @@ public slots:
void handleExecRunToFunction() void handleExecRunToFunction()
{ {
resetLocation(); currentEngine()->resetLocation();
ITextEditor *textEditor = currentTextEditor(); ITextEditor *textEditor = currentTextEditor();
QTC_ASSERT(textEditor, return); QTC_ASSERT(textEditor, return);
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(textEditor->widget()); QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(textEditor->widget());
@@ -1274,9 +1250,6 @@ public slots:
return m_mainWindow->activeDebugLanguages() & lang; return m_mainWindow->activeDebugLanguages() & lang;
} }
void resetLocation();
void removeLocationMark();
void doRemoveLocationMark();
QVariant sessionValue(const QString &name); QVariant sessionValue(const QString &name);
void setSessionValue(const QString &name, const QVariant &value); void setSessionValue(const QString &name, const QVariant &value);
QIcon locationMarkIcon() const { return m_locationMarkIcon; } QIcon locationMarkIcon() const { return m_locationMarkIcon; }
@@ -1297,7 +1270,6 @@ public:
DebuggerRunControlFactory *m_debuggerRunControlFactory; DebuggerRunControlFactory *m_debuggerRunControlFactory;
QString m_previousMode; QString m_previousMode;
QScopedPointer<TextEditor::BaseTextMark> m_locationMark;
Context m_continuableContext; Context m_continuableContext;
Context m_interruptibleContext; Context m_interruptibleContext;
Context m_undisturbableContext; Context m_undisturbableContext;
@@ -1344,7 +1316,6 @@ public:
bool m_busy; bool m_busy;
QTimer m_statusTimer; QTimer m_statusTimer;
QTimer m_locationTimer;
QString m_lastPermanentStatusMessage; QString m_lastPermanentStatusMessage;
mutable CPlusPlus::Snapshot m_codeModelSnapshot; mutable CPlusPlus::Snapshot m_codeModelSnapshot;
@@ -1999,6 +1970,8 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
if (m_currentEngine == engine) if (m_currentEngine == engine)
return; return;
if (m_currentEngine)
m_currentEngine->resetLocation();
m_currentEngine = engine; m_currentEngine = engine;
m_localsWindow->setModel(engine->localsModel()); m_localsWindow->setModel(engine->localsModel());
@@ -2284,26 +2257,6 @@ void DebuggerPluginPrivate::updateDebugActions()
m_debugAction->setEnabled(pe->canRun(project, Constants::DEBUGMODE)); 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) void DebuggerPluginPrivate::onModeChanged(IMode *mode)
{ {
// FIXME: This one gets always called, even if switching between modes // FIXME: This one gets always called, even if switching between modes
@@ -2438,23 +2391,6 @@ const CPlusPlus::Snapshot &DebuggerPluginPrivate::cppCodeModelSnapshot() const
return m_codeModelSnapshot; 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) void DebuggerPluginPrivate::setSessionValue(const QString &name, const QVariant &value)
{ {
QTC_ASSERT(sessionManager(), return); QTC_ASSERT(sessionManager(), return);
@@ -3180,10 +3116,6 @@ void DebuggerPluginPrivate::extensionsInitialized()
SIGNAL(startupProjectChanged(ProjectExplorer::Project*)), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
SLOT(onCurrentProjectChanged(ProjectExplorer::Project*))); SLOT(onCurrentProjectChanged(ProjectExplorer::Project*)));
connect(&m_locationTimer,
SIGNAL(timeout()),
SLOT(doRemoveLocationMark()));
QTC_ASSERT(m_coreSettings, /**/); QTC_ASSERT(m_coreSettings, /**/);
m_watchersWindow->setVisible(false); m_watchersWindow->setVisible(false);
m_returnWindow->setVisible(false); m_returnWindow->setVisible(false);

View File

@@ -72,7 +72,9 @@ ModulesWindow::ModulesWindow(QWidget *parent)
void ModulesWindow::moduleActivated(const QModelIndex &index) 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) void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
@@ -85,6 +87,7 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
name = index.data().toString(); name = index.data().toString();
DebuggerEngine *engine = debuggerCore()->currentEngine(); DebuggerEngine *engine = debuggerCore()->currentEngine();
QTC_ASSERT(engine, return);
const bool enabled = engine->debuggerActionsEnabled(); const bool enabled = engine->debuggerActionsEnabled();
const unsigned capabilities = engine->debuggerCapabilities(); const unsigned capabilities = engine->debuggerCapabilities();
@@ -167,7 +170,7 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
else if (act == actLoadSymbolsForModule) else if (act == actLoadSymbolsForModule)
engine->loadSymbols(name); engine->loadSymbols(name);
else if (act == actEditFile) else if (act == actEditFile)
debuggerCore()->gotoLocation(name); engine->gotoLocation(name);
else if (act == actShowModuleSymbols) else if (act == actShowModuleSymbols)
engine->requestModuleSymbols(name); engine->requestModuleSymbols(name);
} }

View File

@@ -81,15 +81,19 @@ SourceFilesWindow::SourceFilesWindow(QWidget *parent)
void SourceFilesWindow::sourceFileActivated(const QModelIndex &index) 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) void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev)
{ {
DebuggerEngine *engine = currentEngine();
QTC_ASSERT(engine, return);
QModelIndex index = indexAt(ev->pos()); QModelIndex index = indexAt(ev->pos());
index = index.sibling(index.row(), 0); index = index.sibling(index.row(), 0);
QString name = index.data().toString(); QString name = index.data().toString();
bool engineActionsEnabled = currentEngine()->debuggerActionsEnabled(); bool engineActionsEnabled = engine->debuggerActionsEnabled();
QMenu menu; QMenu menu;
QAction *act1 = new QAction(tr("Reload Data"), &menu); QAction *act1 = new QAction(tr("Reload Data"), &menu);
@@ -113,9 +117,9 @@ void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev)
QAction *act = menu.exec(ev->globalPos()); QAction *act = menu.exec(ev->globalPos());
if (act == act1) if (act == act1)
currentEngine()->reloadSourceFiles(); engine->reloadSourceFiles();
else if (act == act2) else if (act == act2)
debuggerCore()->gotoLocation(name); engine->gotoLocation(name);
} }
} // namespace Internal } // namespace Internal