Skip to content

Commit ba25fec

Browse files
committed
auto merge of #13615 : alexcrichton/rust/improve-demangling, r=brson
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.
2 parents 2c22ae4 + 55310ac commit ba25fec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/libstd/rt/backtrace.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
109109
let i: uint = from_str(s.slice_to(s.len() - rest.len())).unwrap();
110110
s = rest.slice_from(i);
111111
rest = rest.slice_to(i);
112-
loop {
112+
while rest.len() > 0 {
113113
if rest.starts_with("$") {
114114
macro_rules! demangle(
115115
($($pat:expr => $demangled:expr),*) => ({
@@ -144,8 +144,12 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
144144
"$x5d" => "]"
145145
)
146146
} else {
147-
try!(writer.write_str(rest));
148-
break;
147+
let idx = match rest.find('$') {
148+
None => rest.len(),
149+
Some(i) => i,
150+
};
151+
try!(writer.write_str(rest.slice_to(idx)));
152+
rest = rest.slice_from(idx);
149153
}
150154
}
151155
}
@@ -774,4 +778,10 @@ mod test {
774778
t!("_ZN8$UP$test4foobE", "~test::foob");
775779
t!("_ZN8$x20test4foobE", " test::foob");
776780
}
781+
782+
#[test]
783+
fn demangle_many_dollars() {
784+
t!("_ZN12test$x20test4foobE", "test test::foob");
785+
t!("_ZN12test$UP$test4foobE", "test~test::foob");
786+
}
777787
}

0 commit comments

Comments
 (0)