Commit db80d20f authored by hjk's avatar hjk

Debugger: Restrict LocationMark dragging

... to engines that actually support JumpToLine and make it
work in disassembler views.

Change-Id: I10368ea719587caa7c4f33665eff57c2bf300d84
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent ff63fd11
......@@ -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<DebuggerEngine> 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();
}
......
......@@ -36,6 +36,7 @@
#include "debuggerstartparameters.h"
#include <projectexplorer/devicesupport/idevice.h>
#include <texteditor/textmark.h>
#include <QObject>
#include <QProcess>
......@@ -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<DebuggerEngine> m_engine;
};
DebuggerEngine *createEngine(DebuggerEngineType et, const DebuggerRunParameters &rp, QStringList *errors);
DebuggerRunControl *createAndScheduleRun(const DebuggerRunParameters &rp, const ProjectExplorer::Kit *kit);
......
......@@ -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()
......
......@@ -98,7 +98,7 @@ typedef QPair<FrameKey, DisassemblerLines> CacheEntry;
class DisassemblerAgentPrivate
{
public:
DisassemblerAgentPrivate();
DisassemblerAgentPrivate(DebuggerEngine *engine);
~DisassemblerAgentPrivate();
void configureMimeType();
DisassemblerLines contentsAtCurrentLocation() const;
......@@ -107,22 +107,20 @@ public:
QPointer<TextDocument> document;
Location location;
QPointer<DebuggerEngine> engine;
TextMark locationMark;
LocationMark locationMark;
QList<TextMark *> breakpointMarks;
QList<CacheEntry> 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()
{
......
......@@ -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
......@@ -33,12 +33,18 @@
#include <QString>
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment