Qt: Run GDB server on emulation thread

This commit is contained in:
Jean-Baptiste Boric
2023-02-25 17:27:03 +01:00
parent 4494a2c73c
commit 7810e68a58
8 changed files with 82 additions and 66 deletions

View File

@ -7,33 +7,46 @@
#include "qthost.h"
Log_SetChannel(GDBServer);
GDBServer::GDBServer(QObject *parent, u16 port)
GDBServer::GDBServer(QObject *parent)
: QTcpServer(parent)
{
if (listen(QHostAddress::LocalHost, port)) {
Log_InfoPrintf("GDB server listening on TCP port %u", port);
}
else {
Log_InfoPrintf("Failed to listen on TCP port %u for GDB server: %s", port, errorString().toUtf8().constData());
}
}
GDBServer::~GDBServer()
{
Log_InfoPrint("GDB server stopped");
for (auto* thread : m_connections) {
thread->quit();
thread->wait();
delete thread;
stop();
}
void GDBServer::start(quint16 port) {
if (isListening())
{
return;
}
if (!listen(QHostAddress::LocalHost, port))
{
Log_ErrorPrintf("Failed to listen on TCP port %u for GDB server: %s", port,
errorString().toUtf8().constData());
return;
}
Log_InfoPrintf("GDB server listening on TCP port %u", port);
}
void GDBServer::stop()
{
if (isListening())
{
close();
Log_InfoPrint("GDB server stopped");
}
for (QObject* connection : children()) {
connection->deleteLater();
}
}
void GDBServer::incomingConnection(qintptr descriptor)
{
Log_InfoPrint("Accepted connection on GDB server");
GDBConnection *thread = new GDBConnection(this, descriptor);
connect(g_emu_thread, &EmuThread::systemPaused, thread, &GDBConnection::onEmulationPaused);
connect(g_emu_thread, &EmuThread::systemResumed, thread, &GDBConnection::onEmulationResumed);
thread->start();
m_connections.push_back(thread);
new GDBConnection(this, descriptor);
}