Skip to content

Instantly share code, notes, and snippets.

View matheusd's full-sized avatar

Matheus Degiovani matheusd

View GitHub Profile
@psobot
psobot / format_stacktrace_from_strace.py
Last active October 31, 2022 12:58
Dump a stack trace of a Go process without stderr attached. This is a super dirty hack, but it uses strace, pgrep and python to send QUIT to a Golang process, intercept its system calls to stderr, and format them nicely for humans. Tested on Ubuntu with Go 1.1.
import sys
import re
output = sys.stdin.readlines()
r = re.compile(r'write\(2, "(.+?)", \d+\)\s+= \d+')
print "".join([x.replace(r'\n', "\n").replace(r'\t', "\t") for x in sum([r.findall(o) for o in output], [])])