Commit Graph

129 Commits

Author SHA1 Message Date
Pedro Alves 05779d57f9 Make {get,set}_inferior_io_terminal inferior methods
This converts the get_inferior_io_terminal and
set_inferior_io_terminal free functions to inferior methods.

Since the related commands are called "tty", "{set,show}
inferior-tty", and MI's "-inferior-tty-{set,show}", to make the
connection between the commands and the code more obvious, the methods
are named set_tty/tty instead of set_io_terminal/io_terminal.

gdb/ChangeLog:

	* fork-child.c (prefork_hook): Adjust.
	* infcmd.c (set_inferior_io_terminal, get_inferior_io_terminal):
	Delete.
	(set_inferior_tty_command, show_inferior_tty_command): Adjust.
	* inferior.c (inferior::set_tty, inferior::tty): New methods.
	* inferior.h (set_inferior_io_terminal, get_inferior_io_terminal):
	Remove declarations.
	(struct inferior) <set_tty, tty>: New methods.
	(struct inferior) <terminal>: Rename to ...
	(struct inferior) <m_terminal>: ... this and make private.
	* main.c (captured_main_1): Adjust.
	* mi/mi-cmd-env.c (mi_cmd_inferior_tty_set): Adjust.
	(mi_cmd_inferior_tty_show): Adjust.
	* nto-procfs.c (nto_procfs_target::create_inferior): Adjust.
	* windows-nat.c (windows_nat_target::create_inferior): Adjust.
2020-06-27 14:56:05 +01:00
Simon Marchi 277474eea0 gdb: make inferior::terminal a unique ptr
This changes the inferior::terminal field to be a unique pointer, so its
deallocation is automatically managed.

gdb/ChangeLog:

	* inferior.h (struct inferior) <terminal>: Change type to
	gdb::unique_xmalloc_ptr<char>.
	* inferior.c (inferior::~inferior): Don't free inf->terminal.
	* infcmd.c (set_inferior_io_terminal): Don't free terminal
	field, adjust to unique pointer.
	(get_inferior_io_terminal): Adjust to unique pointer.

Change-Id: Iedb6459b4f9eeae812b0cb9d514b5707d5107cdb
2020-06-25 14:44:35 -04:00
Tom Tromey 740480b88a Remove iterate_over_inferiors
The last caller of iterate_over_inferiors is darwin-nat.c.  This patch
removes the calls from this file, and then remove
iterate_over_inferiors.

In general I think "external iteration" is to be preferred in gdb, the
main benefit being that the code is easier to read.

I rebuilt this on Darwin.  I seem to only have access to Darwin
systems where gdb does not yet work :-(, so I can't run the test
suite.

gdb/ChangeLog
2020-04-23  Tom Tromey  <tom@tromey.com>

	* inferior.h (iterate_over_inferiors): Don't declare.
	* inferior.c (iterate_over_inferiors): Remove.
	* darwin-nat.c (find_inferior_task_it, find_inferior_pid_it):
	Remove.
	(darwin_find_inferior_by_task, darwin_find_inferior_by_pid): Don't
	use iterate_over_inferiors.
	(darwin_resume_inferior_it)
	(struct resume_inferior_threads_param)
	(darwin_resume_inferior_threads_it): Remove.
	(darwin_nat_target::resume): Don't use iterate_over_inferiors.

Change-Id: Ib2fdf2c98e40f13156ff869ed3173d5f1fdae7ea
2020-04-23 06:26:31 -06:00
Pedro Alves 381ce63f2f Refactor delete_program_space as a destructor
Currently, while the program_space's ctor adds the new pspace to the
pspaces list, the destructor doesn't remove the pspace from the pspace
list.  Instead, you're supposed to use delete_program_space, to both
remove the pspace from the list, and deleting the pspace.

This patch eliminates delete_program_space, and makes the pspace dtor
remove the deleted pspace from the pspace list itself, i.e., makes the
dtor do the mirror opposite of the ctor.

I found this helps with a following patch that will allocate a mock
program_space on the stack.  It's easier to just let the regular dtor
remove the mock pspace from the pspace list than arrange to call
delete_program_space instead of the pspace dtor in that situation.

While at it, move the ctor/dtor intro comments to the header file, and
make the ctor explicit.

gdb/ChangeLog:
2020-04-16  Pedro Alves  <palves@redhat.com>

	* inferior.c (delete_inferior): Use delete operator directly
	instead of delete_program_space.
	* progspace.c (add_program_space): New, factored out from
	program_space::program_space.
	(remove_program_space): New, factored out from
	delete_program_space.
	(program_space::program_space): Remove intro comment.  Rewrite.
	(program_space::~program_space): Remove intro comment.  Call
	remove_program_space.
	(delete_program_space): Delete.
	* progspace.h (program_space::program_space): Make explicit.  Move
	intro comment here, adjusted.
	(program_space::~program_space): Move intro comment here,
	adjusted.
	(delete_program_space): Remove.
2020-04-16 14:50:07 +01:00
Pedro Alves 4ec89149dd Remove last traces of discard_all_inferiors
The multi-target patch should have removed all traces of
discard_all_inferiors, but somehow one use stayed behind along with
the definition of the function.

discard_all_inferiors is bad now because it blindly exits inferiors of
all target connections.  It's best to remove it.

gdb/ChangeLog:
2020-01-12  Pedro Alves  <palves@redhat.com>

	* bsd-kvm.c (bsd_kvm_target::close): Call exit_inferior_silent
	directly for the current inferior instead of
	discard_all_inferiors.
	(discard_all_inferiors): Delete.
2020-01-12 00:40:02 +00:00
Tankut Baris Aktemur d9ebdab754 Switch the inferior before outputting its id in "info inferiors"
GDB uses the 'current_top_target' when displaying the description of
an inferior.  This leads to same target being used for each inferior
and, in turn, yields incorrect output when the inferior has a target
that is supposed to give a specialized output.  For instance, the
remote target outputs "Remote target" instead of "process XYZ" as the
description if the multi-process feature is not supported or turned
off.

E.g.: Suppose we have a native and a remote target, and the native is
the current inferior.  The remote target does not support multi-process.
For "info inferiors", we would expect to see:

~~~
(gdb) i inferiors
  Num  Description       Connection       Executable
* 1    process 29060     1 (native)       /a/path
  2    Remote target     2 (remote ...)
~~~

but instead we get

~~~
(gdb) i inferiors
  Num  Description       Connection       Executable
* 1    process 29060     1 (native)       /a/path
  2    process 42000     2 (remote ...)
~~~

Similarly, if the current inferior is the remote one, we would expect
to see

~~~
(gdb) i inferiors
  Num  Description       Connection       Executable
  1    process 29060     1 (native)       /a/path
* 2    Remote target     2 (remote ...)
~~~

but we get

~~~
(gdb) i inferiors
  Num  Description       Connection       Executable
* 1    Remote target     1 (native)       /a/path
  2    Remote target     2 (remote ...)
~~~

With this patch, we switch to the inferior when outputting its
description, so that the current_top_target will be aligned to the
inferior we are displaying.

For testing, this patch expands the "info inferiors" test for the
multi-target feature.  The test was checking for the output of the
info commands after setup, only when the current inferior is the last
added inferior.

This patch does the following to the testcase:

1. The "info inferiors" and "info connections" test is extracted out
   from the "setup" procedure to a separate procedure.

2. The test is enriched to check the output after switching to each
   inferior, not just the last one.

3. The test is performed twice; one for when the multi-process feature
   is turned on, one for off.

gdb/ChangeLog:
2020-01-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* inferior.c (print_inferior): Switch inferior before printing it.

gdb/testsuite/ChangeLog:
2020-01-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.multi/multi-target.exp (setup): Factor out "info
	connections" and "info inferiors" tests to ...
	(test_info_inferiors): ... this new procedure.
	(top level): Run new "info-inferiors" tests.
2020-01-10 20:06:17 +00:00
Pedro Alves 121b3efd49 Add "info connections" command, "info inferiors" connection number/string
This commit extends the CLI a bit for multi-target, in three ways.

#1 - New "info connections" command.

This is a new command that lists the open connections (process_stratum
targets).  For example, if you're debugging two remote connections, a
couple local/native processes, and a core dump, all at the same time,
you might see something like this:

 (gdb) info connections
   Num  What                     Description
   1    remote 192.168.0.1:9999  Remote serial target in gdb-specific protocol
   2    remote 192.168.0.2:9998  Remote serial target in gdb-specific protocol
 * 3    native                   Native process
   4    core                     Local core dump file

#2 - New "info inferiors" "Connection" column

You'll also see a new matching "Connection" column in "info
inferiors", showing you which connection an inferior is bound to:

 (gdb) info inferiors
   Num  Description       Connection                   Executable
   1    process 18526     1 (remote 192.168.0.1:9999)  target:/tmp/a.out
   2    process 18531     2 (remote 192.168.0.2:9998)  target:/tmp/a.out
   3    process 19115     3 (native)                   /tmp/prog1
   4    process 6286      4 (core)                     myprogram
 * 5    process 19122     3 (native)                   /bin/hello

#3 - Makes "add-inferior" show the inferior's target connection

"add-inferior" now shows you the connection you've just bound the
inferior to, which is the current process_stratum target:

 (gdb) add-inferior
 [New inferior 2]
 Added inferior 2 on connection 1 (extended-remote localhost:2346)

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_SFILES): Add target-connection.c.
	* inferior.c (uiout_field_connection): New function.
	(print_inferior): Add new "connection-id" column.
	(add_inferior_command): Show connection number/string of added
	inferior.
	* process-stratum-target.h
	(process_stratum_target::connection_string): New virtual method.
	(process_stratum_target::connection_number): New field.
	* remote.c (remote_target::connection_string): New override.
	* target-connection.c: New file.
	* target-connection.h: New file.
	* target.c (decref_target): Remove process_stratum targets from
	the connection list.
	(target_stack::push): Add process_stratum targets to the
	connection list.

gdb/testsuite/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

	* gdb.base/kill-detach-inferiors-cmd.exp: Adjust expected output
	of "add-inferior".
	* gdb.base/quit-live.exp: Likewise.
	* gdb.base/remote-exec-file.exp: Likewise.
	* gdb.guile/scm-progspace.exp: Likewise.
	* gdb.linespec/linespec.exp: Likewise.
	* gdb.mi/new-ui-mi-sync.exp: Likewise.
	* gdb.mi/user-selected-context-sync.exp: Likewise.
	* gdb.multi/multi-target.exp (setup): Add "info connection" and
	"info inferiors" tests.
	* gdb.multi/remove-inferiors.exp: Adjust expected output of
	"add-inferior".
	* gdb.multi/watchpoint-multi.exp: Likewise.
	* gdb.python/py-inferior.exp: Likewise.
	* gdb.server/extended-remote-restart.exp: Likewise.
	* gdb.threads/fork-plus-threads.exp: Adjust expected output of
	"info inferiors".
	* gdb.threads/forking-threads-plus-breakpoint.exp: Likewise.
	* gdb.trace/report.exp: Likewise.
2020-01-10 20:06:14 +00:00
Pedro Alves 5b6d1e4fa4 Multi-target support
This commit adds multi-target support to GDB.  What this means is that
with this commit, GDB can now be connected to different targets at the
same time.  E.g., you can debug a live native process and a core dump
at the same time, connect to multiple gdbservers, etc.

Actually, the word "target" is overloaded in gdb.  We already have a
target stack, with pushes several target_ops instances on top of one
another.  We also have "info target" already, which means something
completely different to what this patch does.

So from here on, I'll be using the "target connections" term, to mean
an open process_stratum target, pushed on a target stack.  This patch
makes gdb have multiple target stacks, and multiple process_stratum
targets open simultaneously.  The user-visible changes / commands will
also use this terminology, but of course it's all open to debate.

User-interface-wise, not that much changes.  The main difference is
that each inferior may have its own target connection.

A target connection (e.g., a target extended-remote connection) may
support debugging multiple processes, just as before.

Say you're debugging against gdbserver in extended-remote mode, and
you do "add-inferior" to prepare to spawn a new process, like:

 (gdb) target extended-remote :9999
 ...
 (gdb) start
 ...
 (gdb) add-inferior
 Added inferior 2
 (gdb) inferior 2
 [Switching to inferior 2 [<null>] (<noexec>)]
 (gdb) file a.out
 ...
 (gdb) start
 ...

At this point, you have two inferiors connected to the same gdbserver.

With this commit, GDB will maintain a target stack per inferior,
instead of a global target stack.

To preserve the behavior above, by default, "add-inferior" makes the
new inferior inherit a copy of the target stack of the current
inferior.  Same across a fork - the child inherits a copy of the
target stack of the parent.  While the target stacks are copied, the
targets themselves are not.  Instead, target_ops is made a
refcounted_object, which means that target_ops instances are
refcounted, which each inferior counting for a reference.

What if you want to create an inferior and connect it to some _other_
target?  For that, this commit introduces a new "add-inferior
-no-connection" option that makes the new inferior not share the
current inferior's target.  So you could do:

 (gdb) target extended-remote :9999
 Remote debugging using :9999
 ...
 (gdb) add-inferior -no-connection
 [New inferior 2]
 Added inferior 2
 (gdb) inferior 2
 [Switching to inferior 2 [<null>] (<noexec>)]
 (gdb) info inferiors
   Num  Description       Executable
   1    process 18401     target:/home/pedro/tmp/main
 * 2    <null>
 (gdb) tar extended-remote :10000
 Remote debugging using :10000
 ...
 (gdb) info inferiors
   Num  Description       Executable
   1    process 18401     target:/home/pedro/tmp/main
 * 2    process 18450     target:/home/pedro/tmp/main
 (gdb)

A following patch will extended "info inferiors" to include a column
indicating which connection an inferior is bound to, along with a
couple other UI tweaks.

Other than that, debugging is the same as before.  Users interact with
inferiors and threads as before.  The only difference is that
inferiors may be bound to processes running in different machines.

That's pretty much all there is to it in terms of noticeable UI
changes.

On to implementation.

Since we can be connected to different systems at the same time, a
ptid_t is no longer a unique identifier.  Instead a thread can be
identified by a pair of ptid_t and 'process_stratum_target *', the
later being the instance of the process_stratum target that owns the
process/thread.  Note that process_stratum_target inherits from
target_ops, and all process_stratum targets inherit from
process_stratum_target.  In earlier patches, many places in gdb were
converted to refer to threads by thread_info pointer instead of
ptid_t, but there are still places in gdb where we start with a
pid/tid and need to find the corresponding inferior or thread_info
objects.  So you'll see in the patch many places adding a
process_stratum_target parameter to functions that used to take only a
ptid_t.

Since each inferior has its own target stack now, we can always find
the process_stratum target for an inferior.  That is done via a
inf->process_target() convenience method.

Since each inferior has its own target stack, we need to handle the
"beneath" calls when servicing target calls.  The solution I settled
with is just to make sure to switch the current inferior to the
inferior you want before making a target call.  Not relying on global
context is just not feasible in current GDB.  Fortunately, there
aren't that many places that need to do that, because generally most
code that calls target methods already has the current context
pointing to the right inferior/thread.  Note, to emphasize -- there's
no method to "switch to this target stack".  Instead, you switch the
current inferior, and that implicitly switches the target stack.

In some spots, we need to iterate over all inferiors so that we reach
all target stacks.

Native targets are still singletons.  There's always only a single
instance of such targets.

Remote targets however, we'll have one instance per remote connection.

The exec target is still a singleton.  There's only one instance.  I
did not see the point of instanciating more than one exec_target
object.

After vfork, we need to make sure to push the exec target on the new
inferior.  See exec_on_vfork.

For type safety, functions that need a {target, ptid} pair to identify
a thread, take a process_stratum_target pointer for target parameter
instead of target_ops *.  Some shared code in gdb/nat/ also need to
gain a target pointer parameter.  This poses an issue, since gdbserver
doesn't have process_stratum_target, only target_ops.  To fix this,
this commit renames gdbserver's target_ops to process_stratum_target.
I think this makes sense.  There's no concept of target stack in
gdbserver, and gdbserver's target_ops really implements a
process_stratum-like target.

The thread and inferior iterator functions also gain
process_stratum_target parameters.  These are used to be able to
iterate over threads and inferiors of a given target.  Following usual
conventions, if the target pointer is null, then we iterate over
threads and inferiors of all targets.

I tried converting "add-inferior" to the gdb::option framework, as a
preparatory patch, but that stumbled on the fact that gdb::option does
not support file options yet, for "add-inferior -exec".  I have a WIP
patchset that adds that, but it's not a trivial patch, mainly due to
need to integrate readline's filename completion, so I deferred that
to some other time.

In infrun.c/infcmd.c, the main change is that we need to poll events
out of all targets.  See do_target_wait.  Right after collecting an
event, we switch the current inferior to an inferior bound to the
target that reported the event, so that target methods can be used
while handling the event.  This makes most of the code transparent to
multi-targets.  See fetch_inferior_event.

infrun.c:stop_all_threads is interesting -- in this function we need
to stop all threads of all targets.  What the function does is send an
asynchronous stop request to all threads, and then synchronously waits
for events, with target_wait, rinse repeat, until all it finds are
stopped threads.  Now that we have multiple targets, it's not
efficient to synchronously block in target_wait waiting for events out
of one target.  Instead, we implement a mini event loop, with
interruptible_select, select'ing on one file descriptor per target.
For this to work, we need to be able to ask the target for a waitable
file descriptor.  Such file descriptors already exist, they are the
descriptors registered in the main event loop with add_file_handler,
inside the target_async implementations.  This commit adds a new
target_async_wait_fd target method that just returns the file
descriptor in question.  See wait_one / stop_all_threads in infrun.c.

The 'threads_executing' global is made a per-target variable.  Since
it is only relevant to process_stratum_target targets, this is where
it is put, instead of in target_ops.

You'll notice that remote.c includes some FIXME notes.  These refer to
the fact that the global arrays that hold data for the remote packets
supported are still globals.  For example, if we connect to two
different servers/stubs, then each might support different remote
protocol features.  They might even be different architectures, like
e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a
host/controller scenario as a single program.  That isn't going to
work correctly today, because of said globals.  I'm leaving fixing
that for another pass, since it does not appear to be trivial, and I'd
rather land the base work first.  It's already useful to be able to
debug multiple instances of the same server (e.g., a distributed
cluster, where you have full control over the servers installed), so I
think as is it's already reasonable incremental progress.

Current limitations:

 - You can only resume more that one target at the same time if all
   targets support asynchronous debugging, and support non-stop mode.
   It should be possible to support mixed all-stop + non-stop
   backends, but that is left for another time.  This means that
   currently in order to do multi-target with gdbserver you need to
   issue "maint set target-non-stop on".  I would like to make that
   mode be the default, but we're not there yet.  Note that I'm
   talking about how the target backend works, only.  User-visible
   all-stop mode works just fine.

 - As explained above, connecting to different remote servers at the
   same time is likely to produce bad results if they don't support the
   exact set of RSP features.

