How to pass RUST_BACKTRACE=1 when running a Rust binary installed in Debian?

Just in case someone is looking for setting environment variable from source code, here is how you do it: use std::env; fn main() { // this method needs to be inside main() method env::set_var(“RUST_BACKTRACE”, “1”); } The benefit of this approach — in contrast to manually setting the env variable from PowerShell– is that you … Read more

Can one use libSegFault.so to get backtraces for SIGABRT?

env SEGFAULT_SIGNALS=”abrt segv” LD_PRELOAD=/lib/libSegFault.so someapp Note that the actual path to the preload library may differ. On my machine, I’d use env SEGFAULT_SIGNALS=”abrt segv” LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so some-64bit-app or env SEGFAULT_SIGNALS=”abrt segv” LD_PRELOAD=/lib/i386-linux-gnu/libSegFault.so some-32bit-app depending whether the application I was running was compiled 64-bit or 32-bit. (You can use file to check.) The source tells us there … Read more

Is it possible to print a backtrace in Rust without panicking?

Rust uses the backtrace crate to print the backtrace in case of panics (has been merged in PR #60852). A simple example can be found in the crate documentation use backtrace::Backtrace; fn main() { let bt = Backtrace::new(); // do_some_work(); println!(“{:?}”, bt); } which gives for example stack backtrace: 0: playground::main::h6849180917e9510b (0x55baf1676201) at src/main.rs:4 1: … Read more

How to unwind the stack to get backtrace for the specified stack pointer (SP)?

In order to to get stacktrace of code which caused SIGSEGV instead of stacktrace of the signal handler, you have to get ARM registers from ucontext_t and use them for unwinding. But it is hard to do with _Unwind_Backtrace(). Thus, if you use libc++ (LLVM STL) and compile for 32-bit ARM, better try precompiled libunwind, … Read more

What is the meaning of question marks ‘?’ in Linux kernel panic call traces?

‘?’ means that the information about this stack entry is probably not reliable. The stack output mechanism (see the implementation of dump_trace() function) was unable to prove that the address it has found is a valid return address in the call stack. ‘?’ itself is output by printk_stack_address(). The stack entry may be valid or … Read more

Win32 – Backtrace from C code

Alright, now I got it. : ) The problem was in the SYMBOL_INFO structure. It needs to be allocated on the heap, reserving space for the symbol name, and initialized properly. Here’s the final code: void printStack( void ); void printStack( void ) { unsigned int i; void * stack[ 100 ]; unsigned short frames; … Read more