by gimli-rs

gimli-rs / cpp_demangle

A crate for demangling C++ symbols

213 Stars 22 Forks Last release: Not found Other 530 Commits 19 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

: a C++ linker symbol demangler

Build Status

This crate can parse a C++ “mangled” linker symbol name into a Rust value describing what the name refers to: a variable, a function, a virtual table, etc. The description type implements

, producing human-readable text describing the mangled name. Debuggers and profilers can use this crate to provide more meaningful output.

C++ requires the compiler to choose names for linker symbols consistently across compilation units, so that two compilation units that have seen the same declarations can pair up definitions in one unit with references in another. Almost all platforms other than Microsoft Windows follow the Itanium C++ ABI's rules for this.

For example, suppose a C++ compilation unit has the definition:

namespace space {
  int foo(int x, int y) { return x+y; }

The Itanium C++ ABI specifies that the linker symbol for that function must be named

. This crate can parse that name into a Rust value representing its structure. Formatting the value with the
macro or the
trait method yields the string
space::foo(int, int)
, which is more meaningful to the C++ developer.



to your crate's
cpp_demangle = "0.3.0"

And then demangle some C++ symbols!

extern crate cpp_demangle;
use cpp_demangle::Symbol;
use std::string::ToString;

let mangled = b"_ZN5space3fooEibc";

let sym = Symbol::new(&mangled[..]) .expect("Could not parse mangled symbol!");

let demangled = sym.to_string(); assert_eq!(demangled, "space::foo(int, bool, char)");


may be configured for working in
environments that still have allocation support via the
crate. This is nightly rust only, at the moment, since the
crate's collections aren't stabilized.

Disable the "std" feature, and enable the "alloc" feature:

cpp_demangle = {
  version = "0.3.0",
  default-features = false,
  features = ["alloc"]


Documentation on docs.rs

Example programs:

Install it locally with this command:

  cargo install cpp_demangle --example cppfilt

Implementation Status

Work is ongoing. While

can parse every mangled symbol in
's demangler's test suite (the canonical Itanium C++ symbol demangler used by GNU tools such as
), it does not format all of them character-for-character identically. I'm working on fixing that ;)

Despite that, I believe

is fairly robust. I've been running AFL on
overnight and it hasn't found any panics for a long time now (and never found any crashes -- thanks Rust!).


Licensed under either of

  • Apache License, Version 2.0 (
    or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (
    or http://opensource.org/licenses/MIT)

at your option.


See CONTRIBUTING.md for hacking.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.