--- procfs.c 2006-01-13 21:37:45.000000000 +0400 +++ inf-procfs.c 2006-01-13 21:13:15.000000000 +0400 @@ -1,29 +1,29 @@ /* Machine independent support for SVR4 /proc (process file system) for GDB. - Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, - Inc. + Copyright (C) 2006 Free Software Foundation, Inc. Written by Michael Snyder at Cygnus Solutions. Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others. -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 2 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, write to the Free Software Foundation, -Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ + 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ #include "defs.h" +#include "inf-procfs.h" #include "inferior.h" #include "target.h" #include "gdbcore.h" @@ -51,37 +51,35 @@ Boston, MA 02110-1301, USA. */ #include "inflow.h" #include "auxv.h" -/* - * PROCFS.C - * - * This module provides the interface between GDB and the - * /proc file system, which is used on many versions of Unix - * as a means for debuggers to control other processes. - * Examples of the systems that use this interface are: - * Irix - * Solaris - * OSF - * Unixware - * AIX5 - * - * /proc works by imitating a file system: you open a simulated file - * that represents the process you wish to interact with, and - * perform operations on that "file" in order to examine or change - * the state of the other process. - * - * The most important thing to know about /proc and this module - * is that there are two very different interfaces to /proc: - * One that uses the ioctl system call, and - * another that uses read and write system calls. - * This module has to support both /proc interfaces. This means - * that there are two different ways of doing every basic operation. - * - * In order to keep most of the code simple and clean, I have - * defined an interface "layer" which hides all these system calls. - * An ifdef (NEW_PROC_API) determines which interface we are using, - * and most or all occurrances of this ifdef should be confined to - * this interface layer. - */ +/* inf-procfs.c + + This module provides the interface between GDB and the + /proc file system, which is used on many versions of Unix + as a means for debuggers to control other processes. + Examples of the systems that use this interface are: + Irix + Solaris + OSF + Unixware + AIX5 + + /proc works by imitating a file system: you open a simulated file + that represents the process you wish to interact with, and + perform operations on that "file" in order to examine or change + the state of the other process. + + The most important thing to know about /proc and this module + is that there are two very different interfaces to /proc: + One that uses the ioctl system call, and + another that uses read and write system calls. + This module has to support both /proc interfaces. This means + that there are two different ways of doing every basic operation. + + In order to keep most of the code simple and clean, I have + defined an interface "layer" which hides all these system calls. + An ifdef (NEW_PROC_API) determines which interface we are using, + and most or all occurrances of this ifdef should be confined to + this interface layer. */ /* Determine which /proc API we are using: @@ -108,9 +106,7 @@ Boston, MA 02110-1301, USA. */ /* =================== TARGET_OPS "MODULE" =================== */ -/* - * This module defines the GDB target vector and its methods. - */ +/* This module defines the GDB target vector and its methods. */ static void procfs_open (char *, int); static void procfs_attach (char *, int); @@ -151,57 +147,61 @@ static char * procfs_make_note_section ( static int procfs_can_use_hw_breakpoint (int, int, int); -struct target_ops procfs_ops; /* the target vector */ +struct target_ops *procfs_ops; /* the target vector */ -static void -init_procfs_ops (void) +struct target_ops * +inf_procfs_target (void) { - procfs_ops.to_shortname = "procfs"; - procfs_ops.to_longname = "Unix /proc child process"; - procfs_ops.to_doc = + procfs_ops = XZALLOC (struct target_ops); + + procfs_ops->to_shortname = "procfs"; + procfs_ops->to_longname = "Unix /proc child process"; + procfs_ops->to_doc = "Unix /proc child process (started by the \"run\" command)."; - procfs_ops.to_open = procfs_open; - procfs_ops.to_can_run = procfs_can_run; - procfs_ops.to_create_inferior = procfs_create_inferior; - procfs_ops.to_kill = procfs_kill_inferior; - procfs_ops.to_mourn_inferior = procfs_mourn_inferior; - procfs_ops.to_attach = procfs_attach; - procfs_ops.to_detach = procfs_detach; - procfs_ops.to_wait = procfs_wait; - procfs_ops.to_resume = procfs_resume; - procfs_ops.to_prepare_to_store = procfs_prepare_to_store; - procfs_ops.to_fetch_registers = procfs_fetch_registers; - procfs_ops.to_store_registers = procfs_store_registers; - procfs_ops.to_xfer_partial = procfs_xfer_partial; - procfs_ops.deprecated_xfer_memory = procfs_xfer_memory; - procfs_ops.to_insert_breakpoint = memory_insert_breakpoint; - procfs_ops.to_remove_breakpoint = memory_remove_breakpoint; - procfs_ops.to_notice_signals = procfs_notice_signals; - procfs_ops.to_files_info = procfs_files_info; - procfs_ops.to_stop = procfs_stop; - - procfs_ops.to_terminal_init = terminal_init_inferior; - procfs_ops.to_terminal_inferior = terminal_inferior; - procfs_ops.to_terminal_ours_for_output = terminal_ours_for_output; - procfs_ops.to_terminal_ours = terminal_ours; - procfs_ops.to_terminal_save_ours = terminal_save_ours; - procfs_ops.to_terminal_info = child_terminal_info; - - procfs_ops.to_find_new_threads = procfs_find_new_threads; - procfs_ops.to_thread_alive = procfs_thread_alive; - procfs_ops.to_pid_to_str = procfs_pid_to_str; - - procfs_ops.to_has_all_memory = 1; - procfs_ops.to_has_memory = 1; - procfs_ops.to_has_execution = 1; - procfs_ops.to_has_stack = 1; - procfs_ops.to_has_registers = 1; - procfs_ops.to_stratum = process_stratum; - procfs_ops.to_has_thread_control = tc_schedlock; - procfs_ops.to_find_memory_regions = proc_find_memory_regions; - procfs_ops.to_make_corefile_notes = procfs_make_note_section; - procfs_ops.to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint; - procfs_ops.to_magic = OPS_MAGIC; + procfs_ops->to_open = procfs_open; + procfs_ops->to_can_run = procfs_can_run; + procfs_ops->to_create_inferior = procfs_create_inferior; + procfs_ops->to_kill = procfs_kill_inferior; + procfs_ops->to_mourn_inferior = procfs_mourn_inferior; + procfs_ops->to_attach = procfs_attach; + procfs_ops->to_detach = procfs_detach; + procfs_ops->to_wait = procfs_wait; + procfs_ops->to_resume = procfs_resume; + procfs_ops->to_prepare_to_store = procfs_prepare_to_store; + procfs_ops->to_fetch_registers = procfs_fetch_registers; + procfs_ops->to_store_registers = procfs_store_registers; + procfs_ops->to_xfer_partial = procfs_xfer_partial; + procfs_ops->deprecated_xfer_memory = procfs_xfer_memory; + procfs_ops->to_insert_breakpoint = memory_insert_breakpoint; + procfs_ops->to_remove_breakpoint = memory_remove_breakpoint; + procfs_ops->to_notice_signals = procfs_notice_signals; + procfs_ops->to_files_info = procfs_files_info; + procfs_ops->to_stop = procfs_stop; + + procfs_ops->to_terminal_init = terminal_init_inferior; + procfs_ops->to_terminal_inferior = terminal_inferior; + procfs_ops->to_terminal_ours_for_output = terminal_ours_for_output; + procfs_ops->to_terminal_ours = terminal_ours; + procfs_ops->to_terminal_save_ours = terminal_save_ours; + procfs_ops->to_terminal_info = child_terminal_info; + + procfs_ops->to_find_new_threads = procfs_find_new_threads; + procfs_ops->to_thread_alive = procfs_thread_alive; + procfs_ops->to_pid_to_str = procfs_pid_to_str; + + procfs_ops->to_has_all_memory = 1; + procfs_ops->to_has_memory = 1; + procfs_ops->to_has_execution = 1; + procfs_ops->to_has_stack = 1; + procfs_ops->to_has_registers = 1; + procfs_ops->to_stratum = process_stratum; + procfs_ops->to_has_thread_control = tc_schedlock; + procfs_ops->to_find_memory_regions = proc_find_memory_regions; + procfs_ops->to_make_corefile_notes = procfs_make_note_section; + procfs_ops->to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint; + procfs_ops->to_magic = OPS_MAGIC; + + return procfs_ops; } /* =================== END, TARGET_OPS "MODULE" =================== */ @@ -3533,7 +3533,7 @@ procfs_attach (char *args, int from_tty) fflush (stdout); } inferior_ptid = do_attach (pid_to_ptid (pid)); - push_target (&procfs_ops); + push_target (procfs_ops); } static void @@ -3561,7 +3561,7 @@ procfs_detach (char *args, int from_tty) do_detach (sig); inferior_ptid = null_ptid; - unpush_target (&procfs_ops); + unpush_target (procfs_ops); } static ptid_t @@ -4776,7 +4776,7 @@ procfs_mourn_inferior (void) if (pi) destroy_procinfo (pi); } - unpush_target (&procfs_ops); + unpush_target (procfs_ops); generic_mourn_inferior (); } @@ -4799,7 +4799,7 @@ procfs_init_inferior (int pid) /* This routine called on the parent side (GDB side) after GDB forks the inferior. */ - push_target (&procfs_ops); + push_target (procfs_ops); if ((pi = create_procinfo (pid, 0)) == NULL) perror ("procfs: out of memory in 'init_inferior'"); @@ -5967,8 +5967,6 @@ proc_untrace_sysexit_cmd (char *args, in void _initialize_procfs (void) { - init_procfs_ops (); - add_target (&procfs_ops); add_info ("proc", info_proc_cmd, _("\ Show /proc process information about any running process.\n\ Specify process id, or use the program being debugged by default.\n\