Python C++ Symbol Demangler
Cxxfilt provides a Python interface to demangle C++ symbol names, typically found in compiled binaries or stack traces. It wraps the functionality of system utilities like `c++filt` or `abi::__cxa_demangle`. The current version is 0.3.0, and it is actively maintained on GitHub.
Warnings
- breaking Python 2.7 is no longer supported in `cxxfilt` versions 0.3.0 and above. For Python 2.7 compatibility, use `cxxfilt` version < 0.3.
- gotcha The library does not officially support Windows environments. It is primarily tested on Linux and macOS, and is expected to work on Unix-like systems with `libc` and `libc++/libstdc++`.
- gotcha Although `import cxxfilt` no longer fails if system C/C++ libraries are unavailable (since v0.3.0), attempting to demangle symbols will fail or raise `LibraryNotFound` or `InternalError` if the underlying native demangling functions are not accessible.
- gotcha The `cxxfilt.demangle()` function can raise an `InvalidName` exception if the provided string is not a valid C++ ABI mangled name.
Install
-
pip install cxxfilt
Imports
- demangle
import cxxfilt symbol_name = '_ZNSt22condition_variable_anyD2Ev' demangled_name = cxxfilt.demangle(symbol_name)
Quickstart
import cxxfilt
mangled_symbol = '_ZNSt22condition_variable_anyD2Ev'
demangled_symbol = cxxfilt.demangle(mangled_symbol)
print(f"Mangled: {mangled_symbol}")
print(f"Demangled: {demangled_symbol}")
# To check if the underlying demangler is valid (e.g., if system libraries are present)
# The import itself no longer fails if libraries are missing since v0.3.0.
is_demangler_valid = not isinstance(cxxfilt.default_demangler, cxxfilt.DeferedErrorDemangler)
print(f"Is demangler valid: {is_demangler_valid}")