How to print exception stack trace of Objective-C exceptions with GNU runtime and without GNUStep?

徘徊边缘 提交于 2019-12-13 16:03:53

问题


I have an Objective-C app build on Linux with GCC 4.3 using no specific framework (only GNU-runtime). I am using Objective-C exceptions (via the '-fobjc-exceptions' compiler flag).

Now I want to print the stack trace of such an exception when I caught some. Or what would make me even happier: put the trace in a string or some kind of structure to evaluate or print it later on.

How can that be achieved?


回答1:


  NSArray * stack = [NSThread callStackSymbols];

It may help.




回答2:


Since no more knowledge is floating in, here is what I found out by myself:

At least under Linux I can use the GNU extensions backtrace and backtrace_symbols to get addresses of the call stack and the corresponding symbols. This helps a little but is far away from the information that gdb gives. There are neither line numbers nor arguments values.

With the glibc extension dladdr I can get similar information but not further.

This is still not exactly what I'm looking for but no one got so clause – so I would accept my own answer :(.



来源:https://stackoverflow.com/questions/3651204/how-to-print-exception-stack-trace-of-objective-c-exceptions-with-gnu-runtime-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!