2010-12-08 12:43:11 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-12-08 12:43:11 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-12-08 12:43:11 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-12-08 12:43:11 +01:00
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-12-08 12:43:11 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "memoryagent.h"
|
|
|
|
|
|
|
|
|
|
#include "debuggerengine.h"
|
2011-04-08 16:18:47 +02:00
|
|
|
#include "debuggerstartparameters.h"
|
2010-12-08 12:43:11 +01:00
|
|
|
#include "debuggercore.h"
|
2011-04-08 16:18:47 +02:00
|
|
|
#include "memoryviewwidget.h"
|
2010-12-08 12:43:11 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QMessageBox>
|
2011-04-08 16:18:47 +02:00
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
2010-12-08 12:43:11 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2010-12-14 12:29:32 +01:00
|
|
|
// MemoryAgent
|
2010-12-08 12:43:11 +01:00
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/*!
|
2011-01-26 17:22:25 +01:00
|
|
|
\class Debugger::Internal::MemoryAgent
|
2010-12-08 12:43:11 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace { const int DataRange = 1024 * 1024; }
|
|
|
|
|
|
2011-02-25 14:57:21 +01:00
|
|
|
MemoryAgent::MemoryAgent(DebuggerEngine *engine)
|
2010-12-08 12:43:11 +01:00
|
|
|
: QObject(engine), m_engine(engine)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(engine, /**/);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
MemoryAgent::~MemoryAgent()
|
2010-12-08 12:43:11 +01:00
|
|
|
{
|
|
|
|
|
QList<IEditor *> editors;
|
|
|
|
|
foreach (QPointer<IEditor> editor, m_editors)
|
|
|
|
|
if (editor)
|
|
|
|
|
editors.append(editor.data());
|
2010-12-13 18:17:31 +01:00
|
|
|
EditorManager::instance()->closeEditors(editors);
|
2010-12-08 12:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-08 16:18:47 +02:00
|
|
|
void MemoryAgent::openMemoryView(quint64 address, quint64 length, const QPoint &pos)
|
|
|
|
|
{
|
|
|
|
|
MemoryViewWidget *w = new MemoryViewWidget(Core::ICore::instance()->mainWindow());
|
|
|
|
|
w->setUpdateOnInferiorStop(true);
|
|
|
|
|
w->move(pos);
|
|
|
|
|
w->requestMemory(address, length);
|
|
|
|
|
addMemoryView(w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemoryAgent::addMemoryView(MemoryViewWidget *w)
|
|
|
|
|
{
|
|
|
|
|
w->setAbi(m_engine->startParameters().toolChainAbi);
|
|
|
|
|
connect(w, SIGNAL(memoryRequested(quint64,quint64)),
|
|
|
|
|
this, SLOT(updateMemoryView(quint64,quint64)));
|
|
|
|
|
connect(m_engine, SIGNAL(stateChanged(Debugger::DebuggerState)),
|
|
|
|
|
w, SLOT(engineStateChanged(Debugger::DebuggerState)));
|
|
|
|
|
connect(w, SIGNAL(openViewRequested(quint64,quint64,QPoint)),
|
|
|
|
|
this, SLOT(openMemoryView(quint64,quint64,QPoint)));
|
|
|
|
|
w->requestMemory();
|
|
|
|
|
w->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemoryAgent::updateMemoryView(quint64 address, quint64 length)
|
|
|
|
|
{
|
|
|
|
|
m_engine->fetchMemory(this, sender(), address, length);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
void MemoryAgent::createBinEditor(quint64 addr)
|
2010-12-08 12:43:11 +01:00
|
|
|
{
|
|
|
|
|
EditorManager *editorManager = EditorManager::instance();
|
|
|
|
|
QString titlePattern = tr("Memory $");
|
|
|
|
|
IEditor *editor = editorManager->openEditorWithContents(
|
|
|
|
|
Core::Constants::K_DEFAULT_BINARY_EDITOR_ID,
|
|
|
|
|
&titlePattern);
|
|
|
|
|
if (editor) {
|
2011-02-25 13:21:54 +01:00
|
|
|
editor->setProperty(Constants::OPENED_BY_DEBUGGER, true);
|
|
|
|
|
editor->setProperty(Constants::OPENED_WITH_MEMORY, true);
|
2010-12-08 12:43:11 +01:00
|
|
|
connect(editor->widget(),
|
2011-02-28 15:01:19 +01:00
|
|
|
SIGNAL(dataRequested(Core::IEditor*,quint64)),
|
|
|
|
|
SLOT(fetchLazyData(Core::IEditor*,quint64)));
|
2010-12-08 12:43:11 +01:00
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(newWindowRequested(quint64)),
|
|
|
|
|
SLOT(createBinEditor(quint64)));
|
|
|
|
|
connect(editor->widget(),
|
2011-02-25 13:21:54 +01:00
|
|
|
SIGNAL(newRangeRequested(Core::IEditor*,quint64)),
|
2010-12-08 12:43:11 +01:00
|
|
|
SLOT(provideNewRange(Core::IEditor*,quint64)));
|
|
|
|
|
connect(editor->widget(),
|
2011-02-25 13:21:54 +01:00
|
|
|
SIGNAL(startOfFileRequested(Core::IEditor*)),
|
2010-12-08 12:43:11 +01:00
|
|
|
SLOT(handleStartOfFileRequested(Core::IEditor*)));
|
|
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(endOfFileRequested(Core::IEditor *)),
|
|
|
|
|
SLOT(handleEndOfFileRequested(Core::IEditor*)));
|
2011-02-25 13:21:54 +01:00
|
|
|
connect(editor->widget(),
|
|
|
|
|
SIGNAL(dataChanged(Core::IEditor*,quint64,QByteArray)),
|
|
|
|
|
SLOT(handleDataChanged(Core::IEditor*,quint64,QByteArray)));
|
2010-12-08 12:43:11 +01:00
|
|
|
m_editors << editor;
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed");
|
2011-02-24 09:17:21 +01:00
|
|
|
QMetaObject::invokeMethod(editor->widget(), "setSizes",
|
|
|
|
|
Q_ARG(quint64, addr),
|
|
|
|
|
Q_ARG(int, DataRange),
|
|
|
|
|
Q_ARG(int, BinBlockSize));
|
2011-02-25 13:21:54 +01:00
|
|
|
editorManager->activateEditor(editor);
|
2010-12-08 12:43:11 +01:00
|
|
|
} else {
|
|
|
|
|
showMessageBox(QMessageBox::Warning,
|
|
|
|
|
tr("No memory viewer available"),
|
|
|
|
|
tr("The memory contents cannot be shown as no viewer plugin "
|
|
|
|
|
"for binary data has been loaded."));
|
|
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-28 15:01:19 +01:00
|
|
|
void MemoryAgent::fetchLazyData(IEditor *editor, quint64 block)
|
2010-12-08 12:43:11 +01:00
|
|
|
{
|
|
|
|
|
m_engine->fetchMemory(this, editor, BinBlockSize * block, BinBlockSize);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
void MemoryAgent::addLazyData(QObject *editorToken, quint64 addr,
|
2010-12-08 12:43:11 +01:00
|
|
|
const QByteArray &ba)
|
|
|
|
|
{
|
2011-04-08 16:18:47 +02:00
|
|
|
|
|
|
|
|
if (IEditor *editor = qobject_cast<IEditor *>(editorToken)) {
|
|
|
|
|
if (QWidget *editorWidget = editor->widget()) {
|
|
|
|
|
QMetaObject::invokeMethod(editorWidget , "addData",
|
|
|
|
|
Q_ARG(quint64, addr / BinBlockSize), Q_ARG(QByteArray, ba));
|
|
|
|
|
}
|
|
|
|
|
return;
|
2010-12-08 12:43:11 +01:00
|
|
|
}
|
2011-04-08 16:18:47 +02:00
|
|
|
if (MemoryViewWidget *mvw = qobject_cast<MemoryViewWidget*>(editorToken))
|
|
|
|
|
mvw->setData(ba);
|
2010-12-08 12:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
void MemoryAgent::provideNewRange(IEditor *editor, quint64 address)
|
2010-12-08 12:43:11 +01:00
|
|
|
{
|
2011-02-24 09:17:21 +01:00
|
|
|
QMetaObject::invokeMethod(editor->widget(), "setSizes",
|
|
|
|
|
Q_ARG(quint64, address),
|
|
|
|
|
Q_ARG(int, DataRange),
|
2010-12-08 12:43:11 +01:00
|
|
|
Q_ARG(int, BinBlockSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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-12-14 12:29:32 +01:00
|
|
|
void MemoryAgent::handleStartOfFileRequested(IEditor *editor)
|
2010-12-08 12:43:11 +01:00
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(),
|
|
|
|
|
"setCursorPosition", Q_ARG(int, 0));
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
void MemoryAgent::handleEndOfFileRequested(IEditor *editor)
|
2010-12-08 12:43:11 +01:00
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(),
|
|
|
|
|
"setCursorPosition", Q_ARG(int, DataRange - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-25 13:21:54 +01:00
|
|
|
void MemoryAgent::handleDataChanged(IEditor *editor,
|
|
|
|
|
quint64 addr, const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
m_engine->changeMemory(this, editor, addr, data);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
void MemoryAgent::updateContents()
|
2010-12-13 18:17:31 +01:00
|
|
|
{
|
|
|
|
|
foreach (QPointer<IEditor> editor, m_editors)
|
|
|
|
|
if (editor)
|
|
|
|
|
QMetaObject::invokeMethod(editor->widget(), "updateContents");
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-16 10:44:21 +01:00
|
|
|
bool MemoryAgent::hasVisibleEditor() const
|
|
|
|
|
{
|
|
|
|
|
QList<IEditor *> visible = EditorManager::instance()->visibleEditors();
|
|
|
|
|
foreach (QPointer<IEditor> editor, m_editors)
|
|
|
|
|
if (visible.contains(editor.data()))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 16:18:47 +02:00
|
|
|
bool MemoryAgent::isBigEndian(const ProjectExplorer::Abi &a)
|
|
|
|
|
{
|
|
|
|
|
switch (a.architecture()) {
|
|
|
|
|
case ProjectExplorer::Abi::UnknownArchitecture:
|
|
|
|
|
case ProjectExplorer::Abi::X86Architecture:
|
|
|
|
|
case ProjectExplorer::Abi::ItaniumArchitecture: // Configureable
|
|
|
|
|
case ProjectExplorer::Abi::ArmArchitecture: // Configureable
|
|
|
|
|
break;
|
|
|
|
|
case ProjectExplorer::Abi::MipsArcitecture: // Configureable
|
|
|
|
|
case ProjectExplorer::Abi::PowerPCArchitecture: // Configureable
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read a POD variable from a memory location. Swap bytes if endianness differs
|
|
|
|
|
template <class POD> POD readPod(const unsigned char *data, bool swapByteOrder)
|
|
|
|
|
{
|
|
|
|
|
POD pod = 0;
|
|
|
|
|
if (swapByteOrder) {
|
|
|
|
|
unsigned char *target = reinterpret_cast<unsigned char *>(&pod) + sizeof(POD) - 1;
|
|
|
|
|
for (size_t i = 0; i < sizeof(POD); i++)
|
|
|
|
|
*target-- = data[i];
|
|
|
|
|
} else {
|
|
|
|
|
std::memcpy(&pod, data, sizeof(POD));
|
|
|
|
|
}
|
|
|
|
|
return pod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read memory from debuggee
|
|
|
|
|
quint64 MemoryAgent::readInferiorPointerValue(const unsigned char *data, const ProjectExplorer::Abi &a)
|
|
|
|
|
{
|
|
|
|
|
const bool swapByteOrder = isBigEndian(a) != isBigEndian(ProjectExplorer::Abi::hostAbi());
|
|
|
|
|
return a.wordWidth() == 32 ? readPod<quint32>(data, swapByteOrder) :
|
|
|
|
|
readPod<quint64>(data, swapByteOrder);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 12:43:11 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|