all repos — mgba @ 7d009ec43c0ce59903643913609bc7766f3cb7fb

mGBA Game Boy Advance Emulator

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	GameController::Interrupter interrupter(m_gameController);
42	shutdownInternal();
43	m_gameController->setDebugger(nullptr);
44}
45
46void DebuggerController::breakInto() {
47	if (!isAttached()) {
48		return;
49	}
50	GameController::Interrupter interrupter(m_gameController);
51	mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0);
52}
53
54void DebuggerController::shutdown() {
55	QObject::disconnect(m_autoattach);
56	if (!isAttached()) {
57		return;
58	}
59	GameController::Interrupter interrupter(m_gameController);
60	shutdownInternal();
61}
62
63void DebuggerController::shutdownInternal() {
64	// No default implementation
65}