all repos — mgba @ 9c92a29b28d1f81224ba28d5fc83a9481eccd5eb

mGBA Game Boy Advance Emulator

src/platform/qt/GDBController.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
12GDBController::GDBController(GameController* controller, QObject* parent)
13	: QObject(parent)
14	, m_gameController(controller)
15	, m_port(2345)
16	, m_bindAddress(0)
17{
18	GDBStubCreate(&m_gdbStub);
19}
20
21ushort GDBController::port() {
22	return m_port;
23}
24
25uint32_t GDBController::bindAddress() {
26	return m_bindAddress;
27}
28
29bool GDBController::isAttached() {
30	return m_gameController->debugger() == &m_gdbStub.d;
31}
32
33void GDBController::setPort(ushort port) {
34	m_port = port;
35}
36
37void GDBController::setBindAddress(uint32_t bindAddress) {
38	m_bindAddress = bindAddress;
39}
40
41void GDBController::attach() {
42	if (isAttached()) {
43		return;
44	}
45	m_gameController->setDebugger(&m_gdbStub.d);
46}
47
48void GDBController::detach() {
49	if (!isAttached()) {
50		return;
51	}
52	bool wasPaused = m_gameController->isPaused();
53	disconnect(m_gameController, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updateGDB()));
54	m_gameController->setPaused(true);
55	GDBStubShutdown(&m_gdbStub);
56	m_gameController->setDebugger(nullptr);
57	m_gameController->setPaused(wasPaused);
58}
59
60void GDBController::listen() {
61	if (!isAttached()) {
62		attach();
63	}
64	bool wasPaused = m_gameController->isPaused();
65	connect(m_gameController, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updateGDB()));
66	m_gameController->setPaused(true);
67	GDBStubListen(&m_gdbStub, m_port, m_bindAddress);
68	m_gameController->setPaused(wasPaused);
69}
70
71void GDBController::updateGDB() {
72	bool wasPaused = m_gameController->isPaused();
73	m_gameController->setPaused(true);
74	GDBStubUpdate(&m_gdbStub);
75	m_gameController->setPaused(wasPaused);
76}