#!/usr/bin/env bash # Take a backtrace of every thread of an emulator that is running under gdb. # # Pair with the wrapper at /sylph-home/re/bin/gdb-wrap/xenia_canary (see # docs/re/mission-freeze-resume-spin.md): ptrace_scope=1 forbids attaching to a # running emulator, so it has to be STARTED under gdb. # # SIGINT to gdb stops the inferior; commands then go in through the command file # the wrapper is tailing, and the answer comes back in the gdb log. `continue` at # the end so the run can carry on. set -u CMD="${GDB_CMD_FILE:-/tmp/gdb-cmd}" OUT="${GDB_OUT_FILE:-/tmp/gdb-out.log}" DEPTH="${1:-12}" pid=$(pgrep -x gdb | head -1) [ -n "$pid" ] || { echo "no gdb process — was the emulator started with XENIA_BIN=/sylph-home/re/bin/gdb-wrap/xenia_canary ?"; exit 1; } mark="=== BT $(date +%s) ===" before=$(wc -c < "$OUT") kill -INT "$pid" sleep 3 { echo "echo $mark\\n"; echo "info threads"; echo "thread apply all bt $DEPTH"; echo "echo === END ===\\n"; echo "continue"; } >> "$CMD" sleep 8 tail -c +$((before + 1)) "$OUT"