How to create SIGINT when using Xcode for debugging?

My console applications trap SIGINT so it can exit gracefully.

Pressing CTRL + C inside Xcode while debugging a program has no effect.

I can find the process and use the terminal window to send SIGINT to my process, however I hope that there will be a simpler solution that I can make in Xcode.

+6
source share
5 answers

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

  • Press the pause button of the debugger and wait until the debug console receives focus.
  • Type handle SIGINT pass and press Enter
  • Click Continue

Now press the Pause button of the Xcode debugger console again so that SIGINT gets into your application.

If you do not want the debugger to stop as soon as SIGINT is caught, you can also add handle SIGINT nostop to the previous list. p>

+5
source

In Xcode 5+ (llvm):

  • Pause the process

  • At the prompt (llvm) type process signal SIGINT

  • Resume execution

+3
source

One of the tasks associated with working with interrupts is to create MainMenu with a short CTRL-C clipping that executes the requested procedure or sends itself a SIGINT if you really need a whitefish.

+1
source

One solution is to use the UNIX kill or killall commands.

If you know the process ID, you can open a terminal application and enter:

 kill -SIGINT 415 

(where 415 is the PID for this process)

Or maybe easier, you can enter

 killall -SIGINT my_console_app 

(where my_console_app is the name of your application, i.e. the name of the generated binary file, and not a set if it is in one)

This will send a signal to all instances of the application, as the name killall suggests, so it may be unacceptable. It might be worth checking if there are other processes with the same name that will be executed before you execute killall (;

+1
source

Update for 2017 / Xcode 8 : the right command to inform lldb of your intention to handle interrupts:

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

In my experience, even with the above commands, the pause function of the debugger will still interrupt the application and give control to the debugger stack pointer, however pkill -2 appname on the terminal will call 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 } 
+1
source

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


All Articles