2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-05-18 12:12:22 +02:00
|
|
|
|
|
|
|
|
#include "threadshandler.h"
|
|
|
|
|
|
2011-09-01 16:36:27 +02:00
|
|
|
#include "debuggercore.h"
|
2013-01-24 10:38:40 +01:00
|
|
|
#include "debuggerprotocol.h"
|
|
|
|
|
#include "watchutils.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2012-10-19 16:37:57 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2013-11-20 02:19:54 +01:00
|
|
|
static void mergeThreadData(ThreadData &data, const ThreadData &other)
|
2012-10-19 16:37:57 +02:00
|
|
|
{
|
|
|
|
|
if (!other.core.isEmpty())
|
|
|
|
|
data.core = other.core;
|
|
|
|
|
if (!other.fileName.isEmpty())
|
|
|
|
|
data.fileName = other.fileName;
|
|
|
|
|
if (!other.targetId.isEmpty())
|
|
|
|
|
data.targetId = other.targetId;
|
|
|
|
|
if (!other.name.isEmpty())
|
|
|
|
|
data.name = other.name;
|
|
|
|
|
if (other.frameLevel != -1)
|
|
|
|
|
data.frameLevel = other.frameLevel;
|
|
|
|
|
if (!other.function.isEmpty())
|
|
|
|
|
data.function = other.function;
|
2013-06-06 13:18:13 +02:00
|
|
|
if (other.address)
|
2012-10-19 16:37:57 +02:00
|
|
|
data.address = other.address;
|
|
|
|
|
if (!other.module.isEmpty())
|
|
|
|
|
data.module = other.module;
|
|
|
|
|
if (!other.details.isEmpty())
|
|
|
|
|
data.details = other.details;
|
|
|
|
|
if (!other.state.isEmpty())
|
|
|
|
|
data.state = other.state;
|
|
|
|
|
if (other.lineNumber != -1)
|
|
|
|
|
data.lineNumber = other.lineNumber;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 02:19:54 +01:00
|
|
|
static QVariant threadPart(const ThreadData &thread, int column)
|
|
|
|
|
{
|
|
|
|
|
switch (column) {
|
|
|
|
|
case ThreadData::IdColumn:
|
|
|
|
|
return thread.id.raw();
|
|
|
|
|
case ThreadData::FunctionColumn:
|
|
|
|
|
return thread.function;
|
|
|
|
|
case ThreadData::FileColumn:
|
|
|
|
|
return thread.fileName.isEmpty() ? thread.module : thread.fileName;
|
|
|
|
|
case ThreadData::LineColumn:
|
|
|
|
|
return thread.lineNumber >= 0
|
|
|
|
|
? QString::number(thread.lineNumber) : QString();
|
|
|
|
|
case ThreadData::AddressColumn:
|
|
|
|
|
return thread.address > 0
|
|
|
|
|
? QLatin1String("0x") + QString::number(thread.address, 16)
|
|
|
|
|
: QString();
|
|
|
|
|
case ThreadData::CoreColumn:
|
|
|
|
|
return thread.core;
|
|
|
|
|
case ThreadData::StateColumn:
|
|
|
|
|
return thread.state;
|
|
|
|
|
case ThreadData::TargetIdColumn:
|
|
|
|
|
if (thread.targetId.startsWith(QLatin1String("Thread ")))
|
|
|
|
|
return thread.targetId.mid(7);
|
|
|
|
|
return thread.targetId;
|
|
|
|
|
case ThreadData::NameColumn:
|
|
|
|
|
return thread.name;
|
|
|
|
|
case ThreadData::DetailsColumn:
|
|
|
|
|
return thread.details;
|
|
|
|
|
case ThreadData::ComboNameColumn:
|
|
|
|
|
return QString::fromLatin1("#%1 %2").arg(thread.id.raw()).arg(thread.name);
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ThreadsHandler
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2010-11-05 17:02:27 +01:00
|
|
|
|
|
|
|
|
static QString threadToolTip(const ThreadData &thread)
|
2010-07-02 14:35:41 +02:00
|
|
|
{
|
2010-11-19 09:39:50 +01:00
|
|
|
const char start[] = "<tr><td>";
|
|
|
|
|
const char sep[] = "</td><td>";
|
|
|
|
|
const char end[] = "</td>";
|
2010-07-02 14:35:41 +02:00
|
|
|
QString rc;
|
|
|
|
|
QTextStream str(&rc);
|
|
|
|
|
str << "<html><head/><body><table>"
|
2010-11-19 09:39:50 +01:00
|
|
|
<< start << ThreadsHandler::tr("Thread id:")
|
2012-10-19 16:37:57 +02:00
|
|
|
<< sep << thread.id.raw() << end;
|
2010-07-02 14:35:41 +02:00
|
|
|
if (!thread.targetId.isEmpty())
|
2010-11-19 09:39:50 +01:00
|
|
|
str << start << ThreadsHandler::tr("Target id:")
|
|
|
|
|
<< sep << thread.targetId << end;
|
2012-10-19 16:37:57 +02:00
|
|
|
if (!thread.groupId.isEmpty())
|
|
|
|
|
str << start << ThreadsHandler::tr("Group id:")
|
|
|
|
|
<< sep << thread.groupId << end;
|
2010-09-17 13:28:50 +02:00
|
|
|
if (!thread.name.isEmpty())
|
2010-11-19 09:39:50 +01:00
|
|
|
str << start << ThreadsHandler::tr("Name:")
|
|
|
|
|
<< sep << thread.name << end;
|
2010-07-02 14:35:41 +02:00
|
|
|
if (!thread.state.isEmpty())
|
2010-11-19 09:39:50 +01:00
|
|
|
str << start << ThreadsHandler::tr("State:")
|
|
|
|
|
<< sep << thread.state << end;
|
2010-07-02 14:35:41 +02:00
|
|
|
if (!thread.core.isEmpty())
|
2010-11-19 09:39:50 +01:00
|
|
|
str << start << ThreadsHandler::tr("Core:")
|
|
|
|
|
<< sep << thread.core << end;
|
2010-07-21 13:11:03 +02:00
|
|
|
if (thread.address) {
|
2010-11-19 09:39:50 +01:00
|
|
|
str << start << ThreadsHandler::tr("Stopped at:") << sep;
|
2010-07-02 14:35:41 +02:00
|
|
|
if (!thread.function.isEmpty())
|
|
|
|
|
str << thread.function << "<br>";
|
|
|
|
|
if (!thread.fileName.isEmpty())
|
|
|
|
|
str << thread.fileName << ':' << thread.lineNumber << "<br>";
|
2012-08-21 16:31:03 +02:00
|
|
|
str << formatToolTipAddress(thread.address);
|
2010-07-02 14:35:41 +02:00
|
|
|
}
|
|
|
|
|
str << "</table></body></html>";
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ThreadsHandler
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-02-04 15:08:31 +01:00
|
|
|
/*!
|
2013-06-05 14:29:24 +02:00
|
|
|
\class Debugger::Internal::ThreadData
|
|
|
|
|
\internal
|
|
|
|
|
\brief The ThreadData class contains information
|
|
|
|
|
about a single thread.
|
2011-02-04 15:08:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Debugger::Internal::ThreadsHandler
|
2013-06-05 14:29:24 +02:00
|
|
|
\internal
|
|
|
|
|
\brief The ThreadsHandler class provides a model to
|
|
|
|
|
represent the running threads in a QTreeView or ComboBox.
|
2011-02-04 15:08:31 +01:00
|
|
|
*/
|
|
|
|
|
|
2010-11-05 17:02:27 +01:00
|
|
|
ThreadsHandler::ThreadsHandler()
|
2013-11-14 13:24:02 +01:00
|
|
|
: m_currentId(),
|
2010-05-18 12:12:22 +02:00
|
|
|
m_positionIcon(QLatin1String(":/debugger/images/location_16.png")),
|
|
|
|
|
m_emptyIcon(QLatin1String(":/debugger/images/debugger_empty_14.png"))
|
|
|
|
|
{
|
2011-04-18 16:40:59 +02:00
|
|
|
m_resetLocationScheduled = false;
|
2013-08-19 13:30:10 +02:00
|
|
|
setObjectName(QLatin1String("ThreadsModel"));
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-14 13:24:02 +01:00
|
|
|
int ThreadsHandler::currentThreadIndex() const
|
|
|
|
|
{
|
|
|
|
|
return indexOf(m_currentId);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
int ThreadsHandler::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2010-11-19 09:39:50 +01:00
|
|
|
// Since the stack is not a tree, row count is 0 for any valid parent.
|
2010-05-18 12:12:22 +02:00
|
|
|
return parent.isValid() ? 0 : m_threads.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ThreadsHandler::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : int(ThreadData::ColumnCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ThreadsHandler::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QVariant();
|
|
|
|
|
const int row = index.row();
|
2011-09-01 16:36:27 +02:00
|
|
|
if (row >= m_threads.size())
|
2010-05-18 12:12:22 +02:00
|
|
|
return QVariant();
|
|
|
|
|
const ThreadData &thread = m_threads.at(row);
|
|
|
|
|
|
2010-07-02 14:35:41 +02:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
2013-11-20 02:19:54 +01:00
|
|
|
return threadPart(thread, index.column());
|
2010-07-02 14:35:41 +02:00
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
return threadToolTip(thread);
|
2010-07-21 13:11:03 +02:00
|
|
|
case Qt::DecorationRole:
|
2010-11-19 09:39:50 +01:00
|
|
|
// Return icon that indicates whether this is the active stack frame.
|
2010-07-02 14:35:41 +02:00
|
|
|
if (index.column() == 0)
|
2013-11-14 13:24:02 +01:00
|
|
|
return (thread.id == m_currentId) ? m_positionIcon : m_emptyIcon;
|
2010-07-02 14:35:41 +02:00
|
|
|
break;
|
2012-10-19 16:37:57 +02:00
|
|
|
case ThreadData::IdRole:
|
|
|
|
|
return thread.id.raw();
|
2010-07-02 14:35:41 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
QVariant ThreadsHandler::headerData
|
|
|
|
|
(int section, Qt::Orientation orientation, int role) const
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
|
|
|
|
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
|
|
|
|
|
return QVariant();
|
|
|
|
|
switch (section) {
|
|
|
|
|
case ThreadData::IdColumn:
|
2011-09-26 16:48:54 +02:00
|
|
|
return QString(QLatin1String(" ") + tr("ID") + QLatin1String(" "));
|
2010-05-18 12:12:22 +02:00
|
|
|
case ThreadData::FunctionColumn:
|
|
|
|
|
return tr("Function");
|
|
|
|
|
case ThreadData::FileColumn:
|
|
|
|
|
return tr("File");
|
|
|
|
|
case ThreadData::LineColumn:
|
|
|
|
|
return tr("Line");
|
|
|
|
|
case ThreadData::AddressColumn:
|
|
|
|
|
return tr("Address");
|
|
|
|
|
case ThreadData::CoreColumn:
|
|
|
|
|
return tr("Core");
|
|
|
|
|
case ThreadData::StateColumn:
|
|
|
|
|
return tr("State");
|
2011-09-01 16:36:27 +02:00
|
|
|
case ThreadData::TargetIdColumn:
|
2011-09-26 16:48:54 +02:00
|
|
|
return tr("Target ID");
|
2012-10-16 10:48:44 +02:00
|
|
|
case ThreadData::DetailsColumn:
|
|
|
|
|
return tr("Details");
|
2010-09-13 12:37:30 +02:00
|
|
|
case ThreadData::NameColumn:
|
|
|
|
|
return tr("Name");
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-18 16:40:59 +02:00
|
|
|
Qt::ItemFlags ThreadsHandler::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
2012-10-19 16:37:57 +02:00
|
|
|
const int row = index.row();
|
|
|
|
|
const bool stopped = row >= 0 && row < m_threads.size()
|
|
|
|
|
&& m_threads.at(row).stopped;
|
|
|
|
|
return stopped ? QAbstractTableModel::flags(index) : Qt::ItemFlags(0);
|
2011-04-18 16:40:59 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
void ThreadsHandler::sort(int column, Qt::SortOrder order)
|
2013-11-20 02:19:54 +01:00
|
|
|
{
|
2014-06-16 18:25:52 +04:00
|
|
|
layoutAboutToBeChanged();
|
|
|
|
|
Utils::sort(m_threads, [&](const ThreadData &t1, const ThreadData &t2) -> bool {
|
|
|
|
|
const QVariant v1 = threadPart(t1, column);
|
|
|
|
|
const QVariant v2 = threadPart(t2, column);
|
2013-11-20 02:19:54 +01:00
|
|
|
if (v1 == v2)
|
|
|
|
|
return false;
|
2013-11-20 14:47:31 +01:00
|
|
|
// FIXME: Use correct toXXX();
|
2014-06-16 18:25:52 +04:00
|
|
|
return (v1.toString() < v2.toString()) ^ (order == Qt::DescendingOrder);
|
2013-11-20 02:19:54 +01:00
|
|
|
}
|
2014-06-16 18:25:52 +04:00
|
|
|
);
|
2013-11-20 02:19:54 +01:00
|
|
|
layoutChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
ThreadId ThreadsHandler::currentThread() const
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2013-11-14 13:24:02 +01:00
|
|
|
return m_currentId;
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
ThreadId ThreadsHandler::threadAt(int index) const
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2012-10-19 16:37:57 +02:00
|
|
|
QTC_ASSERT(index >= 0 && index < m_threads.size(), return ThreadId());
|
|
|
|
|
return m_threads[index].id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::setCurrentThread(ThreadId id)
|
|
|
|
|
{
|
2013-11-14 13:24:02 +01:00
|
|
|
if (id == m_currentId)
|
2010-05-18 12:12:22 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-11-14 13:24:02 +01:00
|
|
|
const int index = indexOf(id);
|
2012-10-19 16:37:57 +02:00
|
|
|
if (index == -1) {
|
|
|
|
|
qWarning("ThreadsHandler::setCurrentThreadId: No such thread %d.", int(id.raw()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 09:39:50 +01:00
|
|
|
// Emit changed for previous frame.
|
2013-11-14 13:24:02 +01:00
|
|
|
threadDataChanged(m_currentId);
|
2010-05-18 12:12:22 +02:00
|
|
|
|
2013-11-14 13:24:02 +01:00
|
|
|
m_currentId = id;
|
2010-05-18 12:12:22 +02:00
|
|
|
|
2011-09-01 16:36:27 +02:00
|
|
|
// Emit changed for new frame.
|
2013-11-14 13:24:02 +01:00
|
|
|
threadDataChanged(m_currentId);
|
2011-09-01 16:36:27 +02:00
|
|
|
|
|
|
|
|
updateThreadBox();
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
int ThreadsHandler::indexOf(ThreadId threadId) const
|
2010-07-02 10:58:47 +02:00
|
|
|
{
|
2012-10-19 16:37:57 +02:00
|
|
|
for (int i = m_threads.size(); --i >= 0; )
|
2010-07-02 10:58:47 +02:00
|
|
|
if (m_threads.at(i).id == threadId)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
void ThreadsHandler::updateThread(const ThreadData &thread)
|
|
|
|
|
{
|
|
|
|
|
const int i = indexOf(thread.id);
|
|
|
|
|
if (i == -1) {
|
|
|
|
|
beginInsertRows(QModelIndex(), m_threads.size(), m_threads.size());
|
|
|
|
|
m_threads.append(thread);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
} else {
|
|
|
|
|
mergeThreadData(m_threads[i], thread);
|
2013-11-14 13:24:02 +01:00
|
|
|
threadDataChanged(thread.id);
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::removeThread(ThreadId threadId)
|
|
|
|
|
{
|
|
|
|
|
const int i = indexOf(threadId);
|
|
|
|
|
if (i == -1)
|
|
|
|
|
return;
|
|
|
|
|
beginRemoveRows(QModelIndex(), i, i);
|
|
|
|
|
m_threads.remove(i);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void ThreadsHandler::setThreads(const Threads &threads)
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2012-09-20 10:31:34 +02:00
|
|
|
beginResetModel();
|
2010-05-18 12:12:22 +02:00
|
|
|
m_threads = threads;
|
2013-11-14 13:24:02 +01:00
|
|
|
bool found = false;
|
|
|
|
|
for (int i = 0, n = m_threads.size(); i < n; ++i)
|
|
|
|
|
if (threads.at(i).id == m_currentId) {
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
m_currentId = ThreadId();
|
2011-04-18 16:40:59 +02:00
|
|
|
m_resetLocationScheduled = false;
|
2012-09-20 10:31:34 +02:00
|
|
|
endResetModel();
|
2011-09-01 16:36:27 +02:00
|
|
|
updateThreadBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::updateThreadBox()
|
|
|
|
|
{
|
|
|
|
|
QStringList list;
|
|
|
|
|
foreach (const ThreadData &thread, m_threads)
|
2012-10-19 16:37:57 +02:00
|
|
|
list.append(QString::fromLatin1("#%1 %2").arg(thread.id.raw()).arg(thread.name));
|
2014-10-22 13:04:47 +02:00
|
|
|
Internal::setThreads(list, indexOf(m_currentId));
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-14 13:24:02 +01:00
|
|
|
void ThreadsHandler::threadDataChanged(ThreadId id)
|
2012-10-19 16:37:57 +02:00
|
|
|
{
|
2013-11-14 13:24:02 +01:00
|
|
|
int row = indexOf(id);
|
|
|
|
|
if (row < 0)
|
|
|
|
|
return;
|
|
|
|
|
QModelIndex l = index(row, 0);
|
|
|
|
|
QModelIndex r = index(row, ThreadData::ColumnCount - 1);
|
|
|
|
|
dataChanged(l, r);
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
Threads ThreadsHandler::threads() const
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
|
|
|
|
return m_threads;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
ThreadData ThreadsHandler::thread(ThreadId id) const
|
|
|
|
|
{
|
|
|
|
|
const int i = indexOf(id);
|
|
|
|
|
return i == -1 ? ThreadData() : m_threads.at(i);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
void ThreadsHandler::removeAll()
|
|
|
|
|
{
|
2012-09-20 10:31:34 +02:00
|
|
|
beginResetModel();
|
2010-05-18 12:12:22 +02:00
|
|
|
m_threads.clear();
|
2013-11-14 13:24:02 +01:00
|
|
|
m_currentId = ThreadId();
|
2012-09-20 10:31:34 +02:00
|
|
|
endResetModel();
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
void ThreadsHandler::notifyRunning(const QByteArray &data)
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2012-10-19 16:37:57 +02:00
|
|
|
if (data.isEmpty() || data == "all") {
|
|
|
|
|
notifyAllRunning();
|
|
|
|
|
} else {
|
|
|
|
|
bool ok;
|
|
|
|
|
qlonglong id = data.toLongLong(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
notifyRunning(ThreadId(id));
|
|
|
|
|
else // FIXME
|
|
|
|
|
notifyAllRunning();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::notifyAllRunning()
|
|
|
|
|
{
|
|
|
|
|
for (int i = m_threads.size(); --i >= 0; )
|
|
|
|
|
m_threads[i].notifyRunning();
|
|
|
|
|
layoutChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::notifyRunning(ThreadId id)
|
|
|
|
|
{
|
|
|
|
|
int i = indexOf(id);
|
|
|
|
|
if (i >= 0) {
|
|
|
|
|
m_threads[i].notifyRunning();
|
2013-11-14 13:24:02 +01:00
|
|
|
threadDataChanged(id);
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
void ThreadsHandler::notifyStopped(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
if (data.isEmpty() || data == "all") {
|
|
|
|
|
notifyAllStopped();
|
|
|
|
|
} else {
|
|
|
|
|
bool ok;
|
|
|
|
|
qlonglong id = data.toLongLong(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
notifyRunning(ThreadId(id));
|
|
|
|
|
else // FIXME
|
|
|
|
|
notifyAllStopped();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::notifyAllStopped()
|
|
|
|
|
{
|
|
|
|
|
for (int i = m_threads.size(); --i >= 0; )
|
|
|
|
|
m_threads[i].stopped = true;
|
|
|
|
|
layoutChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::notifyStopped(ThreadId id)
|
|
|
|
|
{
|
|
|
|
|
int i = indexOf(id);
|
|
|
|
|
if (i >= 0) {
|
|
|
|
|
m_threads[i].stopped = true;
|
2013-11-14 13:24:02 +01:00
|
|
|
threadDataChanged(id);
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::updateThreads(const GdbMi &data)
|
2010-11-08 17:15:33 +01:00
|
|
|
{
|
|
|
|
|
// ^done,threads=[{id="1",target-id="Thread 0xb7fdc710 (LWP 4264)",
|
|
|
|
|
// frame={level="0",addr="0x080530bf",func="testQString",args=[],
|
|
|
|
|
// file="/.../app.cpp",fullname="/../app.cpp",line="1175"},
|
|
|
|
|
// state="stopped",core="0"}],current-thread-id="1"
|
2012-10-24 16:48:09 +02:00
|
|
|
|
|
|
|
|
// Emit changed for previous frame.
|
2013-11-14 13:24:02 +01:00
|
|
|
// if (m_currentIndex != -1) {
|
|
|
|
|
// rowChanged(m_currentIndex);
|
|
|
|
|
// m_currentIndex = -1;
|
|
|
|
|
// }
|
2012-10-24 16:48:09 +02:00
|
|
|
|
2015-02-17 17:44:54 +01:00
|
|
|
const std::vector<GdbMi> &items = data["threads"].children();
|
2010-11-08 17:15:33 +01:00
|
|
|
const int n = items.size();
|
|
|
|
|
for (int index = 0; index != n; ++index) {
|
2015-02-17 17:44:54 +01:00
|
|
|
const GdbMi item = items[index];
|
2013-05-03 18:26:10 +02:00
|
|
|
const GdbMi frame = item["frame"];
|
2010-11-08 17:15:33 +01:00
|
|
|
ThreadData thread;
|
2013-05-07 12:09:54 +02:00
|
|
|
thread.id = ThreadId(item["id"].toInt());
|
2013-06-06 13:18:47 +02:00
|
|
|
thread.targetId = item["target-id"].toLatin1();
|
|
|
|
|
thread.details = item["details"].toLatin1();
|
|
|
|
|
thread.core = item["core"].toLatin1();
|
|
|
|
|
thread.state = item["state"].toLatin1();
|
|
|
|
|
thread.address = frame["addr"].toAddress();
|
|
|
|
|
thread.function = frame["func"].toLatin1();
|
|
|
|
|
thread.fileName = frame["fullname"].toLatin1();
|
2013-05-07 12:09:54 +02:00
|
|
|
thread.lineNumber = frame["line"].toInt();
|
2013-05-03 18:26:10 +02:00
|
|
|
thread.module = QString::fromLocal8Bit(frame["from"].data());
|
2013-06-06 13:18:47 +02:00
|
|
|
thread.name = item["name"].toLatin1();
|
2013-11-14 13:24:02 +01:00
|
|
|
thread.stopped = thread.state != QLatin1String("running");
|
2012-10-19 16:37:57 +02:00
|
|
|
updateThread(thread);
|
2010-11-08 17:15:33 +01:00
|
|
|
}
|
2012-10-24 16:48:09 +02:00
|
|
|
|
2013-11-14 13:24:02 +01:00
|
|
|
const GdbMi current = data["current-thread-id"];
|
|
|
|
|
if (current.isValid()) {
|
|
|
|
|
ThreadId currentId = ThreadId(current.data().toLongLong());
|
|
|
|
|
if (currentId != m_currentId) {
|
|
|
|
|
threadDataChanged(m_currentId);
|
|
|
|
|
m_currentId = currentId;
|
|
|
|
|
threadDataChanged(m_currentId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-24 16:48:09 +02:00
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
updateThreadBox();
|
2010-11-08 17:15:33 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-18 16:40:59 +02:00
|
|
|
void ThreadsHandler::scheduleResetLocation()
|
|
|
|
|
{
|
|
|
|
|
m_resetLocationScheduled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::resetLocation()
|
|
|
|
|
{
|
|
|
|
|
if (m_resetLocationScheduled) {
|
|
|
|
|
m_resetLocationScheduled = false;
|
2012-10-19 16:37:57 +02:00
|
|
|
layoutChanged();
|
2011-04-18 16:40:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-13 10:17:06 +02:00
|
|
|
QAbstractItemModel *ThreadsHandler::model()
|
|
|
|
|
{
|
2013-11-20 02:19:54 +01:00
|
|
|
return this;
|
2011-10-13 10:17:06 +02:00
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|