2016-04-08 16:28:54 +00:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-07-18 10:22:03 +00:00
|
|
|
#include <array>
|
2020-03-20 18:05:47 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2018-01-12 03:33:56 +00:00
|
|
|
#include "yuzu/debugger/wait_tree.h"
|
2020-07-18 10:22:03 +00:00
|
|
|
#include "yuzu/uisettings.h"
|
2018-01-12 03:33:56 +00:00
|
|
|
#include "yuzu/util/util.h"
|
2016-04-08 16:28:54 +00:00
|
|
|
|
2018-07-24 08:06:33 +00:00
|
|
|
#include "common/assert.h"
|
2020-03-20 18:05:47 +00:00
|
|
|
#include "core/arm/arm_interface.h"
|
2018-02-18 20:17:16 +00:00
|
|
|
#include "core/core.h"
|
2018-04-20 20:52:06 +00:00
|
|
|
#include "core/hle/kernel/handle_table.h"
|
2016-04-08 16:28:54 +00:00
|
|
|
#include "core/hle/kernel/mutex.h"
|
2018-10-20 18:34:41 +00:00
|
|
|
#include "core/hle/kernel/process.h"
|
2018-11-27 14:18:29 +00:00
|
|
|
#include "core/hle/kernel/readable_event.h"
|
2018-08-31 16:21:34 +00:00
|
|
|
#include "core/hle/kernel/scheduler.h"
|
2020-02-11 14:46:25 +00:00
|
|
|
#include "core/hle/kernel/synchronization_object.h"
|
2016-04-08 16:28:54 +00:00
|
|
|
#include "core/hle/kernel/thread.h"
|
2018-09-20 23:28:48 +00:00
|
|
|
#include "core/memory.h"
|
2016-04-08 16:28:54 +00:00
|
|
|
|
2020-07-18 10:22:03 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr std::array<std::array<Qt::GlobalColor, 2>, 10> WaitTreeColors{{
|
|
|
|
{Qt::GlobalColor::darkGreen, Qt::GlobalColor::green},
|
|
|
|
{Qt::GlobalColor::darkGreen, Qt::GlobalColor::green},
|
|
|
|
{Qt::GlobalColor::darkBlue, Qt::GlobalColor::cyan},
|
|
|
|
{Qt::GlobalColor::lightGray, Qt::GlobalColor::lightGray},
|
|
|
|
{Qt::GlobalColor::lightGray, Qt::GlobalColor::lightGray},
|
|
|
|
{Qt::GlobalColor::darkRed, Qt::GlobalColor::red},
|
|
|
|
{Qt::GlobalColor::darkYellow, Qt::GlobalColor::yellow},
|
|
|
|
{Qt::GlobalColor::red, Qt::GlobalColor::red},
|
|
|
|
{Qt::GlobalColor::darkCyan, Qt::GlobalColor::cyan},
|
|
|
|
{Qt::GlobalColor::gray, Qt::GlobalColor::gray},
|
|
|
|
}};
|
|
|
|
|
|
|
|
bool IsDarkTheme() {
|
2020-07-18 15:02:41 +00:00
|
|
|
const auto& theme = UISettings::values.theme;
|
|
|
|
return theme == QStringLiteral("qdarkstyle") || theme == QStringLiteral("colorful_dark");
|
2020-07-18 10:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeItem::WaitTreeItem() = default;
|
2018-08-06 16:58:46 +00:00
|
|
|
WaitTreeItem::~WaitTreeItem() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QColor WaitTreeItem::GetColor() const {
|
2020-07-18 10:22:03 +00:00
|
|
|
if (IsDarkTheme()) {
|
|
|
|
return QColor(Qt::GlobalColor::white);
|
|
|
|
} else {
|
|
|
|
return QColor(Qt::GlobalColor::black);
|
|
|
|
}
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeItem::GetChildren() const {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeItem::Expand() {
|
|
|
|
if (IsExpandable() && !expanded) {
|
|
|
|
children = GetChildren();
|
|
|
|
for (std::size_t i = 0; i < children.size(); ++i) {
|
|
|
|
children[i]->parent = this;
|
|
|
|
children[i]->row = i;
|
|
|
|
}
|
|
|
|
expanded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitTreeItem* WaitTreeItem::Parent() const {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::unique_ptr<WaitTreeItem>>& WaitTreeItem::Children() const {
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WaitTreeItem::IsExpandable() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t WaitTreeItem::Row() const {
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList() {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeThread>> item_list;
|
2018-05-05 16:08:16 +00:00
|
|
|
std::size_t row = 0;
|
2019-11-25 01:15:51 +00:00
|
|
|
auto add_threads = [&](const std::vector<std::shared_ptr<Kernel::Thread>>& threads) {
|
2018-05-05 16:08:16 +00:00
|
|
|
for (std::size_t i = 0; i < threads.size(); ++i) {
|
2020-02-25 02:04:12 +00:00
|
|
|
if (!threads[i]->IsHLEThread()) {
|
|
|
|
item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i]));
|
|
|
|
item_list.back()->row = row;
|
|
|
|
}
|
2018-05-05 16:08:16 +00:00
|
|
|
++row;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-15 13:25:11 +00:00
|
|
|
const auto& system = Core::System::GetInstance();
|
2019-03-29 21:12:02 +00:00
|
|
|
add_threads(system.GlobalScheduler().GetThreadList());
|
2018-05-05 16:08:16 +00:00
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
return item_list;
|
|
|
|
}
|
|
|
|
|
2018-12-05 20:59:48 +00:00
|
|
|
WaitTreeText::WaitTreeText(QString t) : text(std::move(t)) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeText::~WaitTreeText() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QString WaitTreeText::GetText() const {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2019-03-06 02:52:19 +00:00
|
|
|
WaitTreeMutexInfo::WaitTreeMutexInfo(VAddr mutex_address, const Kernel::HandleTable& handle_table)
|
|
|
|
: mutex_address(mutex_address) {
|
2019-11-26 21:29:34 +00:00
|
|
|
mutex_value = Core::System::GetInstance().Memory().Read32(mutex_address);
|
2018-04-20 20:52:06 +00:00
|
|
|
owner_handle = static_cast<Kernel::Handle>(mutex_value & Kernel::Mutex::MutexOwnerMask);
|
2018-08-28 16:30:33 +00:00
|
|
|
owner = handle_table.Get<Kernel::Thread>(owner_handle);
|
2018-04-20 20:52:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeMutexInfo::~WaitTreeMutexInfo() = default;
|
|
|
|
|
2018-04-20 20:52:06 +00:00
|
|
|
QString WaitTreeMutexInfo::GetText() const {
|
2019-05-19 04:47:34 +00:00
|
|
|
return tr("waiting for mutex 0x%1").arg(mutex_address, 16, 16, QLatin1Char{'0'});
|
2018-04-20 20:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeMutexInfo::GetChildren() const {
|
2019-05-19 04:47:34 +00:00
|
|
|
const bool has_waiters = (mutex_value & Kernel::Mutex::MutexHasWaitersFlag) != 0;
|
2018-04-20 20:52:06 +00:00
|
|
|
|
2019-05-19 04:47:34 +00:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list;
|
2018-04-20 20:52:06 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("has waiters: %1").arg(has_waiters)));
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
2019-05-19 04:47:34 +00:00
|
|
|
tr("owner handle: 0x%1").arg(owner_handle, 8, 16, QLatin1Char{'0'})));
|
|
|
|
if (owner != nullptr) {
|
2018-04-20 20:52:06 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeThread>(*owner));
|
2019-05-19 04:47:34 +00:00
|
|
|
}
|
2018-04-20 20:52:06 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-05-19 21:52:49 +00:00
|
|
|
WaitTreeCallstack::WaitTreeCallstack(const Kernel::Thread& thread) : thread(thread) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeCallstack::~WaitTreeCallstack() = default;
|
2018-05-19 21:52:49 +00:00
|
|
|
|
|
|
|
QString WaitTreeCallstack::GetText() const {
|
|
|
|
return tr("Call stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeCallstack::GetChildren() const {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list;
|
|
|
|
|
2020-03-20 18:05:47 +00:00
|
|
|
if (thread.IsHLEThread()) {
|
|
|
|
return list;
|
|
|
|
}
|
2018-05-19 21:52:49 +00:00
|
|
|
|
2020-03-20 18:05:47 +00:00
|
|
|
if (thread.GetOwnerProcess() == nullptr || !thread.GetOwnerProcess()->Is64BitProcess()) {
|
|
|
|
return list;
|
|
|
|
}
|
2019-05-19 04:47:34 +00:00
|
|
|
|
2020-05-08 22:53:13 +00:00
|
|
|
auto backtrace = Core::ARM_Interface::GetBacktraceFromContext(Core::System::GetInstance(),
|
|
|
|
thread.GetContext64());
|
2019-05-19 04:47:34 +00:00
|
|
|
|
2020-03-20 18:05:47 +00:00
|
|
|
for (auto& entry : backtrace) {
|
|
|
|
std::string s = fmt::format("{:20}{:016X} {:016X} {:016X} {}", entry.module, entry.address,
|
2020-05-08 22:53:13 +00:00
|
|
|
entry.original_address, entry.offset, entry.name);
|
2020-03-20 18:05:47 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(QString::fromStdString(s)));
|
2018-05-19 21:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
WaitTreeSynchronizationObject::WaitTreeSynchronizationObject(const Kernel::SynchronizationObject& o)
|
|
|
|
: object(o) {}
|
|
|
|
WaitTreeSynchronizationObject::~WaitTreeSynchronizationObject() = default;
|
2018-08-31 16:21:34 +00:00
|
|
|
|
|
|
|
WaitTreeExpandableItem::WaitTreeExpandableItem() = default;
|
|
|
|
WaitTreeExpandableItem::~WaitTreeExpandableItem() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
bool WaitTreeExpandableItem::IsExpandable() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
QString WaitTreeSynchronizationObject::GetText() const {
|
2016-04-08 16:28:54 +00:00
|
|
|
return tr("[%1]%2 %3")
|
|
|
|
.arg(object.GetObjectId())
|
|
|
|
.arg(QString::fromStdString(object.GetTypeName()),
|
|
|
|
QString::fromStdString(object.GetName()));
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
std::unique_ptr<WaitTreeSynchronizationObject> WaitTreeSynchronizationObject::make(
|
|
|
|
const Kernel::SynchronizationObject& object) {
|
2016-04-08 16:28:54 +00:00
|
|
|
switch (object.GetHandleType()) {
|
2018-12-04 03:50:16 +00:00
|
|
|
case Kernel::HandleType::ReadableEvent:
|
2018-11-27 14:18:29 +00:00
|
|
|
return std::make_unique<WaitTreeEvent>(static_cast<const Kernel::ReadableEvent&>(object));
|
2016-04-08 16:28:54 +00:00
|
|
|
case Kernel::HandleType::Thread:
|
|
|
|
return std::make_unique<WaitTreeThread>(static_cast<const Kernel::Thread&>(object));
|
|
|
|
default:
|
2020-02-11 14:46:25 +00:00
|
|
|
return std::make_unique<WaitTreeSynchronizationObject>(object);
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeSynchronizationObject::GetChildren() const {
|
2016-04-08 16:28:54 +00:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list;
|
|
|
|
|
|
|
|
const auto& threads = object.GetWaitingThreads();
|
|
|
|
if (threads.empty()) {
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("waited by no thread")));
|
|
|
|
} else {
|
|
|
|
list.push_back(std::make_unique<WaitTreeThreadList>(threads));
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
WaitTreeObjectList::WaitTreeObjectList(
|
|
|
|
const std::vector<std::shared_ptr<Kernel::SynchronizationObject>>& list, bool w_all)
|
2016-04-08 16:28:54 +00:00
|
|
|
: object_list(list), wait_all(w_all) {}
|
|
|
|
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeObjectList::~WaitTreeObjectList() = default;
|
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
QString WaitTreeObjectList::GetText() const {
|
|
|
|
if (wait_all)
|
|
|
|
return tr("waiting for all objects");
|
|
|
|
return tr("waiting for one of the following objects");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeObjectList::GetChildren() const {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list(object_list.size());
|
|
|
|
std::transform(object_list.begin(), object_list.end(), list.begin(),
|
2020-02-11 14:46:25 +00:00
|
|
|
[](const auto& t) { return WaitTreeSynchronizationObject::make(*t); });
|
2016-04-08 16:28:54 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
WaitTreeThread::WaitTreeThread(const Kernel::Thread& thread)
|
|
|
|
: WaitTreeSynchronizationObject(thread) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeThread::~WaitTreeThread() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QString WaitTreeThread::GetText() const {
|
|
|
|
const auto& thread = static_cast<const Kernel::Thread&>(object);
|
|
|
|
QString status;
|
2018-10-03 22:47:57 +00:00
|
|
|
switch (thread.GetStatus()) {
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Running:
|
2016-04-08 16:28:54 +00:00
|
|
|
status = tr("running");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Ready:
|
2020-03-07 17:07:04 +00:00
|
|
|
if (!thread.IsPaused()) {
|
2020-03-12 20:48:43 +00:00
|
|
|
if (thread.WasRunning()) {
|
|
|
|
status = tr("running");
|
|
|
|
} else {
|
|
|
|
status = tr("ready");
|
|
|
|
}
|
2020-03-07 17:07:04 +00:00
|
|
|
} else {
|
|
|
|
status = tr("paused");
|
|
|
|
}
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
2018-12-03 17:25:27 +00:00
|
|
|
case Kernel::ThreadStatus::Paused:
|
|
|
|
status = tr("paused");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitHLEEvent:
|
2018-03-18 23:45:20 +00:00
|
|
|
status = tr("waiting for HLE return");
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitSleep:
|
2016-04-08 16:28:54 +00:00
|
|
|
status = tr("sleeping");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitIPC:
|
2018-07-25 19:47:35 +00:00
|
|
|
status = tr("waiting for IPC reply");
|
|
|
|
break;
|
2019-04-17 11:21:19 +00:00
|
|
|
case Kernel::ThreadStatus::WaitSynch:
|
2016-04-08 16:28:54 +00:00
|
|
|
status = tr("waiting for objects");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitMutex:
|
2018-04-20 20:52:06 +00:00
|
|
|
status = tr("waiting for mutex");
|
|
|
|
break;
|
2019-03-13 23:55:04 +00:00
|
|
|
case Kernel::ThreadStatus::WaitCondVar:
|
|
|
|
status = tr("waiting for condition variable");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitArb:
|
2018-06-21 07:40:29 +00:00
|
|
|
status = tr("waiting for address arbiter");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Dormant:
|
2016-04-08 16:28:54 +00:00
|
|
|
status = tr("dormant");
|
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Dead:
|
2016-04-08 16:28:54 +00:00
|
|
|
status = tr("dead");
|
|
|
|
break;
|
|
|
|
}
|
2018-10-03 22:47:57 +00:00
|
|
|
|
2020-03-02 04:46:10 +00:00
|
|
|
const auto& context = thread.GetContext64();
|
2018-10-03 22:47:57 +00:00
|
|
|
const QString pc_info = tr(" PC = 0x%1 LR = 0x%2")
|
2019-05-19 04:47:34 +00:00
|
|
|
.arg(context.pc, 8, 16, QLatin1Char{'0'})
|
|
|
|
.arg(context.cpu_registers[30], 8, 16, QLatin1Char{'0'});
|
2020-02-11 14:46:25 +00:00
|
|
|
return QStringLiteral("%1%2 (%3) ")
|
|
|
|
.arg(WaitTreeSynchronizationObject::GetText(), pc_info, status);
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QColor WaitTreeThread::GetColor() const {
|
2020-07-18 15:02:41 +00:00
|
|
|
const std::size_t color_index = IsDarkTheme() ? 1 : 0;
|
2020-07-18 10:22:03 +00:00
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
const auto& thread = static_cast<const Kernel::Thread&>(object);
|
2018-10-03 22:47:57 +00:00
|
|
|
switch (thread.GetStatus()) {
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Running:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[0][color_index]);
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Ready:
|
2020-03-07 17:07:04 +00:00
|
|
|
if (!thread.IsPaused()) {
|
2020-03-12 20:48:43 +00:00
|
|
|
if (thread.WasRunning()) {
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[1][color_index]);
|
2020-03-12 20:48:43 +00:00
|
|
|
} else {
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[2][color_index]);
|
2020-03-12 20:48:43 +00:00
|
|
|
}
|
2020-03-07 17:07:04 +00:00
|
|
|
} else {
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[3][color_index]);
|
2020-03-07 17:07:04 +00:00
|
|
|
}
|
2018-12-04 07:25:34 +00:00
|
|
|
case Kernel::ThreadStatus::Paused:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[4][color_index]);
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitHLEEvent:
|
|
|
|
case Kernel::ThreadStatus::WaitIPC:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[5][color_index]);
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitSleep:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[6][color_index]);
|
2019-04-17 11:21:19 +00:00
|
|
|
case Kernel::ThreadStatus::WaitSynch:
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitMutex:
|
2019-03-13 23:55:04 +00:00
|
|
|
case Kernel::ThreadStatus::WaitCondVar:
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::WaitArb:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[7][color_index]);
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Dormant:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[8][color_index]);
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadStatus::Dead:
|
2020-07-18 10:22:03 +00:00
|
|
|
return QColor(WaitTreeColors[9][color_index]);
|
2016-04-08 16:28:54 +00:00
|
|
|
default:
|
|
|
|
return WaitTreeItem::GetColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThread::GetChildren() const {
|
2020-02-11 14:46:25 +00:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeSynchronizationObject::GetChildren());
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
const auto& thread = static_cast<const Kernel::Thread&>(object);
|
|
|
|
|
|
|
|
QString processor;
|
2018-10-03 22:47:57 +00:00
|
|
|
switch (thread.GetProcessorID()) {
|
2018-12-28 02:14:59 +00:00
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_IDEAL:
|
|
|
|
processor = tr("ideal");
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
2018-09-13 19:57:45 +00:00
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_0:
|
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_1:
|
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_2:
|
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_3:
|
2018-10-03 22:47:57 +00:00
|
|
|
processor = tr("core %1").arg(thread.GetProcessorID());
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-10-03 22:47:57 +00:00
|
|
|
processor = tr("Unknown processor %1").arg(thread.GetProcessorID());
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("processor = %1").arg(processor)));
|
2018-05-10 23:12:46 +00:00
|
|
|
list.push_back(
|
2018-10-03 22:47:57 +00:00
|
|
|
std::make_unique<WaitTreeText>(tr("ideal core = %1").arg(thread.GetIdealCore())));
|
|
|
|
list.push_back(
|
|
|
|
std::make_unique<WaitTreeText>(tr("affinity mask = %1").arg(thread.GetAffinityMask())));
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("thread id = %1").arg(thread.GetThreadID())));
|
2016-04-08 16:28:54 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("priority = %1(current) / %2(normal)")
|
2018-10-03 22:47:57 +00:00
|
|
|
.arg(thread.GetPriority())
|
|
|
|
.arg(thread.GetNominalPriority())));
|
2016-04-08 16:28:54 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
2018-10-03 22:47:57 +00:00
|
|
|
tr("last running ticks = %1").arg(thread.GetLastRunningTicks())));
|
2016-04-08 16:28:54 +00:00
|
|
|
|
2018-10-03 22:47:57 +00:00
|
|
|
const VAddr mutex_wait_address = thread.GetMutexWaitAddress();
|
|
|
|
if (mutex_wait_address != 0) {
|
2019-03-06 02:52:19 +00:00
|
|
|
const auto& handle_table = thread.GetOwnerProcess()->GetHandleTable();
|
|
|
|
list.push_back(std::make_unique<WaitTreeMutexInfo>(mutex_wait_address, handle_table));
|
2018-10-03 22:47:57 +00:00
|
|
|
} else {
|
2018-04-20 20:52:06 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("not waiting for mutex")));
|
2018-10-03 22:47:57 +00:00
|
|
|
}
|
2018-04-20 20:52:06 +00:00
|
|
|
|
2019-04-17 11:21:19 +00:00
|
|
|
if (thread.GetStatus() == Kernel::ThreadStatus::WaitSynch) {
|
2020-02-11 14:46:25 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeObjectList>(thread.GetSynchronizationObjects(),
|
2020-04-01 21:28:49 +00:00
|
|
|
thread.IsWaitingSync()));
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-19 21:52:49 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeCallstack>(thread));
|
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
WaitTreeEvent::WaitTreeEvent(const Kernel::ReadableEvent& object)
|
|
|
|
: WaitTreeSynchronizationObject(object) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeEvent::~WaitTreeEvent() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
2019-11-25 01:15:51 +00:00
|
|
|
WaitTreeThreadList::WaitTreeThreadList(const std::vector<std::shared_ptr<Kernel::Thread>>& list)
|
2016-04-08 16:28:54 +00:00
|
|
|
: thread_list(list) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeThreadList::~WaitTreeThreadList() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QString WaitTreeThreadList::GetText() const {
|
|
|
|
return tr("waited by thread");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThreadList::GetChildren() const {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list(thread_list.size());
|
|
|
|
std::transform(thread_list.begin(), thread_list.end(), list.begin(),
|
|
|
|
[](const auto& t) { return std::make_unique<WaitTreeThread>(*t); });
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitTreeModel::WaitTreeModel(QObject* parent) : QAbstractItemModel(parent) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeModel::~WaitTreeModel() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QModelIndex WaitTreeModel::index(int row, int column, const QModelIndex& parent) const {
|
|
|
|
if (!hasIndex(row, column, parent))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
if (parent.isValid()) {
|
|
|
|
WaitTreeItem* parent_item = static_cast<WaitTreeItem*>(parent.internalPointer());
|
|
|
|
parent_item->Expand();
|
|
|
|
return createIndex(row, column, parent_item->Children()[row].get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return createIndex(row, column, thread_items[row].get());
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex WaitTreeModel::parent(const QModelIndex& index) const {
|
|
|
|
if (!index.isValid())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
WaitTreeItem* parent_item = static_cast<WaitTreeItem*>(index.internalPointer())->Parent();
|
|
|
|
if (!parent_item) {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
return createIndex(static_cast<int>(parent_item->Row()), 0, parent_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int WaitTreeModel::rowCount(const QModelIndex& parent) const {
|
|
|
|
if (!parent.isValid())
|
|
|
|
return static_cast<int>(thread_items.size());
|
|
|
|
|
|
|
|
WaitTreeItem* parent_item = static_cast<WaitTreeItem*>(parent.internalPointer());
|
|
|
|
parent_item->Expand();
|
|
|
|
return static_cast<int>(parent_item->Children().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
int WaitTreeModel::columnCount(const QModelIndex&) const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant WaitTreeModel::data(const QModelIndex& index, int role) const {
|
|
|
|
if (!index.isValid())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return static_cast<WaitTreeItem*>(index.internalPointer())->GetText();
|
|
|
|
case Qt::ForegroundRole:
|
|
|
|
return static_cast<WaitTreeItem*>(index.internalPointer())->GetColor();
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeModel::ClearItems() {
|
|
|
|
thread_items.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeModel::InitItems() {
|
|
|
|
thread_items = WaitTreeItem::MakeThreadItemList();
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitTreeWidget::WaitTreeWidget(QWidget* parent) : QDockWidget(tr("Wait Tree"), parent) {
|
2019-05-19 04:47:34 +00:00
|
|
|
setObjectName(QStringLiteral("WaitTreeWidget"));
|
2016-04-08 16:28:54 +00:00
|
|
|
view = new QTreeView(this);
|
|
|
|
view->setHeaderHidden(true);
|
|
|
|
setWidget(view);
|
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeWidget::~WaitTreeWidget() = default;
|
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
void WaitTreeWidget::OnDebugModeEntered() {
|
2016-12-16 00:01:48 +00:00
|
|
|
if (!Core::System::GetInstance().IsPoweredOn())
|
2016-04-08 16:28:54 +00:00
|
|
|
return;
|
|
|
|
model->InitItems();
|
|
|
|
view->setModel(model);
|
|
|
|
setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeWidget::OnDebugModeLeft() {
|
|
|
|
setEnabled(false);
|
|
|
|
view->setModel(nullptr);
|
|
|
|
model->ClearItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeWidget::OnEmulationStarting(EmuThread* emu_thread) {
|
|
|
|
model = new WaitTreeModel(this);
|
|
|
|
view->setModel(model);
|
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeWidget::OnEmulationStopping() {
|
|
|
|
view->setModel(nullptr);
|
|
|
|
delete model;
|
|
|
|
setEnabled(false);
|
|
|
|
}
|