Skip to content

Commit 1ad5008

Browse files
authored
Merge pull request #197 from jan-auer/block-invoke
Demangle invocation block symbols
2 parents 48fb959 + 21acf3a commit 1ad5008

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

examples/cppfilt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ fn find_mangled(haystack: &[u8]) -> Option<usize> {
2121

2222
for i in 0..haystack.len() - 1 {
2323
if haystack[i] == b'_' {
24-
let next = haystack[i + 1];
25-
if next == b'Z' || next == b'_' && haystack.get(i + 2) == Some(&b'Z') {
26-
return Some(i);
24+
match (haystack[i + 1], haystack.get(i + 2), haystack.get(i + 3), haystack.get(i + 4)) {
25+
(b'Z', _, _, _)
26+
| (b'_', Some(b'Z'), _, _)
27+
| (b'_', Some(b'_'), Some(b'Z'), _) => return Some(i),
28+
| (b'_', Some(b'_'), Some(b'_'), Some(b'Z')) => return Some(i),
29+
_ => (),
2730
}
2831
}
2932
}

src/ast.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,12 +1296,21 @@ macro_rules! define_vocabulary {
12961296
///
12971297
/// ```text
12981298
/// <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1299+
/// ::= ___Z <encoding> <block_invoke>
1300+
/// ::= <type>
1301+
///
1302+
/// <block_invoke> ::= _block_invoke
1303+
/// ::= _block_invoke<decimal-digit>+
1304+
/// ::= _block_invoke_<decimal-digit>+
12991305
/// ```
13001306
#[derive(Clone, Debug, PartialEq, Eq)]
13011307
pub enum MangledName {
13021308
/// The encoding of the mangled symbol name.
13031309
Encoding(Encoding, Vec<CloneSuffix>),
13041310

1311+
/// The encoding of the mangled symbol name.
1312+
BlockInvoke(Encoding, Option<isize>),
1313+
13051314
/// A top-level type. Technically not allowed by the standard, however in
13061315
/// practice this can happen, and is tested for by libiberty.
13071316
Type(TypeHandle),
@@ -1326,6 +1335,23 @@ impl Parse for MangledName {
13261335
return Ok((MangledName::Encoding(encoding, clone_suffixes), tail));
13271336
}
13281337

1338+
if let Ok(tail) = consume(b"___Z", input).or_else(|_| consume(b"____Z", input)) {
1339+
let (encoding, tail) = Encoding::parse(ctx, subs, tail)?;
1340+
let tail = consume(b"_block_invoke", tail)?;
1341+
1342+
let tail_opt = match consume(b"_", tail) {
1343+
Ok(tail) => Some(parse_number(10, false, tail)?),
1344+
Err(_) => parse_number(10, false, tail).ok(),
1345+
};
1346+
1347+
let (digits, tail) = match tail_opt {
1348+
Some((digits, tail)) => (Some(digits), tail),
1349+
None => (None, tail),
1350+
};
1351+
1352+
return Ok((MangledName::BlockInvoke(encoding, digits), tail));
1353+
}
1354+
13291355
if let Ok(tail) = consume(b"_GLOBAL_", input) {
13301356
let (global_ctor_dtor, tail) = GlobalCtorDtor::parse(ctx, subs, tail)?;
13311357
return Ok((MangledName::GlobalCtorDtor(global_ctor_dtor), tail));
@@ -1359,6 +1385,11 @@ where
13591385
}
13601386
Ok(())
13611387
},
1388+
MangledName::BlockInvoke(ref enc, _) => {
1389+
write!(ctx, "invocation function for block in ")?;
1390+
enc.demangle(ctx, scope)?;
1391+
Ok(())
1392+
}
13621393
MangledName::Type(ref ty) => ty.demangle(ctx, scope),
13631394
MangledName::GlobalCtorDtor(ref gcd) => gcd.demangle(ctx, scope),
13641395
}

tests/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,8 @@ demangles!(
506506
_ZNK1QssERKS_,
507507
"Q::operator<=>(Q const&) const"
508508
);
509+
// Taken from https://git.llvm.org/klaus/libcxxabi/commit/5dd173b3792e868a7ebfa699d156f24075eafc01.diff
510+
demangles!(
511+
___ZN19URLConnectionClient33_clientInterface_cancelConnectionEP16dispatch_queue_sU13block_pointerFvvE_block_invoke14,
512+
"invocation function for block in URLConnectionClient::_clientInterface_cancelConnection(dispatch_queue_s*, void () block_pointer)"
513+
);

0 commit comments

Comments
 (0)