How To Loop Through All Active Thread in iPad app

前端 未结 2 671
傲寒
傲寒 2020-12-13 01:03

In the iPad app that I\'m creating, I\'m trying to handle the uncaught Exceptions by outputting the callStackSymbols of the exception. This can be done with [NSExcepti

相关标签:
2条回答
  • 2020-12-13 01:47

    This seems fraught with peril, doubly so if you need to ask here for help. May I suggest PLCrashReporter? Its listed features are:

    • Implemented as a in-process fully async-safe signal handler.
    • Does not interfere with debugging in gdb
    • Handles both uncaught Objective-C exceptions and fatal signals (SIGSEGV, SIGBUS, etc)
    • Backtraces for all active threads are provided. (emphasis my own)
    • Provides full register state for the crashed thread.

    Better yet, have a look at QuincyKit, a very handy wrapper around PLCrashReporter.

    0 讨论(0)
  • 2020-12-13 01:57

    This is a complex area, as Sedate Alien noted. You will need to implement your own stack walking to retrieve a stack trace from the other active threads; APIs such as backtrace(3) and +[NSThread callStackSymbols] will only produce a backtrace for the current thread.

    Since I'm familiar with the PLCrashReporter code, I'll just use it for examples:

    • To fetch the thread list, you'll need to use task_threads(): https://opensource.plausible.coop/stash/projects/PLCR/repos/plcrashreporter/browse/Source/PLCrashLogWriter.m?at=refs%2Ftags%2F1.0#694

    • Once you have the thread list, you can fetch the thread state via thread_get_state(): https://opensource.plausible.coop/stash/projects/PLCR/repos/plcrashreporter/browse/Source/PLCrashFrameWalker_arm.c?at=refs%2Ftags%2F1.0#73

    • Using the thread state, you can walk the target's stack: https://opensource.plausible.coop/stash/projects/PLCR/repos/plcrashreporter/browse/Source/PLCrashFrameWalker_arm.c?at=refs%2Ftags%2F1.0#104

    Note that all this code is a bit unusual, as it executes within a signal handler and is written to be async-safe; if you're unfamiliar with the complications around signal handling, this is a good starting point: http://www.mikeash.com/pyblog/friday-qa-2011-04-01-signal-handling.html

    Implementing this kind of thing correctly is a gigantic headache; I would really recommend that you make use of PLCrashReporter, or one of the products built on top of it (QuincyKit, HockeyApp, Atlassian JMC, etc).

    0 讨论(0)
提交回复
热议问题