all repos — mgba @ 4731bae9e00a39c0ba2090846f16296704442514

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 "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		mDebuggerEnter(m_debugger, DEBUGGER_ENTER_ATTACHED, 0);
50	} else {
51		m_autoattach = true;
52	}
53}
54
55void DebuggerController::detach() {
56	if (!isAttached()) {
57		return;
58	}
59	if (m_gameController) {
60		CoreController::Interrupter interrupter(m_gameController);
61		shutdownInternal();
62		m_gameController->setDebugger(nullptr);
63	} else {
64		m_autoattach = false;
65	}
66}
67
68void DebuggerController::breakInto() {
69	if (!isAttached()) {
70		return;
71	}
72	CoreController::Interrupter interrupter(m_gameController);
73	mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0);
74}
75
76void DebuggerController::shutdown() {
77	m_autoattach = false;
78	if (!isAttached()) {
79		return;
80	}
81	CoreController::Interrupter interrupter(m_gameController);
82	shutdownInternal();
83}
84
85void DebuggerController::attachInternal() {
86	// No default implementation
87}
88
89void DebuggerController::shutdownInternal() {
90	// No default implementation
91}