FreeBSD updates courtesy of John Baldwin.

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>
	    John Baldwin  <jhb@FreeBSD.org>

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::thread_architecture): Adjust.
	* ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call.
	(task_command_1): Likewise.
	* aix-thread.c (sync_threadlists, aix_thread_target::resume)
	(aix_thread_target::wait, aix_thread_target::fetch_registers)
	(aix_thread_target::store_registers)
	(aix_thread_target::thread_alive): Adjust.
	* amd64-fbsd-tdep.c: Include "inferior.h".
	(amd64fbsd_get_thread_local_address): Pass down target.
	* amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle
	thread's gdbarch instead of target_gdbarch.
	* break-catch-sig.c (signal_catchpoint_print_it): Adjust call to
	get_last_target_status.
	* break-catch-syscall.c (print_it_catch_syscall): Likewise.
	* breakpoint.c (breakpoints_should_be_inserted_now): Consider all
	inferiors.
	(update_inserted_breakpoint_locations): Skip if inferiors with no
	execution.
	(update_global_location_list): When handling moribund locations,
	find representative inferior for location's pspace, and use thread
	count of its process_stratum target.
	* bsd-kvm.c (bsd_kvm_target_open): Pass target down.
	* bsd-uthread.c (bsd_uthread_target::wait): Use
	as_process_stratum_target and adjust thread_change_ptid and
	add_thread calls.
	(bsd_uthread_target::update_thread_list): Use
	as_process_stratum_target and adjust find_thread_ptid,
	thread_change_ptid and add_thread calls.
	* btrace.c (maint_btrace_packet_history_cmd): Adjust
	find_thread_ptid call.
	* corelow.c (add_to_thread_list): Adjust add_thread call.
	(core_target_open): Adjust add_thread_silent and thread_count
	calls.
	(core_target::pid_to_str): Adjust find_inferior_ptid call.
	* ctf.c (ctf_target_open): Adjust add_thread_silent call.
	* event-top.c (async_disconnect): Pop targets from all inferiors.
	* exec.c (add_target_sections): Push exec target on all inferiors
	sharing the program space.
	(remove_target_sections): Remove the exec target from all
	inferiors sharing the program space.
	(exec_on_vfork): New.
	* exec.h (exec_on_vfork): Declare.
	* fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter.
	Pass it down.
	(fbsd_nat_target::update_thread_list): Adjust.
	(fbsd_nat_target::resume): Adjust.
	(fbsd_handle_debug_trap): Add fbsd_nat_target parameter.  Pass it
	down.
	(fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust.
	* fbsd-tdep.c (fbsd_corefile_thread): Adjust
	get_thread_arch_regcache call.
	* fork-child.c (gdb_startup_inferior): Pass target down to
	startup_inferior and set_executing.
	* gdbthread.h (struct process_stratum_target): Forward declare.
	(add_thread, add_thread_silent, add_thread_with_info)
	(in_thread_list): Add process_stratum_target parameter.
	(find_thread_ptid(inferior*, ptid_t)): New overload.
	(find_thread_ptid, thread_change_ptid): Add process_stratum_target
	parameter.
	(all_threads()): Delete overload.
	(all_threads, all_non_exited_threads): Add process_stratum_target
	parameter.
	(all_threads_safe): Use brace initialization.
	(thread_count): Add process_stratum_target parameter.
	(set_resumed, set_running, set_stop_requested, set_executing)
	(threads_are_executing, finish_thread_state): Add
	process_stratum_target parameter.
	(switch_to_thread): Use is_current_thread.
	* i386-fbsd-tdep.c: Include "inferior.h".
	(i386fbsd_get_thread_local_address): Pass down target.
	* i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust.
	* inf-child.c (inf_child_target::maybe_unpush_target): Remove
	have_inferiors check.
	* inf-ptrace.c (inf_ptrace_target::create_inferior)
	(inf_ptrace_target::attach): Adjust.
	* infcall.c (run_inferior_call): Adjust.
	* infcmd.c (run_command_1): Pass target to
	scoped_finish_thread_state.
	(proceed_thread_callback): Skip inferiors with no execution.
	(continue_command): Rename 'all_threads' local to avoid hiding
	'all_threads' function.  Adjust get_last_target_status call.
	(prepare_one_step): Adjust set_running call.
	(signal_command): Use user_visible_resume_target.  Compare thread
	pointers instead of inferior_ptid.
	(info_program_command): Adjust to pass down target.
	(attach_command): Mark target's 'thread_executing' flag.
	(stop_current_target_threads_ns): New, factored out from ...
	(interrupt_target_1): ... this.  Switch inferior before making
	target calls.
	* inferior-iter.h
	(struct all_inferiors_iterator, struct all_inferiors_range)
	(struct all_inferiors_safe_range)
	(struct all_non_exited_inferiors_range): Filter on
	process_stratum_target too.  Remove explicit.
	* inferior.c (inferior::inferior): Push dummy target on target
	stack.
	(find_inferior_pid, find_inferior_ptid, number_of_live_inferiors):
	Add process_stratum_target parameter, and pass it down.
	(have_live_inferiors): Adjust.
	(switch_to_inferior_and_push_target): New.
	(add_inferior_command, clone_inferior_command): Handle
	"-no-connection" parameter.  Use
	switch_to_inferior_and_push_target.
	(_initialize_inferior): Mention "-no-connection" option in
	the help of "add-inferior" and "clone-inferior" commands.
	* inferior.h: Include "process-stratum-target.h".
	(interrupt_target_1): Use bool.
	(struct inferior) <push_target, unpush_target, target_is_pushed,
	find_target_beneath, top_target, process_target, target_at,
	m_stack>: New.
	(discard_all_inferiors): Delete.
	(find_inferior_pid, find_inferior_ptid, number_of_live_inferiors)
	(all_inferiors, all_non_exited_inferiors): Add
	process_stratum_target parameter.
	* infrun.c: Include "gdb_select.h" and <unordered_map>.
	(target_last_proc_target): New global.
	(follow_fork_inferior): Push target on new inferior.  Pass target
	to add_thread_silent.  Call exec_on_vfork.  Handle target's
	reference count.
	(follow_fork): Adjust get_last_target_status call.  Also consider
	target.
	(follow_exec): Push target on new inferior.
	(struct execution_control_state) <target>: New field.
	(user_visible_resume_target): New.
	(do_target_resume): Call target_async.
	(resume_1): Set target's threads_executing flag.  Consider resume
	target.
	(commit_resume_all_targets): New.
	(proceed): Also consider resume target.  Skip threads of inferiors
	with no execution.  Commit resumtion in all targets.
	(start_remote): Pass current inferior to wait_for_inferior.
	(infrun_thread_stop_requested): Consider target as well.  Pass
	thread_info pointer to clear_inline_frame_state instead of ptid.
	(infrun_thread_thread_exit): Consider target as well.
	(random_pending_event_thread): New inferior parameter.  Use it.
	(do_target_wait): Rename to ...
	(do_target_wait_1): ... this.  Add inferior parameter, and pass it
	down.
	(threads_are_resumed_pending_p, do_target_wait): New.
	(prepare_for_detach): Adjust calls.
	(wait_for_inferior): New inferior parameter.  Handle it.  Use
	do_target_wait_1 instead of do_target_wait.
	(fetch_inferior_event): Adjust.  Switch to representative
	inferior.  Pass target down.
	(set_last_target_status): Add process_stratum_target parameter.
	Save target in global.
	(get_last_target_status): Add process_stratum_target parameter and
	handle it.
	(nullify_last_target_wait_ptid): Clear 'target_last_proc_target'.
	(context_switch): Check inferior_ptid == null_ptid before calling
	inferior_thread().
	(get_inferior_stop_soon): Pass down target.
	(wait_one): Rename to ...
	(poll_one_curr_target): ... this.
	(struct wait_one_event): New.
	(wait_one): New.
	(stop_all_threads): Adjust.
	(handle_no_resumed, handle_inferior_event): Adjust to consider the
	event's target.
	(switch_back_to_stepped_thread): Also consider target.
	(print_stop_event): Update.
	(normal_stop): Update.  Also consider the resume target.
	* infrun.h (wait_for_inferior): Remove declaration.
	(user_visible_resume_target): New declaration.
	(get_last_target_status, set_last_target_status): New
	process_stratum_target parameter.
	* inline-frame.c (clear_inline_frame_state(ptid_t)): Add
	process_stratum_target parameter, and use it.
	(clear_inline_frame_state (thread_info*)): New.
	* inline-frame.c (clear_inline_frame_state(ptid_t)): Add
	process_stratum_target parameter.
	(clear_inline_frame_state (thread_info*)): Declare.
	* linux-fork.c (delete_checkpoint_command): Pass target down to
	find_thread_ptid.
	(checkpoint_command): Adjust.
	* linux-nat.c (linux_nat_target::follow_fork): Switch to thread
	instead of just tweaking inferior_ptid.
	(linux_nat_switch_fork): Pass target down to thread_change_ptid.
	(exit_lwp): Pass target down to find_thread_ptid.
	(attach_proc_task_lwp_callback): Pass target down to
	add_thread/set_running/set_executing.
	(linux_nat_target::attach): Pass target down to
	thread_change_ptid.
	(get_detach_signal): Pass target down to find_thread_ptid.
	Consider last target status's target.
	(linux_resume_one_lwp_throw, resume_lwp)
	(linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp)
	(stop_wait_callback, save_stop_reason, linux_nat_filter_event)
	(linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down.
	(linux_nat_target::async_wait_fd): New.
	(linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass
	target down.
	* linux-nat.h (linux_nat_target::async_wait_fd): Declare.
	* linux-tdep.c (get_thread_arch_regcache): Pass target down.
	* linux-thread-db.c (struct thread_db_info::process_target): New
	field.
	(add_thread_db_info): Save target.
	(get_thread_db_info): New process_stratum_target parameter.  Also
	match target.
	(delete_thread_db_info): New process_stratum_target parameter.
	Also match target.
	(thread_from_lwp): Adjust to pass down target.
	(thread_db_notice_clone): Pass down target.
	(check_thread_db_callback): Pass down target.
	(try_thread_db_load_1): Always push the thread_db target.
	(try_thread_db_load, record_thread): Pass target down.
	(thread_db_target::detach): Pass target down.  Always unpush the
	thread_db target.
	(thread_db_target::wait, thread_db_target::mourn_inferior): Pass
	target down.  Always unpush the thread_db target.
	(find_new_threads_callback, thread_db_find_new_threads_2)
	(thread_db_target::update_thread_list): Pass target down.
	(thread_db_target::pid_to_str): Pass current inferior down.
	(thread_db_target::get_thread_local_address): Pass target down.
	(thread_db_target::resume, maintenance_check_libthread_db): Pass
	target down.
	* nto-procfs.c (nto_procfs_target::update_thread_list): Adjust.
	* procfs.c (procfs_target::procfs_init_inferior): Declare.
	(proc_set_current_signal, do_attach, procfs_target::wait): Adjust.
	(procfs_init_inferior): Rename to ...
	(procfs_target::procfs_init_inferior): ... this and adjust.
	(procfs_target::create_inferior, procfs_notice_thread)
	(procfs_do_thread_registers): Adjust.
	* ppc-fbsd-tdep.c: Include "inferior.h".
	(ppcfbsd_get_thread_local_address): Pass down target.
	* proc-service.c (ps_xfer_memory): Switch current inferior and
	program space as well.
	(get_ps_regcache): Pass target down.
	* process-stratum-target.c
	(process_stratum_target::thread_address_space)
	(process_stratum_target::thread_architecture): Pass target down.
	* process-stratum-target.h
	(process_stratum_target::threads_executing): New field.
	(as_process_stratum_target): New.
	* ravenscar-thread.c
	(ravenscar_thread_target::update_inferior_ptid): Pass target down.
	(ravenscar_thread_target::wait, ravenscar_add_thread): Pass target
	down.
	* record-btrace.c (record_btrace_target::info_record): Adjust.
	(record_btrace_target::record_method)
	(record_btrace_target::record_is_replaying)
	(record_btrace_target::fetch_registers)
	(get_thread_current_frame_id, record_btrace_target::resume)
	(record_btrace_target::wait, record_btrace_target::stop): Pass
	target down.
	* record-full.c (record_full_wait_1): Switch to event thread.
	Pass target down.
	* regcache.c (regcache::regcache)
	(get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add
	process_stratum_target parameter and handle it.
	(current_thread_target): New global.
	(get_thread_regcache): Add process_stratum_target parameter and
	handle it.  Switch inferior before calling target method.
	(get_thread_regcache): Pass target down.
	(get_thread_regcache_for_ptid): Pass target down.
	(registers_changed_ptid): Add process_stratum_target parameter and
	handle it.
	(registers_changed_thread, registers_changed): Pass target down.
	(test_get_thread_arch_aspace_regcache): New.
	(current_regcache_test): Define a couple local test_target_ops
	instances and use them for testing.
	(readwrite_regcache): Pass process_stratum_target parameter.
	(cooked_read_test, cooked_write_test): Pass mock_target down.
	* regcache.h (get_thread_regcache, get_thread_arch_regcache)
	(get_thread_arch_aspace_regcache): Add process_stratum_target
	parameter.
	(regcache::target): New method.
	(regcache::regcache, regcache::get_thread_arch_aspace_regcache)
	(regcache::registers_changed_ptid): Add process_stratum_target
	parameter.
	(regcache::m_target): New field.
	(registers_changed_ptid): Add process_stratum_target parameter.
	* remote.c (remote_state::supports_vCont_probed): New field.
	(remote_target::async_wait_fd): New method.
	(remote_unpush_and_throw): Add remote_target parameter.
	(get_current_remote_target): Adjust.
	(remote_target::remote_add_inferior): Push target.
	(remote_target::remote_add_thread)
	(remote_target::remote_notice_new_inferior)
	(get_remote_thread_info): Pass target down.
	(remote_target::update_thread_list): Skip threads of inferiors
	bound to other targets.  (remote_target::close): Don't discard
	inferiors.  (remote_target::add_current_inferior_and_thread)
	(remote_target::process_initial_stop_replies)
	(remote_target::start_remote)
	(remote_target::remote_serial_quit_handler): Pass down target.
	(remote_target::remote_unpush_target): New remote_target
	parameter.  Unpush the target from all inferiors.
	(remote_target::remote_unpush_and_throw): New remote_target
	parameter.  Pass it down.
	(remote_target::open_1): Check whether the current inferior has
	execution instead of checking whether any inferior is live.  Pass
	target down.
	(remote_target::remote_detach_1): Pass down target.  Use
	remote_unpush_target.
	(extended_remote_target::attach): Pass down target.
	(remote_target::remote_vcont_probe): Set supports_vCont_probed.
	(remote_target::append_resumption): Pass down target.
	(remote_target::append_pending_thread_resumptions)
	(remote_target::remote_resume_with_hc, remote_target::resume)
	(remote_target::commit_resume): Pass down target.
	(remote_target::remote_stop_ns): Check supports_vCont_probed.
	(remote_target::interrupt_query)
	(remote_target::remove_new_fork_children)
	(remote_target::check_pending_events_prevent_wildcard_vcont)
	(remote_target::remote_parse_stop_reply)
	(remote_target::process_stop_reply): Pass down target.
	(first_remote_resumed_thread): New remote_target parameter.  Pass
	it down.
	(remote_target::wait_as): Pass down target.
	(unpush_and_perror): New remote_target parameter.  Pass it down.
	(remote_target::readchar, remote_target::remote_serial_write)
	(remote_target::getpkt_or_notif_sane_1)
	(remote_target::kill_new_fork_children, remote_target::kill): Pass
	down target.
	(remote_target::mourn_inferior): Pass down target.  Use
	remote_unpush_target.
	(remote_target::core_of_thread)
	(remote_target::remote_btrace_maybe_reopen): Pass down target.
	(remote_target::pid_to_exec_file)
	(remote_target::thread_handle_to_thread_info): Pass down target.
	(remote_target::async_wait_fd): New.
	* riscv-fbsd-tdep.c: Include "inferior.h".
	(riscv_fbsd_get_thread_local_address): Pass down target.
	* sol2-tdep.c (sol2_core_pid_to_str): Pass down target.
	* sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs)
	(ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback):
	Adjust.
	* solib-spu.c (spu_skip_standalone_loader): Pass down target.
	* solib-svr4.c (enable_break): Pass down target.
	* spu-multiarch.c (parse_spufs_run): Pass down target.
	* spu-tdep.c (spu2ppu_sniffer): Pass down target.
	* target-delegates.c: Regenerate.
	* target.c (g_target_stack): Delete.
	(current_top_target): Return the current inferior's top target.
	(target_has_execution_1): Refer to the passed-in inferior's top
	target.
	(target_supports_terminal_ours): Check whether the initial
	inferior was already created.
	(decref_target): New.
	(target_stack::push): Incref/decref the target.
	(push_target, push_target, unpush_target): Adjust.
	(target_stack::unpush): Defref target.
	(target_is_pushed): Return bool.  Adjust to refer to the current
	inferior's target stack.
	(dispose_inferior): Delete, and inline parts ...
	(target_preopen): ... here.  Only dispose of the current inferior.
	(target_detach): Hold strong target reference while detaching.
	Pass target down.
	(target_thread_name): Add assertion.
	(target_resume): Pass down target.
	(target_ops::beneath, find_target_at): Adjust to refer to the
	current inferior's target stack.
	(get_dummy_target): New.
	(target_pass_ctrlc): Pass the Ctrl-C to the first inferior that
	has a thread running.
	(initialize_targets): Rename to ...
	(_initialize_target): ... this.
	* target.h: Include "gdbsupport/refcounted-object.h".
	(struct target_ops): Inherit refcounted_object.
	(target_ops::shortname, target_ops::longname): Make const.
	(target_ops::async_wait_fd): New method.
	(decref_target): Declare.
	(struct target_ops_ref_policy): New.
	(target_ops_ref): New typedef.
	(get_dummy_target): Declare function.
	(target_is_pushed): Return bool.
	* thread-iter.c (all_matching_threads_iterator::m_inf_matches)
	(all_matching_threads_iterator::all_matching_threads_iterator):
	Handle filter target.
	* thread-iter.h (struct all_matching_threads_iterator, struct
	all_matching_threads_range, class all_non_exited_threads_range):
	Filter by target too.  Remove explicit.
	* thread.c (threads_executing): Delete.
	(inferior_thread): Pass down current inferior.
	(clear_thread_inferior_resources): Pass down thread pointer
	instead of ptid_t.
	(add_thread_silent, add_thread_with_info, add_thread): Add
	process_stratum_target parameter.  Use it for thread and inferior
	searches.
	(is_current_thread): New.
	(thread_info::deletable): Use it.
	(find_thread_ptid, thread_count, in_thread_list)
	(thread_change_ptid, set_resumed, set_running): New
	process_stratum_target parameter.  Pass it down.
	(set_executing): New process_stratum_target parameter.  Pass it
	down.  Adjust reference to 'threads_executing'.
	(threads_are_executing): New process_stratum_target parameter.
	Adjust reference to 'threads_executing'.
	(set_stop_requested, finish_thread_state): New
	process_stratum_target parameter.  Pass it down.
	(switch_to_thread): Also match inferior.
	(switch_to_thread): New process_stratum_target parameter.  Pass it
	down.
	(update_threads_executing): Reimplement.
	* top.c (quit_force): Pop targets from all inferior.
	(gdb_init): Don't call initialize_targets.
	* windows-nat.c (windows_nat_target) <get_windows_debug_event>:
	Declare.
	(windows_add_thread, windows_delete_thread): Adjust.
	(get_windows_debug_event): Rename to ...
	(windows_nat_target::get_windows_debug_event): ... this.  Adjust.
	* tracefile-tfile.c (tfile_target_open): Pass down target.
	* gdbsupport/common-gdbthread.h (struct process_stratum_target):
	Forward declare.
	(switch_to_thread): Add process_stratum_target parameter.
	* mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target
	parameter.  Use it.
	(mi_on_resume): Pass target down.
	* nat/fork-inferior.c (startup_inferior): Add
	process_stratum_target parameter.  Pass it down.
	* nat/fork-inferior.h (startup_inferior): Add
	process_stratum_target parameter.
	* python/py-threadevent.c (py_get_event_thread): Pass target down.

gdb/gdbserver/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

	* fork-child.c (post_fork_inferior): Pass target down to
	startup_inferior.
	* inferiors.c (switch_to_thread): Add process_stratum_target
	parameter.
	* lynx-low.c (lynx_target_ops): Now a process_stratum_target.
	* nto-low.c (nto_target_ops): Now a process_stratum_target.
	* linux-low.c (linux_target_ops): Now a process_stratum_target.
	* remote-utils.c (prepare_resume_reply): Pass the target to
	switch_to_thread.
	* target.c (the_target): Now a process_stratum_target.
	(done_accessing_memory): Pass the target to switch_to_thread.
	(set_target_ops): Ajust to use process_stratum_target.
	* target.h (struct target_ops): Rename to ...
	(struct process_stratum_target): ... this.
	(the_target, set_target_ops): Adjust.
	(prepare_to_access_memory): Adjust comment.
	* win32-low.c (child_xfer_memory): Adjust to use
	process_stratum_target.
	(win32_target_ops): Now a process_stratum_target.
2020-01-10 20:06:08 +00:00
Pedro Alves db2d40f7d0 Introduce switch_to_inferior_no_thread
Several places want to switch context to an inferior and its pspace,
while at the same time switch to "no thread selected".  This commit
adds a function that does that, and uses it in a few places.

gdb/ChangeLog:
2020-01-10  Pedro Alves <palves@redhat.com>

	* inferior.c (switch_to_inferior_no_thread): New function,
	factored out from ...
	(inferior_command): ... here.
	* inferior.h (switch_to_inferior_no_thread): Declare.
	* mi/mi-main.c (run_one_inferior): Use
	switch_to_inferior_no_thread.
2020-01-10 20:05:47 +00:00
Pedro Alves 5018ce90c1 Make target_ops::has_execution take an 'inferior *' instead of a ptid_t
With the multi-target work, each inferior will have its own target
stack, so to call a target method, we'll need to make sure that the
inferior in question is the current one, otherwise target->beneath()
calls will find the target beneath in the wrong inferior.

In some places, it's much more convenient to be able to check whether
an inferior has execution without having to switch to it in order to
call target_has_execution on the right inferior/target stack, to avoid
side effects with switching inferior/thread/program space.

The current target_ops::has_execution method takes a ptid_t as
parameter, which, in a multi-target world, isn't sufficient to
identify the target.  This patch prepares to address that, by changing
the parameter to an inferior pointer instead.  From the inferior,
we'll be able to query its target stack to tell which target is
beneath.

Also adds a new inferior::has_execution() method to make callers a bit
more natural to read.

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

	* corelow.c (core_target::has_execution): Change parameter type to
	inferior pointer.
	* inferior.c (number_of_live_inferiors): Use
	inferior::has_execution instead of target_has_execution_1.
	* inferior.h (inferior::has_execution): New.
	* linux-thread-db.c (thread_db_target::update_thread_list): Use
	inferior::has_execution instead of target_has_execution_1.
	* process-stratum-target.c
	(process_stratum_target::has_execution): Change parameter type to
	inferior pointer.  Check the inferior's PID instead of
	inferior_ptid.
	* process-stratum-target.h
	(process_stratum_target::has_execution): Change parameter type to
	inferior pointer.
	* record-full.c (record_full_core_target::has_execution): Change
	parameter type to inferior pointer.
	* target.c (target_has_execution_1): Change parameter type to
	inferior pointer.
	(target_has_execution_current): Adjust.
	* target.h (target_ops::has_execution): Change parameter type to
	inferior pointer.
	(target_has_execution_1): Change parameter type to inferior
	pointer.  Change return type to bool.
	* tracefile.h (tracefile_target::has_execution): Change parameter
	type to inferior pointer.
2020-01-10 20:05:44 +00:00
Pedro Alves 873657b9e8 Preserve selected thread in all-stop w/ background execution
In non-stop mode, if you resume the program in the background (with
"continue&", for example), then gdb makes sure to not switch the
current thread behind your back.  That means that you can be sure that
the commands you type apply to the thread you selected, even if some
other thread that was running in the background hits some event just
while you're typing.

In all-stop mode, however, if you resume the program in the
background, gdb let's the current thread switch behind your back.

This is bogus, of course.  All-stop and non-stop background
resumptions should behave the same.

This patch fixes that, and adds a testcase that exposes the bad
behavior in current master.

The fork-running-state.exp changes are necessary because that
preexisting testcase was expecting the old behavior:

Before:

  continue &
  Continuing.
  (gdb)
  [Attaching after process 8199 fork to child process 8203]
  [New inferior 2 (process 8203)]
  info threads
    Id   Target Id                      Frame
    1.1  process 8199 "fork-running-st" (running)
  * 2.1  process 8203 "fork-running-st" (running)
  (gdb)

After:

  continue &
  Continuing.
  (gdb)
  [Attaching after process 24660 fork to child process 24664]
  [New inferior 2 (process 24664)]
  info threads
    Id   Target Id                       Frame
  * 1.1  process 24660 "fork-running-st" (running)
    2.1  process 24664 "fork-running-st" (running)
  (gdb)

Here we see that before this patch GDB switches current inferior to
the new inferior behind the user's back, as a side effect of handling
the fork.

The delete_exited_threads call in inferior_appeared is there to fix an
issue that Baris found in a previous version of this patch.  The
fetch_inferior_event change increases the refcount of the current
thread, and in case the fetched inferior event denotes a thread exit,
the thread will not be deleted right away.  A non-deleted but exited
thread stays in the inferior's thread list.  This, in turn, causes the
"init_thread_list" call in inferior.c to be skipped.  A consequence is
that the global thread ID counter is not restarted if the current
thread exits, and then the inferior is restarted:

 (gdb) start
 Temporary breakpoint 1 at 0x4004d6: file main.c, line 21.
 Starting program: /tmp/main

 Temporary breakpoint 1, main () at main.c:21
 21        foo ();
 (gdb) info threads -gid
   Id   GId  Target Id            Frame
 * 1    1    process 16106 "main" main () at main.c:21
 (gdb) c
 Continuing.
 [Inferior 1 (process 16106) exited normally]
 (gdb) start
 Temporary breakpoint 2 at 0x4004d6: file main.c, line 21.
 Starting program: /tmp/main

 Temporary breakpoint 2, main () at main.c:21
 21        foo ();
 (gdb) info threads -gid
   Id   GId  Target Id            Frame
 * 1    2    process 16138 "main" main () at main.c:21
       ^^^

Notice that GId == 2 above.  It should have been "1" instead.

The new tids-git-reset.exp testcase exercises the problem above.

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (scoped_restore_current_thread)
	<dont_restore, restore, m_dont_restore>: Declare.
	* thread.c (thread_alive): Add assertion.  Return bool.
	(switch_to_thread_if_alive): New.
	(prune_threads): Switch inferior/thread.
	(print_thread_info_1): Switch thread before calling target methods.
	(scoped_restore_current_thread::restore): New, factored out from
	...
	(scoped_restore_current_thread::~scoped_restore_current_thread):
	... this.
	(scoped_restore_current_thread::scoped_restore_current_thread):
	Add assertion.
	(thread_apply_all_command, thread_select): Use
	switch_to_thread_if_alive.

gdb/testsuite/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

	* gdb.base/fork-running-state.exp (do_test): Adjust expected
	output.
	* gdb.threads/async.c: New.
	* gdb.threads/async.exp: New.
	* gdb.multi/tids-gid-reset.c: New.
	* gdb.multi/tids-gid-reset.exp: New.
2020-01-10 20:05:41 +00:00
Joel Brobecker b811d2c292 Update copyright year range in all GDB files.
gdb/ChangeLog:

        Update copyright year range in all GDB files.
2020-01-01 10:20:53 +04:00
Philippe Waroquiers 908641f530 Fix leaks when pruning inferiors.
Valgrind detects various inferior related leaks, such as:
  ==31877== 5,530 (56 direct, 5,474 indirect) bytes in 1 blocks are definitely lost in loss record 7,131 of 7,355
  ==31877==    at 0x4C2E18C: calloc (vg_replace_malloc.c:760)
  ==31877==    by 0x23E580: xcalloc (alloc.c:100)
  ==31877==    by 0x4794A9: xcnewvec<void*> (poison.h:158)
  ==31877==    by 0x4794A9: registry_alloc_data(registry_data_registry*, registry_fields*) (registry.c:51)
  ==31877==    by 0x3A537C: inferior_alloc_data (inferior.c:43)
  ==31877==    by 0x3A537C: inferior::inferior(int) (inferior.c:92)
  ==31877==    by 0x3A5426: add_inferior_silent(int) (inferior.c:98)
  ==31877==    by 0x3A5530: add_inferior(int) (inferior.c:122)
  ...

Origin of the leaks is in prune_inferiors: prune_inferiors is first removing
the inferior to prune from the inferior list, then calls delete_inferior.
But delete_inferior will only really destroy the inferior when it finds
it into the inferior list.
As delete_inferior is removing the inferior to delete from the inferior list,
ensure prune_inferiors only calls delete_inferior, without touching the
inferior list.

gdb/ChangeLog
2019-12-05  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
	* inferior.c (prune_inferiors):  Only call delete_inferior.
	Do not modify the inferior list.
2019-12-05 23:19:22 +01:00
Simon Marchi b926335f33 Remove unused overload of exit_inferior_silent
This function is not used in the code base.

gdb/ChangeLog:

	* inferior.c (exit_inferior_silent): Remove.

Change-Id: Ib2b7662744da079185ceac2a165b47590bd3113c
2019-11-26 14:29:20 -05:00
Christian Biesinger 491144b5e2 Change boolean options to bool instead of int
This is for add_setshow_boolean_cmd as well as the gdb::option interface.

gdb/ChangeLog:

2019-09-17  Christian Biesinger  <cbiesinger@google.com>

	* ada-lang.c (ada_ignore_descriptive_types_p): Change to bool.
	(print_signatures): Likewise.
	(trust_pad_over_xvs): Likewise.
	* arch/aarch64-insn.c (aarch64_debug): Likewise.
	* arch/aarch64-insn.h (aarch64_debug): Likewise.
	* arm-linux-nat.c (arm_apcs_32): Likewise.
	* arm-linux-tdep.c (arm_apcs_32): Likewise.
	* arm-nbsd-nat.c (arm_apcs_32): Likewise.
	* arm-tdep.c (arm_debug): Likewise.
	(arm_apcs_32): Likewise.
	* auto-load.c (debug_auto_load): Likewise.
	(auto_load_gdb_scripts): Likewise.
	(global_auto_load): Likewise.
	(auto_load_local_gdbinit): Likewise.
	(auto_load_local_gdbinit_loaded): Likewise.
	* auto-load.h (global_auto_load): Likewise.
	(auto_load_local_gdbinit): Likewise.
	(auto_load_local_gdbinit_loaded): Likewise.
	* breakpoint.c (disconnected_dprintf): Likewise.
	(breakpoint_proceeded): Likewise.
	(automatic_hardware_breakpoints): Likewise.
	(always_inserted_mode): Likewise.
	(target_exact_watchpoints): Likewise.
	(_initialize_breakpoint): Update.
	* breakpoint.h (target_exact_watchpoints): Change to bool.
	* btrace.c (maint_btrace_pt_skip_pad): Likewise.
	* cli/cli-cmds.c (trace_commands): Likewise.
	* cli/cli-cmds.h (trace_commands): Likewise.
	* cli/cli-decode.c (add_setshow_boolean_cmd): Change int* argument
	to bool*.
	* cli/cli-logging.c (logging_overwrite): Change to bool.
	(logging_redirect): Likewise.
	(debug_redirect): Likewise.
	* cli/cli-option.h (option_def) <boolean>: Change return type to bool*.
	(struct boolean_option_def) <get_var_address_cb_>: Change return type
	to bool.
	<boolean_option_def>: Update.
	(struct flag_option_def): Change default type of Context to bool
	from int.
	<flag_option_def>: Change return type of var_address_cb_ to bool*.
	* cli/cli-setshow.c (do_set_command): Cast to bool* instead of int*.
	(get_setshow_command_value_string): Likewise.
	* cli/cli-style.c (cli_styling): Change to bool.
	(source_styling): Likewise.
	* cli/cli-style.h (source_styling): Likewise.
	(cli_styling): Likewise.
	* cli/cli-utils.h (struct qcs_flags) <quiet, cont, silent>: Change
	to bool.
	* command.h (var_types): Update comment.
	(add_setshow_boolean_cmd): Change int* var argument to bool*.
	* compile/compile-cplus-types.c (debug_compile_cplus_types): Change to
	bool.
	(debug_compile_cplus_scopes): Likewise.
	* compile/compile-internal.h (compile_debug): Likewise.
	* compile/compile.c (compile_debug): Likewise.
	(struct compile_options) <raw>: Likewise.
	* cp-support.c (catch_demangler_crashes): Likewise.
	* cris-tdep.c (usr_cmd_cris_version_valid): Likewise.
	(usr_cmd_cris_dwarf2_cfi): Likewise.
	* csky-tdep.c (csky_debug): Likewise.
	* darwin-nat.c (enable_mach_exceptions): Likewise.
	* dcache.c (dcache_enabled_p): Likewise.
	* defs.h (info_verbose): Likewise.
	* demangle.c (demangle): Likewise.
	(asm_demangle): Likewise.
	* dwarf-index-cache.c (debug_index_cache): Likewise.
	* dwarf2-frame.c (dwarf2_frame_unwinders_enabled_p): Likewise.
	* dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Likewise.
	* dwarf2read.c (check_physname): Likewise.
	(use_deprecated_index_sections): Likewise.
	(dwarf_always_disassemble): Likewise.
	* eval.c (overload_resolution): Likewise.
	* event-top.c (set_editing_cmd_var): Likewise.
	(exec_done_display_p): Likewise.
	* event-top.h (set_editing_cmd_var): Likewise.
	(exec_done_display_p): Likewise.
	* exec.c (write_files): Likewise.
	* fbsd-nat.c (debug_fbsd_lwp): Likewise
	(debug_fbsd_nat): Likewise.
	* frame.h (struct frame_print_options) <print_raw_frame_arguments>:
	Likewise.
	(struct set_backtrace_options) <backtrace_past_main>: Likewise.
	<backtrace_past_entry> Likewise.
	* gdb-demangle.h (demangle): Likewise.
	(asm_demangle): Likewise.
	* gdb_bfd.c (bfd_sharing): Likewise.
	* gdbcore.h (write_files): Likewise.
	* gdbsupport/common-debug.c (show_debug_regs): Likewise.
	* gdbsupport/common-debug.h (show_debug_regs): Likewise.
	* gdbthread.h (print_thread_events): Likewise.
	* gdbtypes.c (opaque_type_resolution): Likewise.
	(strict_type_checking): Likewise.
	* gnu-nat.c (gnu_debug_flag): Likewise.
	* guile/scm-auto-load.c (auto_load_guile_scripts): Likewise.
	* guile/scm-param.c (pascm_variable): Add boolval.
	(add_setshow_generic): Update.
	(pascm_param_value): Update.
	(pascm_set_param_value_x): Update.
	* hppa-tdep.c (hppa_debug): Change to bool..
	* infcall.c (may_call_functions_p): Likewise.
	(coerce_float_to_double_p): Likewise.
	(unwind_on_signal_p): Likewise.
	(unwind_on_terminating_exception_p): Likewise.
	* infcmd.c (startup_with_shell): Likewise.
	* inferior.c (print_inferior_events): Likewise.
	* inferior.h (startup_with_shell): Likewise.
	(print_inferior_events): Likewise.
	* infrun.c (step_stop_if_no_debug): Likewise.
	(detach_fork): Likewise.
	(debug_displaced): Likewise.
	(disable_randomization): Likewise.
	(non_stop): Likewise.
	(non_stop_1): Likewise.
	(observer_mode): Likewise.
	(observer_mode_1): Likewise.
	(set_observer_mode): Update.
	(sched_multi): Change to bool.
	* infrun.h (debug_displaced): Likewise.
	(sched_multi): Likewise.
	(step_stop_if_no_debug): Likewise.
	(non_stop): Likewise.
	(disable_randomization): Likewise.
	* linux-tdep.c (use_coredump_filter): Likewise.
	(dump_excluded_mappings): Likewise.
	* linux-thread-db.c (auto_load_thread_db): Likewise.
	(check_thread_db_on_load): Likewise.
	* main.c (captured_main_1): Update.
	* maint-test-options.c (struct test_options_opts) <flag_opt, xx1_opt,
	xx2_opt, boolean_opt>: Change to bool.
	* maint-test-settings.c (maintenance_test_settings_boolean): Likewise.
	* maint.c (maintenance_profile_p): Likewise.
	(per_command_time): Likewise.
	(per_command_space): Likewise.
	(per_command_symtab): Likewise.
	* memattr.c (inaccessible_by_default): Likewise.
	* mi/mi-main.c (mi_async): Likewise.
	(mi_async_1): Likewise.
	* mips-tdep.c (mips64_transfers_32bit_regs_p): Likewise.
	* nat/fork-inferior.h (startup_with_shell): Likewise.
	* nat/linux-namespaces.c (debug_linux_namespaces): Likewise.
	* nat/linux-namespaces.h (debug_linux_namespaces): Likewise.
	* nios2-tdep.c (nios2_debug): Likewise.
	* or1k-tdep.c (or1k_debug): Likewise.
	* parse.c (parser_debug): Likewise.
	* parser-defs.h (parser_debug): Likewise.
	* printcmd.c (print_symbol_filename): Likewise.
	* proc-api.c (procfs_trace): Likewise.
	* python/py-auto-load.c (auto_load_python_scripts): Likewise.
	* python/py-param.c (union parmpy_variable): Add "bool boolval" field.
	(set_parameter_value): Update.
	(add_setshow_generic): Update.
	* python/py-value.c (copy_py_bool_obj): Change argument from int*
	to bool*.
	* python/python.c (gdbpy_parameter_value): Cast to bool* instead of
	int*.
	* ravenscar-thread.c (ravenscar_task_support): Change to bool.
	* record-btrace.c (record_btrace_target::store_registers): Update.
	* record-full.c (record_full_memory_query): Change to bool.
	(record_full_stop_at_limit): Likewise.
	* record-full.h (record_full_memory_query): Likewise.
	* remote-notif.c (notif_debug): Likewise.
	* remote-notif.h (notif_debug): Likewise.
	* remote.c (use_range_stepping): Likewise.
	(interrupt_on_connect): Likewise.
	(remote_break): Likewise.
	* ser-tcp.c (tcp_auto_retry): Likewise.
	* ser-unix.c (serial_hwflow): Likewise.
	* skip.c (debug_skip): Likewise.
	* solib-aix.c (solib_aix_debug): Likewise.
	* spu-tdep.c (spu_stop_on_load_p): Likewise.
	(spu_auto_flush_cache_p): Likewise.
	* stack.c (struct backtrace_cmd_options) <full, no_filters, hide>:
	Likewise.
	(struct info_print_options) <quiet>: Likewise.
	* symfile-debug.c (debug_symfile): Likewise.
	* symfile.c (auto_solib_add): Likewise.
	(separate_debug_file_debug): Likewise.
	* symfile.h (auto_solib_add): Likewise.
	(separate_debug_file_debug): Likewise.
	* symtab.c (basenames_may_differ): Likewise.
	(struct filename_partial_match_opts) <dirname, basename>: Likewise.
	(struct info_print_options) <quiet, exclude_minsyms>: Likewise.
	(struct info_types_options) <quiet>: Likewise.
	* symtab.h (demangle): Likewise.
	(basenames_may_differ): Likewise.
	* target-dcache.c (stack_cache_enabled_1): Likewise.
	(code_cache_enabled_1): Likewise.
	* target.c (trust_readonly): Likewise.
	(may_write_registers): Likewise.
	(may_write_memory): Likewise.
	(may_insert_breakpoints): Likewise.
	(may_insert_tracepoints): Likewise.
	(may_insert_fast_tracepoints): Likewise.
	(may_stop): Likewise.
	(auto_connect_native_target): Likewise.
	(target_stop_and_wait): Update.
	(target_async_permitted): Change to bool.
	(target_async_permitted_1): Likewise.
	(may_write_registers_1): Likewise.
	(may_write_memory_1): Likewise.
	(may_insert_breakpoints_1): Likewise.
	(may_insert_tracepoints_1): Likewise.
	(may_insert_fast_tracepoints_1): Likewise.
	(may_stop_1): Likewise.
	* target.h (target_async_permitted): Likewise.
	(may_write_registers): Likewise.
	(may_write_memory): Likewise.
	(may_insert_breakpoints): Likewise.
	(may_insert_tracepoints): Likewise.
	(may_insert_fast_tracepoints): Likewise.
	(may_stop): Likewise.
	* thread.c (struct info_threads_opts) <show_global_ids>: Likewise.
	(make_thread_apply_all_options_def_group): Change argument from int*
	to bool*.
	(thread_apply_all_command): Update.
	(print_thread_events): Change to bool.
	* top.c (confirm): Likewise.
	(command_editing_p): Likewise.
	(history_expansion_p): Likewise.
	(write_history_p): Likewise.
	(info_verbose): Likewise.
	* top.h (confirm): Likewise.
	(history_expansion_p): Likewise.
	* tracepoint.c (disconnected_tracing): Likewise.
	(circular_trace_buffer): Likewise.
	* typeprint.c (print_methods): Likewise.
	(print_typedefs): Likewise.
	* utils.c (debug_timestamp): Likewise.
	(sevenbit_strings): Likewise.
	(pagination_enabled): Likewise.
	* utils.h (sevenbit_strings): Likewise.
	(pagination_enabled): Likewise.
	* valops.c (overload_resolution): Likewise.
	* valprint.h (struct value_print_options) <prettyformat_arrays,
	prettyformat_structs, vtblprint, unionprint, addressprint, objectprint,
	stop_print_at_null, print_array_indexes, deref_ref, static_field_print,
	pascal_static_field_print, raw, summary, symbol_print, finish_print>:
	Likewise.
	* windows-nat.c (new_console): Likewise.
	(cygwin_exceptions): Likewise.
	(new_group): Likewise.
	(debug_exec): Likewise.
	(debug_events): Likewise.
	(debug_memory): Likewise.
	(debug_exceptions): Likewise.
	(useshell): Likewise.
	* windows-tdep.c (maint_display_all_tib): Likewise.
	* xml-support.c (debug_xml): Likewise.
2019-09-18 09:35:12 +09:00
Tom Tromey 381befeedf Rename field_int to field_signed
This renames ui_out::field_int to field_signed, and field_fmt_int to
field_fmt_signed; and changes the type of the "value" parameter from
int to LONGEST.

Tested by the buildbot.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tromey@adacore.com>

	* ui-out.h (class ui_out) <field_signed, field_fmt_signed,
	do_field_signed>: Rename.  Change type of "value".
	* ui-out.c (ui_out::field_signed): Rename from field_int.
	Change type of "value".
	(ui_out::field_fmt_signed): Rename from field_fmt_int.  Change
	type of "value".
	* tui/tui-out.h (class tui_ui_out) <do_field_signed>: Rename from
	do_field_int.  Change type of "value".
	* tui/tui-out.c (tui_ui_out::do_field_signed): Rename from
	do_field_int.  Change type of "value".
	* tracepoint.c (trace_status_mi, tfind_1)
	(print_one_static_tracepoint_marker): Update.
	* thread.c (print_thread_info_1, print_selected_thread_frame):
	Update.
	* stack.c (print_frame, print_frame_info): Update.
	* spu-tdep.c (info_spu_signal_command, info_spu_dma_cmdlist):
	Update.
	* source.c (print_source_lines_base): Update.
	* skip.c (info_skip_command): Update.
	* record-btrace.c (btrace_ui_out_decode_error)
	(btrace_call_history_src_line): Update.
	* python/py-framefilter.c (py_print_single_arg, py_print_frame):
	Update.
	* progspace.c (print_program_space): Update.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Update.
	* mi/mi-out.h (class mi_ui_out) <do_field_signed>: Rename from
	do_field_int.  Change type of "value".
	* mi/mi-out.c (mi_ui_out::do_table_begin)
	(mi_ui_out::do_table_header): Update.
	(mi_ui_out::do_field_signed): Rename from do_field_int.  Change
	type of "value".
	* mi/mi-main.c (mi_cmd_thread_list_ids, print_one_inferior)
	(mi_cmd_data_list_changed_registers, output_register)
	(mi_cmd_data_read_memory, mi_load_progress)
	(mi_cmd_trace_frame_collected): Update.
	* mi/mi-interp.c (mi_on_normal_stop_1, mi_output_solib_attribs):
	Update.
	* mi/mi-cmd-var.c (print_varobj, mi_cmd_var_create)
	(mi_cmd_var_delete, mi_cmd_var_info_num_children)
	(mi_cmd_var_list_children, varobj_update_one): Update.
	* mi/mi-cmd-stack.c (mi_cmd_stack_info_depth)
	(mi_cmd_stack_list_args, list_arg_or_local): Update.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file): Update.
	* inferior.c (print_inferior): Update.
	* gdb_bfd.c (print_one_bfd): Update.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Update.
	* darwin-nat-info.c (darwin_debug_regions_recurse): Update.
	* cli-out.h (class cli_ui_out) <do_field_signed>: Rename from
	do_field_int.  Change type of "value".
	* cli-out.c (cli_ui_out::do_field_signed): Rename from
	do_field_int.  Change type of "value".
	* breakpoint.c (watchpoint_check, print_breakpoint_location)
	(print_one_breakpoint_location, print_it_catch_fork)
	(print_one_catch_fork, print_it_catch_vfork)
	(print_one_catch_vfork, print_it_catch_solib)
	(print_it_catch_exec, print_it_ranged_breakpoint)
	(print_mention_watchpoint, print_mention_masked_watchpoint)
	(bkpt_print_it, update_static_tracepoint): Update.
	* break-catch-throw.c (print_it_exception_catchpoint): Update.
	* break-catch-syscall.c (print_it_catch_syscall): Update.
	* ada-tasks.c (print_ada_task_info): Update.
	* ada-lang.c (print_it_exception, print_mention_exception):
	Update.
2019-07-17 10:34:05 -06:00
Tom Tromey 268a13a5a3 Rename common to gdbsupport
This is the next patch in the ongoing series to move gdbsever to the
top level.

This patch just renames the "common" directory.  The idea is to do
this move in two parts: first rename the directory (this patch), then
move the directory to the top.  This approach makes the patches a bit
more tractable.

I chose the name "gdbsupport" for the directory.  However, as this
patch was largely written by sed, we could pick a new name without too
much difficulty.

Tested by the buildbot.

gdb/ChangeLog
2019-07-09  Tom Tromey  <tom@tromey.com>

	* contrib/ari/gdb_ari.sh: Change common to gdbsupport.
	* configure: Rebuild.
	* configure.ac: Change common to gdbsupport.
	* gdbsupport: Rename from common.
	* acinclude.m4: Change common to gdbsupport.
	* Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES)
	(HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to
	gdbsupport.
	* aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c,
	amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c,
	amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c,
	amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c,
	amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c,
	arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c,
	arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c,
	arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c,
	arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c,
	auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h,
	btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c,
	charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c,
	cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c,
	coff-pe-read.c, command.h, compile/compile-c-support.c,
	compile/compile-c.h, compile/compile-cplus-symbols.c,
	compile/compile-cplus-types.c, compile/compile-cplus.h,
	compile/compile-loc2c.c, compile/compile.c, completer.c,
	completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c,
	cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c,
	darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c,
	disasm.h, dtrace-probe.c, dwarf-index-cache.c,
	dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c,
	dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c,
	event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c,
	features/aarch64-core.c, features/aarch64-fpu.c,
	features/aarch64-pauth.c, features/aarch64-sve.c,
	features/i386/32bit-avx.c, features/i386/32bit-avx512.c,
	features/i386/32bit-core.c, features/i386/32bit-linux.c,
	features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c,
	features/i386/32bit-segments.c, features/i386/32bit-sse.c,
	features/i386/64bit-avx.c, features/i386/64bit-avx512.c,
	features/i386/64bit-core.c, features/i386/64bit-linux.c,
	features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c,
	features/i386/64bit-segments.c, features/i386/64bit-sse.c,
	features/i386/x32-core.c, features/riscv/32bit-cpu.c,
	features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c,
	features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c,
	features/riscv/64bit-fpu.c, features/tic6x-c6xp.c,
	features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h,
	findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h,
	gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c,
	gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c,
	go32-nat.c, guile/guile.c, guile/scm-ports.c,
	guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c,
	i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c,
	i386-linux-tdep.c, i386-tdep.c, i387-tdep.c,
	ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c,
	inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h,
	inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h,
	inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c,
	linux-tdep.c, linux-thread-db.c, location.c, machoread.c,
	macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h,
	mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c,
	mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h,
	minsyms.c, mips-linux-tdep.c, namespace.h,
	nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h,
	nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c,
	nat/amd64-linux-siginfo.c, nat/fork-inferior.c,
	nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c,
	nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c,
	nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h,
	nat/linux-waitpid.c, nat/mips-linux-watch.c,
	nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c,
	nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c,
	nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h,
	obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c,
	parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c,
	procfs.c, producer.c, progspace.h, psymtab.h,
	python/py-framefilter.c, python/py-inferior.c, python/py-ref.h,
	python/py-type.c, python/python.c, record-btrace.c, record-full.c,
	record.c, record.h, regcache-dump.c, regcache.c, regcache.h,
	remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c,
	riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c,
	selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c,
	ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c,
	source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c,
	stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h,
	symtab.c, symtab.h, target-descriptions.c, target-descriptions.h,
	target-memory.c, target.c, target.h, target/waitstatus.c,
	target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c,
	top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c,
	tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h,
	unittests/array-view-selftests.c,
	unittests/child-path-selftests.c, unittests/cli-utils-selftests.c,
	unittests/common-utils-selftests.c,
	unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c,
	unittests/format_pieces-selftests.c,
	unittests/function-view-selftests.c,
	unittests/lookup_name_info-selftests.c,
	unittests/memory-map-selftests.c, unittests/memrange-selftests.c,
	unittests/mkdir-recursive-selftests.c,
	unittests/observable-selftests.c,
	unittests/offset-type-selftests.c, unittests/optional-selftests.c,
	unittests/parse-connection-spec-selftests.c,
	unittests/ptid-selftests.c, unittests/rsp-low-selftests.c,
	unittests/scoped_fd-selftests.c,
	unittests/scoped_mmap-selftests.c,
	unittests/scoped_restore-selftests.c,
	unittests/string_view-selftests.c, unittests/style-selftests.c,
	unittests/tracepoint-selftests.c, unittests/unpack-selftests.c,
	unittests/utils-selftests.c, unittests/xml-utils-selftests.c,
	utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c,
	value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c,
	xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c,
	xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport.

gdb/gdbserver/ChangeLog
2019-07-09  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Change common to gdbsupport.
	* acinclude.m4: Change common to gdbsupport.
	* Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS)
	(version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change
	common to gdbsupport.
	* ax.c, event-loop.c, fork-child.c, gdb_proc_service.h,
	gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c,
	inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c,
	linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c,
	linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c,
	linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h,
	nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c,
	server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h,
	thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change
	common to gdbsupport.
2019-07-09 07:45:38 -06:00
Philippe Waroquiers 66452beb77 Fix leaks by clearing registers and frame caches.
Valgrind reports leaks such as the below in the tests:
gdb.threads/corethreads.exp
gdb.threads/gcore-thread.exp
gdb.ada/task_switch_in_core.exp
gdb.trace/tfile.exp
gdb.base/siginfo-thread.exp

==12701== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,928 of 3,247
==12701==    at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==12701==    by 0x5CF771: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330)
==12701==    by 0x5CF92A: get_thread_regcache (regcache.c:366)
==12701==    by 0x5CF92A: get_current_regcache() (regcache.c:372)
==12701==    by 0x4C7964: get_current_frame() (frame.c:1587)
==12701==    by 0x4C7A3C: get_selected_frame(char const*) (frame.c:1651)
==12701==    by 0x669EAD: print_thread_info_1(ui_out*, char const*, int, int, int) (thread.c:1151)
==12701==    by 0x66A9A1: info_threads_command(char const*, int) (thread.c:1217)
==12701==    by 0x40A878: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1892)
...

