2008-09-22 17:12:19 +02:00
|
|
|
/* Multi-process control for GDB, the GNU debugger.
|
|
|
|
|
2009-01-03 06:58:08 +01:00
|
|
|
Copyright (C) 2008, 2009 Free Software Foundation, Inc.
|
2008-09-22 17:12:19 +02:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "inferior.h"
|
|
|
|
#include "target.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "gdbcmd.h"
|
|
|
|
#include "gdbthread.h"
|
|
|
|
#include "ui-out.h"
|
2008-11-17 13:28:05 +01:00
|
|
|
#include "observer.h"
|
gdb/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* linux-nat.c (linux_child_follow_fork): If we're staying attached
to the child process, enable event reporting on it. Don't handle
checkpoints here. Instead, add the child fork to the lwp thread
and inferior lists without clobbering the previous inferior. Let
the thread_db layer learn about a new child process, even if
following the parent.
(linux_nat_switch_fork): Delete lwps of the current inferior only,
instead of clearing the whole list. Use thread_change_ptid to
give the core the illusion the new checkpoint is still the same
inferior. Clear the register cache.
(linux_handle_extended_wait): Handle checkpoints here.
(linux_multi_process): Turn on.
* linux-fork.c (struct fork_info) <pc>: Remove field.
(init_fork_list): Do not delete the checkpoint from the inferior
list (it is not there).
(fork_load_infrun_state): Don't switch inferior_ptid here. Pass
the new checkpoint's ptid to linux_nat_switch_fork.
(fork_save_infrun_state): Make static. Don't stop the pc field of
fork_info, it's gone.
(linux_fork_mourn_inferior): Don't delete the checkpoint from the
inferior list, it's not there.
(linux_fork_detach): Ditto.
(delete_fork_command): Replace mention of fork/checkpoint by
checkpoint only.
(detach_fork_command): Likewise. Don't delete the checkpoint from
the inferior list.
(info_forks_command): Adjust.
(restore_detach_fork): Delete.
(checkpointing_pid): New.
(linux_fork_checkpointing_p): New.
(save_detach_fork): Delete.
(checkpoint_command): Delete temp_detach_fork. Don't remove
breakpoints, that's a nop. Store the pid of the process we're
checkpointing, and use make_cleanup_restore_integer to restore it.
Don't reinsert breakpoints here.
(process_command, fork_command): Delete.
(restart_command): Update comments to only mention checkpoints,
not forks.
(_initialize_linux_fork): Delete "fork", "process", "info forks"
commands.
* linux-fork.h (fork_save_infrun_state, fork_list): Delete
declarations.
(linux_fork_checkpointing_p): Declare.
* cli/cli-cmds.c (killlist): New.
* cli/cli-cmds.h (killlist): Declare.
* gdbcmd.h (killlist): Declare.
* inferior.c: Include "gdbthread.h".
(detach_inferior_command, kill_inferior_command)
(inferior_command): New.
(info_inferiors_command): Allow specifying a specific inferior id.
(_initialize_inferiors): Register "inferior", "kill inferior" and
"detach inferior" commands.
* infcmd.c (_initialize_infcmd): Make "kill" a prefix command.
* gdbthread.h (any_thread_of_process): Declare.
* thread.c (any_thread_of_process): New.
* NEWS: Mention multi-inferior debugging. Mention 'info
inferiors', 'inferior', 'detach inferior' and 'kill inferior' as
new commands.
(Removed commands): New section, mentioning that 'info forks',
'fork', 'process', 'delete fork' and 'detach fork' are now gone.
gdb/testsuite/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.base/multi-forks.exp: Only run detach-on-fork tests on
linux. Adjust to use "inferior", "info inferiors", "detach
inferior" and "kill inferior" instead of "restart", "info fork",
"detach fork" and "delete fork".
* gdb.base/ending-run.exp: Spell out "info".
* gdb.base/help.exp: Adjust to use test_prefix_command_help for
the "kill" command.
gdb/doc/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Debugging multiple inferiors): Document the
"inferior", "detach inferior" and "kill inferior" commands.
(Debugging Programs with Multiple Processes): Adjust to mention
generic "inferior" commands. Delete mention of "detach fork" and
"delete fork". Cross reference to "Debugging multiple inferiors"
section.
2009-07-02 23:57:28 +02:00
|
|
|
#include "gdbthread.h"
|
2008-09-22 17:12:19 +02:00
|
|
|
|
|
|
|
void _initialize_inferiors (void);
|
|
|
|
|
|
|
|
static struct inferior *inferior_list = NULL;
|
|
|
|
static int highest_inferior_num;
|
|
|
|
|
|
|
|
/* Print notices on inferior events (attach, detach, etc.), set with
|
|
|
|
`set print inferior-events'. */
|
|
|
|
static int print_inferior_events = 0;
|
|
|
|
|
|
|
|
struct inferior*
|
|
|
|
current_inferior (void)
|
|
|
|
{
|
|
|
|
struct inferior *inf = find_inferior_pid (ptid_get_pid (inferior_ptid));
|
|
|
|
gdb_assert (inf);
|
|
|
|
return inf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_inferior (struct inferior *inf)
|
|
|
|
{
|
2008-11-05 21:23:07 +01:00
|
|
|
discard_all_inferior_continuations (inf);
|
2008-09-22 17:12:19 +02:00
|
|
|
xfree (inf->private);
|
|
|
|
xfree (inf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_inferior_list (void)
|
|
|
|
{
|
|
|
|
struct inferior *inf, *infnext;
|
|
|
|
|
|
|
|
highest_inferior_num = 0;
|
|
|
|
if (!inferior_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = infnext)
|
|
|
|
{
|
|
|
|
infnext = inf->next;
|
|
|
|
free_inferior (inf);
|
|
|
|
}
|
|
|
|
|
|
|
|
inferior_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct inferior *
|
|
|
|
add_inferior_silent (int pid)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
|
|
|
|
inf = xmalloc (sizeof (*inf));
|
|
|
|
memset (inf, 0, sizeof (*inf));
|
|
|
|
inf->pid = pid;
|
|
|
|
|
2008-09-22 17:20:08 +02:00
|
|
|
inf->stop_soon = NO_STOP_QUIETLY;
|
|
|
|
|
2008-09-22 17:12:19 +02:00
|
|
|
inf->num = ++highest_inferior_num;
|
|
|
|
inf->next = inferior_list;
|
|
|
|
inferior_list = inf;
|
|
|
|
|
2009-05-06 19:25:18 +02:00
|
|
|
observer_notify_new_inferior (pid);
|
|
|
|
|
2008-09-22 17:12:19 +02:00
|
|
|
return inf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct inferior *
|
|
|
|
add_inferior (int pid)
|
|
|
|
{
|
|
|
|
struct inferior *inf = add_inferior_silent (pid);
|
|
|
|
|
|
|
|
if (print_inferior_events)
|
|
|
|
printf_unfiltered (_("[New inferior %d]\n"), pid);
|
|
|
|
|
|
|
|
return inf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct delete_thread_of_inferior_arg
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
int silent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
delete_thread_of_inferior (struct thread_info *tp, void *data)
|
|
|
|
{
|
|
|
|
struct delete_thread_of_inferior_arg *arg = data;
|
|
|
|
|
|
|
|
if (ptid_get_pid (tp->ptid) == arg->pid)
|
|
|
|
{
|
|
|
|
if (arg->silent)
|
|
|
|
delete_thread_silent (tp->ptid);
|
|
|
|
else
|
|
|
|
delete_thread (tp->ptid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If SILENT then be quiet -- don't announce a inferior death, or the
|
|
|
|
exit of its threads. */
|
|
|
|
static void
|
|
|
|
delete_inferior_1 (int pid, int silent)
|
|
|
|
{
|
|
|
|
struct inferior *inf, *infprev;
|
|
|
|
struct delete_thread_of_inferior_arg arg = { pid, silent };
|
|
|
|
|
|
|
|
infprev = NULL;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; infprev = inf, inf = inf->next)
|
|
|
|
if (inf->pid == pid)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!inf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
arg.pid = pid;
|
|
|
|
arg.silent = silent;
|
|
|
|
|
|
|
|
iterate_over_threads (delete_thread_of_inferior, &arg);
|
2008-11-17 13:28:05 +01:00
|
|
|
|
2009-05-18 02:58:38 +02:00
|
|
|
/* Notify the observers before removing the inferior from the list,
|
|
|
|
so that the observers have a change to look it up. */
|
2008-11-17 13:28:05 +01:00
|
|
|
observer_notify_inferior_exit (pid);
|
2009-05-18 02:58:38 +02:00
|
|
|
|
|
|
|
if (infprev)
|
|
|
|
infprev->next = inf->next;
|
|
|
|
else
|
|
|
|
inferior_list = inf->next;
|
|
|
|
|
|
|
|
free_inferior (inf);
|
2008-09-22 17:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delete_inferior (int pid)
|
|
|
|
{
|
|
|
|
delete_inferior_1 (pid, 0);
|
|
|
|
|
|
|
|
if (print_inferior_events)
|
|
|
|
printf_unfiltered (_("[Inferior %d exited]\n"), pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delete_inferior_silent (int pid)
|
|
|
|
{
|
|
|
|
delete_inferior_1 (pid, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
detach_inferior (int pid)
|
|
|
|
{
|
|
|
|
delete_inferior_1 (pid, 1);
|
|
|
|
|
|
|
|
if (print_inferior_events)
|
|
|
|
printf_unfiltered (_("[Inferior %d detached]\n"), pid);
|
|
|
|
}
|
|
|
|
|
2008-09-22 17:18:30 +02:00
|
|
|
void
|
|
|
|
discard_all_inferiors (void)
|
|
|
|
{
|
|
|
|
struct inferior *inf, *infnext;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = infnext)
|
|
|
|
{
|
|
|
|
infnext = inf->next;
|
|
|
|
delete_inferior_silent (inf->pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-22 17:12:19 +02:00
|
|
|
static struct inferior *
|
|
|
|
find_inferior_id (int num)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
if (inf->num == num)
|
|
|
|
return inf;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct inferior *
|
|
|
|
find_inferior_pid (int pid)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
if (inf->pid == pid)
|
|
|
|
return inf;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct inferior *
|
|
|
|
iterate_over_inferiors (int (*callback) (struct inferior *, void *),
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct inferior *inf, *infnext;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = infnext)
|
|
|
|
{
|
|
|
|
infnext = inf->next;
|
|
|
|
if ((*callback) (inf, data))
|
|
|
|
return inf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
valid_gdb_inferior_id (int num)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
if (inf->num == num)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pid_to_gdb_inferior_id (int pid)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
if (inf->pid == pid)
|
|
|
|
return inf->num;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gdb_inferior_id_to_pid (int num)
|
|
|
|
{
|
|
|
|
struct inferior *inferior = find_inferior_id (num);
|
|
|
|
if (inferior)
|
|
|
|
return inferior->pid;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
in_inferior_list (int pid)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
if (inf->pid == pid)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
have_inferiors (void)
|
|
|
|
{
|
|
|
|
return inferior_list != NULL;
|
|
|
|
}
|
|
|
|
|
* target.h (struct target_ops): Make to_has_all_memory,
to_has_memory, to_has_stack, to_has_registers and to_has_execution
methods instead of variables.
(target_has_all_memory_1, target_has_memory_1, target_has_stack_1)
(target_has_registers_1, target_has_execution_1): Declare
functions.
(target_has_all_memory): Rewrite to call target_has_all_memory_1.
(target_has_memory): Rewrite to call target_has_memory_1.
(target_has_stack): Rewrite to call target_has_all_stack_1.
(target_has_registers): Rewrite to call target_has_registers_1.
(target_has_execution): Rewrite to call target_has_execution_1.
(default_child_has_all_memory, default_child_has_memory)
(default_child_has_stack, default_child_has_registers)
(default_child_has_execution): Declare.
(target_mark_running, target_mark_exited): Delete declarations.
* target.c (default_child_has_all_memory,
default_child_has_memory, default_child_has_stack,
default_child_has_registers, default_child_has_execution): New.
(target_has_all_memory_1, target_has_memory_1, target_has_stack_1,
target_has_registers_1, target_has_execution_1): New.
(add_target): Default the to_has_all_memory, to_has_all_memory,
to_has_memory, to_has_stack, to_has_registers and to_has_execution
callbacks to return 0.
(update_current_target): Do not inherit to_has_all_memory,
to_has_memory, to_has_stack, to_has_registers or to_has_execution.
(target_mark_running, target_mark_exited): Delete.
(memory_xfer_partial): Adjust.
(target_read_memory, target_write_memory, target_search_memory):
Dispatch to the the top-most target, not the flattened
current_target.
(target_info): Adjust.
(init_dummy_target): Install return_zero as callback for
to_has_all_memory, to_has_memory, to_has_stack, to_has_registers,
to_has_execution.
(set_maintenance_target_async_permitted): Use have_live_inferiors
instead of target_has_execution.
* target-memory.c (target_write_memory_blocks): Dispatch memory
writes to the the top-most target, not the flattened
current_target.
* breakpoint.c (insert_breakpoints): Don't check for
target_has_execution here.
(update_global_location_list): Check if there are live inferiors
to debug instead of target_has_execution.
* infcmd.c (kill_command, detach_command): Check if there are
inferiors instead of target_has_execution.
* inferior.h (have_live_inferiors): Declare.
* inferior.c (have_live_inferiors): New.
* infrun.c (normal_stop): Don't check for target_has_execution to
finish the thread states.
* thread.c (is_thread_state, is_stopped, is_exited, is_running)
(any_running, is_executing): Remove checks for
target_has_execution.
* top.c (kill_or_detach): Don't try to kill core inferiors.
(quit_target): Don't check for target_has_execution.
* corelow.c (core_has_memory, core_has_stack, core_has_registers):
New.
(init_core_ops): Install core_has_memory, core_has_stack and
core_has_registers.
* exec.c (exec_has_memory): New.
(init_exec_ops): Install exec_has_memory.
* remote.c (remote_add_inferior): Don't call target_mark_running.
(remote_start_remote): Don't call target_mark_exited or call
target_mark_running.
(remote_open_1): Use have_inferiors instead of
target_has_execution. Don't use target_mark_exited.
(init_remote_ops): Install deafult_child_has_all_memory,
default_child_has_memory, default_child_has_stack,
default_child_has_registers, default_child_has_execution.
* bsd-kvm.c (bsd_kvm_return_one): New.
(bsd_kvm_add_target): Register bsd_kvm_return_one as
to_has_memory, to_has_stack and to_has_registers callbacks.
* remote-m32r-sdi.c (m32r_return_one): New.
(init_m32r_ops): Register it.
* inf-child.c (inf_child_target): Adjust to register
default_child_has_all_memory, default_child_has_memory,
default_child_has_stack, default_child_has_registers,
default_child_has_execution callbacks.
* gnu-nat.c (init_gnu_ops): Likewise.
* go32-nat.c (init_go32_ops): Likewise.
* hpux-thread.c (init_hpux_thread_ops): Likewise.
* monitor.c (init_base_monitor_ops): Likewise.
* nto-procfs.c (init_procfs_ops): Likewise.
* remote-mips.c (_initialize_remote_mips): Likewise.
* windows-nat.c (init_windows_ops): Likewise.
* remote-sim.c (gdbsim_create_inferior): Don't use
target_mark_running or target_mark_exited.
(gdbsim_mourn_inferior): Don't call target_mark_exited.
(init_gdbsim_ops): Adjust to register
default_child_has_all_memory, default_child_has_memory,
default_child_has_stack, default_child_has_registers,
default_child_has_execution callbacks.
* linux-nat.c (linux_nat_xfer_partial): If reading memory, and
there's no inferior selected, defer to a lower stratum.
2009-06-07 18:46:48 +02:00
|
|
|
int
|
|
|
|
have_live_inferiors (void)
|
|
|
|
{
|
|
|
|
/* The check on stratum suffices, as GDB doesn't currently support
|
|
|
|
multiple target interfaces. */
|
|
|
|
return (current_target.to_stratum >= process_stratum && have_inferiors ());
|
|
|
|
}
|
|
|
|
|
2008-09-22 17:12:19 +02:00
|
|
|
/* Prints the list of inferiors and their details on UIOUT. This is a
|
|
|
|
version of 'info_inferior_command' suitable for use from MI.
|
|
|
|
|
|
|
|
If REQUESTED_INFERIOR is not -1, it's the GDB id of the inferior that
|
|
|
|
should be printed. Otherwise, all inferiors are printed. */
|
|
|
|
void
|
|
|
|
print_inferior (struct ui_out *uiout, int requested_inferior)
|
|
|
|
{
|
|
|
|
struct inferior *inf;
|
|
|
|
struct cleanup *old_chain;
|
2009-06-11 00:08:19 +02:00
|
|
|
int inf_count = 0;
|
2008-09-22 17:12:19 +02:00
|
|
|
|
2009-06-11 00:08:19 +02:00
|
|
|
/* Compute number of inferiors we will print. */
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
{
|
|
|
|
struct cleanup *chain2;
|
|
|
|
|
|
|
|
if (requested_inferior != -1 && inf->num != requested_inferior)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
++inf_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inf_count == 0)
|
|
|
|
{
|
|
|
|
ui_out_message (uiout, 0, "No inferiors.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_chain = make_cleanup_ui_out_table_begin_end (uiout, 3, inf_count,
|
|
|
|
"inferiors");
|
2009-08-25 17:24:12 +02:00
|
|
|
ui_out_table_header (uiout, 1, ui_left, "current", "");
|
|
|
|
ui_out_table_header (uiout, 4, ui_left, "number", "Num");
|
|
|
|
ui_out_table_header (uiout, 17, ui_left, "target-id", "Description");
|
2009-06-11 00:08:19 +02:00
|
|
|
ui_out_table_body (uiout);
|
2008-09-22 17:12:19 +02:00
|
|
|
|
|
|
|
for (inf = inferior_list; inf; inf = inf->next)
|
|
|
|
{
|
|
|
|
struct cleanup *chain2;
|
|
|
|
|
|
|
|
if (requested_inferior != -1 && inf->num != requested_inferior)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
|
|
|
|
|
|
|
|
if (inf->pid == ptid_get_pid (inferior_ptid))
|
2009-06-11 00:08:19 +02:00
|
|
|
ui_out_field_string (uiout, "current", "*");
|
2008-09-22 17:12:19 +02:00
|
|
|
else
|
2009-06-11 00:08:19 +02:00
|
|
|
ui_out_field_skip (uiout, "current");
|
2008-09-22 17:12:19 +02:00
|
|
|
|
2009-08-25 17:24:12 +02:00
|
|
|
ui_out_field_int (uiout, "number", inf->num);
|
|
|
|
ui_out_field_string (uiout, "target-id",
|
|
|
|
target_pid_to_str (pid_to_ptid (inf->pid)));
|
2008-09-22 17:12:19 +02:00
|
|
|
|
|
|
|
ui_out_text (uiout, "\n");
|
|
|
|
do_cleanups (chain2);
|
|
|
|
}
|
|
|
|
|
2009-08-25 17:24:12 +02:00
|
|
|
if (inferior_list
|
|
|
|
&& ptid_equal (inferior_ptid, null_ptid))
|
|
|
|
ui_out_message (uiout, 0, "\n\
|
|
|
|
No selected inferior/thread. See `help thread' or `help inferior'.\n");
|
|
|
|
|
2008-09-22 17:12:19 +02:00
|
|
|
do_cleanups (old_chain);
|
|
|
|
}
|
|
|
|
|
gdb/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* linux-nat.c (linux_child_follow_fork): If we're staying attached
to the child process, enable event reporting on it. Don't handle
checkpoints here. Instead, add the child fork to the lwp thread
and inferior lists without clobbering the previous inferior. Let
the thread_db layer learn about a new child process, even if
following the parent.
(linux_nat_switch_fork): Delete lwps of the current inferior only,
instead of clearing the whole list. Use thread_change_ptid to
give the core the illusion the new checkpoint is still the same
inferior. Clear the register cache.
(linux_handle_extended_wait): Handle checkpoints here.
(linux_multi_process): Turn on.
* linux-fork.c (struct fork_info) <pc>: Remove field.
(init_fork_list): Do not delete the checkpoint from the inferior
list (it is not there).
(fork_load_infrun_state): Don't switch inferior_ptid here. Pass
the new checkpoint's ptid to linux_nat_switch_fork.
(fork_save_infrun_state): Make static. Don't stop the pc field of
fork_info, it's gone.
(linux_fork_mourn_inferior): Don't delete the checkpoint from the
inferior list, it's not there.
(linux_fork_detach): Ditto.
(delete_fork_command): Replace mention of fork/checkpoint by
checkpoint only.
(detach_fork_command): Likewise. Don't delete the checkpoint from
the inferior list.
(info_forks_command): Adjust.
(restore_detach_fork): Delete.
(checkpointing_pid): New.
(linux_fork_checkpointing_p): New.
(save_detach_fork): Delete.
(checkpoint_command): Delete temp_detach_fork. Don't remove
breakpoints, that's a nop. Store the pid of the process we're
checkpointing, and use make_cleanup_restore_integer to restore it.
Don't reinsert breakpoints here.
(process_command, fork_command): Delete.
(restart_command): Update comments to only mention checkpoints,
not forks.
(_initialize_linux_fork): Delete "fork", "process", "info forks"
commands.
* linux-fork.h (fork_save_infrun_state, fork_list): Delete
declarations.
(linux_fork_checkpointing_p): Declare.
* cli/cli-cmds.c (killlist): New.
* cli/cli-cmds.h (killlist): Declare.
* gdbcmd.h (killlist): Declare.
* inferior.c: Include "gdbthread.h".
(detach_inferior_command, kill_inferior_command)
(inferior_command): New.
(info_inferiors_command): Allow specifying a specific inferior id.
(_initialize_inferiors): Register "inferior", "kill inferior" and
"detach inferior" commands.
* infcmd.c (_initialize_infcmd): Make "kill" a prefix command.
* gdbthread.h (any_thread_of_process): Declare.
* thread.c (any_thread_of_process): New.
* NEWS: Mention multi-inferior debugging. Mention 'info
inferiors', 'inferior', 'detach inferior' and 'kill inferior' as
new commands.
(Removed commands): New section, mentioning that 'info forks',
'fork', 'process', 'delete fork' and 'detach fork' are now gone.
gdb/testsuite/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.base/multi-forks.exp: Only run detach-on-fork tests on
linux. Adjust to use "inferior", "info inferiors", "detach
inferior" and "kill inferior" instead of "restart", "info fork",
"detach fork" and "delete fork".
* gdb.base/ending-run.exp: Spell out "info".
* gdb.base/help.exp: Adjust to use test_prefix_command_help for
the "kill" command.
gdb/doc/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Debugging multiple inferiors): Document the
"inferior", "detach inferior" and "kill inferior" commands.
(Debugging Programs with Multiple Processes): Adjust to mention
generic "inferior" commands. Delete mention of "detach fork" and
"delete fork". Cross reference to "Debugging multiple inferiors"
section.
2009-07-02 23:57:28 +02:00
|
|
|
static void
|
|
|
|
detach_inferior_command (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
int num, pid;
|
|
|
|
struct thread_info *tp;
|
|
|
|
|
|
|
|
if (!args || !*args)
|
|
|
|
error (_("Requires argument (inferior id to detach)"));
|
|
|
|
|
|
|
|
num = parse_and_eval_long (args);
|
|
|
|
|
|
|
|
if (!valid_gdb_inferior_id (num))
|
|
|
|
error (_("Inferior ID %d not known."), num);
|
|
|
|
|
|
|
|
pid = gdb_inferior_id_to_pid (num);
|
|
|
|
|
|
|
|
tp = any_thread_of_process (pid);
|
|
|
|
if (!tp)
|
|
|
|
error (_("Inferior has no threads."));
|
|
|
|
|
|
|
|
switch_to_thread (tp->ptid);
|
|
|
|
|
|
|
|
detach_command (NULL, from_tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kill_inferior_command (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
int num, pid;
|
|
|
|
struct thread_info *tp;
|
|
|
|
|
|
|
|
if (!args || !*args)
|
|
|
|
error (_("Requires argument (inferior id to kill)"));
|
|
|
|
|
|
|
|
num = parse_and_eval_long (args);
|
|
|
|
|
|
|
|
if (!valid_gdb_inferior_id (num))
|
|
|
|
error (_("Inferior ID %d not known."), num);
|
|
|
|
|
|
|
|
pid = gdb_inferior_id_to_pid (num);
|
|
|
|
|
|
|
|
tp = any_thread_of_process (pid);
|
|
|
|
if (!tp)
|
|
|
|
error (_("Inferior has no threads."));
|
|
|
|
|
|
|
|
switch_to_thread (tp->ptid);
|
|
|
|
|
|
|
|
target_kill ();
|
|
|
|
|
|
|
|
bfd_cache_close_all ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
inferior_command (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
int num, pid;
|
|
|
|
|
|
|
|
if (!have_inferiors ())
|
|
|
|
error (_("No inferiors"));
|
|
|
|
|
|
|
|
num = parse_and_eval_long (args);
|
|
|
|
|
|
|
|
if (!valid_gdb_inferior_id (num))
|
|
|
|
error (_("Inferior ID %d not known."), num);
|
|
|
|
|
|
|
|
pid = gdb_inferior_id_to_pid (num);
|
|
|
|
|
|
|
|
if (pid != ptid_get_pid (inferior_ptid))
|
|
|
|
{
|
|
|
|
struct thread_info *tp;
|
|
|
|
|
|
|
|
tp = any_thread_of_process (pid);
|
|
|
|
if (!tp)
|
|
|
|
error (_("Inferior has no threads."));
|
|
|
|
|
|
|
|
switch_to_thread (tp->ptid);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf_filtered (_("[Switching to thread %d (%s)] "),
|
|
|
|
pid_to_thread_id (inferior_ptid),
|
|
|
|
target_pid_to_str (inferior_ptid));
|
|
|
|
|
|
|
|
if (is_running (inferior_ptid))
|
|
|
|
ui_out_text (uiout, "(running)\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui_out_text (uiout, "\n");
|
|
|
|
print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-22 17:12:19 +02:00
|
|
|
/* Print information about currently known inferiors. */
|
|
|
|
|
|
|
|
static void
|
gdb/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* linux-nat.c (linux_child_follow_fork): If we're staying attached
to the child process, enable event reporting on it. Don't handle
checkpoints here. Instead, add the child fork to the lwp thread
and inferior lists without clobbering the previous inferior. Let
the thread_db layer learn about a new child process, even if
following the parent.
(linux_nat_switch_fork): Delete lwps of the current inferior only,
instead of clearing the whole list. Use thread_change_ptid to
give the core the illusion the new checkpoint is still the same
inferior. Clear the register cache.
(linux_handle_extended_wait): Handle checkpoints here.
(linux_multi_process): Turn on.
* linux-fork.c (struct fork_info) <pc>: Remove field.
(init_fork_list): Do not delete the checkpoint from the inferior
list (it is not there).
(fork_load_infrun_state): Don't switch inferior_ptid here. Pass
the new checkpoint's ptid to linux_nat_switch_fork.
(fork_save_infrun_state): Make static. Don't stop the pc field of
fork_info, it's gone.
(linux_fork_mourn_inferior): Don't delete the checkpoint from the
inferior list, it's not there.
(linux_fork_detach): Ditto.
(delete_fork_command): Replace mention of fork/checkpoint by
checkpoint only.
(detach_fork_command): Likewise. Don't delete the checkpoint from
the inferior list.
(info_forks_command): Adjust.
(restore_detach_fork): Delete.
(checkpointing_pid): New.
(linux_fork_checkpointing_p): New.
(save_detach_fork): Delete.
(checkpoint_command): Delete temp_detach_fork. Don't remove
breakpoints, that's a nop. Store the pid of the process we're
checkpointing, and use make_cleanup_restore_integer to restore it.
Don't reinsert breakpoints here.
(process_command, fork_command): Delete.
(restart_command): Update comments to only mention checkpoints,
not forks.
(_initialize_linux_fork): Delete "fork", "process", "info forks"
commands.
* linux-fork.h (fork_save_infrun_state, fork_list): Delete
declarations.
(linux_fork_checkpointing_p): Declare.
* cli/cli-cmds.c (killlist): New.
* cli/cli-cmds.h (killlist): Declare.
* gdbcmd.h (killlist): Declare.
* inferior.c: Include "gdbthread.h".
(detach_inferior_command, kill_inferior_command)
(inferior_command): New.
(info_inferiors_command): Allow specifying a specific inferior id.
(_initialize_inferiors): Register "inferior", "kill inferior" and
"detach inferior" commands.
* infcmd.c (_initialize_infcmd): Make "kill" a prefix command.
* gdbthread.h (any_thread_of_process): Declare.
* thread.c (any_thread_of_process): New.
* NEWS: Mention multi-inferior debugging. Mention 'info
inferiors', 'inferior', 'detach inferior' and 'kill inferior' as
new commands.
(Removed commands): New section, mentioning that 'info forks',
'fork', 'process', 'delete fork' and 'detach fork' are now gone.
gdb/testsuite/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.base/multi-forks.exp: Only run detach-on-fork tests on
linux. Adjust to use "inferior", "info inferiors", "detach
inferior" and "kill inferior" instead of "restart", "info fork",
"detach fork" and "delete fork".
* gdb.base/ending-run.exp: Spell out "info".
* gdb.base/help.exp: Adjust to use test_prefix_command_help for
the "kill" command.
gdb/doc/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Debugging multiple inferiors): Document the
"inferior", "detach inferior" and "kill inferior" commands.
(Debugging Programs with Multiple Processes): Adjust to mention
generic "inferior" commands. Delete mention of "detach fork" and
"delete fork". Cross reference to "Debugging multiple inferiors"
section.
2009-07-02 23:57:28 +02:00
|
|
|
info_inferiors_command (char *args, int from_tty)
|
2008-09-22 17:12:19 +02:00
|
|
|
{
|
gdb/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* linux-nat.c (linux_child_follow_fork): If we're staying attached
to the child process, enable event reporting on it. Don't handle
checkpoints here. Instead, add the child fork to the lwp thread
and inferior lists without clobbering the previous inferior. Let
the thread_db layer learn about a new child process, even if
following the parent.
(linux_nat_switch_fork): Delete lwps of the current inferior only,
instead of clearing the whole list. Use thread_change_ptid to
give the core the illusion the new checkpoint is still the same
inferior. Clear the register cache.
(linux_handle_extended_wait): Handle checkpoints here.
(linux_multi_process): Turn on.
* linux-fork.c (struct fork_info) <pc>: Remove field.
(init_fork_list): Do not delete the checkpoint from the inferior
list (it is not there).
(fork_load_infrun_state): Don't switch inferior_ptid here. Pass
the new checkpoint's ptid to linux_nat_switch_fork.
(fork_save_infrun_state): Make static. Don't stop the pc field of
fork_info, it's gone.
(linux_fork_mourn_inferior): Don't delete the checkpoint from the
inferior list, it's not there.
(linux_fork_detach): Ditto.
(delete_fork_command): Replace mention of fork/checkpoint by
checkpoint only.
(detach_fork_command): Likewise. Don't delete the checkpoint from
the inferior list.
(info_forks_command): Adjust.
(restore_detach_fork): Delete.
(checkpointing_pid): New.
(linux_fork_checkpointing_p): New.
(save_detach_fork): Delete.
(checkpoint_command): Delete temp_detach_fork. Don't remove
breakpoints, that's a nop. Store the pid of the process we're
checkpointing, and use make_cleanup_restore_integer to restore it.
Don't reinsert breakpoints here.
(process_command, fork_command): Delete.
(restart_command): Update comments to only mention checkpoints,
not forks.
(_initialize_linux_fork): Delete "fork", "process", "info forks"
commands.
* linux-fork.h (fork_save_infrun_state, fork_list): Delete
declarations.
(linux_fork_checkpointing_p): Declare.
* cli/cli-cmds.c (killlist): New.
* cli/cli-cmds.h (killlist): Declare.
* gdbcmd.h (killlist): Declare.
* inferior.c: Include "gdbthread.h".
(detach_inferior_command, kill_inferior_command)
(inferior_command): New.
(info_inferiors_command): Allow specifying a specific inferior id.
(_initialize_inferiors): Register "inferior", "kill inferior" and
"detach inferior" commands.
* infcmd.c (_initialize_infcmd): Make "kill" a prefix command.
* gdbthread.h (any_thread_of_process): Declare.
* thread.c (any_thread_of_process): New.
* NEWS: Mention multi-inferior debugging. Mention 'info
inferiors', 'inferior', 'detach inferior' and 'kill inferior' as
new commands.
(Removed commands): New section, mentioning that 'info forks',
'fork', 'process', 'delete fork' and 'detach fork' are now gone.
gdb/testsuite/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.base/multi-forks.exp: Only run detach-on-fork tests on
linux. Adjust to use "inferior", "info inferiors", "detach
inferior" and "kill inferior" instead of "restart", "info fork",
"detach fork" and "delete fork".
* gdb.base/ending-run.exp: Spell out "info".
* gdb.base/help.exp: Adjust to use test_prefix_command_help for
the "kill" command.
gdb/doc/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Debugging multiple inferiors): Document the
"inferior", "detach inferior" and "kill inferior" commands.
(Debugging Programs with Multiple Processes): Adjust to mention
generic "inferior" commands. Delete mention of "detach fork" and
"delete fork". Cross reference to "Debugging multiple inferiors"
section.
2009-07-02 23:57:28 +02:00
|
|
|
int requested = -1;
|
|
|
|
|
|
|
|
if (args && *args)
|
|
|
|
{
|
|
|
|
requested = parse_and_eval_long (args);
|
|
|
|
if (!valid_gdb_inferior_id (requested))
|
|
|
|
error (_("Inferior ID %d not known."), requested);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_inferior (uiout, requested);
|
2008-09-22 17:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print notices when new inferiors are created and die. */
|
|
|
|
static void
|
|
|
|
show_print_inferior_events (struct ui_file *file, int from_tty,
|
|
|
|
struct cmd_list_element *c, const char *value)
|
|
|
|
{
|
|
|
|
fprintf_filtered (file, _("Printing of inferior events is %s.\n"), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_initialize_inferiors (void)
|
|
|
|
{
|
|
|
|
add_info ("inferiors", info_inferiors_command,
|
|
|
|
_("IDs of currently known inferiors."));
|
|
|
|
|
|
|
|
add_setshow_boolean_cmd ("inferior-events", no_class,
|
|
|
|
&print_inferior_events, _("\
|
|
|
|
Set printing of inferior events (e.g., inferior start and exit)."), _("\
|
|
|
|
Show printing of inferior events (e.g., inferior start and exit)."), NULL,
|
|
|
|
NULL,
|
|
|
|
show_print_inferior_events,
|
|
|
|
&setprintlist, &showprintlist);
|
gdb/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* linux-nat.c (linux_child_follow_fork): If we're staying attached
to the child process, enable event reporting on it. Don't handle
checkpoints here. Instead, add the child fork to the lwp thread
and inferior lists without clobbering the previous inferior. Let
the thread_db layer learn about a new child process, even if
following the parent.
(linux_nat_switch_fork): Delete lwps of the current inferior only,
instead of clearing the whole list. Use thread_change_ptid to
give the core the illusion the new checkpoint is still the same
inferior. Clear the register cache.
(linux_handle_extended_wait): Handle checkpoints here.
(linux_multi_process): Turn on.
* linux-fork.c (struct fork_info) <pc>: Remove field.
(init_fork_list): Do not delete the checkpoint from the inferior
list (it is not there).
(fork_load_infrun_state): Don't switch inferior_ptid here. Pass
the new checkpoint's ptid to linux_nat_switch_fork.
(fork_save_infrun_state): Make static. Don't stop the pc field of
fork_info, it's gone.
(linux_fork_mourn_inferior): Don't delete the checkpoint from the
inferior list, it's not there.
(linux_fork_detach): Ditto.
(delete_fork_command): Replace mention of fork/checkpoint by
checkpoint only.
(detach_fork_command): Likewise. Don't delete the checkpoint from
the inferior list.
(info_forks_command): Adjust.
(restore_detach_fork): Delete.
(checkpointing_pid): New.
(linux_fork_checkpointing_p): New.
(save_detach_fork): Delete.
(checkpoint_command): Delete temp_detach_fork. Don't remove
breakpoints, that's a nop. Store the pid of the process we're
checkpointing, and use make_cleanup_restore_integer to restore it.
Don't reinsert breakpoints here.
(process_command, fork_command): Delete.
(restart_command): Update comments to only mention checkpoints,
not forks.
(_initialize_linux_fork): Delete "fork", "process", "info forks"
commands.
* linux-fork.h (fork_save_infrun_state, fork_list): Delete
declarations.
(linux_fork_checkpointing_p): Declare.
* cli/cli-cmds.c (killlist): New.
* cli/cli-cmds.h (killlist): Declare.
* gdbcmd.h (killlist): Declare.
* inferior.c: Include "gdbthread.h".
(detach_inferior_command, kill_inferior_command)
(inferior_command): New.
(info_inferiors_command): Allow specifying a specific inferior id.
(_initialize_inferiors): Register "inferior", "kill inferior" and
"detach inferior" commands.
* infcmd.c (_initialize_infcmd): Make "kill" a prefix command.
* gdbthread.h (any_thread_of_process): Declare.
* thread.c (any_thread_of_process): New.
* NEWS: Mention multi-inferior debugging. Mention 'info
inferiors', 'inferior', 'detach inferior' and 'kill inferior' as
new commands.
(Removed commands): New section, mentioning that 'info forks',
'fork', 'process', 'delete fork' and 'detach fork' are now gone.
gdb/testsuite/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.base/multi-forks.exp: Only run detach-on-fork tests on
linux. Adjust to use "inferior", "info inferiors", "detach
inferior" and "kill inferior" instead of "restart", "info fork",
"detach fork" and "delete fork".
* gdb.base/ending-run.exp: Spell out "info".
* gdb.base/help.exp: Adjust to use test_prefix_command_help for
the "kill" command.
gdb/doc/
2009-07-02 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Debugging multiple inferiors): Document the
"inferior", "detach inferior" and "kill inferior" commands.
(Debugging Programs with Multiple Processes): Adjust to mention
generic "inferior" commands. Delete mention of "detach fork" and
"delete fork". Cross reference to "Debugging multiple inferiors"
section.
2009-07-02 23:57:28 +02:00
|
|
|
|
|
|
|
add_cmd ("inferior", class_run, detach_inferior_command, _("\
|
|
|
|
Detach from inferior ID."),
|
|
|
|
&detachlist);
|
|
|
|
|
|
|
|
add_cmd ("inferior", class_run, kill_inferior_command, _("\
|
|
|
|
Kill inferior ID."),
|
|
|
|
&killlist);
|
|
|
|
|
|
|
|
add_cmd ("inferior", class_run, inferior_command, _("\
|
|
|
|
Use this command to switch between inferiors.\n\
|
|
|
|
The new inferior ID must be currently known."),
|
|
|
|
&cmdlist);
|
2008-09-22 17:12:19 +02:00
|
|
|
}
|