How can I stop Rust from dead-code eliminating Debug impls so I can call them from GDB?

66 points Sweet-Accountant9580 17 comments

I’m debugging some Rust code with GDB, and I’d like to be able to call my type’s Debug implementation (impl Debug for MyType) directly from the debugger.

The problem is that if the Debug impl isn’t used anywhere in my Rust code, rustc/LLVM seems to dead-code eliminate it. That makes it impossible to call the function from GDB, since the symbol doesn’t even exist in the binary.

Is there a way to tell rustc/cargo to always keep those debug functions around, even if they’re not referenced, FOR EACH type that implements Debug?