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 : DebuggerController(controller, &m_gdbStub.d, parent)
14 , m_port(2345)
15 , m_bindAddress({ IPV4, 0 })
16{
17 GDBStubCreate(&m_gdbStub);
18}
19
20ushort GDBController::port() {
21 return m_port;
22}
23
24bool GDBController::isAttached() {
25 return m_gameController->debugger() == &m_gdbStub.d;
26}
27
28void GDBController::setPort(ushort port) {
29 m_port = port;
30}
31
32void GDBController::setBindAddress(uint32_t bindAddress) {
33 m_bindAddress.version = IPV4;
34 m_bindAddress.ipv4 = htonl(bindAddress);
35}
36
37void GDBController::listen() {
38 m_gameController->threadInterrupt();
39 if (!isAttached()) {
40 attach();
41 }
42 if (GDBStubListen(&m_gdbStub, m_port, &m_bindAddress)) {
43 emit listening();
44 } else {
45 detach();
46 emit listenFailed();
47 }
48 m_gameController->threadContinue();
49}
50
51void GDBController::shutdownInternal() {
52 GDBStubShutdown(&m_gdbStub);
53}