Fix these leaks by clearing registers and frame caches.
This leak and fix is similar to the leak fixed by 799efbe8e0
2019-05-04 07:22:01 +02:00
Tom Tromey 9ab8741a48 Consistently use bool for fake_pid_p
I noticed a few spots where fake_pid_p is handled as an int, whereas
the field in struct inferior has type bool.  This patch changes the
remaining places to use bool as well.

Tested by the buildbot.

gdb/ChangeLog
2019-04-09  Tom Tromey  <tromey@adacore.com>

	* remote.c (remote_target::remote_add_inferior): Change fake_pid_p
	to bool.
	(extended_remote_target::attach): Update.
	(remote_target::remote_notice_new_inferior): Update.
	(remote_target::add_current_inferior_and_thread): Update.
	* inferior.c (exit_inferior_1): Use "false".
	* corelow.c (add_to_thread_list): Make fake_pid_p bool.
2019-04-09 11:59:25 -06:00
Tom Tromey a068643d69 Change pid_to_str to return std::string
Currently the target pid_to_str method returns a const char *, so many
implementations have a static buffer that they update.  This patch
changes these methods to return a std::string instead.  I think this
is cleaner and avoids possible gotchas when calling pid_to_str on
different ptids in a single statement.  (Though no such calls exist
currently.)

This also updates various helper functions, and the gdbarch pid_to_str
methods.

I also made a best effort to fix all the callers, but I can't build
some of the *-nat.c files.

Tested by the buildbot.

gdb/ChangeLog
2019-03-13  Tom Tromey  <tromey@adacore.com>

	* i386-gnu-nat.c (i386_gnu_nat_target::fetch_registers)
	(i386_gnu_nat_target::store_registers): Update.
	* target-debug.h (target_debug_print_std_string): New macro.
	* x86-linux-nat.c (x86_linux_nat_target::enable_btrace): Update.
	* windows-tdep.c (display_one_tib): Update.
	* tui/tui-stack.c (tui_make_status_line): Update.
	* top.c (print_inferior_quit_action): Update.
	* thread.c (thr_try_catch_cmd): Update.
	(add_thread_with_info): Update.
	(thread_target_id_str): Update.
	(thr_try_catch_cmd): Update.
	(thread_command): Update.
	(thread_find_command): Update.
	* record-btrace.c (record_btrace_target::info_record)
	(record_btrace_resume_thread, record_btrace_target::resume)
	(record_btrace_cancel_resume, record_btrace_step_thread)
	(record_btrace_target::wait, record_btrace_target::wait)
	(record_btrace_target::wait, record_btrace_target::stop): Update.
	* progspace.c (print_program_space): Update.
	* process-stratum-target.c
	(process_stratum_target::thread_address_space): Update.
	* linux-fork.c (linux_fork_mourn_inferior)
	(detach_checkpoint_command, info_checkpoints_command)
	(linux_fork_context): Update.
	(linux_fork_detach): Update.
	(class scoped_switch_fork_info): Update.
	(delete_checkpoint_command): Update.
	* infrun.c (follow_fork_inferior): Update.
	(follow_fork_inferior): Update.
	(proceed_after_vfork_done): Update.
	(handle_vfork_child_exec_or_exit): Update.
	(follow_exec): Update.
	(displaced_step_prepare_throw): Update.
	(displaced_step_restore): Update.
	(start_step_over): Update.
	(resume_1): Update.
	(clear_proceed_status_thread): Update.
	(proceed): Update.
	(print_target_wait_results): Update.
	(do_target_wait): Update.
	(context_switch): Update.
	(stop_all_threads): Update.
	(restart_threads): Update.
	(finish_step_over): Update.
	(handle_signal_stop): Update.
	(switch_back_to_stepped_thread): Update.
	(keep_going_pass_signal): Update.
	(print_exited_reason): Update.
	(normal_stop): Update.
	* inferior.c (inferior_pid_to_str): Change return type.
	(print_selected_inferior): Update.
	(add_inferior): Update.
	(detach_inferior): Update.
	* dummy-frame.c (fprint_dummy_frames): Update.
	* dcache.c (dcache_info_1): Update.
	* btrace.c (btrace_enable, btrace_disable, btrace_teardown)
	(btrace_fetch, btrace_clear): Update.
	* linux-tdep.c (linux_core_pid_to_str): Change return type.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Change return
	type.
	* fbsd-tdep.c (fbsd_core_pid_to_str): Change return type.
	* sol2-tdep.h (sol2_core_pid_to_str): Change return type.
	* sol2-tdep.c (sol2_core_pid_to_str): Change return type.
	* gdbarch.c, gdbarch.h: Rebuild.
	* gdbarch.sh (core_pid_to_str): Change return type.
	* windows-nat.c (struct windows_nat_target) <pid_to_str>: Change
	return type.
	(windows_nat_target::pid_to_str): Change return type.
	(windows_delete_thread): Update.
	(windows_nat_target::attach): Update.
	(windows_nat_target::files_info): Update.
	* target-delegates.c: Rebuild.
	* sol-thread.c (class sol_thread_target) <pid_to_str>: Change
	return type.
	(sol_thread_target::pid_to_str): Change return type.
	* remote.c (class remote_target) <pid_to_str>: Change return
	type.
	(remote_target::pid_to_str): Change return type.
	(extended_remote_target::attach, remote_target::remote_stop_ns)
	(remote_target::remote_notif_remove_queued_reply)
	(remote_target::push_stop_reply, remote_target::disable_btrace):
	Update.
	(extended_remote_target::attach): Update.
	* remote-sim.c (struct gdbsim_target) <pid_to_str>: Change return
	type.
	(gdbsim_target::pid_to_str): Change return type.
	* ravenscar-thread.c (struct ravenscar_thread_target)
	<pid_to_str>: Change return type.
	(ravenscar_thread_target::pid_to_str): Change return type.
	* procfs.c (class procfs_target) <pid_to_str>: Change return
	type.
	(procfs_target::pid_to_str): Change return type.
	(procfs_target::attach): Update.
	(procfs_target::detach): Update.
	(procfs_target::fetch_registers): Update.
	(procfs_target::store_registers): Update.
	(procfs_target::wait): Update.
	(procfs_target::files_info): Update.
	* obsd-nat.c (obsd_nat_target::pid_to_str): Change return type.
	* nto-procfs.c (struct nto_procfs_target) <pid_to_str>: Change
	return type.
	(nto_procfs_target::pid_to_str): Change return type.
	(nto_procfs_target::files_info, nto_procfs_target::attach): Update.
	* linux-thread-db.c (class thread_db_target) <pid_to_str>: Change
	return type.
	* linux-nat.c (linux_nat_target::pid_to_str): Change return type.
	(exit_lwp): Update.
	(attach_proc_task_lwp_callback, get_detach_signal)
	(detach_one_lwp, resume_lwp, linux_nat_target::resume)
	(linux_nat_target::resume, wait_lwp, stop_callback)
	(maybe_clear_ignore_sigint, stop_wait_callback, status_callback)
	(save_stop_reason, select_event_lwp, linux_nat_filter_event)
	(linux_nat_wait_1, resume_stopped_resumed_lwps)
	(linux_nat_target::wait, linux_nat_stop_lwp): Update.
	* inf-ptrace.c (inf_ptrace_target::pid_to_str): Change return
	type.
	(inf_ptrace_target::attach): Update.
	(inf_ptrace_target::files_info): Update.
	* go32-nat.c (struct go32_nat_target) <pid_to_str>: Change return
	type.
	(go32_nat_target::pid_to_str): Change return type.
	* gnu-nat.c (gnu_nat_target::pid_to_str): Change return type.
	(gnu_nat_target::wait): Update.
	(gnu_nat_target::wait): Update.
	(gnu_nat_target::resume): Update.
	* fbsd-nat.c (fbsd_nat_target::pid_to_str): Change return type.
	(fbsd_nat_target::wait): Update.
	* darwin-nat.c (darwin_nat_target::pid_to_str): Change return
	type.
	(darwin_nat_target::attach): Update.
	* corelow.c (class core_target) <pid_to_str>: Change return type.
	(core_target::pid_to_str): Change return type.
	* target.c (normal_pid_to_str): Change return type.
	(default_pid_to_str): Likewise.
	(target_pid_to_str): Change return type.
	(target_translate_tls_address): Update.
	(target_announce_detach): Update.
	* bsd-uthread.c (struct bsd_uthread_target) <pid_to_str>: Change
	return type.
	(bsd_uthread_target::pid_to_str): Change return type.
	* bsd-kvm.c (class bsd_kvm_target) <pid_to_str>: Change return
	type.
	(bsd_kvm_target::pid_to_str): Change return type.
	* aix-thread.c (class aix_thread_target) <pid_to_str>: Change
	return type.
	(aix_thread_target::pid_to_str): Change return type.
	* target.h (struct target_ops) <pid_to_str>: Change return type.
	(target_pid_to_str, normal_pid_to_str): Likewise.
	* obsd-nat.h (class obsd_nat_target) <pid_to_str>: Change return
	type.
	* linux-nat.h (class linux_nat_target) <pid_to_str>: Change return
	type.
	* inf-ptrace.h (struct inf_ptrace_target) <pid_to_str>: Change
	return type.
	* gnu-nat.h (struct gnu_nat_target) <pid_to_str>: Change return
	type.
	* fbsd-nat.h (class fbsd_nat_target) <pid_to_str>: Change return
	type.
	* darwin-nat.h (class darwin_nat_target) <pid_to_str>: Change
	return type.
