From fb9d584394ed00fb00af826b1d498dbc5d87940f Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Thu, 3 Dec 2026 05:08:55 -0500 Subject: [PATCH] Diagnostic: log ptrace emulation --- tools/fex/patches/0029-diag-ptrace.patch | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tools/fex/patches/0029-diag-ptrace.patch diff --git a/tools/fex/patches/0029-diag-ptrace.patch b/tools/fex/patches/0029-diag-ptrace.patch new file mode 100644 index 0000000000..12110cb3fd --- /dev/null +++ b/tools/fex/patches/0029-diag-ptrace.patch @@ -0,0 +1,58 @@ +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +index 62acdb0..46da076 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +@@ -27,6 +27,7 @@ + + namespace FEX::HLE::PtraceEmu { + namespace { ++#define DDPT(fmt, ...) ::dprintf(2, "DDPT %d/%ld " fmt "\n", ::getpid(), (long)::syscall(SYS_gettid), ##__VA_ARGS__) + #ifndef NT_X86_XSTATE + constexpr uintptr_t NT_X86_XSTATE = 0x202; + #endif +@@ -180,6 +181,7 @@ namespace { + } + + void Stop(uint64_t Nr, const uint64_t Args[6], bool Entry, uint64_t Ret, const uint64_t* Regs) { ++ DDPT("stop nr=%lld entry=%d rip=%#llx", (long long)Nr, Entry, (unsigned long long)Regs[Rip]); + SharedState& S = *Current; + if (!HasHostTracer()) { + S.SyscallStops = 0; +@@ -212,6 +214,7 @@ namespace { + } + + const uint64_t Dirty = S.DirtyMask; ++ if (Dirty) DDPT("apply dirty=%#llx entry=%d rip=%#llx", (unsigned long long)Dirty, Entry, (unsigned long long)S.Regs[Rip]); + if (!Dirty) { + return NoOverride; + } +@@ -577,10 +580,12 @@ void ApplyPendingFlush(FEXCore::Core::CpuStateFrame* Frame) { + uint64_t TakePendingRip() { + const uint64_t Rip = PendingRip; + PendingRip = 0; ++ if (Rip) DDPT("take rip=%#llx", (unsigned long long)Rip); + return Rip; + } + + bool TryGuestSignalStop(FEXCore::Core::CpuStateFrame* Frame, int Signal) { ++ DDPT("sigstop sig=%d attached=%llu rip=%#llx", Signal, (unsigned long long)Current->Attached, (unsigned long long)Frame->State.rip); + if (Signal != SIGTRAP && Signal != SIGSEGV) { + return false; + } +@@ -631,6 +636,7 @@ bool FixupWaitStatus(pid_t Pid, int* Status) { + return false; + } + const int St = *Status; ++ DDPT("wait pid=%d st=%#x", Pid, St); + + if (WIFEXITED(St) || WIFSIGNALED(St)) { + Forget(Pid, true); +@@ -677,6 +683,8 @@ bool FixupWaitStatus(pid_t Pid, int* Status) { + } + + bool HandleRequest(int Request, pid_t Pid, void* Addr, void* Data, uint64_t* Result) { ++ DDPT("req %d pid=%d addr=%p data=%p", Request, Pid, Addr, Data); ++ if (Request == 13 && Data) DDPT("setregs rip=%#llx rcx=%#llx", (unsigned long long)static_cast(Data)[Rip], (unsigned long long)static_cast(Data)[11]); + switch (Request) { + case PTRACE_TRACEME: + *Result = HostPtrace(Request, Pid, Addr, Data);