2022-12-04 11:03:45 +00:00
|
|
|
// 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"
|
2024-05-23 10:20:16 +00:00
|
|
|
#include "gdbconnection.h"
|
2022-07-11 13:03:29 +00:00
|
|
|
#include "qthost.h"
|
2020-12-17 17:32:29 +00:00
|
|
|
Log_SetChannel(GDBServer);
|
|
|
|
|
2024-05-23 10:20:16 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2024-05-23 10:20:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-05-23 10:20:16 +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
|
|
|
}
|