2019-03-13 13:50:13 -06:00
Philippe Waroquiers e3abbe7e94 Ensure 'help set/show print inferior-events' shows the example events.
Without this patch, the help stops after  'e.g.' :
  (gdb) apropos \(inferior\|thread\) event
  set print inferior-events -- Set printing of inferior events (e.g.
  set print thread-events -- Set printing of thread events (such as thread start and exit)
  show print inferior-events -- Show printing of inferior events (e.g.
  show print thread-events -- Show printing of thread events (such as thread start and exit)

Using the same notation as for the thread evenets (i.e. 'such as') gives:
 (gdb) apropos \(inferior\|thread\) event
 set print inferior-events -- Set printing of inferior events (such as inferior start and exit)
 set print thread-events -- Set printing of thread events (such as thread start and exit)
 show print inferior-events -- Show printing of inferior events (such as inferior start and exit)
 show print thread-events -- Show printing of thread events (such as thread start and exit)
2019-03-09 12:25:11 +01:00
Tom Tromey 0747795c08 Normalize includes to use common/
This changes all includes to use the form "common/filename.h" rather
than just "filename.h".  This was written by a script.

gdb/ChangeLog
2019-01-25  Tom Tromey  <tom@tromey.com>

	* xtensa-linux-nat.c: Fix common/ includes.
	* xml-support.h: Fix common/ includes.
	* xml-support.c: Fix common/ includes.
	* x86-linux-nat.c: Fix common/ includes.
	* windows-nat.c: Fix common/ includes.
	* varobj.h: Fix common/ includes.
	* varobj.c: Fix common/ includes.
	* value.c: Fix common/ includes.
	* valops.c: Fix common/ includes.
	* utils.c: Fix common/ includes.
	* unittests/xml-utils-selftests.c: Fix common/ includes.
	* unittests/utils-selftests.c: Fix common/ includes.
	* unittests/unpack-selftests.c: Fix common/ includes.
	* unittests/tracepoint-selftests.c: Fix common/ includes.
	* unittests/style-selftests.c: Fix common/ includes.
	* unittests/string_view-selftests.c: Fix common/ includes.
	* unittests/scoped_restore-selftests.c: Fix common/ includes.
	* unittests/scoped_mmap-selftests.c: Fix common/ includes.
	* unittests/scoped_fd-selftests.c: Fix common/ includes.
	* unittests/rsp-low-selftests.c: Fix common/ includes.
	* unittests/parse-connection-spec-selftests.c: Fix common/
	includes.
	* unittests/optional-selftests.c: Fix common/ includes.
	* unittests/offset-type-selftests.c: Fix common/ includes.
	* unittests/observable-selftests.c: Fix common/ includes.
	* unittests/mkdir-recursive-selftests.c: Fix common/ includes.
	* unittests/memrange-selftests.c: Fix common/ includes.
	* unittests/memory-map-selftests.c: Fix common/ includes.
	* unittests/lookup_name_info-selftests.c: Fix common/ includes.
	* unittests/function-view-selftests.c: Fix common/ includes.
	* unittests/environ-selftests.c: Fix common/ includes.
	* unittests/copy_bitwise-selftests.c: Fix common/ includes.
	* unittests/common-utils-selftests.c: Fix common/ includes.
	* unittests/cli-utils-selftests.c: Fix common/ includes.
	* unittests/array-view-selftests.c: Fix common/ includes.
	* ui-file.c: Fix common/ includes.
	* tui/tui-io.c: Fix common/ includes.
	* tracepoint.h: Fix common/ includes.
	* tracepoint.c: Fix common/ includes.
	* tracefile-tfile.c: Fix common/ includes.
	* top.h: Fix common/ includes.
	* top.c: Fix common/ includes.
	* thread.c: Fix common/ includes.
	* target/waitstatus.h: Fix common/ includes.
	* target/waitstatus.c: Fix common/ includes.
	* target.h: Fix common/ includes.
	* target.c: Fix common/ includes.
	* target-memory.c: Fix common/ includes.
	* target-descriptions.c: Fix common/ includes.
	* symtab.h: Fix common/ includes.
	* symfile.c: Fix common/ includes.
	* stap-probe.c: Fix common/ includes.
	* spu-linux-nat.c: Fix common/ includes.
	* sparc-nat.c: Fix common/ includes.
	* source.c: Fix common/ includes.
	* solib.c: Fix common/ includes.
	* solib-target.c: Fix common/ includes.
	* ser-unix.c: Fix common/ includes.
	* ser-tcp.c: Fix common/ includes.
	* ser-pipe.c: Fix common/ includes.
	* ser-base.c: Fix common/ includes.
	* selftest-arch.c: Fix common/ includes.
	* s12z-tdep.c: Fix common/ includes.
	* rust-exp.y: Fix common/ includes.
	* rs6000-aix-tdep.c: Fix common/ includes.
	* riscv-tdep.c: Fix common/ includes.
	* remote.c: Fix common/ includes.
	* remote-notif.h: Fix common/ includes.
	* remote-fileio.h: Fix common/ includes.
	* remote-fileio.c: Fix common/ includes.
	* regcache.h: Fix common/ includes.
	* regcache.c: Fix common/ includes.
	* record-btrace.c: Fix common/ includes.
	* python/python.c: Fix common/ includes.
	* python/py-type.c: Fix common/ includes.
	* python/py-inferior.c: Fix common/ includes.
	* progspace.h: Fix common/ includes.
	* producer.c: Fix common/ includes.
	* procfs.c: Fix common/ includes.
	* proc-api.c: Fix common/ includes.
	* printcmd.c: Fix common/ includes.
	* ppc-linux-nat.c: Fix common/ includes.
	* parser-defs.h: Fix common/ includes.
	* osdata.c: Fix common/ includes.
	* obsd-nat.c: Fix common/ includes.
	* nat/x86-linux.c: Fix common/ includes.
	* nat/x86-linux-dregs.c: Fix common/ includes.
	* nat/x86-dregs.h: Fix common/ includes.
	* nat/x86-dregs.c: Fix common/ includes.
	* nat/ppc-linux.c: Fix common/ includes.
	* nat/mips-linux-watch.h: Fix common/ includes.
	* nat/mips-linux-watch.c: Fix common/ includes.
	* nat/linux-waitpid.c: Fix common/ includes.
	* nat/linux-ptrace.h: Fix common/ includes.
	* nat/linux-ptrace.c: Fix common/ includes.
	* nat/linux-procfs.c: Fix common/ includes.
	* nat/linux-personality.c: Fix common/ includes.
	* nat/linux-osdata.c: Fix common/ includes.
	* nat/linux-namespaces.c: Fix common/ includes.
	* nat/linux-btrace.h: Fix common/ includes.
	* nat/linux-btrace.c: Fix common/ includes.
	* nat/fork-inferior.c: Fix common/ includes.
	* nat/amd64-linux-siginfo.c: Fix common/ includes.
	* nat/aarch64-sve-linux-ptrace.c: Fix common/ includes.
	* nat/aarch64-linux.c: Fix common/ includes.
	* nat/aarch64-linux-hw-point.h: Fix common/ includes.
	* nat/aarch64-linux-hw-point.c: Fix common/ includes.
	* namespace.h: Fix common/ includes.
	* mips-linux-tdep.c: Fix common/ includes.
	* minsyms.c: Fix common/ includes.
	* mi/mi-parse.h: Fix common/ includes.
	* mi/mi-main.c: Fix common/ includes.
	* mi/mi-cmd-env.c: Fix common/ includes.
	* memrange.h: Fix common/ includes.
	* memattr.c: Fix common/ includes.
	* maint.h: Fix common/ includes.
	* maint.c: Fix common/ includes.
	* main.c: Fix common/ includes.
	* machoread.c: Fix common/ includes.
	* location.c: Fix common/ includes.
	* linux-thread-db.c: Fix common/ includes.
	* linux-nat.c: Fix common/ includes.
	* linux-fork.c: Fix common/ includes.
	* inline-frame.c: Fix common/ includes.
	* infrun.c: Fix common/ includes.
	* inflow.c: Fix common/ includes.
	* inferior.h: Fix common/ includes.
	* inferior.c: Fix common/ includes.
	* infcmd.c: Fix common/ includes.
	* inf-ptrace.c: Fix common/ includes.
	* inf-child.c: Fix common/ includes.
	* ia64-linux-nat.c: Fix common/ includes.
	* i387-tdep.c: Fix common/ includes.
	* i386-tdep.c: Fix common/ includes.
	* i386-linux-tdep.c: Fix common/ includes.
	* i386-linux-nat.c: Fix common/ includes.
	* i386-go32-tdep.c: Fix common/ includes.
	* i386-fbsd-tdep.c: Fix common/ includes.
	* i386-fbsd-nat.c: Fix common/ includes.
	* guile/scm-type.c: Fix common/ includes.
	* guile/guile.c: Fix common/ includes.
	* go32-nat.c: Fix common/ includes.
	* gnu-nat.c: Fix common/ includes.
	* gdbthread.h: Fix common/ includes.
	* gdbarch-selftests.c: Fix common/ includes.
	* gdb_usleep.c: Fix common/ includes.
	* gdb_select.h: Fix common/ includes.
	* gdb_bfd.c: Fix common/ includes.
	* gcore.c: Fix common/ includes.
	* fork-child.c: Fix common/ includes.
	* findvar.c: Fix common/ includes.
	* fbsd-nat.c: Fix common/ includes.
	* event-top.c: Fix common/ includes.
	* event-loop.c: Fix common/ includes.
	* dwarf2read.c: Fix common/ includes.
	* dwarf2loc.c: Fix common/ includes.
	* dwarf2-frame.c: Fix common/ includes.
	* dwarf-index-cache.c: Fix common/ includes.
	* dtrace-probe.c: Fix common/ includes.
	* disasm-selftests.c: Fix common/ includes.
	* defs.h: Fix common/ includes.
	* csky-tdep.c: Fix common/ includes.
	* cp-valprint.c: Fix common/ includes.
	* cp-support.h: Fix common/ includes.
	* cp-support.c: Fix common/ includes.
	* corelow.c: Fix common/ includes.
	* completer.h: Fix common/ includes.
	* completer.c: Fix common/ includes.
	* compile/compile.c: Fix common/ includes.
	* compile/compile-loc2c.c: Fix common/ includes.
	* compile/compile-cplus-types.c: Fix common/ includes.
	* compile/compile-cplus-symbols.c: Fix common/ includes.
	* command.h: Fix common/ includes.
	* cli/cli-dump.c: Fix common/ includes.
	* cli/cli-cmds.c: Fix common/ includes.
	* charset.c: Fix common/ includes.
	* build-id.c: Fix common/ includes.
	* btrace.h: Fix common/ includes.
	* btrace.c: Fix common/ includes.
	* breakpoint.h: Fix common/ includes.
	* breakpoint.c: Fix common/ includes.
	* ax.h:
	(enum agent_op): Fix common/ includes.
	* ax-general.c (struct aop_map): Fix common/ includes.
	* ax-gdb.c: Fix common/ includes.
	* auxv.c: Fix common/ includes.
	* auto-load.c: Fix common/ includes.
	* arm-tdep.c: Fix common/ includes.
	* arch/riscv.c: Fix common/ includes.
	* arch/ppc-linux-common.c: Fix common/ includes.
	* arch/i386.c: Fix common/ includes.
	* arch/arm.c: Fix common/ includes.
	* arch/arm-linux.c: Fix common/ includes.
	* arch/arm-get-next-pcs.c: Fix common/ includes.
	* arch/amd64.c: Fix common/ includes.
	* arch/aarch64.c: Fix common/ includes.
	* arch/aarch64-insn.c: Fix common/ includes.
	* arch-utils.c: Fix common/ includes.
	* amd64-windows-tdep.c: Fix common/ includes.
	* amd64-tdep.c: Fix common/ includes.
	* amd64-sol2-tdep.c: Fix common/ includes.
	* amd64-obsd-tdep.c: Fix common/ includes.
	* amd64-nbsd-tdep.c: Fix common/ includes.
	* amd64-linux-tdep.c: Fix common/ includes.
	* amd64-linux-nat.c: Fix common/ includes.
	* amd64-fbsd-tdep.c: Fix common/ includes.
	* amd64-fbsd-nat.c: Fix common/ includes.
	* amd64-dicos-tdep.c: Fix common/ includes.
	* amd64-darwin-tdep.c: Fix common/ includes.
	* agent.c: Fix common/ includes.
	* ada-lang.h: Fix common/ includes.
	* ada-lang.c: Fix common/ includes.
	* aarch64-tdep.c: Fix common/ includes.

gdb/gdbserver/ChangeLog
2019-01-25  Tom Tromey  <tom@tromey.com>

	* win32-low.c: Fix common/ includes.
	* win32-i386-low.c: Fix common/ includes.
	* tracepoint.c: Fix common/ includes.
	* thread-db.c: Fix common/ includes.
	* target.h: Fix common/ includes.
	* symbol.c: Fix common/ includes.
	* spu-low.c: Fix common/ includes.
	* server.h: Fix common/ includes.
	* server.c: Fix common/ includes.
	* remote-utils.c: Fix common/ includes.
	* regcache.h: Fix common/ includes.
	* regcache.c: Fix common/ includes.
	* nto-x86-low.c: Fix common/ includes.
	* notif.h: Fix common/ includes.
	* mem-break.h: Fix common/ includes.
	* lynx-low.c: Fix common/ includes.
	* lynx-i386-low.c: Fix common/ includes.
	* linux-x86-tdesc-selftest.c: Fix common/ includes.
	* linux-x86-low.c: Fix common/ includes.
	* linux-low.c: Fix common/ includes.
	* inferiors.h: Fix common/ includes.
	* i387-fp.c: Fix common/ includes.
	* hostio.c: Fix common/ includes.
	* hostio-errno.c: Fix common/ includes.
	* gdbthread.h: Fix common/ includes.
	* gdbreplay.c: Fix common/ includes.
	* fork-child.c: Fix common/ includes.
	* event-loop.c: Fix common/ includes.
	* ax.c:
	(enum gdb_agent_op): Fix common/ includes.
2019-01-25 15:28:16 -07:00
Joel Brobecker 42a4f53d2b Update copyright year range in all GDB files.
This commit applies all changes made after running the gdb/copyright.py
script.

Note that one file was flagged by the script, due to an invalid
copyright header
(gdb/unittests/basic_string_view/element_access/char/empty.cc).
As the file was copied from GCC's libstdc++-v3 testsuite, this commit
leaves this file untouched for the time being; a patch to fix the header
was sent to gcc-patches first.

gdb/ChangeLog:

	Update copyright year range in all GDB files.
2019-01-01 10:01:51 +04:00
Pedro Alves 0803633106 Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc.
As preparation for multi-target, this patch makes each inferior have
its own thread list.

This isn't absolutely necessary for multi-target, but simplifies
things.  It originally stemmed from the desire to eliminate the
init_thread_list calls sprinkled around, plus it makes it more
efficient to iterate over threads of a given inferior (no need to
always iterate over threads of all inferiors).

We still need to iterate over threads of all inferiors in a number of
places, which means we'd need adjust the ALL_THREADS /
ALL_NON_EXITED_THREADS macros.  However, naively tweaking those macros
to have an extra for loop, like:

     #define ALL_THREADS (thr, inf) \
       for (inf = inferior_list; inf; inf = inf->next) \
	 for (thr = inf->thread_list; thr; thr = thr->next)

causes problems with code that does "break" or "continue" within the
ALL_THREADS loop body.  Plus, we need to declare the extra "inf" local
variable in order to pass it as temporary variable to ALL_THREADS
(etc.)

It gets even trickier when we consider extending the macros to filter
out threads matching a ptid_t and a target.  The macros become tricker
to read/write.  Been there.

An alternative (which was my next attempt), is to replace the
ALL_THREADS etc. iteration style with for_each_all_threads,
for_each_non_exited_threads, etc. functions which would take a
callback as parameter, which would usually be passed a lambda.
However, I did not find that satisfactory at all, because the
resulting code ends up a little less natural / more noisy to read,
write and debug/step-through (due to use of lambdas), and in many
places where we use "continue;" to skip to the next thread now need to
use "return;".  (I ran into hard to debug bugs caused by a
continue/return confusion.)

I.e., before:

    ALL_NON_EXITED_THREADS (tp)
      {
	if (tp->not_what_I_want)
	  continue;
	// do something
      }

would turn into:

    for_each_non_exited_thread ([&] (thread_info *tp)
      {
	if (tp->not_what_I_want)
	  return;
	// do something
      });

Lastly, the solution I settled with was to replace the ALL_THREADS /
ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges
and iterators, such that you can instead naturaly iterate over
threads/inferiors using range-for, like e.g,.:

   // all threads, including THREAD_EXITED threads.
   for (thread_info *tp : all_threads ())
     { .... }

   // all non-exited threads.
   for (thread_info *tp : all_non_exited_threads ())
     { .... }

   // all non-exited threads of INF inferior.
   for (thread_info *tp : inf->non_exited_threads ())
     { .... }

The all_non_exited_threads() function takes an optional filter ptid_t as
parameter, which is quite convenient when we need to iterate over
threads matching that filter.  See e.g., how the
set_executing/set_stop_requested/finish_thread_state etc. functions in
thread.c end up being simplified.

Most of the patch thus is about adding the infrustructure for allowing
the above.  Later on when we get to actual multi-target, these
functions/ranges/iterators will gain a "target_ops *" parameter so
that e.g., we can iterate over all threads of a given target that
match a given filter ptid_t.

The only entry points users needs to be aware of are the
all_threads/all_non_exited_threads etc. functions seen above.  Thus,
those functions are declared in gdbthread.h/inferior.h.  The actual
iterators/ranges are mainly "internals" and thus are put out of view
in the new thread-iter.h/thread-iter.c/inferior-iter.h files.  That
keeps the gdbthread.h/inferior.h headers quite a bit more readable.

A common/safe-iterator.h header is added which adds a template that
can be used to build "safe" iterators, which are forward iterators
that can be used to replace the ALL_THREADS_SAFE macro and other
instances of the same idiom in future.

There's a little bit of shuffling of code between
gdbthread.h/thread.c/inferior.h in the patch.  That is necessary in
order to avoid circular dependencies between the
gdbthread.h/inferior.h headers.

As for the init_thread_list calls sprinkled around, they're all
eliminated by this patch, and a new, central call is added to
inferior_appeared.  Note how also related to that, there's a call to
init_wait_for_inferior in remote.c that is eliminated.
init_wait_for_inferior is currently responsible for discarding skipped
inline frames, which had to be moved elsewhere.  Given that nowadays
we always have a thread even for single-threaded processes, the
natural place is to delete a frame's inline frame info when we delete
the thread.  I.e., from clear_thread_inferior_resources.

gdb/ChangeLog:
2018-11-22  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_SFILES): Add thread-iter.c.
	* breakpoint.c (breakpoints_should_be_inserted_now): Replace
	ALL_NON_EXITED_THREADS with all_non_exited_threads.
	(print_one_breakpoint_location): Replace ALL_INFERIORS with
	all_inferiors.
	* bsd-kvm.c: Include inferior.h.
	* btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS
	with all_non_exited_threads.
	* common/filtered-iterator.h: New.
	* common/safe-iterator.h: New.
	* corelow.c (core_target_open): Don't call init_thread_list here.
	* darwin-nat.c (thread_info_from_private_thread_info): Replace
	ALL_THREADS with all_threads.
	* fbsd-nat.c (fbsd_nat_target::resume): Replace
	ALL_NON_EXITED_THREADS with inf->non_exited_threads.
	* fbsd-tdep.c (fbsd_make_corefile_notes): Replace
	ALL_NON_EXITED_THREADS with inf->non_exited_threads.
	* fork-child.c (postfork_hook): Don't call init_thread_list here.
	* gdbarch-selftests.c (register_to_value_test): Adjust.
	* gdbthread.h: Don't include "inferior.h" here.
	(struct inferior): Forward declare.
	(enum step_over_calls_kind): Moved here from inferior.h.
	(thread_info::deletable): Definition moved to thread.c.
	(find_thread_ptid (inferior *, ptid_t)): Declare.
	(ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete.
	Include "thread-iter.h".
	(all_threads, all_non_exited_threads, all_threads_safe): New.
	(any_thread_p): Declare.
	(thread_list): Delete.
	* infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with
	all_non_exited_threads.
	(proceed_after_attach_callback): Delete.
	(proceed_after_attach): Take an inferior pointer instead of an
	integer PID.  Adjust to use range-for.
	(attach_post_wait): Pass down inferior pointer instead of pid.
	Use range-for instead of ALL_NON_EXITED_THREADS.
	(detach_command): Remove init_thread_list call.
	* inferior-iter.h: New.
	* inferior.c (struct delete_thread_of_inferior_arg): Delete.
	(delete_thread_of_inferior): Delete.
	(delete_inferior, exit_inferior_1): Use range-for with
	inf->threads_safe() instead of iterate_over_threads.
	(inferior_appeared): Call init_thread_list here.
	(discard_all_inferiors): Use all_non_exited_inferiors.
	(find_inferior_id, find_inferior_pid): Use all_inferiors.
	(iterate_over_inferiors): Use all_inferiors_safe.
	(have_inferiors, number_of_live_inferiors): Use
	all_non_exited_inferiors.
	(number_of_inferiors): Use all_inferiors and std::distance.
	(print_inferior): Use all_inferiors.
	* inferior.h: Include gdbthread.h.
	(enum step_over_calls_kind): Moved to gdbthread.h.
	(struct inferior) <thread_list>: New field.
	<threads, non_exited_threads, threads_safe>: New methods.
	(ALL_INFERIORS): Delete.
	Include "inferior-iter.h".
	(ALL_NON_EXITED_INFERIORS): Delete.
	(all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New
	functions.
	* inflow.c (child_interrupt, child_pass_ctrlc): Replace
	ALL_NON_EXITED_THREADS with all_non_exited_threads.
	* infrun.c (follow_exec): Use all_threads_safe.
	(clear_proceed_status, proceed): Use all_non_exited_threads.
	(init_wait_for_inferior): Don't clear inline frame state here.
	(infrun_thread_stop_requested, for_each_just_stopped_thread): Use
	all_threads instead of ALL_NON_EXITED_THREADS.
	(random_pending_event_thread): Use all_non_exited_threads instead
	of ALL_NON_EXITED_THREADS.  Use a lambda for repeated code.
	(clean_up_just_stopped_threads_fsms): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	(handle_no_resumed): Use all_non_exited_threads instead of
	ALL_NON_EXITED_THREADS.  Use all_inferiors instead of
	ALL_INFERIORS.
	(restart_threads, switch_back_to_stepped_thread): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with
	all_inferiors.
	(kill_unfollowed_fork_children): Use inf->non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	* linux-tdep.c (linux_make_corefile_notes): Use
	inf->non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* linux-thread-db.c (thread_db_target::update_thread_list):
	Replace ALL_INFERIORS with all_inferiors.
	(thread_db_target::thread_handle_to_thread_info): Use
	inf->non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* mi/mi-interp.c (multiple_inferiors_p): New.
	(mi_on_resume_1): Simplify using all_non_exited_threads and
	multiple_inferiors_p.
	* mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	* nto-procfs.c (nto_procfs_target::open): Don't call
	init_thread_list here.
	* record-btrace.c (record_btrace_target_open)
	(record_btrace_target::stop_recording)
	(record_btrace_target::close)
	(record_btrace_target::record_is_replaying)
	(record_btrace_target::resume, record_btrace_target::wait)
	(record_btrace_target::record_stop_replaying): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* record-full.c (record_full_wait_1): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	* regcache.c (cooked_read_test): Remove reference to global
	thread_list.
	* remote-sim.c (gdbsim_target::create_inferior): Don't call
	init_thread_list here.
	* remote.c (remote_target::update_thread_list): Use
	all_threads_safe instead of ALL_NON_EXITED_THREADS.
	(remote_target::process_initial_stop_replies): Replace
	ALL_INFERIORS with all_non_exited_inferiors and use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	(remote_target::open_1): Don't call init_thread_list here.
	(remote_target::append_pending_thread_resumptions)
	(remote_target::remote_resume_with_hc): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	(remote_target::commit_resume)
	(remote_target::remove_new_fork_children): Replace ALL_INFERIORS
	with all_non_exited_inferiors and use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	(remote_target::kill_new_fork_children): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.  Remove
	init_thread_list and init_wait_for_inferior calls.
	(remote_target::remote_btrace_maybe_reopen)
	(remote_target::thread_handle_to_thread_info): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* target.c (target_terminal::restore_inferior)
	(target_terminal_is_ours_kind): Replace ALL_INFERIORS with
	all_non_exited_inferiors.
	* thread-iter.c: New file.
	* thread-iter.h: New file.
	* thread.c: Include "inline-frame.h".
	(thread_list): Delete.
	(clear_thread_inferior_resources): Call clear_inline_frame_state.
	(init_thread_list): Use all_threads_safe instead of
	ALL_THREADS_SAFE.  Adjust to per-inferior thread lists.
	(new_thread): Adjust to per-inferior thread lists.
	(add_thread_silent): Pass inferior to find_thread_ptid.
	(thread_info::deletable): New, moved from the header.
	(delete_thread_1): Adjust to per-inferior thread lists.
	(find_thread_global_id): Use inf->threads().
	(find_thread_ptid): Use find_inferior_ptid and pass inferior to
	find_thread_ptid.
	(find_thread_ptid(inferior*, ptid_t)): New overload.
	(iterate_over_threads): Use all_threads_safe.
	(any_thread_p): New.
	(thread_count): Use all_threads and std::distance.
	(live_threads_count): Use all_non_exited_threads and
	std::distance.
	(valid_global_thread_id): Use all_threads.
	(in_thread_list): Use find_thread_ptid.
	(first_thread_of_inferior): Adjust to per-inferior thread lists.
	(any_thread_of_inferior, any_live_thread_of_inferior): Use
	inf->non_exited_threads().
	(prune_threads, delete_exited_threads): Use all_threads_safe.
	(thread_change_ptid): Pass inferior pointer to find_thread_ptid.
	(set_resumed, set_running): Use all_non_exited_threads.
	(is_thread_state, is_stopped, is_exited, is_running)
	(is_executing): Delete.
	(set_executing, set_stop_requested, finish_thread_state): Use
	all_non_exited_threads.
	(print_thread_info_1): Use all_inferiors and all_threads.
	(thread_apply_all_command): Use all_non_exited_threads.
	(thread_find_command): Use all_threads.
	(update_threads_executing): Use all_non_exited_threads.
	* tid-parse.c (parse_thread_id): Use inf->threads.
	* x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 16:13:23 +00:00
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
Tom Tromey ee841dd8fe Use new and delete for struct infcall_control_state
This changes infrun.c to use new and delete for infcall_control_state.

gdb/ChangeLog
2018-09-17  Tom Tromey  <tom@tromey.com>

	* gdbthread.h (struct thread_control_state): Add initializer.
	(class thread_info) <control>: Remove initializer.
	* inferior.h (struct inferior_control_state): Add initializer.
	(class inferior) <control>: Remove initializer.
	(exit_inferior_1): Update.
	* infrun.c (struct infcall_control_state): Add constructors.
	(save_infcall_control_state): Use new.
	(restore_infcall_control_state, discard_infcall_control_state):
	Use delete.
2018-09-17 00:42:18 -06:00
Tom Tromey 8d49165d83 Simple unused variable removals
This patch holds all the straightforward unused variable deletions.

gdb/ChangeLog
2018-07-22  Tom Tromey  <tom@tromey.com>

	* guile/scm-value.c (gdbscm_value_call): Remove unused variables.
	* guile/scm-math.c (vlscm_unop_gdbthrow, vlscm_binop_gdbthrow)
	(vlscm_convert_typed_value_from_scheme): Remove unused variable.
	* buildsym-legacy.c (get_macro_table): Remove unused variable.
	* stack.c (frame_apply_level_command): Remove unused variable.
	* tic6x-tdep.c (tic6x_push_dummy_call): Remove unused variable.
	* sparc64-tdep.c (adi_examine_command): Remove unused variable.
	* rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Remove
	unused variable.
	* nios2-tdep.c (nios2_push_dummy_call): Remove unused variable.
	* mep-tdep.c (mep_push_dummy_call): Remove unused variable.
	* ada-lang.c (ada_lookup_symbol_list_worker): Remove unused
	variable.
	* amd64-tdep.c (amd64_supply_xsave): Remove unused variable.
	* arm-tdep.c (arm_record_data_proc_misc_ld_str): Remove unused
	variable.
	* breakpoint.c (check_no_tracepoint_commands, update_watchpoint):
	Remove unused variable.
	* cli/cli-script.c (recurse_read_control_structure): Remove unused
	variable.
	* common/tdesc.c (print_xml_feature::visit): Remove unused
	variable.
	* compile/compile-object-load.c (store_regs): Remove unused
	variables.
	* complaints.c (clear_complaints): Remove unused variable.
	* corelow.c (core_target_open): Remove unused variable.
	* fbsd-tdep.c (fbsd_core_info_proc_status): Remove unused
	variable.
	* guile/scm-frame.c (gdbscm_frame_read_var): Remove unused
	variable.
	* guile/scm-symtab.c (stscm_print_sal_smob): Remove unused
	variable.
	* guile/scm-type.c (gdbscm_field_baseclass_p): Remove unused
	variable.
	* guile/scm-utils.c (gdbscm_parse_function_args): Remove unused
	variable.
	* hppa-tdep.c (hppa_stub_frame_unwind_cache): Remove unused
	variable.
	* ia64-tdep.c (examine_prologue): Remove unused variable.
	* infcall.c (run_inferior_call): Remove unused variable.
	* inferior.c (exit_inferior): Remove unused variable.
	* infrun.c (infrun_thread_ptid_changed): Remove unused variable.
	* linespec.c (decode_line_2): Remove unused variable.
	* linux-nat.c (super_close): Remove.
	* linux-tdep.c (linux_info_proc): Remove unused variable.
	* mi/mi-main.c (mi_execute_command): Remove unused variable.
	* microblaze-linux-tdep.c (microblaze_linux_sigtramp_cache):
	Remove unused variable.
	* parse.c (find_minsym_type_and_address): Remove unused variable.
	* printcmd.c (info_symbol_command, printf_floating): Remove unused
	variable.
	* python/py-breakpoint.c (bppy_set_commands): Remove unused
	variable.
	* python/py-unwind.c (unwind_infopy_dealloc): Remove unused
	variables.
	* record-btrace.c (record_btrace_target::store_registers): Remove
	unused variable.
	(cmd_show_record_btrace_cpu): Remove unused variable.
	* riscv-tdep.c (riscv_register_reggroup_p)
	(riscv_push_dummy_call, riscv_return_value): Remove unused
	variable.
	* rust-exp.y (literal): Remove unused variable.
	* rust-lang.c (rust_evaluate_subexp) <OP_RUST_ARARAY>: Remove
	unused variable.
	<STRUCTOP_ANONYMOUS>: Likewise.
	* s390-linux-tdep.c (s390_linux_init_abi_31)
	(s390_linux_init_abi_64): Remove unused variable.
	* ser-ming2.c (ser_windows_read_prim, pipe_select_thread)
	(file_select_thread, net_windows_open, _initialize_ser_windows):
	Remove unused variables.
	* symtab.c (find_pc_sect_line): Remove unused variable.
	* target-memory.c (compute_garbled_blocks): Remove unused
	variable.
	(target_write_memory_blocks): Remove unused variable.
	* target.c (target_stack::unpush): Remove unused variables.
	* tracepoint.c (start_tracing, all_tracepoint_actions)
	(merge_uploaded_trace_state_variables)
	(print_one_static_tracepoint_marker): Remove unused variable.
	* unittests/basic_string_view/element_access/char/1.cc (test01):
	Remove unused variable.
	* windows-nat.c (windows_continue, windows_add_all_dlls)
	(do_initial_windows_stuff, windows_nat_target::create_inferior):
	Remove unused variables.
2018-07-22 13:20:01 -06:00
Tom Tromey e99b03dcf4 Remove ptid_get_pid
This removes ptid_get_pid in favor of calling the ptid_t::pid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_pid): Remove.
	* common/ptid.h (ptid_get_pid): Don't declare.
	* aarch64-linux-nat.c: Update.
	* ada-lang.c: Update.
	* aix-thread.c: Update.
	* alpha-bsd-nat.c: Update.
	* amd64-fbsd-nat.c: Update.
	* amd64-linux-nat.c: Update.
	* arm-linux-nat.c: Update.
	* arm-nbsd-nat.c: Update.
	* auxv.c: Update.
	* break-catch-syscall.c: Update.
	* breakpoint.c: Update.
	* bsd-uthread.c: Update.
	* corelow.c: Update.
	* ctf.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* fbsd-tdep.c: Update.
	* gcore.c: Update.
	* gnu-nat.c: Update.
	* hppa-nbsd-nat.c: Update.
	* hppa-obsd-nat.c: Update.
	* i386-fbsd-nat.c: Update.
	* ia64-linux-nat.c: Update.
	* inf-ptrace.c: Update.
	* infcmd.c: Update.
	* inferior.c: Update.
	* inferior.h: Update.
	* inflow.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* m68k-bsd-nat.c: Update.
	* mi/mi-interp.c: Update.
	* mi/mi-main.c: Update.
	* mips-linux-nat.c: Update.
	* mips-nbsd-nat.c: Update.
	* mips64-obsd-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/aarch64-linux.c: Update.
	* nat/linux-btrace.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* ppc-linux-nat.c: Update.
	* ppc-nbsd-nat.c: Update.
	* ppc-obsd-nat.c: Update.
	* proc-service.c: Update.
	* procfs.c: Update.
	* python/py-inferior.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* record.c: Update.
	* remote-sim.c: Update.
	* remote.c: Update.
	* rs6000-nat.c: Update.
	* s390-linux-nat.c: Update.
	* sh-nbsd-nat.c: Update.
	* sol-thread.c: Update.
	* sparc-nat.c: Update.
	* sparc64-tdep.c: Update.
	* spu-linux-nat.c: Update.
	* spu-tdep.c: Update.
	* target-debug.h: Update.
	* target.c: Update.
	* thread.c: Update.
	* tid-parse.c: Update.
	* tracefile-tfile.c: Update.
	* vax-bsd-nat.c: Update.
	* windows-nat.c: Update.
	* x86-linux-nat.c: Update.
	* x86-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-mips-low.c: Update.
	* lynx-low.c: Update.
	* mem-break.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* target.c: Update.
	* tracepoint.c: Update.
2018-07-03 11:36:42 -06:00
Tom Tromey f2907e4991 Remove pid_to_ptid
This removes pid_to_ptid in favor of calling the ptid_t constructor
directly.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (pid_to_ptid): Remove.
	* common/ptid.h (pid_to_ptid): Don't declare.
	* aix-thread.c: Update.
	* arm-linux-nat.c: Update.
	* common/ptid.c: Update.
	* common/ptid.h: Update.
	* corelow.c: Update.
	* ctf.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* fork-child.c: Update.
	* gnu-nat.c: Update.
	* go32-nat.c: Update.
	* inf-ptrace.c: Update.
	* infcmd.c: Update.
	* inferior.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/fork-inferior.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* procfs.c: Update.
	* progspace.c: Update.
	* remote.c: Update.
	* rs6000-nat.c: Update.
	* s390-linux-nat.c: Update.
	* sol-thread.c: Update.
	* spu-linux-nat.c: Update.
	* target.c: Update.
	* top.c: Update.
	* tracefile-tfile.c: Update.
	* windows-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-ppc-low.c: Update.
	* linux-x86-low.c: Update.
	* proc-service.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* thread-db.c: Update.
	* win32-low.c: Update.
2018-07-03 11:36:42 -06:00
Tom Tromey 057302ceb3 Remove exit_inferior_num_silent
The sole caller of exit_inferior_num_silent was getting the inferior's
number to then use the number to look up the inferior again.  I think
it's better to simply not have exit_inferior_num_silent; any potential
callers that only have the inferior's number should probably be
converted to pass the inferior itself around instead.

Tested by the buildbot.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* infrun.c (follow_exec): Use exit_inferior_silent.
	* inferior.c (exit_inferior_num_silent): Remove.
	* inferior.h (exit_inferior_num_silent): Don't declare.
2018-07-03 09:49:30 -06:00
Pedro Alves 00431a78b2 Use thread_info and inferior pointers more throughout
This is more preparation bits for multi-target support.

In a multi-target scenario, we need to address the case of different
processes/threads running on different targets that happen to have the
same PID/PTID.  E.g., we can have both process 123 in target 1, and
process 123 in target 2, while they're in reality different processes
running on different machines.  Or maybe we've loaded multiple
instances of the same core file.  Etc.

To address this, in my WIP multi-target branch, threads and processes
are uniquely identified by the (process_stratum target_ops *, ptid_t)
and (process_stratum target_ops *, pid) tuples respectively.  I.e.,
each process_stratum instance has its own thread/process number space.

As you can imagine, that requires passing around target_ops * pointers
in a number of functions where we're currently passing only a ptid_t
or an int.  E.g., when we look up a thread_info object by ptid_t in
find_thread_ptid, the ptid_t alone isn't sufficient.

In many cases though, we already have the thread_info or inferior
pointer handy, but we "lose" it somewhere along the call stack, only
to look it up again by ptid_t/pid.  Since thread_info or inferior
objects know their parent target, if we pass around thread_info or
inferior pointers when possible, we avoid having to add extra
target_ops parameters to many functions, and also, we eliminate a
number of by ptid_t/int lookups.

So that's what this patch does.  In a bit more detail:

- Changes a number of functions and methods to take a thread_info or
  inferior pointer instead of a ptid_t or int parameter.

- Changes a number of structure fields from ptid_t/int to inferior or
  thread_info pointers.

- Uses the inferior_thread() function whenever possible instead of
  inferior_ptid.

- Uses thread_info pointers directly when possible instead of the
  is_running/is_stopped etc. routines that require a lookup.

- A number of functions are eliminated along the way, such as:

  int valid_gdb_inferior_id (int num);
  int pid_to_gdb_inferior_id (int pid);
  int gdb_inferior_id_to_pid (int num);
  int in_inferior_list (int pid);

- A few structures and places hold a thread_info pointer across
  inferior execution, so now they take a strong reference to the
  (refcounted) thread_info object to avoid the thread_info pointer
  getting stale.  This is done in enable_thread_stack_temporaries and
  in the infcall.c code.

- Related, there's a spot in infcall.c where using a RAII object to
  handle the refcount would be handy, so a gdb::ref_ptr specialization
  for thread_info is added (thread_info_ref, in gdbthread.h), along
  with a gdb_ref_ptr policy that works for all refcounted_object types
  (in common/refcounted-object.h).

gdb/ChangeLog:
2018-06-21  Pedro Alves  <palves@redhat.com>

	* ada-lang.h (ada_get_task_number): Take a thread_info pointer
	instead of a ptid_t.  All callers adjusted.
	* ada-tasks.c (ada_get_task_number): Likewise.  All callers
	adjusted.
	(print_ada_task_info, display_current_task_id, task_command_1):
	Adjust.
	* breakpoint.c (watchpoint_in_thread_scope): Adjust to use
	inferior_thread.
	(breakpoint_kind): Adjust.
	(remove_breakpoints_pid): Rename to ...
	(remove_breakpoints_inf): ... this.  Adjust to take an inferior
	pointer.  All callers adjusted.
	(bpstat_clear_actions): Use inferior_thread.
	(get_bpstat_thread): New.
	(bpstat_do_actions): Use it.
	(bpstat_check_breakpoint_conditions, bpstat_stop_status): Adjust
	to take a thread_info pointer.  All callers adjusted.
	(set_longjmp_breakpoint_for_call_dummy, set_momentary_breakpoint)
	(breakpoint_re_set_thread): Use inferior_thread.
	* breakpoint.h (struct inferior): Forward declare.
	(bpstat_stop_status): Update.
	(remove_breakpoints_pid): Delete.
	(remove_breakpoints_inf): New.
	* bsd-uthread.c (bsd_uthread_target::wait)
	(bsd_uthread_target::update_thread_list): Use find_thread_ptid.
	* btrace.c (btrace_add_pc, btrace_enable, btrace_fetch)
	(maint_btrace_packet_history_cmd)
	(maint_btrace_clear_packet_history_cmd): Adjust.
	(maint_btrace_clear_cmd, maint_info_btrace_cmd): Adjust to use
	inferior_thread.
	* cli/cli-interp.c: Include "inferior.h".
	* common/refcounted-object.h (struct
	refcounted_object_ref_policy): New.
	* compile/compile-object-load.c: Include gdbthread.h.
	(store_regs): Use inferior_thread.
	* corelow.c (core_target::close): Use current_inferior.
	(core_target_open): Adjust to use first_thread_of_inferior and use
	the current inferior.
	* ctf.c (ctf_target::close): Adjust to use current_inferior.
	* dummy-frame.c (dummy_frame_id) <ptid>: Delete, replaced by ...
	<thread>: ... this new field.  All references adjusted.
	(dummy_frame_pop, dummy_frame_discard, register_dummy_frame_dtor):
	Take a thread_info pointer instead of a ptid_t.
	* dummy-frame.h (dummy_frame_push, dummy_frame_pop)
	(dummy_frame_discard, register_dummy_frame_dtor): Take a
	thread_info pointer instead of a ptid_t.
	* elfread.c: Include "inferior.h".
	(elf_gnu_ifunc_resolver_stop, elf_gnu_ifunc_resolver_return_stop):
	Use inferior_thread.
	* eval.c (evaluate_subexp): Likewise.
	* frame.c (frame_pop, has_stack_frames, find_frame_sal): Use
	inferior_thread.
	* gdb_proc_service.h (struct thread_info): Forward declare.
	(struct ps_prochandle) <ptid>: Delete, replaced by ...
	<thread>: ... this new field.  All references adjusted.
	* gdbarch.h, gdbarch.c: Regenerate.
	* gdbarch.sh (get_syscall_number): Replace 'ptid' parameter with a
	'thread' parameter.  All implementations and callers adjusted.
	* gdbthread.h (thread_info) <set_running>: New method.
	(delete_thread, delete_thread_silent): Take a thread_info pointer
	instead of a ptid.
	(global_thread_id_to_ptid, ptid_to_global_thread_id): Delete.
	(first_thread_of_process): Delete, replaced by ...
	(first_thread_of_inferior): ... this new function.  All callers
	adjusted.
	(any_live_thread_of_process): Delete, replaced by ...
	(any_live_thread_of_inferior): ... this new function.  All callers
	adjusted.
	(switch_to_thread, switch_to_no_thread): Declare.
	(is_executing): Delete.
	(enable_thread_stack_temporaries): Update comment.
	<enable_thread_stack_temporaries>: Take a thread_info pointer
	instead of a ptid_t.  Incref the thread.
	<~enable_thread_stack_temporaries>: Decref the thread.
	<m_ptid>: Delete
	<m_thr>: New.
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(get_last_thread_stack_temporary)
	(value_in_thread_stack_temporaries, can_access_registers_thread):
	Take a thread_info pointer instead of a ptid_t.  All callers
	adjusted.
	* infcall.c (get_call_return_value): Use inferior_thread.
	(run_inferior_call): Work with thread pointers instead of ptid_t.
	(call_function_by_hand_dummy): Work with thread pointers instead
	of ptid_t.  Use thread_info_ref.
	* infcmd.c (proceed_thread_callback): Access thread's state
	directly.
	(ensure_valid_thread, ensure_not_running): Use inferior_thread,
	access thread's state directly.
	(continue_command): Use inferior_thread.
	(info_program_command): Use find_thread_ptid and access thread
	state directly.
	(proceed_after_attach_callback): Use thread state directly.
	(notice_new_inferior): Take a thread_info pointer instead of a
	ptid_t.  All callers adjusted.
	(exit_inferior): Take an inferior pointer instead of a pid.  All
	callers adjusted.
	(exit_inferior_silent): New.
	(detach_inferior): Delete.
	(valid_gdb_inferior_id, pid_to_gdb_inferior_id)
	(gdb_inferior_id_to_pid, in_inferior_list): Delete.
	(detach_inferior_command, kill_inferior_command): Use
	find_inferior_id instead of valid_gdb_inferior_id and
	gdb_inferior_id_to_pid.
	(inferior_command): Use inferior and thread pointers.
	* inferior.h (struct thread_info): Forward declare.
	(notice_new_inferior): Take a thread_info pointer instead of a
	ptid_t.  All callers adjusted.
	(detach_inferior): Delete declaration.
	(exit_inferior, exit_inferior_silent): Take an inferior pointer
	instead of a pid.  All callers adjusted.
	(gdb_inferior_id_to_pid, pid_to_gdb_inferior_id, in_inferior_list)
	(valid_gdb_inferior_id): Delete.
	* infrun.c (follow_fork_inferior, proceed_after_vfork_done)
	(handle_vfork_child_exec_or_exit, follow_exec): Adjust.
	(struct displaced_step_inferior_state) <pid>: Delete, replaced by
	...
	<inf>: ... this new field.
	<step_ptid>: Delete, replaced by ...
	<step_thread>: ... this new field.
	(get_displaced_stepping_state): Take an inferior pointer instead
	of a pid.  All callers adjusted.
	(displaced_step_in_progress_any_inferior): Adjust.
	(displaced_step_in_progress_thread): Take a thread pointer instead
	of a ptid_t.  All callers adjusted.
	(displaced_step_in_progress, add_displaced_stepping_state): Take
	an inferior pointer instead of a pid.  All callers adjusted.
	(get_displaced_step_closure_by_addr): Adjust.
	(remove_displaced_stepping_state): Take an inferior pointer
	instead of a pid.  All callers adjusted.
	(displaced_step_prepare_throw, displaced_step_prepare)
	(displaced_step_fixup): Take a thread pointer instead of a ptid_t.
	All callers adjusted.
	(start_step_over): Adjust.
	(infrun_thread_ptid_changed): Remove bit updating ptids in the
	displaced step queue.
	(do_target_resume): Adjust.
	(fetch_inferior_event): Use inferior_thread.
	(context_switch, get_inferior_stop_soon): Take an
	execution_control_state pointer instead of a ptid_t.  All callers
	adjusted.
	(switch_to_thread_cleanup): Delete.
	(stop_all_threads): Use scoped_restore_current_thread.
	* inline-frame.c: Include "gdbthread.h".
	(inline_state) <inline_state>: Take a thread pointer instead of a
	ptid_t.  All callers adjusted.
	<ptid>: Delete, replaced by ...
	<thread>: ... this new field.
	(find_inline_frame_state): Take a thread pointer instead of a
	ptid_t.  All callers adjusted.
	(skip_inline_frames, step_into_inline_frame)
	(inline_skipped_frames, inline_skipped_symbol): Take a thread
	pointer instead of a ptid_t.  All callers adjusted.
	* inline-frame.h (skip_inline_frames, step_into_inline_frame)
	(inline_skipped_frames, inline_skipped_symbol): Likewise.
	* linux-fork.c (delete_checkpoint_command): Adjust to use thread
	pointers directly.
	* linux-nat.c (get_detach_signal): Likewise.
	* linux-thread-db.c (thread_from_lwp): New 'stopped' parameter.
	(thread_db_notice_clone): Adjust.
	(thread_db_find_new_threads_silently)
	(thread_db_find_new_threads_2, thread_db_find_new_threads_1): Take
	a thread pointer instead of a ptid_t.  All callers adjusted.
	* mi/mi-cmd-var.c: Include "inferior.h".
	(mi_cmd_var_update_iter): Update to use thread pointers.
	* mi/mi-interp.c (mi_new_thread): Update to use the thread's
	inferior directly.
	(mi_output_running_pid, mi_inferior_count): Delete, bits factored
	out to ...
	(mi_output_running): ... this new function.
	(mi_on_resume_1): Adjust to use it.
	(mi_user_selected_context_changed): Adjust to use inferior_thread.
	* mi/mi-main.c (proceed_thread): Adjust to use thread pointers
	directly.
	(interrupt_thread_callback): : Adjust to use thread and inferior
	pointers.
	* proc-service.c: Include "gdbthread.h".
	(ps_pglobal_lookup): Adjust to use the thread's inferior directly.
	* progspace-and-thread.c: Include "inferior.h".
	* progspace.c: Include "inferior.h".
	* python/py-exitedevent.c (create_exited_event_object): Adjust to
	hold a reference to an inferior_object.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Adjust to use
	inferior_thread.
	* python/py-inferior.c (struct inferior_object): Give the type a
	tag name instead of a typedef.
	(python_on_normal_stop): No need to check if the current thread is
	listed.
	(inferior_to_inferior_object): Change return type to
	inferior_object.  All callers adjusted.
	(find_thread_object): Delete, bits factored out to ...
	(thread_to_thread_object): ... this new function.
	* python/py-infthread.c (create_thread_object): Use
	inferior_to_inferior_object.
	(thpy_is_stopped): Use thread pointer directly.
	(gdbpy_selected_thread): Use inferior_thread.
	* python/py-record-btrace.c (btpy_list_object) <ptid>: Delete
	field, replaced with ...
	<thread>: ... this new field.  All users adjusted.
	(btpy_insn_or_gap_new): Drop const.
	(btpy_list_new): Take a thread pointer instead of a ptid_t.  All
	callers adjusted.
	* python/py-record.c: Include "gdbthread.h".
	(recpy_insn_new, recpy_func_new): Take a thread pointer instead of
	a ptid_t.  All callers adjusted.
	(gdbpy_current_recording): Use inferior_thread.
	* python/py-record.h (recpy_record_object) <ptid>: Delete
	field, replaced with ...
	<thread>: ... this new field.  All users adjusted.
	(recpy_element_object) <ptid>: Delete
	field, replaced with ...
	<thread>: ... this new field.  All users adjusted.
	(recpy_insn_new, recpy_func_new): Take a thread pointer instead of
	a ptid_t.  All callers adjusted.
	* python/py-threadevent.c: Include "gdbthread.h".
	(get_event_thread): Use thread_to_thread_object.
	* python/python-internal.h (struct inferior_object): Forward
	declare.
	(find_thread_object, find_inferior_object): Delete declarations.
	(thread_to_thread_object, inferior_to_inferior_object): New
	declarations.
	* record-btrace.c: Include "inferior.h".
	(require_btrace_thread): Use inferior_thread.
	(record_btrace_frame_sniffer)
	(record_btrace_tailcall_frame_sniffer): Use inferior_thread.
	(get_thread_current_frame): Use scoped_restore_current_thread and
	switch_to_thread.
	(get_thread_current_frame): Use thread pointer directly.
	(record_btrace_replay_at_breakpoint): Use thread's inferior
	pointer directly.
	* record-full.c: Include "inferior.h".
	* regcache.c: Include "gdbthread.h".
	(get_thread_arch_regcache): Use the inferior's address space
	directly.
	(get_thread_regcache, registers_changed_thread): New.
	* regcache.h (get_thread_regcache(thread_info *thread)): New
	overload.
	(registers_changed_thread): New.
	(remote_target) <remote_detach_1>: Swap order of parameters.
	(remote_add_thread): <remote_add_thread>: Return the new thread.
	(get_remote_thread_info(ptid_t)): New overload.
	(remote_target::remote_notice_new_inferior): Use thread pointers
	directly.
	(remote_target::process_initial_stop_replies): Use
	thread_info::set_running.
	(remote_target::remote_detach_1, remote_target::detach)
	(extended_remote_target::detach): Adjust.
	* stack.c (frame_show_address): Use inferior_thread.
	* target-debug.h (target_debug_print_thread_info_pp): New.
	* target-delegates.c: Regenerate.
	* target.c (default_thread_address_space): Delete.
	(memory_xfer_partial_1): Use current_inferior.
	(target_detach): Use current_inferior.
	(target_thread_address_space): Delete.
	(generic_mourn_inferior): Use current_inferior.
	* target.h (struct target_ops) <thread_address_space>: Delete.
	(target_thread_address_space): Delete.
	* thread.c (init_thread_list): Use ALL_THREADS_SAFE.  Use thread
	pointers directly.
	(delete_thread_1, delete_thread, delete_thread_silent): Take a
	thread pointer instead of a ptid_t.  Adjust all callers.
	(ptid_to_global_thread_id, global_thread_id_to_ptid): Delete.
	(first_thread_of_process): Delete, replaced by ...
	(first_thread_of_inferior): ... this new function.  All callers
	adjusted.
	(any_thread_of_process): Rename to ...
	(any_thread_of_inferior): ... this, and take an inferior pointer.
	(any_live_thread_of_process): Rename to ...
	(any_live_thread_of_inferior): ... this, and take an inferior
	pointer.
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(value_in_thread_stack_temporaries)
	(get_last_thread_stack_temporary): Take a thread pointer instead
	of a ptid_t.  Adjust all callers.
	(thread_info::set_running): New.
	(validate_registers_access): Use inferior_thread.
	(can_access_registers_ptid): Rename to ...
	(can_access_registers_thread): ... this, and take a thread
	pointer.
	(print_thread_info_1): Adjust to compare thread pointers instead
	of ptids.
	(switch_to_no_thread, switch_to_thread): Make extern.
	(scoped_restore_current_thread::~scoped_restore_current_thread):
	Use m_thread pointer directly.
	(scoped_restore_current_thread::scoped_restore_current_thread):
	Use inferior_thread.
	(thread_command): Use thread pointer directly.
	(thread_num_make_value_helper): Use inferior_thread.
	* top.c (execute_command): Use inferior_thread.
	* tui/tui-interp.c: Include "inferior.h".
	* varobj.c (varobj_create): Use inferior_thread.
	(value_of_root_1): Use find_thread_global_id instead of
	global_thread_id_to_ptid.
2018-06-21 17:09:31 +01:00
Tom Tromey a3c25011e4 Fix help and documentation for inferior commands
This changes inferior.c to add Usage lines for all commands, and to
change how "metasyntactic variables" are written to conform to GNU
style.

While doing this I noticed that the manual doesn't document the
argument to "info inferiors", so I've added that as well.

ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* inferior.c (initialize_inferiors): Update help strings.

doc/ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Inferiors and Programs): Document argument to "info
	inferiors".
2018-05-24 12:29:19 -06:00
Sergio Durigan Junior f67c0c9171 Enable 'set print inferior-events' and improve detach/fork/kill/exit messages
This patch aims to turn 'set print inferior-events' always on, and do
some cleanup on the messages printed by GDB when various inferior
events happen (attach, detach, fork, kill, exit).

To make sure that the patch is correct, I've tested it with a handful
of combinations of 'set follow-fork-mode', 'set detach-on-fork' and
'set print inferior-events'.  In the end, I decided to make my
hand-made test into an official testcase.  More on that below.

Using the following program as an example:

  #include <unistd.h>
  int main ()
  {
    fork ();
    return 0;
  }

We see the following outputs from the patched GDB:

- With 'set print inferior-events on':

    (gdb) r
    Starting program: a.out
    [Detaching after fork from child process 27749]
    [Inferior 1 (process 27745) exited normally]
    (gdb)

- With 'set print inferior-events off':

    (gdb) r
    Starting program: a.out
    [Inferior 1 (process 27823) exited normally]
    (gdb)

  Comparing this against an unpatched GDB:

- With 'set print inferior-events off' and 'set follow-fork-mode
  child':

    (gdb) r
    Starting program: a.out
    [Inferior 2 (process 5993) exited normally]
    (gdb)

  Compare this against an unpatched GDB:

    (unpatched-gdb) r
    Starting program: a.out
    [New process 5702]
    [Inferior 2 (process 5702) exited normally]
    (unpatched-gdb)

  It is possible to notice that, in this scenario, the patched GDB
  will lose the '[New process %d]' message.

- With 'set print inferior-events on', 'set follow-fork-mode child'
  and 'set detach-on-fork on':

    (gdb) r
    Starting program: a.out
    [Attaching after process 27905 fork to child process 27909]
    [New inferior 2 (process 27909)]
    [Detaching after fork from parent process 27905]
    [Inferior 1 (process 27905) detached]
    [Inferior 2 (process 27909) exited normally]
    (gdb)

  Compare this output with an unpatched GDB, using the same settings:

    (unpatched-gdb) r
    Starting program: a.out
    [New inferior 28033]
    [Inferior 28029 detached]
    [New process 28033]
    [Inferior 2 (process 28033) exited normally]
    [Inferior 28033 exited]
    (unpatched-gdb)

As can be seen above, I've also made a few modifications to messages
that are printed when 'set print inferior-events' is on.  For example,
a few of the messages did not contain the '[' and ']' as
prefix/suffix, which led to a few inconsistencies like:

  Attaching after process 22995 fork to child process 22999.
  [New inferior 22999]
  Detaching after fork from child process 22999.
  [Inferior 22995 detached]
  [Inferior 2 (process 22999) exited normally]

So I took the opportunity and included the square brackets where
applicable.  I have also made the existing messages more uniform, by
always printing "Inferior %d (process %d)..." where applicable.  This
makes it easier to identify the inferior number and the PID number
from the messages.

As suggested by Pedro, the "[Inferior %d exited]" message from
'exit_inferior' has been removed, because it got duplicated when
'inferior-events' is on.  I'm also using the
'add_{thread,inferior}_silent' versions (instead of their verbose
counterparts) on some locations, also to avoid duplicated messages.
For example, a patched GDB with 'set print inferior-events on', 'set
detach-on-fork on' and 'set follow-fork-mode child', but using
'add_thread', would print:

  (gdb) run
  Starting program: a.out
  [Attaching after process 25088 fork to child process 25092.]
  [New inferior 25092]   <--- duplicated
  [Detaching after fork from child process 25092.]
  [Inferior 25088 detached]
  [New process 25092]    <--- duplicated
  [Inferior 2 (process 25092) exited normally]

But if we use 'add_thread_silent' (with the same configuration as
before):

  (gdb) run
  Starting program: a.out
  [Attaching after process 31606 fork to child process 31610]
  [New inferior 2 (process 31610)]
  [Detaching after fork from parent process 31606]
  [Inferior 1 (process 31606) detached]
  [Inferior 2 (process 31610) exited normally]

As for the tests, the configuration options being exercised are:

- follow-fork-mode: child/parent
- detach-on-fork: on/off
- print inferior-events: on/off

It was also necessary to perform adjustments on several testcases,
because the expected messages changed considerably.

Built and regtested on BuildBot, without regressions.

gdb/ChangeLog:
2018-04-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* infcmd.c (kill_command): Print message when inferior has
	been killed.
	* inferior.c (print_inferior_events): Remove 'static'.  Set as
	'1'.
	(add_inferior): Improve message printed when
	'print_inferior_events' is on.
	(exit_inferior): Remove message printed when
	'print_inferior_events' is on.
	(detach_inferior): Improve message printed when
	'print_inferior_events' is on.
	(initialize_inferiors): Use 'add_inferior_silent' to set
	'current_inferior_'.
	* inferior.h (print_inferior_events): Declare here as
	'extern'.
	* infrun.c (follow_fork_inferior): Print '[Attaching...]' or
	'[Detaching...]' messages when 'print_inferior_events' is on.
	Use 'add_thread_silent' instead of 'add_thread'.  Add '[' and ']'
	as prefix/suffix for messages.  Remove periods.  Fix erroneous
	'Detaching after fork from child...', replace it by '... from
	parent...'.
	(handle_vfork_child_exec_or_exit): Add '[' and ']' as
	prefix/suffix when printing 'Detaching...' messages.  Print
	them when 'print_inferior_events' is on.
	* remote.c (remote_detach_1): Print message when detaching
	from inferior and '!is_fork_parent'.

gdb/testsuite/ChangeLog:
2018-04-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/attach-non-pgrp-leader.exp: Adjust 'Detaching...'
	regexps to expect for '[Inferior ... detached]' as well.
	* gdb.base/attach.exp: Likewise.
	* gdb.base/catch-syscall.exp (check_for_program_end): Adjust
	"gdb_continue_to_end".
	(test_catch_syscall_with_wrong_args): Likewise.
	* gdb.base/foll-fork.exp: Adjust regexps to match '[' and
	']'.  Don't set 'verbose' on.
	* gdb.base/foll-vfork.exp: Likewise.
	* gdb.base/fork-print-inferior-events.c: New file.
	* gdb.base/fork-print-inferior-events.exp: New file.
	* gdb.base/hook-stop.exp: Adjust regexps to expect for new
	'[Inferior ... has been killed]' message.
	* gdb.base/kill-after-signal.exp: Likewise.
	* gdb.base/solib-overlap.exp: Adjust regexps to expect for new
	detach message.
	* gdb.threads/kill.exp: Adjust regexps to expect for new kill
	message.
	* gdb.threads/clone-attach-detach.exp: Adjust 'Detaching...'
	regexps to expect for '[Inferior ... detached]' as well.
	* gdb.threads/process-dies-while-detaching.exp: Likewise.
2018-04-24 15:46:15 -04:00
Tom Tromey 76727919ce Convert observers to C++
This converts observers from using a special source-generating script
to be plain C++.  This version of the patch takes advantage of C++11
by using std::function and variadic templates; incorporates Pedro's
patches; and renames the header file to "observable.h" (this change
eliminates the need for a clean rebuild).

Note that Pedro's patches used a template lambda in tui-hooks.c, but
this failed to compile on some buildbot instances (presumably due to
differing C++ versions); I replaced this with an ordinary template
function.

Regression tested on the buildbot.

gdb/ChangeLog
2018-03-19  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* unittests/observable-selftests.c: New file.
	* common/observable.h: New file.
	* observable.h: New file.
	* ada-lang.c, ada-tasks.c, agent.c, aix-thread.c, annotate.c,
	arm-tdep.c, auto-load.c, auxv.c, break-catch-syscall.c,
	breakpoint.c, bsd-uthread.c, cli/cli-interp.c, cli/cli-setshow.c,
	corefile.c, dummy-frame.c, event-loop.c, event-top.c, exec.c,
	extension.c, frame.c, gdbarch.c, guile/scm-breakpoint.c,
	infcall.c, infcmd.c, inferior.c, inflow.c, infrun.c, jit.c,
	linux-tdep.c, linux-thread-db.c, m68klinux-tdep.c,
	mi/mi-cmd-break.c, mi/mi-interp.c, mi/mi-main.c, objfiles.c,
	ppc-linux-nat.c, ppc-linux-tdep.c, printcmd.c, procfs.c,
	python/py-breakpoint.c, python/py-finishbreakpoint.c,
	python/py-inferior.c, python/py-unwind.c, ravenscar-thread.c,
	record-btrace.c, record-full.c, record.c, regcache.c, remote.c,
	riscv-tdep.c, sol-thread.c, solib-aix.c, solib-spu.c, solib.c,
	spu-multiarch.c, spu-tdep.c, stack.c, symfile-mem.c, symfile.c,
	symtab.c, thread.c, top.c, tracepoint.c, tui/tui-hooks.c,
	tui/tui-interp.c, valops.c: Update all users.
	* tui/tui-hooks.c (tui_bp_created_observer)
	(tui_bp_deleted_observer, tui_bp_modified_observer)
	(tui_inferior_exit_observer, tui_before_prompt_observer)
	(tui_normal_stop_observer, tui_register_changed_observer):
	Remove.
	(tui_observers_token): New global.
	(attach_or_detach, tui_attach_detach_observers): New functions.
	(tui_install_hooks, tui_remove_hooks): Use
	tui_attach_detach_observers.
	* record-btrace.c (record_btrace_thread_observer): Remove.
	(record_btrace_thread_observer_token): New global.
	* observer.sh: Remove.
	* observer.c: Rename to observable.c.
	* observable.c (namespace gdb_observers): Define new objects.
	(observer_debug): Move into gdb_observers namespace.
	(struct observer, struct observer_list, xalloc_observer_list_node)
	(xfree_observer_list_node, generic_observer_attach)
	(generic_observer_detach, generic_observer_notify): Remove.
	(_initialize_observer): Update.
	Don't include observer.inc.
	* Makefile.in (generated_files): Remove observer.h, observer.inc.
	(clean mostlyclean): Likewise.
	(observer.h, observer.inc): Remove targets.
	(SUBDIR_UNITTESTS_SRCS): Add observable-selftests.c.
	(COMMON_SFILES): Use observable.c, not observer.c.
	* .gitignore: Remove observer.h.

gdb/doc/ChangeLog
2018-03-19  Tom Tromey  <tom@tromey.com>

	* observer.texi: Remove.

gdb/testsuite/ChangeLog
2018-03-19  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/observer.exp: Remove.
2018-03-19 09:37:49 -06:00
Simon Marchi 564b1e3f29 C++ify program_space
This patch makes program_space a C++ object by adding a
constructor/destructor, giving default values to fields, and using
new/delete.

gdb/ChangeLog:

	* progspace.h (struct program_space): Add constructor and
	destructor, initialize fields.
	(add_program_space): Remove.
	* progspace.c (add_program_space): Rename to...
	(program_space::program_space): ... this.
	(release_program_space): Rename to...
	(program_space::~program_space): ... this.
	(delete_program_space): Use delete to delete program_space.
	(initialize_progspace): Use new to allocate program_space.
	* inferior.c (add_inferior_with_spaces): Likewise.
	(clone_inferior_command): Likewise.
	* infrun.c (follow_fork_inferior): Likewise.
	(handle_vfork_child_exec_or_exit): Likewise.
2018-03-02 23:22:08 -05:00
Yao Qi 85046ae23f Reset inferior::control on inferior exit
When we kill an inferior, the inferior is not deleted.  What is more, it
is reused when the new process is created, so we need to reset inferior's
state when it exits.

gdb:

2018-02-15  Yao Qi  <yao.qi@linaro.org>

	PR gdb/22849
	* inferior.c (exit_inferior_1): Reset inf->control.
2018-02-15 14:48:30 +00:00
Simon Marchi bc09b0c14f Make linux_nat_detach/thread_db_detach use the inferior parameter
This patch makes these two functions actually use the inferior parameter
added by the previous patch, instead of reading inferior_ptid.  I chose
these two, because they are the one actually used when I detach on my
GNU/Linux system, so they were easy to test.

I took the opportunity to pass the inferior being detached to
inf_ptrace_detach_success, so it could use it too.  From there, it made
sense to add an overload of detach_inferior that takes the inferior
directly rather than the pid, to avoid having to pass inf->pid only for
the callee to look up the inferior structure by pid.

gdb/ChangeLog:

	* inf-ptrace.c (inf_ptrace_detach): Adjust call to
	inf_ptrace_detach_success.
	(inf_ptrace_detach_success): Add inferior parameter, use it
	instead of inferior_ptid, pass it to detach_inferior.
	* inf-ptrace.h (inf_ptrace_detach_success): Add inferior
	parameter.
	* inferior.c (detach_inferior): Add overload that takes an
	inferior object.
	* inferior.h (detach_inferior): Likewise.
	* linux-nat.c (linux_nat_detach): Use the inf parameter, don't
	use inferior_ptid, adjust call to inf_ptrace_detach_success.
	* linux-thread-db.c (thread_db_detach): Use inf parameter.
2018-01-19 11:48:11 -05:00
Joel Brobecker e2882c8578 Update copyright year range in all GDB files
gdb/ChangeLog:

        Update copyright year range in all GDB files
2018-01-02 07:38:06 +04:00
Simon Marchi 089354bb06 Create private_inferior class hierarchy
There are currently multiple definitions of private_inferior, defined in
remote.c and darwin-nat.h.  The patch that poisons XNEW and friends for
non-POD types trips on that, because private_inferior is freed in
~inferior(), where it is an opaque type.  Since the compiler can't tell
whether the type is POD, it gives an error.  Also, we can't start using
C++ features in these structures (make them non-POD) as long as there
are multiple definitions with the same name.  For these reasons, this
patch makes a class hierarchy, with private_inferior being the abstract
base class, and darwin_inferior & remote_inferior inheriting from it.
Destruction is done through the virtual destructor.

I stumbled on some suspicious code in the darwin implementation though.
darwin_check_new_threads does an XCNEW(darwin_thread_t) when it finds a
new thread, allocating a new structure for it (darwin_thread_t is a
typedef for private_thread_info).  It then VEC_safe_pushes it in a
vector defined as DEF_VEC_O (a vector of objects).  This means that the
structure content gets copied in the vector.  The thread_info object is
created with the XCNEW'ed structure as the private thread info, while
the rest of the code works with the instance in the vector.  We have
therefore two distinct instances of darwin_thread_t/private_thread_info
for each thread.  This is not really a problem in practice, because
thread_info::priv is not used in the darwin code.  I still find it weird
and far from ideal, so I tried to fix it by changing the vector to be a
vector of pointers.  There should now be a single instance of the
structure for each thread.  The deallocation of the
darwin_thread_t/private_thread_info structure is done by the thread_info
destructor.

I am able to build on macOS, but not really test, since the port seems a
bit broken.  I am not able to debug reliably on the machine I have
access to, which runs macOS 10.12.6.

gdb/ChangeLog:

	* inferior.h (private_inferior): Define structure type, add
	virtual pure destructor.
	(inferior) <priv>: Change type to unique_ptr.
	* inferior.c (private_inferior::~private_inferior): Provide
	default implementation.
	(inferior::~inferior): Don't free priv field.
	(exit_inferior_1): Likewise.
	* darwin-nat.h (struct darwin_exception_info): Initialize fields.
	(darwin_exception_info): Remove typedef.
	(DEF_VEC_O (darwin_thread_t)); Remove.
	(private_inferior): Rename to ...
	(darwin_private_inferior): ... this, extend private_inferior.
	(get_darwin_inferior): New.
	<threads>: Change type to std::vector of darwin_thread_t pointers.
	* darwin-nat.c (darwin_check_new_threads): Adjust.
	(find_inferior_task_it): Adjust.
	(darwin_find_thread); Adjust.
	(darwin_suspend_inferior): Adjust.
	(darwin_resume_inferior): Adjust.
	(darwin_find_new_inferior): Adjust.
	(darwin_decode_notify_message): Adjust.
	(darwin_send_reply): Adjust.
	(darwin_resume_inferior_threads): Adjust.
	(darwin_suspend_inferior_threads): Adjust.
	(darwin_decode_message): Adjust.
	(darwin_wait): Adjust.
	(darwin_interrupt): Adjust.
	(darwin_deallocate_threads): Adjust.
	(darwin_mourn_inferior): Adjust, don't free private data.
	(darwin_reply_to_all_pending_messages): Adjust.
	(darwin_stop_inferior): Adjust.
	(darwin_setup_exceptions): Adjust.
	(darwin_kill_inferior): Adjust.
	(darwin_setup_request_notification): Adjust.
	(darwin_attach_pid): Adjust.
	(darwin_init_thread_list): Adjust.
	(darwin_setup_fake_stop_event): Adjust.
	(darwin_attach): Adjust.
	(darwin_detach): Adjust.
	(darwin_xfer_partial): Adjust.
	(set_enable_mach_exceptions): Adjust.
	(darwin_pid_to_exec_file): Adjust.
	(darwin_get_ada_task_ptid): Adjust.
	* darwin-nat-info.c (get_task_from_args): Adjust.
	(info_mach_ports_command): Adjust.
	(info_mach_region_command): Adjust.
	(info_mach_exceptions_command): Adjust.
	* remote.c (private_inferior): Rename to ...
	(remote_private_inferior): ... this, initialize fields.
	(get_remote_inferior); New.
	(remote_commit_resume): Use get_remote_inferior.
	(check_pending_event_prevents_wildcard_vcont_callback): Likewise.
2017-11-24 10:39:31 -05:00
Tom Tromey 1d12d88f18 Constify add_info
This patch constifies add_info and updates all the info commands.  The
bulk of this patch was written using a script; and then I did a manual
pass to fix up the remaining compilation errors.

I could not compile every changed file; in particular nto-procfs.c,
gnu-nat.c, and darwin-nat-info.c; but I at least tried to check the
correctness by inspection.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* frame.h (info_locals_command, info_args_command): Constify.
	* auto-load.h (auto_load_info_scripts): Constify.
	* inferior.h (registers_info): Constify.
	* copying.c: Rebuild.
	* copying.awk: Constify generated commands.
	* auto-load.c (auto_load_info_scripts)
	(info_auto_load_gdb_scripts): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Take a
	cmd_const_cfunc_ftype.
	* command.h (add_info): Take a cmd_const_cfunc_ftype.
	* tui/tui-win.c (tui_all_windows_info): Constify.
	* python/py-auto-load.c (info_auto_load_python_scripts):
	Constify.
	* cli/cli-cmds.c (show_command): Remove non-const overload.
	* tracepoint.c (info_tvariables_command, info_scope_command):
	Constify.
	(info_static_tracepoint_markers_command): Constify.
	* thread.c (info_threads_command): Constify.
	(print_thread_info_1): Constify.
	* target.c (info_target_command): Constify.
	* symtab.c (info_sources_command, info_functions_command)
	(info_types_command): Constify.
	(info_variables_command): Remove non-const overload.
	* symfile.c (info_ext_lang_command): Constify.
	* stack.c (info_frame_command, info_locals_command)
	(info_args_command): Constify.
	(backtrace_command): Remove non-const overload.
	* source.c (info_source_command, info_line_command): Constify.
	* solib.c (info_sharedlibrary_command): Constify.
	* skip.c (info_skip_command): Constify.
	* ser-go32.c (info_serial_command): Constify.
	* reverse.c (info_bookmarks_command): Constify.
	* printcmd.c (info_symbol_command, info_address_command)
	(info_display_command): Constify.
	* osdata.c (info_osdata_command): Constify.
	* objc-lang.c (info_selectors_command, info_classes_command):
	Constify.
	* nto-procfs.c (procfs_pidlist, procfs_meminfo): Constify.
	* memattr.c (info_mem_command): Constify.
	* macrocmd.c (info_macro_command, info_macros_command): Constify.
	* linux-fork.c (info_checkpoints_command): Constify.
	* infrun.c (info_signals_command): Constify.
	* inflow.c (info_terminal_command): Constify.
	* inferior.c (info_inferiors_command): Constify.
	(print_inferior): Constify.
	* infcmd.c (info_program_command, info_all_registers_command)
	(info_registers_command, info_vector_command)
	(info_float_command): Constify.
	(registers_info): Constify.
	* gnu-nat.c (info_send_rights_cmd, info_recv_rights_cmd)
	(info_port_sets_cmd, info_dead_names_cmd, info_port_rights_cmd):
	Constify.
	* f-valprint.c (info_common_command): Constify.
	* dcache.c (info_dcache_command): Constify.
	(dcache_info_1): Constify.
	* darwin-nat-info.c (info_mach_tasks_command)
	(info_mach_task_command, info_mach_ports_command)
	(info_mach_port_command, info_mach_threads_command)
	(info_mach_thread_command, info_mach_regions_command)
	(info_mach_regions_recurse_command, info_mach_region_command)
	(info_mach_exceptions_command): Constify.
	(get_task_from_args): Constify.
	* cp-support.c (info_vtbl_command): Constify.
	* breakpoint.c (info_watchpoints_command)
	(info_tracepoints_command): Constify.
	(info_breakpoints_command): Remove non-const overload.
	* avr-tdep.c (avr_io_reg_read_command): Constify.
	* auxv.c (info_auxv_command): Constify.
	* ada-tasks.c (info_tasks_command): Constify.
	(info_task): Constify.
	* ada-lang.c (info_exceptions_command): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 0b39b52e6e Constify add_com
This changes add_com to take a cmd_const_cfunc_ftype, and then fixes
up all the command implementations.

In most cases this is trivial.

In a couple of places I had to again introduce a temporary non-const
overload.  These overloads will be removed when add_info is
constified.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* solib.h (no_shared_libraries): Constify.
	* frame.h (return_command): Constify.
	* cli/cli-cmds.h (quit_command): Constify.
	* top.h (quit_command, execute_command): Constify.
	* target.h (flash_erase_command): Constify.
	* inferior.h (set_inferior_args, attach_command): Constify.
	* tracepoint.h (start_tracing, stop_tracing): Constify.
	* breakpoint.h (break_command, tbreak_command)
	(hbreak_command_wrapper, thbreak_command_wrapper)
	(rbreak_command_wrapper, watch_command_wrapper)
	(awatch_command_wrapper, rwatch_command_wrapper)
	(get_tracepoint_by_number): Constify.
	* symtab.c (info_variables_command, rbreak_command)
	(symtab_symbol_info): Constify.
	(info_variables_command): Add non-const overload.
	* top.c (dont_repeat_command): Constify.
	* breakpoint.c (ignore_command, commands_command)
	(condition_command, tbreak_command, hbreak_command)
	(thbreak_command, clear_command, break_command)
	(info_breakpoints_command, watch_command, rwatch_command)
	(awatch_command, trace_command, ftrace_command, strace_command)
	(trace_pass_command, break_range_command, dprintf_command)
	(agent_printf_command, get_tracepoint_by_number)
	(watch_maybe_just_location, trace_pass_command): Constify.
	(info_breakpoints_command): Add non-const overload.
	* tracefile.c (tsave_command): Constify.
	* infcmd.c (attach_command, disconnect_command, signal_command)
	(queue_signal_command, stepi_command, nexti_command)
	(finish_command, next_command, step_command, until_command)
	(advance_command, jump_command, continue_command, run_command)
	(start_command, starti_command, interrupt_command)
	(run_command_1, set_inferior_args, step_1): Constify.
	* inferior.c (add_inferior_command, remove_inferior_command)
	(clone_inferior_command): Constify.
	* linux-fork.c (checkpoint_command, restart_command): Constify.
	* windows-nat.c (signal_event_command): Constify.
	* guile/guile.c (guile_repl_command, guile_command): Constify.
	* printcmd.c (x_command, display_command, printf_command)
	(output_command, set_command, call_command, print_command)
	(eval_command): Constify.
	(non_const_set_command): Remove.
	(_initialize_printcmd): Update.
	* source.c (forward_search_command, reverse_search_command):
	Constify.
	* jit.c (jit_reader_load_command, jit_reader_unload_command):
	Constify.
	* infrun.c (handle_command): Constify.
	* memattr.c (mem_command): Constify.
	* stack.c (return_command, up_command, up_silently_command)
	(down_command, down_silently_command, frame_command)
	(backtrace_command, func_command, backtrace_command_1): Constify.
	(backtrace_command): Add non-const overload.
	* remote-sim.c (simulator_command): Constify.
	* exec.c (set_section_command): Constify.
	* tracepoint.c (tdump_command, trace_variable_command)
	(tstatus_command, tstop_command, tstart_command)
	(end_actions_pseudocommand, while_stepping_pseudocommand)
	(collect_pseudocommand, teval_pseudocommand, actions_command)
	(start_tracing, stop_tracing): Constify.
	* value.c (init_if_undefined_command): Constify.
	* tui/tui-stack.c (tui_update_command): Constify.
	* tui/tui-win.c (tui_refresh_all_command)
	(tui_set_tab_width_command, tui_set_win_height_command)
	(tui_set_focus_command, tui_scroll_forward_command)
	(tui_scroll_backward_command, tui_scroll_left_command)
	(tui_scroll_right_command, parse_scrolling_args, tui_set_focus)
	(tui_set_win_height): Constify.
	* tui/tui-layout.c (tui_layout_command): Constify.
	* procfs.c (proc_trace_syscalls, proc_trace_sysentry_cmd)
	(proc_trace_sysexit_cmd, proc_untrace_sysentry_cmd)
	(proc_untrace_sysexit_cmd): Constify.
	* remote.c (threadlist_test_cmd, threadinfo_test_cmd)
	(threadset_test_cmd, threadlist_update_test_cmd)
	(threadalive_test): Constify.
	* objc-lang.c (print_object_command): Constify.
	* command.h (add_com): Constify.
	* cli/cli-dump.c (restore_command): Constify.
	* cli/cli-cmds.c (pwd_command, echo_command, quit_command)
	(help_command, complete_command, shell_command, edit_command)
	(list_command, disassemble_command, make_command)
	(apropos_command, alias_command): Constify.
	* cli/cli-script.c (document_command, define_command)
	(while_command, if_command, validate_comname): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Change type of
	"fun".
	* target.c (do_monitor_command, flash_erase_command): Constify.
	* regcache.c (reg_flush_command): Constify.
	* reverse.c (reverse_step, reverse_next, reverse_stepi)
	(reverse_nexti, reverse_continue, reverse_finish)
	(save_bookmark_command, goto_bookmark_command)
	(exec_reverse_once): Constify.
	* python/python.c (python_interactive_command, python_command):
	Constify.
	* typeprint.c (ptype_command, whatis_command, whatis_exp):
	Constify.
	* solib.c (sharedlibrary_command, no_shared_libraries): Constify.
	* gcore.c (gcore_command): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey e503b1919b Constify some commands in inferior.c
gdb/ChangeLog
2017-09-27  Tom Tromey  <tom@tromey.com>

	* inferior.c (detach_inferior_command, kill_inferior_command)
	(inferior_command): Constify.
2017-09-27 08:45:08 -06:00
John Baldwin 481695ed5f Remove unnecessary function prototypes.
These prototypes were required when compiling GDB as C but are not
required for C++.

gdb/ChangeLog:

	* aarch64-linux-nat.c: Remove _initialize_aarch64_linux_nat
	prototype.
	* aarch64-linux-tdep.c: Remove _initialize_aarch64_linux_tdep
	prototype.
	* aarch64-newlib-tdep.c: Remove _initialize_aarch64_newlib_tdep
	prototype.
	* aarch64-tdep.c: Remove _initialize_aarch64_tdep prototype.
	* ada-exp.y: Remove _initialize_ada_exp prototype.
	* ada-lang.c: Remove _initialize_ada_language prototype.
	* ada-tasks.c: Remove _initialize_tasks prototype.
	* addrmap.c: Remove _initialize_addrmap prototype.
	* agent.c: Remove _initialize_agent prototype.
	* aix-thread.c: Remove _initialize_aix_thread prototype.
	* alpha-bsd-nat.c: Remove _initialize_alphabsd_nat prototype.
	* alpha-linux-nat.c: Remove _initialize_alpha_linux_nat prototype.
	* alpha-linux-tdep.c: Remove _initialize_alpha_linux_tdep
	prototype.
	* alpha-nbsd-tdep.c: Remove _initialize_alphanbsd_tdep prototype.
	* alpha-obsd-tdep.c: Remove _initialize_alphaobsd_tdep prototype.
	* alpha-tdep.c: Remove _initialize_alpha_tdep prototype.
	* amd64-darwin-tdep.c: Remove _initialize_amd64_darwin_tdep
	prototype.
	* amd64-dicos-tdep.c: Remove _initialize_amd64_dicos_tdep
	prototype.
	* amd64-fbsd-nat.c: Remove _initialize_amd64fbsd_nat prototype.
	* amd64-fbsd-tdep.c: Remove _initialize_amd64fbsd_tdep prototype.
	* amd64-linux-nat.c: Remove _initialize_amd64_linux_nat prototype.
	* amd64-linux-tdep.c: Remove _initialize_amd64_linux_tdep
	prototype.
	* amd64-nbsd-nat.c: Remove _initialize_amd64nbsd_nat prototype.
	* amd64-nbsd-tdep.c: Remove _initialize_amd64nbsd_tdep prototype.
	* amd64-obsd-nat.c: Remove _initialize_amd64obsd_nat prototype.
	* amd64-obsd-tdep.c: Remove _initialize_amd64obsd_tdep prototype.
	* amd64-sol2-tdep.c: Remove _initialize_amd64_sol2_tdep prototype.
	* amd64-tdep.c: Remove _initialize_amd64_tdep prototype.
	* amd64-windows-nat.c: Remove _initialize_amd64_windows_nat
	prototype.
	* amd64-windows-tdep.c: Remove _initialize_amd64_windows_tdep
	prototype.
	* annotate.c: Remove _initialize_annotate prototype.
	* arc-newlib-tdep.c: Remove _initialize_arc_newlib_tdep prototype.
	* arc-tdep.c: Remove _initialize_arc_tdep prototype.
	* arch-utils.c: Remove _initialize_gdbarch_utils prototype.
	* arm-linux-nat.c: Remove _initialize_arm_linux_nat prototype.
	* arm-linux-tdep.c: Remove _initialize_arm_linux_tdep prototype.
	* arm-nbsd-tdep.c: Remove _initialize_arm_netbsd_tdep prototype.
	* arm-obsd-tdep.c: Remove _initialize_armobsd_tdep prototype.
	* arm-symbian-tdep.c: Remove _initialize_arm_symbian_tdep
	prototype.
	* arm-tdep.c: Remove _initialize_arm_tdep prototype.
	* arm-wince-tdep.c: Remove _initialize_arm_wince_tdep prototype.
	* auto-load.c: Remove _initialize_auto_load prototype.
	* auxv.c: Remove _initialize_auxv prototype.
	* avr-tdep.c: Remove _initialize_avr_tdep prototype.
	* ax-gdb.c: Remove _initialize_ax_gdb prototype.
	* bfin-linux-tdep.c: Remove _initialize_bfin_linux_tdep prototype.
	* bfin-tdep.c: Remove _initialize_bfin_tdep prototype.
	* break-catch-sig.c: Remove _initialize_break_catch_sig prototype.
	* break-catch-syscall.c: Remove _initialize_break_catch_syscall
	prototype.
	* break-catch-throw.c: Remove _initialize_break_catch_throw
	prototype.
	* breakpoint.c: Remove _initialize_breakpoint prototype.
	* bsd-uthread.c: Remove _initialize_bsd_uthread prototype.
	* btrace.c: Remove _initialize_btrace prototype.
	* charset.c: Remove _initialize_charset prototype.
	* cli/cli-cmds.c: Remove _initialize_cli_cmds prototype.
	* cli/cli-dump.c: Remove _initialize_cli_dump prototype.
	* cli/cli-interp.c: Remove _initialize_cli_interp prototype.
	* cli/cli-logging.c: Remove _initialize_cli_logging prototype.
	* cli/cli-script.c: Remove _initialize_cli_script prototype.
	* coff-pe-read.c: Remove _initialize_coff_pe_read prototype.
	* coffread.c: Remove _initialize_coffread prototype.
	* compile/compile.c: Remove _initialize_compile prototype.
	* complaints.c: Remove _initialize_complaints prototype.
	* completer.c: Remove _initialize_completer prototype.
	* copying.awk: Remove _initialize_copying prototype.
	* copying.c: Regenerate.
	* core-regset.c: Remove _initialize_core_regset prototype.
	* corefile.c: Remove _initialize_core prototype.
	* corelow.c: Remove _initialize_corelow prototype.
	* cp-abi.c: Remove _initialize_cp_abi prototype.
	* cp-namespace.c: Remove _initialize_cp_namespace prototype.
	* cp-support.c: Remove _initialize_cp_support prototype.
	* cp-valprint.c: Remove _initialize_cp_valprint prototype.
	* cris-linux-tdep.c: Remove _initialize_cris_linux_tdep prototype.
	* cris-tdep.c: Remove _initialize_cris_tdep prototype.
	* ctf.c: Remove _initialize_ctf prototype.
	* d-lang.c: Remove _initialize_d_language prototype.
	* darwin-nat-info.c: Remove _initialize_darwin_info_commands
	prototype.
	* darwin-nat.c: Remove _initialize_darwin_inferior prototype.
	* dbxread.c: Remove _initialize_dbxread prototype.
	* dcache.c: Remove _initialize_dcache prototype.
	* demangle.c: Remove _initialize_demangler prototype.
	* disasm-selftests.c: Remove _initialize_disasm_selftests
	prototype.
	* disasm.c: Remove _initialize_disasm prototype.
	* dtrace-probe.c: Remove _initialize_dtrace_probe prototype.
	* dummy-frame.c: Remove _initialize_dummy_frame prototype.
	* dwarf2-frame-tailcall.c: Remove _initialize_tailcall_frame
	prototype.
	* dwarf2-frame.c: Remove _initialize_dwarf2_frame prototype.
	* dwarf2expr.c: Remove _initialize_dwarf2expr prototype.
	* dwarf2loc.c: Remove _initialize_dwarf2loc prototype.
	* dwarf2read.c: Remove _initialize_dwarf2_read prototype.
	* elfread.c: Remove _initialize_elfread prototype.
	* exec.c: Remove _initialize_exec prototype.
	* extension.c: Remove _initialize_extension prototype.
	* f-lang.c: Remove _initialize_f_language prototype.
	* f-valprint.c: Remove _initialize_f_valprint prototype.
	* fbsd-nat.c: Remove _initialize_fbsd_nat prototype.
	* fbsd-tdep.c: Remove _initialize_fbsd_tdep prototype.
	* filesystem.c: Remove _initialize_filesystem prototype.
	* findcmd.c: Remove _initialize_mem_search prototype.
	* fork-child.c: Remove _initialize_fork_child prototype.
	* frame-base.c: Remove _initialize_frame_base prototype.
	* frame-unwind.c: Remove _initialize_frame_unwind prototype.
	* frame.c: Remove _initialize_frame prototype.
	* frv-linux-tdep.c: Remove _initialize_frv_linux_tdep prototype.
	* frv-tdep.c: Remove _initialize_frv_tdep prototype.
	* ft32-tdep.c: Remove _initialize_ft32_tdep prototype.
	* gcore.c: Remove _initialize_gcore prototype.
	* gdb_bfd.c: Remove _initialize_gdb_bfd prototype.
	* gdbarch.c: Regenerate.
	* gdbarch.sh: Remove _initialize_gdbarch prototype.
	* gdbtypes.c: Remove _initialize_gdbtypes prototype.
	* gnu-nat.c: Remove _initialize_gnu_nat prototype.
	* gnu-v2-abi.c: Remove _initialize_gnu_v2_abi prototype.
	* gnu-v3-abi.c: Remove _initialize_gnu_v3_abi prototype.
	* go-lang.c: Remove _initialize_go_language prototype.
	* go32-nat.c: Remove _initialize_go32_nat prototype.
	* guile/guile.c: Remove _initialize_guile prototype.
	* h8300-tdep.c: Remove _initialize_h8300_tdep prototype.
	* hppa-linux-nat.c: Remove _initialize_hppa_linux_nat prototype.
	* hppa-linux-tdep.c: Remove _initialize_hppa_linux_tdep prototype.
	* hppa-nbsd-nat.c: Remove _initialize_hppanbsd_nat prototype.
	* hppa-nbsd-tdep.c: Remove _initialize_hppanbsd_tdep prototype.
	* hppa-obsd-nat.c: Remove _initialize_hppaobsd_nat prototype.
	* hppa-obsd-tdep.c: Remove _initialize_hppaobsd_tdep prototype.
	* hppa-tdep.c: Remove _initialize_hppa_tdep prototype.
	* i386-bsd-nat.c: Remove _initialize_i386bsd_nat prototype.
	* i386-cygwin-tdep.c: Remove _initialize_i386_cygwin_tdep
	prototype.
	* i386-darwin-tdep.c: Remove _initialize_i386_darwin_tdep
	prototype.
	* i386-dicos-tdep.c: Remove _initialize_i386_dicos_tdep prototype.
	* i386-fbsd-nat.c: Remove _initialize_i386fbsd_nat prototype.
	* i386-fbsd-tdep.c: Remove _initialize_i386fbsd_tdep prototype.
	* i386-gnu-nat.c: Remove _initialize_i386gnu_nat prototype.
	* i386-gnu-tdep.c: Remove _initialize_i386gnu_tdep prototype.
	* i386-linux-nat.c: Remove _initialize_i386_linux_nat prototype.
	* i386-linux-tdep.c: Remove _initialize_i386_linux_tdep prototype.
	* i386-nbsd-nat.c: Remove _initialize_i386nbsd_nat prototype.
	* i386-nbsd-tdep.c: Remove _initialize_i386nbsd_tdep prototype.
	* i386-nto-tdep.c: Remove _initialize_i386nto_tdep prototype.
	* i386-obsd-nat.c: Remove _initialize_i386obsd_nat prototype.
	* i386-obsd-tdep.c: Remove _initialize_i386obsd_tdep prototype.
	* i386-sol2-nat.c: Remove _initialize_amd64_sol2_nat prototype.
	* i386-sol2-tdep.c: Remove _initialize_amd64_sol2_tdep prototype.
	* i386-tdep.c: Remove _initialize_i386_tdep prototype.
	* i386-windows-nat.c: Remove _initialize_i386_windows_nat
	prototype.
	* ia64-libunwind-tdep.c: Remove _initialize_libunwind_frame
	prototype.
	* ia64-linux-nat.c: Remove _initialize_ia64_linux_nat prototype.
	* ia64-linux-tdep.c: Remove _initialize_ia64_linux_tdep prototype.
	* ia64-tdep.c: Remove _initialize_ia64_tdep prototype.
	* ia64-vms-tdep.c: Remove _initialize_ia64_vms_tdep prototype.
	* infcall.c: Remove _initialize_infcall prototype.
	* infcmd.c: Remove _initialize_infcmd prototype.
	* inferior.c: Remove _initialize_inferiors prototype.
	* inflow.c: Remove _initialize_inflow prototype.
	* infrun.c: Remove _initialize_infrun prototype.
	* interps.c: Remove _initialize_interpreter prototype.
	* iq2000-tdep.c: Remove _initialize_iq2000_tdep prototype.
	* jit.c: Remove _initialize_jit prototype.
	* language.c: Remove _initialize_language prototype.
	* linux-fork.c: Remove _initialize_linux_fork prototype.
	* linux-nat.c: Remove _initialize_linux_nat prototype.
	* linux-tdep.c: Remove _initialize_linux_tdep prototype.
	* linux-thread-db.c: Remove _initialize_thread_db prototype.
	* lm32-tdep.c: Remove _initialize_lm32_tdep prototype.
	* m2-lang.c: Remove _initialize_m2_language prototype.
	* m32c-tdep.c: Remove _initialize_m32c_tdep prototype.
	* m32r-linux-nat.c: Remove _initialize_m32r_linux_nat prototype.
	* m32r-linux-tdep.c: Remove _initialize_m32r_linux_tdep prototype.
	* m32r-tdep.c: Remove _initialize_m32r_tdep prototype.
	* m68hc11-tdep.c: Remove _initialize_m68hc11_tdep prototype.
	* m68k-bsd-nat.c: Remove _initialize_m68kbsd_nat prototype.
	* m68k-bsd-tdep.c: Remove _initialize_m68kbsd_tdep prototype.
	* m68k-linux-nat.c: Remove _initialize_m68k_linux_tdep prototype.
	* m68k-linux-tdep.c: Remove _initialize_m68k_linux_tdep prototype.
	* m68k-tdep.c: Remove _initialize_m68k_tdep prototype.
	* m88k-bsd-nat.c: Remove _initialize_m68kbsd_nat prototype.
	* m88k-tdep.c: Remove _initialize_m68kbsd_tdep prototype.
	* machoread.c: Remove _initialize_machoread prototype.
	* macrocmd.c: Remove _initialize_macrocmd prototype.
	* macroscope.c: Remove _initialize_macroscope prototype.
	* maint.c: Remove _initialize_maint_cmds prototype.
	* mdebugread.c: Remove _initialize_mdebugread prototype.
	* memattr.c: Remove _initialize_mem prototype.
	* mep-tdep.c: Remove _initialize_mep_tdep prototype.
	* mi/mi-cmd-env.c: Remove _initialize_mi_cmd_env prototype.
	* mi/mi-cmds.c: Remove _initialize_mi_cmds prototype.
	* mi/mi-interp.c: Remove _initialize_mi_interp prototype.
	* mi/mi-main.c: Remove _initialize_mi_main prototype.
	* microblaze-linux-tdep.c: Remove
	_initialize_microblaze_linux_tdep prototype.
	* microblaze-tdep.c: Remove _initialize_microblaze_tdep prototype.
	* mips-fbsd-nat.c: Remove _initialize_mips_fbsd_nat prototype.
	* mips-fbsd-tdep.c: Remove _initialize_mips_fbsd_tdep prototype.
	* mips-linux-nat.c: Remove _initialize_mips_linux_nat prototype.
	* mips-linux-tdep.c: Remove _initialize_mips_linux_tdep prototype.
	* mips-nbsd-nat.c: Remove _initialize_mipsnbsd_nat prototype.
	* mips-nbsd-tdep.c: Remove _initialize_mipsnbsd_tdep prototype.
	* mips-sde-tdep.c: Remove _initialize_mips_sde_tdep prototype.
	* mips-tdep.c: Remove _initialize_mips_tdep prototype.
	* mips64-obsd-nat.c: Remove _initialize_mips64obsd_nat prototype.
	* mips64-obsd-tdep.c: Remove _initialize_mips64obsd_tdep
	prototype.
	* mipsread.c: Remove _initialize_mipsread prototype.
	* mn10300-linux-tdep.c: Remove _initialize_mn10300_linux_tdep
	prototype.
	* mn10300-tdep.c: Remove _initialize_mn10300_tdep prototype.
	* moxie-tdep.c: Remove _initialize_moxie_tdep prototype.
	* msp430-tdep.c: Remove _initialize_msp430_tdep prototype.
	* mt-tdep.c: Remove _initialize_mt_tdep prototype.
	* nds32-tdep.c: Remove _initialize_nds32_tdep prototype.
	* nios2-linux-tdep.c: Remove _initialize_nios2_linux_tdep
	prototype.
	* nios2-tdep.c: Remove _initialize_nios2_tdep prototype.
	* nto-procfs.c: Remove _initialize_procfs prototype.
	* nto-tdep.c: Remove _initialize_nto_tdep prototype.
	* objc-lang.c: Remove _initialize_objc_language prototype.
	* objfiles.c: Remove _initialize_objfiles prototype.
	* observer.c: Remove observer_test_first_notification_function,
	observer_test_second_notification_function,
	observer_test_third_notification_function, and
	_initialize_observer prototypes.
	* opencl-lang.c: Remove _initialize_opencl_language prototypes.
	* osabi.c: Remove _initialize_gdb_osabi prototype.
	* osdata.c: Remove _initialize_osdata prototype.
	* p-valprint.c: Remove _initialize_pascal_valprint prototype.
	* parse.c: Remove _initialize_parse prototype.
	* ppc-fbsd-nat.c: Remove _initialize_ppcfbsd_nat prototype.
	* ppc-fbsd-tdep.c: Remove _initialize_ppcfbsd_tdep prototype.
	* ppc-linux-nat.c: Remove _initialize_ppc_linux_nat prototype.
	* ppc-linux-tdep.c: Remove _initialize_ppc_linux_tdep prototype.
	* ppc-nbsd-nat.c: Remove _initialize_ppcnbsd_nat prototype.
	* ppc-nbsd-tdep.c: Remove _initialize_ppcnbsd_tdep prototype.
	* ppc-obsd-nat.c: Remove _initialize_ppcobsd_nat prototype.
	* ppc-obsd-tdep.c: Remove _initialize_ppcobsd_tdep prototype.
	* printcmd.c: Remove _initialize_printcmd prototype.
	* probe.c: Remove _initialize_probe prototype.
	* proc-api.c: Remove _initialize_proc_api prototype.
	* proc-events.c: Remove _initialize_proc_events prototype.
	* proc-service.c: Remove _initialize_proc_service prototype.
	* procfs.c: Remove _initialize_procfs prototype.
	* psymtab.c: Remove _initialize_psymtab prototype.
	* python/python.c: Remove _initialize_python prototype.
	* ravenscar-thread.c: Remove _initialize_ravenscar prototype.
	* record-btrace.c: Remove _initialize_record_btrace prototype.
	* record-full.c: Remove _initialize_record_full prototype.
	* record.c: Remove _initialize_record prototype.
	* regcache.c: Remove _initialize_regcache prototype.
	* reggroups.c: Remove _initialize_reggroup prototype.
	* remote-notif.c: Remove _initialize_notif prototype.
	* remote-sim.c: Remove _initialize_remote_sim prototype.
	* remote.c: Remove _initialize_remote prototype.
	* reverse.c: Remove _initialize_reverse prototype.
	* rl78-tdep.c: Remove _initialize_rl78_tdep prototype.
	* rs6000-aix-tdep.c: Remove _initialize_rs6000_aix_tdep prototype.
	* rs6000-lynx178-tdep.c: Remove _initialize_rs6000_lynx178_tdep
	prototype.
	* rs6000-nat.c: Remove _initialize_rs6000_nat prototype.
	* rs6000-tdep.c: Remove _initialize_rs6000_tdep prototype.
	* rust-exp.y: Remove _initialize_rust_exp prototype.
	* rx-tdep.c: Remove _initialize_rx_tdep prototype.
	* s390-linux-nat.c: Remove _initialize_s390_nat prototype.
	* s390-linux-tdep.c: Remove _initialize_s390_tdep prototype.
	* score-tdep.c: Remove _initialize_score_tdep prototype.
	* selftest-arch.c: Remove _initialize_selftests_foreach_arch
	prototype.
	* ser-go32.c: Remove _initialize_ser_dos prototype.
	* ser-mingw.c: Remove _initialize_ser_windows prototype.
	* ser-pipe.c: Remove _initialize_ser_pipe prototype.
	* ser-tcp.c: Remove _initialize_ser_tcp prototype.
	* ser-unix.c: Remove _initialize_ser_hardwire prototype.
	* serial.c: Remove _initialize_serial prototype.
	* sh-linux-tdep.c: Remove _initialize_sh_linux_tdep prototype.
	* sh-nbsd-nat.c: Remove _initialize_shnbsd_nat prototype.
	* sh-nbsd-tdep.c: Remove _initialize_shnbsd_tdep prototype.
	* sh-tdep.c: Remove _initialize_sh_tdep prototype.
	* skip.c: Remove _initialize_step_skip prototype.
	* sol-thread.c: Remove _initialize_sol_thread prototype.
	* solib-aix.c: Remove _initialize_solib_aix prototype.
	* solib-darwin.c: Remove _initialize_darwin_solib prototype.
	* solib-dsbt.c: Remove _initialize_dsbt_solib prototype.
	* solib-frv.c: Remove _initialize_frv_solib prototype.
	* solib-spu.c: Remove _initialize_spu_solib prototype.
	* solib-svr4.c: Remove _initialize_svr4_solib prototype.
	* solib-target.c: Remove _initialize_solib_target prototype.
	* solib.c: Remove _initialize_solib prototype.
	* source.c: Remove _initialize_source prototype.
	* sparc-linux-nat.c: Remove _initialize_sparc_linux_nat prototype.
	* sparc-linux-tdep.c: Remove _initialize_sparc_linux_tdep
	prototype.
	* sparc-nat.c: Remove _initialize_sparc_nat prototype.
	* sparc-nbsd-nat.c: Remove _initialize_sparcnbsd_nat prototype.
	* sparc-nbsd-tdep.c: Remove _initialize_sparcnbsd_tdep prototype.
	* sparc-obsd-tdep.c: Remove _initialize_sparc32obsd_tdep
	prototype.
	* sparc-sol2-nat.c: Remove _initialize_sparc_sol2_nat prototype.
	* sparc-sol2-tdep.c: Remove _initialize_sparc_sol2_tdep prototype.
	* sparc-tdep.c: Remove _initialize_sparc_tdep prototype.
	* sparc64-fbsd-nat.c: Remove _initialize_sparc64fbsd_nat
	prototype.
	* sparc64-fbsd-tdep.c: Remove _initialize_sparc64fbsd_tdep
	prototype.
	* sparc64-linux-nat.c: Remove _initialize_sparc64_linux_nat
	prototype.
	* sparc64-linux-tdep.c: Remove _initialize_sparc64_linux_tdep
	prototype.
	* sparc64-nat.c: Remove _initialize_sparc64_nat prototype.
	* sparc64-nbsd-nat.c: Remove _initialize_sparc64nbsd_nat
	prototype.
	* sparc64-nbsd-tdep.c: Remove _initialize_sparc64nbsd_tdep
	prototype.
	* sparc64-obsd-nat.c: Remove _initialize_sparc64obsd_nat
	prototype.
	* sparc64-obsd-tdep.c: Remove _initialize_sparc64obsd_tdep
	prototype.
	* sparc64-sol2-tdep.c: Remove _initialize_sparc64_sol2_tdep
	prototype.
	* spu-linux-nat.c: Remove _initialize_spu_nat prototype.
	* spu-multiarch.c: Remove _initialize_spu_multiarch prototype.
	* spu-tdep.c: Remove _initialize_spu_tdep prototype.
	* stabsread.c: Remove _initialize_stabsread prototype.
	* stack.c: Remove _initialize_stack prototype.
	* stap-probe.c: Remove _initialize_stap_probe prototype.
	* std-regs.c: Remove _initialize_frame_reg prototype.
	* symfile-debug.c: Remove _initialize_symfile_debug prototype.
	* symfile-mem.c: Remove _initialize_symfile_mem prototype.
	* symfile.c: Remove _initialize_symfile prototype.
	* symmisc.c: Remove _initialize_symmisc prototype.
	* symtab.c: Remove _initialize_symtab prototype.
	* target-dcache.c: Remove _initialize_target_dcache prototype.
	* target-descriptions.c: Remove _initialize_target_descriptions
	prototype.
	* thread.c: Remove _initialize_thread prototype.
	* tic6x-linux-tdep.c: Remove _initialize_tic6x_linux_tdep
	prototype.
	* tic6x-tdep.c: Remove _initialize_tic6x_tdep prototype.
	* tilegx-linux-nat.c: Remove _initialize_tile_linux_nat prototype.
	* tilegx-linux-tdep.c: Remove _initialize_tilegx_linux_tdep
	prototype.
	* tilegx-tdep.c: Remove _initialize_tilegx_tdep prototype.
	* tracefile-tfile.c: Remove _initialize_tracefile_tfile prototype.
	* tracefile.c: Remove _initialize_tracefile prototype.
	* tracepoint.c: Remove _initialize_tracepoint prototype.
	* tui/tui-hooks.c: Remove _initialize_tui_hooks prototype.
	* tui/tui-interp.c: Remove _initialize_tui_interp prototype.
	* tui/tui-layout.c: Remove _initialize_tui_layout prototype.
	* tui/tui-regs.c: Remove _initialize_tui_regs prototype.
	* tui/tui-stack.c: Remove _initialize_tui_stack prototype.
	* tui/tui-win.c: Remove _initialize_tui_win prototype.
	* tui/tui.c: Remove _initialize_tui prototype.
	* typeprint.c: Remove _initialize_typeprint prototype.
	* user-regs.c: Remove _initialize_user_regs prototype.
	* utils.c: Remove _initialize_utils prototype.
	* v850-tdep.c: Remove _initialize_v850_tdep prototype.
	* valarith.c: Remove _initialize_valarith prototype.
	* valops.c: Remove _initialize_valops prototype.
	* valprint.c: Remove _initialize_valprint prototype.
	* value.c: Remove _initialize_values prototype.
	* varobj.c: Remove _initialize_varobj prototype.
	* vax-bsd-nat.c: Remove _initialize_vaxbsd_nat prototype.
	* vax-nbsd-tdep.c: Remove _initialize_vaxnbsd_tdep prototype.
	* vax-tdep.c: Remove _initialize_vax_tdep prototype.
	* windows-nat.c: Remove _initialize_windows_nat,
	_initialize_check_for_gdb_ini, and _initialize_loadable
	prototypes.
	* windows-tdep.c: Remove _initialize_windows_tdep prototype.
	* xcoffread.c: Remove _initialize_xcoffread prototype.
	* xml-support.c: Remove _initialize_xml_support prototype.
	* xstormy16-tdep.c: Remove _initialize_xstormy16_tdep prototype.
	* xtensa-linux-nat.c: Remove _initialize_xtensa_linux_nat
	prototype.
	* xtensa-linux-tdep.c: Remove _initialize_xtensa_linux_tdep
	prototype.
	* xtensa-tdep.c: Remove _initialize_xtensa_tdep prototype.
2017-09-09 11:02:37 -07:00
Tom Tromey 773a1edcd1 Introduce gdb_argv, a class wrapper for buildargv
This introduces gdb_argv, a class wrapping an "argv" pointer; that is,
a pointer to a NULL-terminated array of char*, where both the array
and each non-NULL element in the array are xmalloc'd.

This patch then changes most users of gdb_buildargv to use gdb_argv
instead.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.h (struct gdb_argv_deleter): New.
	(gdb_argv): New class.
	* utils.c (gdb_argv::reset): New method.
	* tracepoint.c (delete_trace_variable_command): Use gdb_argv.
	* tracefile.c (tsave_command): Use gdb_argv.
	* top.c (new_ui_command): Use gdb_argv.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols, maintenance_expand_symtabs): Use gdb_argv.
	* symfile.c (symbol_file_command, generic_load)
	(remove_symbol_file_command): Use gdb_argv.
	* stack.c (backtrace_command): Use gdb_argv.
	* source.c (add_path, show_substitute_path_command)
	(unset_substitute_path_command, set_substitute_path_command):
	Use gdb_argv.
	* skip.c (skip_command): Use gdb_argv.  Use gdb_buildargv.
	* ser-mingw.c (pipe_windows_open): Use gdb_argv.
	* remote.c (extended_remote_run, remote_put_command)
	(remote_get_command, remote_delete_command): Use gdb_argv.
	* remote-sim.c (gdbsim_load, gdbsim_create_inferior)
	(gdbsim_open): Use gdb_argv.
	* python/py-cmd.c (gdbpy_string_to_argv): Use gdb_argv.
	* psymtab.c (maintenance_print_psymbols): Use gdb_argv.
	* procfs.c (procfs_info_proc): Use gdb_argv.
	* interps.c (interpreter_exec_cmd): Use gdb_argv.
	* infrun.c (handle_command): Use gdb_argv.
	* inferior.c (add_inferior_command, clone_inferior_command):
	Use gdb_argv.
	* guile/scm-string.c (gdbscm_string_to_argv): Use gdb_argv.
	* exec.c (exec_file_command): Use gdb_argv.
	* cli/cli-cmds.c (alias_command): Use gdb_argv.
	* compile/compile.c (build_argc_argv): Use gdb_argv.
