Commit d765cd73 authored by hjk's avatar hjk

Debugger: Recognize source data within disassembler view

... and use it to toggle breakpoints by file and line,
and for jumping to file and line.

Task-number: QTCREATORBUG-14278
Change-Id: I799d085eb53339905ea3608022aeae5a9aef1fda
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent e3c2236c
......@@ -150,8 +150,11 @@ bool LocationMark::isDraggable() const
void LocationMark::dragToLine(int line)
{
if (m_engine) {
if (BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor())
m_engine->executeJumpToLine(getLocationContext(textEditor->textDocument(), line));
if (BaseTextEditor *textEditor = BaseTextEditor::currentTextEditor()) {
ContextData location = getLocationContext(textEditor->textDocument(), line);
if (location.isValid())
m_engine->executeJumpToLine(location);
}
}
}
......
......@@ -170,15 +170,18 @@ private:
quint64 m_address;
};
enum LocationType { UnknownLocation, LocationByFile, LocationByAddress };
class ContextData
{
public:
ContextData() : lineNumber(0), address(0) {}
bool isValid() const { return type != UnknownLocation; }
public:
LocationType type = UnknownLocation;
QString fileName;
int lineNumber;
quint64 address;
int lineNumber = 0;
quint64 address = 0;
};
class DebuggerEngine : public QObject
......
......@@ -47,6 +47,7 @@ namespace Internal {
const char OPENED_BY_DEBUGGER[] = "OpenedByDebugger";
const char OPENED_WITH_DISASSEMBLY[] = "DisassemblerView";
const char DISASSEMBLER_SOURCE_FILE[] = "DisassemblerSourceFile";
// Debug action
const char DEBUG[] = "Debugger.Debug";
......
This diff is collapsed.
......@@ -38,6 +38,7 @@
#include "debuggerstartparameters.h"
#include "debuggerstringutils.h"
#include "disassemblerlines.h"
#include "sourceutils.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
......@@ -292,10 +293,13 @@ void DisassemblerAgent::setContentsToDocument(const DisassemblerLines &contents)
widget->setReadOnly(true);
widget->setRequestMarkEnabled(true);
}
// FIXME: This is accumulating quite a bit out-of-band data.
// Make that a proper TextDocument reimplementation.
d->document = qobject_cast<TextDocument *>(editor->document());
QTC_ASSERT(d->document, return);
d->document->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
d->document->setProperty(Debugger::Constants::OPENED_WITH_DISASSEMBLY, true);
d->document->setProperty(Debugger::Constants::DISASSEMBLER_SOURCE_FILE, d->location.fileName());
d->configureMimeType();
} else {
EditorManager::activateEditorForDocument(d->document);
......@@ -345,9 +349,19 @@ void DisassemblerAgent::updateBreakpointMarkers()
const quint64 address = bp.response().address;
if (!address)
continue;
const int lineNumber = contents.lineForAddress(address);
int lineNumber = contents.lineForAddress(address);
if (!lineNumber)
continue;
// HACK: If it's a FileAndLine breakpoint, and there's a source line
// above, move the marker up there. That allows setting and removing
// normal breakpoints from within the disassembler view.
if (bp.type() == BreakpointByFileAndLine) {
ContextData context = getLocationContext(d->document, lineNumber - 1);
if (context.type == LocationByFile)
--lineNumber;
}
TextMark *marker = new TextMark(QString(), lineNumber,
Constants::TEXT_MARK_CATEGORY_BREAKPOINT);
marker->setIcon(bp.icon());
......
......@@ -29,7 +29,9 @@
****************************************************************************/
#include "disassemblerlines.h"
#include "debuggerengine.h"
#include "debuggerstringutils.h"
#include "sourceutils.h"
#include <QDebug>
#include <QFile>
......@@ -72,13 +74,6 @@ void DisassemblerLine::fromString(const QString &unparsed)
data = unparsed;
}
quint64 DisassemblerLine::addressFromDisassemblyLine(const QString &line)
{
DisassemblerLine l;
l.fromString(line);
return l.address;
}
quint64 DisassemblerLines::startAddress() const
{
for (int i = 0; i < m_data.size(); ++i)
......
......@@ -53,9 +53,6 @@ public:
QString toString(int maxOp = 0) const;
void fromString(const QString &unparsed);
// Return address of an assembly line "0x0dfd bla".
static quint64 addressFromDisassemblyLine(const QString &line);
public:
quint64 address; // (ass) Address of instruction in memory/in binary.
QString function; // (ass) Function to which current instruction belongs.
......
......@@ -48,6 +48,8 @@
#include <utils/qtcassert.h>
#include <QDebug>
#include <QTextDocument>
#include <QTextBlock>
#include <string.h>
#include <ctype.h>
......@@ -340,11 +342,29 @@ 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);
QString line = document->document()->findBlockByNumber(lineNumber - 1).text();
DisassemblerLine l;
l.fromString(line);
if (l.address) {
data.type = LocationByAddress;
data.address = l.address;
} else {
QString fileName = document->property(Constants::DISASSEMBLER_SOURCE_FILE).toString();
if (!fileName.isEmpty()) {
// Possibly one of the "27 [1] foo = x" lines
int pos = line.indexOf(QLatin1Char('['));
int ln = line.left(pos - 1).toInt();
if (ln > 0) {
data.type = LocationByFile;
data.fileName = fileName;
data.lineNumber = ln;
}
}
}
} else {
data.type = LocationByFile;
data.fileName = document->filePath().toString();
data.lineNumber = lineNumber;
}
return data;
......
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