I’ve been working on a command-line app to analyze the link map generated when we build our app and report on the size of each module and each file within that module. I also wanted to provide a means of showing information about the individual symbols within each file, but the names of the symbols are mangled:_$sSo31AVCaptureVideoStabilizationModeVSHSCSH9hashValueSivgTW
There is a command-line demangling tool that is part of the Swift distribution, but it simply refused to spit out a value. I kept getting a value of _ ---> _
, which indicates it couldn’t understand the string.
Eventually, I discovered that you need to replace the leading “_” with a “\” backslash character. This is needed because the “$” symbol is reserved in the shell and needs to be escaped. If you try to demangle a symbol with a leading “$” the shell will hang until you press Ctrl+C. So, the string becomes:\$sSo31AVCaptureVideoStabilizationModeVSHSCSH9hashValueSivgTW
When fed into swift demangle
, I finally got the output I was looking for:protocol witness for Swift.Hashable.hashValue.getter : Swift.Int in conformance __C.AVCaptureVideoStabilizationMode : Swift.Hashable in __C_Synthesized
Certainly more readable, but an awfully long “name” for the symbol. I’ll figure that out next.