2017-08-03 07:59:08 -06:00
Tom Tromey 4a2b031d54 Introduce and use ui_out_emit_table
This introduces ui_out_emit_table, similar to the other existing
ui_out RAII classes, and then uses it in a number of places.  This
replaces some cleanups.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (tvariables_info_1): Use ui_out_emit_table.
	(info_static_tracepoint_markers_command): Likewise.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_table.
	* skip.c (skip_info): Use ui_out_emit_table.
	* progspace.c (print_program_space): Use ui_out_emit_table.
	* osdata.c (info_osdata): Use ui_out_emit_table.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Use
	ui_out_emit_table.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_table.
	* inferior.c (print_inferior): Use ui_out_emit_table.
	* gdb_bfd.c (maintenance_info_bfds): Use ui_out_emit_table.
	* breakpoint.c (breakpoint_1): Use ui_out_emit_table.
	* auto-load.c (auto_load_info_scripts): Use ui_out_emit_table.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_table.
	* ui-out.h (class ui_out_emit_table): New.
2017-08-03 07:58:51 -06:00
Sergio Durigan Junior 9a6c7d9c02 C++ify gdb/common/environ.c
As part of the preparation necessary for my upcoming task, I'd like to
propose that we turn gdb_environ into a class.  The approach taken
here is simple: the class gdb_environ contains everything that is
needed to manipulate the environment variables.  These variables are
stored in an std::vector<char *>, which can be converted to a 'char
**' and passed as argument to functions that need it.

