Skip to content

Instantly share code, notes, and snippets.

@skaes
Created March 26, 2010 10:28
Show Gist options
  • Save skaes/344749 to your computer and use it in GitHub Desktop.
Save skaes/344749 to your computer and use it in GitHub Desktop.
quickly obtain the call stack of a running ruby process
#!/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