问题
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