How do you print out a stack trace to the console/log in Cocoa?

前端 未结 6 1296
旧巷少年郎
旧巷少年郎 2020-12-04 04:49

I\'d like to log the call trace during certain points, like failed assertions, or uncaught exceptions.

6条回答
  •  渐次进展
    2020-12-04 05:19

    Cocoa already logs the stack trace on uncaught exceptions to the console although they're just raw memory addresses. If you want symbolic information in the console there's some sample code from Apple.

    If you want to generate a stack trace at an arbitrary point in your code (and you're on Leopard), see the backtrace man page. Before Leopard, you actually had to dig through the call stack itself.

提交回复
热议问题