How do I generate a SIGINT when using XCode to debug?

Viewed 4773

My console app traps SIGINT so it can exit gracefully.

Pressing CTRL+C inside XCode while the program is being debugged, though, has no effect.

I can find the process and use a terminal window to send a SIGINT to my process, however I'm hoping there's a simpler solution that I can do within XCode.

6 Answers

Update for XCode 12+

In the modern versions of XCode it is hard to intercept SIGINT. For debug purposes it is better to use SIGINFO in place of SIGINT. You can generate that in Terminal using ^T (CTRL+T).

So during debugging temporary replace SIGINT with SIGINFO in your code. To intercept SIGINFO try next steps all together:

  1. Go to Product > Scheme > Edit Scheme > Run > Options and change Console from Use Xcode to Use Terminal.
  2. Run your program
  3. Pause the program
  4. In the Xcode console, enter this:
(lldb) process handle -p true -s false -n false SIGINFO

You will get:

NAME         PASS   STOP   NOTIFY
===========  =====  =====  ======
SIGINFO      true   false  false
  1. Resume the program
  2. Switch to Terminal and press CTRL+T.

Your signal handler will fire.

Don't forget to return SIGINT back after finishing debugging!

Related