Skip to content

Commit

Permalink
Add scala native demangling and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol authored and mstange committed Mar 7, 2024
1 parent d6f9edf commit 2a1cf89
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions samply-symbols/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ thiserror = "1.0.57"
cpp_demangle = "0.4.0"
msvc-demangler = "0.10.0"
rustc-demangle = "0.1.21"
scala-native-demangle = "0.0.6"
bitflags = "2"
bytesize = { version = "1.0.1", optional = true }
bitvec = { version = "1.0.0", optional = true }
Expand Down
54 changes: 54 additions & 0 deletions samply-symbols/src/demangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub fn demangle_any(name: &str) -> String {
return msvc_demangler::demangle(name, flags).unwrap_or_else(|_| name.to_string());
}

if name.starts_with("__S") {
if let Ok(symbol) = scala_native_demangle::demangle_with_defaults(&name[1..name.len()]) {
return symbol;
}
}

if let Ok(demangled_symbol) = rustc_demangle::try_demangle(name) {
return format!("{demangled_symbol:#}");
}
Expand All @@ -37,3 +43,51 @@ pub fn demangle_any(name: &str) -> String {

name.to_owned()
}

#[cfg(test)]
mod tests {
use crate::demangle::demangle_any;
#[test]
fn cpp_demangling() {
assert_eq!(
demangle_any("_ZNK8KxVectorI16KxfArcFileRecordjEixEj"),
"KxVector<KxfArcFileRecord, unsigned int>::operator[](unsigned int) const"
)
}

#[test]
fn mscvc_demangling() {
assert_eq!(
demangle_any("??_R3?$KxSet@V?$KxSpe@DI@@I@@8"),
"KxSet<KxSpe<char, unsigned int>, unsigned int>::`RTTI Class Hierarchy Descriptor'"
)
}

#[test]
fn rust_demangling() {
assert_eq!(
demangle_any(
"_RNvMsr_NtCs3ssYzQotkvD_3std4pathNtB5_7PathBuf3newCs15kBYyAo9fc_7mycrate"
),
"<std::path::PathBuf>::new"
)
}

#[test]
fn ocaml_demangling() {
assert_eq!(demangle_any("camlA__b__c_1002"), "A.b.c_1002")
}

#[test]
fn scala_native_demangling() {
assert_eq!(
demangle_any("__SM17java.lang.IntegerD7compareiiiEo"),
"java.lang.Integer.compare(Int,Int): Int"
)
}

#[test]
fn no_demangling() {
assert_eq!(demangle_any("_!!!!!!!bla"), "!!!!!!!bla")
}
}

0 comments on commit 2a1cf89

Please sign in to comment.