src/platform/qt/DebuggerController.cpp (view raw)
1/* Copyright (c) 2013-2014 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 "GameController.h"
9
10using namespace QGBA;
11
12DebuggerController::DebuggerController(GameController* controller, mDebugger* debugger, QObject* parent)
13 : QObject(parent)
14 , m_gameController(controller)
15 , m_debugger(debugger)
16{
17}
18
19bool DebuggerController::isAttached() {
20 return m_gameController->debugger() == m_debugger;
21}
22
23void DebuggerController::attach() {
24 if (isAttached()) {
25 return;
26 }
27 if (m_gameController->isLoaded()) {
28 m_gameController->setDebugger(m_debugger);
29 mDebuggerEnter(m_debugger, DEBUGGER_ENTER_ATTACHED, 0);
30 } else {
31 QObject::disconnect(m_autoattach);
32 m_autoattach = connect(m_gameController, SIGNAL(gameStarted(mCoreThread*, const QString&)), this, SLOT(attach()));
33 }
34}
35
36void DebuggerController::detach() {
37 QObject::disconnect(m_autoattach);
38 if (!isAttached()) {
39 return;
40 }
41 m_gameController->threadInterrupt();
42 shutdownInternal();
43 m_gameController->setDebugger(nullptr);
44 m_gameController->threadContinue();
45}
46
47void DebuggerController::breakInto() {
48 if (!isAttached()) {
49 return;
50 }
51 m_gameController->threadInterrupt();
52 mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0);
53 m_gameController->threadContinue();
54}
55
56void DebuggerController::shutdown() {
57 QObject::disconnect(m_autoattach);
58 if (!isAttached()) {
59 return;
60 }
61 m_gameController->threadInterrupt();
62 shutdownInternal();
63 m_gameController->threadContinue();
64}
65
66void DebuggerController::shutdownInternal() {
67 // No default implementation
68}