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 "CoreController.h"
9 
10 using namespace QGBA;
11 
GDBController(QObject * parent)12 GDBController::GDBController(QObject* parent)
13 	: DebuggerController(&m_gdbStub.d, parent)
14 	, m_bindAddress({ IPV4, {0} })
15 {
16 	GDBStubCreate(&m_gdbStub);
17 }
18 
port()19 ushort GDBController::port() {
20 	return m_port;
21 }
22 
isAttached()23 bool GDBController::isAttached() {
24 	return m_gameController && m_gameController->debugger() == &m_gdbStub.d;
25 }
26 
setPort(ushort port)27 void GDBController::setPort(ushort port) {
28 	m_port = port;
29 }
30 
setBindAddress(const Address & address)31 void GDBController::setBindAddress(const Address& address) {
32 	m_bindAddress = address;
33 }
34 
listen()35 void GDBController::listen() {
36 	if (GDBStubListen(&m_gdbStub, m_port, &m_bindAddress)) {
37 		if (!isAttached()) {
38 			attach();
39 		}
40 		emit listening();
41 	} else {
42 		detach();
43 		emit listenFailed();
44 	}
45 }
46 
shutdownInternal()47 void GDBController::shutdownInternal() {
48 	GDBStubShutdown(&m_gdbStub);
49 }
50