Qt: Add error message if listening for GDB port fails
Jeffrey Pfau jeffrey@endrift.com
Wed, 21 Jan 2015 22:45:48 -0800
6 files changed,
29 insertions(+),
8 deletions(-)
M
src/debugger/gdb-stub.c
→
src/debugger/gdb-stub.c
@@ -449,7 +449,7 @@ stub->d.log = 0;
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 @@ if (SOCKET_FAILED(stub->socket)) {
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 @@ if (err) {
goto cleanup; } - return 1; + return true; cleanup: if (stub->d.log) {@@ -476,7 +476,7 @@ stub->d.log(&stub->d, DEBUGGER_LOG_ERROR, "Couldn't listen on port");
} SocketClose(stub->socket); stub->socket = INVALID_SOCKET; - return 0; + return false; } void GDBStubHangup(struct GDBStub* stub) {
M
src/debugger/gdb-stub.h
→
src/debugger/gdb-stub.h
@@ -37,7 +37,7 @@ int untilPoll;
}; 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*);
M
src/platform/qt/GDBController.cpp
→
src/platform/qt/GDBController.cpp
@@ -58,6 +58,11 @@ m_gameController->threadInterrupt();
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(); }
M
src/platform/qt/GDBController.h
→
src/platform/qt/GDBController.h
@@ -35,6 +35,10 @@ void attach();
void detach(); void listen(); +signals: + void listening(); + void listenFailed(); + private: GDBStub m_gdbStub; GameController* m_gameController;
M
src/platform/qt/GDBWindow.cpp
→
src/platform/qt/GDBWindow.cpp
@@ -9,6 +9,7 @@ #include <QGridLayout>
#include <QGroupBox> #include <QLabel> #include <QLineEdit> +#include <QMessageBox> #include <QPushButton> #include <QVBoxLayout>@@ -46,6 +47,9 @@ settingsGrid->addWidget(m_bindAddressEdit, 1, 1, Qt::AlignLeft);
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 @@ m_portEdit->setEnabled(false);
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 @@ m_startStopButton->setText(tr("Start"));
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(); }
M
src/platform/qt/GDBWindow.h
→
src/platform/qt/GDBWindow.h
@@ -28,6 +28,8 @@
void started(); void stopped(); + void failed(); + private: GDBController* m_gdbController;