1 /* Subroutines for handling an "inferior" (child) process as a target
3 Copyright 1990, 1991 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "frame.h" /* required by inferior.h */
28 #include "ieee-float.h" /* Required by REGISTER_CONVERT_TO_XXX */
31 child_prepare_to_store PARAMS ((void));
34 child_wait PARAMS ((int *));
37 child_open PARAMS ((char *, int));
40 child_files_info PARAMS ((struct target_ops *));
43 child_detach PARAMS ((char *, int));
45 /* Forward declaration */
46 extern struct target_ops child_ops;
48 /* Wait for child to do something. Return pid of child, or -1 in case
49 of error; store status through argument pointer STATUS. */
59 pid = proc_wait (status);
63 if (pid == -1) /* No more children to wait for */
65 fprintf (stderr, "Child process unexpectedly missing.\n");
66 *status = 42; /* Claim it exited with signal 42 */
69 } while (pid != inferior_pid); /* Some other child died or stopped */
76 * takes a program previously attached to and detaches it.
77 * The program resumes execution and will no longer stop
78 * on signals, etc. We better not have left any breakpoints
79 * in the program or it'll die when it hits one. For this
80 * to work, it may be necessary for the process to have been
81 * previously attached. It *might* work if the program was
82 * started via the normal ptrace (PTRACE_TRACEME).
86 child_detach (args, from_tty)
95 char *exec_file = get_exec_file (0);
98 printf ("Detaching program: %s pid %d\n",
99 exec_file, inferior_pid);
103 siggnal = atoi (args);
107 unpush_target (&child_ops); /* Pop out of handling an inferior */
109 error ("This version of Unix does not support detaching a process.");
113 /* Get ready to modify the registers array. On machines which store
114 individual registers, this doesn't need to do anything. On machines
115 which store all the registers in one fell swoop, this makes sure
116 that registers contains all the registers from the program being
120 child_prepare_to_store ()
122 #ifdef CHILD_PREPARE_TO_STORE
123 CHILD_PREPARE_TO_STORE ();
127 /* Print status information about what we're accessing. */
130 child_files_info (ignore)
131 struct target_ops *ignore;
133 printf ("\tUsing the running image of %s process %d.\n",
134 attach_flag? "attached": "child", inferior_pid);
139 child_open (arg, from_tty)
143 error ("Use the \"run\" command to start a Unix child process.");
146 struct target_ops child_ops = {
147 "child", /* to_shortname */
148 "Unix child process", /* to_longname */
149 "Unix child process (started by the \"run\" command).", /* to_doc */
150 child_open, /* to_open */
152 child_attach, /* to_attach */
153 child_detach, /* to_detach */
154 child_resume, /* to_resume */
155 child_wait, /* to_wait */
156 fetch_inferior_registers, /* to_fetch_registers */
157 store_inferior_registers, /* to_store_registers */
158 child_prepare_to_store, /* to_prepare_to_store */
159 child_xfer_memory, /* to_xfer_memory */
160 child_files_info, /* to_files_info */
161 memory_insert_breakpoint, /* to_insert_breakpoint */
162 memory_remove_breakpoint, /* to_remove_breakpoint */
163 terminal_init_inferior, /* to_terminal_init */
164 terminal_inferior, /* to_terminal_inferior */
165 terminal_ours_for_output, /* to_terminal_ours_for_output */
166 terminal_ours, /* to_terminal_ours */
167 child_terminal_info, /* to_terminal_info */
168 kill_inferior, /* to_kill */
170 0, /* to_lookup_symbol */
171 child_create_inferior, /* to_create_inferior */
172 child_mourn_inferior, /* to_mourn_inferior */
173 process_stratum, /* to_stratum */
175 1, /* to_has_all_memory */
176 1, /* to_has_memory */
177 1, /* to_has_stack */
178 1, /* to_has_registers */
179 1, /* to_has_execution */
181 0, /* sections_end */
182 OPS_MAGIC /* to_magic */
186 _initialize_inftarg ()
188 add_target (&child_ops);