all repos — mgba @ 691600902c18fbee18ba8ab12cefed8403b3c7ae

mGBA Game Boy Advance Emulator

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 "GameController.h"
 9
10using namespace QGBA;
11
12DebuggerController::DebuggerController(GameController* controller, mDebugger* debugger, QObject* parent)
13	: QObject(parent)
14	, m_debugger(debugger)
15	, m_gameController(controller)
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		attachInternal();
29		m_gameController->setDebugger(m_debugger);
30		mDebuggerEnter(m_debugger, DEBUGGER_ENTER_ATTACHED, 0);
31	} else {
32		QObject::disconnect(m_autoattach);
33		m_autoattach = connect(m_gameController, &GameController::gameStarted, this, &DebuggerController::attach);
34	}
35}
36
37void DebuggerController::detach() {
38	QObject::disconnect(m_autoattach);
39	if (!isAttached()) {
40		return;
41	}
42	GameController::Interrupter interrupter(m_gameController);
43	shutdownInternal();
44	m_gameController->setDebugger(nullptr);
45}
46
47void DebuggerController::breakInto() {
48	if (!isAttached()) {
49		return;
50	}
51	GameController::Interrupter interrupter(m_gameController);
52	mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0);
53}
54
55void DebuggerController::shutdown() {
56	QObject::disconnect(m_autoattach);
57	if (!isAttached()) {
58		return;
59	}
60	GameController::Interrupter interrupter(m_gameController);
61	shutdownInternal();
62}
63
64void DebuggerController::attachInternal() {
65	// No default implementation
66}
67
68void DebuggerController::shutdownInternal() {
69	// No default implementation
70}