DemangleConfig

Struct DemangleConfig 

Source
#[non_exhaustive]
pub struct DemangleConfig { pub fix_namespaced_global_constructor_bug: bool, pub fix_array_length_arg: bool, pub demangle_global_keyed_frames: bool, pub ellipsis_emit_space_after_comma: bool, pub fix_extension_int: bool, pub fix_array_in_return_position: bool, pub fix_function_pointers_in_template_lists: bool, }
Expand description

Tweak how a symbol should be disassembled.

The constructors provide sensible defaults, so there’s usually no need to override each option.

Refer to each option to see what it does and examples.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§fix_namespaced_global_constructor_bug: bool

Recreate a c++filt bug where it won’t emit the “global constructors keyed to “ prefix for a namespaced function.

This is just another c++filt compatibility setting.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_namespaced_global_constructor_bug = false;

let demangled = demangle("_GLOBAL_$I$__Q210Scenegraph10Scenegraph", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("Scenegraph::Scenegraph::Scenegraph(void)")
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_namespaced_global_constructor_bug = true;

let demangled = demangle("_GLOBAL_$I$__Q210Scenegraph10Scenegraph", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("global constructors keyed to Scenegraph::Scenegraph::Scenegraph(void)")
);
§fix_array_length_arg: bool

By default g++ subtracts 1 from the length of array arguments, thus producing a confusing mangled name.

c++filt uses this length as-is, which produces a demangled symbol that does not match the original C++ symbol.

This setting adds 1 to the length, making the demangled symbol match more accurately the real symbol.

This is just another c++filt compatibility setting.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_array_length_arg = false;

let demangled = demangle("simpler_array__FPA41_A24_Ci", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("simpler_array(int const (*)[41][24])")
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_array_length_arg = true;

let demangled = demangle("simpler_array__FPA41_A24_Ci", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("simpler_array(int const (*)[42][25])")
);
§demangle_global_keyed_frames: bool

Recognize and demangle symbols prefixed by _GLOBAL_$F$.

c++filt does not recognizes this prefix, so it tries to demangle it as other mangled kinds, like functions, methods, etc.

When turned on, the symbol gets demangled the same way _GLOBAL_$I$ and _GLOBAL_$D$ are demangled, but the word “frames” is used instead of “constructors” or “destructors”. This name is made-up based on some usages from projects that have this symbol present.

This is just another c++filt compatibility setting.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.demangle_global_keyed_frames = false;

let demangled = demangle("_GLOBAL_$F$__7istreamiP9streambufP7ostream", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("istream::_GLOBAL_$F$(int, streambuf *, ostream *)")
);
let demangled = demangle("_GLOBAL_$F$__default_terminate", &config);
assert!(
    demangled.is_err()
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.demangle_global_keyed_frames = true;

let demangled = demangle("_GLOBAL_$F$__7istreamiP9streambufP7ostream", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("global frames keyed to istream::istream(int, streambuf *, ostream *)")
);
let demangled = demangle("_GLOBAL_$F$__default_terminate", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("global frames keyed to __default_terminate")
);
§ellipsis_emit_space_after_comma: bool

Emit an space between a comma and an ellipsis (...) in the argument list.

This is just another c++filt compatibility setting.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.ellipsis_emit_space_after_comma = false;

let demangled = demangle("Printf__7ConsolePce", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("Console::Printf(char *,...)")
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.ellipsis_emit_space_after_comma = true;

let demangled = demangle("Printf__7ConsolePce", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("Console::Printf(char *, ...)")
);
§fix_extension_int: bool

If enabled, emit __int128_t and __uint128_t types instead of int128_t and unsigned int128_t.

The former is valid syntax in g++ for this GNU integer extension type, while the latter is the syntax used by c++filt, but not accepted by g++.

This is just another c++filt compatibility setting.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_extension_int = false;

let demangled = demangle("testing_func__FRCI80", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("testing_func(int128_t const &)")
);
let demangled = demangle("testing_func__FRCUI80", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("testing_func(unsigned int128_t const &)")
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_extension_int = true;

let demangled = demangle("testing_func__FRCI80", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("testing_func(__int128_t const &)")
);
let demangled = demangle("testing_func__FRCUI80", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("testing_func(__uint128_t const &)")
);
§fix_array_in_return_position: bool

If enabled, emit proper syntax for arrays as return types in templated functions.

Disabling this option make it mimic the c++filt behavior for arrays in return position, which is not valid C++ but is simpler to read.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_array_in_return_position = false;

let demangled = demangle("an_array__H1Zi_X01_PA3_f", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("float (*)[3] an_array<int>(int)")
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_array_in_return_position = true;

let demangled = demangle("an_array__H1Zi_X01_PA3_f", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("float (*an_array<int>(int))[3]")
);
§fix_function_pointers_in_template_lists: bool

If enabled, emit proper syntax for return types of function pointers in template lists.

Disabling this option make it mimic the c++filt behavior for function pointers in template lists, which is not valid C++ but is simpler to read.

The c++filt behavior also omits the return type of the function pointer while this option does explicitly shows it.

§Examples

Turning off this setting (mimicking c++filt behavior):

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_function_pointers_in_template_lists = false;

let demangled = demangle("alloc__t5Table1PFUi_Pv16DefaultFunc__FUiUi", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("Table<&DefaultFunc(unsigned int)>::alloc(unsigned int)")
);

The setting turned on:

use gnuv2_demangle::{demangle, DemangleConfig};

let mut config = DemangleConfig::new();
config.fix_function_pointers_in_template_lists = true;

let demangled = demangle("alloc__t5Table1PFUi_Pv16DefaultFunc__FUiUi", &config);
assert_eq!(
    demangled.as_deref(),
    Ok("Table<(void *(*)(unsigned int)) &DefaultFunc>::alloc(unsigned int)")
);

Implementations§

Source§

impl DemangleConfig

Source

pub const fn new() -> Self

The default configuration.

Source

pub const fn new_g2dem() -> Self

Use improved output and valid C++ syntax whenever possible.

Source

pub const fn new_cfilt() -> Self

Mimics the (rather questionable) c++filt’s behavior, including what may be considered c++filt bugs.

Useful for validating demangling against c++filt.

Trait Implementations§

Source§

impl Clone for DemangleConfig

Source§

fn clone(&self) -> DemangleConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DemangleConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DemangleConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for DemangleConfig

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DemangleConfig

Source§

fn cmp(&self, other: &DemangleConfig) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DemangleConfig

Source§

fn eq(&self, other: &DemangleConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DemangleConfig

Source§

fn partial_cmp(&self, other: &DemangleConfig) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for DemangleConfig

Source§

impl Eq for DemangleConfig

Source§

impl StructuralPartialEq for DemangleConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.