2010-02-02 17:25:14 +01: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).
|
2010-02-02 17:25:14 +01: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
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "snapshothandler.h"
|
|
|
|
|
|
2010-06-15 12:15:25 +02:00
|
|
|
#include "debuggerconstants.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
#include "debuggerengine.h"
|
2010-07-13 15:57:34 +02:00
|
|
|
#include "debuggerrunner.h"
|
|
|
|
|
#include "debuggerplugin.h"
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2010-11-02 16:14:00 +01:00
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtGui/QIcon>
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
#if 0
|
2010-02-02 17:25:14 +01:00
|
|
|
SnapshotData::SnapshotData()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void SnapshotData::clear()
|
|
|
|
|
{
|
|
|
|
|
m_frames.clear();
|
|
|
|
|
m_location.clear();
|
|
|
|
|
m_date = QDateTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SnapshotData::function() const
|
|
|
|
|
{
|
|
|
|
|
if (m_frames.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
const StackFrame &frame = m_frames.at(0);
|
|
|
|
|
return frame.function + ":" + QString::number(frame.line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SnapshotData::toString() const
|
|
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
QTextStream str(&res);
|
2010-09-10 10:51:43 +02:00
|
|
|
/* str << SnapshotHandler::tr("Function:") << ' ' << function() << ' '
|
2010-02-02 17:25:14 +01:00
|
|
|
<< SnapshotHandler::tr("File:") << ' ' << m_location << ' '
|
2010-09-10 10:51:43 +02:00
|
|
|
<< SnapshotHandler::tr("Date:") << ' ' << m_date.toString(); */
|
2010-02-02 17:25:14 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SnapshotData::toToolTip() const
|
|
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
QTextStream str(&res);
|
|
|
|
|
str << "<html><body><table>"
|
2010-09-10 10:51:43 +02:00
|
|
|
/*
|
2010-02-02 17:25:14 +01:00
|
|
|
<< "<tr><td>" << SnapshotHandler::tr("Function:")
|
|
|
|
|
<< "</td><td>" << function() << "</td></tr>"
|
|
|
|
|
<< "<tr><td>" << SnapshotHandler::tr("File:")
|
|
|
|
|
<< "</td><td>" << QDir::toNativeSeparators(m_location) << "</td></tr>"
|
2010-09-10 10:51:43 +02:00
|
|
|
<< "</table></body></html>"; */
|
2010-02-02 17:25:14 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDebug operator<<(QDebug d, const SnapshotData &f)
|
|
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
QTextStream str(&res);
|
|
|
|
|
str << f.location();
|
|
|
|
|
/*
|
|
|
|
|
str << "level=" << f.level << " address=" << f.address;
|
|
|
|
|
if (!f.function.isEmpty())
|
|
|
|
|
str << ' ' << f.function;
|
|
|
|
|
if (!f.location.isEmpty())
|
|
|
|
|
str << ' ' << f.location << ':' << f.line;
|
|
|
|
|
if (!f.from.isEmpty())
|
|
|
|
|
str << " from=" << f.from;
|
|
|
|
|
if (!f.to.isEmpty())
|
|
|
|
|
str << " to=" << f.to;
|
|
|
|
|
*/
|
|
|
|
|
d.nospace() << res;
|
|
|
|
|
return d;
|
|
|
|
|
}
|
2010-07-13 15:57:34 +02:00
|
|
|
#endif
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// SnapshotHandler
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-07-20 18:06:34 +02:00
|
|
|
SnapshotHandler::SnapshotHandler()
|
2010-07-30 22:16:59 +02:00
|
|
|
: m_positionIcon(QIcon(QLatin1String(":/debugger/images/location_16.png"))),
|
|
|
|
|
m_emptyIcon(QIcon(QLatin1String(":/debugger/images/debugger_empty_14.png")))
|
2010-02-02 17:25:14 +01:00
|
|
|
{
|
2010-07-13 15:57:34 +02:00
|
|
|
m_currentIndex = -1;
|
2010-02-02 17:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SnapshotHandler::~SnapshotHandler()
|
|
|
|
|
{
|
2010-07-13 15:57:34 +02:00
|
|
|
for (int i = m_snapshots.size(); --i >= 0; ) {
|
2010-07-13 17:57:39 +02:00
|
|
|
if (DebuggerEngine *engine = engineAt(i)) {
|
2010-09-07 14:19:44 +02:00
|
|
|
const DebuggerStartParameters & sp = engine->startParameters();
|
|
|
|
|
if (sp.isSnapshot && !sp.coreFile.isEmpty())
|
|
|
|
|
QFile::remove(sp.coreFile);
|
2010-07-13 17:57:39 +02:00
|
|
|
}
|
2010-07-13 15:57:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebuggerEngine *SnapshotHandler::engineAt(int i) const
|
|
|
|
|
{
|
2010-07-13 17:57:39 +02:00
|
|
|
DebuggerEngine *engine = m_snapshots.at(i)->engine();
|
|
|
|
|
QTC_ASSERT(engine, qDebug() << "ENGINE AT " << i << "DELETED");
|
|
|
|
|
return engine;
|
2010-02-02 17:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SnapshotHandler::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
// Since the stack is not a tree, row count is 0 for any valid parent
|
|
|
|
|
return parent.isValid() ? 0 : m_snapshots.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SnapshotHandler::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2010-07-13 15:57:34 +02:00
|
|
|
return parent.isValid() ? 0 : 2;
|
2010-02-02 17:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant SnapshotHandler::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid() || index.row() >= m_snapshots.size())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
const DebuggerEngine *engine = engineAt(index.row());
|
2010-07-13 17:57:39 +02:00
|
|
|
|
|
|
|
|
if (role == SnapshotCapabilityRole)
|
|
|
|
|
return engine && (engine->debuggerCapabilities() & SnapshotCapability);
|
|
|
|
|
|
|
|
|
|
if (!engine)
|
|
|
|
|
return QLatin1String("<finished>");
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
const DebuggerStartParameters &sp = engine->startParameters();
|
2010-02-02 17:25:14 +01:00
|
|
|
|
2010-09-10 10:51:43 +02:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
2010-02-02 17:25:14 +01:00
|
|
|
switch (index.column()) {
|
2010-07-13 15:57:34 +02:00
|
|
|
case 0:
|
|
|
|
|
return sp.displayName;
|
|
|
|
|
case 1:
|
|
|
|
|
return sp.coreFile.isEmpty() ? sp.executable : sp.coreFile;
|
2010-02-02 17:25:14 +01:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
2010-09-10 10:51:43 +02:00
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
return QVariant();
|
2010-02-02 17:25:14 +01:00
|
|
|
|
2010-11-05 19:38:40 +01:00
|
|
|
case Qt::DecorationRole:
|
|
|
|
|
// Return icon that indicates whether this is the active stack frame.
|
2010-09-10 10:51:43 +02:00
|
|
|
if (index.column() == 0)
|
|
|
|
|
return (index.row() == m_currentIndex) ? m_positionIcon : m_emptyIcon;
|
|
|
|
|
break;
|
2010-02-02 17:25:14 +01:00
|
|
|
|
2010-09-10 10:51:43 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-02-02 17:25:14 +01:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant SnapshotHandler::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
|
switch (section) {
|
2010-07-13 15:57:34 +02:00
|
|
|
case 0: return tr("Name");
|
|
|
|
|
case 1: return tr("File");
|
2010-02-02 17:25:14 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags SnapshotHandler::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (index.row() >= m_snapshots.size())
|
|
|
|
|
return 0;
|
|
|
|
|
if (index.row() == m_snapshots.size())
|
|
|
|
|
return QAbstractTableModel::flags(index);
|
|
|
|
|
return true ? QAbstractTableModel::flags(index) : Qt::ItemFlags(0);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:38:40 +01:00
|
|
|
void SnapshotHandler::activateSnapshot(int index)
|
2010-06-15 12:15:25 +02:00
|
|
|
{
|
2010-11-05 19:38:40 +01:00
|
|
|
m_currentIndex = index;
|
|
|
|
|
//qDebug() << "ACTIVATING INDEX: " << m_currentIndex << " OF " << size();
|
|
|
|
|
DebuggerPlugin::displayDebugger(m_snapshots.at(index));
|
|
|
|
|
reset();
|
2010-06-15 12:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:38:40 +01:00
|
|
|
void SnapshotHandler::createSnapshot(int index)
|
|
|
|
|
{
|
|
|
|
|
DebuggerEngine *engine = engineAt(index);
|
|
|
|
|
QTC_ASSERT(engine, return);
|
|
|
|
|
engine->createSnapshot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotHandler::removeSnapshot(int index)
|
|
|
|
|
{
|
|
|
|
|
DebuggerEngine *engine = engineAt(index);
|
|
|
|
|
//qDebug() << "REMOVING " << engine;
|
|
|
|
|
QTC_ASSERT(engine, return);
|
2010-07-13 15:57:34 +02:00
|
|
|
#if 0
|
|
|
|
|
// See http://sourceware.org/bugzilla/show_bug.cgi?id=11241.
|
|
|
|
|
setState(EngineSetupRequested);
|
|
|
|
|
postCommand("set stack-cache off");
|
|
|
|
|
#endif
|
2010-11-08 17:43:31 +01:00
|
|
|
//QString fileName = engine->startParameters().coreFile;
|
2010-11-05 19:38:40 +01:00
|
|
|
//if (!fileName.isEmpty())
|
|
|
|
|
// QFile::remove(fileName);
|
|
|
|
|
m_snapshots.removeAt(index);
|
|
|
|
|
if (index == m_currentIndex)
|
|
|
|
|
m_currentIndex = -1;
|
|
|
|
|
else if (index < m_currentIndex)
|
|
|
|
|
--m_currentIndex;
|
2010-11-08 17:43:31 +01:00
|
|
|
//engine->quitDebugger();
|
2010-11-05 19:38:40 +01:00
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
|
2010-02-02 17:25:14 +01:00
|
|
|
void SnapshotHandler::removeAll()
|
|
|
|
|
{
|
|
|
|
|
m_snapshots.clear();
|
2010-07-13 15:57:34 +02:00
|
|
|
m_currentIndex = -1;
|
2010-02-02 17:25:14 +01:00
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
void SnapshotHandler::appendSnapshot(DebuggerRunControl *rc)
|
2010-02-02 17:25:14 +01:00
|
|
|
{
|
2010-07-13 15:57:34 +02:00
|
|
|
m_snapshots.append(rc);
|
|
|
|
|
m_currentIndex = size() - 1;
|
2010-02-02 17:25:14 +01:00
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 17:57:39 +02:00
|
|
|
void SnapshotHandler::removeSnapshot(DebuggerRunControl *rc)
|
|
|
|
|
{
|
2010-07-15 13:23:44 +02:00
|
|
|
// Could be that the run controls died before it was appended.
|
2010-07-13 17:57:39 +02:00
|
|
|
int index = m_snapshots.indexOf(rc);
|
2010-07-15 13:23:44 +02:00
|
|
|
if (index != -1)
|
|
|
|
|
removeSnapshot(index);
|
2010-07-13 17:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
void SnapshotHandler::setCurrentIndex(int index)
|
2010-02-02 17:25:14 +01:00
|
|
|
{
|
|
|
|
|
m_currentIndex = index;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 11:08:50 +02:00
|
|
|
DebuggerRunControl *SnapshotHandler::at(int i) const
|
2010-07-21 17:06:22 +02:00
|
|
|
{
|
|
|
|
|
return m_snapshots.at(i).data();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 11:08:50 +02:00
|
|
|
QList<DebuggerRunControl*> SnapshotHandler::runControls() const
|
|
|
|
|
{
|
|
|
|
|
// Return unique list of run controls
|
|
|
|
|
QList<DebuggerRunControl*> rc;
|
|
|
|
|
rc.reserve(m_snapshots.size());
|
|
|
|
|
foreach(const QPointer<DebuggerRunControl> &runControlPtr, m_snapshots)
|
|
|
|
|
if (DebuggerRunControl *runControl = runControlPtr)
|
|
|
|
|
if (!rc.contains(runControl))
|
|
|
|
|
rc.push_back(runControl);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 17:25:14 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|