summaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/wait_tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/debugger/wait_tree.cpp')
-rw-r--r--src/citra_qt/debugger/wait_tree.cpp417
1 files changed, 0 insertions, 417 deletions
diff --git a/src/citra_qt/debugger/wait_tree.cpp b/src/citra_qt/debugger/wait_tree.cpp
deleted file mode 100644
index eefbcb9f1..000000000
--- a/src/citra_qt/debugger/wait_tree.cpp
+++ /dev/null
@@ -1,417 +0,0 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "citra_qt/debugger/wait_tree.h"
6#include "citra_qt/util/util.h"
7
8#include "core/hle/kernel/condition_variable.h"
9#include "core/hle/kernel/event.h"
10#include "core/hle/kernel/mutex.h"
11#include "core/hle/kernel/thread.h"
12#include "core/hle/kernel/timer.h"
13#include "core/hle/kernel/wait_object.h"
14
15WaitTreeItem::~WaitTreeItem() {}
16
17QColor WaitTreeItem::GetColor() const {
18 return QColor(Qt::GlobalColor::black);
19}
20
21std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeItem::GetChildren() const {
22 return {};
23}
24
25void WaitTreeItem::Expand() {
26 if (IsExpandable() && !expanded) {
27 children = GetChildren();
28 for (std::size_t i = 0; i < children.size(); ++i) {
29 children[i]->parent = this;
30 children[i]->row = i;
31 }
32 expanded = true;
33 }
34}
35
36WaitTreeItem* WaitTreeItem::Parent() const {
37 return parent;
38}
39
40const std::vector<std::unique_ptr<WaitTreeItem>>& WaitTreeItem::Children() const {
41 return children;
42}
43
44bool WaitTreeItem::IsExpandable() const {
45 return false;
46}
47
48std::size_t WaitTreeItem::Row() const {
49 return row;
50}
51
52std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList() {
53 const auto& threads = Kernel::GetThreadList();
54 std::vector<std::unique_ptr<WaitTreeThread>> item_list;
55 item_list.reserve(threads.size());
56 for (std::size_t i = 0; i < threads.size(); ++i) {
57 item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i]));
58 item_list.back()->row = i;
59 }
60 return item_list;
61}
62
63WaitTreeText::WaitTreeText(const QString& t) : text(t) {}
64
65QString WaitTreeText::GetText() const {
66 return text;
67}
68
69WaitTreeWaitObject::WaitTreeWaitObject(const Kernel::WaitObject& o) : object(o) {}
70
71bool WaitTreeExpandableItem::IsExpandable() const {
72 return true;
73}
74
75QString WaitTreeWaitObject::GetText() const {
76 return tr("[%1]%2 %3")
77 .arg(object.GetObjectId())
78 .arg(QString::fromStdString(object.GetTypeName()),
79 QString::fromStdString(object.GetName()));
80}
81
82std::unique_ptr<WaitTreeWaitObject> WaitTreeWaitObject::make(const Kernel::WaitObject& object) {
83 switch (object.GetHandleType()) {
84 case Kernel::HandleType::Event:
85 return std::make_unique<WaitTreeEvent>(static_cast<const Kernel::Event&>(object));
86 case Kernel::HandleType::Mutex:
87 return std::make_unique<WaitTreeMutex>(static_cast<const Kernel::Mutex&>(object));
88 case Kernel::HandleType::ConditionVariable:
89 return std::make_unique<WaitTreeConditionVariable>(
90 static_cast<const Kernel::ConditionVariable&>(object));
91 case Kernel::HandleType::Timer:
92 return std::make_unique<WaitTreeTimer>(static_cast<const Kernel::Timer&>(object));
93 case Kernel::HandleType::Thread:
94 return std::make_unique<WaitTreeThread>(static_cast<const Kernel::Thread&>(object));
95 default:
96 return std::make_unique<WaitTreeWaitObject>(object);
97 }
98}
99
100std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeWaitObject::GetChildren() const {
101 std::vector<std::unique_ptr<WaitTreeItem>> list;
102
103 const auto& threads = object.GetWaitingThreads();
104 if (threads.empty()) {
105 list.push_back(std::make_unique<WaitTreeText>(tr("waited by no thread")));
106 } else {
107 list.push_back(std::make_unique<WaitTreeThreadList>(threads));
108 }
109 return list;
110}
111
112QString WaitTreeWaitObject::GetResetTypeQString(Kernel::ResetType reset_type) {
113 switch (reset_type) {
114 case Kernel::ResetType::OneShot:
115 return tr("one shot");
116 case Kernel::ResetType::Sticky:
117 return tr("sticky");
118 case Kernel::ResetType::Pulse:
119 return tr("pulse");
120 }
121}
122
123WaitTreeObjectList::WaitTreeObjectList(
124 const std::vector<Kernel::SharedPtr<Kernel::WaitObject>>& list, bool w_all)
125 : object_list(list), wait_all(w_all) {}
126
127QString WaitTreeObjectList::GetText() const {
128 if (wait_all)
129 return tr("waiting for all objects");
130 return tr("waiting for one of the following objects");
131}
132
133std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeObjectList::GetChildren() const {
134 std::vector<std::unique_ptr<WaitTreeItem>> list(object_list.size());
135 std::transform(object_list.begin(), object_list.end(), list.begin(),
136 [](const auto& t) { return WaitTreeWaitObject::make(*t); });
137 return list;
138}
139
140WaitTreeThread::WaitTreeThread(const Kernel::Thread& thread) : WaitTreeWaitObject(thread) {}
141
142QString WaitTreeThread::GetText() const {
143 const auto& thread = static_cast<const Kernel::Thread&>(object);
144 QString status;
145 switch (thread.status) {
146 case THREADSTATUS_RUNNING:
147 status = tr("running");
148 break;
149 case THREADSTATUS_READY:
150 status = tr("ready");
151 break;
152 case THREADSTATUS_WAIT_ARB:
153 status = tr("waiting for address 0x%1").arg(thread.wait_address, 8, 16, QLatin1Char('0'));
154 break;
155 case THREADSTATUS_WAIT_SLEEP:
156 status = tr("sleeping");
157 break;
158 case THREADSTATUS_WAIT_SYNCH_ALL:
159 case THREADSTATUS_WAIT_SYNCH_ANY:
160 status = tr("waiting for objects");
161 break;
162 case THREADSTATUS_DORMANT:
163 status = tr("dormant");
164 break;
165 case THREADSTATUS_DEAD:
166 status = tr("dead");
167 break;
168 }
169 QString pc_info = tr(" PC = 0x%1 LR = 0x%2")
170 .arg(thread.context.pc, 8, 16, QLatin1Char('0'))
171 .arg(thread.context.cpu_registers[31], 8, 16, QLatin1Char('0'));
172 return WaitTreeWaitObject::GetText() + pc_info + " (" + status + ") ";
173}
174
175QColor WaitTreeThread::GetColor() const {
176 const auto& thread = static_cast<const Kernel::Thread&>(object);
177 switch (thread.status) {
178 case THREADSTATUS_RUNNING:
179 return QColor(Qt::GlobalColor::darkGreen);
180 case THREADSTATUS_READY:
181 return QColor(Qt::GlobalColor::darkBlue);
182 case THREADSTATUS_WAIT_ARB:
183 return QColor(Qt::GlobalColor::darkRed);
184 case THREADSTATUS_WAIT_SLEEP:
185 return QColor(Qt::GlobalColor::darkYellow);
186 case THREADSTATUS_WAIT_SYNCH_ALL:
187 case THREADSTATUS_WAIT_SYNCH_ANY:
188 return QColor(Qt::GlobalColor::red);
189 case THREADSTATUS_DORMANT:
190 return QColor(Qt::GlobalColor::darkCyan);
191 case THREADSTATUS_DEAD:
192 return QColor(Qt::GlobalColor::gray);
193 default:
194 return WaitTreeItem::GetColor();
195 }
196}
197
198std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThread::GetChildren() const {
199 std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
200
201 const auto& thread = static_cast<const Kernel::Thread&>(object);
202
203 QString processor;
204 switch (thread.processor_id) {
205 case ThreadProcessorId::THREADPROCESSORID_DEFAULT:
206 processor = tr("default");
207 break;
208 case ThreadProcessorId::THREADPROCESSORID_0:
209 case ThreadProcessorId::THREADPROCESSORID_1:
210 case ThreadProcessorId::THREADPROCESSORID_2:
211 case ThreadProcessorId::THREADPROCESSORID_3:
212 processor = tr("core %1").arg(thread.processor_id);
213 break;
214 default:
215 processor = tr("Unknown processor %1").arg(thread.processor_id);
216 break;
217 }
218
219 list.push_back(std::make_unique<WaitTreeText>(tr("processor = %1").arg(processor)));
220 list.push_back(std::make_unique<WaitTreeText>(tr("thread id = %1").arg(thread.GetThreadId())));
221 list.push_back(std::make_unique<WaitTreeText>(tr("priority = %1(current) / %2(normal)")
222 .arg(thread.current_priority)
223 .arg(thread.nominal_priority)));
224 list.push_back(std::make_unique<WaitTreeText>(
225 tr("last running ticks = %1").arg(thread.last_running_ticks)));
226
227 if (thread.held_mutexes.empty()) {
228 list.push_back(std::make_unique<WaitTreeText>(tr("not holding mutex")));
229 } else {
230 list.push_back(std::make_unique<WaitTreeMutexList>(thread.held_mutexes));
231 }
232 if (thread.status == THREADSTATUS_WAIT_SYNCH_ANY ||
233 thread.status == THREADSTATUS_WAIT_SYNCH_ALL) {
234 list.push_back(std::make_unique<WaitTreeObjectList>(thread.wait_objects,
235 thread.IsSleepingOnWaitAll()));
236 }
237
238 return list;
239}
240
241WaitTreeEvent::WaitTreeEvent(const Kernel::Event& object) : WaitTreeWaitObject(object) {}
242
243std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeEvent::GetChildren() const {
244 std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
245
246 list.push_back(std::make_unique<WaitTreeText>(
247 tr("reset type = %1")
248 .arg(GetResetTypeQString(static_cast<const Kernel::Event&>(object).reset_type))));
249 return list;
250}
251
252WaitTreeMutex::WaitTreeMutex(const Kernel::Mutex& object) : WaitTreeWaitObject(object) {}
253
254std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeMutex::GetChildren() const {
255 std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
256
257 const auto& mutex = static_cast<const Kernel::Mutex&>(object);
258 if (mutex.GetHasWaiters()) {
259 list.push_back(std::make_unique<WaitTreeText>(tr("locked by thread:")));
260 list.push_back(std::make_unique<WaitTreeThread>(*mutex.GetHoldingThread()));
261 } else {
262 list.push_back(std::make_unique<WaitTreeText>(tr("free")));
263 }
264 return list;
265}
266
267WaitTreeConditionVariable::WaitTreeConditionVariable(const Kernel::ConditionVariable& object)
268 : WaitTreeWaitObject(object) {}
269
270std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeConditionVariable::GetChildren() const {
271 std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
272
273 const auto& condition_variable = static_cast<const Kernel::ConditionVariable&>(object);
274 list.push_back(std::make_unique<WaitTreeText>(
275 tr("available count = %1").arg(condition_variable.GetAvailableCount())));
276 return list;
277}
278
279WaitTreeTimer::WaitTreeTimer(const Kernel::Timer& object) : WaitTreeWaitObject(object) {}
280
281std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeTimer::GetChildren() const {
282 std::vector<std::unique_ptr<WaitTreeItem>> list(WaitTreeWaitObject::GetChildren());
283
284 const auto& timer = static_cast<const Kernel::Timer&>(object);
285
286 list.push_back(std::make_unique<WaitTreeText>(
287 tr("reset type = %1").arg(GetResetTypeQString(timer.reset_type))));
288 list.push_back(
289 std::make_unique<WaitTreeText>(tr("initial delay = %1").arg(timer.initial_delay)));
290 list.push_back(
291 std::make_unique<WaitTreeText>(tr("interval delay = %1").arg(timer.interval_delay)));
292 return list;
293}
294
295WaitTreeMutexList::WaitTreeMutexList(
296 const boost::container::flat_set<Kernel::SharedPtr<Kernel::Mutex>>& list)
297 : mutex_list(list) {}
298
299QString WaitTreeMutexList::GetText() const {
300 return tr("holding mutexes");
301}
302
303std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeMutexList::GetChildren() const {
304 std::vector<std::unique_ptr<WaitTreeItem>> list(mutex_list.size());
305 std::transform(mutex_list.begin(), mutex_list.end(), list.begin(),
306 [](const auto& t) { return std::make_unique<WaitTreeMutex>(*t); });
307 return list;
308}
309
310WaitTreeThreadList::WaitTreeThreadList(const std::vector<Kernel::SharedPtr<Kernel::Thread>>& list)
311 : thread_list(list) {}
312
313QString WaitTreeThreadList::GetText() const {
314 return tr("waited by thread");
315}
316
317std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThreadList::GetChildren() const {
318 std::vector<std::unique_ptr<WaitTreeItem>> list(thread_list.size());
319 std::transform(thread_list.begin(), thread_list.end(), list.begin(),
320 [](const auto& t) { return std::make_unique<WaitTreeThread>(*t); });
321 return list;
322}
323
324WaitTreeModel::WaitTreeModel(QObject* parent) : QAbstractItemModel(parent) {}
325
326QModelIndex WaitTreeModel::index(int row, int column, const QModelIndex& parent) const {
327 if (!hasIndex(row, column, parent))
328 return {};
329
330 if (parent.isValid()) {
331 WaitTreeItem* parent_item = static_cast<WaitTreeItem*>(parent.internalPointer());
332 parent_item->Expand();
333 return createIndex(row, column, parent_item->Children()[row].get());
334 }
335
336 return createIndex(row, column, thread_items[row].get());
337}
338
339QModelIndex WaitTreeModel::parent(const QModelIndex& index) const {
340 if (!index.isValid())
341 return {};
342
343 WaitTreeItem* parent_item = static_cast<WaitTreeItem*>(index.internalPointer())->Parent();
344 if (!parent_item) {
345 return QModelIndex();
346 }
347 return createIndex(static_cast<int>(parent_item->Row()), 0, parent_item);
348}
349
350int WaitTreeModel::rowCount(const QModelIndex& parent) const {
351 if (!parent.isValid())
352 return static_cast<int>(thread_items.size());
353
354 WaitTreeItem* parent_item = static_cast<WaitTreeItem*>(parent.internalPointer());
355 parent_item->Expand();
356 return static_cast<int>(parent_item->Children().size());
357}
358
359int WaitTreeModel::columnCount(const QModelIndex&) const {
360 return 1;
361}
362
363QVariant WaitTreeModel::data(const QModelIndex& index, int role) const {
364 if (!index.isValid())
365 return {};
366
367 switch (role) {
368 case Qt::DisplayRole:
369 return static_cast<WaitTreeItem*>(index.internalPointer())->GetText();
370 case Qt::ForegroundRole:
371 return static_cast<WaitTreeItem*>(index.internalPointer())->GetColor();
372 default:
373 return {};
374 }
375}
376
377void WaitTreeModel::ClearItems() {
378 thread_items.clear();
379}
380
381void WaitTreeModel::InitItems() {
382 thread_items = WaitTreeItem::MakeThreadItemList();
383}
384
385WaitTreeWidget::WaitTreeWidget(QWidget* parent) : QDockWidget(tr("Wait Tree"), parent) {
386 setObjectName("WaitTreeWidget");
387 view = new QTreeView(this);
388 view->setHeaderHidden(true);
389 setWidget(view);
390 setEnabled(false);
391}
392
393void WaitTreeWidget::OnDebugModeEntered() {
394 if (!Core::System::GetInstance().IsPoweredOn())
395 return;
396 model->InitItems();
397 view->setModel(model);
398 setEnabled(true);
399}
400
401void WaitTreeWidget::OnDebugModeLeft() {
402 setEnabled(false);
403 view->setModel(nullptr);
404 model->ClearItems();
405}
406
407void WaitTreeWidget::OnEmulationStarting(EmuThread* emu_thread) {
408 model = new WaitTreeModel(this);
409 view->setModel(model);
410 setEnabled(false);
411}
412
413void WaitTreeWidget::OnEmulationStopping() {
414 view->setModel(nullptr);
415 delete model;
416 setEnabled(false);
417}