-
Notifications
You must be signed in to change notification settings - Fork 186
Getting a Ruby thread dump
Silvio Moioli edited this page Jun 6, 2022
·
1 revision
C stack trace:
gdb -p <RUBY_PID>
(gdb) thread apply all backtrace
(gdb) quit
Please note that while gdb
is attached the Ruby process is blocked.
Ruby stack trace:
gdb -p <RUBY_PID>
(gdb) call (void) close(1)
(gdb) call (void) close(2)
(gdb) shell tty
/dev/pts/0
(gdb) call (int) open("/dev/pts/0", 2, 0)
$1 = 1
(gdb) call (int) open("/dev/pts/0", 2, 0)
$2 = 2
(gdb) call (void)rb_backtrace()
(gdb) quit
It is possible to script gdb
by putting commands in a file passed with the -x
option. Note that this file should contain set pagination off
as the first instruction.
Full details about the technique: https://blog.newrelic.com/engineering/debugging-stuck-ruby-processes-what-to-do-before-you-kill-9/