Skip to content

Instantly share code, notes, and snippets.

@hadrianw
Last active June 14, 2018 12:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadrianw/5b8d33a4b353c49e7dbd6eb55f817901 to your computer and use it in GitHub Desktop.
Save hadrianw/5b8d33a4b353c49e7dbd6eb55f817901 to your computer and use it in GitHub Desktop.
strace with backtrace thanks to gdb
#!/bin/sh
cmd=$1
shift
# FIXME: it would be good for every argument to be wrapped in quotes
echo run $@ | gdb "$cmd" -x strace.gdb &> gdb-strace-log
set pagination off
set $clone_flags = -1
# clone
# call - determine if it's a thread
catch syscall clone
commands
bt
set $clone_flags = $rdi
c
end
condition $bpnum ($rax == -38)
# return - run gdb for pid
catch syscall clone
commands
eval "shell echo c | gdb -p %d -x strace.gdb &> gdb-strace-log.%d &", $rax, $rax
c
end
# CLONE_THREAD 0x10000
condition $bpnum ($rax != -38) && !($clone_flags & 0x10000)
# fork
catch syscall fork
commands
eval "shell echo c | gdb -p %d -x strace.gdb &> gdb-strace-log.%d &", $rax, $rax
c
end
condition $bpnum $rax != -38
# all the rest
catch syscall
commands
bt
continue
end
condition $bpnum $rax == -38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment