Created
March 26, 2010 10:28
-
-
Save skaes/344749 to your computer and use it in GitHub Desktop.
quickly obtain the call stack of a running ruby process
This file contains hidden or 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 -e | |
process=$1 | |
commands=`mktemp -t gdb.XXXXXXXXXX` | |
cat > $commands << '_EOF_' | |
if during_gc == 1 | |
x/s "cannot backtrace during gc" | |
else | |
set $stack = (VALUE)backtrace(-1) | |
set $count = (int)rb_fix2int(rb_ary_length($stack)) | |
set $index = 0 | |
while $index < $count | |
set $frame = (VALUE)rb_ary_entry($stack, $index) | |
x/s ((struct RString*)$frame)->ptr | |
set $index = $index + 1 | |
end | |
end | |
detach | |
_EOF_ | |
gdb --batch --pid=$process -x $commands 2>&1 | grep 0x | |
rm -f $commands |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment