Skip to content

Commit 1c1becf

Browse files
committed
Enhance the way to demangle rust symbols
Try to demangle with both cpp_demange and rustc_demange, and choose the shorter one. Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
1 parent 7e76dd8 commit 1c1becf

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ serde_json = "1.0"
4040
rand = "0.8"
4141
rand_distr = "0.4"
4242
remoteprocess = {version="0.5.0", features=["unwind"]}
43+
rustc-demangle = "0.1.24"
4344
chrono = "0.4.26"
4445

4546
[dev-dependencies]

src/native_stack_trace.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,13 @@ impl NativeStack {
273273
if func.starts_with('_') {
274274
if let Ok((sym, _)) = BorrowedSymbol::with_tail(func.as_bytes()) {
275275
let options = DemangleOptions::new().no_params().no_return_type();
276-
if let Ok(sym) = sym.demangle(&options) {
276+
if let Ok(mut sym) = sym.demangle(&options) {
277+
// try to demangle with rustc_demangle for better representation for Rust symbols
278+
if let Ok(sym2) = rustc_demangle::try_demangle(func) {
279+
if sym2.as_str().len() < sym.len() {
280+
sym = sym2.to_string();
281+
}
282+
}
277283
demangled = Some(sym);
278284
}
279285
}

0 commit comments

Comments
 (0)