gdb/python/py-threadevent.c - gdb

Functions defined

Source code

  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.

  2.    This file is part of GDB.

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

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

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

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

  16. /* thread events can either be thread specific or process wide.  If gdb is
  17.    running in non-stop mode then the event is thread specific, otherwise
  18.    it is process wide.
  19.    This function returns the currently stopped thread in non-stop mode and
  20.    Py_None otherwise.  In each case it returns a borrowed reference.  */

  21. static PyObject *get_event_thread (void)
  22.   CPYCHECKER_RETURNS_BORROWED_REF;

  23. static PyObject *
  24. get_event_thread (void)
  25. {
  26.   PyObject *thread = NULL;

  27.   if (non_stop)
  28.     thread = (PyObject *) find_thread_object (inferior_ptid);
  29.   else
  30.     thread = Py_None;

  31.   if (!thread)
  32.     {
  33.       PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
  34.       return NULL;
  35.     }

  36.   return thread;
  37. }

  38. PyObject *
  39. create_thread_event_object (PyTypeObject *py_type)
  40. {
  41.   PyObject *thread = NULL;
  42.   PyObject *thread_event_obj = NULL;

  43.   thread_event_obj = create_event_object (py_type);
  44.   if (!thread_event_obj)
  45.     goto fail;

  46.   thread = get_event_thread ();
  47.   if (!thread)
  48.     goto fail;

  49.   if (evpy_add_attribute (thread_event_obj,
  50.                           "inferior_thread",
  51.                           thread) < 0)
  52.     goto fail;

  53.   return thread_event_obj;

  54.   fail:
  55.    Py_XDECREF (thread_event_obj);
  56.    return NULL;
  57. }

  58. GDBPY_NEW_EVENT_TYPE (thread,
  59.                       "gdb.ThreadEvent",
  60.                       "ThreadEvent",
  61.                       "GDB thread event object",
  62.                       event_object_type,
  63.                       /*no qual*/);