+2018-11-22  Pedro Alves  <palves@redhat.com>
+
+       * cli/cli-interp.c (cli_on_user_selected_context_changed): Use
+       inferior_thread instead of find_thread_ptid, and only when
+       inferior_ptid is not null_ptid.
+       * inferior.c (add_inferior): Don't include target_pid_to_str
+       output when the inferior is not started.
+       * python/py-inferior.c (python_on_normal_stop): Don't use
+       find_thread_ptid.
+       (tui_on_user_selected_context_changed): Use inferior_thread
+       instead of find_thread_ptid, and only when inferior_ptid is not
+       null_ptid.
+
 2018-11-21  Benno Fünfstück  <benno.fuenfstueck@gmail.com>
 
        PR python/23714
 
 static void
 cli_on_user_selected_context_changed (user_selected_what selection)
 {
-  struct thread_info *tp;
-
   /* This event is suppressed.  */
   if (cli_suppress_notification.user_selected_context)
     return;
 
-  tp = find_thread_ptid (inferior_ptid);
+  thread_info *tp = inferior_ptid != null_ptid ? inferior_thread () : NULL;
 
   SWITCH_THRU_ALL_UIS ()
     {
 
   struct inferior *inf = add_inferior_silent (pid);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[New inferior %d (%s)]\n"),
-                      inf->num,
-                      target_pid_to_str (ptid_t (pid)));
+    {
+      if (pid != 0)
+       printf_unfiltered (_("[New inferior %d (%s)]\n"),
+                          inf->num,
+                          target_pid_to_str (ptid_t (pid)));
+      else
+       printf_unfiltered (_("[New inferior %d]\n"), inf->num);
+    }
 
   return inf;
 }
 
   if (!gdb_python_initialized)
     return;
 
-  if (!find_thread_ptid (inferior_ptid))
-      return;
+  if (inferior_ptid == null_ptid)
+    return;
 
   stop_signal = inferior_thread ()->suspend.stop_signal;
 
 
 static void
 tui_on_user_selected_context_changed (user_selected_what selection)
 {
-  struct thread_info *tp;
-
   /* This event is suppressed.  */
   if (cli_suppress_notification.user_selected_context)
     return;
 
-  tp = find_thread_ptid (inferior_ptid);
+  thread_info *tp = inferior_ptid != null_ptid ? inferior_thread () : NULL;
 
   SWITCH_THRU_ALL_UIS ()
     {