#!/usr/bin/env bash
# trace_login.sh -- attach the login-path tracer to the running FIFA17.exe.
# Prereqs: FIFA 17 running; kernel.yama.ptrace_scope=0; lsx_responder_v2 up with
# an UNBOUNDED heartbeat so pushes are still in flight while we trace, e.g.:
#     OPENFUT_LSX_EVENT_COUNT=100000 python3 -u tools/lsx_responder_v2.py
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
PID="$(pgrep -x FIFA17.exe | head -1 || true)"
if [ -z "${PID}" ]; then echo "FIFA17.exe not running"; exit 1; fi
echo "attaching to FIFA17.exe pid=${PID}"
TMP="$(mktemp /tmp/trace_login.XXXX.gdb)"
sed "s/PIDHERE/${PID}/" "${DIR}/trace_login.gdb" > "${TMP}"
# gdb must run with ptrace rights; if not root, ptrace_scope=0 suffices.
gdb -batch -x "${TMP}" 2>&1 | tee /tmp/trace_login.log
rm -f "${TMP}"
