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 }
36}
37
38void DebuggerController::attach() {
39 if (isAttached()) {
40 return;
41 }
42 if (m_gameController) {
43 attachInternal();
44 m_gameController->setDebugger(m_debugger);
45 mDebuggerEnter(m_debugger, DEBUGGER_ENTER_ATTACHED, 0);
46 }
47}
48
49void DebuggerController::detach() {
50 QObject::disconnect(m_autoattach);
51 if (!isAttached()) {
52 return;
53 }
54 if (m_gameController) {
55 CoreController::Interrupter interrupter(m_gameController);
56 shutdownInternal();
57 m_gameController->setDebugger(nullptr);
58 }
59}
60
61void DebuggerController::breakInto() {
62 if (!isAttached()) {
63 return;
64 }
65 CoreController::Interrupter interrupter(m_gameController);
66 mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0);
67}
68
69void DebuggerController::shutdown() {
70 QObject::disconnect(m_autoattach);
71 if (!isAttached()) {
72 return;
73 }
74 CoreController::Interrupter interrupter(m_gameController);
75 shutdownInternal();
76}
77
78void DebuggerController::attachInternal() {
79 // No default implementation
80}
81
82void DebuggerController::shutdownInternal() {
83 // No default implementation
84}