Commit 1bd71635 authored by hjk's avatar hjk
Browse files

debugger: cache disassembler results per-function.

parent c27d8b72
......@@ -143,10 +143,10 @@ public:
struct DisassemblerViewAgentPrivate
{
QPointer<TextEditor::ITextEditor> editor;
QString address;
QString function;
StackFrame frame;
QPointer<DebuggerManager> manager;
LocationMark2 *locationMark;
QHash<QString, QString> cache;
};
/*!
......@@ -193,17 +193,33 @@ DisassemblerViewAgent::~DisassemblerViewAgent()
{
if (d->editor)
d->editor->deleteLater();
d->editor = 0;
delete d;
d = 0;
}
void DisassemblerViewAgent::cleanup()
{
d->cache.clear();
//if (d->editor)
// d->editor->deleteLater();
//d->editor = 0;
}
void DisassemblerViewAgent::setFrame(const StackFrame &frame)
{
d->frame = frame;
if (!frame.function.isEmpty()) {
QHash<QString, QString>::ConstIterator it =
d->cache.find(frame.function + frame.file);
if (it != d->cache.end()) {
setContents(*it);
return;
}
}
IDebuggerEngine *engine = d->manager->currentEngine();
QTC_ASSERT(engine, return);
engine->fetchDisassembler(this, frame);
d->address = frame.address;
d->function = frame.function;
}
void DisassemblerViewAgent::setContents(const QString &contents)
......@@ -212,6 +228,7 @@ void DisassemblerViewAgent::setContents(const QString &contents)
using namespace Core;
using namespace TextEditor;
d->cache.insert(d->frame.function + d->frame.file, contents);
QPlainTextEdit *plainTextEdit = 0;
EditorManager *editorManager = EditorManager::instance();
if (!d->editor) {
......@@ -232,10 +249,10 @@ void DisassemblerViewAgent::setContents(const QString &contents)
plainTextEdit->setPlainText(contents);
d->editor->markableInterface()->removeMark(d->locationMark);
d->editor->setDisplayName(_("Disassembler (%1)").arg(d->function));
d->editor->setDisplayName(_("Disassembler (%1)").arg(d->frame.function));
for (int pos = 0, line = 0; ; ++line, ++pos) {
if (contents.midRef(pos, d->address.size()) == d->address) {
if (contents.midRef(pos, d->frame.address.size()) == d->frame.address) {
d->editor->markableInterface()->addMark(d->locationMark, line + 1);
if (plainTextEdit) {
QTextCursor tc = plainTextEdit->textCursor();
......@@ -252,7 +269,7 @@ void DisassemblerViewAgent::setContents(const QString &contents)
QString DisassemblerViewAgent::address() const
{
return d->address;
return d->frame.address;
}
} // namespace Internal
......
......@@ -85,6 +85,7 @@ public:
void setFrame(const StackFrame &frame);
Q_SLOT void setContents(const QString &contents);
QString address() const;
void cleanup();
private:
DisassemblerViewAgentPrivate *d;
......
......@@ -254,9 +254,9 @@ static Debugger::Internal::IDebuggerEngine *scriptEngine = 0;
static Debugger::Internal::IDebuggerEngine *tcfEngine = 0;
static Debugger::Internal::IDebuggerEngine *winEngine = 0;
struct DebuggerManagerPrivate {
DebuggerManagerPrivate();
struct DebuggerManagerPrivate
{
DebuggerManagerPrivate(DebuggerManager *manager);
static DebuggerManager *instance;
......@@ -297,7 +297,7 @@ struct DebuggerManagerPrivate {
bool m_busy;
QTimer *m_statusTimer;
QString m_lastPermanentStatusMessage;
DisassemblerViewAgent *m_disassemblerViewAgent;
DisassemblerViewAgent m_disassemblerViewAgent;
IDebuggerEngine *m_engine;
DebuggerState m_state;
......@@ -305,14 +305,15 @@ struct DebuggerManagerPrivate {
DebuggerManager *DebuggerManagerPrivate::instance = 0;
DebuggerManagerPrivate::DebuggerManagerPrivate()
: m_startParameters(new DebuggerStartParameters)
DebuggerManagerPrivate::DebuggerManagerPrivate(DebuggerManager *manager)
: m_startParameters(new DebuggerStartParameters),
m_disassemblerViewAgent(manager)
{
m_inferiorPid = 0;
m_disassemblerViewAgent = 0;
}
DebuggerManager::DebuggerManager() : d(new DebuggerManagerPrivate)
DebuggerManager::DebuggerManager()
: d(new DebuggerManagerPrivate(this))
{
DebuggerManagerPrivate::instance = this;
init();
......@@ -1034,6 +1035,7 @@ void DebuggerManager::cleanupViews()
watchHandler()->cleanup();
registerHandler()->removeAll();
d->m_sourceFilesWindow->removeAll();
d->m_disassemblerViewAgent.cleanup();
}
void DebuggerManager::exitDebugger()
......@@ -1342,9 +1344,7 @@ void DebuggerManager::resetLocation()
void DebuggerManager::gotoLocation(const Debugger::Internal::StackFrame &frame, bool setMarker)
{
if (theDebuggerBoolSetting(OperateByInstruction) || !frame.isUsable()) {
if (!d->m_disassemblerViewAgent)
d->m_disassemblerViewAgent = new DisassemblerViewAgent(this);
d->m_disassemblerViewAgent->setFrame(frame);
d->m_disassemblerViewAgent.setFrame(frame);
if (setMarker)
resetLocation();
} else {
......@@ -1627,8 +1627,8 @@ void DebuggerManager::setState(DebuggerState state)
QString msg = _("State changed from %1(%2) to %3(%4).")
.arg(stateName(d->m_state)).arg(d->m_state).arg(stateName(state)).arg(state);
if (!((d->m_state == -1 && state == 0) || (d->m_state == 0 && state == 0)))
qDebug() << msg << d->m_state << state;
//if (!((d->m_state == -1 && state == 0) || (d->m_state == 0 && state == 0)))
// qDebug() << msg << d->m_state << state;
if (!isAllowedTransition(d->m_state, state))
qDebug() << "UNEXPECTED STATE TRANSITION: " << msg;
......
......@@ -728,10 +728,9 @@ void GdbEngine::postCommand(const QString &command, GdbCommandFlags flags,
void GdbEngine::postCommandHelper(const GdbCommand &cmd)
{
if (!stateAcceptsGdbCommands(state())) {
qDebug() << _("NO GDB PROCESS RUNNING, CMD IGNORED: ") << cmd.command
<< state();
PENDING_DEBUG(_("NO GDB PROCESS RUNNING, CMD IGNORED: ") + cmd.command);
debugMessage(_("NO GDB PROCESS RUNNING, CMD IGNORED: ") + cmd.command);
debugMessage(_("NO GDB PROCESS RUNNING, CMD IGNORED: %1 %2")
.arg(cmd.command).arg(state()));
return;
}
......@@ -1292,6 +1291,7 @@ void GdbEngine::handleStop2(const GdbMi &data)
f.file = QFile::decodeName(fullName.data());
f.line = frame.findChild("line").data().toInt();
f.address = _(frame.findChild("addr").data());
f.function = _(frame.findChild("func").data());
gotoLocation(f, true);
}
......
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