Duckstation/src/duckstation-qt/gdbserver.cpp

53 lines
1,018 B
C++
Raw Normal View History

// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> and contributors.
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
2020-12-17 17:32:29 +00:00
#include "gdbserver.h"
#include "gdbconnection.h"
#include "common/log.h"
#include "qthost.h"
2020-12-17 17:32:29 +00:00
Log_SetChannel(GDBServer);
2023-02-25 16:27:03 +00:00
GDBServer::GDBServer(QObject *parent)
2020-12-17 17:32:29 +00:00
: QTcpServer(parent)
{
2023-02-25 16:27:03 +00:00
}
GDBServer::~GDBServer()
{
stop();
}
void GDBServer::start(quint16 port) {
if (isListening())
{
return;
2020-12-17 17:32:29 +00:00
}
2023-02-25 16:27:03 +00:00
if (!listen(QHostAddress::LocalHost, port))
{
Log_ErrorPrintf("Failed to listen on TCP port %u for GDB server: %s", port,
errorString().toUtf8().constData());
return;
2020-12-17 17:32:29 +00:00
}
2023-02-25 16:27:03 +00:00
Log_InfoPrintf("GDB server listening on TCP port %u", port);
2020-12-17 17:32:29 +00:00
}
2023-02-25 16:27:03 +00:00
void GDBServer::stop()
2020-12-17 17:32:29 +00:00
{
2023-02-25 16:27:03 +00:00
if (isListening())
{
close();
Log_InfoPrint("GDB server stopped");
}
for (QObject* connection : children()) {
connection->deleteLater();
2020-12-17 17:32:29 +00:00
}
}
void GDBServer::incomingConnection(qintptr descriptor)
{
2023-02-25 16:27:03 +00:00
new GDBConnection(this, descriptor);
2020-12-17 17:32:29 +00:00
}