2016-04-08 18:28:54 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-07-18 12:22:03 +02:00
|
|
|
#include <array>
|
2020-03-20 19:05:47 +01:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2018-01-12 04:33:56 +01:00
|
|
|
#include "yuzu/debugger/wait_tree.h"
|
2020-07-18 12:22:03 +02:00
|
|
|
#include "yuzu/uisettings.h"
|
2018-01-12 04:33:56 +01:00
|
|
|
#include "yuzu/util/util.h"
|
2016-04-08 18:28:54 +02:00
|
|
|
|
2018-07-24 10:06:33 +02:00
|
|
|
#include "common/assert.h"
|
2020-03-20 19:05:47 +01:00
|
|
|
#include "core/arm/arm_interface.h"
|
2018-02-18 21:17:16 +01:00
|
|
|
#include "core/core.h"
|
2021-04-24 06:50:04 +02:00
|
|
|
#include "core/hle/kernel/k_class_token.h"
|
2021-04-24 11:40:31 +02:00
|
|
|
#include "core/hle/kernel/k_handle_table.h"
|
2021-04-24 07:04:28 +02:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2021-01-30 07:48:06 +01:00
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
2020-12-03 03:08:35 +01:00
|
|
|
#include "core/hle/kernel/k_scheduler.h"
|
2020-12-22 07:36:53 +01:00
|
|
|
#include "core/hle/kernel/k_synchronization_object.h"
|
2020-12-31 08:01:08 +01:00
|
|
|
#include "core/hle/kernel/k_thread.h"
|
2020-12-30 10:14:02 +01:00
|
|
|
#include "core/hle/kernel/svc_common.h"
|
2021-01-03 10:49:18 +01:00
|
|
|
#include "core/hle/kernel/svc_types.h"
|
2018-09-21 01:28:48 +02:00
|
|
|
#include "core/memory.h"
|
2016-04-08 18:28:54 +02:00
|
|
|
|
2020-07-18 12:22:03 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr std::array<std::array<Qt::GlobalColor, 2>, 10> WaitTreeColors{{
|
|
|
|
{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 17:02:41 +02:00
|
|
|
const auto& theme = UISettings::values.theme;
|
2020-07-19 09:00:34 +02:00
|
|
|
return theme == QStringLiteral("qdarkstyle") ||
|
|
|
|
theme == QStringLiteral("qdarkstyle_midnight_blue") ||
|
|
|
|
theme == QStringLiteral("colorful_dark") ||
|
|
|
|
theme == QStringLiteral("colorful_midnight_blue");
|
2020-07-18 12:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeItem::WaitTreeItem() = default;
|
2018-08-06 18:58:46 +02:00
|
|
|
WaitTreeItem::~WaitTreeItem() = default;
|
2016-04-08 18:28:54 +02:00
|
|
|
|
|
|
|
QColor WaitTreeItem::GetColor() const {
|
2020-07-18 12:22:03 +02:00
|
|
|
if (IsDarkTheme()) {
|
|
|
|
return QColor(Qt::GlobalColor::white);
|
|
|
|
} else {
|
|
|
|
return QColor(Qt::GlobalColor::black);
|
|
|
|
}
|
2016-04-08 18:28:54 +02: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 18:08:16 +02:00
|
|
|
std::size_t row = 0;
|
2021-04-04 04:11:46 +02:00
|
|
|
auto add_threads = [&](const std::vector<Kernel::KThread*>& threads) {
|
2018-05-05 18:08:16 +02:00
|
|
|
for (std::size_t i = 0; i < threads.size(); ++i) {
|
2021-01-25 07:55:08 +01:00
|
|
|
if (threads[i]->GetThreadTypeForDebugging() == Kernel::ThreadType::User) {
|
|
|
|
item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i]));
|
|
|
|
item_list.back()->row = row;
|
|
|
|
}
|
2018-05-05 18:08:16 +02:00
|
|
|
++row;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-15 15:25:11 +02:00
|
|
|
const auto& system = Core::System::GetInstance();
|
2020-12-03 03:08:35 +01:00
|
|
|
add_threads(system.GlobalSchedulerContext().GetThreadList());
|
2018-05-05 18:08:16 +02:00
|
|
|
|
2016-04-08 18:28:54 +02:00
|
|
|
return item_list;
|
|
|
|
}
|
|
|
|
|
2018-12-05 21:59:48 +01:00
|
|
|
WaitTreeText::WaitTreeText(QString t) : text(std::move(t)) {}
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeText::~WaitTreeText() = default;
|
2016-04-08 18:28:54 +02:00
|
|
|
|
|
|
|
QString WaitTreeText::GetText() const {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2021-04-24 11:40:31 +02:00
|
|
|
WaitTreeMutexInfo::WaitTreeMutexInfo(VAddr mutex_address, const Kernel::KHandleTable& handle_table)
|
2019-03-06 03:52:19 +01:00
|
|
|
: mutex_address(mutex_address) {
|
2019-11-26 22:29:34 +01:00
|
|
|
mutex_value = Core::System::GetInstance().Memory().Read32(mutex_address);
|
2020-12-30 10:14:02 +01:00
|
|
|
owner_handle = static_cast<Kernel::Handle>(mutex_value & Kernel::Svc::HandleWaitMask);
|
2021-04-21 07:18:56 +02:00
|
|
|
owner = handle_table.GetObject<Kernel::KThread>(owner_handle).GetPointerUnsafe();
|
2018-04-20 22:52:06 +02:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeMutexInfo::~WaitTreeMutexInfo() = default;
|
|
|
|
|
2018-04-20 22:52:06 +02:00
|
|
|
QString WaitTreeMutexInfo::GetText() const {
|
2019-05-19 06:47:34 +02:00
|
|
|
return tr("waiting for mutex 0x%1").arg(mutex_address, 16, 16, QLatin1Char{'0'});
|
2018-04-20 22:52:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeMutexInfo::GetChildren() const {
|
2020-12-30 10:14:02 +01:00
|
|
|
const bool has_waiters = (mutex_value & Kernel::Svc::HandleWaitMask) != 0;
|
2018-04-20 22:52:06 +02:00
|
|
|
|
2019-05-19 06:47:34 +02:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list;
|
2018-04-20 22:52:06 +02: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 06:47:34 +02:00
|
|
|
tr("owner handle: 0x%1").arg(owner_handle, 8, 16, QLatin1Char{'0'})));
|
|
|
|
if (owner != nullptr) {
|
2018-04-20 22:52:06 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeThread>(*owner));
|
2019-05-19 06:47:34 +02:00
|
|
|
}
|
2018-04-20 22:52:06 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-12-31 08:01:08 +01:00
|
|
|
WaitTreeCallstack::WaitTreeCallstack(const Kernel::KThread& thread) : thread(thread) {}
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeCallstack::~WaitTreeCallstack() = default;
|
2018-05-19 23:52:49 +02: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;
|
|
|
|
|
2021-01-25 07:55:08 +01:00
|
|
|
if (thread.GetThreadTypeForDebugging() != Kernel::ThreadType::User) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-03-20 19:05:47 +01:00
|
|
|
if (thread.GetOwnerProcess() == nullptr || !thread.GetOwnerProcess()->Is64BitProcess()) {
|
|
|
|
return list;
|
|
|
|
}
|
2019-05-19 06:47:34 +02:00
|
|
|
|
2020-05-09 00:53:13 +02:00
|
|
|
auto backtrace = Core::ARM_Interface::GetBacktraceFromContext(Core::System::GetInstance(),
|
|
|
|
thread.GetContext64());
|
2019-05-19 06:47:34 +02:00
|
|
|
|
2020-03-20 19:05:47 +01:00
|
|
|
for (auto& entry : backtrace) {
|
|
|
|
std::string s = fmt::format("{:20}{:016X} {:016X} {:016X} {}", entry.module, entry.address,
|
2020-05-09 00:53:13 +02:00
|
|
|
entry.original_address, entry.offset, entry.name);
|
2020-03-20 19:05:47 +01:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(QString::fromStdString(s)));
|
2018-05-19 23:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-12-22 07:36:53 +01:00
|
|
|
WaitTreeSynchronizationObject::WaitTreeSynchronizationObject(
|
|
|
|
const Kernel::KSynchronizationObject& o)
|
2020-02-11 15:46:25 +01:00
|
|
|
: object(o) {}
|
|
|
|
WaitTreeSynchronizationObject::~WaitTreeSynchronizationObject() = default;
|
2018-08-31 18:21:34 +02:00
|
|
|
|
|
|
|
WaitTreeExpandableItem::WaitTreeExpandableItem() = default;
|
|
|
|
WaitTreeExpandableItem::~WaitTreeExpandableItem() = default;
|
2016-04-08 18:28:54 +02:00
|
|
|
|
|
|
|
bool WaitTreeExpandableItem::IsExpandable() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:46:25 +01:00
|
|
|
QString WaitTreeSynchronizationObject::GetText() const {
|
2021-04-24 06:50:04 +02:00
|
|
|
return tr("[%1] %2 %3")
|
|
|
|
.arg(object.GetId())
|
|
|
|
.arg(QString::fromStdString(object.GetTypeObj().GetName()),
|
|
|
|
QString::fromStdString(object.GetName()));
|
2016-04-08 18:28:54 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 15:46:25 +01:00
|
|
|
std::unique_ptr<WaitTreeSynchronizationObject> WaitTreeSynchronizationObject::make(
|
2020-12-22 07:36:53 +01:00
|
|
|
const Kernel::KSynchronizationObject& object) {
|
2021-04-24 06:50:04 +02:00
|
|
|
const auto type =
|
|
|
|
static_cast<Kernel::KClassTokenGenerator::ObjectType>(object.GetTypeObj().GetClassToken());
|
|
|
|
switch (type) {
|
|
|
|
case Kernel::KClassTokenGenerator::ObjectType::KReadableEvent:
|
2021-01-30 07:48:06 +01:00
|
|
|
return std::make_unique<WaitTreeEvent>(static_cast<const Kernel::KReadableEvent&>(object));
|
2021-04-24 06:50:04 +02:00
|
|
|
case Kernel::KClassTokenGenerator::ObjectType::KThread:
|
2020-12-31 08:01:08 +01:00
|
|
|
return std::make_unique<WaitTreeThread>(static_cast<const Kernel::KThread&>(object));
|
2016-04-08 18:28:54 +02:00
|
|
|
default:
|
2020-02-11 15:46:25 +01:00
|
|
|
return std::make_unique<WaitTreeSynchronizationObject>(object);
|
2016-04-08 18:28:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:46:25 +01:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeSynchronizationObject::GetChildren() const {
|
2016-04-08 18:28:54 +02:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list;
|
|
|
|
|
2021-04-24 06:50:04 +02:00
|
|
|
auto threads = object.GetWaitingThreadsForDebugging();
|
2016-04-08 18:28:54 +02:00
|
|
|
if (threads.empty()) {
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("waited by no thread")));
|
|
|
|
} else {
|
2021-04-24 06:50:04 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeThreadList>(std::move(threads)));
|
2016-04-08 18:28:54 +02:00
|
|
|
}
|
2021-04-24 06:50:04 +02:00
|
|
|
|
2016-04-08 18:28:54 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-12-22 07:36:53 +01:00
|
|
|
WaitTreeObjectList::WaitTreeObjectList(const std::vector<Kernel::KSynchronizationObject*>& list,
|
|
|
|
bool w_all)
|
2016-04-08 18:28:54 +02:00
|
|
|
: object_list(list), wait_all(w_all) {}
|
|
|
|
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeObjectList::~WaitTreeObjectList() = default;
|
|
|
|
|
2016-04-08 18:28:54 +02: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 15:46:25 +01:00
|
|
|
[](const auto& t) { return WaitTreeSynchronizationObject::make(*t); });
|
2016-04-08 18:28:54 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-12-31 08:01:08 +01:00
|
|
|
WaitTreeThread::WaitTreeThread(const Kernel::KThread& thread)
|
2020-02-11 15:46:25 +01:00
|
|
|
: WaitTreeSynchronizationObject(thread) {}
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeThread::~WaitTreeThread() = default;
|
2016-04-08 18:28:54 +02:00
|
|
|
|
|
|
|
QString WaitTreeThread::GetText() const {
|
2020-12-31 08:01:08 +01:00
|
|
|
const auto& thread = static_cast<const Kernel::KThread&>(object);
|
2016-04-08 18:28:54 +02:00
|
|
|
QString status;
|
2020-12-28 22:16:43 +01:00
|
|
|
switch (thread.GetState()) {
|
|
|
|
case Kernel::ThreadState::Runnable:
|
2021-01-20 22:42:27 +01:00
|
|
|
if (!thread.IsSuspended()) {
|
|
|
|
status = tr("runnable");
|
2020-03-07 18:07:04 +01:00
|
|
|
} else {
|
|
|
|
status = tr("paused");
|
|
|
|
}
|
2016-04-08 18:28:54 +02:00
|
|
|
break;
|
2020-12-28 22:16:43 +01:00
|
|
|
case Kernel::ThreadState::Waiting:
|
2021-01-10 23:29:02 +01:00
|
|
|
switch (thread.GetWaitReasonForDebugging()) {
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Sleep:
|
|
|
|
status = tr("sleeping");
|
|
|
|
break;
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::IPC:
|
|
|
|
status = tr("waiting for IPC reply");
|
|
|
|
break;
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Synchronization:
|
|
|
|
status = tr("waiting for objects");
|
|
|
|
break;
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::ConditionVar:
|
|
|
|
status = tr("waiting for condition variable");
|
|
|
|
break;
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Arbitration:
|
|
|
|
status = tr("waiting for address arbiter");
|
|
|
|
break;
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Suspended:
|
|
|
|
status = tr("waiting for suspend resume");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = tr("waiting");
|
|
|
|
break;
|
|
|
|
}
|
2018-12-03 18:25:27 +01:00
|
|
|
break;
|
2020-12-28 22:16:43 +01:00
|
|
|
case Kernel::ThreadState::Initialized:
|
|
|
|
status = tr("initialized");
|
2016-04-08 18:28:54 +02:00
|
|
|
break;
|
2020-12-28 22:16:43 +01:00
|
|
|
case Kernel::ThreadState::Terminated:
|
|
|
|
status = tr("terminated");
|
2016-04-08 18:28:54 +02:00
|
|
|
break;
|
2021-01-10 10:02:46 +01:00
|
|
|
default:
|
|
|
|
status = tr("unknown");
|
|
|
|
break;
|
2016-04-08 18:28:54 +02:00
|
|
|
}
|
2018-10-04 00:47:57 +02:00
|
|
|
|
2020-03-02 05:46:10 +01:00
|
|
|
const auto& context = thread.GetContext64();
|
2018-10-04 00:47:57 +02:00
|
|
|
const QString pc_info = tr(" PC = 0x%1 LR = 0x%2")
|
2019-05-19 06:47:34 +02:00
|
|
|
.arg(context.pc, 8, 16, QLatin1Char{'0'})
|
|
|
|
.arg(context.cpu_registers[30], 8, 16, QLatin1Char{'0'});
|
2020-02-11 15:46:25 +01:00
|
|
|
return QStringLiteral("%1%2 (%3) ")
|
|
|
|
.arg(WaitTreeSynchronizationObject::GetText(), pc_info, status);
|
2016-04-08 18:28:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QColor WaitTreeThread::GetColor() const {
|
2020-07-18 17:02:41 +02:00
|
|
|
const std::size_t color_index = IsDarkTheme() ? 1 : 0;
|
2020-07-18 12:22:03 +02:00
|
|
|
|
2020-12-31 08:01:08 +01:00
|
|
|
const auto& thread = static_cast<const Kernel::KThread&>(object);
|
2020-12-28 22:16:43 +01:00
|
|
|
switch (thread.GetState()) {
|
|
|
|
case Kernel::ThreadState::Runnable:
|
2021-01-20 22:42:27 +01:00
|
|
|
if (!thread.IsSuspended()) {
|
|
|
|
return QColor(WaitTreeColors[0][color_index]);
|
2020-03-07 18:07:04 +01:00
|
|
|
} else {
|
2020-11-15 07:37:45 +01:00
|
|
|
return QColor(WaitTreeColors[2][color_index]);
|
2020-03-07 18:07:04 +01:00
|
|
|
}
|
2020-12-28 22:16:43 +01:00
|
|
|
case Kernel::ThreadState::Waiting:
|
2021-01-10 23:29:02 +01:00
|
|
|
switch (thread.GetWaitReasonForDebugging()) {
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::IPC:
|
|
|
|
return QColor(WaitTreeColors[4][color_index]);
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Sleep:
|
|
|
|
return QColor(WaitTreeColors[5][color_index]);
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Synchronization:
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::ConditionVar:
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Arbitration:
|
|
|
|
case Kernel::ThreadWaitReasonForDebugging::Suspended:
|
|
|
|
return QColor(WaitTreeColors[6][color_index]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QColor(WaitTreeColors[3][color_index]);
|
|
|
|
}
|
2020-12-28 22:16:43 +01:00
|
|
|
case Kernel::ThreadState::Initialized:
|
2020-11-15 07:37:45 +01:00
|
|
|
return QColor(WaitTreeColors[7][color_index]);
|
2020-12-28 22:16:43 +01:00
|
|
|
case Kernel::ThreadState::Terminated:
|
2020-11-15 07:37:45 +01:00
|
|
|
return QColor(WaitTreeColors[8][color_index]);
|
2016-04-08 18:28:54 +02:00
|
|
|
default:
|
|
|
|
return WaitTreeItem::GetColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThread::GetChildren() const {
|
2020-02-11 15:46:25 +01:00
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeSynchronizationObject::GetChildren());
|
2016-04-08 18:28:54 +02:00
|
|
|
|
2020-12-31 08:01:08 +01:00
|
|
|
const auto& thread = static_cast<const Kernel::KThread&>(object);
|
2016-04-08 18:28:54 +02:00
|
|
|
|
|
|
|
QString processor;
|
2021-01-20 22:42:27 +01:00
|
|
|
switch (thread.GetActiveCore()) {
|
2021-01-03 10:49:18 +01:00
|
|
|
case Kernel::Svc::IdealCoreUseProcessValue:
|
2018-12-28 03:14:59 +01:00
|
|
|
processor = tr("ideal");
|
2016-04-08 18:28:54 +02:00
|
|
|
break;
|
|
|
|
default:
|
2021-01-20 22:42:27 +01:00
|
|
|
processor = tr("core %1").arg(thread.GetActiveCore());
|
2016-04-08 18:28:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("processor = %1").arg(processor)));
|
2021-01-20 22:42:27 +01:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
|
|
|
tr("ideal core = %1").arg(thread.GetIdealCoreForDebugging())));
|
2020-11-17 06:02:45 +01:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
|
|
|
tr("affinity mask = %1").arg(thread.GetAffinityMask().GetAffinityMask())));
|
2018-10-04 00:47:57 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("thread id = %1").arg(thread.GetThreadID())));
|
2016-04-08 18:28:54 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("priority = %1(current) / %2(normal)")
|
2018-10-04 00:47:57 +02:00
|
|
|
.arg(thread.GetPriority())
|
2020-12-30 10:14:02 +01:00
|
|
|
.arg(thread.GetBasePriority())));
|
2016-04-08 18:28:54 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
2020-12-03 03:08:35 +01:00
|
|
|
tr("last running ticks = %1").arg(thread.GetLastScheduledTick())));
|
2016-04-08 18:28:54 +02:00
|
|
|
|
2020-12-30 10:14:02 +01:00
|
|
|
const VAddr mutex_wait_address = thread.GetMutexWaitAddressForDebugging();
|
2018-10-04 00:47:57 +02:00
|
|
|
if (mutex_wait_address != 0) {
|
2019-03-06 03:52:19 +01:00
|
|
|
const auto& handle_table = thread.GetOwnerProcess()->GetHandleTable();
|
|
|
|
list.push_back(std::make_unique<WaitTreeMutexInfo>(mutex_wait_address, handle_table));
|
2018-10-04 00:47:57 +02:00
|
|
|
} else {
|
2018-04-20 22:52:06 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("not waiting for mutex")));
|
2018-10-04 00:47:57 +02:00
|
|
|
}
|
2018-04-20 22:52:06 +02:00
|
|
|
|
2021-01-10 23:29:02 +01:00
|
|
|
if (thread.GetState() == Kernel::ThreadState::Waiting &&
|
|
|
|
thread.GetWaitReasonForDebugging() ==
|
|
|
|
Kernel::ThreadWaitReasonForDebugging::Synchronization) {
|
2020-12-22 07:36:53 +01:00
|
|
|
list.push_back(std::make_unique<WaitTreeObjectList>(thread.GetWaitObjectsForDebugging(),
|
|
|
|
thread.IsCancellable()));
|
2016-04-08 18:28:54 +02:00
|
|
|
}
|
|
|
|
|
2018-05-19 23:52:49 +02:00
|
|
|
list.push_back(std::make_unique<WaitTreeCallstack>(thread));
|
|
|
|
|
2016-04-08 18:28:54 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2021-01-30 07:48:06 +01:00
|
|
|
WaitTreeEvent::WaitTreeEvent(const Kernel::KReadableEvent& object)
|
2020-02-11 15:46:25 +01:00
|
|
|
: WaitTreeSynchronizationObject(object) {}
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeEvent::~WaitTreeEvent() = default;
|
2016-04-08 18:28:54 +02:00
|
|
|
|
2021-04-24 06:50:04 +02:00
|
|
|
WaitTreeThreadList::WaitTreeThreadList(std::vector<Kernel::KThread*>&& list)
|
|
|
|
: thread_list(std::move(list)) {}
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeThreadList::~WaitTreeThreadList() = default;
|
2016-04-08 18:28:54 +02: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 18:21:34 +02:00
|
|
|
WaitTreeModel::~WaitTreeModel() = default;
|
2016-04-08 18:28:54 +02: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();
|
|
|
|
}
|
|
|
|
|
2020-12-23 01:32:58 +01:00
|
|
|
WaitTreeWidget::WaitTreeWidget(QWidget* parent) : QDockWidget(tr("&Wait Tree"), parent) {
|
2019-05-19 06:47:34 +02:00
|
|
|
setObjectName(QStringLiteral("WaitTreeWidget"));
|
2016-04-08 18:28:54 +02:00
|
|
|
view = new QTreeView(this);
|
|
|
|
view->setHeaderHidden(true);
|
|
|
|
setWidget(view);
|
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:21:34 +02:00
|
|
|
WaitTreeWidget::~WaitTreeWidget() = default;
|
|
|
|
|
2016-04-08 18:28:54 +02:00
|
|
|
void WaitTreeWidget::OnDebugModeEntered() {
|
2016-12-16 01:01:48 +01:00
|
|
|
if (!Core::System::GetInstance().IsPoweredOn())
|
2016-04-08 18:28:54 +02: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);
|
|
|
|
}
|