binutils-gdb/gdb/cli
Pedro Alves 151bb4a505 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.
2018-11-22 16:09:12 +00:00
..
cli-cmds.c Unify shell-finding logic 2018-10-27 11:58:40 -06:00
cli-cmds.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-decode.c gdb: Change how frames are selected for 'frame' and 'info frame'. 2018-09-28 11:59:34 +01:00
cli-decode.h Use counted_command_line everywhere 2018-05-04 15:58:06 -06:00
cli-dump.c Fix PR cli/23785: Check if file exists when invoking "restore FILE binary" 2018-10-18 17:39:09 -04:00
cli-interp.c Avoid find_thread_ptid with null_ptid 2018-11-22 16:09:12 +00:00
cli-interp.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-logging.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-script.c python: Make gdb.execute("show commands") work (PR 23669) 2018-09-17 08:26:24 -04:00
cli-script.h Let gdb.execute handle multi-line commands 2018-05-04 15:58:09 -06:00
cli-setshow.c Convert observers to C++ 2018-03-19 09:37:49 -06:00
cli-setshow.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
cli-utils.c New cli-utils.h/.c function extract_info_print_args 2018-10-27 13:45:57 +02:00
cli-utils.h New cli-utils.h/.c function extract_info_print_args 2018-10-27 13:45:57 +02:00