-
Notifications
You must be signed in to change notification settings - Fork 493
Proper symbol demangling for doReadClassName
#5093
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
Conversation
|
I wish I had seen the discussion sooner. I had a similar effort going on https://github.com/lethosor/dfhack/commits/cxx-demangle-windows/ about a year ago. I hadn't touched It would be great if cxx_demangle in MiscUtils could use your changes too: https://github.com/DFHack/dfhack/blob/e4f3cd94ce621d02ae82e82a68a418d8c45bd01c/library/MiscUtils.cpp#L672C27-L672C39 |
|
@lethosor I absolutely should be able to update Take the following demangled symbol for example: class std::_Func_impl_no_alloc<class `public: void __cdecl widgets::widget::set_custom_render(class std::function<void __cdecl(class widgets::widget * __ptr64)>) __ptr64'::`2'::<lambda_1>,void,class widgets::widget * __ptr64,unsigned int>Do we want to include the class specifiers, visibility modifiers, or any other markers? I know that a number of those don't seem to appear in a gcc mangled name. |
|
I would care more about what more "normal" symbols look like, i.e. things that we're more likely to demangle. Mainly things like global type names ( I think the bigger question is what DFHack currently cares about. Thanks for looking into the UNDNAME flags. |
|
It is true The main reason for the change was for cross-platform consistency and ensuring the function returns a result that isn't trimmed in unusual manners. This mainly affects classes inside of namespaces or including template parameters. Class names that aren't in the format of If this is a change that doesn't seem warranted at this time, I am glad to simply repurpose portions of this experiment into improving |
|
Through further testing I have discovered inconsistencies can occur when running under wine. The affected symbols were discovered via a An example of an offending symbol: is (improperly) demangled to std::shared_ptr<widgets::container>::_Func_impl_no_allocIn the simpler symbols with fewer template arguments I am yet to see any unusual results. |
Isn't this also the case for classes that do match that pattern? (or did you mean "are" instead of "aren't"?) The focus string logic is very specific to viewscreens, so I don't think
for comparison, what's the "proper" result? |
|
All strings returned by doClassName are trimmed as described, not just ones not matching the standard pattern. At this point, it looks like adding Windows support to cxxDemangle would be preferable and introduce fewer potential issues. The proper demangling of the symbol I previously provided would be: std::_Func_impl_no_alloc<`widgets::add_happiness_tex'::`2'::<lambda_1>,void>The demangled result still looks somewhat incorrect, but at least seems more accurate. Wine contains a flawed implementation of demangling which causes some symbols to fail demangling as well. As such, the use of the For the time being I am closing this PR as the changes are not critical and may cause additional problems in some environments. |
This replaces the flawed manual demangling with proper demanglers capable of supporting additional language features such as namespaces.
For example, the mangled symbol
N6DFHack21dfhack_lua_viewscreenEwas previously demangled asDFHack21dhack_lua_viewscreenE. This patch ensures demangling returns the properDFHack::dfhack_lua_viewscreen. This also ensures that class names returned remain consistent between platforms.Basic functionality has been tested on Linux, Windows, and Wine, with no unexpected results seen so far.