Skip to content

Commit

Permalink
std: Fix demangling with middle special chars
Browse files Browse the repository at this point in the history
Previously, symbols with rust escape sequences (denoted with dollar signs)
weren't demangled if the escape sequence showed up in the middle. This alters
the printing loop to look through the entire string for dollar characters.
  • Loading branch information
alexcrichton committed Apr 19, 2014
1 parent b75683c commit 55310ac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/libstd/rt/backtrace.rs
Expand Up @@ -109,7 +109,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
let i: uint = from_str(s.slice_to(s.len() - rest.len())).unwrap();
s = rest.slice_from(i);
rest = rest.slice_to(i);
loop {
while rest.len() > 0 {
if rest.starts_with("$") {
macro_rules! demangle(
($($pat:expr => $demangled:expr),*) => ({
Expand Down Expand Up @@ -144,8 +144,12 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
"$x5d" => "]"
)
} else {
try!(writer.write_str(rest));
break;
let idx = match rest.find('$') {
None => rest.len(),
Some(i) => i,
};
try!(writer.write_str(rest.slice_to(idx)));
rest = rest.slice_from(idx);
}
}
}
Expand Down Expand Up @@ -774,4 +778,10 @@ mod test {
t!("_ZN8$UP$test4foobE", "~test::foob");
t!("_ZN8$x20test4foobE", " test::foob");
}

#[test]
fn demangle_many_dollars() {
t!("_ZN12test$x20test4foobE", "test test::foob");
t!("_ZN12test$UP$test4foobE", "test~test::foob");
}
}

1 comment on commit 55310ac

@brson
Copy link

@brson brson commented on 55310ac Apr 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.