Skip to content

Instantly share code, notes, and snippets.

@chr5tphr
Last active May 28, 2019 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chr5tphr/f516fe353151a8e7c3037c3f354e924f to your computer and use it in GitHub Desktop.
Save chr5tphr/f516fe353151a8e7c3037c3f354e924f to your computer and use it in GitHub Desktop.
from socket import socket, AF_UNIX
from pdb import Pdb
from os import unlink, getuid, getpid, chmod
from signal import signal, SIGUSR1
def rtrace(signum, frame):
spath = '/tmp/{:d}.pdb.{:d}'.format(getuid(), getpid())
with socket(AF_UNIX) as sock:
chmod(sock.fileno(), 0o700)
sock.bind(spath)
sock.listen(1)
conn, addr = sock.accept()
fd = conn.makefile('rw')
dbgr = Pdb(stdin=fd, stdout=fd)
dbgr.set_trace()
unlink(spath)
signal(SIGUSR1, rtrace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment