Is there a way to get a stack trace with a kill signal like with Go?


With Go we can use kill -ABRT <pid> to kill a process and get a stack trace. It’s useful to debug hangs. Is there something similar with Rust? With a crate maybe.


You can use gdb to attach to already running process in order to debug it.

~ $ rust-gdb -p [process pid]
0x000055995850fd36 in infinite_loop::main () at
3           loop {}
(gdb) bt
#0  0x0000564c5292ad36 in infinite_loop::main () at
#1  0x0000564c5293da2b in panic_unwind::__rust_maybe_catch_panic () at /checkout/src/libpanic_unwind/
#2  0x0000564c52936569 in std::panicking::try<(),closure> () at /checkout/src/libstd/
#3  std::panic::catch_unwind<closure,()> () at /checkout/src/libstd/
#4  std::rt::lang_start () at /checkout/src/libstd/
#5  0x0000564c5292ad73 in main ()



Do you know if I can have a backtrace of all the running threads with that?


It will not do it for you, though you could probably make a crate which uses backtrace and ptrace to get backtraces for all threads.


Servo automatically produces a backtace for the current thread when a segfault occurs:


You can also use lldb:

(lldb) target stop-hook add
Enter your stop hook command(s). Type ‘DONE’ to end.

disassemble --pc
Stop hook #1 added.



Considering how awesome the documentation community of Rust is; I would love to see some docs of how to use gdb, valgrind, and/or other-perf-tools for Rust development.

Maybe advanced debugging could be a new chapter of the Rust Book?