Commit 85482ff5 authored by hjk's avatar hjk Committed by hjk

debugger: fix off-by-one location marker on last instruction in a function

Change-Id: Iecdce6e3935cc002ab2c6c6e346f879db1898a6d
Reviewed-on: http://codereview.qt.nokia.com/4121Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent cd2d9361
......@@ -67,7 +67,7 @@ namespace Internal {
///////////////////////////////////////////////////////////////////////
//
// DisassemblerAgent
// FrameKey
//
///////////////////////////////////////////////////////////////////////
......@@ -86,38 +86,45 @@ public:
bool FrameKey::matches(const Location &loc) const
{
return loc.address() >= startAddress
&& loc.address() < endAddress
&& loc.fileName() == fileName && loc.functionName() == functionName;
&& loc.address() <= endAddress
&& loc.fileName() == fileName
&& loc.functionName() == functionName;
}
typedef QPair<FrameKey, DisassemblerLines> CacheEntry;
///////////////////////////////////////////////////////////////////////
//
// DisassemblerAgentPrivate
//
///////////////////////////////////////////////////////////////////////
class DisassemblerAgentPrivate
{
public:
DisassemblerAgentPrivate();
~DisassemblerAgentPrivate();
void configureMimeType();
DisassemblerLines contentsAtCurrentLocation() const;
public:
QPointer<TextEditor::ITextEditor> editor;
Location location;
bool tryMixed;
QPointer<DebuggerEngine> engine;
ITextMark *locationMark;
QList<ITextMark *> breakpointMarks;
QList<CacheEntry> cache;
QString mimeType;
bool m_resetLocationScheduled;
bool tryMixed;
bool resetLocationScheduled;
};
DisassemblerAgentPrivate::DisassemblerAgentPrivate()
: editor(0),
tryMixed(true),
mimeType(_("text/x-qtcreator-generic-asm")),
m_resetLocationScheduled(false)
tryMixed(true),
resetLocationScheduled(false)
{
locationMark = new ITextMark;
locationMark->setIcon(debuggerCore()->locationMarkIcon());
......@@ -134,6 +141,23 @@ DisassemblerAgentPrivate::~DisassemblerAgentPrivate()
delete locationMark;
}
DisassemblerLines DisassemblerAgentPrivate::contentsAtCurrentLocation() const
{
for (int i = 0, n = cache.size(); i != n; ++i) {
const CacheEntry &entry = cache.at(i);
if (entry.first.matches(location))
return entry.second;
}
return DisassemblerLines();
}
///////////////////////////////////////////////////////////////////////
//
// DisassemblerAgent
//
///////////////////////////////////////////////////////////////////////
/*!
\class Debugger::Internal::DisassemblerAgent
......@@ -169,15 +193,15 @@ void DisassemblerAgent::cleanup()
void DisassemblerAgent::scheduleResetLocation()
{
d->m_resetLocationScheduled = true;
d->resetLocationScheduled = true;
}
void DisassemblerAgent::resetLocation()
{
if (!d->editor)
return;
if (d->m_resetLocationScheduled) {
d->m_resetLocationScheduled = false;
if (d->resetLocationScheduled) {
d->resetLocationScheduled = false;
d->editor->markableInterface()->removeMark(d->locationMark);
}
}
......@@ -216,7 +240,7 @@ void DisassemblerAgent::setLocation(const Location &loc)
.arg(loc.functionName(), QDir::toNativeSeparators(loc.fileName()));
d->engine->showMessage(msg);
setContentsToEditor(d->cache.at(index).second);
d->m_resetLocationScheduled = false; // In case reset from previous run still pending.
d->resetLocationScheduled = false; // In case reset from previous run still pending.
} else {
d->engine->fetchDisassembler(this);
}
......@@ -322,10 +346,7 @@ void DisassemblerAgent::setContentsToEditor(const DisassemblerLines &contents)
void DisassemblerAgent::updateLocationMarker()
{
QTC_ASSERT(d->editor, return);
const int index = indexOf(d->location);
const DisassemblerLines contents = index != -1 ?
d->cache.at(index).second : DisassemblerLines();
const DisassemblerLines contents = d->contentsAtCurrentLocation();
int lineNumber = contents.lineForAddress(d->location.address());
if (d->location.needsMarker()) {
d->editor->markableInterface()->removeMark(d->locationMark);
......@@ -353,9 +374,7 @@ void DisassemblerAgent::updateBreakpointMarkers()
if (ids.isEmpty())
return;
const int index = indexOf(d->location);
const DisassemblerLines contents = index != -1 ?
d->cache.at(index).second : DisassemblerLines();
const DisassemblerLines contents = d->contentsAtCurrentLocation();
foreach (TextEditor::ITextMark *marker, d->breakpointMarks)
d->editor->markableInterface()->removeMark(marker);
d->breakpointMarks.clear();
......
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