Skip to content

Instantly share code, notes, and snippets.

@mikeys
Created April 28, 2013 06:46
Show Gist options
  • Save mikeys/5476128 to your computer and use it in GitHub Desktop.
Save mikeys/5476128 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Create a temporary file which will hold the GDB Commands
TMPFILE=`mktemp /tmp/gdbcommands.XXXXXX` || exit 1
# Add commands to the newly created file
cat <<-EOF > $TMPFILE
define redirect_stdout
call rb_eval_string("\$_old_stdout, \$stdout = \$stdout, File.open('/tmp/ruby-debug.' + Process.pid.to_s, 'a'); \$stdout.sync = true")
end
define ruby_eval
call(rb_p(rb_eval_string_protect(\$arg0,(int*)0)))
end
redirect_stdout
ruby_eval("Kernel.caller")
quit
EOF
# Fetch all 'Rack' process pids
RACK_PIDS=$(pgrep -f Rack)
# Dump stacktrace from all 'Rack' processes
# Stacktrace will be available in /tmp/ruby-debug.PID
for RACK_PID in $RACK_PIDS
do
sudo gdb --batch-silent -x $TMPFILE ruby $RACK_PID
done
# Kill all 'dumped' Passenger processes
sudo kill -9 $RACK_PIDS
# Remove temporary config file
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment