Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3] Avoid find_thread_ptid with null_ptid
Date: Mon, 01 Oct 2018 10:32:00 -0000	[thread overview]
Message-ID: <20181001103252.5150-2-palves@redhat.com> (raw)
In-Reply-To: <20181001103252.5150-1-palves@redhat.com>

With a following patch, find_thread_ptid will first find the inferior
for the passed-in ptid, using find_inferior_pid, and then look for the
thread in that inferior's thread list.  If we pass down null_ptid to
find_thread_ptid then that means we'll end up passing 0 to
find_inferior_pid, which hits this assertion:

>   struct inferior *
>   find_inferior_pid (int pid)
>   {
>     struct inferior *inf;
>
>     /* Looking for inferior pid == 0 is always wrong, and indicative of
>	a bug somewhere else.  There may be more than one with pid == 0,
>	for instance.  */
>     gdb_assert (pid != 0);

This patch prepares for the change, by avoiding passing down null_ptid
to find_thread_ptid or to functions that naturally use it, such as the
target_pid_to_str call in inferior.c:add_inferior.  In that latter
case, the patch changes GDB output,

from:
 (gdb) add-inferior
 [New inferior 2 (process 0)]

to:
 (gdb) add-inferior
 [New inferior 2]

which seems like a good change to me.  It might not even make sense to
talk about "process" for the current target, for example.

The python_on_normal_stop change ends up avoiding looking up the
same thread twice (inferior_thread also does a look up).

gdb/ChangeLog:
yyyy-mm-dd  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.
---
 gdb/cli/cli-interp.c     |  4 +---
 gdb/inferior.c           | 11 ++++++++---
 gdb/python/py-inferior.c |  4 ++--
 gdb/tui/tui-interp.c     |  4 +---
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 2aa41d6c8b..2d8482fa49 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -251,13 +251,11 @@ cli_on_command_error (void)
 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 ()
     {
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 17d28c4cf5..394386a4b7 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -122,9 +122,14 @@ add_inferior (int pid)
   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;
 }
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 5bba676478..7f8644b94b 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -86,8 +86,8 @@ python_on_normal_stop (struct bpstats *bs, int print_frame)
   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;
 
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index acc8f0371c..a4f3925198 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -210,13 +210,11 @@ tui_on_command_error (void)
 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 ()
     {
-- 
2.14.4


  reply	other threads:[~2018-10-01 10:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 10:32 [PATCH 0/3] Per-inferior thread list, multi-target prep Pedro Alves
2018-10-01 10:32 ` Pedro Alves [this message]
2018-10-01 15:54   ` [PATCH 1/3] Avoid find_thread_ptid with null_ptid Tom Tromey
2018-10-02 17:08     ` Pedro Alves
2018-10-01 10:33 ` [PATCH 3/3] Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc Pedro Alves
2018-10-01 16:33   ` John Baldwin
2018-10-02 13:21     ` Pedro Alves
2018-10-03 17:34       ` John Baldwin
2018-10-04 19:16         ` Pedro Alves
2018-10-01 17:12   ` Tom Tromey
2018-10-03 12:12     ` Pedro Alves
2018-10-01 10:33 ` [PATCH 2/3] Fix follow_exec latent problem Pedro Alves
2018-11-22 16:28 ` [PATCH 0/3] Per-inferior thread list, multi-target prep Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181001103252.5150-2-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox