Can Core Foundation be used in PLCrashReporter callback?

I am using PLCrashReporter in my iOS project and I am curious if the Core Foundation code can be used in my normal callback mode. The thing that handles my needs is CFPreferences. Here is part of the code I am creating:

void LMCrashCallback(siginfo_t* info, ucontext_t* uap, void* context) {
  CFStringRef networkStatusOnCrash;
  networkStatusOnCrash = (CFStringRef)CFPreferencesCopyAppValue(networkStatusKey, kCFPreferencesCurrentApplication);
  CFStringRef additionalInfo = CFStringCreateWithFormat(
              NULL, NULL, CFSTR( "Additional Crash Properties:[Internet: %@]", networkStatusOnCrash);
  CFPreferencesSetAppValue(additionalInfoKey, additionalInfo,
                           kCFPreferencesCurrentApplication);
  CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
}

      

My goal is to collect some system information, just in time when the application crashed, such as the type of internet connection.

I know it's a good idea to create your own callback on failure due to asynchronous functions, but it might help.

Also as another option: is there a way to extend some kind of PLCrashReportSystemInfo class?

+3


source to share


1 answer


It is very dangerous. In particular, the call CFStringCreateWithFormat

allocates memory. Allocating memory in the middle of a crash handler can lead to battery deadlock (yes, there was this error ...) For example, if you were in the middle free()

(which is not an unusual place to crash), you may already be holding a spinlock on the heap. When you call malloc

to get some memory, you can spin the heap again and get stumped. The heap must be locked so often and in such short periods of time that it does not use the locking lock. This is equivalent while (locked) {}

.

You seem to be just reading the preference and copying it to another preference. There is no reason to do this inside a fault handler. Just check hasPendingCrashReport

during startup (which I assume you are already doing) and then read the key. It's not clear what it is networkStatusKey

, but it should still be there when you run it again.



If for some reason it was changed very early (before you call it hasPendingCrashReport

), you can grab it in main()

before starting the application. Or you can grab it in a method +load

that gets called even earlier.

+3


source







All Articles