2016-04-08 12:28:54 -04:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-01-11 22:33:56 -05:00
|
|
|
#include "yuzu/debugger/wait_tree.h"
|
|
|
|
#include "yuzu/util/util.h"
|
2016-04-08 12:28:54 -04:00
|
|
|
|
2018-07-24 04:06:33 -04:00
|
|
|
#include "common/assert.h"
|
2018-02-18 15:17:16 -05:00
|
|
|
#include "core/core.h"
|
2018-04-20 16:52:06 -04:00
|
|
|
#include "core/hle/kernel/handle_table.h"
|
2016-04-08 12:28:54 -04:00
|
|
|
#include "core/hle/kernel/mutex.h"
|
2018-10-20 14:34:41 -04:00
|
|
|
#include "core/hle/kernel/process.h"
|
2018-11-27 09:18:29 -05:00
|
|
|
#include "core/hle/kernel/readable_event.h"
|
2018-08-31 12:21:34 -04:00
|
|
|
#include "core/hle/kernel/scheduler.h"
|
2016-04-08 12:28:54 -04:00
|
|
|
#include "core/hle/kernel/thread.h"
|
2017-05-29 18:45:30 -04:00
|
|
|
#include "core/hle/kernel/wait_object.h"
|
2018-09-20 19:28:48 -04:00
|
|
|
#include "core/memory.h"
|
2016-04-08 12:28:54 -04:00
|
|
|
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeItem::WaitTreeItem() = default;
|
2018-08-06 12:58:46 -04:00
|
|
|
WaitTreeItem::~WaitTreeItem() = default;
|
2016-04-08 12:28:54 -04:00
|
|
|
|
|
|
|
QColor WaitTreeItem::GetColor() const {
|
|
|
|
return QColor(Qt::GlobalColor::black);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 12:08:16 -04:00
|
|
|
std::size_t row = 0;
|
|
|
|
auto add_threads = [&](const std::vector<Kernel::SharedPtr<Kernel::Thread>>& threads) {
|
|
|
|
for (std::size_t i = 0; i < threads.size(); ++i) {
|
|
|
|
item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i]));
|
|
|
|
item_list.back()->row = row;
|
|
|
|
++row;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-15 09:25:11 -04:00
|
|
|
const auto& system = Core::System::GetInstance();
|
|
|
|
add_threads(system.Scheduler(0).GetThreadList());
|
|
|
|
add_threads(system.Scheduler(1).GetThreadList());
|
|
|
|
add_threads(system.Scheduler(2).GetThreadList());
|
|
|
|
add_threads(system.Scheduler(3).GetThreadList());
|
2018-05-05 12:08:16 -04:00
|
|
|
|
2016-04-08 12:28:54 -04:00
|
|
|
return item_list;
|
|
|
|
}
|
|
|
|
|
2018-12-05 15:59:48 -05:00
|
|
|
WaitTreeText::WaitTreeText(QString t) : text(std::move(t)) {}
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeText::~WaitTreeText() = default;
|
2016-04-08 12:28:54 -04:00
|
|
|
|
|
|
|
QString WaitTreeText::GetText() const {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2019-03-05 21:52:19 -05:00
|
|
|
WaitTreeMutexInfo::WaitTreeMutexInfo(VAddr mutex_address, const Kernel::HandleTable& handle_table)
|
|
|
|
: mutex_address(mutex_address) {
|
2018-04-20 16:52:06 -04:00
|
|
|
mutex_value = Memory::Read32(mutex_address);
|
|
|
|
owner_handle = static_cast<Kernel::Handle>(mutex_value & Kernel::Mutex::MutexOwnerMask);
|
2018-08-28 12:30:33 -04:00
|
|
|
owner = handle_table.Get<Kernel::Thread>(owner_handle);
|
2018-04-20 16:52:06 -04:00
|
|
|
}
|
|
|
|
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeMutexInfo::~WaitTreeMutexInfo() = default;
|
|
|
|
|
2018-04-20 16:52:06 -04:00
|
|
|
QString WaitTreeMutexInfo::GetText() const {
|
|
|
|
return tr("waiting for mutex 0x%1").arg(mutex_address, 16, 16, QLatin1Char('0'));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeMutexInfo::GetChildren() const {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list;
|
|
|
|
|
|
|
|
bool has_waiters = (mutex_value & Kernel::Mutex::MutexHasWaitersFlag) != 0;
|
|
|
|
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("has waiters: %1").arg(has_waiters)));
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
|
|
|
tr("owner handle: 0x%1").arg(owner_handle, 8, 16, QLatin1Char('0'))));
|
|
|
|
if (owner != nullptr)
|
|
|
|
list.push_back(std::make_unique<WaitTreeThread>(*owner));
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-05-19 17:52:49 -04:00
|
|
|
WaitTreeCallstack::WaitTreeCallstack(const Kernel::Thread& thread) : thread(thread) {}
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeCallstack::~WaitTreeCallstack() = default;
|
2018-05-19 17:52:49 -04: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;
|
|
|
|
|
2018-09-15 09:21:06 -04:00
|
|
|
constexpr std::size_t BaseRegister = 29;
|
2018-10-03 18:47:57 -04:00
|
|
|
u64 base_pointer = thread.GetContext().cpu_registers[BaseRegister];
|
2018-05-19 17:52:49 -04:00
|
|
|
|
|
|
|
while (base_pointer != 0) {
|
|
|
|
u64 lr = Memory::Read64(base_pointer + sizeof(u64));
|
|
|
|
if (lr == 0)
|
|
|
|
break;
|
|
|
|
list.push_back(
|
|
|
|
std::make_unique<WaitTreeText>(tr("0x%1").arg(lr - sizeof(u32), 16, 16, QChar('0'))));
|
|
|
|
base_pointer = Memory::Read64(base_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-04-08 12:28:54 -04:00
|
|
|
WaitTreeWaitObject::WaitTreeWaitObject(const Kernel::WaitObject& o) : object(o) {}
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeWaitObject::~WaitTreeWaitObject() = default;
|
|
|
|
|
|
|
|
WaitTreeExpandableItem::WaitTreeExpandableItem() = default;
|
|
|
|
WaitTreeExpandableItem::~WaitTreeExpandableItem() = default;
|
2016-04-08 12:28:54 -04:00
|
|
|
|
|
|
|
bool WaitTreeExpandableItem::IsExpandable() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WaitTreeWaitObject::GetText() const {
|
|
|
|
return tr("[%1]%2 %3")
|
|
|
|
.arg(object.GetObjectId())
|
|
|
|
.arg(QString::fromStdString(object.GetTypeName()),
|
|
|
|
QString::fromStdString(object.GetName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<WaitTreeWaitObject> WaitTreeWaitObject::make(const Kernel::WaitObject& object) {
|
|
|
|
switch (object.GetHandleType()) {
|
2018-12-03 22:50:16 -05:00
|
|
|
case Kernel::HandleType::ReadableEvent:
|
2018-11-27 09:18:29 -05:00
|
|
|
return std::make_unique<WaitTreeEvent>(static_cast<const Kernel::ReadableEvent&>(object));
|
2016-04-08 12:28:54 -04:00
|
|
|
case Kernel::HandleType::Thread:
|
|
|
|
return std::make_unique<WaitTreeThread>(static_cast<const Kernel::Thread&>(object));
|
|
|
|
default:
|
|
|
|
return std::make_unique<WaitTreeWaitObject>(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeWaitObject::GetChildren() const {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WaitTreeWaitObject::GetResetTypeQString(Kernel::ResetType reset_type) {
|
|
|
|
switch (reset_type) {
|
|
|
|
case Kernel::ResetType::OneShot:
|
|
|
|
return tr("one shot");
|
|
|
|
case Kernel::ResetType::Sticky:
|
|
|
|
return tr("sticky");
|
|
|
|
}
|
2018-07-24 04:06:33 -04:00
|
|
|
UNREACHABLE();
|
|
|
|
return {};
|
2016-04-08 12:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
WaitTreeObjectList::WaitTreeObjectList(
|
|
|
|
const std::vector<Kernel::SharedPtr<Kernel::WaitObject>>& list, bool w_all)
|
|
|
|
: object_list(list), wait_all(w_all) {}
|
|
|
|
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeObjectList::~WaitTreeObjectList() = default;
|
|
|
|
|
2016-04-08 12:28:54 -04: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(),
|
|
|
|
[](const auto& t) { return WaitTreeWaitObject::make(*t); });
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitTreeThread::WaitTreeThread(const Kernel::Thread& thread) : WaitTreeWaitObject(thread) {}
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeThread::~WaitTreeThread() = default;
|
2016-04-08 12:28:54 -04:00
|
|
|
|
|
|
|
QString WaitTreeThread::GetText() const {
|
|
|
|
const auto& thread = static_cast<const Kernel::Thread&>(object);
|
|
|
|
QString status;
|
2018-10-03 18:47:57 -04:00
|
|
|
switch (thread.GetStatus()) {
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Running:
|
2016-04-08 12:28:54 -04:00
|
|
|
status = tr("running");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Ready:
|
2016-04-08 12:28:54 -04:00
|
|
|
status = tr("ready");
|
|
|
|
break;
|
2018-12-03 12:25:27 -05:00
|
|
|
case Kernel::ThreadStatus::Paused:
|
|
|
|
status = tr("paused");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitHLEEvent:
|
2018-03-18 19:45:20 -04:00
|
|
|
status = tr("waiting for HLE return");
|
2016-04-08 12:28:54 -04:00
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitSleep:
|
2016-04-08 12:28:54 -04:00
|
|
|
status = tr("sleeping");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitIPC:
|
2018-07-25 15:47:35 -04:00
|
|
|
status = tr("waiting for IPC reply");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitSynchAll:
|
|
|
|
case Kernel::ThreadStatus::WaitSynchAny:
|
2016-04-08 12:28:54 -04:00
|
|
|
status = tr("waiting for objects");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitMutex:
|
2018-04-20 16:52:06 -04:00
|
|
|
status = tr("waiting for mutex");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitArb:
|
2018-06-21 03:40:29 -04:00
|
|
|
status = tr("waiting for address arbiter");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Dormant:
|
2016-04-08 12:28:54 -04:00
|
|
|
status = tr("dormant");
|
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Dead:
|
2016-04-08 12:28:54 -04:00
|
|
|
status = tr("dead");
|
|
|
|
break;
|
|
|
|
}
|
2018-10-03 18:47:57 -04:00
|
|
|
|
|
|
|
const auto& context = thread.GetContext();
|
|
|
|
const QString pc_info = tr(" PC = 0x%1 LR = 0x%2")
|
|
|
|
.arg(context.pc, 8, 16, QLatin1Char('0'))
|
|
|
|
.arg(context.cpu_registers[30], 8, 16, QLatin1Char('0'));
|
2016-04-08 12:28:54 -04:00
|
|
|
return WaitTreeWaitObject::GetText() + pc_info + " (" + status + ") ";
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor WaitTreeThread::GetColor() const {
|
|
|
|
const auto& thread = static_cast<const Kernel::Thread&>(object);
|
2018-10-03 18:47:57 -04:00
|
|
|
switch (thread.GetStatus()) {
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Running:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::darkGreen);
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Ready:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::darkBlue);
|
2018-12-04 02:25:34 -05:00
|
|
|
case Kernel::ThreadStatus::Paused:
|
|
|
|
return QColor(Qt::GlobalColor::lightGray);
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitHLEEvent:
|
|
|
|
case Kernel::ThreadStatus::WaitIPC:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::darkRed);
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitSleep:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::darkYellow);
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::WaitSynchAll:
|
|
|
|
case Kernel::ThreadStatus::WaitSynchAny:
|
|
|
|
case Kernel::ThreadStatus::WaitMutex:
|
|
|
|
case Kernel::ThreadStatus::WaitArb:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::red);
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Dormant:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::darkCyan);
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadStatus::Dead:
|
2016-04-08 12:28:54 -04:00
|
|
|
return QColor(Qt::GlobalColor::gray);
|
|
|
|
default:
|
|
|
|
return WaitTreeItem::GetColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThread::GetChildren() const {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
|
|
|
|
|
|
|
|
const auto& thread = static_cast<const Kernel::Thread&>(object);
|
|
|
|
|
|
|
|
QString processor;
|
2018-10-03 18:47:57 -04:00
|
|
|
switch (thread.GetProcessorID()) {
|
2018-12-27 21:14:59 -05:00
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_IDEAL:
|
|
|
|
processor = tr("ideal");
|
2016-04-08 12:28:54 -04:00
|
|
|
break;
|
2018-09-13 15:57:45 -04:00
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_0:
|
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_1:
|
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_2:
|
|
|
|
case Kernel::ThreadProcessorId::THREADPROCESSORID_3:
|
2018-10-03 18:47:57 -04:00
|
|
|
processor = tr("core %1").arg(thread.GetProcessorID());
|
2016-04-08 12:28:54 -04:00
|
|
|
break;
|
|
|
|
default:
|
2018-10-03 18:47:57 -04:00
|
|
|
processor = tr("Unknown processor %1").arg(thread.GetProcessorID());
|
2016-04-08 12:28:54 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("processor = %1").arg(processor)));
|
2018-05-10 19:12:46 -04:00
|
|
|
list.push_back(
|
2018-10-03 18:47:57 -04: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 12:28:54 -04:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("priority = %1(current) / %2(normal)")
|
2018-10-03 18:47:57 -04:00
|
|
|
.arg(thread.GetPriority())
|
|
|
|
.arg(thread.GetNominalPriority())));
|
2016-04-08 12:28:54 -04:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
2018-10-03 18:47:57 -04:00
|
|
|
tr("last running ticks = %1").arg(thread.GetLastRunningTicks())));
|
2016-04-08 12:28:54 -04:00
|
|
|
|
2018-10-03 18:47:57 -04:00
|
|
|
const VAddr mutex_wait_address = thread.GetMutexWaitAddress();
|
|
|
|
if (mutex_wait_address != 0) {
|
2019-03-05 21:52:19 -05:00
|
|
|
const auto& handle_table = thread.GetOwnerProcess()->GetHandleTable();
|
|
|
|
list.push_back(std::make_unique<WaitTreeMutexInfo>(mutex_wait_address, handle_table));
|
2018-10-03 18:47:57 -04:00
|
|
|
} else {
|
2018-04-20 16:52:06 -04:00
|
|
|
list.push_back(std::make_unique<WaitTreeText>(tr("not waiting for mutex")));
|
2018-10-03 18:47:57 -04:00
|
|
|
}
|
2018-04-20 16:52:06 -04:00
|
|
|
|
2018-10-03 18:47:57 -04:00
|
|
|
if (thread.GetStatus() == Kernel::ThreadStatus::WaitSynchAny ||
|
|
|
|
thread.GetStatus() == Kernel::ThreadStatus::WaitSynchAll) {
|
|
|
|
list.push_back(std::make_unique<WaitTreeObjectList>(thread.GetWaitObjects(),
|
2016-12-14 12:13:02 -05:00
|
|
|
thread.IsSleepingOnWaitAll()));
|
2016-04-08 12:28:54 -04:00
|
|
|
}
|
|
|
|
|
2018-05-19 17:52:49 -04:00
|
|
|
list.push_back(std::make_unique<WaitTreeCallstack>(thread));
|
|
|
|
|
2016-04-08 12:28:54 -04:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-11-27 09:18:29 -05:00
|
|
|
WaitTreeEvent::WaitTreeEvent(const Kernel::ReadableEvent& object) : WaitTreeWaitObject(object) {}
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeEvent::~WaitTreeEvent() = default;
|
2016-04-08 12:28:54 -04:00
|
|
|
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeEvent::GetChildren() const {
|
|
|
|
std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
|
|
|
|
|
|
|
|
list.push_back(std::make_unique<WaitTreeText>(
|
|
|
|
tr("reset type = %1")
|
2018-11-26 18:34:07 -05:00
|
|
|
.arg(GetResetTypeQString(
|
2018-11-27 09:18:29 -05:00
|
|
|
static_cast<const Kernel::ReadableEvent&>(object).GetResetType()))));
|
2016-04-08 12:28:54 -04:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitTreeThreadList::WaitTreeThreadList(const std::vector<Kernel::SharedPtr<Kernel::Thread>>& list)
|
|
|
|
: thread_list(list) {}
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeThreadList::~WaitTreeThreadList() = default;
|
2016-04-08 12:28:54 -04: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 12:21:34 -04:00
|
|
|
WaitTreeModel::~WaitTreeModel() = default;
|
2016-04-08 12:28:54 -04: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) {
|
|
|
|
setObjectName("WaitTreeWidget");
|
|
|
|
view = new QTreeView(this);
|
|
|
|
view->setHeaderHidden(true);
|
|
|
|
setWidget(view);
|
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2018-08-31 12:21:34 -04:00
|
|
|
WaitTreeWidget::~WaitTreeWidget() = default;
|
|
|
|
|
2016-04-08 12:28:54 -04:00
|
|
|
void WaitTreeWidget::OnDebugModeEntered() {
|
2016-12-15 19:01:48 -05:00
|
|
|
if (!Core::System::GetInstance().IsPoweredOn())
|
2016-04-08 12:28:54 -04: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);
|
|
|
|
}
|