gdb/python/py-exitedevent.c - gdb

Functions defined

Source code

  1. /* Python interface to inferior exit events.

  2.    Copyright (C) 2009-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "py-event.h"

  16. static PyTypeObject exited_event_object_type
  17.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");

  18. static PyObject *
  19. create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
  20. {
  21.   PyObject *exited_event;
  22.   PyObject *inf_obj = NULL;

  23.   exited_event = create_event_object (&exited_event_object_type);

  24.   if (!exited_event)
  25.     goto fail;

  26.   if (exit_code)
  27.     {
  28.       PyObject *exit_code_obj = PyLong_FromLongLong (*exit_code);
  29.       int failed;

  30.       if (exit_code_obj == NULL)
  31.         goto fail;

  32.       failed = evpy_add_attribute (exited_event, "exit_code",
  33.                                    exit_code_obj) < 0;
  34.       Py_DECREF (exit_code_obj);
  35.       if (failed)
  36.         goto fail;
  37.     }

  38.   inf_obj = inferior_to_inferior_object (inf);
  39.   if (!inf_obj || evpy_add_attribute (exited_event,
  40.                                       "inferior",
  41.                                       inf_obj) < 0)
  42.     goto fail;
  43.   Py_DECREF (inf_obj);

  44.   return exited_event;

  45. fail:
  46.   Py_XDECREF (inf_obj);
  47.   Py_XDECREF (exited_event);
  48.   return NULL;
  49. }

  50. /* Callback that is used when an exit event occurs.  This function
  51.    will create a new Python exited event object.  */

  52. int
  53. emit_exited_event (const LONGEST *exit_code, struct inferior *inf)
  54. {
  55.   PyObject *event;

  56.   if (evregpy_no_listeners_p (gdb_py_events.exited))
  57.     return 0;

  58.   event = create_exited_event_object (exit_code, inf);

  59.   if (event)
  60.     return evpy_emit_event (event, gdb_py_events.exited);

  61.   return -1;
  62. }


  63. GDBPY_NEW_EVENT_TYPE (exited,
  64.                       "gdb.ExitedEvent",
  65.                       "ExitedEvent",
  66.                       "GDB exited event object",
  67.                       event_object_type,
  68.                       static);