src/platform/qt/DebuggerController.cpp (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "GDBController.h"
7
8#include "CoreController.h"
9
10using namespace QGBA;
11
12DebuggerController::DebuggerController(mDebugger* debugger, QObject* parent)
13 : QObject(parent)
14 , m_debugger(debugger)
15{
16}
17
18bool DebuggerController::isAttached() {
19 if (!m_gameController) {
20 return false;
21 }
22 return m_gameController->debugger() == m_debugger;
23}
24
25void DebuggerController::setController(std::shared_ptr<CoreController> controller) {
26 if (m_gameController && controller != m_gameController) {
27 m_gameController->disconnect(this);
28 detach();
29 }
30 m_gameController = controller;
31 if (controller) {
32 connect(m_gameController.get(), &CoreController::stopping, [this]() {
33 setController(nullptr);
34 });
35 if (m_autoattach) {
36 m_autoattach = false;
37 attach();
38 }
39 }
40}
41
42void DebuggerController::attach() {
43 if (isAttached()) {
44 return;
45 }
46 if (m_gameController) {
47 attachInternal();
48 m_gameController->setDebugger(m_debugger);
49 } else {
50 m_autoattach = true;
51 }
52}
53
54void DebuggerController::detach() {
55 if (!isAttached()) {
56 return;
57 }
58 if (m_gameController) {
59 CoreController::Interrupter interrupter(m_gameController);
60 shutdownInternal();
61 m_gameController->setDebugger(nullptr);
62 } else {
63 m_autoattach = false;
64 }
65}
66
67void DebuggerController::breakInto() {
68 if (!isAttached()) {
69 return;
70 }
71 CoreController::Interrupter interrupter(m_gameController);
72 mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0);
73}
74
75void DebuggerController::shutdown() {
76 m_autoattach = false;
77 if (!isAttached()) {
78 return;
79 }
80 CoreController::Interrupter interrupter(m_gameController);
81 shutdownInternal();
82}
83
84void DebuggerController::attachInternal() {
85 // No default implementation
86}
87
88void DebuggerController::shutdownInternal() {
89 // No default implementation
90}