Search code examples
gdbgudgdb-python

gdb Python API: exceptions disappearing?


Does anyone know why, in certain places, Python code inside of gdb doesn't properly handle exceptions? Or, to clarify, perhaps the exception message is going somewhere other than the *gud buffer. gdb is not returning control to the prompt, as expected.

(I'm using GNU gdb (GDB) 7.11.50.20160212-git in Emacs (24.5.1) gud mode)

For example:

class SomeEvent():
   def __init__(self, ...):
      ... do something ...
   def __call__(self):
      ... do something BAD here ...


gdb.post_event(SomeEvent())

When 'SomeEvent' is handled, it will just execute '__call__' up to the bad code, return, and then continue normal operation (as I can observe).

I've noticed this behavior in other 'callback' type methods, such as Stop() of a subclassed gdb.Breakpoint.


Solution

  • gdb.post_event ignores exceptions when the event object is invoked. You can see this clearly in the source code, in gdbpy_run_events:

      /* Ignore errors.  */
      call_result = PyObject_CallObject (item->event, NULL);
      if (call_result == NULL)
        PyErr_Clear ();
    

    This seems like a bug to me -- it would be more useful to print a stack trace or something instead.