The usage has not changed much.  As per Pedro's suggestion, this class
uses a static factory method initialization.  This means that when an
instance is created, it is initially empty.  When needed, it has to be
initialized using the static method 'from_host_environ'.

As mentioned before, this is a preparation for an upcoming work that I
will be posting in the next few weeks or so.  For that work, I'll
probably create another data structure that will contain all the
environment variables that were set by the user using the 'set
environment' command, because I'll need access to them.  This will be
much easier with the class-ification of gdb_environ.

As noted, this has been regression-tested with the new version of
environ.exp and no regressions were found.

gdb/ChangeLog:
2017-06-20  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	'unittests/environ-selftests.c'.
	(SUBDIR_UNITTESTS_OBS): Add 'environ-selftests.o'.
	* charset.c (find_charset_names): Declare object 'iconv_env'.
	Update code to use 'iconv_env' object.  Remove call to
	'free_environ'.
	* common/environ.c: Include <utility>.
	(make_environ): Delete function.
	(free_environ): Delete function.
	(gdb_environ::clear): New function.
	(gdb_environ::operator=): New function.
	(gdb_environ::get): Likewise.
	(environ_vector): Delete function.
	(set_in_environ): Delete function.
	(gdb_environ::set): New function.
	(unset_in_environ): Delete function.
	(gdb_environ::unset): New function.
	(gdb_environ::envp): Likewise.
	* common/environ.h: Include <vector>.
	(struct gdb_environ): Delete; transform into...
	(class gdb_environ): ... this class.
	(free_environ): Delete prototype.
	(init_environ, get_in_environ, set_in_environ, unset_in_environ,
	environ_vector): Likewise.
	* infcmd.c (run_command_1): Update code to call
	'envp' from 'gdb_environ' class.
	(environment_info): Update code to call methods from 'gdb_environ'
	class.
	(unset_environment_command): Likewise.
	(path_info): Likewise.
	(path_command): Likewise.
	* inferior.c (inferior::~inferior): Delete call to 'free_environ'.
	(inferior::inferior): Initialize 'environment' using the host's
	information.
	* inferior.h: Remove forward declaration of 'struct gdb_environ'.
	Include "environ.h".
	(class inferior) <environment>: Change type from 'struct
	gdb_environ' to 'gdb_environ'.
	* mi/mi-cmd-env.c (mi_cmd_env_path): Update code to call
	methods from 'gdb_environ' class.
	* solib.c (solib_find_1): Likewise
	* unittests/environ-selftests.c: New file.

