Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 881
Adam Davis Avatar asked Jul 08 '11 17:07

Adam Davis


3 Answers

The pause button of the debugger console actually sends a SIGINT to your app. If you want to make the debugger pass the signal to your app you can do the following:

  1. Press the pause button of the debugger and wait for the debug console to gain focus
  2. Type handle SIGINT pass and press ENTER
  3. Press the Continue button

Now pressing again the Pause button of the debugger console of Xcode will make the SIGINT hit your app.

If you don't want the debugger to stop as soon as the SIGINT is caught you might also want to add handle SIGINT nostop to the previous list.

like image 145
alediaferia Avatar answered Nov 19 '22 18:11

alediaferia


Update for 2017 / Xcode 8: the proper command(s) for informing lldb of your intention for handling interrupts:

process handle SIGINT -s false
process handle SIGINT -p true

In my experience, even with the above commands, the pause feature of the debugger still will interrupt the app and yield control to the debugger's stack pointer, however a pkill -2 appname at the terminal will trigger your interrupt function without any interaction with the debugger, for example:

void on_signal(int sig) {
  is_interrupted = 1;
}

int main(int argc, const char * argv[]) {
  signal(SIGINT, on_signal);
  // ... do stuff
}
like image 6
wobbals Avatar answered Nov 19 '22 18:11

wobbals


In Xcode 5+ (llvm):

  1. Pause the process

  2. At the (llvm) prompt, enter process signal SIGINT

  3. Resume execution

like image 4
craig65535 Avatar answered Nov 19 '22 19:11

craig65535