Last active
November 20, 2015 02:14
-
-
Save jayrhynas/0ec7165890494d9a7f81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSThread { | |
class func logCallStack(showRedacted showRedacted: Bool = false) { | |
#if DEBUG | |
let removeRedacted: String -> Bool = { symbol in | |
return showRedacted ? true : symbol.rangeOfString("<redacted>", options: []) == nil | |
} | |
let swiftSymbolRegex = try! NSRegularExpression(pattern: " (_T\\S+) \\+", options: []) | |
let demangle: String -> String = { symbol in | |
let symbolStr = symbol as NSString | |
guard let match = swiftSymbolRegex.firstMatchInString(symbol, options: [], range: NSMakeRange(0, symbolStr.length)) | |
else { return symbol } | |
let range = match.rangeAtIndex(1) | |
let demangledName = _stdlib_demangleName(symbolStr.substringWithRange(range)) | |
return symbolStr.stringByReplacingCharactersInRange(range, withString: demangledName) | |
} | |
let symbols = self.callStackSymbols() | |
.dropFirst(2) // drop first two symbols (logCallStack and @objc logCallStack) | |
.filter(removeRedacted) | |
.map(demangle) | |
.joinWithSeparator("\n") | |
print(symbols) | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment