Xcode - 在断言上调用堆栈跟踪?
现在,当我的断言之一在 Xcode 中被触发时,我会收到断言消息和堆栈转储,其中充满了对我来说意义不大的数字。
为了获得调用堆栈的跟踪,它需要我调试应用程序,并将其运行到发生断言的位置,并希望它再次断言。对于 100% 可重现的错误来说,这并不是什么大问题,但仍然是浪费时间。
如果每次断言被命中时我都能得到调用堆栈跟踪,那就更好了。
如何定义一个断言宏来转储 Xcode 中的调用堆栈跟踪?
Right now when one of my asserts is triggered in Xcode, I get the assert message, and a dump of the stack, which is full of numbers that are not very meaningful to me.
In order to get a trace of the call stack, it requires me to debug the application, and run it up to the point where the assert occurred, and hope that it asserts again. For bugs that are 100% reproducible, this isn't too huge of a problem, but is still a waste of time.
It would be much better if I got a call stack trace every time an assert is hit.
How do you define an assert macro that will dump a call stack trace in Xcode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSThread
有一个名为callStackSymbols
的类方法(并且NSException
有一个同名的实例方法)。抱歉,我不经常使用异常,也不经常使用断言(不为这两个事实感到自豪),所以我不确定断言宏应该做什么。或者,正如 KennyTM 善意指出的那样,您可以使用
backtrace_symbols
。甚至有一种方法可以将符号直接输出到文件描述符,backtrace_symbols_fd
。NSThread
has a class method calledcallStackSymbols
(andNSException
has an instance method of the same name). Sorry, I don't regularly use exceptions and don't regularly use asserts either (not proud of either fact), so I'm not sure what the assertion macro should do.Or, as KennyTM kindly pointed out, you can use
backtrace_symbols
. There is even a method that outputs the symbols directly to a file descriptor,backtrace_symbols_fd
.在 iOS 4.x 上你可以使用 [NSThread callStackSymbols] 。
On iOS 4.x you can use [NSThread callStackSymbols] so.