2023-01-04 07:11:28 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2023 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
|
|
|
|
#include "ThreadModel.h"
|
|
|
|
|
|
|
|
#include "QtUtils.h"
|
|
|
|
|
|
|
|
ThreadModel::ThreadModel(DebugInterface& cpu, QObject* parent)
|
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
, m_cpu(cpu)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ThreadModel::rowCount(const QModelIndex&) const
|
|
|
|
{
|
2021-10-08 11:12:03 +00:00
|
|
|
return m_cpu.GetThreadList().size();
|
2023-01-04 07:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ThreadModel::columnCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return ThreadModel::COLUMN_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ThreadModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
2021-10-08 11:12:03 +00:00
|
|
|
const auto threads = m_cpu.GetThreadList();
|
|
|
|
auto* const thread = threads.at(index.row()).get();
|
|
|
|
|
2023-01-04 07:11:28 +00:00
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case ThreadModel::ID:
|
2021-10-08 11:12:03 +00:00
|
|
|
return thread->TID();
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::PC:
|
|
|
|
{
|
2021-10-08 11:12:03 +00:00
|
|
|
if (thread->Status() == ThreadStatus::THS_RUN)
|
2023-01-04 07:11:28 +00:00
|
|
|
return QtUtils::FilledQStringFromValue(m_cpu.getPC(), 16);
|
2021-10-08 11:12:03 +00:00
|
|
|
|
|
|
|
return QtUtils::FilledQStringFromValue(thread->PC(), 16);
|
2023-01-04 07:11:28 +00:00
|
|
|
}
|
|
|
|
case ThreadModel::ENTRY:
|
2021-10-08 11:12:03 +00:00
|
|
|
return QtUtils::FilledQStringFromValue(thread->EntryPoint(), 16);
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::PRIORITY:
|
2021-10-08 11:12:03 +00:00
|
|
|
return QString::number(thread->Priority());
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::STATE:
|
|
|
|
{
|
2021-10-08 11:12:03 +00:00
|
|
|
const auto& state = ThreadStateStrings.find(thread->Status());
|
2023-01-04 07:11:28 +00:00
|
|
|
if (state != ThreadStateStrings.end())
|
|
|
|
return state->second;
|
2021-10-08 11:12:03 +00:00
|
|
|
|
|
|
|
return tr("INVALID");
|
2023-01-04 07:11:28 +00:00
|
|
|
}
|
|
|
|
case ThreadModel::WAIT_TYPE:
|
|
|
|
{
|
2021-10-08 11:12:03 +00:00
|
|
|
const auto& waitType = ThreadWaitStrings.find(thread->Wait());
|
2023-01-04 07:11:28 +00:00
|
|
|
if (waitType != ThreadWaitStrings.end())
|
|
|
|
return waitType->second;
|
2021-10-08 11:12:03 +00:00
|
|
|
|
|
|
|
return tr("INVALID");
|
2023-01-04 07:11:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (role == Qt::UserRole)
|
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case ThreadModel::ID:
|
2021-10-08 11:12:03 +00:00
|
|
|
return thread->TID();
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::PC:
|
|
|
|
{
|
2021-10-08 11:12:03 +00:00
|
|
|
if (thread->Status() == ThreadStatus::THS_RUN)
|
2023-01-04 07:11:28 +00:00
|
|
|
return m_cpu.getPC();
|
2021-10-08 11:12:03 +00:00
|
|
|
|
|
|
|
return thread->PC();
|
2023-01-04 07:11:28 +00:00
|
|
|
}
|
|
|
|
case ThreadModel::ENTRY:
|
2021-10-08 11:12:03 +00:00
|
|
|
return thread->EntryPoint();
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::PRIORITY:
|
2021-10-08 11:12:03 +00:00
|
|
|
return thread->Priority();
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::STATE:
|
2021-10-08 11:12:03 +00:00
|
|
|
return static_cast<u32>(thread->Status());
|
2023-01-04 07:11:28 +00:00
|
|
|
case ThreadModel::WAIT_TYPE:
|
2021-10-08 11:12:03 +00:00
|
|
|
return static_cast<u32>(thread->Wait());
|
2023-01-04 07:11:28 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ThreadModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
switch (section)
|
|
|
|
{
|
|
|
|
case ThreadColumns::ID:
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Warning: short space limit. Abbreviate if needed.
|
2023-01-04 07:11:28 +00:00
|
|
|
return tr("ID");
|
|
|
|
case ThreadColumns::PC:
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Warning: short space limit. Abbreviate if needed. PC = Program Counter (location where the CPU is executing).
|
2023-01-04 07:11:28 +00:00
|
|
|
return tr("PC");
|
|
|
|
case ThreadColumns::ENTRY:
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Warning: short space limit. Abbreviate if needed.
|
2023-01-04 07:11:28 +00:00
|
|
|
return tr("ENTRY");
|
|
|
|
case ThreadColumns::PRIORITY:
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Warning: short space limit. Abbreviate if needed.
|
2023-01-04 07:11:28 +00:00
|
|
|
return tr("PRIORITY");
|
|
|
|
case ThreadColumns::STATE:
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Warning: short space limit. Abbreviate if needed.
|
2023-01-04 07:11:28 +00:00
|
|
|
return tr("STATE");
|
|
|
|
case ThreadColumns::WAIT_TYPE:
|
2023-03-18 21:14:55 +00:00
|
|
|
//: Warning: short space limit. Abbreviate if needed.
|
2023-01-04 07:11:28 +00:00
|
|
|
return tr("WAIT TYPE");
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadModel::refreshData()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
2023-01-07 02:35:57 +00:00
|
|
|
}
|