Update Rust demangling to use rustc-demangle

The rust-demangle-capi crate hasn't been updated since 2016 and
out-of-date. Instead, Breakpad needs to use C API offered by the
rustc-demangle to demangle Rust symbols.

*** TESTING ***

1) Set up rustc-demangle

> git clone https://github.com/rust-lang/rustc-demangle.git
> cd rustc-demangle
> cargo build -p rustc-demangle-capi --release

2) Breakpad

> ./configure --with-rustc-demangle=<path to rustc-demangle>
> make check src/common/dward_cu_to_module

Change-Id: Ib68b62ef329f1397bc379a1d04c632781e4b2069
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3273324
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Alex Pankhurst 2021-11-10 13:25:30 -08:00 committed by Joshua Peraza
parent fe35cd43f2
commit 38ee0be4d1
6 changed files with 56 additions and 55 deletions

View file

@ -1268,12 +1268,12 @@ TEST_F(Specifications, MangledNameRust) {
TestFunctionCount(1);
TestFunction(0,
#ifndef HAVE_RUST_DEMANGLE
#ifndef HAVE_RUSTC_DEMANGLE
// Rust mangled names should pass through untouched if not
// using rust-demangle.
// using rustc-demangle.
kName,
#else
// If rust-demangle is available this should be properly
// If rustc-demangle is available this should be properly
// demangled.
"rustc_demangle::demangle",
#endif

View file

@ -35,13 +35,14 @@
#include "common/language.h"
#include <stdlib.h>
#include <array>
#if !defined(__ANDROID__)
#include <cxxabi.h>
#endif
#if defined(HAVE_RUST_DEMANGLE)
#include <rust_demangle.h>
#if defined(HAVE_RUSTC_DEMANGLE)
#include <rustc_demangle.h>
#endif
#include <limits>
@ -178,13 +179,13 @@ class RustLanguage: public Language {
// abi_demangle doesn't produce stellar results due to them having
// another layer of encoding.
// If callers provide rustc-demangle, use that.
#if defined(HAVE_RUST_DEMANGLE)
char* rust_demangled = rust_demangle(mangled.c_str());
if (rust_demangled == nullptr) {
#if defined(HAVE_RUSTC_DEMANGLE)
std::array<char, 1 * 1024 * 1024> rustc_demangled;
if (rustc_demangle(mangled.c_str(), rustc_demangled.data(),
rustc_demangled.size()) == 0) {
return kDemangleFailure;
}
demangled->assign(rust_demangled);
free_rust_demangled_name(rust_demangled);
demangled->assign(rustc_demangled.data());
#else
// Otherwise, pass through the mangled name so callers can demangle
// after the fact.