GithubHelp home page GithubHelp logo

quark-zju / cpp_demangle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gimli-rs/cpp_demangle

0.0 1.0 0.0 3.68 MB

Slightly modified to demangle long input

License: Apache License 2.0

Shell 0.14% C 0.53% Rust 99.25% Makefile 0.08%

cpp_demangle's Introduction

cpp_demangle: 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 Display, 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 _ZN5space3fooEii. This crate can parse that name into a Rust value representing its structure. Formatting the value with the format! macro or the std::string::ToString::to_string trait method yields the string space::foo(int, int), which is more meaningful to the C++ developer.

Usage

Add cpp_demangle to your crate's Cargo.toml:

[dependencies]
cpp_demangle = "0.4.3"

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)");

no_std Support

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

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

[dependencies]
cpp_demangle = {
  version = "0.4.3",
  default-features = false,
  features = ["alloc"]
}

Documentation

Documentation on docs.rs

Example programs:

  • A c++filt clone.

    Install it locally with this command:

    cargo install cpp_demangle --example cppfilt
    

Implementation Status

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

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

License

Licensed under either of

at your option.

Contribution

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.

cpp_demangle's People

Contributors

fitzgen avatar khuey avatar saldivarcher avatar jimblandy avatar rocallahan avatar dependabot-preview[bot] avatar dependabot[bot] avatar swatinem avatar mitsuhiko avatar atouchet avatar est31 avatar a1phyr avatar jan-auer avatar striezel avatar dependabot-support avatar llogiq avatar frewsxcv avatar ignatenkobrain avatar mstange avatar mclark4386 avatar benesch avatar philipc avatar diamondlovesyou avatar tromey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.