This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Handle SIGINT in Python


>just my 2 cents to the discussion.
>[I'm not sure I could follow all the arguments, so my comments are based on Khoo's patch]
>
>+static void
>+gdbpy_handle_sigint (int sig)
>+{
>+  PyErr_SetInterrupt ();
>+}
>
>I would be quite afraid if GDB could throw an KeyboardInterruptException in any call to its API, there wouldn't be any way to ensure internal consistency inside the script, except with try_catch surrounding every GDB function call ...

Of course, but that is exactly what you want.  In any Python script, if you need to handle interrupts for proper operation, you wrap the critical section in a try..except block.  If not, then you don't.  There is nothing new or different here in the GDB case.  Any Python statement can throw a KeyboardException.

The only difference is in what happens when you get to the top of a Python script with a KeyboardInterrupt exception and no one is catching it.  In an interactive session (python shell) you get a backtrace.  I think in a Python interactive session inside GDB ("python" command with no arguments) the same should be true.  In a script invocation from the command shell (outside GDB) you'd also get a traceback in this case.  In GDB, you probably should not, as was discussed earlier; in that case, the interrupt should be passed up to the GDB common machinery to handle exactly as it would handle an interrupt for any other command, without a Python style traceback printout.

	paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]