Debug SIGTERM handler in Xcode?

Xcode 6.3.2


I have a daemon that hooks SIGHUP, SIGINT, and SIGTERM. They all direct the signals to call a signal_handler() function.


I was having an intermittent crash when the daemon was existing, so I ran the process in Xcode hoping to catch the problem. Unfortunately, I can't reproduce it. When I send the process a SIGTERM (kill -TERM <pid>), Xcode breaks in my run loop and says my process received a SIGTERM. Unexpected, but OK.


But then I click on the Continue button and ... nothing happens. The program goes right back to running normally, The signal_handler() function is never called.


Does anyone know how I can debug signals using the debugger, without the debugger intercepting it and "eating" the signal?

Answered by Ken Thomases in 17879022

You need to use the "process signal SIGTERM" command at the lldb console prompt to continue and deliver the signal.


Alternatively, you can use "process handle -s0 -p1 SIGTERM" in advance to tell the debugger to not stop when the signal is received and to pass it along to the debugee.

Accepted Answer

You need to use the "process signal SIGTERM" command at the lldb console prompt to continue and deliver the signal.


Alternatively, you can use "process handle -s0 -p1 SIGTERM" in advance to tell the debugger to not stop when the signal is received and to pass it along to the debugee.

Ken,


Thanks a million! That did the trick nicely. For future reference, the lldb command to change how the debugger handles a specific signal is


process handle <SIGNALNAME> [ --pass <true|false|1|0> ] [ --stop <true|false|1|0> ] [ --notify <true|false|1|0> ]


--pass determines if the signal will be passed to the process' signal handler

--stop determines if the debugger will stop your process when a signal is received

--notify controls whether a message about the signal gets logged


In my case, the solution was: process handle SIGTERM --stop false --pass true

Is it possible to configure Xcode, so the the lldb always does the "process handle SIGTERM --stop false --pass true"?

When launching the app inside Xcode?

instead of always having to type in the "process handle SIGTERM --stop false --pass true" everytime (it's getting a bit tedious to re-type this everytime you CMD+R the app, when you are testing that it's handling the signals correctly ....)

Would be nice if there was a setting in inside Xcode, that you could configure the lldb with what you want it to do each time.

You can put a breakpoint that executes the lldb command and automatically continues somewhere in your app startup code. See https://stackoverflow.com/a/25631359/292145

Debug SIGTERM handler in Xcode?
 
 
Q