Open xPaw opened 1 month ago
On any given system, the C++ compiler will generate either __Znwm
or _Znwm
. It would be incorrect to discard a leading underscore on systems that don't add a leading underscore. So it should never be the case that manually stripping an underscore can break demangling strings. You should strip a leading underscore if your symbols have leading underscores, and not strip it if you don't.
Is there a practical case where this could cause issues?
This tool in particular does it automatically (it also handles Windows symbols by itself too, so there's that) https://github.com/nico/demumble
In my opinion doing it automatically is unwise. It will do the wrong thing in some cases. It should never be ambiguous whether a symbol might or might not be a mangled name.
There's this code:
https://github.com/ianlancetaylor/demangle/blob/81f5be970ecae4046912a026004100b0535be16e/demangle.go#L153-L156
I don't see why it can't support double underscores by itself either. Currently it requires manually stripping the underscore, but then it breaks demangling strings that already have only one underscore.
For example:
echo "__Znwm" | c++filt -_