forked from mirrors/gecko-dev
The new version of breakpad imported in bug 1309172 doesn't demangle rust symbols at all, contrary to before, where it tried to C++ demangle them, which worked for many, although far from all. It however has rust-demangle support as long as it's linked against a copy of the rust-demangle-capi crate from https://github.com/luser/rust-demangle-capi/ This imports the code from the rust-demangle-capi crate but because of some build system complications it's not taken as-is: - it uses rusty-cheddar, which is deprecated, to generate a C header. - rusty-cheddar depends on syntex_syntax, which now fails to build. - rust-demangle-capi has crate-type staticlib, which can't be used as a dependency in a Cargo.toml. For that reason, we can't create a fake crate that depends on it to have it vendored. Overall, it's only a few lines of rust, and the C header can be written manually, so this is what we do here. The created crate is named in a way specific to dump_syms. The build system doesn't know how to figure out what system libraries are required to link rust static libraries, although the rust compiler has /some/ support to get the information, so we handle that manually. --HG-- extra : rebase_source : 9f5a9bfe2148d3040e11c7121a88e85a7f2d5c53
25 lines
804 B
Rust
25 lines
804 B
Rust
extern crate rustc_demangle;
|
|
|
|
use rustc_demangle::demangle;
|
|
use std::ffi::{CStr, CString};
|
|
use std::ptr;
|
|
|
|
/// Demangle `name` as a Rust symbol.
|
|
///
|
|
/// The resulting pointer should be freed with `free_demangled_name`.
|
|
#[no_mangle]
|
|
pub extern fn rust_demangle(name: *const std::os::raw::c_char) -> *mut std::os::raw::c_char {
|
|
let demangled = format!("{:#}", demangle(&unsafe { CStr::from_ptr(name) }.to_string_lossy()));
|
|
CString::new(demangled)
|
|
.map(|s| s.into_raw())
|
|
.unwrap_or(ptr::null_mut())
|
|
}
|
|
|
|
/// Free a string that was returned from `rust_demangle`.
|
|
#[no_mangle]
|
|
pub extern fn free_rust_demangled_name(demangled: *mut std::os::raw::c_char) {
|
|
if demangled != ptr::null_mut() {
|
|
// Just take ownership here.
|
|
unsafe { CString::from_raw(demangled) };
|
|
}
|
|
}
|