diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 96638cef077..6c22b15b103 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -46,6 +46,7 @@ #include "gdb/gdbengine.h" // REMOVE #include "registerhandler.h" #include "sourcefileshandler.h" +#include "sourceutils.h" #include "stackhandler.h" #include "terminal.h" #include "threadshandler.h" @@ -134,28 +135,25 @@ Location::Location(const StackFrame &frame, bool marker) } -class LocationMark : public TextMark +LocationMark::LocationMark(DebuggerEngine *engine, const QString &file, int line) + : TextMark(file, line, Constants::TEXT_MARK_CATEGORY_LOCATION), m_engine(engine) { -public: - LocationMark(DebuggerEngine *engine, const QString &file, int line) - : TextMark(file, line, Constants::TEXT_MARK_CATEGORY_LOCATION), m_engine(engine) - {} + setIcon(Internal::locationMarkIcon()); + setPriority(TextMark::HighPriority); +} -private: - bool isDraggable() const { return true; } +bool LocationMark::isDraggable() const +{ + return m_engine->hasCapability(JumpToLineCapability); +} - void dragToLine(int line) - { - if (m_engine) { - ContextData data; - data.fileName = fileName(); - data.lineNumber = line; - m_engine->executeJumpToLine(data); - } +void LocationMark::dragToLine(int line) +{ + if (m_engine) { + if (BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor()) + m_engine->executeJumpToLine(getLocationContext(textEditor->textDocument(), line)); } - - QPointer m_engine; -}; +} ////////////////////////////////////////////////////////////////////// // @@ -632,11 +630,8 @@ void DebuggerEngine::gotoLocation(const Location &loc) if (newEditor) editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true); - if (loc.needsMarker()) { + if (loc.needsMarker()) d->m_locationMark.reset(new LocationMark(this, file, line)); - d->m_locationMark->setIcon(Internal::locationMarkIcon()); - d->m_locationMark->setPriority(TextMark::HighPriority); - } //qDebug() << "MEMORY: " << d->m_memoryAgent.hasVisibleEditor(); } diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h index c830a0ded35..e6625fc1dc3 100644 --- a/src/plugins/debugger/debuggerengine.h +++ b/src/plugins/debugger/debuggerengine.h @@ -36,6 +36,7 @@ #include "debuggerstartparameters.h" #include +#include #include #include @@ -446,6 +447,18 @@ private: DebuggerEnginePrivate *d; }; +class LocationMark : public TextEditor::TextMark +{ +public: + LocationMark(DebuggerEngine *engine, const QString &file, int line); + +private: + bool isDraggable() const; + void dragToLine(int line); + + QPointer m_engine; +}; + DebuggerEngine *createEngine(DebuggerEngineType et, const DebuggerRunParameters &rp, QStringList *errors); DebuggerRunControl *createAndScheduleRun(const DebuggerRunParameters &rp, const ProjectExplorer::Kit *kit); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index a79bef2e8c5..95049cb16f8 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -552,25 +552,6 @@ static Kit *findUniversalCdbKit() return KitManager::find(cdbMatcher()); } -static bool currentTextEditorPosition(ContextData *data) -{ - BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor(); - if (!textEditor) - return false; - const TextDocument *document = textEditor->textDocument(); - QTC_ASSERT(document, return false); - data->fileName = document->filePath().toString(); - if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) { - int lineNumber = textEditor->currentLine(); - QString line = textEditor->textDocument()->plainText() - .section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1); - data->address = DisassemblerLine::addressFromDisassemblyLine(line); - } else { - data->lineNumber = textEditor->currentLine(); - } - return true; -} - /////////////////////////////////////////////////////////////////////// // // DebuggerPluginPrivate @@ -848,17 +829,17 @@ public slots: void handleExecJumpToLine() { currentEngine()->resetLocation(); - ContextData data; - if (currentTextEditorPosition(&data)) - currentEngine()->executeJumpToLine(data); + if (BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor()) + currentEngine()->executeJumpToLine(getLocationContext(textEditor->textDocument(), + textEditor->currentLine())); } void handleExecRunToLine() { currentEngine()->resetLocation(); - ContextData data; - if (currentTextEditorPosition(&data)) - currentEngine()->executeRunToLine(data); + if (BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor()) + currentEngine()->executeRunToLine(getLocationContext(textEditor->textDocument(), + textEditor->currentLine())); } void handleExecRunToSelectedFunction() diff --git a/src/plugins/debugger/disassembleragent.cpp b/src/plugins/debugger/disassembleragent.cpp index a7df1f215ec..e6f5632ff7c 100644 --- a/src/plugins/debugger/disassembleragent.cpp +++ b/src/plugins/debugger/disassembleragent.cpp @@ -98,7 +98,7 @@ typedef QPair CacheEntry; class DisassemblerAgentPrivate { public: - DisassemblerAgentPrivate(); + DisassemblerAgentPrivate(DebuggerEngine *engine); ~DisassemblerAgentPrivate(); void configureMimeType(); DisassemblerLines contentsAtCurrentLocation() const; @@ -107,22 +107,20 @@ public: QPointer document; Location location; QPointer engine; - TextMark locationMark; + LocationMark locationMark; QList breakpointMarks; QList cache; QString mimeType; bool resetLocationScheduled; }; -DisassemblerAgentPrivate::DisassemblerAgentPrivate() +DisassemblerAgentPrivate::DisassemblerAgentPrivate(DebuggerEngine *engine) : document(0), - locationMark(QString(), 0, Constants::TEXT_MARK_CATEGORY_LOCATION), + engine(engine), + locationMark(engine, QString(), 0), mimeType(_("text/x-qtcreator-generic-asm")), resetLocationScheduled(false) -{ - locationMark.setIcon(Internal::locationMarkIcon()); - locationMark.setPriority(TextMark::HighPriority); -} +{} DisassemblerAgentPrivate::~DisassemblerAgentPrivate() { @@ -157,10 +155,8 @@ DisassemblerLines DisassemblerAgentPrivate::contentsAtCurrentLocation() const */ DisassemblerAgent::DisassemblerAgent(DebuggerEngine *engine) - : QObject(0), d(new DisassemblerAgentPrivate) -{ - d->engine = engine; -} + : d(new DisassemblerAgentPrivate(engine)) +{} DisassemblerAgent::~DisassemblerAgent() { diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp index e70696ccc55..5da06340b40 100644 --- a/src/plugins/debugger/sourceutils.cpp +++ b/src/plugins/debugger/sourceutils.cpp @@ -30,6 +30,9 @@ #include "sourceutils.h" +#include "debuggerinternalconstants.h" +#include "debuggerengine.h" +#include "disassemblerlines.h" #include "watchdata.h" #include "watchutils.h" @@ -333,5 +336,19 @@ QString fixCppExpression(const QString &expIn) return removeObviousSideEffects(exp); } +ContextData getLocationContext(TextDocument *document, int lineNumber) +{ + ContextData data; + QTC_ASSERT(document, return data); + data.fileName = document->filePath().toString(); + if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) { + QString line = document->plainText().section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1); + data.address = DisassemblerLine::addressFromDisassemblyLine(line); + } else { + data.lineNumber = lineNumber; + } + return data; +} + } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/sourceutils.h b/src/plugins/debugger/sourceutils.h index 9d3d50be97e..862ecfc9eb2 100644 --- a/src/plugins/debugger/sourceutils.h +++ b/src/plugins/debugger/sourceutils.h @@ -33,12 +33,18 @@ #include -namespace TextEditor { class TextEditorWidget; } +namespace TextEditor { +class TextDocument; +class TextEditorWidget; +} + namespace CPlusPlus { class Snapshot; } namespace Debugger { namespace Internal { +class ContextData; + // Editor tooltip support QString cppExpressionAt(TextEditor::TextEditorWidget *editorWidget, int pos, int *line, int *column, QString *function = 0, @@ -53,6 +59,8 @@ bool getUninitializedVariables(const CPlusPlus::Snapshot &snapshot, const QString &function, const QString &file, int line, QStringList *uninitializedVariables); +ContextData getLocationContext(TextEditor::TextDocument *document, int lineNumber); + } // namespace Internal } // namespace Debugger