diff --git a/src/debugger/gdb-stub.c b/src/debugger/gdb-stub.c index 0b5145764..e6623fca1 100644 --- a/src/debugger/gdb-stub.c +++ b/src/debugger/gdb-stub.c @@ -449,7 +449,7 @@ void GDBStubCreate(struct GDBStub* stub) { stub->untilPoll = GDB_STUB_INTERVAL; } -int GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAddress) { +bool GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAddress) { if (!SOCKET_FAILED(stub->socket)) { GDBStubShutdown(stub); } @@ -458,7 +458,7 @@ int GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAddr if (stub->d.log) { stub->d.log(&stub->d, DEBUGGER_LOG_ERROR, "Couldn't open socket"); } - return 0; + return false; } if (!SocketSetBlocking(stub->socket, false)) { goto cleanup; @@ -468,7 +468,7 @@ int GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAddr goto cleanup; } - return 1; + return true; cleanup: if (stub->d.log) { @@ -476,7 +476,7 @@ cleanup: } SocketClose(stub->socket); stub->socket = INVALID_SOCKET; - return 0; + return false; } void GDBStubHangup(struct GDBStub* stub) { diff --git a/src/debugger/gdb-stub.h b/src/debugger/gdb-stub.h index 25b435715..97cb69b22 100644 --- a/src/debugger/gdb-stub.h +++ b/src/debugger/gdb-stub.h @@ -37,7 +37,7 @@ struct GDBStub { }; void GDBStubCreate(struct GDBStub*); -int GDBStubListen(struct GDBStub*, int port, const struct Address* bindAddress); +bool GDBStubListen(struct GDBStub*, int port, const struct Address* bindAddress); void GDBStubHangup(struct GDBStub*); void GDBStubShutdown(struct GDBStub*); diff --git a/src/platform/qt/GDBController.cpp b/src/platform/qt/GDBController.cpp index a229a3b66..68511a092 100644 --- a/src/platform/qt/GDBController.cpp +++ b/src/platform/qt/GDBController.cpp @@ -58,6 +58,11 @@ void GDBController::listen() { if (!isAttached()) { attach(); } - GDBStubListen(&m_gdbStub, m_port, &m_bindAddress); + if (GDBStubListen(&m_gdbStub, m_port, &m_bindAddress)) { + emit listening(); + } else { + detach(); + emit listenFailed(); + } m_gameController->threadContinue(); } diff --git a/src/platform/qt/GDBController.h b/src/platform/qt/GDBController.h index ebd80e571..771fabf3d 100644 --- a/src/platform/qt/GDBController.h +++ b/src/platform/qt/GDBController.h @@ -35,6 +35,10 @@ public slots: void detach(); void listen(); +signals: + void listening(); + void listenFailed(); + private: GDBStub m_gdbStub; GameController* m_gameController; diff --git a/src/platform/qt/GDBWindow.cpp b/src/platform/qt/GDBWindow.cpp index aeb034c80..de467bb12 100644 --- a/src/platform/qt/GDBWindow.cpp +++ b/src/platform/qt/GDBWindow.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,9 @@ GDBWindow::GDBWindow(GDBController* controller, QWidget* parent) m_startStopButton = new QPushButton; mainSegment->addWidget(m_startStopButton); + connect(m_gdbController, SIGNAL(listening()), this, SLOT(started())); + connect(m_gdbController, SIGNAL(listenFailed()), this, SLOT(failed())); + if (m_gdbController->isAttached()) { started(); } else { @@ -88,7 +92,6 @@ void GDBWindow::started() { m_bindAddressEdit->setEnabled(false); m_startStopButton->setText(tr("Stop")); disconnect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(listen())); - disconnect(m_startStopButton, SIGNAL(clicked()), this, SLOT(started())); connect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(detach())); connect(m_startStopButton, SIGNAL(clicked()), this, SLOT(stopped())); } @@ -100,5 +103,12 @@ void GDBWindow::stopped() { disconnect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(detach())); disconnect(m_startStopButton, SIGNAL(clicked()), this, SLOT(stopped())); connect(m_startStopButton, SIGNAL(clicked()), m_gdbController, SLOT(listen())); - connect(m_startStopButton, SIGNAL(clicked()), this, SLOT(started())); +} + +void GDBWindow::failed() { + QMessageBox* failure = new QMessageBox(QMessageBox::Warning, tr("Crash"), + tr("Could not start GDB server"), + QMessageBox::Ok, this, Qt::Sheet); + failure->setAttribute(Qt::WA_DeleteOnClose); + failure->show(); } diff --git a/src/platform/qt/GDBWindow.h b/src/platform/qt/GDBWindow.h index 31a8ff5d3..683e7c632 100644 --- a/src/platform/qt/GDBWindow.h +++ b/src/platform/qt/GDBWindow.h @@ -28,6 +28,8 @@ private slots: void started(); void stopped(); + void failed(); + private: GDBController* m_gdbController;