How to intercept EXC_BAD_INSTRUCTION when deploying Nil

I am building some basic crash logging system based on this blog post ( yes , I know about PLCRashReporter and no , I can’t use it and I need to roll my own, albeit limited. Thanks).

My code registers both an exception handler (s NSSetUncaughtExceptionHandler()) and a signal handler for most signals:

SIGQUIT
SIGILL
SIGTRAP
SIGABRT
SIGEMT
SIGFPE
SIGBUS
SIGSEGV
SIGSYS
SIGPIPE
SIGALRM
SIGXCPU
SIGXFSZ

It seems to work just fine with Objective-C basic things like "unrecognized selector sent to instance ..." etc.


Then I tried this with the following Swift code :

var empty:String! = nil

let index = empty.startIndex // < KA-BOOM!

... EXC_BAD_INSTRUCTION ( ), :

:

... Xcode.

?

, SIGTRAP; , , , .


: , Swift ( , ..); . , XCode EXC_BAD_INSTRUCTION, : , ?


2: , , 20+, signal.h ( ); , .


3: Apple " " :

Trace Trap [EXC_BREAKPOINT//SIGTRAP]

, , . , __builtin_trap(). , .

(, libdispatch) . " " .

Swift , , :

  • nil

, , . . , . , .

( )

: SIGTRAP?

+8
1

TL; DR: , .


, , , SIGUSR1 ( "" ) kill():

kill(0, SIGUSR1);

Xcode , kill(), , .

, , / , , .

, :

process handle SIGUSR1 -n true -p true -s false

... Xcode :

kill(pid, SIGUSR1);

... , . ; ..

SIGTRAP ( SIGABRT), ( !), (, ), Swift, , .


, unrecognized selector sent to instance... , , Objective C, Unix . ( " Objective C"?).

, NSSetUncaughtExceptionHandler() ...

( , , , / , )

+5

Source: https://habr.com/ru/post/1660932/


All Articles