1 /* Target-vector operations for controlling Unix child processes, for GDB.
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "frame.h" /* required by inferior.h */
31 child_prepare_to_store
PARAMS ((void));
35 child_wait
PARAMS ((int *));
36 #endif /* CHILD_WAIT */
39 child_open
PARAMS ((char *, int));
42 child_files_info
PARAMS ((struct target_ops
*));
45 child_detach
PARAMS ((char *, int));
48 child_attach
PARAMS ((char *, int));
51 ptrace_me
PARAMS ((void));
54 ptrace_him
PARAMS ((int));
57 child_create_inferior
PARAMS ((char *, char *, char **));
60 child_mourn_inferior
PARAMS ((void));
63 child_can_run
PARAMS ((void));
65 extern char **environ
;
67 /* Forward declaration */
68 extern struct target_ops child_ops
;
72 /* Wait for child to do something. Return pid of child, or -1 in case
73 of error; store status through argument pointer STATUS. */
76 child_wait (pid
, status
)
84 set_sigint_trap(); /* Causes SIGINT to be passed on to the
94 if (save_errno
== EINTR
)
96 fprintf (stderr
, "Child process unexpectedly missing: %s.\n",
97 safe_strerror (save_errno
));
98 *status
= 42; /* Claim it exited with signal 42 */
101 } while (pid
!= inferior_pid
); /* Some other child died or stopped */
104 #endif /* CHILD_WAIT */
106 /* Attach to process PID, then initialize for debugging it. */
109 child_attach (args
, from_tty
)
117 error_no_arg ("process-id to attach");
119 #ifndef ATTACH_DETACH
120 error ("Can't attach to a process on this machine.");
124 if (pid
== getpid()) /* Trying to masturbate? */
125 error ("I refuse to debug myself!");
129 exec_file
= (char *) get_exec_file (0);
132 printf ("Attaching to program `%s', %s\n", exec_file
, target_pid_to_str (pid
));
134 printf ("Attaching to %s\n", target_pid_to_str (pid
));
141 push_target (&child_ops
);
142 #endif /* ATTACH_DETACH */
146 /* Take a program previously attached to and detaches it.
147 The program resumes execution and will no longer stop
148 on signals, etc. We'd better not have left any breakpoints
149 in the program or it'll die when it hits one. For this
150 to work, it may be necessary for the process to have been
151 previously attached. It *might* work if the program was
152 started via the normal ptrace (PTRACE_TRACEME). */
155 child_detach (args
, from_tty
)
164 char *exec_file
= get_exec_file (0);
167 printf ("Detaching from program: %s %s\n", exec_file
,
168 target_pid_to_str (inferior_pid
));
172 siggnal
= atoi (args
);
176 unpush_target (&child_ops
); /* Pop out of handling an inferior */
178 error ("This version of Unix does not support detaching a process.");
182 /* Get ready to modify the registers array. On machines which store
183 individual registers, this doesn't need to do anything. On machines
184 which store all the registers in one fell swoop, this makes sure
185 that registers contains all the registers from the program being
189 child_prepare_to_store ()
191 #ifdef CHILD_PREPARE_TO_STORE
192 CHILD_PREPARE_TO_STORE ();
196 /* Print status information about what we're accessing. */
199 child_files_info (ignore
)
200 struct target_ops
*ignore
;
202 printf ("\tUsing the running image of %s %s.\n",
203 attach_flag
? "attached": "child", target_pid_to_str (inferior_pid
));
208 child_open (arg
, from_tty
)
212 error ("Use the \"run\" command to start a Unix child process.");
215 /* Stub function which causes the inferior that runs it, to be ptrace-able
216 by its parent process. */
221 /* "Trace me, Dr. Memory!" */
222 call_ptrace (0, 0, (PTRACE_ARG3_TYPE
) 0, 0);
225 /* Stub function which causes the GDB that runs it, to start ptrace-ing
226 the child process. */
232 push_target (&child_ops
);
235 /* Start an inferior Unix child process and sets inferior_pid to its pid.
236 EXEC_FILE is the file to run.
237 ALLARGS is a string containing the arguments to the program.
238 ENV is the environment vector to pass. Errors reported with error(). */
241 child_create_inferior (exec_file
, allargs
, env
)
246 fork_inferior (exec_file
, allargs
, env
, ptrace_me
, ptrace_him
);
247 /* We are at the first instruction we care about. */
248 /* Pedal to the metal... */
249 proceed ((CORE_ADDR
) -1, 0, 0);
253 child_mourn_inferior ()
255 unpush_target (&child_ops
);
256 generic_mourn_inferior ();
265 struct target_ops child_ops
= {
266 "child", /* to_shortname */
267 "Unix child process", /* to_longname */
268 "Unix child process (started by the \"run\" command).", /* to_doc */
269 child_open
, /* to_open */
271 child_attach
, /* to_attach */
272 child_detach
, /* to_detach */
273 child_resume
, /* to_resume */
274 child_wait
, /* to_wait */
275 fetch_inferior_registers
, /* to_fetch_registers */
276 store_inferior_registers
, /* to_store_registers */
277 child_prepare_to_store
, /* to_prepare_to_store */
278 child_xfer_memory
, /* to_xfer_memory */
279 child_files_info
, /* to_files_info */
280 memory_insert_breakpoint
, /* to_insert_breakpoint */
281 memory_remove_breakpoint
, /* to_remove_breakpoint */
282 terminal_init_inferior
, /* to_terminal_init */
283 terminal_inferior
, /* to_terminal_inferior */
284 terminal_ours_for_output
, /* to_terminal_ours_for_output */
285 terminal_ours
, /* to_terminal_ours */
286 child_terminal_info
, /* to_terminal_info */
287 kill_inferior
, /* to_kill */
289 0, /* to_lookup_symbol */
290 child_create_inferior
, /* to_create_inferior */
291 child_mourn_inferior
, /* to_mourn_inferior */
292 child_can_run
, /* to_can_run */
293 0, /* to_notice_signals */
294 process_stratum
, /* to_stratum */
296 1, /* to_has_all_memory */
297 1, /* to_has_memory */
298 1, /* to_has_stack */
299 1, /* to_has_registers */
300 1, /* to_has_execution */
302 0, /* sections_end */
303 OPS_MAGIC
/* to_magic */
307 _initialize_inftarg ()
309 add_target (&child_ops
);