+2018-08-24  Pedro Alves  <palves@redhat.com>
+           Simon Marchi  <simon.marchi@ericsson.com>
+
+       PR gdb/23379
+       * python/py-continueevent.c: Include "gdbthread.h".
+       (create_continue_event_object): Add intro comment.  Add 'ptid'
+       parameter.  Use it to find thread to pass to
+       create_thread_event_object.
+       (emit_continue_event): Pass PTID down to
+       create_continue_event_object.
+       * python/py-event.h (py_get_event_thread): Declare.
+       (create_thread_event_object): Remove default from 'thread'
+       parameter.
+       * python/py-stopevent.c (create_stop_event_object): Use
+       py_get_event_thread.
+       * python/py-threadevent.c (get_event_thread): Rename to ...
+       (py_get_event_thread): ... this, make extern, add 'ptid' parameter
+       and use it to find the thread.
+       (create_thread_event_object): Assert that THREAD isn't null.
+       Don't find the event thread here.
+
 2018-08-23  Kevin Buettner  <kevinb@redhat.com>
 
        * block.h (blockrange, blockranges): New struct declarations.
 
 #include "defs.h"
 #include "py-event.h"
 #include "py-ref.h"
+#include "gdbthread.h"
+
+/* Create a gdb.ContinueEvent event.  gdb.ContinueEvent is-a
+   gdb.ThreadEvent, and thread events can either be thread specific or
+   process wide.  If gdb is running in non-stop mode then the event is
+   thread specific (in which case the PTID thread is included in the
+   event), otherwise it is process wide (in which case PTID is
+   ignored).  In either case a new reference is returned.  */
 
 static gdbpy_ref<>
-create_continue_event_object (void)
+create_continue_event_object (ptid_t ptid)
 {
-  return create_thread_event_object (&continue_event_object_type);
+  PyObject *py_thr = py_get_event_thread (ptid);
+
+  if (py_thr == nullptr)
+    return nullptr;
+
+  return create_thread_event_object (&continue_event_object_type, py_thr);
 }
 
 /* Callback function which notifies observers when a continue event occurs.
   if (evregpy_no_listeners_p (gdb_py_events.cont))
     return 0;
 
-  gdbpy_ref<> event (create_continue_event_object ());
+  gdbpy_ref<> event (create_continue_event_object (ptid));
   if (event != NULL)
     return evpy_emit_event (event.get (), gdb_py_events.cont);
   return -1;
 
                             eventregistry_object *registry);
 
 extern gdbpy_ref<> create_event_object (PyTypeObject *py_type);
+
+/* thread events can either be thread specific or process wide.  If gdb is
+   running in non-stop mode then the event is thread specific, otherwise
+   it is process wide.
+   This function returns the currently stopped thread in non-stop mode and
+   Py_None otherwise.  In each case it returns a borrowed reference.  */
+extern PyObject *py_get_event_thread (ptid_t ptid)
+  CPYCHECKER_RETURNS_BORROWED_REF;
+
 extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type,
-                                              PyObject *thread = nullptr);
+                                              PyObject *thread);
+
 extern int emit_new_objfile_event (struct objfile *objfile);
 extern int emit_clear_objfiles_event (void);
 
 
 gdbpy_ref<>
 create_stop_event_object (PyTypeObject *py_type)
 {
-  return create_thread_event_object (py_type);
+  return create_thread_event_object (py_type,
+                                    py_get_event_thread (inferior_ptid));
 }
 
 /* Callback observers when a stop event occurs.  This function will create a
 
 #include "infrun.h"
 #include "gdbthread.h"
 
-/* thread events can either be thread specific or process wide.  If gdb is
-   running in non-stop mode then the event is thread specific, otherwise
-   it is process wide.
-   This function returns the currently stopped thread in non-stop mode and
-   Py_None otherwise.  In each case it returns a borrowed reference.  */
+/* See py-event.h.  */
 
-static PyObject *get_event_thread (void)
-  CPYCHECKER_RETURNS_BORROWED_REF;
-
-static PyObject *
-get_event_thread (void)
+PyObject *
+py_get_event_thread (ptid_t ptid)
 {
-  PyObject *thread;
+  PyObject *pythread;
 
   if (non_stop)
-    thread = (PyObject *) thread_to_thread_object (inferior_thread ());
+    {
+      thread_info *thread = find_thread_ptid (ptid);
+      if (thread != nullptr)
+       pythread = (PyObject *) thread_to_thread_object (thread);
+    }
   else
-    thread = Py_None;
+    pythread = Py_None;
 
-  if (!thread)
+  if (!pythread)
     {
       PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
       return NULL;
     }
 
-  return thread;
+  return pythread;
 }
 
 gdbpy_ref<>
 create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
 {
+  gdb_assert (thread != NULL);
+
   gdbpy_ref<> thread_event_obj (create_event_object (py_type));
   if (thread_event_obj == NULL)
     return NULL;
 
-  if (thread == NULL)
-    {
-      thread = get_event_thread ();
-      if (!thread)
-       return NULL;
-    }
-
   if (evpy_add_attribute (thread_event_obj.get (),
                           "inferior_thread",
                           thread) < 0)