all repos — mgba @ 1a7656fe3673b527cc337354aa880217785b22aa

mGBA Game Boy Advance Emulator

Support creating the GDB stub in Qt
Jeffrey Pfau jeffrey@endrift.com
Sat, 01 Feb 2014 20:47:44 -0800
commit

1a7656fe3673b527cc337354aa880217785b22aa

parent

adcfc37db2c3b63367524a61f6a1f3d5577d6ca5

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

@@ -16,6 +16,10 @@ find_package(OpenGL REQUIRED)

set(SOURCE_FILES AudioDevice.cpp Display.cpp GameController.cpp Window.cpp) +if(USE_GDB_STUB) + set(SOURCE_FILES ${SOURCE_FILES} GDBController.cpp GDBWindow.cpp) +endif() + add_executable(QGBAc WIN32 MACOSX_BUNDLE main.cpp ${SOURCE_FILES}) qt5_use_modules(QGBAc Widgets Multimedia OpenGL)
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -51,6 +51,23 @@ GBAThreadJoin(&m_threadContext);

delete m_renderer; } +ARMDebugger* GameController::debugger() { + return m_threadContext.debugger; +} + +void GameController::setDebugger(ARMDebugger* debugger) { + bool wasPaused = isPaused(); + setPaused(true); + if (m_threadContext.debugger) { + GBADetachDebugger(m_threadContext.gba); + } + m_threadContext.debugger = debugger; + if (m_threadContext.debugger) { + GBAAttachDebugger(m_threadContext.gba, m_threadContext.debugger); + } + setPaused(wasPaused); +} + void GameController::loadGame(const QString& path) { m_rom = new QFile(path); if (!m_rom->open(QIODevice::ReadOnly)) {

@@ -64,6 +81,10 @@ m_threadContext.fd = m_rom->handle();

m_threadContext.fname = path.toLocal8Bit().constData(); GBAThreadStart(&m_threadContext); emit gameStarted(&m_threadContext); +} + +bool GameController::isPaused() { + return GBAThreadIsPaused(&m_threadContext); } void GameController::setPaused(bool paused) {
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -27,6 +27,13 @@ ~GameController();

const uint32_t* drawContext() const { return m_drawContext; } + bool isPaused(); + +#ifdef USE_GDB_STUB + ARMDebugger* debugger(); + void setDebugger(ARMDebugger*); +#endif + signals: void frameAvailable(const uint32_t*); void audioDeviceAvailable(GBAAudio*);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -5,9 +5,17 @@ #include <QKeyEvent>

#include <QKeySequence> #include <QMenuBar> +#include "GDBWindow.h" +#include "GDBController.h" + using namespace QGBA; -Window::Window(QWidget* parent) : QMainWindow(parent) { +Window::Window(QWidget* parent) + : QMainWindow(parent) +#ifdef USE_GDB_STUB + , m_gdbController(nullptr) +#endif +{ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setMinimumSize(240, 160);

@@ -66,6 +74,16 @@ m_controller->loadGame(filename);

} } +#ifdef USE_GDB_STUB +void Window::gdbOpen() { + if (!m_gdbController) { + m_gdbController = new GDBController(m_controller, this); + } + GDBWindow* window = new GDBWindow(m_gdbController); + window->show(); +} +#endif + void Window::keyPressEvent(QKeyEvent* event) { if (event->isAutoRepeat()) { QWidget::keyPressEvent(event);

@@ -134,4 +152,11 @@ frameAdvance->setDisabled(true);

connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance())); m_gameActions.append(frameAdvance); emulationMenu->addAction(frameAdvance); + + QMenu* debuggingMenu = menubar->addMenu(tr("&Debugging")); +#ifdef USE_GDB_STUB + QAction* gdbWindow = new QAction(tr("Start &GDB server"), nullptr); + connect(gdbWindow, SIGNAL(triggered()), this, SLOT(gdbOpen())); + debuggingMenu->addAction(gdbWindow); +#endif }
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -13,6 +13,8 @@ #include "Display.h"

namespace QGBA { +class GDBController; + class Window : public QMainWindow { Q_OBJECT

@@ -27,6 +29,10 @@

public slots: void selectROM(); +#ifdef USE_GDB_STUB + void gdbOpen(); +#endif + protected: virtual void keyPressEvent(QKeyEvent* event); virtual void keyReleaseEvent(QKeyEvent* event);

@@ -41,6 +47,10 @@ void setupMenu(QMenuBar*);

GameController* m_controller; Display* m_display; QList<QAction*> m_gameActions; + +#ifdef USE_GDB_STUB + GDBController* m_gdbController; +#endif }; }