py-threadevent.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (C) 2009-2022 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. #include "gdbthread.h"
  17. /* See py-event.h. */
  18. gdbpy_ref<>
  19. py_get_event_thread (ptid_t ptid)
  20. {
  21. if (non_stop)
  22. {
  23. thread_info *thread
  24. = find_thread_ptid (current_inferior ()->process_target (),
  25. ptid);
  26. if (thread != nullptr)
  27. return thread_to_thread_object (thread);
  28. PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
  29. return NULL;
  30. }
  31. return gdbpy_ref<>::new_reference (Py_None);
  32. }
  33. gdbpy_ref<>
  34. create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
  35. {
  36. gdb_assert (thread != NULL);
  37. gdbpy_ref<> thread_event_obj = create_event_object (py_type);
  38. if (thread_event_obj == NULL)
  39. return NULL;
  40. if (evpy_add_attribute (thread_event_obj.get (),
  41. "inferior_thread",
  42. thread) < 0)
  43. return NULL;
  44. return thread_event_obj;
  45. }