Duckstation/src/duckstation-qt/gdbserver.cpp

53 lines
979 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 "common/log.h"
#include "gdbconnection.h"
#include "qthost.h"
2020-12-17 17:32:29 +00:00
Log_SetChannel(GDBServer);
GDBServer::GDBServer(QObject* parent) : QTcpServer(parent)
2020-12-17 17:32:29 +00:00
{
2023-02-25 16:27:03 +00:00
}
GDBServer::~GDBServer()
{
stop();
}
void GDBServer::start(quint16 port)
{
2023-02-25 16:27:03 +00:00
if (isListening())
{
return;
2020-12-17 17:32:29 +00:00
}
2023-02-25 16:27:03 +00:00
if (!listen(QHostAddress::LocalHost, port))
{
2024-05-23 10:55:28 +00:00
ERROR_LOG("Failed to listen on TCP port {} for GDB server: {}", port, errorString().toUtf8().constData());
2023-02-25 16:27:03 +00:00
return;
2020-12-17 17:32:29 +00:00
}
2023-02-25 16:27:03 +00:00
2024-05-23 10:55:28 +00:00
INFO_LOG("GDB server listening on TCP port {}", 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();
2024-05-23 10:55:28 +00:00
INFO_LOG("GDB server stopped");
2023-02-25 16:27:03 +00:00
}
for (QObject* connection : children())
{
2023-02-25 16:27:03 +00:00
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
}