This repository has been archived on 2024-06-01. You can view files and clone it, but cannot push or open issues or pull requests.
cathook/attach-gdb
LightCat e7d6c7797c
Fix visual branch (#1673 but changed) (#1680)
Fix some visual issues and update c++/boost

Co-authored-by: Stephen Martin <stephenmartinemail2003@gmail.com>
Co-authored-by: Stephen Martin <93275421+STEVE4git@users.noreply.github.com>
2022-07-07 23:26:51 +02:00

48 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
[[ ! -z "$SUDO_USER" ]] && RUNUSER="$SUDO_USER" || RUNUSER="$LOGNAME"
RUNCMD="sudo -u $RUNUSER"
$RUNCMD bash ./scripts/updater true
$RUNCMD bash ./report-crash true
line=$(pgrep -u $RUNUSER hl2_linux)
arr=($line)
if [ $# == 1 ]; then
proc=$1
else
if [ ${#arr[@]} == 0 ]; then
echo TF2 isn\'t running!
exit
fi
proc=${arr[0]}
fi
echo Running instances: "${arr[@]}"
echo Attaching to "$proc"
#sudo ./detach $inst bin/libcathook.so
#if grep -q "$(realpath bin/libcathook.so)" /proc/"$proc"/maps; then
# echo already loaded
# exit
#fi
FILENAME="/tmp/.gl$(head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 6)"
cp "bin/libcathook.so" "$FILENAME"
echo loading "$FILENAME" to "$proc"
gdbbin="gdb"
$gdbbin -n -q -batch \
-ex "attach $proc" \
-ex "echo \033[1mCalling dlopen\033[0m\n" \
-ex "call ((void*(*)(const char*, int))dlopen)(\"$FILENAME\", 1)" \
-ex "echo \033[1mCalling dlerror\033[0m\n" \
-ex "call ((char*(*)(void))dlerror)()" \
-ex "continue" \
-ex "backtrace"
rm $FILENAME