gdb/gdbserver/ChangeLog:
2017-06-20  Sergio Durigan Junior  <sergiodj@redhat.com>

	* linux-low.c (linux_create_inferior): Adjust code to access the
	environment information via 'gdb_environ' class.
	* lynx-low.c (lynx_create_inferior): Likewise.
	* server.c (our_environ): Make it an instance of 'gdb_environ'.
	(get_environ): Return a pointer to 'our_environ'.
	(captured_main): Initialize 'our_environ'.
	* server.h (get_environ): Adjust prototype.
	* spu-low.c (spu_create_inferior): Adjust code to access the
	environment information via 'gdb_environ' class.
2017-06-20 08:59:27 -04:00
Pedro Alves 5ed8105e02 RAII-fy make_cleanup_restore_current_thread & friends
After all the make_cleanup_restore_current_thread fixing, I thought
I'd convert that and its relatives (which are all cleanups) to RAII
classes.

scoped_restore_current_pspace_and_thread was put in a separate file to
avoid a circular dependency.

Tested on x86-64 Fedora 23, native and gdbserver.

gdb/ChangeLog:
2017-05-04  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SFILES): Add progspace-and-thread.c.
	(HFILES_NO_SRCDIR): Add progspace-and-thread.h.
	(COMMON_OBS): Add progspace-and-thread.o.
	* breakpoint.c: Include "progspace-and-thread.h".
	(update_inserted_breakpoint_locations)
	(insert_breakpoint_locations, create_longjmp_master_breakpoint):
	Use scoped_restore_current_pspace_and_thread.
	(create_std_terminate_master_breakpoint): Use
	scoped_restore_current_program_space.
	(remove_breakpoint): Use scoped_restore_current_pspace_and_thread.
	(print_breakpoint_location): Use
	scoped_restore_current_program_space.
	(bp_loc_is_permanent): Use
	scoped_restore_current_pspace_and_thread.
	(resolve_sal_pc): Use scoped_restore_current_pspace_and_thread.
	(download_tracepoint_locations): Use
	scoped_restore_current_pspace_and_thread.
	(breakpoint_re_set): Use scoped_restore_current_pspace_and_thread.
	* exec.c (exec_close_1): Use scoped_restore_current_program_space.
	(enum step_over_calls_kind): Moved from inferior.h.
	(class scoped_restore_current_thread): New class.
	* gdbthread.h (make_cleanup_restore_current_thread): Delete
	declaration.
	(scoped_restore_current_thread): New class.
	* infcmd.c: Include "common/gdb_optional.h".
	(continue_1, proceed_after_attach): Use
	scoped_restore_current_thread.
	(notice_new_inferior): Use scoped_restore_current_thread.
	* inferior.c: Include "progspace-and-thread.h".
	(restore_inferior, save_current_inferior): Delete.
	(add_inferior_command, clone_inferior_command): Use
	scoped_restore_current_pspace_and_thread.
	* inferior.h (scoped_restore_current_inferior): New class.
	* infrun.c: Include "progspace-and-thread.h" and
	"common/gdb_optional.h".
	(follow_fork_inferior): Use
	scoped_restore_current_pspace_and_thread.
	(scoped_restore_exited_inferior): New class.
	(handle_vfork_child_exec_or_exit): Use
	scoped_restore_exited_inferior,
	scoped_restore_current_pspace_and_thread,
	scoped_restore_current_thread and scoped_restore.
	(fetch_inferior_event): Use scoped_restore_current_thread.
	* linespec.c (decode_line_full, decode_line_1): Use
	scoped_restore_current_program_space.
	* mi/mi-main.c: Include "progspace-and-thread.h".
	(exec_continue): Use scoped_restore_current_thread.
	(mi_cmd_exec_run): Use scoped_restore_current_pspace_and_thread.
	(mi_cmd_trace_frame_collected): Use scoped_restore_current_thread.
	* proc-service.c (ps_pglobal_lookup): Use
	scoped_restore_current_program_space.
	* progspace-and-thread.c: New file.
	* progspace-and-thread.h: New file.
	* progspace.c (release_program_space, clone_program_space): Use
	scoped_restore_current_program_space.
	(restore_program_space, save_current_program_space)
	(save_current_space_and_thread): Delete.
	(switch_to_program_space_and_thread): Moved to
	progspace-and-thread.c.
	* progspace.h (save_current_program_space)
	(save_current_space_and_thread): Delete declarations.
	(scoped_restore_current_program_space): New class.
	* remote.c (remote_btrace_maybe_reopen): Use
	scoped_restore_current_thread.
	* symtab.c: Include "progspace-and-thread.h".
	(skip_prologue_sal): Use scoped_restore_current_pspace_and_thread.
	* thread.c (print_thread_info_1): Use
	scoped_restore_current_thread.
	(struct current_thread_cleanup): Delete.
	(do_restore_current_thread_cleanup)
	(restore_current_thread_cleanup_dtor): Rename/convert both to ...
	(scoped_restore_current_thread::~scoped_restore_current_thread):
	... this new dtor.
	(make_cleanup_restore_current_thread): Rename/convert to ...
	(scoped_restore_current_thread::scoped_restore_current_thread):
	... this new ctor.
	(thread_apply_all_command): Use scoped_restore_current_thread.
	(thread_apply_command): Use scoped_restore_current_thread.
	* tracepoint.c (tdump_command): Use scoped_restore_current_thread.
	* varobj.c (value_of_root_1): Use scoped_restore_current_thread.
