aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/gdb-firejail.sh
blob: 1dc30be3e48fafde4cf4d53d481c2a563cc7552f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
# This file is part of Firejail project
# Copyright (C) 2014-2024 Firejail Authors
# License GPL v2
set -x

# gdb setuid helper script.
# This script forks a background process as the current user which will
# immediately send itself a `STOP` signal.  Then gdb running as root will
# attach to that process, which will send it the `CONT` signal to continue
# execution.  Then the backgrounded process will exec the program with the
# given arguments.  This will allow the root gdb to trace the unprivileged
# setuid firejail process from the absolute beginning.

if [ -z "${1##*/firejail}" ]; then
	FIREJAIL=$1
else
	# First argument is not named firejail, then add default unless environment
	# variable already set.
	set -- ${FIREJAIL:=$(command -v firejail)} "$@"
fi

bash -c "kill -STOP \$\$; exec \"\$0\" \"\$@\"" "$@" &
sudo gdb -e "$FIREJAIL" -p "$!"