2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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"
|
2015-11-23 16:41:54 +01:00
|
|
|
#include "debuggericons.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>
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
#include <QCoreApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2015-06-12 11:55:57 +02:00
|
|
|
#include <QIcon>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ThreadItem
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
static const QIcon &positionIcon()
|
2012-10-19 16:37:57 +02:00
|
|
|
{
|
2015-11-23 16:41:54 +01:00
|
|
|
static QIcon icon = Icons::LOCATION.icon();
|
2015-06-12 11:55:57 +02:00
|
|
|
return icon;
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
static const QIcon &emptyIcon()
|
2013-11-20 02:19:54 +01:00
|
|
|
{
|
2015-11-23 16:41:54 +01:00
|
|
|
static QIcon icon = Icons::EMPTY.icon();
|
2015-06-12 11:55:57 +02:00
|
|
|
return icon;
|
2013-11-20 02:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 09:39:44 +02:00
|
|
|
class ThreadItem : public TreeItem
|
2010-07-02 14:35:41 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Debugger::Internal::ThreadsHandler)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ThreadItem(const ThreadsHandler *handler, const ThreadData &data = ThreadData())
|
2016-04-29 09:39:44 +02:00
|
|
|
: threadData(data), handler(handler)
|
2015-06-12 11:55:57 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
return threadPart(column);
|
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
return threadToolTip();
|
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
|
// Return icon that indicates whether this is the active stack frame.
|
|
|
|
|
if (column == 0)
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.id == handler->currentThread() ? positionIcon() : emptyIcon();
|
2015-06-12 11:55:57 +02:00
|
|
|
break;
|
|
|
|
|
case ThreadData::IdRole:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.id.raw();
|
2015-06-12 11:55:57 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(int column) const
|
|
|
|
|
{
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.stopped ? TreeItem::flags(column) : Qt::ItemFlags(0);
|
2015-06-12 11:55:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString threadToolTip() const
|
|
|
|
|
{
|
|
|
|
|
const char start[] = "<tr><td>";
|
|
|
|
|
const char sep[] = "</td><td>";
|
|
|
|
|
const char end[] = "</td>";
|
|
|
|
|
QString rc;
|
|
|
|
|
QTextStream str(&rc);
|
|
|
|
|
str << "<html><head/><body><table>"
|
|
|
|
|
<< start << ThreadsHandler::tr("Thread id:")
|
2016-04-29 09:39:44 +02:00
|
|
|
<< sep << threadData.id.raw() << end;
|
|
|
|
|
if (!threadData.targetId.isEmpty())
|
2015-06-12 11:55:57 +02:00
|
|
|
str << start << ThreadsHandler::tr("Target id:")
|
2016-04-29 09:39:44 +02:00
|
|
|
<< sep << threadData.targetId << end;
|
|
|
|
|
if (!threadData.groupId.isEmpty())
|
2015-06-12 11:55:57 +02:00
|
|
|
str << start << ThreadsHandler::tr("Group id:")
|
2016-04-29 09:39:44 +02:00
|
|
|
<< sep << threadData.groupId << end;
|
|
|
|
|
if (!threadData.name.isEmpty())
|
2015-06-12 11:55:57 +02:00
|
|
|
str << start << ThreadsHandler::tr("Name:")
|
2016-04-29 09:39:44 +02:00
|
|
|
<< sep << threadData.name << end;
|
|
|
|
|
if (!threadData.state.isEmpty())
|
2015-06-12 11:55:57 +02:00
|
|
|
str << start << ThreadsHandler::tr("State:")
|
2016-04-29 09:39:44 +02:00
|
|
|
<< sep << threadData.state << end;
|
|
|
|
|
if (!threadData.core.isEmpty())
|
2015-06-12 11:55:57 +02:00
|
|
|
str << start << ThreadsHandler::tr("Core:")
|
2016-04-29 09:39:44 +02:00
|
|
|
<< sep << threadData.core << end;
|
|
|
|
|
if (threadData.address) {
|
2015-06-12 11:55:57 +02:00
|
|
|
str << start << ThreadsHandler::tr("Stopped at:") << sep;
|
2016-04-29 09:39:44 +02:00
|
|
|
if (!threadData.function.isEmpty())
|
|
|
|
|
str << threadData.function << "<br>";
|
|
|
|
|
if (!threadData.fileName.isEmpty())
|
|
|
|
|
str << threadData.fileName << ':' << threadData.lineNumber << "<br>";
|
|
|
|
|
str << formatToolTipAddress(threadData.address);
|
2015-06-12 11:55:57 +02:00
|
|
|
}
|
|
|
|
|
str << "</table></body></html>";
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant threadPart(int column) const
|
|
|
|
|
{
|
|
|
|
|
switch (column) {
|
|
|
|
|
case ThreadData::IdColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.id.raw();
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::FunctionColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.function;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::FileColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.fileName.isEmpty() ? threadData.module : threadData.fileName;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::LineColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.lineNumber >= 0
|
|
|
|
|
? QString::number(threadData.lineNumber) : QString();
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::AddressColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.address > 0
|
|
|
|
|
? QLatin1String("0x") + QString::number(threadData.address, 16)
|
2015-06-12 11:55:57 +02:00
|
|
|
: QString();
|
|
|
|
|
case ThreadData::CoreColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.core;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::StateColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.state;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::TargetIdColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
if (threadData.targetId.startsWith(QLatin1String("Thread ")))
|
|
|
|
|
return threadData.targetId.mid(7);
|
|
|
|
|
return threadData.targetId;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::NameColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.name;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::DetailsColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return threadData.details;
|
2015-06-12 11:55:57 +02:00
|
|
|
case ThreadData::ComboNameColumn:
|
2016-04-29 09:39:44 +02:00
|
|
|
return QString::fromLatin1("#%1 %2").arg(threadData.id.raw()).arg(threadData.name);
|
2015-06-12 11:55:57 +02:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
2010-07-02 14:35:41 +02:00
|
|
|
}
|
2015-06-12 11:55:57 +02:00
|
|
|
|
|
|
|
|
void notifyRunning() // Clear state information.
|
|
|
|
|
{
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.address = 0;
|
|
|
|
|
threadData.function.clear();
|
|
|
|
|
threadData.fileName.clear();
|
|
|
|
|
threadData.frameLevel = -1;
|
|
|
|
|
threadData.state.clear();
|
|
|
|
|
threadData.lineNumber = -1;
|
|
|
|
|
threadData.stopped = false;
|
2015-06-12 11:55:57 +02:00
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void notifyStopped()
|
|
|
|
|
{
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.stopped = true;
|
2015-06-12 11:55:57 +02:00
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mergeThreadData(const ThreadData &other)
|
|
|
|
|
{
|
|
|
|
|
if (!other.core.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.core = other.core;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.fileName.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.fileName = other.fileName;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.targetId.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.targetId = other.targetId;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.name.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.name = other.name;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (other.frameLevel != -1)
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.frameLevel = other.frameLevel;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.function.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.function = other.function;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (other.address)
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.address = other.address;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.module.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.module = other.module;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.details.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.details = other.details;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (!other.state.isEmpty())
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.state = other.state;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (other.lineNumber != -1)
|
2016-04-29 09:39:44 +02:00
|
|
|
threadData.lineNumber = other.lineNumber;
|
2015-06-12 11:55:57 +02:00
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2016-04-29 09:39:44 +02:00
|
|
|
ThreadData threadData;
|
2015-06-12 11:55:57 +02:00
|
|
|
const ThreadsHandler * const handler;
|
|
|
|
|
};
|
2010-07-02 14:35:41 +02:00
|
|
|
|
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()
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2011-04-18 16:40:59 +02:00
|
|
|
m_resetLocationScheduled = false;
|
2013-08-19 13:30:10 +02:00
|
|
|
setObjectName(QLatin1String("ThreadsModel"));
|
2015-06-12 11:55:57 +02:00
|
|
|
setRootItem(new ThreadItem(this));
|
|
|
|
|
setHeader({
|
|
|
|
|
QLatin1String(" ") + tr("ID") + QLatin1String(" "),
|
|
|
|
|
tr("Address"), tr("Function"), tr("File"), tr("Line"), tr("State"),
|
|
|
|
|
tr("Name"), tr("Target ID"), tr("Details"), tr("Core"),
|
|
|
|
|
});
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
static ThreadItem *itemForThreadId(const ThreadsHandler *handler, ThreadId threadId)
|
2013-11-14 13:24:02 +01:00
|
|
|
{
|
2016-04-29 09:39:44 +02:00
|
|
|
const auto matcher = [threadId](ThreadItem *item) { return item->threadData.id == threadId; };
|
2015-06-12 11:55:57 +02:00
|
|
|
return handler->findItemAtLevel<ThreadItem *>(1, matcher);
|
2013-11-14 13:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
static int indexForThreadId(const ThreadsHandler *handler, ThreadId threadId)
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
ThreadItem *item = itemForThreadId(handler, threadId);
|
|
|
|
|
return item ? handler->rootItem()->children().indexOf(item) : -1;
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
int ThreadsHandler::currentThreadIndex() const
|
2011-04-18 16:40:59 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
return indexForThreadId(this, m_currentId);
|
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
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
rootItem()->sortChildren([order, column](const TreeItem *item1, const TreeItem *item2) -> bool {
|
|
|
|
|
const QVariant v1 = static_cast<const ThreadItem *>(item1)->threadPart(column);
|
|
|
|
|
const QVariant v2 = static_cast<const ThreadItem *>(item2)->threadPart(column);
|
2013-11-20 02:19:54 +01:00
|
|
|
if (v1 == v2)
|
|
|
|
|
return false;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (column == 0)
|
|
|
|
|
return (v1.toInt() < v2.toInt()) ^ (order == Qt::DescendingOrder);
|
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);
|
2015-06-12 11:55:57 +02:00
|
|
|
});
|
2013-11-20 02:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
QTC_ASSERT(index >= 0 && index < rootItem()->childCount(), return ThreadId());
|
2016-04-29 09:39:44 +02:00
|
|
|
return static_cast<ThreadItem *>(rootItem()->childAt(index))->threadData.id;
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
ThreadItem *newItem = itemForThreadId(this, id);
|
|
|
|
|
if (!newItem) {
|
2012-10-19 16:37:57 +02:00
|
|
|
qWarning("ThreadsHandler::setCurrentThreadId: No such thread %d.", int(id.raw()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
ThreadItem *oldItem = itemForThreadId(this, m_currentId);
|
2013-11-14 13:24:02 +01:00
|
|
|
m_currentId = id;
|
2015-06-12 11:55:57 +02:00
|
|
|
if (oldItem)
|
|
|
|
|
oldItem->update();
|
2010-05-18 12:12:22 +02:00
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
newItem->update();
|
2011-09-01 16:36:27 +02:00
|
|
|
|
|
|
|
|
updateThreadBox();
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 15:17:14 +02:00
|
|
|
QByteArray ThreadsHandler::pidForGroupId(const QByteArray &groupId) const
|
|
|
|
|
{
|
|
|
|
|
return m_pidForGroupId[groupId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::notifyGroupCreated(const QByteArray &groupId, const QByteArray &pid)
|
|
|
|
|
{
|
|
|
|
|
m_pidForGroupId[groupId] = pid;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 16:41:15 +02:00
|
|
|
void ThreadsHandler::foreachThread(const std::function<void (ThreadItem *)> &func)
|
|
|
|
|
{
|
|
|
|
|
forEachItemAtLevel<ThreadItem *>(1, func);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
void ThreadsHandler::updateThread(const ThreadData &threadData)
|
2010-07-02 10:58:47 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
if (ThreadItem *item = itemForThreadId(this, threadData.id))
|
|
|
|
|
item->mergeThreadData(threadData);
|
|
|
|
|
else
|
|
|
|
|
rootItem()->appendChild(new ThreadItem(this, threadData));
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::removeThread(ThreadId threadId)
|
|
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
if (ThreadItem *item = itemForThreadId(this, threadId))
|
|
|
|
|
delete takeItem(item);
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void ThreadsHandler::setThreads(const Threads &threads)
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
auto root = new ThreadItem(this);
|
|
|
|
|
for (int i = 0, n = threads.size(); i < n; ++i)
|
|
|
|
|
root->appendChild(new ThreadItem(this, threads.at(i)));
|
|
|
|
|
rootItem()->removeChildren();
|
|
|
|
|
setRootItem(root);
|
2011-04-18 16:40:59 +02:00
|
|
|
m_resetLocationScheduled = false;
|
2011-09-01 16:36:27 +02:00
|
|
|
updateThreadBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::updateThreadBox()
|
|
|
|
|
{
|
|
|
|
|
QStringList list;
|
2016-05-04 16:41:15 +02:00
|
|
|
foreachThread([&list](ThreadItem *item) {
|
2016-04-29 09:39:44 +02:00
|
|
|
list.append(QString::fromLatin1("#%1 %2").arg(item->threadData.id.raw()).arg(item->threadData.name));
|
2016-05-04 16:41:15 +02:00
|
|
|
});
|
2015-06-12 11:55:57 +02:00
|
|
|
Internal::setThreadBoxContents(list, indexForThreadId(this, m_currentId));
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
ThreadData ThreadsHandler::thread(ThreadId id) const
|
|
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
if (ThreadItem *item = itemForThreadId(this, id))
|
2016-04-29 09:39:44 +02:00
|
|
|
return item->threadData;
|
2015-06-12 11:55:57 +02:00
|
|
|
return ThreadData();
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
void ThreadsHandler::removeAll()
|
|
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
rootItem()->removeChildren();
|
2015-06-12 15:17:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ThreadsHandler::notifyGroupExited(const QByteArray &groupId)
|
|
|
|
|
{
|
|
|
|
|
QList<ThreadItem *> list;
|
2016-05-04 16:41:15 +02:00
|
|
|
foreachThread([&list, groupId](ThreadItem *item) {
|
2016-04-29 09:39:44 +02:00
|
|
|
if (item->threadData.groupId == groupId)
|
2015-06-12 15:17:14 +02:00
|
|
|
list.append(item);
|
2016-05-04 16:41:15 +02:00
|
|
|
});
|
2015-06-12 15:17:14 +02:00
|
|
|
foreach (ThreadItem *item, list)
|
|
|
|
|
delete takeItem(item);
|
|
|
|
|
|
|
|
|
|
m_pidForGroupId.remove(groupId);
|
|
|
|
|
return m_pidForGroupId.isEmpty();
|
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()
|
|
|
|
|
{
|
2016-05-04 16:41:15 +02:00
|
|
|
foreachThread([](ThreadItem *item) { item->notifyRunning(); });
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
void ThreadsHandler::notifyRunning(ThreadId threadId)
|
2012-10-19 16:37:57 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
if (ThreadItem *item = itemForThreadId(this, threadId))
|
|
|
|
|
item->notifyRunning();
|
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()
|
|
|
|
|
{
|
2016-05-04 16:41:15 +02:00
|
|
|
foreachThread([](ThreadItem *item) { item->notifyStopped(); });
|
2012-10-19 16:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:55:57 +02:00
|
|
|
void ThreadsHandler::notifyStopped(ThreadId threadId)
|
2012-10-19 16:37:57 +02:00
|
|
|
{
|
2015-06-12 11:55:57 +02:00
|
|
|
if (ThreadItem *item = itemForThreadId(this, threadId))
|
|
|
|
|
item->notifyStopped();
|
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
|
|
|
|
2015-10-15 17:57:39 +02:00
|
|
|
const QVector<GdbMi> items = data["threads"].children();
|
2015-02-19 16:44:58 +01:00
|
|
|
const int n = int(items.size());
|
2010-11-08 17:15:33 +01:00
|
|
|
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"];
|
2015-06-12 11:55:57 +02:00
|
|
|
m_currentId = current.isValid() ? ThreadId(current.data().toLongLong()) : ThreadId();
|
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
|