demangle
demangle copied to clipboard
Handle double leading underscores on Mac
Filter() cannot handle double leading underscore on Mac OS X.
Here is a sample code and output:
package main
import (
"github.com/ianlancetaylor/demangle"
"fmt"
)
func main(){
name := "__ZNSt3__111char_traitsIcE11eq_int_typeEii"
options := []demangle.Option{demangle.NoParams, demangle.NoTemplateParams}
fmt.Println(demangle.Filter(name, options...))
fmt.Println(demangle.Filter(name[1:], options...))
}
Output:
$> go run test.go
__ZNSt3__111char_traitsIcE11eq_int_typeEii
std::__1::char_traits::eq_int_type
it's because macOS prefix every symbol with an extra underscore. I think it's the caller's responsibility to remove it before passing it to Filter.
For example, c++filt on macOS also doesn't handle the example unless the leading underscore is stripped.
Yes, stripping it easy but it's fairly straight forward to detect the platform and handle the leading underscore. It makes the use of the package easier and returns the expected results.
I guess adding a StripLeadingUnderscore Option might be OK, but stripping it unconditionally might be undesirable as the underscored version really is not C++ mangled name defined by the IA64 ABI (what if there is another platform that adds another prefix or even suffix to standard mangled name?)