|
|
|
|
@ -7,28 +7,31 @@
|
|
|
|
|
#include "qthost.h"
|
|
|
|
|
Log_SetChannel(GDBConnection);
|
|
|
|
|
|
|
|
|
|
GDBConnection::GDBConnection(QObject* parent, int descriptor) : QThread(parent), m_descriptor(descriptor)
|
|
|
|
|
GDBConnection::GDBConnection(GDBServer* parent, intptr_t descriptor) : QTcpSocket(parent), m_descriptor(descriptor)
|
|
|
|
|
{
|
|
|
|
|
Log_InfoPrintf("(%u) Accepted new connection on GDB server", m_descriptor);
|
|
|
|
|
|
|
|
|
|
connect(&m_socket, &QTcpSocket::readyRead, this, &GDBConnection::receivedData);
|
|
|
|
|
connect(&m_socket, &QTcpSocket::disconnected, this, &GDBConnection::gotDisconnected);
|
|
|
|
|
|
|
|
|
|
if (m_socket.setSocketDescriptor(m_descriptor))
|
|
|
|
|
{
|
|
|
|
|
g_emu_thread->setSystemPaused(true, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (!setSocketDescriptor(descriptor))
|
|
|
|
|
{
|
|
|
|
|
Log_ErrorPrintf("(%u) Failed to set socket descriptor: %s", m_descriptor,
|
|
|
|
|
m_socket.errorString().toUtf8().constData());
|
|
|
|
|
Log_ErrorPrintf("(%" PRIdPTR ") Failed to set socket descriptor: %s", descriptor,
|
|
|
|
|
errorString().toUtf8().constData());
|
|
|
|
|
deleteLater();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(g_emu_thread, &EmuThread::systemPaused, this, &GDBConnection::onEmulationPaused);
|
|
|
|
|
connect(g_emu_thread, &EmuThread::systemResumed, this, &GDBConnection::onEmulationResumed);
|
|
|
|
|
connect(this, &QTcpSocket::readyRead, this, &GDBConnection::receivedData);
|
|
|
|
|
connect(this, &QTcpSocket::disconnected, this, &GDBConnection::gotDisconnected);
|
|
|
|
|
|
|
|
|
|
Log_InfoPrintf("(%" PRIdPTR ") Client connected", m_descriptor);
|
|
|
|
|
|
|
|
|
|
m_seen_resume = System::IsPaused();
|
|
|
|
|
g_emu_thread->setSystemPaused(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GDBConnection::gotDisconnected()
|
|
|
|
|
{
|
|
|
|
|
Log_InfoPrintf("(%u) Client disconnected", m_descriptor);
|
|
|
|
|
this->exit(0);
|
|
|
|
|
Log_InfoPrintf("(%" PRIdPTR ") Client disconnected", m_descriptor);
|
|
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GDBConnection::receivedData()
|
|
|
|
|
@ -36,7 +39,7 @@ void GDBConnection::receivedData()
|
|
|
|
|
qint64 bytesRead;
|
|
|
|
|
char buffer[256];
|
|
|
|
|
|
|
|
|
|
while ((bytesRead = m_socket.read(buffer, sizeof(buffer))) > 0)
|
|
|
|
|
while ((bytesRead = read(buffer, sizeof(buffer))) > 0)
|
|
|
|
|
{
|
|
|
|
|
for (char c : std::string_view(buffer, bytesRead))
|
|
|
|
|
{
|
|
|
|
|
@ -44,19 +47,19 @@ void GDBConnection::receivedData()
|
|
|
|
|
|
|
|
|
|
if (GDBProtocol::IsPacketInterrupt(m_readBuffer))
|
|
|
|
|
{
|
|
|
|
|
Log_DebugPrintf("(%u) > Interrupt request", m_descriptor);
|
|
|
|
|
g_emu_thread->setSystemPaused(true, true);
|
|
|
|
|
Log_DebugPrintf("(%" PRIdPTR ") > Interrupt request", m_descriptor);
|
|
|
|
|
g_emu_thread->setSystemPaused(true);
|
|
|
|
|
m_readBuffer.erase();
|
|
|
|
|
}
|
|
|
|
|
else if (GDBProtocol::IsPacketContinue(m_readBuffer))
|
|
|
|
|
{
|
|
|
|
|
Log_DebugPrintf("(%u) > Continue request", m_descriptor);
|
|
|
|
|
g_emu_thread->setSystemPaused(false, false);
|
|
|
|
|
Log_DebugPrintf("(%" PRIdPTR ") > Continue request", m_descriptor);
|
|
|
|
|
g_emu_thread->setSystemPaused(false);
|
|
|
|
|
m_readBuffer.erase();
|
|
|
|
|
}
|
|
|
|
|
else if (GDBProtocol::IsPacketComplete(m_readBuffer))
|
|
|
|
|
{
|
|
|
|
|
Log_DebugPrintf("(%u) > %s", m_descriptor, m_readBuffer.c_str());
|
|
|
|
|
Log_DebugPrintf("(%" PRIdPTR ") > %s", m_descriptor, m_readBuffer.c_str());
|
|
|
|
|
writePacket(GDBProtocol::ProcessPacket(m_readBuffer));
|
|
|
|
|
m_readBuffer.erase();
|
|
|
|
|
}
|
|
|
|
|
@ -64,7 +67,8 @@ void GDBConnection::receivedData()
|
|
|
|
|
}
|
|
|
|
|
if (bytesRead == -1)
|
|
|
|
|
{
|
|
|
|
|
Log_ErrorPrintf("(%u) Failed to read from socket: %s", m_descriptor, m_socket.errorString().toUtf8().constData());
|
|
|
|
|
Log_ErrorPrintf("(%" PRIdPTR ") Failed to read from socket: %s", m_descriptor,
|
|
|
|
|
errorString().toUtf8().constData());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -87,9 +91,10 @@ void GDBConnection::onEmulationResumed()
|
|
|
|
|
|
|
|
|
|
void GDBConnection::writePacket(std::string_view packet)
|
|
|
|
|
{
|
|
|
|
|
Log_DebugPrintf("(%u) < %*s", m_descriptor, packet.length(), packet.data());
|
|
|
|
|
if (m_socket.write(packet.data(), packet.length()) == -1)
|
|
|
|
|
Log_DebugPrintf("(%" PRIdPTR ") < %*s", m_descriptor, packet.length(), packet.data());
|
|
|
|
|
if (write(packet.data(), packet.length()) == -1)
|
|
|
|
|
{
|
|
|
|
|
Log_ErrorPrintf("(%u) Failed to write to socket: %s", m_descriptor, m_socket.errorString().toUtf8().constData());
|
|
|
|
|
Log_ErrorPrintf("(%" PRIdPTR ") Failed to write to socket: %s", m_descriptor,
|
|
|
|
|
errorString().toUtf8().constData());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|