2017-05-04 15:18:44 +01:00
Tom Tromey 2e78302469 Use ui_out_emit_tuple
This patch changes various places to use ui_out_emit_tuple,
eliminating a number of cleanups.  This patch only tackles "easy"
cases, which are ones where the cleanups in question were
block-structured and did not involve any changes other than the
obvious replacement.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

	* record-btrace.c (record_btrace_insn_history)
	(record_btrace_insn_history_range, record_btrace_call_history)
	(record_btrace_call_history_range): Use ui_out_emit_tuple.
	* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
	ui_out_emit_tuple.
	* stack.c (print_frame_info): Use ui_out_emit_tuple.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
	* skip.c (skip_info): Use ui_out_emit_tuple.
	* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
	* progspace.c (print_program_space): Use ui_out_emit_tuple.
	* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
	* osdata.c (info_osdata): Use ui_out_emit_tuple.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
	ui_out_emit_tuple.
	* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
	(output_register, mi_cmd_data_read_memory)
	(mi_cmd_data_read_memory_bytes, mi_load_progress)
	(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
	* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
	Use ui_out_emit_tuple.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
	ui_out_emit_tuple.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
	(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_tuple.
	* inferior.c (print_inferior): Use ui_out_emit_tuple.
	* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
	* disasm.c (do_mixed_source_and_assembly_deprecated)
	(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
	* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
	* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
	* breakpoint.c (print_one_breakpoint_location)
	(print_one_breakpoint): Use ui_out_emit_tuple.
	* auto-load.c (print_script, info_auto_load_cmd): Use
	ui_out_emit_tuple.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.
2017-04-22 09:46:58 -06:00
Pedro Alves 3a3fd0fd2c Fix removing inferiors from within "thread apply" commands
This patch fixes an internal error exposed by a test that does
something like:

  define kill-and-remove
    kill inferiors 2
    remove-inferiors 2
  end

  # Start one inferior.
  start

  # Start another inferior.
  add-inferior 2
  inferior 2
  start

  # Kill and remove inferior 1 while inferior 2 is selected.
  thread apply 1.1 kill-and-remove

The internal error looks like this:

 Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)):
 [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)]
 [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))]
 #0  main () at src/gdb/testsuite/gdb.threads/threadapply.c:38
 38          for (i = 0; i < NUM; i++)
 src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error)

There are several problems around this area of the code.  One is that
in do_restore_current_thread_cleanup, we do a look up of inferior by
ptid, which can find the wrong inferior if the previously selected
inferior exited and some other inferior was started with a reused pid
(rare, but still...).

The other problem is that the "remove-inferiors" command rejects
attempts to remove the current inferior, but when we get to
"remove-inferiors" in a "thread apply THR remove-inferiors 2" command,
the current inferior is the inferior of thread THR, not the previously
selected inferior, so if the previously selected inferior was inferior
2, that command still manages to wipe it, and then gdb restores the
old selected inferior, which is now a dangling pointer...

So the fix here is:

- Make make_cleanup_restore_current_thread store a pointer to the
  previously selected inferior directly, and use it directly instead
  of doing ptid look ups.

- Add a refcount to inferiors, very similar to thread_info's refcount,
  that is incremented/decremented by
  make_cleanup_restore_current_thread, and checked before deleting an
  inferior.  To avoid duplication, a new refcounted_object type is
  added, that both thread_info and inferior inherit from.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* common/refcounted-object.h: New file.
	* gdbthread.h: Include "common/refcounted-object.h".
	(thread_info): Inherit from refcounted_object and add comments.
	(thread_info::incref, thread_info::decref)
	(thread_info::m_refcount): Delete.
	(thread_info::deletable): Use the refcounted_object::refcount()
	method.
	* inferior.c (current_inferior_): Add comment.
	(set_current_inferior): Increment/decrement refcounts.
	(prune_inferiors, remove_inferior_command): Skip inferiors marked
	not-deletable instead of comparing with the current inferior.
	(initialize_inferiors): Increment the initial inferior's refcount.
	* inferior.h (struct inferior): Forward declare.
	Include "common/refcounted-object.h".
	(current_inferior, set_current_inferior): Move declaration to
	before struct inferior's definition, and fix comment.
	(inferior): Inherit from refcounted_object.  Add comments.
	* thread.c (switch_to_thread_no_regs): Reference the thread's
	inferior pointer directly instead of doing a ptid lookup.
	(switch_to_no_thread): New function.
	(switch_to_thread(thread_info *)): New function, factored out
	from ...
	(switch_to_thread(ptid_t)): ... this.
	(restore_current_thread): Delete.
	(current_thread_cleanup): Remove 'inf_id' and 'was_removable'
	fields, and add 'inf' field.
	(do_restore_current_thread_cleanup): Check whether old->inf is
	alive instead of looking up an inferior by ptid.  Use
	switch_to_thread and switch_to_no_thread.
	(restore_current_thread_cleanup_dtor): Use old->inf directly
	instead of lookup up an inferior by id.  Decref the inferior.
	Don't restore 'removable'.
	(make_cleanup_restore_current_thread): Same the inferior pointer
	in old, instead of the inferior number.  Incref the inferior.
	Don't save/clear 'removable'.

gdb/testsuite/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* gdb.threads/threadapply.exp (kill_and_remove_inferior): New
	procedure.
	(top level): Call it.
	* lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 13:12:23 +01:00
Pedro Alves 0550c95595 Make inferior a class with cdtors, and use new/delete
struct inferior became a non-POD when enum_flags was made a non-POD,
so we should be allocating/destroying inferiors with new/delete, etc.
That's what this commit does.

Note: this commit makes all boolean fields of inferior be "bool",
except the "detaching" field.  That'll require more work, so I split
it to a separate patch.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* inferior.c (free_inferior): Convert to ...
	(inferior::~inferior): ... this dtor.
	(inferior::inferior): New ctor, factored out from ...
	(add_inferior_silent): ... here.  Allocate the inferior with a new
	expression.
	(delete_inferior): Call delete instead of free_inferior.
	* inferior.h (gdb_environ, continuation): Forward declare.
	(inferior): Now a class.  Add in-class initialization to all
	members.  Make boolean fields bool, except 'detaching'.
	(inferior::inferior): New explicit ctor.
	(inferior::~inferior): New.
2017-04-13 16:18:16 +01:00