summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2018-11-22 16:09:12 +0000
committerPedro Alves <palves@redhat.com>2018-11-22 16:09:12 +0000
commit151bb4a5059e73934f7bc61318efaaffe0c91b81 (patch)
tree1fc2e95d8a6fe37949f6ee0d3893aaaca32474b7
parentAutomatic date update in version.in (diff)
downloadbinutils-gdb-151bb4a5059e73934f7bc61318efaaffe0c91b81.tar.gz
binutils-gdb-151bb4a5059e73934f7bc61318efaaffe0c91b81.tar.bz2
binutils-gdb-151bb4a5059e73934f7bc61318efaaffe0c91b81.tar.xz
Avoid find_thread_ptid with null_ptid
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: 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.
-rw-r--r--gdb/ChangeLog13
-rw-r--r--gdb/cli/cli-interp.c4
-rw-r--r--gdb/inferior.c11
-rw-r--r--gdb/python/py-inferior.c4
-rw-r--r--gdb/tui/tui-interp.c4
5 files changed, 25 insertions, 11 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d562a4b..a6738bd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
12018-11-22 Pedro Alves <palves@redhat.com>
2
3 * cli/cli-interp.c (cli_on_user_selected_context_changed): Use
4 inferior_thread instead of find_thread_ptid, and only when
5 inferior_ptid is not null_ptid.
6 * inferior.c (add_inferior): Don't include target_pid_to_str
7 output when the inferior is not started.
8 * python/py-inferior.c (python_on_normal_stop): Don't use
9 find_thread_ptid.
10 (tui_on_user_selected_context_changed): Use inferior_thread
11 instead of find_thread_ptid, and only when inferior_ptid is not
12 null_ptid.
13
12018-11-21 Benno Fünfstück <benno.fuenfstueck@gmail.com> 142018-11-21 Benno Fünfstück <benno.fuenfstueck@gmail.com>
2 15
3 PR python/23714 16 PR python/23714
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 75d8093..b527fc7 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -257,13 +257,11 @@ cli_on_command_error (void)
257static void 257static void
258cli_on_user_selected_context_changed (user_selected_what selection) 258cli_on_user_selected_context_changed (user_selected_what selection)
259{ 259{
260 struct thread_info *tp;
261
262 /* This event is suppressed. */ 260 /* This event is suppressed. */
263 if (cli_suppress_notification.user_selected_context) 261 if (cli_suppress_notification.user_selected_context)
264 return; 262 return;
265 263
266 tp = find_thread_ptid (inferior_ptid); 264 thread_info *tp = inferior_ptid != null_ptid ? inferior_thread () : NULL;
267 265
268 SWITCH_THRU_ALL_UIS () 266 SWITCH_THRU_ALL_UIS ()
269 { 267 {
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 17d28c4..394386a 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -122,9 +122,14 @@ add_inferior (int pid)
122 struct inferior *inf = add_inferior_silent (pid); 122 struct inferior *inf = add_inferior_silent (pid);
123 123
124 if (print_inferior_events) 124 if (print_inferior_events)
125 printf_unfiltered (_("[New inferior %d (%s)]\n"), 125 {
126 inf->num, 126 if (pid != 0)
127 target_pid_to_str (ptid_t (pid))); 127 printf_unfiltered (_("[New inferior %d (%s)]\n"),
128 inf->num,
129 target_pid_to_str (ptid_t (pid)));
130 else
131 printf_unfiltered (_("[New inferior %d]\n"), inf->num);
132 }
128 133
129 return inf; 134 return inf;
130} 135}
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index e987cfe..7b378ca 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)
86 if (!gdb_python_initialized) 86 if (!gdb_python_initialized)
87 return; 87 return;
88 88
89 if (!find_thread_ptid (inferior_ptid)) 89 if (inferior_ptid == null_ptid)
90 return; 90 return;
91 91
92 stop_signal = inferior_thread ()->suspend.stop_signal; 92 stop_signal = inferior_thread ()->suspend.stop_signal;
93 93
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index acc8f03..a4f3925 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -210,13 +210,11 @@ tui_on_command_error (void)
210static void 210static void
211tui_on_user_selected_context_changed (user_selected_what selection) 211tui_on_user_selected_context_changed (user_selected_what selection)
212{ 212{
213 struct thread_info *tp;
214
215 /* This event is suppressed. */ 213 /* This event is suppressed. */
216 if (cli_suppress_notification.user_selected_context) 214 if (cli_suppress_notification.user_selected_context)
217 return; 215 return;
218 216
219 tp = find_thread_ptid (inferior_ptid); 217 thread_info *tp = inferior_ptid != null_ptid ? inferior_thread () : NULL;
220 218
221 SWITCH_THRU_ALL_UIS () 219 SWITCH_THRU_ALL_UIS ()
222 { 220 {