Skip to content

Demangle C++ functions in backtraces #66416

Description

@leo60228

I'm modding a C++ game (which contains debug symbols, thanks flibitijibibo!) using Rust. If I panic in a Rust function from my mod, this is what the backtrace looks like:

thread '<unnamed>' panicked at 'panic test', src/lib.rs:37:5
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77                                                                                   
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:464
  11: std::panicking::begin_panic
             at /rustc/bc0e288ad02ef362b5a6c42aaf61f2901c9b46db/src/libstd/panicking.rs:400
  12: vloader::hook_physfs_init
             at src/lib.rs:37
  13: core::ops::function::Fn::call
             at /rustc/bc0e288ad02ef362b5a6c42aaf61f2901c9b46db/src/libcore/ops/function.rs:69
  14: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /rustc/bc0e288ad02ef362b5a6c42aaf61f2901c9b46db/src/liballoc/boxed.rs:956
  15: vloader::PHYSFS_INIT::__ffi_detour
             at /home/leo60228/vloader/<::detour::macros::static_detour macros>:31
  16: _Z15FILESYSTEM_initPc
             at /home/flibitijibibo/Programming/cppProjects/Contracts/VVVVVV/Src/FileSystemUtils.cpp:39
  17: main
             at /home/flibitijibibo/Programming/cppProjects/Contracts/VVVVVV/Src/main.cpp:39
  18: __libc_start_main
  19: <unknown>

This backtrace is almost perfect, except for the ugly mangled C++ symbol. Now that #65646 allows unwinding through C++ code, it would be nice if Rust demangled them. backtrace-rs already supports this behind a feature, and I tried enabling it through xargo, but it didn't work. I think this might be because of the way std prints backtraces.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-backtraceArea: BacktracesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions