snapshothandler.cpp 7.56 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 7 8
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
15 16 17 18 19 20 21 22 23 24
**
** 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.
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
31 32 33 34 35
**
**************************************************************************/

#include "snapshothandler.h"

36
#include "debuggerconstants.h"
37
#include "debuggercore.h"
38
#include "debuggerengine.h"
39
#include "debuggerrunner.h"
40 41 42 43

#include <utils/qtcassert.h>

#include <QtCore/QDebug>
44 45
#include <QtCore/QFile>
#include <QtGui/QIcon>
46 47 48 49

namespace Debugger {
namespace Internal {

50
#if 0
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
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);
73
/*    str << SnapshotHandler::tr("Function:") << ' ' << function() << ' '
74
        << SnapshotHandler::tr("File:") << ' ' << m_location << ' '
75
        << SnapshotHandler::tr("Date:") << ' ' << m_date.toString(); */
76 77 78 79 80 81 82 83
    return res;
}

QString SnapshotData::toToolTip() const
{
    QString res;
    QTextStream str(&res);
    str << "<html><body><table>"
84
/*
85 86 87 88
        << "<tr><td>" << SnapshotHandler::tr("Function:")
            << "</td><td>" << function() << "</td></tr>"
        << "<tr><td>" << SnapshotHandler::tr("File:")
            << "</td><td>" << QDir::toNativeSeparators(m_location) << "</td></tr>"
89
        << "</table></body></html>"; */
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    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;
}
112
#endif
113 114 115 116 117 118 119

////////////////////////////////////////////////////////////////////////
//
// SnapshotHandler
//
////////////////////////////////////////////////////////////////////////

120
SnapshotHandler::SnapshotHandler()
121 122
  : m_positionIcon(QIcon(QLatin1String(":/debugger/images/location_16.png"))),
    m_emptyIcon(QIcon(QLatin1String(":/debugger/images/debugger_empty_14.png")))
123
{
124
    m_currentIndex = -1;
125 126 127 128
}

SnapshotHandler::~SnapshotHandler()
{
129
    for (int i = m_snapshots.size(); --i >= 0; ) {
130 131
        if (DebuggerEngine *engine = at(i)) {
            const DebuggerStartParameters &sp = engine->startParameters();
132 133
            if (sp.isSnapshot && !sp.coreFile.isEmpty())
                QFile::remove(sp.coreFile);
134
        }
135 136 137
    }
}

138 139 140 141 142 143 144 145
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
{
146
    return parent.isValid() ? 0 : 2;
147 148 149 150 151 152 153
}

QVariant SnapshotHandler::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || index.row() >= m_snapshots.size())
        return QVariant();

154
    const DebuggerEngine *engine = at(index.row());
155 156 157 158 159 160 161

    if (role == SnapshotCapabilityRole)
        return engine && (engine->debuggerCapabilities() & SnapshotCapability);

    if (!engine)
        return QLatin1String("<finished>");

162
    const DebuggerStartParameters &sp = engine->startParameters();
163

164 165
    switch (role) {
    case Qt::DisplayRole:
166
        switch (index.column()) {
167 168 169 170
        case 0:
            return sp.displayName;
        case 1:
            return sp.coreFile.isEmpty() ? sp.executable : sp.coreFile;
171 172 173
        }
        return QVariant();

174 175
    case Qt::ToolTipRole:
        return QVariant();
176

177 178
    case Qt::DecorationRole:
        // Return icon that indicates whether this is the active stack frame.
179 180 181
        if (index.column() == 0)
            return (index.row() == m_currentIndex) ? m_positionIcon : m_emptyIcon;
        break;
182

183 184 185
    default:
        break;
    }
186 187 188 189 190 191 192
    return QVariant();
}

QVariant SnapshotHandler::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
        switch (section) {
193 194
            case 0: return tr("Name");
            case 1: return tr("File");
195 196 197 198 199 200 201 202 203 204 205 206 207 208
        };
    }
    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);
}

209
void SnapshotHandler::activateSnapshot(int index)
210
{
211 212
    m_currentIndex = index;
    //qDebug() << "ACTIVATING INDEX: " << m_currentIndex << " OF " << size();
213
    debuggerCore()->displayDebugger(at(index), true);
214
    reset();
215 216
}

217 218
void SnapshotHandler::createSnapshot(int index)
{
219
    DebuggerEngine *engine = at(index);
220 221 222 223 224 225
    QTC_ASSERT(engine, return);
    engine->createSnapshot();
}

void SnapshotHandler::removeSnapshot(int index)
{
226
    DebuggerEngine *engine = at(index);
227 228
    //qDebug() << "REMOVING " << engine;
    QTC_ASSERT(engine, return);
229 230 231 232 233
#if 0
    // See http://sourceware.org/bugzilla/show_bug.cgi?id=11241.
    setState(EngineSetupRequested);
    postCommand("set stack-cache off");
#endif
234
    //QString fileName = engine->startParameters().coreFile;
235 236 237 238 239 240 241
    //if (!fileName.isEmpty())
    //    QFile::remove(fileName);
    m_snapshots.removeAt(index);
    if (index == m_currentIndex)
        m_currentIndex = -1;
    else if (index < m_currentIndex)
        --m_currentIndex;
242
    //engine->quitDebugger();
243 244 245
    reset();
}

246

247 248 249
void SnapshotHandler::removeAll()
{
    m_snapshots.clear();
250
    m_currentIndex = -1;
251 252 253
    reset();
}

254
void SnapshotHandler::appendSnapshot(DebuggerEngine *engine)
255
{
256
    m_snapshots.append(engine);
257
    m_currentIndex = size() - 1;
258 259 260
    reset();
}

261
void SnapshotHandler::removeSnapshot(DebuggerEngine *engine)
262
{
263
    // Could be that the run controls died before it was appended.
264
    int index = m_snapshots.indexOf(engine);
265 266
    if (index != -1)
        removeSnapshot(index);
267 268
}

269
void SnapshotHandler::setCurrentIndex(int index)
270 271 272 273 274
{
    m_currentIndex = index;
    reset();
}

275
DebuggerEngine *SnapshotHandler::at(int i) const
276 277 278 279
{
    return m_snapshots.at(i).data();
}

280 281
} // namespace Internal
} // namespace Debugger