all repos — mgba @ 4cb243f15c011264e3b4e84100f6e4a050c4a623

mGBA Game Boy Advance Emulator

Qt: Refactor out debug controller
Jeffrey Pfau jeffrey@endrift.com
Wed, 26 Oct 2016 16:41:13 -0700
commit

4cb243f15c011264e3b4e84100f6e4a050c4a623

parent

a0d223eef7c33382231510db9c851f856c891323

M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -75,6 +75,7 @@ AudioProcessor.cpp

CheatsModel.cpp CheatsView.cpp ConfigController.cpp + DebuggerController.cpp Display.cpp DisplayGL.cpp DisplayQt.cpp
A src/platform/qt/DebuggerController.cpp

@@ -0,0 +1,68 @@

+/* Copyright (c) 2013-2014 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "GDBController.h" + +#include "GameController.h" + +using namespace QGBA; + +DebuggerController::DebuggerController(GameController* controller, mDebugger* debugger, QObject* parent) + : QObject(parent) + , m_gameController(controller) + , m_debugger(debugger) +{ +} + +bool DebuggerController::isAttached() { + return m_gameController->debugger() == m_debugger; +} + +void DebuggerController::attach() { + if (isAttached()) { + return; + } + if (m_gameController->isLoaded()) { + m_gameController->setDebugger(m_debugger); + mDebuggerEnter(m_debugger, DEBUGGER_ENTER_ATTACHED, 0); + } else { + QObject::disconnect(m_autoattach); + m_autoattach = connect(m_gameController, SIGNAL(gameStarted(mCoreThread*, const QString&)), this, SLOT(attach())); + } +} + +void DebuggerController::detach() { + QObject::disconnect(m_autoattach); + if (!isAttached()) { + return; + } + m_gameController->threadInterrupt(); + shutdownInternal(); + m_gameController->setDebugger(nullptr); + m_gameController->threadContinue(); +} + +void DebuggerController::breakInto() { + if (!isAttached()) { + return; + } + m_gameController->threadInterrupt(); + mDebuggerEnter(m_debugger, DEBUGGER_ENTER_MANUAL, 0); + m_gameController->threadContinue(); +} + +void DebuggerController::shutdown() { + QObject::disconnect(m_autoattach); + if (!isAttached()) { + return; + } + m_gameController->threadInterrupt(); + shutdownInternal(); + m_gameController->threadContinue(); +} + +void DebuggerController::shutdownInternal() { + // No default implementation +}
A src/platform/qt/DebuggerController.h

@@ -0,0 +1,44 @@

+/* Copyright (c) 2013-2014 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef QGBA_DEBUGGER_CONTROLLER +#define QGBA_DEBUGGER_CONTROLLER + +#include <QObject> + +struct mDebugger; + +namespace QGBA { + +class GameController; + +class DebuggerController : public QObject { +Q_OBJECT + +public: + DebuggerController(GameController* controller, mDebugger* debugger, QObject* parent = nullptr); + +public: + bool isAttached(); + +public slots: + virtual void attach(); + virtual void detach(); + virtual void breakInto(); + virtual void shutdown(); + +protected: + virtual void shutdownInternal(); + + mDebugger* const m_debugger; + GameController* const m_gameController; + +private: + QMetaObject::Connection m_autoattach; +}; + +} + +#endif
M src/platform/qt/GDBController.cppsrc/platform/qt/GDBController.cpp

@@ -10,8 +10,7 @@

using namespace QGBA; GDBController::GDBController(GameController* controller, QObject* parent) - : QObject(parent) - , m_gameController(controller) + : DebuggerController(controller, &m_gdbStub.d, parent) , m_port(2345) , m_bindAddress({ IPV4, 0 }) {

@@ -35,30 +34,6 @@ m_bindAddress.version = IPV4;

m_bindAddress.ipv4 = htonl(bindAddress); } -void GDBController::attach() { - if (isAttached() || (m_gameController->platform() != PLATFORM_GBA && m_gameController->platform() != PLATFORM_NONE)) { - return; - } - if (m_gameController->isLoaded()) { - m_gameController->setDebugger(&m_gdbStub.d); - mDebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_ATTACHED, 0); - } else { - QObject::disconnect(m_autoattach); - m_autoattach = connect(m_gameController, SIGNAL(gameStarted(mCoreThread*, const QString&)), this, SLOT(attach())); - } -} - -void GDBController::detach() { - QObject::disconnect(m_autoattach); - if (!isAttached()) { - return; - } - m_gameController->threadInterrupt(); - GDBStubShutdown(&m_gdbStub); - m_gameController->setDebugger(nullptr); - m_gameController->threadContinue(); -} - void GDBController::listen() { m_gameController->threadInterrupt(); if (!isAttached()) {

@@ -73,11 +48,6 @@ }

m_gameController->threadContinue(); } -void GDBController::breakInto() { - if (!isAttached()) { - return; - } - m_gameController->threadInterrupt(); - mDebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_MANUAL, 0); - m_gameController->threadContinue(); +void GDBController::shutdownInternal() { + GDBStubShutdown(&m_gdbStub); }
M src/platform/qt/GDBController.hsrc/platform/qt/GDBController.h

@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef QGBA_GDB_CONTROLLER #define QGBA_GDB_CONTROLLER -#include <QObject> +#include "DebuggerController.h" #ifdef USE_GDB_STUB

@@ -18,7 +18,7 @@ namespace QGBA {

class GameController; -class GDBController : public QObject { +class GDBController : public DebuggerController { Q_OBJECT public:

@@ -31,23 +31,19 @@

public slots: void setPort(ushort port); void setBindAddress(uint32_t bindAddress); - void attach(); - void detach(); void listen(); - void breakInto(); signals: void listening(); void listenFailed(); private: + virtual void shutdownInternal() override; + GDBStub m_gdbStub; - GameController* m_gameController; ushort m_port; Address m_bindAddress; - - QMetaObject::Connection m_autoattach; }; }