Last active
June 14, 2018 12:10
-
-
Save hadrianw/5b8d33a4b353c49e7dbd6eb55f817901 to your computer and use it in GitHub Desktop.
strace with backtrace thanks to gdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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