mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-11 21:00:40 +02:00
Lots going on here. This moves OS thread object lifetime management and internal thread state lifetime management to the frontend. This causes a bunch of thread handling to move from the FEXCore Context to the frontend. Looking at `FEXCore/include/FEXCore/Core/Context.h` really shows how much of the API has moved to the frontend that FEXCore no longer needs to manage. Primarily this makes FEXCore itself no longer need to care about most of the management of the emulation state. A large amount of the behaviour moved wholesale from Core.cpp to LinuxEmulation's ThreadManager.cpp. Which this manages the lifetimes of both the OS threads and the FEXCore thread state objects. One feature lost was the instruction capability, but this was already buggy and is going to be rewritten/fixed when gdbserver work continues. Now that all of this management is moved to the frontend, the gdbserver can start improving since it can start managing all thread state directly.
114 lines
3.1 KiB
C++
114 lines
3.1 KiB
C++
// SPDX-License-Identifier: MIT
|
|
/*
|
|
$info$
|
|
tags: glue|gdbserver
|
|
$end_info$
|
|
*/
|
|
#pragma once
|
|
|
|
#include <FEXCore/Config/Config.h>
|
|
#include <FEXCore/Core/SignalDelegator.h>
|
|
#include <FEXCore/Utils/Event.h>
|
|
#include <FEXCore/Utils/Threads.h>
|
|
#include <FEXCore/fextl/memory.h>
|
|
#include <FEXCore/fextl/string.h>
|
|
|
|
#include <atomic>
|
|
#include <istream>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <stdint.h>
|
|
|
|
#include "LinuxSyscalls/SignalDelegator.h"
|
|
|
|
namespace FEX {
|
|
|
|
class GdbServer {
|
|
public:
|
|
GdbServer(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *SignalDelegation, FEX::HLE::SyscallHandler *const SyscallHandler);
|
|
~GdbServer();
|
|
|
|
// Public for threading
|
|
void GdbServerLoop();
|
|
|
|
void AlertLibrariesChanged() {
|
|
LibraryMapChanged = true;
|
|
}
|
|
|
|
private:
|
|
void Break(int signal);
|
|
|
|
void OpenListenSocket();
|
|
void CloseListenSocket();
|
|
enum class WaitForConnectionResult {
|
|
CONNECTION,
|
|
ERROR,
|
|
};
|
|
WaitForConnectionResult WaitForConnection();
|
|
fextl::unique_ptr<std::iostream> OpenSocket();
|
|
void StartThread();
|
|
fextl::string ReadPacket(std::iostream &stream);
|
|
void SendPacket(std::ostream &stream, const fextl::string& packet);
|
|
|
|
void SendACK(std::ostream &stream, bool NACK);
|
|
|
|
Event ThreadBreakEvent{};
|
|
void WaitForThreadWakeup();
|
|
|
|
struct HandledPacketType {
|
|
fextl::string Response{};
|
|
enum ResponseType {
|
|
TYPE_NONE,
|
|
TYPE_UNKNOWN,
|
|
TYPE_ACK,
|
|
TYPE_NACK,
|
|
TYPE_ONLYACK,
|
|
TYPE_ONLYNACK,
|
|
};
|
|
ResponseType TypeResponse{};
|
|
};
|
|
|
|
void SendPacketPair(const HandledPacketType& packetPair);
|
|
HandledPacketType ProcessPacket(const fextl::string &packet);
|
|
HandledPacketType handleQuery(const fextl::string &packet);
|
|
HandledPacketType handleXfer(const fextl::string &packet);
|
|
HandledPacketType handleMemory(const fextl::string &packet);
|
|
HandledPacketType handleV(const fextl::string& packet);
|
|
HandledPacketType handleThreadOp(const fextl::string &packet);
|
|
HandledPacketType handleBreakpoint(const fextl::string &packet);
|
|
HandledPacketType handleProgramOffsets();
|
|
|
|
HandledPacketType ThreadAction(char action, uint32_t tid);
|
|
|
|
fextl::string readRegs();
|
|
HandledPacketType readReg(const fextl::string& packet);
|
|
|
|
FEXCore::Context::Context *CTX;
|
|
FEX::HLE::SyscallHandler *const SyscallHandler;
|
|
fextl::unique_ptr<FEXCore::Threads::Thread> gdbServerThread;
|
|
fextl::unique_ptr<std::iostream> CommsStream;
|
|
std::mutex sendMutex;
|
|
bool SettingNoAckMode{false};
|
|
bool NoAckMode{false};
|
|
bool NonStopMode{false};
|
|
fextl::string ThreadString{};
|
|
fextl::string OSDataString{};
|
|
void buildLibraryMap();
|
|
std::atomic<bool> LibraryMapChanged = true;
|
|
std::atomic<bool> CoreShuttingDown{};
|
|
fextl::string LibraryMapString{};
|
|
|
|
// Used to keep track of which signals to pass to the guest
|
|
std::array<bool, FEX::HLE::SignalDelegator::MAX_SIGNALS + 1> PassSignals{};
|
|
uint32_t CurrentDebuggingThread{};
|
|
int ListenSocket{};
|
|
fextl::string GdbUnixSocketPath{};
|
|
FEX_CONFIG_OPT(Filename, APP_FILENAME);
|
|
FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE);
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|