Skip to content

Commit 682f932

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 <[email protected]>
1 parent 64dfe73 commit 682f932

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Cargo.lock

Lines changed: 3 additions & 2 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
@@ -39,6 +39,7 @@ serde_json = "1.0"
3939
rand = "0.8"
4040
rand_distr = "0.4"
4141
remoteprocess = {version="0.4.12", features=["unwind"]}
42+
rustc-demangle = "0.1.24"
4243
chrono = "0.4.26"
4344

4445
[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)