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"
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
#include "debuggeractions.h"
|
2011-09-01 16:36:27 +02:00
|
|
|
#include "debuggercore.h"
|
2016-07-18 12:36:31 +02:00
|
|
|
#include "debuggerengine.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>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <utils/basetreeview.h>
|
2012-10-19 16:37:57 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <utils/savedaction.h>
|
2012-10-19 16:37:57 +02:00
|
|
|
|
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>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <QMenu>
|
2015-06-12 11:55:57 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
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
|
|
|
{}
|
|
|
|
|
|
2018-07-23 22:28:49 +02:00
|
|
|
QVariant data(int column, int role) const override
|
2015-06-12 11:55:57 +02:00
|
|
|
{
|
|
|
|
|
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-06-27 14:38:36 +02:00
|
|
|
return threadData.id == handler->currentThread() ? Icons::LOCATION.icon()
|
|
|
|
|
: Icons::EMPTY.icon();
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 22:28:49 +02:00
|
|
|
Qt::ItemFlags flags(int column) const override
|
2015-06-12 11:55:57 +02:00
|
|
|
{
|
2018-07-23 22:28:49 +02:00
|
|
|
return threadData.stopped ? TreeItem::flags(column) : Qt::ItemFlags({});
|
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
|
|
|
*/
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
ThreadsHandler::ThreadsHandler(DebuggerEngine *engine)
|
|
|
|
|
: m_engine(engine)
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
2013-08-19 13:30:10 +02:00
|
|
|
setObjectName(QLatin1String("ThreadsModel"));
|
2015-06-12 11:55:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
bool ThreadsHandler::setData(const QModelIndex &idx, const QVariant &data, int role)
|
|
|
|
|
{
|
|
|
|
|
if (role == BaseTreeView::ItemActivatedRole) {
|
|
|
|
|
ThreadId id = ThreadId(idx.data(ThreadData::IdRole).toLongLong());
|
|
|
|
|
m_engine->selectThread(id);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == BaseTreeView::ItemViewEventRole) {
|
2016-09-29 15:49:34 +03:00
|
|
|
ItemViewEvent ev = data.value<ItemViewEvent>();
|
|
|
|
|
|
|
|
|
|
if (ev.as<QContextMenuEvent>()) {
|
|
|
|
|
auto menu = new QMenu;
|
|
|
|
|
menu->addAction(action(SettingsDialog));
|
|
|
|
|
menu->popup(ev.globalPos());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-07-18 12:36:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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; };
|
2016-06-24 09:36:42 +02:00
|
|
|
return handler->findItemAtLevel<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);
|
2017-02-07 08:53:00 +01:00
|
|
|
return item ? handler->rootItem()->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
|
|
|
{
|
2016-06-27 13:46:46 +02:00
|
|
|
rootItem()->sortChildren([order, column](const ThreadItem *item1, const ThreadItem *item2) -> bool {
|
|
|
|
|
const QVariant v1 = item1->threadPart(column);
|
|
|
|
|
const QVariant v2 = 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-06-27 13:46:46 +02:00
|
|
|
return 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
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QString ThreadsHandler::pidForGroupId(const QString &groupId) const
|
2015-06-12 15:17:14 +02:00
|
|
|
{
|
|
|
|
|
return m_pidForGroupId[groupId];
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void ThreadsHandler::notifyGroupCreated(const QString &groupId, const QString &pid)
|
2015-06-12 15:17:14 +02:00
|
|
|
{
|
|
|
|
|
m_pidForGroupId[groupId] = pid;
|
|
|
|
|
}
|
|
|
|
|
|
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))
|
2016-07-04 15:53:53 +02:00
|
|
|
destroyItem(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-06-24 09:36:42 +02:00
|
|
|
forItemsAtLevel<1>([&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
|
|
|
});
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
m_engine->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
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
bool ThreadsHandler::notifyGroupExited(const QString &groupId)
|
2015-06-12 15:17:14 +02:00
|
|
|
{
|
|
|
|
|
QList<ThreadItem *> list;
|
2016-06-24 09:36:42 +02:00
|
|
|
forItemsAtLevel<1>([&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)
|
2016-07-04 15:53:53 +02:00
|
|
|
destroyItem(item);
|
2015-06-12 15:17:14 +02:00
|
|
|
|
|
|
|
|
m_pidForGroupId.remove(groupId);
|
|
|
|
|
return m_pidForGroupId.isEmpty();
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void ThreadsHandler::notifyRunning(const QString &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-06-24 09:36:42 +02:00
|
|
|
forItemsAtLevel<1>([](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
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void ThreadsHandler::notifyStopped(const QString &data)
|
2012-10-19 16:37:57 +02:00
|
|
|
{
|
|
|
|
|
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-06-24 09:36:42 +02:00
|
|
|
forItemsAtLevel<1>([](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());
|
2016-06-07 17:04:53 +02:00
|
|
|
thread.targetId = item["target-id"].data();
|
|
|
|
|
thread.details = item["details"].data();
|
|
|
|
|
thread.core = item["core"].data();
|
|
|
|
|
thread.state = item["state"].data();
|
2013-06-06 13:18:47 +02:00
|
|
|
thread.address = frame["addr"].toAddress();
|
2016-06-07 17:04:53 +02:00
|
|
|
thread.function = frame["func"].data();
|
|
|
|
|
thread.fileName = frame["fullname"].data();
|
2013-05-07 12:09:54 +02:00
|
|
|
thread.lineNumber = frame["line"].toInt();
|
2016-06-07 17:04:53 +02:00
|
|
|
thread.module = frame["from"].data();
|
|
|
|
|
thread.name = item["name"].data();
|
|
|
|
|
thread.stopped = thread.state != "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
|