aboutsummaryrefslogtreecommitdiff
path: root/gdb/inferior.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2009-07-02 21:57:28 +0000
committerPedro Alves <palves@redhat.com>2009-07-02 21:57:28 +0000
commit2277426b30143428d49daf1d3e422f5096c4c4cb (patch)
treee02a568122cbe0c10f2fdf3761746e39b35492f7 /gdb/inferior.c
parent59837fe086d095b2ce147ac6e3539f6843007f4f (diff)
downloadgdb-2277426b30143428d49daf1d3e422f5096c4c4cb.zip
gdb-2277426b30143428d49daf1d3e422f5096c4c4cb.tar.gz
gdb-2277426b30143428d49daf1d3e422f5096c4c4cb.tar.bz2
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.
Diffstat (limited to 'gdb/inferior.c')
-rw-r--r--gdb/inferior.c118
1 files changed, 116 insertions, 2 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c
index a99a3be..43eacda 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -25,6 +25,7 @@
#include "gdbthread.h"
#include "ui-out.h"
#include "observer.h"
+#include "gdbthread.h"
void _initialize_inferiors (void);
@@ -352,12 +353,112 @@ print_inferior (struct ui_out *uiout, int requested_inferior)
do_cleanups (old_chain);
}
+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);
+ }
+}
+
/* Print information about currently known inferiors. */
static void
-info_inferiors_command (char *arg, int from_tty)
+info_inferiors_command (char *args, int from_tty)
{
- print_inferior (uiout, -1);
+ 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);
}
/* Print notices when new inferiors are created and die. */
@@ -381,4 +482,17 @@ Show printing of inferior events (e.g., inferior start and exit)."), NULL,
NULL,
show_print_inferior_events,
&setprintlist, &showprintlist);
+
+ 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);
}