Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for UNDNAME_NO_ARGUMENTS #71

Open
garyttierney opened this issue Feb 5, 2024 · 1 comment
Open

Support for UNDNAME_NO_ARGUMENTS #71

garyttierney opened this issue Feb 5, 2024 · 1 comment

Comments

@garyttierney
Copy link

Using the NO_ARGUMENTS flag with UnDecorateSymbolName allows the user to demangle a plain type (e.g. RTTI name) with no symbol. This is useful for demangling names produced by type_id().

The MSDN documentation implies this would be used to avoid demangling function parameters, but the WINE implementation (and in my experience) disagrees: https://github.com/wine-mirror/wine/blob/master/dlls/msvcrt/undname.c#L1458-L1469.

The easy way forward is simply to shortcut to read_var_type() in parse if that flag is present and return no Symbol. I've tested a hack that does something like this to make sure it works:

    fn parse(&mut self) -> Result<ParseResult<'a>> {
        // MSVC-style mangled symbols must start with b'?'.
        if !self.consume(b"?") {
            return Err(self.fail("does not start with b'?'"));
        }

        if self.type_only {
            let ty = self.read_var_type(StorageClass::empty())?;
            return Ok(ParseResult {
                // TODO: making the `Symbol` an `Option` would be a breaking change, how should we handle this?
                symbol: Symbol {
                    name: Name::Discriminator(0),
                    scope: NameSequence { names: Vec::new() }
                },
                symbol_type: ty,
            });
        }

And adjust the serializer to only emit the type. I have a work in progress patch and will open a PR shortly, but the current issues I have are how to handle the optional Symbol and any information about NO_ARGUMENTS that I might be missing beyond my own experience/the WINE implementation.

@garyttierney
Copy link
Author

garyttierney commented Feb 5, 2024

Examples: https://godbolt.org/z/YMEWq3q5x

??_R0?AV?$C@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@8 DQ FLAT:??_7type_info@@6B@ ; C<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > `RTTI Type Descriptor'
        DQ      0000000000000000H
        DB      '.?AV?$C@V?$basic_string@DU?$char_traits@D@std@@V?$alloca'
        DB      'tor@D@2@@std@@@@', 00H
??_R0?AVB@0@@8 DQ FLAT:??_7type_info@@6B@             ; B::B `RTTI Type Descriptor'
        DQ      0000000000000000H
        DB      '.?AVB@0@', 00H
??_R0?AVA@@@8 DQ FLAT:??_7type_info@@6B@                ; A `RTTI Type Descriptor'
        DQ      0000000000000000H
        DB      '.?AVA@@', 00H

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant