chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 00:06:02 +00:00
|
|
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-04-08 16:28:54 +00:00
|
|
|
|
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"
|
2016-04-08 16:28:54 +00:00
|
|
|
|
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"
|
2021-04-24 04:50:04 +00:00
|
|
|
#include "core/hle/kernel/k_class_token.h"
|
2021-04-24 09:40:31 +00:00
|
|
|
#include "core/hle/kernel/k_handle_table.h"
|
2021-04-24 05:04:28 +00:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2021-01-30 06:48:06 +00:00
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
2020-12-03 02:08:35 +00:00
|
|
|
#include "core/hle/kernel/k_scheduler.h"
|
2020-12-22 06:36:53 +00:00
|
|
|
#include "core/hle/kernel/k_synchronization_object.h"
|
2020-12-31 07:01:08 +00:00
|
|
|
#include "core/hle/kernel/k_thread.h"
|
2020-12-30 09:14:02 +00:00
|
|
|
#include "core/hle/kernel/svc_common.h"
|
2021-01-03 09:49:18 +00:00
|
|
|
#include "core/hle/kernel/svc_types.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::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;
|
2020-07-19 07:00:34 +00:00
|
|
|
return theme == QStringLiteral("qdarkstyle") ||
|
|
|
|
theme == QStringLiteral("qdarkstyle_midnight_blue") ||
|
|
|
|
theme == QStringLiteral("colorful_dark") ||
|
|
|
|
theme == QStringLiteral("colorful_midnight_blue");
|
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;
|
|
|
|
}
|
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList(
|
|
|
|
Core::System& system) {
|
2016-04-08 16:28:54 +00:00
|
|
|
std::vector<std::unique_ptr<WaitTreeThread>> item_list;
|
2018-05-05 16:08:16 +00:00
|
|
|
std::size_t row = 0;
|
2021-04-04 02:11:46 +00:00
|
|
|
auto add_threads = [&](const std::vector<Kernel::KThread*>& threads) {
|
2018-05-05 16:08:16 +00:00
|
|
|
for (std::size_t i = 0; i < threads.size(); ++i) {
|
2022-01-18 00:41:06 +00:00
|
|
|
if (threads[i]->GetThreadType() == Kernel::ThreadType::User) {
|
2021-09-03 01:40:55 +00:00
|
|
|
item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i], system));
|
2021-01-25 06:55:08 +00:00
|
|
|
item_list.back()->row = row;
|
|
|
|
}
|
2018-05-05 16:08:16 +00:00
|
|
|
++row;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-03 02:08:35 +00:00
|
|
|
add_threads(system.GlobalSchedulerContext().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;
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:44:08 +00:00
|
|
|
WaitTreeMutexInfo::WaitTreeMutexInfo(VAddr mutex_address_, const Kernel::KHandleTable& handle_table,
|
2021-09-03 01:40:55 +00:00
|
|
|
Core::System& system_)
|
2022-06-14 09:44:08 +00:00
|
|
|
: mutex_address{mutex_address_}, system{system_} {
|
2021-09-03 01:40:55 +00:00
|
|
|
mutex_value = system.Memory().Read32(mutex_address);
|
2020-12-30 09:14:02 +00:00
|
|
|
owner_handle = static_cast<Kernel::Handle>(mutex_value & Kernel::Svc::HandleWaitMask);
|
2021-04-21 05:18:56 +00:00
|
|
|
owner = handle_table.GetObject<Kernel::KThread>(owner_handle).GetPointerUnsafe();
|
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 {
|
2020-12-30 09:14:02 +00:00
|
|
|
const bool has_waiters = (mutex_value & Kernel::Svc::HandleWaitMask) != 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) {
|
2021-09-03 01:40:55 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeThread>(*owner, system));
|
2019-05-19 04:47:34 +00:00
|
|
|
}
|
2018-04-20 20:52:06 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:44:08 +00:00
|
|
|
WaitTreeCallstack::WaitTreeCallstack(const Kernel::KThread& thread_, Core::System& system_)
|
|
|
|
: thread{thread_}, system{system_} {}
|
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;
|
|
|
|
|
2022-01-18 00:41:06 +00:00
|
|
|
if (thread.GetThreadType() != Kernel::ThreadType::User) {
|
2021-01-25 06:55:08 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
auto backtrace = Core::ARM_Interface::GetBacktraceFromContext(system, 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-12-22 06:36:53 +00:00
|
|
|
WaitTreeSynchronizationObject::WaitTreeSynchronizationObject(
|
2022-06-14 09:44:08 +00:00
|
|
|
const Kernel::KSynchronizationObject& object_, Core::System& system_)
|
|
|
|
: object{object_}, system{system_} {}
|
2020-02-11 14:46:25 +00:00
|
|
|
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 {
|
2021-04-24 04:50:04 +00:00
|
|
|
return tr("[%1] %2 %3")
|
|
|
|
.arg(object.GetId())
|
|
|
|
.arg(QString::fromStdString(object.GetTypeObj().GetName()),
|
|
|
|
QString::fromStdString(object.GetName()));
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 14:46:25 +00:00
|
|
|
std::unique_ptr<WaitTreeSynchronizationObject> WaitTreeSynchronizationObject::make(
|
2021-09-03 01:40:55 +00:00
|
|
|
const Kernel::KSynchronizationObject& object, Core::System& system) {
|
2021-04-24 04:50:04 +00:00
|
|
|
const auto type =
|
|
|
|
static_cast<Kernel::KClassTokenGenerator::ObjectType>(object.GetTypeObj().GetClassToken());
|
|
|
|
switch (type) {
|
|
|
|
case Kernel::KClassTokenGenerator::ObjectType::KReadableEvent:
|
2021-09-03 01:40:55 +00:00
|
|
|
return std::make_unique<WaitTreeEvent>(static_cast<const Kernel::KReadableEvent&>(object),
|
|
|
|
system);
|
2021-04-24 04:50:04 +00:00
|
|
|
case Kernel::KClassTokenGenerator::ObjectType::KThread:
|
2021-09-03 01:40:55 +00:00
|
|
|
return std::make_unique<WaitTreeThread>(static_cast<const Kernel::KThread&>(object),
|
|
|
|
system);
|
2016-04-08 16:28:54 +00:00
|
|
|
default:
|
2021-09-03 01:40:55 +00:00
|
|
|
return std::make_unique<WaitTreeSynchronizationObject>(object, system);
|
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;
|
|
|
|
|
2021-04-24 04:50:04 +00:00
|
|
|
auto threads = object.GetWaitingThreadsForDebugging();
|
2016-04-08 16:28:54 +00:00
|
|
|
if (threads.empty()) {
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("waited by no thread")));
|
|
|
|
} else {
|
2021-09-03 01:40:55 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeThreadList>(std::move(threads), system));
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
2021-04-24 04:50:04 +00:00
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-12-22 06:36:53 +00:00
|
|
|
WaitTreeObjectList::WaitTreeObjectList(const std::vector<Kernel::KSynchronizationObject*>& list,
|
2021-09-03 01:40:55 +00:00
|
|
|
bool w_all, Core::System& system_)
|
|
|
|
: object_list(list), wait_all(w_all), system{system_} {}
|
2016-04-08 16:28:54 +00:00
|
|
|
|
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());
|
2021-09-03 01:40:55 +00:00
|
|
|
std::transform(object_list.begin(), object_list.end(), list.begin(), [this](const auto& t) {
|
|
|
|
return WaitTreeSynchronizationObject::make(*t, system);
|
|
|
|
});
|
2016-04-08 16:28:54 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
WaitTreeThread::WaitTreeThread(const Kernel::KThread& thread, Core::System& system_)
|
|
|
|
: WaitTreeSynchronizationObject(thread, system_), system{system_} {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeThread::~WaitTreeThread() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QString WaitTreeThread::GetText() const {
|
2020-12-31 07:01:08 +00:00
|
|
|
const auto& thread = static_cast<const Kernel::KThread&>(object);
|
2016-04-08 16:28:54 +00:00
|
|
|
QString status;
|
2020-12-28 21:16:43 +00:00
|
|
|
switch (thread.GetState()) {
|
|
|
|
case Kernel::ThreadState::Runnable:
|
2021-01-20 21:42:27 +00:00
|
|
|
if (!thread.IsSuspended()) {
|
|
|
|
status = tr("runnable");
|
2020-03-07 17:07:04 +00:00
|
|
|
} else {
|
|
|
|
status = tr("paused");
|
|
|
|
}
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
2020-12-28 21:16:43 +00:00
|
|
|
case Kernel::ThreadState::Waiting:
|
2021-01-10 22:29:02 +00: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 17:25:27 +00:00
|
|
|
break;
|
2020-12-28 21:16:43 +00:00
|
|
|
case Kernel::ThreadState::Initialized:
|
|
|
|
status = tr("initialized");
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
2020-12-28 21:16:43 +00:00
|
|
|
case Kernel::ThreadState::Terminated:
|
|
|
|
status = tr("terminated");
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
2021-01-10 09:02:46 +00:00
|
|
|
default:
|
|
|
|
status = tr("unknown");
|
|
|
|
break;
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
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
|
|
|
|
2020-12-31 07:01:08 +00:00
|
|
|
const auto& thread = static_cast<const Kernel::KThread&>(object);
|
2020-12-28 21:16:43 +00:00
|
|
|
switch (thread.GetState()) {
|
|
|
|
case Kernel::ThreadState::Runnable:
|
2021-01-20 21:42:27 +00:00
|
|
|
if (!thread.IsSuspended()) {
|
|
|
|
return QColor(WaitTreeColors[0][color_index]);
|
2020-03-07 17:07:04 +00:00
|
|
|
} else {
|
2020-11-15 06:37:45 +00:00
|
|
|
return QColor(WaitTreeColors[2][color_index]);
|
2020-03-07 17:07:04 +00:00
|
|
|
}
|
2020-12-28 21:16:43 +00:00
|
|
|
case Kernel::ThreadState::Waiting:
|
2021-01-10 22:29:02 +00: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 21:16:43 +00:00
|
|
|
case Kernel::ThreadState::Initialized:
|
2020-11-15 06:37:45 +00:00
|
|
|
return QColor(WaitTreeColors[7][color_index]);
|
2020-12-28 21:16:43 +00:00
|
|
|
case Kernel::ThreadState::Terminated:
|
2020-11-15 06:37:45 +00:00
|
|
|
return QColor(WaitTreeColors[8][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
|
|
|
|
2020-12-31 07:01:08 +00:00
|
|
|
const auto& thread = static_cast<const Kernel::KThread&>(object);
|
2016-04-08 16:28:54 +00:00
|
|
|
|
|
|
|
QString processor;
|
2021-01-20 21:42:27 +00:00
|
|
|
switch (thread.GetActiveCore()) {
|
2021-01-03 09:49:18 +00:00
|
|
|
case Kernel::Svc::IdealCoreUseProcessValue:
|
2018-12-28 02:14:59 +00:00
|
|
|
processor = tr("ideal");
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-01-20 21:42:27 +00:00
|
|
|
processor = tr("core %1").arg(thread.GetActiveCore());
|
2016-04-08 16:28:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("processor = %1").arg(processor)));
|
2021-01-20 21:42:27 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
|
|
|
tr("ideal core = %1").arg(thread.GetIdealCoreForDebugging())));
|
2020-11-17 05:02:45 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
|
|
|
tr("affinity mask = %1").arg(thread.GetAffinityMask().GetAffinityMask())));
|
2018-10-03 22:47:57 +00:00
|
|
|
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())
|
2020-12-30 09:14:02 +00:00
|
|
|
.arg(thread.GetBasePriority())));
|
2016-04-08 16:28:54 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
2020-12-03 02:08:35 +00:00
|
|
|
tr("last running ticks = %1").arg(thread.GetLastScheduledTick())));
|
2016-04-08 16:28:54 +00:00
|
|
|
|
2020-12-30 09:14:02 +00:00
|
|
|
const VAddr mutex_wait_address = thread.GetMutexWaitAddressForDebugging();
|
2018-10-03 22:47:57 +00:00
|
|
|
if (mutex_wait_address != 0) {
|
2019-03-06 02:52:19 +00:00
|
|
|
const auto& handle_table = thread.GetOwnerProcess()->GetHandleTable();
|
2021-09-03 01:40:55 +00:00
|
|
|
list.push_back(
|
|
|
|
std::make_unique<WaitTreeMutexInfo>(mutex_wait_address, handle_table, system));
|
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
|
|
|
|
2021-01-10 22:29:02 +00:00
|
|
|
if (thread.GetState() == Kernel::ThreadState::Waiting &&
|
|
|
|
thread.GetWaitReasonForDebugging() ==
|
|
|
|
Kernel::ThreadWaitReasonForDebugging::Synchronization) {
|
2020-12-22 06:36:53 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeObjectList>(thread.GetWaitObjectsForDebugging(),
|
2021-09-03 01:40:55 +00:00
|
|
|
thread.IsCancellable(), system));
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
list.push_back(std::make_unique<WaitTreeCallstack>(thread, system));
|
2018-05-19 21:52:49 +00:00
|
|
|
|
2016-04-08 16:28:54 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:44:08 +00:00
|
|
|
WaitTreeEvent::WaitTreeEvent(const Kernel::KReadableEvent& object_, Core::System& system_)
|
|
|
|
: WaitTreeSynchronizationObject(object_, system_) {}
|
2018-08-31 16:21:34 +00:00
|
|
|
WaitTreeEvent::~WaitTreeEvent() = default;
|
2016-04-08 16:28:54 +00:00
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
WaitTreeThreadList::WaitTreeThreadList(std::vector<Kernel::KThread*>&& list, Core::System& system_)
|
|
|
|
: thread_list(std::move(list)), system{system_} {}
|
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(),
|
2021-09-03 01:40:55 +00:00
|
|
|
[this](const auto& t) { return std::make_unique<WaitTreeThread>(*t, system); });
|
2016-04-08 16:28:54 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
WaitTreeModel::WaitTreeModel(Core::System& system_, QObject* parent)
|
|
|
|
: QAbstractItemModel(parent), system{system_} {}
|
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() {
|
2021-09-03 01:40:55 +00:00
|
|
|
thread_items = WaitTreeItem::MakeThreadItemList(system);
|
2016-04-08 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 01:40:55 +00:00
|
|
|
WaitTreeWidget::WaitTreeWidget(Core::System& system_, QWidget* parent)
|
|
|
|
: QDockWidget(tr("&Wait Tree"), parent), system{system_} {
|
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() {
|
2021-09-03 01:40:55 +00:00
|
|
|
if (!system.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) {
|
2021-09-03 01:40:55 +00:00
|
|
|
model = new WaitTreeModel(system, this);
|
2016-04-08 16:28:54 +00:00
|
|
|
view->setModel(model);
|
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitTreeWidget::OnEmulationStopping() {
|
|
|
|
view->setModel(nullptr);
|
|
|
|
delete model;
|
|
|
|
setEnabled(false);
|
|
|
|
}
|