Skip to content

Commit a98a592

Browse files
committed
Support demangling symbols with dot-delimited words at the end
This accounts for values like LLVM IR branch labels. Closes #15
1 parent 7a8b109 commit a98a592

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use core::fmt;
3636
pub struct Demangle<'a> {
3737
original: &'a str,
3838
inner: &'a str,
39+
suffix: &'a str,
3940
valid: bool,
4041
/// The number of ::-separated elements in the original name.
4142
elements: usize,
@@ -98,6 +99,15 @@ pub fn demangle(mut s: &str) -> Demangle {
9899
}
99100
}
100101

102+
// Output like LLVM IR adds extra period-delimited words. See if
103+
// we are in that case and save the trailing words if so.
104+
let mut suffix = "";
105+
if let Some(i) = s.rfind("E.") {
106+
let (head, tail) = s.split_at(i + 1); // After the E, before the period
107+
s = head;
108+
suffix = tail;
109+
}
110+
101111
// First validate the symbol. If it doesn't look like anything we're
102112
// expecting, we just print it literally. Note that we must handle non-Rust
103113
// symbols because we could have any function in the backtrace.
@@ -155,6 +165,7 @@ pub fn demangle(mut s: &str) -> Demangle {
155165

156166
Demangle {
157167
inner: inner,
168+
suffix: suffix,
158169
valid: valid,
159170
elements: elements,
160171
original: s,
@@ -288,6 +299,8 @@ impl<'a> fmt::Display for Demangle<'a> {
288299
}
289300
}
290301

302+
try!(f.write_str(self.suffix));
303+
291304
Ok(())
292305
}
293306
}
@@ -398,6 +411,12 @@ mod tests {
398411
t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
399412
}
400413

414+
#[test]
415+
fn demangle_llvm_ir_branch_labels() {
416+
t!("_ZN4core5slice77_$LT$impl$u20$core..ops..index..IndexMut$LT$I$GT$$u20$for$u20$$u5b$T$u5d$$GT$9index_mut17haf9727c2edfbc47bE.exit.i.i", "core::slice::<impl core::ops::index::IndexMut<I> for [T]>::index_mut::haf9727c2edfbc47b.exit.i.i");
417+
t_nohash!("_ZN4core5slice77_$LT$impl$u20$core..ops..index..IndexMut$LT$I$GT$$u20$for$u20$$u5b$T$u5d$$GT$9index_mut17haf9727c2edfbc47bE.exit.i.i", "core::slice::<impl core::ops::index::IndexMut<I> for [T]>::index_mut.exit.i.i");
418+
}
419+
401420
#[test]
402421
fn dont_panic() {
403422
super::demangle("_ZN2222222222222222222222EE").to_string();

0 commit comments

Comments
 (0)