2010-05-18 12:12:22 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-05-18 12:12:22 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "threadshandler.h"
|
2010-11-08 17:15:33 +01:00
|
|
|
#include "gdb/gdbmi.h"
|
2010-05-18 12:12:22 +02:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
#include "debuggerconstants.h"
|
2011-09-01 16:36:27 +02:00
|
|
|
#include "debuggercore.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2010-07-21 13:11:03 +02:00
|
|
|
#include <QtCore/QDebug>
|
2010-07-02 14:35:41 +02:00
|
|
|
#include <QtCore/QTextStream>
|
2011-10-13 10:17:06 +02:00
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// 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:")
|
|
|
|
|
<< sep << thread.id << 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;
|
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>";
|
|
|
|
|
str.setIntegerBase(16);
|
|
|
|
|
str << "0x" << thread.address;
|
|
|
|
|
str.setIntegerBase(10);
|
|
|
|
|
}
|
|
|
|
|
str << "</table></body></html>";
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ThreadsHandler
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-02-04 15:08:31 +01:00
|
|
|
/*!
|
|
|
|
|
\struct Debugger::Internal::ThreadData
|
|
|
|
|
\brief A structure containing information about a single thread
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Debugger::Internal::ThreadsHandler
|
|
|
|
|
\brief A model to represent the running threads in a QTreeView or ComboBox
|
|
|
|
|
*/
|
|
|
|
|
|
2010-11-05 17:02:27 +01:00
|
|
|
ThreadsHandler::ThreadsHandler()
|
|
|
|
|
: m_currentIndex(0),
|
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;
|
|
|
|
|
m_contentsValid = false;
|
2011-10-13 10:17:06 +02:00
|
|
|
m_proxyModel = new QSortFilterProxyModel(this);
|
|
|
|
|
m_proxyModel->setSourceModel(this);
|
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:
|
2010-05-18 12:12:22 +02:00
|
|
|
switch (index.column()) {
|
|
|
|
|
case ThreadData::IdColumn:
|
|
|
|
|
return thread.id;
|
|
|
|
|
case ThreadData::FunctionColumn:
|
|
|
|
|
return thread.function;
|
|
|
|
|
case ThreadData::FileColumn:
|
2011-04-18 15:07:58 +02:00
|
|
|
return thread.fileName.isEmpty() ? thread.module : thread.fileName;
|
2010-05-18 12:12:22 +02:00
|
|
|
case ThreadData::LineColumn:
|
2010-06-16 11:08:54 +02:00
|
|
|
return thread.lineNumber >= 0
|
|
|
|
|
? QString::number(thread.lineNumber) : QString();
|
2010-05-18 12:12:22 +02:00
|
|
|
case ThreadData::AddressColumn:
|
2010-06-16 11:08:54 +02:00
|
|
|
return thread.address > 0
|
|
|
|
|
? QLatin1String("0x") + QString::number(thread.address, 16)
|
|
|
|
|
: QString();
|
2010-05-18 12:12:22 +02:00
|
|
|
case ThreadData::CoreColumn:
|
|
|
|
|
return thread.core;
|
|
|
|
|
case ThreadData::StateColumn:
|
|
|
|
|
return thread.state;
|
2011-09-01 16:36:27 +02:00
|
|
|
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::ComboNameColumn:
|
|
|
|
|
return QString("#%1 %2").arg(thread.id).arg(thread.name);
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
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)
|
|
|
|
|
return (index.row() == m_currentIndex) ? m_positionIcon : m_emptyIcon;
|
|
|
|
|
break;
|
|
|
|
|
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");
|
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
|
|
|
|
|
{
|
|
|
|
|
return m_contentsValid ? QAbstractTableModel::flags(index) : Qt::ItemFlags(0);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
int ThreadsHandler::currentThreadId() const
|
|
|
|
|
{
|
|
|
|
|
if (m_currentIndex < 0 || m_currentIndex >= m_threads.size())
|
|
|
|
|
return -1;
|
|
|
|
|
return m_threads[m_currentIndex].id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::setCurrentThread(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index == m_currentIndex)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-11-19 09:39:50 +01:00
|
|
|
// Emit changed for previous frame.
|
2010-05-18 12:12:22 +02:00
|
|
|
QModelIndex i = ThreadsHandler::index(m_currentIndex, 0);
|
|
|
|
|
emit dataChanged(i, i);
|
|
|
|
|
|
|
|
|
|
m_currentIndex = index;
|
|
|
|
|
|
2011-09-01 16:36:27 +02:00
|
|
|
// Emit changed for new frame.
|
2010-05-18 12:12:22 +02:00
|
|
|
i = ThreadsHandler::index(m_currentIndex, 0);
|
|
|
|
|
emit dataChanged(i, i);
|
2011-09-01 16:36:27 +02:00
|
|
|
|
|
|
|
|
updateThreadBox();
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-02 10:58:47 +02:00
|
|
|
void ThreadsHandler::setCurrentThreadId(int id)
|
|
|
|
|
{
|
|
|
|
|
const int index = indexOf(id);
|
2011-09-01 16:36:27 +02:00
|
|
|
if (index != -1)
|
2010-07-02 10:58:47 +02:00
|
|
|
setCurrentThread(index);
|
2011-09-01 16:36:27 +02:00
|
|
|
else
|
2010-07-02 10:58:47 +02:00
|
|
|
qWarning("ThreadsHandler::setCurrentThreadId: No such thread %d.", id);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-15 10:56:39 +02:00
|
|
|
int ThreadsHandler::indexOf(quint64 threadId) const
|
2010-07-02 10:58:47 +02:00
|
|
|
{
|
|
|
|
|
const int count = m_threads.size();
|
2010-11-19 09:39:50 +01:00
|
|
|
for (int i = 0; i < count; ++i)
|
2010-07-02 10:58:47 +02:00
|
|
|
if (m_threads.at(i).id == threadId)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void ThreadsHandler::setThreads(const Threads &threads)
|
2010-05-18 12:12:22 +02:00
|
|
|
{
|
|
|
|
|
m_threads = threads;
|
|
|
|
|
if (m_currentIndex >= m_threads.size())
|
2010-07-21 13:11:03 +02:00
|
|
|
m_currentIndex = -1;
|
2011-04-18 16:40:59 +02:00
|
|
|
m_resetLocationScheduled = false;
|
|
|
|
|
m_contentsValid = true;
|
|
|
|
|
reset();
|
2011-09-01 16:36:27 +02:00
|
|
|
updateThreadBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::updateThreadBox()
|
|
|
|
|
{
|
|
|
|
|
QStringList list;
|
|
|
|
|
foreach (const ThreadData &thread, m_threads)
|
|
|
|
|
list.append(QString("#%1 %2").arg(thread.id).arg(thread.name));
|
|
|
|
|
debuggerCore()->setThreads(list, m_currentIndex);
|
2010-05-18 12:12:22 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::removeAll()
|
|
|
|
|
{
|
|
|
|
|
m_threads.clear();
|
|
|
|
|
m_currentIndex = 0;
|
2011-04-18 16:40:59 +02:00
|
|
|
reset();
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::notifyRunning()
|
|
|
|
|
{
|
|
|
|
|
// Threads stopped (that is, address != 0 showing)?
|
|
|
|
|
if (m_threads.empty())
|
|
|
|
|
return;
|
|
|
|
|
if (m_threads.front().address == 0)
|
|
|
|
|
return;
|
2010-06-16 11:08:54 +02:00
|
|
|
const Threads::iterator end = m_threads.end();
|
|
|
|
|
for (Threads::iterator it = m_threads.begin(); it != end; ++it)
|
2010-05-18 12:12:22 +02:00
|
|
|
it->notifyRunning();
|
|
|
|
|
emit dataChanged(index(0, 1),
|
|
|
|
|
index(m_threads.size() - 1, ThreadData::ColumnCount - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-08 17:15:33 +01:00
|
|
|
Threads ThreadsHandler::parseGdbmiThreads(const GdbMi &data, int *currentThread)
|
|
|
|
|
{
|
|
|
|
|
// ^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"
|
|
|
|
|
const QList<GdbMi> items = data.findChild("threads").children();
|
|
|
|
|
const int n = items.size();
|
|
|
|
|
Threads threads;
|
|
|
|
|
threads.reserve(n);
|
|
|
|
|
for (int index = 0; index != n; ++index) {
|
|
|
|
|
bool ok = false;
|
|
|
|
|
const GdbMi item = items.at(index);
|
|
|
|
|
const GdbMi frame = item.findChild("frame");
|
|
|
|
|
ThreadData thread;
|
|
|
|
|
thread.id = item.findChild("id").data().toInt();
|
|
|
|
|
thread.targetId = QString::fromAscii(item.findChild("target-id").data());
|
|
|
|
|
thread.core = QString::fromLatin1(item.findChild("core").data());
|
|
|
|
|
thread.state = QString::fromLatin1(item.findChild("state").data());
|
|
|
|
|
thread.address = frame.findChild("addr").data().toULongLong(&ok, 0);
|
|
|
|
|
thread.function = QString::fromLatin1(frame.findChild("func").data());
|
|
|
|
|
thread.fileName = QString::fromLatin1(frame.findChild("fullname").data());
|
|
|
|
|
thread.lineNumber = frame.findChild("line").data().toInt();
|
2011-04-18 15:07:58 +02:00
|
|
|
thread.module = QString::fromLocal8Bit(frame.findChild("from").data());
|
2010-11-08 17:15:33 +01:00
|
|
|
// Non-GDB (Cdb2) output name here.
|
2010-11-19 09:39:50 +01:00
|
|
|
thread.name = QString::fromLatin1(frame.findChild("name").data());
|
2010-11-08 17:15:33 +01:00
|
|
|
threads.append(thread);
|
|
|
|
|
}
|
|
|
|
|
if (currentThread)
|
|
|
|
|
*currentThread = data.findChild("current-thread-id").data().toInt();
|
|
|
|
|
return threads;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-18 16:40:59 +02:00
|
|
|
void ThreadsHandler::scheduleResetLocation()
|
|
|
|
|
{
|
|
|
|
|
m_resetLocationScheduled = true;
|
|
|
|
|
m_contentsValid = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadsHandler::resetLocation()
|
|
|
|
|
{
|
|
|
|
|
if (m_resetLocationScheduled) {
|
|
|
|
|
m_resetLocationScheduled = false;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-13 10:17:06 +02:00
|
|
|
QAbstractItemModel *ThreadsHandler::model()
|
|
|
|
|
{
|
|
|
|
|
return m_proxyModel;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|