Skip to content

Commit afb0663

Browse files
committed
Fix osx demangling. ref m4b/bingrep#14
1 parent 3ad87d4 commit afb0663

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub fn demangle(s: &str) -> Demangle {
9292
// On Windows, dbghelp strips leading underscores, so we accept "ZN...E"
9393
// form too.
9494
inner = &s[2..s.len() - 1];
95+
} else if s.len() > 5 && s.starts_with("__ZN") && s.ends_with('E') {
96+
// On OSX, symbols are prefixed with an extra _
97+
inner = &s[4..s.len() - 1];
9598
} else {
9699
valid = false;
97100
}
@@ -303,6 +306,14 @@ mod tests {
303306
t!("_ZN12test$BP$test4foobE", "test*test::foob");
304307
}
305308

309+
310+
#[test]
311+
fn demangle_osx() {
312+
t!("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E", "alloc::allocator::Layout::for_value::h02a996811f781011");
313+
t!("__ZN38_$LT$core..option..Option$LT$T$GT$$GT$6unwrap18_MSG_FILE_LINE_COL17haf7cb8d5824ee659E", "<core::option::Option<T>>::unwrap::_MSG_FILE_LINE_COL::haf7cb8d5824ee659");
314+
t!("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E", "core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170");
315+
}
316+
306317
#[test]
307318
fn demangle_windows() {
308319
t!("ZN4testE", "test");

0 commit comments

Comments
 (0)