2009-08-12 10:51:25 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-08-12 10:51:25 +02:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2009-08-12 10:51:25 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "debuggeragents.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
|
|
|
|
|
#include "debuggerengine.h"
|
|
|
|
|
#include "debuggerplugin.h"
|
2009-09-25 15:02:16 +02:00
|
|
|
#include "debuggerstringutils.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
#include "stackframe.h"
|
2010-10-25 13:37:46 +02:00
|
|
|
#include "debuggerconstants.h"
|
2009-08-12 10:51:25 +02:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-08-12 10:51:25 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-08-14 13:04:05 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2010-06-22 14:06:42 +02:00
|
|
|
#include <coreplugin/mimedatabase.h>
|
2009-08-14 13:04:05 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <texteditor/basetexteditor.h>
|
2010-06-22 14:06:42 +02:00
|
|
|
#include <texteditor/plaintexteditor.h>
|
2009-08-14 13:04:05 +02:00
|
|
|
#include <texteditor/basetextmark.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
2010-06-22 14:06:42 +02:00
|
|
|
#include <texteditor/basetextdocument.h>
|
2009-08-14 13:04:05 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2009-10-02 11:45:19 +02:00
|
|
|
#include <QtCore/QDebug>
|
2010-07-07 10:30:34 +02:00
|
|
|
#include <QtCore/QMetaObject>
|
2009-11-19 09:51:21 +01:00
|
|
|
|
|
|
|
|
#include <QtGui/QMessageBox>
|
2009-08-14 13:04:05 +02:00
|
|
|
#include <QtGui/QPlainTextEdit>
|
|
|
|
|
#include <QtGui/QTextCursor>
|
2010-10-29 15:20:10 +02:00
|
|
|
#include <QtGui/QIcon>
|
2009-08-12 10:51:25 +02:00
|
|
|
|
2009-08-12 15:11:05 +02:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
2010-09-09 17:58:26 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
|
2009-08-12 10:51:25 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// MemoryViewAgent
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-09-08 11:59:21 +02:00
|
|
|
/*!
|
2009-08-14 13:04:05 +02:00
|
|
|
\class MemoryViewAgent
|
|
|
|
|
|
|
|
|
|
Objects form this class are created in response to user actions in
|
|
|
|
|
the Gui for showing raw memory from the inferior. After creation
|
|
|
|
|
it handles communication between the engine and the bineditor.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-07 10:30:34 +02:00
|
|
|
namespace { const int DataRange = 1024 * 1024; }
|
|
|
|
|
|
2010-09-13 13:30:35 +02:00
|
|
|
MemoryViewAgent::MemoryViewAgent(Debugger::DebuggerEngine *engine, quint64 addr)
|
2010-06-16 11:08:54 +02:00
|
|
|
: QObject(engine), m_engine(engine)
|
2009-08-14 13:04:05 +02:00
|
|
|
{
|
2010-06-16 11:08:54 +02:00
|
|
|
QTC_ASSERT(engine, /**/);
|
2010-02-17 17:33:42 +01:00
|
|
|
createBinEditor(addr);
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-13 13:30:35 +02:00
|
|
|
MemoryViewAgent::MemoryViewAgent(Debugger::DebuggerEngine *engine, const QString &addr)
|
2010-06-16 11:08:54 +02:00
|
|
|
: QObject(engine), m_engine(engine)
|
2009-08-14 13:04:05 +02:00
|
|
|
{
|
2010-06-16 11:08:54 +02:00
|
|
|
QTC_ASSERT(engine, /**/);
|
2009-08-14 13:04:05 +02:00
|
|
|
bool ok = true;
|
2010-02-17 17:33:42 +01:00
|
|
|
createBinEditor(addr.toULongLong(&ok, 0));
|
2009-08-18 08:34:48 +02:00
|
|
|
//qDebug() << " ADDRESS: " << addr << addr.toUInt(&ok, 0);
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryViewAgent::~MemoryViewAgent()
|
|
|
|
|
{
|
2010-09-09 17:58:26 +02:00
|
|
|
EditorManager *editorManager = EditorManager::instance();
|
|
|
|
|
QList<IEditor *> editors;
|
|
|
|
|
foreach (QPointer<IEditor> editor, m_editors)
|
2010-02-17 17:33:42 +01:00
|
|
|
if (editor)
|
2010-07-23 17:22:44 +02:00
|
|
|
editors.append(editor.data());
|
|
|
|
|
editorManager->closeEditors(editors);
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-17 17:33:42 +01:00
|
|
|
void MemoryViewAgent::createBinEditor(quint64 addr)
|
2009-08-12 10:51:25 +02:00
|
|
|
{
|
2010-09-09 17:58:26 +02:00
|
|
|
EditorManager *editorManager = EditorManager::instance();
|
2009-08-19 14:41:51 +02:00
|
|
|
QString titlePattern = tr("Memory $");
|
2010-09-09 17:58:26 +02:00
|
|
|
IEditor *editor = editorManager->openEditorWithContents(
|
2010-01-07 18:17:24 +01:00
|
|
|
Core::Constants::K_DEFAULT_BINARY_EDITOR_ID,
|
2009-08-12 10:51:25 +02:00
|
|
|
&titlePattern);
|
2010-02-17 17:33:42 +01:00
|
|
|
if (editor) {
|
2010-07-02 12:17:08 +02:00
|
|
|
connect(editor->widget(),
|
2010-09-09 17:58:26 +02:00
|
|
|
SIGNAL(lazyDataRequested(Core::IEditor *, quint64,bool)),
|
|
|
|
|
SLOT(fetchLazyData(Core::IEditor *, quint64,bool)));
|
|
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(newWindowRequested(quint64)),
|
|
|
|
|
SLOT(createBinEditor(quint64)));
|
|
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(newRangeRequested(Core::IEditor *, quint64)),
|
2010-07-02 12:17:08 +02:00
|
|
|
SLOT(provideNewRange(Core::IEditor*,quint64)));
|
2010-09-09 17:58:26 +02:00
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(startOfFileRequested(Core::IEditor *)),
|
|
|
|
|
SLOT(handleStartOfFileRequested(Core::IEditor*)));
|
|
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(endOfFileRequested(Core::IEditor *)),
|
|
|
|
|
SLOT(handleEndOfFileRequested(Core::IEditor*)));
|
2010-02-17 17:33:42 +01:00
|
|
|
m_editors << editor;
|
2010-09-14 15:15:57 +02:00
|
|
|
editorManager->activateEditor(editor);
|
2010-02-17 17:33:42 +01:00
|
|
|
QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed");
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
|
2010-07-07 10:30:34 +02:00
|
|
|
Q_ARG(quint64, addr), Q_ARG(int, DataRange), Q_ARG(int, BinBlockSize));
|
2009-11-19 09:51:21 +01:00
|
|
|
} else {
|
2010-07-21 14:24:29 +02:00
|
|
|
DebuggerEngine::showMessageBox(QMessageBox::Warning,
|
2009-11-19 09:51:21 +01:00
|
|
|
tr("No memory viewer available"),
|
2009-12-04 12:18:47 +01:00
|
|
|
tr("The memory contents cannot be shown as no viewer plugin "
|
2010-01-08 11:31:38 +01:00
|
|
|
"for binary data has been loaded."));
|
2009-11-19 09:51:21 +01:00
|
|
|
deleteLater();
|
|
|
|
|
}
|
2009-08-12 10:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-09 17:58:26 +02:00
|
|
|
void MemoryViewAgent::fetchLazyData(IEditor *editor, quint64 block, bool sync)
|
2009-08-12 10:51:25 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(sync); // FIXME: needed support for incremental searching
|
2010-06-16 11:08:54 +02:00
|
|
|
m_engine->fetchMemory(this, editor, BinBlockSize * block, BinBlockSize);
|
2009-08-12 10:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-17 17:33:42 +01:00
|
|
|
void MemoryViewAgent::addLazyData(QObject *editorToken, quint64 addr,
|
|
|
|
|
const QByteArray &ba)
|
2009-08-12 10:51:25 +02:00
|
|
|
{
|
2010-09-09 17:58:26 +02:00
|
|
|
IEditor *editor = qobject_cast<IEditor *>(editorToken);
|
2010-02-17 17:33:42 +01:00
|
|
|
if (editor && editor->widget()) {
|
2010-09-14 15:15:57 +02:00
|
|
|
Core::EditorManager::instance()->activateEditor(editor);
|
2010-02-17 17:33:42 +01:00
|
|
|
QMetaObject::invokeMethod(editor->widget(), "addLazyData",
|
2009-09-17 08:59:35 +02:00
|
|
|
Q_ARG(quint64, addr / BinBlockSize), Q_ARG(QByteArray, ba));
|
2010-02-17 17:33:42 +01:00
|
|
|
}
|
2009-08-12 10:51:25 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-09 17:58:26 +02:00
|
|
|
void MemoryViewAgent::provideNewRange(IEditor *editor, quint64 address)
|
2010-07-02 12:17:08 +02:00
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
|
2010-07-07 10:30:34 +02:00
|
|
|
Q_ARG(quint64, address), Q_ARG(int, DataRange),
|
2010-07-02 12:17:08 +02:00
|
|
|
Q_ARG(int, BinBlockSize));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-07 10:30:34 +02:00
|
|
|
// Since we are not dealing with files, we take these signals to mean
|
|
|
|
|
// "move to start/end of range". This seems to make more sense than
|
|
|
|
|
// jumping to the start or end of the address space, respectively.
|
2010-09-09 17:58:26 +02:00
|
|
|
void MemoryViewAgent::handleStartOfFileRequested(IEditor *editor)
|
2010-07-07 10:30:34 +02:00
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(),
|
|
|
|
|
"setCursorPosition", Q_ARG(int, 0));
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 17:58:26 +02:00
|
|
|
void MemoryViewAgent::handleEndOfFileRequested(IEditor *editor)
|
2010-07-07 10:30:34 +02:00
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(),
|
|
|
|
|
"setCursorPosition", Q_ARG(int, DataRange - 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-08-12 10:51:25 +02:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// DisassemblerViewAgent
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// Used for the disassembler view
|
|
|
|
|
class LocationMark2 : public TextEditor::ITextMark
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LocationMark2() {}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
QIcon icon() const { return DebuggerPlugin::instance()->locationMarkIcon(); }
|
2009-08-14 13:04:05 +02:00
|
|
|
void updateLineNumber(int /*lineNumber*/) {}
|
|
|
|
|
void updateBlock(const QTextBlock & /*block*/) {}
|
|
|
|
|
void removedFromEditor() {}
|
|
|
|
|
void documentClosing() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DisassemblerViewAgentPrivate
|
|
|
|
|
{
|
2010-06-22 14:06:42 +02:00
|
|
|
DisassemblerViewAgentPrivate();
|
|
|
|
|
void configureMimeType();
|
2010-02-01 16:14:57 +01:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
QPointer<TextEditor::ITextEditor> editor;
|
2009-09-29 16:17:01 +02:00
|
|
|
StackFrame frame;
|
2010-02-01 16:14:57 +01:00
|
|
|
bool tryMixed;
|
2010-06-16 11:08:54 +02:00
|
|
|
QPointer<DebuggerEngine> engine;
|
2009-08-14 13:04:05 +02:00
|
|
|
LocationMark2 *locationMark;
|
2009-09-29 16:17:01 +02:00
|
|
|
QHash<QString, QString> cache;
|
2010-06-22 14:06:42 +02:00
|
|
|
QString mimeType;
|
2009-08-14 13:04:05 +02:00
|
|
|
};
|
|
|
|
|
|
2010-06-22 14:06:42 +02:00
|
|
|
DisassemblerViewAgentPrivate::DisassemblerViewAgentPrivate() :
|
|
|
|
|
editor(0),
|
|
|
|
|
tryMixed(true),
|
|
|
|
|
locationMark(new LocationMark2),
|
|
|
|
|
mimeType(_("text/x-qtcreator-generic-asm"))
|
2009-08-18 11:23:01 +02:00
|
|
|
{
|
2010-06-22 14:06:42 +02:00
|
|
|
}
|
2009-08-18 11:23:01 +02:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
/*!
|
|
|
|
|
\class DisassemblerViewAgent
|
|
|
|
|
|
|
|
|
|
Objects from this class are created in response to user actions in
|
|
|
|
|
the Gui for showing disassembled memory from the inferior. After creation
|
|
|
|
|
it handles communication between the engine and the editor.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
DisassemblerViewAgent::DisassemblerViewAgent(DebuggerEngine *engine)
|
2009-10-06 09:22:57 +02:00
|
|
|
: QObject(0), d(new DisassemblerViewAgentPrivate)
|
2009-08-14 13:04:05 +02:00
|
|
|
{
|
2010-06-16 11:08:54 +02:00
|
|
|
d->engine = engine;
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DisassemblerViewAgent::~DisassemblerViewAgent()
|
|
|
|
|
{
|
2010-09-09 17:58:26 +02:00
|
|
|
EditorManager *editorManager = EditorManager::instance();
|
2009-08-14 13:04:05 +02:00
|
|
|
if (d->editor)
|
2010-09-09 17:58:26 +02:00
|
|
|
editorManager->closeEditors(QList<IEditor *>() << d->editor);
|
2009-09-29 16:17:01 +02:00
|
|
|
d->editor = 0;
|
2009-11-04 17:11:35 +01:00
|
|
|
delete d->locationMark;
|
|
|
|
|
d->locationMark = 0;
|
2009-08-14 13:04:05 +02:00
|
|
|
delete d;
|
2009-09-28 09:41:07 +02:00
|
|
|
d = 0;
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-29 16:17:01 +02:00
|
|
|
void DisassemblerViewAgent::cleanup()
|
|
|
|
|
{
|
|
|
|
|
d->cache.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 16:23:26 +02:00
|
|
|
void DisassemblerViewAgent::resetLocation()
|
|
|
|
|
{
|
|
|
|
|
if (d->editor)
|
|
|
|
|
d->editor->markableInterface()->removeMark(d->locationMark);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 11:45:19 +02:00
|
|
|
QString frameKey(const StackFrame &frame)
|
|
|
|
|
{
|
|
|
|
|
return _("%1:%2:%3").arg(frame.function).arg(frame.file).arg(frame.from);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-01 16:14:57 +01:00
|
|
|
const StackFrame &DisassemblerViewAgent::frame() const
|
|
|
|
|
{
|
|
|
|
|
return d->frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DisassemblerViewAgent::isMixed() const
|
|
|
|
|
{
|
|
|
|
|
return d->tryMixed
|
|
|
|
|
&& d->frame.line > 0
|
|
|
|
|
&& !d->frame.function.isEmpty()
|
|
|
|
|
&& d->frame.function != _("??");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DisassemblerViewAgent::setFrame(const StackFrame &frame, bool tryMixed)
|
2009-08-14 13:04:05 +02:00
|
|
|
{
|
2009-09-29 16:17:01 +02:00
|
|
|
d->frame = frame;
|
2010-02-01 16:14:57 +01:00
|
|
|
d->tryMixed = tryMixed;
|
|
|
|
|
if (isMixed()) {
|
2009-10-02 11:45:19 +02:00
|
|
|
QHash<QString, QString>::ConstIterator it = d->cache.find(frameKey(frame));
|
2009-09-29 16:17:01 +02:00
|
|
|
if (it != d->cache.end()) {
|
2010-01-11 10:22:55 +01:00
|
|
|
QString msg = _("Use cache disassembler for '%1' in '%2'")
|
2009-10-02 11:45:19 +02:00
|
|
|
.arg(frame.function).arg(frame.file);
|
2010-06-16 11:08:54 +02:00
|
|
|
d->engine->showMessage(msg);
|
2009-09-29 16:17:01 +02:00
|
|
|
setContents(*it);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
d->engine->fetchDisassembler(this);
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-22 14:06:42 +02:00
|
|
|
void DisassemblerViewAgentPrivate::configureMimeType()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(editor, return);
|
|
|
|
|
|
|
|
|
|
TextEditor::BaseTextDocument *doc = qobject_cast<TextEditor::BaseTextDocument *>(editor->file());
|
|
|
|
|
QTC_ASSERT(doc, return);
|
|
|
|
|
doc->setMimeType(mimeType);
|
|
|
|
|
|
|
|
|
|
TextEditor::PlainTextEditor *pe = qobject_cast<TextEditor::PlainTextEditor *>(editor->widget());
|
|
|
|
|
QTC_ASSERT(pe, return);
|
|
|
|
|
|
2010-09-09 17:58:26 +02:00
|
|
|
if (const MimeType mtype = ICore::instance()->mimeDatabase()->findByType(mimeType)) {
|
2010-06-22 14:06:42 +02:00
|
|
|
pe->configure(mtype);
|
|
|
|
|
} else {
|
|
|
|
|
qWarning("Assembler mimetype '%s' not found.", qPrintable(mimeType));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DisassemblerViewAgent::mimeType() const
|
|
|
|
|
{
|
|
|
|
|
return d->mimeType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DisassemblerViewAgent::setMimeType(const QString &mt)
|
|
|
|
|
{
|
|
|
|
|
if (mt == d->mimeType)
|
|
|
|
|
return;
|
|
|
|
|
d->mimeType = mt;
|
|
|
|
|
if (d->editor)
|
|
|
|
|
d->configureMimeType();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-21 15:12:33 +02:00
|
|
|
// Return a pair of <linenumber [1..n], character position> of an address
|
|
|
|
|
// in assembly code, assuming lines start with a sane hex address.
|
|
|
|
|
static QPair<int, int> lineNumberOfAddress(const QString &disassembly, quint64 address)
|
|
|
|
|
{
|
|
|
|
|
if (disassembly.isEmpty())
|
|
|
|
|
return QPair<int, int>(-1, -1);
|
|
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
|
const QChar newLine = QLatin1Char('\n');
|
|
|
|
|
|
|
|
|
|
const int size = disassembly.size();
|
|
|
|
|
for (int lineNumber = 1; pos < size; lineNumber++) {
|
|
|
|
|
int endOfLinePos = disassembly.indexOf(newLine, pos + 1);
|
|
|
|
|
if (endOfLinePos == -1)
|
|
|
|
|
endOfLinePos = size;
|
|
|
|
|
const QString line = disassembly.mid(pos, endOfLinePos - pos);
|
|
|
|
|
if (DisassemblerViewAgent::addressFromDisassemblyLine(line) == address)
|
|
|
|
|
return QPair<int, int>(lineNumber, pos);
|
2010-10-27 16:27:12 +02:00
|
|
|
pos = endOfLinePos + 1;
|
2010-09-21 15:12:33 +02:00
|
|
|
}
|
|
|
|
|
return QPair<int, int>(-1, -1);;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
void DisassemblerViewAgent::setContents(const QString &contents)
|
|
|
|
|
{
|
2009-09-28 09:41:07 +02:00
|
|
|
QTC_ASSERT(d, return);
|
2009-08-14 13:04:05 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
2009-10-02 11:45:19 +02:00
|
|
|
d->cache.insert(frameKey(d->frame), contents);
|
2009-08-18 11:23:01 +02:00
|
|
|
QPlainTextEdit *plainTextEdit = 0;
|
2009-08-14 13:04:05 +02:00
|
|
|
EditorManager *editorManager = EditorManager::instance();
|
|
|
|
|
if (!d->editor) {
|
|
|
|
|
QString titlePattern = "Disassembler";
|
|
|
|
|
d->editor = qobject_cast<ITextEditor *>(
|
|
|
|
|
editorManager->openEditorWithContents(
|
2010-01-07 18:17:24 +01:00
|
|
|
Core::Constants::K_DEFAULT_TEXT_EDITOR_ID,
|
2009-08-18 17:27:30 +02:00
|
|
|
&titlePattern));
|
2010-06-22 14:06:42 +02:00
|
|
|
QTC_ASSERT(d->editor, return);
|
2010-10-25 13:37:46 +02:00
|
|
|
d->editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
|
|
|
|
|
d->editor->setProperty(Debugger::Constants::OPENED_WITH_DISASSEMBLY, true);
|
2010-06-22 14:06:42 +02:00
|
|
|
d->configureMimeType();
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-14 15:15:57 +02:00
|
|
|
editorManager->activateEditor(d->editor);
|
2009-08-14 13:04:05 +02:00
|
|
|
|
2009-08-18 11:23:01 +02:00
|
|
|
plainTextEdit = qobject_cast<QPlainTextEdit *>(d->editor->widget());
|
2010-06-22 14:06:42 +02:00
|
|
|
if (plainTextEdit) {
|
2009-08-14 13:04:05 +02:00
|
|
|
plainTextEdit->setPlainText(contents);
|
2010-06-22 14:06:42 +02:00
|
|
|
plainTextEdit->setReadOnly(true);
|
|
|
|
|
}
|
2009-08-14 13:04:05 +02:00
|
|
|
|
|
|
|
|
d->editor->markableInterface()->removeMark(d->locationMark);
|
2009-09-29 16:17:01 +02:00
|
|
|
d->editor->setDisplayName(_("Disassembler (%1)").arg(d->frame.function));
|
2009-08-14 13:04:05 +02:00
|
|
|
|
2010-09-21 15:12:33 +02:00
|
|
|
const QPair<int, int> lineNumberPos = lineNumberOfAddress(contents, d->frame.address);
|
|
|
|
|
if (lineNumberPos.first > 0) {
|
|
|
|
|
d->editor->markableInterface()->addMark(d->locationMark, lineNumberPos.first);
|
|
|
|
|
if (plainTextEdit) {
|
|
|
|
|
QTextCursor tc = plainTextEdit->textCursor();
|
|
|
|
|
tc.setPosition(lineNumberPos.second);
|
|
|
|
|
plainTextEdit->setTextCursor(tc);
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 11:45:19 +02:00
|
|
|
bool DisassemblerViewAgent::contentsCoversAddress(const QString &contents) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d, return false);
|
2010-09-21 15:12:33 +02:00
|
|
|
|
|
|
|
|
return lineNumberOfAddress(contents, d->frame.address).first > 0;
|
2009-10-02 11:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-21 15:12:33 +02:00
|
|
|
quint64 DisassemblerViewAgent::address() const
|
2009-08-14 13:04:05 +02:00
|
|
|
{
|
2009-09-29 16:17:01 +02:00
|
|
|
return d->frame.address;
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-21 14:26:45 +02:00
|
|
|
// Return address of an assembly line "0x0dfd bla"
|
|
|
|
|
quint64 DisassemblerViewAgent::addressFromDisassemblyLine(const QString &line)
|
|
|
|
|
{
|
2010-10-27 15:39:42 +02:00
|
|
|
// Mac gdb has an overflow reporting 64bit addresses causing the instruction
|
|
|
|
|
// to follow the last digit "0x000000013fff4810mov 1,1". Truncate here.
|
|
|
|
|
const int pos = qMin(line.indexOf(QLatin1Char(' ')), 19);
|
2010-09-21 14:26:45 +02:00
|
|
|
if (pos < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
QString addressS = line.left(pos);
|
2010-11-08 16:03:59 +01:00
|
|
|
if (addressS.endsWith(':')) // clang
|
|
|
|
|
addressS.chop(1);
|
2010-09-21 14:26:45 +02:00
|
|
|
if (addressS.startsWith(QLatin1String("0x")))
|
|
|
|
|
addressS.remove(0, 2);
|
|
|
|
|
bool ok;
|
|
|
|
|
const quint64 address = addressS.toULongLong(&ok, 16);
|
|
|
|
|
return ok ? address : quint64(0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-12 10:51:25 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|