Commit | Line | Data |
---|---|---|
3aa6856a | 1 | /* Target-vector operations for controlling Unix child processes, for GDB. |
4ef1f467 DT |
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996 |
3 | Free Software Foundation, Inc. | |
bd5635a1 RP |
4 | Contributed by Cygnus Support. |
5 | ||
65b07ddc DT |
6 | ## Contains temporary hacks.. |
7 | ||
bd5635a1 RP |
8 | This file is part of GDB. |
9 | ||
dcc8abce | 10 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 11 | it under the terms of the GNU General Public License as published by |
dcc8abce JG |
12 | the Free Software Foundation; either version 2 of the License, or |
13 | (at your option) any later version. | |
bd5635a1 | 14 | |
dcc8abce | 15 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
dcc8abce | 21 | along with this program; if not, write to the Free Software |
4ef1f467 | 22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 23 | |
bd5635a1 | 24 | #include "defs.h" |
bd5635a1 RP |
25 | #include "frame.h" /* required by inferior.h */ |
26 | #include "inferior.h" | |
27 | #include "target.h" | |
bd5635a1 | 28 | #include "gdbcore.h" |
100f92e2 | 29 | #include "command.h" |
65b07ddc | 30 | #include "gdb_stat.h" |
310cc570 | 31 | #include <signal.h> |
4ef1f467 DT |
32 | #include <sys/types.h> |
33 | #include <fcntl.h> | |
34 | ||
35 | #ifdef HAVE_WAIT_H | |
36 | # include <wait.h> | |
37 | #else | |
38 | # ifdef HAVE_SYS_WAIT_H | |
39 | # include <sys/wait.h> | |
40 | # endif | |
41 | #endif | |
42 | ||
43 | /* "wait.h" fills in the gaps left by <wait.h> */ | |
44 | #include "wait.h" | |
65b07ddc DT |
45 | #include <sys/unistd.h> |
46 | ||
47 | extern struct symtab_and_line * | |
48 | child_enable_exception_callback PARAMS ((enum exception_event_kind, int)); | |
49 | ||
50 | extern struct exception_event_record * | |
51 | child_get_current_exception_event PARAMS ((void)); | |
310cc570 | 52 | |
dcc8abce JG |
53 | static void |
54 | child_prepare_to_store PARAMS ((void)); | |
55 | ||
de43d7d0 | 56 | #ifndef CHILD_WAIT |
429f1c9f | 57 | static int child_wait PARAMS ((int, struct target_waitstatus *)); |
de43d7d0 | 58 | #endif /* CHILD_WAIT */ |
dcc8abce | 59 | |
65b07ddc DT |
60 | #if !defined(CHILD_POST_WAIT) |
61 | void | |
62 | child_post_wait PARAMS ((int, int)); | |
63 | #endif | |
64 | ||
429f1c9f | 65 | static void child_open PARAMS ((char *, int)); |
dcc8abce JG |
66 | |
67 | static void | |
68 | child_files_info PARAMS ((struct target_ops *)); | |
69 | ||
70 | static void | |
71 | child_detach PARAMS ((char *, int)); | |
bd5635a1 | 72 | |
65b07ddc DT |
73 | static void |
74 | child_detach_from_process PARAMS ((int, char *, int, int)); | |
75 | ||
310cc570 RP |
76 | static void |
77 | child_attach PARAMS ((char *, int)); | |
78 | ||
65b07ddc DT |
79 | static void |
80 | child_attach_to_process PARAMS ((char *, int, int)); | |
81 | ||
82 | #if !defined(CHILD_POST_ATTACH) | |
83 | static void | |
84 | child_post_attach PARAMS ((int)); | |
85 | #endif | |
86 | ||
87 | static void | |
88 | child_require_attach PARAMS ((char *, int)); | |
89 | ||
90 | static void | |
91 | child_require_detach PARAMS ((int, char *, int)); | |
92 | ||
de43d7d0 SG |
93 | static void |
94 | ptrace_me PARAMS ((void)); | |
95 | ||
65b07ddc | 96 | static void |
de43d7d0 SG |
97 | ptrace_him PARAMS ((int)); |
98 | ||
65b07ddc DT |
99 | static void |
100 | child_create_inferior PARAMS ((char *, char *, char **)); | |
310cc570 RP |
101 | |
102 | static void | |
103 | child_mourn_inferior PARAMS ((void)); | |
104 | ||
3aa6856a JG |
105 | static int |
106 | child_can_run PARAMS ((void)); | |
107 | ||
4ef1f467 DT |
108 | static void |
109 | child_stop PARAMS ((void)); | |
110 | ||
111 | #ifndef CHILD_THREAD_ALIVE | |
65b07ddc | 112 | int child_thread_alive PARAMS ((int)); |
4ef1f467 DT |
113 | #endif |
114 | ||
310cc570 RP |
115 | extern char **environ; |
116 | ||
bd5635a1 RP |
117 | /* Forward declaration */ |
118 | extern struct target_ops child_ops; | |
119 | ||
4ef1f467 DT |
120 | int child_suppress_run = 0; /* Non-zero if inftarg should pretend not to |
121 | be a runnable target. Used by targets | |
122 | that can sit atop inftarg, such as HPUX | |
123 | thread support. */ | |
4ef1f467 | 124 | |
de43d7d0 SG |
125 | #ifndef CHILD_WAIT |
126 | ||
65b07ddc DT |
127 | /*##*/ |
128 | /* Enable HACK for ttrace work. In | |
129 | * infttrace.c/require_notification_of_events, | |
130 | * this is set to 0 so that the loop in child_wait | |
131 | * won't loop. | |
132 | */ | |
133 | int not_same_real_pid = 1; | |
134 | /*##*/ | |
135 | ||
136 | ||
bd5635a1 | 137 | /* Wait for child to do something. Return pid of child, or -1 in case |
67ac9759 | 138 | of error; store status through argument pointer OURSTATUS. */ |
bd5635a1 | 139 | |
dcc8abce | 140 | static int |
67ac9759 | 141 | child_wait (pid, ourstatus) |
de43d7d0 | 142 | int pid; |
67ac9759 | 143 | struct target_waitstatus *ourstatus; |
bd5635a1 | 144 | { |
de43d7d0 | 145 | int save_errno; |
67ac9759 | 146 | int status; |
65b07ddc DT |
147 | char * execd_pathname; |
148 | int exit_status; | |
149 | int related_pid; | |
150 | int syscall_id; | |
151 | enum target_waitkind kind; | |
bd5635a1 RP |
152 | |
153 | do { | |
4ef1f467 DT |
154 | set_sigint_trap(); /* Causes SIGINT to be passed on to the |
155 | attached process. */ | |
429f1c9f JK |
156 | set_sigio_trap (); |
157 | ||
4ef1f467 | 158 | pid = proc_wait (inferior_pid, &status); |
65b07ddc | 159 | |
de43d7d0 SG |
160 | save_errno = errno; |
161 | ||
429f1c9f JK |
162 | clear_sigio_trap (); |
163 | ||
4ef1f467 | 164 | clear_sigint_trap(); |
de43d7d0 SG |
165 | |
166 | if (pid == -1) | |
bd5635a1 | 167 | { |
de43d7d0 SG |
168 | if (save_errno == EINTR) |
169 | continue; | |
65b07ddc | 170 | |
67ac9759 | 171 | fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing: %s.\n", |
de43d7d0 | 172 | safe_strerror (save_errno)); |
65b07ddc | 173 | |
67ac9759 JK |
174 | /* Claim it exited with unknown signal. */ |
175 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
176 | ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN; | |
bd5635a1 RP |
177 | return -1; |
178 | } | |
65b07ddc DT |
179 | |
180 | /* Did it exit? | |
181 | */ | |
182 | if (target_has_exited (pid, status, &exit_status)) | |
183 | { | |
184 | /* ??rehrauer: For now, ignore this. */ | |
185 | continue; | |
186 | } | |
187 | ||
188 | if (!target_thread_alive (pid)) | |
189 | { | |
190 | ourstatus->kind = TARGET_WAITKIND_SPURIOUS; | |
191 | return pid; | |
192 | } | |
193 | ||
194 | if (target_has_forked (pid, &related_pid) | |
195 | && (pid == inferior_pid) || (related_pid == inferior_pid)) | |
196 | { | |
197 | ourstatus->kind = TARGET_WAITKIND_FORKED; | |
198 | ourstatus->value.related_pid = related_pid; | |
199 | return pid; | |
200 | } | |
201 | ||
202 | if (target_has_vforked (pid, &related_pid) | |
203 | && (pid == inferior_pid) || (related_pid == inferior_pid)) | |
204 | { | |
205 | ourstatus->kind = TARGET_WAITKIND_VFORKED; | |
206 | ourstatus->value.related_pid = related_pid; | |
207 | return pid; | |
208 | } | |
209 | ||
210 | if (target_has_execd (pid, &execd_pathname)) | |
211 | { | |
212 | /* Are we ignoring initial exec events? (This is likely because | |
213 | we're in the process of starting up the inferior, and another | |
214 | (older) mechanism handles those.) If so, we'll report this | |
215 | as a regular stop, not an exec. | |
216 | */ | |
217 | if (inferior_ignoring_startup_exec_events) | |
218 | { | |
219 | inferior_ignoring_startup_exec_events--; | |
220 | } | |
221 | else | |
222 | { | |
223 | ourstatus->kind = TARGET_WAITKIND_EXECD; | |
224 | ourstatus->value.execd_pathname = execd_pathname; | |
225 | return pid; | |
226 | } | |
227 | } | |
228 | ||
229 | /* All we must do with these is communicate their occurrence | |
230 | to wait_for_inferior... | |
231 | */ | |
232 | if (target_has_syscall_event (pid, &kind, &syscall_id)) | |
233 | { | |
234 | ourstatus->kind = kind; | |
235 | ourstatus->value.syscall_id = syscall_id; | |
236 | return pid; | |
237 | } | |
238 | ||
239 | /*## } while (pid != inferior_pid); ##*/ /* Some other child died or stopped */ | |
240 | /* hack for thread testing */ | |
241 | } while( (pid != inferior_pid) && not_same_real_pid ); | |
242 | /*##*/ | |
243 | ||
67ac9759 | 244 | store_waitstatus (ourstatus, status); |
bd5635a1 RP |
245 | return pid; |
246 | } | |
de43d7d0 | 247 | #endif /* CHILD_WAIT */ |
bd5635a1 | 248 | |
65b07ddc DT |
249 | #if !defined(CHILD_POST_WAIT) |
250 | void | |
251 | child_post_wait (pid, wait_status) | |
252 | int pid; | |
253 | int wait_status; | |
254 | { | |
255 | /* This version of Unix doesn't require a meaningful "post wait" | |
256 | operation. | |
257 | */ | |
258 | } | |
259 | #endif | |
260 | ||
261 | ||
4ef1f467 DT |
262 | #ifndef CHILD_THREAD_ALIVE |
263 | ||
264 | /* Check to see if the given thread is alive. | |
265 | ||
266 | FIXME: Is kill() ever the right way to do this? I doubt it, but | |
267 | for now we're going to try and be compatable with the old thread | |
268 | code. */ | |
65b07ddc | 269 | int |
4ef1f467 DT |
270 | child_thread_alive (pid) |
271 | int pid; | |
272 | { | |
273 | return (kill (pid, 0) != -1); | |
274 | } | |
275 | ||
276 | #endif | |
277 | ||
310cc570 | 278 | static void |
65b07ddc DT |
279 | child_attach_to_process (args, from_tty, after_fork) |
280 | char * args; | |
281 | int from_tty; | |
282 | int after_fork; | |
310cc570 | 283 | { |
310cc570 RP |
284 | if (!args) |
285 | error_no_arg ("process-id to attach"); | |
286 | ||
287 | #ifndef ATTACH_DETACH | |
288 | error ("Can't attach to a process on this machine."); | |
289 | #else | |
100f92e2 JK |
290 | { |
291 | char *exec_file; | |
292 | int pid; | |
65b07ddc DT |
293 | struct target_waitstatus *wstatus; |
294 | char * dummy; | |
310cc570 | 295 | |
65b07ddc DT |
296 | dummy = args; |
297 | pid = strtol (args, &dummy, 0); | |
298 | /* Some targets don't set errno on errors, grrr! */ | |
299 | if ((pid == 0) && (args == dummy)) | |
300 | error ("Illegal process-id: %s\n", args); | |
310cc570 | 301 | |
100f92e2 JK |
302 | if (pid == getpid()) /* Trying to masturbate? */ |
303 | error ("I refuse to debug myself!"); | |
310cc570 | 304 | |
100f92e2 JK |
305 | if (from_tty) |
306 | { | |
307 | exec_file = (char *) get_exec_file (0); | |
310cc570 | 308 | |
65b07ddc DT |
309 | if (after_fork) |
310 | printf_unfiltered ("Attaching after fork to %s\n", | |
100f92e2 | 311 | target_pid_to_str (pid)); |
65b07ddc DT |
312 | else if (exec_file) |
313 | printf_unfiltered ("Attaching to program: %s, %s\n", exec_file, | |
314 | target_pid_to_str (pid)); | |
315 | else | |
316 | printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid)); | |
100f92e2 | 317 | |
67ac9759 | 318 | gdb_flush (gdb_stdout); |
100f92e2 | 319 | } |
310cc570 | 320 | |
65b07ddc DT |
321 | if (!after_fork) |
322 | attach (pid); | |
323 | else | |
324 | REQUIRE_ATTACH (pid); | |
325 | ||
100f92e2 JK |
326 | inferior_pid = pid; |
327 | push_target (&child_ops); | |
328 | } | |
310cc570 RP |
329 | #endif /* ATTACH_DETACH */ |
330 | } | |
331 | ||
3aa6856a | 332 | |
65b07ddc | 333 | /* Attach to process PID, then initialize for debugging it. */ |
bd5635a1 RP |
334 | |
335 | static void | |
65b07ddc DT |
336 | child_attach (args, from_tty) |
337 | char *args; | |
338 | int from_tty; | |
339 | { | |
340 | child_attach_to_process (args, from_tty, 0); | |
341 | } | |
342 | ||
343 | #if !defined(CHILD_POST_ATTACH) | |
344 | static void | |
345 | child_post_attach (pid) | |
346 | int pid; | |
347 | { | |
348 | /* This version of Unix doesn't require a meaningful "post attach" | |
349 | operation by a debugger. | |
350 | */ | |
351 | } | |
352 | #endif | |
353 | ||
354 | ||
355 | static void | |
356 | child_require_attach (args, from_tty) | |
bd5635a1 RP |
357 | char *args; |
358 | int from_tty; | |
65b07ddc DT |
359 | { |
360 | child_attach_to_process (args, from_tty, 1); | |
361 | } | |
362 | ||
363 | static void | |
364 | child_detach_from_process (pid, args, from_tty, after_fork) | |
365 | int pid; | |
366 | char * args; | |
367 | int from_tty; | |
368 | int after_fork; | |
bd5635a1 | 369 | { |
bd5635a1 | 370 | #ifdef ATTACH_DETACH |
100f92e2 JK |
371 | { |
372 | int siggnal = 0; | |
373 | ||
374 | if (from_tty) | |
375 | { | |
376 | char *exec_file = get_exec_file (0); | |
377 | if (exec_file == 0) | |
378 | exec_file = ""; | |
65b07ddc DT |
379 | if (after_fork) |
380 | printf_unfiltered ("Detaching after fork from %s\n", | |
381 | target_pid_to_str (pid)); | |
382 | else | |
383 | printf_unfiltered ("Detaching from program: %s, %s\n", exec_file, | |
384 | target_pid_to_str (pid)); | |
67ac9759 | 385 | gdb_flush (gdb_stdout); |
100f92e2 JK |
386 | } |
387 | if (args) | |
388 | siggnal = atoi (args); | |
389 | ||
65b07ddc DT |
390 | if (!after_fork) |
391 | detach (siggnal); | |
392 | else | |
393 | REQUIRE_DETACH (pid, siggnal); | |
100f92e2 | 394 | } |
bd5635a1 | 395 | #else |
100f92e2 | 396 | error ("This version of Unix does not support detaching a process."); |
bd5635a1 RP |
397 | #endif |
398 | } | |
399 | ||
65b07ddc DT |
400 | /* Take a program previously attached to and detaches it. |
401 | The program resumes execution and will no longer stop | |
402 | on signals, etc. We'd better not have left any breakpoints | |
403 | in the program or it'll die when it hits one. For this | |
404 | to work, it may be necessary for the process to have been | |
405 | previously attached. It *might* work if the program was | |
406 | started via the normal ptrace (PTRACE_TRACEME). */ | |
407 | ||
408 | static void | |
409 | child_detach (args, from_tty) | |
410 | char *args; | |
411 | int from_tty; | |
412 | { | |
413 | child_detach_from_process (inferior_pid, args, from_tty, 0); | |
414 | inferior_pid = 0; | |
415 | unpush_target (&child_ops); | |
416 | } | |
417 | ||
418 | static void | |
419 | child_require_detach (pid, args, from_tty) | |
420 | int pid; | |
421 | char * args; | |
422 | int from_tty; | |
423 | { | |
424 | child_detach_from_process (pid, args, from_tty, 1); | |
425 | } | |
426 | ||
427 | ||
bd5635a1 RP |
428 | /* Get ready to modify the registers array. On machines which store |
429 | individual registers, this doesn't need to do anything. On machines | |
430 | which store all the registers in one fell swoop, this makes sure | |
431 | that registers contains all the registers from the program being | |
432 | debugged. */ | |
433 | ||
dcc8abce | 434 | static void |
bd5635a1 RP |
435 | child_prepare_to_store () |
436 | { | |
437 | #ifdef CHILD_PREPARE_TO_STORE | |
438 | CHILD_PREPARE_TO_STORE (); | |
439 | #endif | |
440 | } | |
441 | ||
bd5635a1 RP |
442 | /* Print status information about what we're accessing. */ |
443 | ||
444 | static void | |
dcc8abce JG |
445 | child_files_info (ignore) |
446 | struct target_ops *ignore; | |
bd5635a1 | 447 | { |
67ac9759 | 448 | printf_unfiltered ("\tUsing the running image of %s %s.\n", |
de43d7d0 | 449 | attach_flag? "attached": "child", target_pid_to_str (inferior_pid)); |
bd5635a1 RP |
450 | } |
451 | ||
e1ce8aa5 | 452 | /* ARGSUSED */ |
70dcc196 JK |
453 | static void |
454 | child_open (arg, from_tty) | |
455 | char *arg; | |
456 | int from_tty; | |
457 | { | |
458 | error ("Use the \"run\" command to start a Unix child process."); | |
459 | } | |
460 | ||
de43d7d0 SG |
461 | /* Stub function which causes the inferior that runs it, to be ptrace-able |
462 | by its parent process. */ | |
463 | ||
464 | static void | |
465 | ptrace_me () | |
466 | { | |
467 | /* "Trace me, Dr. Memory!" */ | |
468 | call_ptrace (0, 0, (PTRACE_ARG3_TYPE) 0, 0); | |
469 | } | |
470 | ||
471 | /* Stub function which causes the GDB that runs it, to start ptrace-ing | |
472 | the child process. */ | |
473 | ||
65b07ddc | 474 | static void |
de43d7d0 SG |
475 | ptrace_him (pid) |
476 | int pid; | |
477 | { | |
478 | push_target (&child_ops); | |
67ac9759 | 479 | |
65b07ddc DT |
480 | /* On some targets, there must be some explicit synchronization |
481 | between the parent and child processes after the debugger | |
482 | forks, and before the child execs the debuggee program. This | |
483 | call basically gives permission for the child to exec. | |
484 | */ | |
485 | ||
486 | target_acknowledge_created_inferior (pid); | |
487 | ||
488 | /* START_INFERIOR_TRAPS_EXPECTED is defined in inferior.h, | |
489 | * and will be 1 or 2 depending on whether we're starting | |
490 | * without or with a shell. | |
491 | */ | |
67ac9759 | 492 | startup_inferior (START_INFERIOR_TRAPS_EXPECTED); |
4ef1f467 | 493 | |
65b07ddc DT |
494 | /* On some targets, there must be some explicit actions taken after |
495 | the inferior has been started up. | |
496 | */ | |
497 | target_post_startup_inferior (pid); | |
de43d7d0 SG |
498 | } |
499 | ||
310cc570 RP |
500 | /* Start an inferior Unix child process and sets inferior_pid to its pid. |
501 | EXEC_FILE is the file to run. | |
502 | ALLARGS is a string containing the arguments to the program. | |
503 | ENV is the environment vector to pass. Errors reported with error(). */ | |
504 | ||
310cc570 RP |
505 | static void |
506 | child_create_inferior (exec_file, allargs, env) | |
507 | char *exec_file; | |
508 | char *allargs; | |
509 | char **env; | |
510 | { | |
65b07ddc DT |
511 | |
512 | #ifdef HPUXHPPA | |
513 | char *tryname; | |
514 | char *shell_file; | |
515 | char *p; | |
516 | char *p1; | |
517 | char *path = getenv ("PATH"); | |
518 | int len; | |
519 | struct stat statbuf; | |
520 | ||
521 | /* On HP-UX, we have a possible bad interaction between | |
522 | * the start-up-with-shell code and our catch-fork/catch-exec | |
523 | * logic. To avoid the bad interaction, we start up with the | |
524 | * C shell ("csh") and pass it the "-f" flag (fast start-up, | |
525 | * don't run .cshrc code). | |
526 | * See further comments in inferior.h toward the bottom | |
527 | * (STARTUP_WITH_SHELL flag) and in fork-child.c | |
528 | */ | |
529 | ||
530 | /* Rather than passing in a hard-wired path like "/bin/csh", | |
531 | * we look down the PATH to find csh. I took this code from | |
532 | * procfs.c, which is the file in the Sun-specific part of GDB | |
533 | * analogous to inftarg.c. See procfs.c for more detailed | |
534 | * comments. - RT | |
535 | */ | |
536 | shell_file = "csh"; | |
537 | if (path == NULL) | |
538 | path = "/bin:/usr/bin"; | |
539 | tryname = alloca (strlen (path) + strlen (shell_file) + 2); | |
540 | for (p = path; p != NULL; p = p1 ? p1 + 1: NULL) | |
541 | { | |
542 | p1 = strchr (p, ':'); | |
543 | if (p1 != NULL) | |
544 | len = p1 - p; | |
545 | else | |
546 | len = strlen (p); | |
547 | strncpy (tryname, p, len); | |
548 | tryname[len] = '\0'; | |
549 | strcat (tryname, "/"); | |
550 | strcat (tryname, shell_file); | |
551 | if (access (tryname, X_OK) < 0) | |
552 | continue; | |
553 | if (stat (tryname, &statbuf) < 0) | |
554 | continue; | |
555 | if (!S_ISREG (statbuf.st_mode)) | |
556 | /* We certainly need to reject directories. I'm not quite | |
557 | as sure about FIFOs, sockets, etc., but I kind of doubt | |
558 | that people want to exec() these things. */ | |
559 | continue; | |
560 | break; | |
561 | } | |
562 | if (p == NULL) | |
563 | /* Not found. I replaced the error() which existed in procfs.c | |
564 | * with simply passing in NULL and hoping fork_inferior() | |
565 | * can deal with it. - RT | |
566 | */ | |
567 | /* error ("Can't find shell %s in PATH", shell_file); */ | |
568 | shell_file = NULL; | |
569 | else | |
570 | shell_file = tryname; | |
571 | ||
572 | fork_inferior (exec_file, allargs, env, ptrace_me, ptrace_him, pre_fork_inferior, shell_file); | |
573 | #else | |
574 | fork_inferior (exec_file, allargs, env, ptrace_me, ptrace_him, NULL, NULL); | |
575 | #endif | |
de43d7d0 SG |
576 | /* We are at the first instruction we care about. */ |
577 | /* Pedal to the metal... */ | |
67ac9759 | 578 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0); |
310cc570 RP |
579 | } |
580 | ||
65b07ddc DT |
581 | #if !defined(CHILD_POST_STARTUP_INFERIOR) |
582 | void | |
583 | child_post_startup_inferior (pid) | |
584 | int pid; | |
585 | { | |
586 | /* This version of Unix doesn't require a meaningful "post startup inferior" | |
587 | operation by a debugger. | |
588 | */ | |
589 | } | |
590 | #endif | |
591 | ||
592 | #if !defined(CHILD_ACKNOWLEDGE_CREATED_INFERIOR) | |
593 | void | |
594 | child_acknowledge_created_inferior (pid) | |
595 | int pid; | |
596 | { | |
597 | /* This version of Unix doesn't require a meaningful "acknowledge created inferior" | |
598 | operation by a debugger. | |
599 | */ | |
600 | } | |
601 | #endif | |
602 | ||
603 | ||
604 | void | |
605 | child_clone_and_follow_inferior (child_pid, followed_child) | |
606 | int child_pid; | |
607 | int *followed_child; | |
608 | { | |
609 | clone_and_follow_inferior (child_pid, followed_child); | |
610 | ||
611 | /* Don't resume CHILD_PID; it's stopped where it ought to be, until | |
612 | the decision gets made elsewhere how to continue it. | |
613 | */ | |
614 | } | |
615 | ||
616 | ||
617 | #if !defined(CHILD_POST_FOLLOW_INFERIOR_BY_CLONE) | |
618 | void | |
619 | child_post_follow_inferior_by_clone () | |
620 | { | |
621 | /* This version of Unix doesn't require a meaningful "post follow inferior" | |
622 | operation by a clone debugger. | |
623 | */ | |
624 | } | |
625 | #endif | |
626 | ||
627 | ||
628 | #if !defined(CHILD_INSERT_FORK_CATCHPOINT) | |
629 | int | |
630 | child_insert_fork_catchpoint (pid) | |
631 | int pid; | |
632 | { | |
633 | /* This version of Unix doesn't support notification of fork events. | |
634 | */ | |
635 | } | |
636 | #endif | |
637 | ||
638 | ||
639 | #if !defined(CHILD_REMOVE_FORK_CATCHPOINT) | |
640 | int | |
641 | child_remove_fork_catchpoint (pid) | |
642 | int pid; | |
643 | { | |
644 | /* This version of Unix doesn't support notification of fork events. | |
645 | */ | |
646 | } | |
647 | #endif | |
648 | ||
649 | ||
650 | #if !defined(CHILD_INSERT_VFORK_CATCHPOINT) | |
651 | int | |
652 | child_insert_vfork_catchpoint (pid) | |
653 | int pid; | |
654 | { | |
655 | /* This version of Unix doesn't support notification of vfork events. | |
656 | */ | |
657 | } | |
658 | #endif | |
659 | ||
660 | ||
661 | #if !defined(CHILD_REMOVE_VFORK_CATCHPOINT) | |
662 | int | |
663 | child_remove_vfork_catchpoint (pid) | |
664 | int pid; | |
665 | { | |
666 | /* This version of Unix doesn't support notification of vfork events. | |
667 | */ | |
668 | } | |
669 | #endif | |
670 | ||
671 | ||
672 | #if !defined(CHILD_HAS_FORKED) | |
673 | int | |
674 | child_has_forked (pid, child_pid) | |
675 | int pid; | |
676 | int * child_pid; | |
677 | { | |
678 | /* This version of Unix doesn't support notification of fork events. | |
679 | */ | |
680 | return 0; | |
681 | } | |
682 | #endif | |
683 | ||
684 | ||
685 | #if !defined(CHILD_HAS_VFORKED) | |
686 | int | |
687 | child_has_vforked (pid, child_pid) | |
688 | int pid; | |
689 | int * child_pid; | |
690 | { | |
691 | /* This version of Unix doesn't support notification of vfork events. | |
692 | */ | |
693 | return 0; | |
694 | } | |
695 | #endif | |
696 | ||
697 | ||
698 | #if !defined(CHILD_CAN_FOLLOW_VFORK_PRIOR_TO_EXEC) | |
699 | int | |
700 | child_can_follow_vfork_prior_to_exec () | |
701 | { | |
702 | /* This version of Unix doesn't support notification of vfork events. | |
703 | However, if it did, it probably wouldn't allow vforks to be followed | |
704 | before the following exec. | |
705 | */ | |
706 | return 0; | |
707 | } | |
708 | #endif | |
709 | ||
710 | ||
711 | #if !defined(CHILD_POST_FOLLOW_VFORK) | |
712 | void | |
713 | child_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child) | |
714 | int parent_pid; | |
715 | int followed_parent; | |
716 | int child_pid; | |
717 | int followed_child; | |
718 | { | |
719 | /* This version of Unix doesn't require a meaningful "post follow vfork" | |
720 | operation by a clone debugger. | |
721 | */ | |
722 | } | |
723 | #endif | |
724 | ||
725 | #if !defined(CHILD_INSERT_EXEC_CATCHPOINT) | |
726 | int | |
727 | child_insert_exec_catchpoint (pid) | |
728 | int pid; | |
729 | { | |
730 | /* This version of Unix doesn't support notification of exec events. | |
731 | */ | |
732 | } | |
733 | #endif | |
734 | ||
735 | ||
736 | #if !defined(CHILD_REMOVE_EXEC_CATCHPOINT) | |
737 | int | |
738 | child_remove_exec_catchpoint (pid) | |
739 | int pid; | |
740 | { | |
741 | /* This version of Unix doesn't support notification of exec events. | |
742 | */ | |
743 | } | |
744 | #endif | |
745 | ||
746 | ||
747 | #if !defined(CHILD_HAS_EXECD) | |
748 | int | |
749 | child_has_execd (pid, execd_pathname) | |
750 | int pid; | |
751 | char ** execd_pathname; | |
752 | { | |
753 | /* This version of Unix doesn't support notification of exec events. | |
754 | */ | |
755 | return 0; | |
756 | } | |
757 | #endif | |
758 | ||
759 | ||
760 | #if !defined(CHILD_REPORTED_EXEC_EVENTS_PER_EXEC_CALL) | |
761 | int | |
762 | child_reported_exec_events_per_exec_call () | |
763 | { | |
764 | /* This version of Unix doesn't support notification of exec events. | |
765 | */ | |
766 | return 1; | |
767 | } | |
768 | #endif | |
769 | ||
770 | ||
771 | #if !defined(CHILD_HAS_SYSCALL_EVENT) | |
772 | int | |
773 | child_has_syscall_event (pid, kind, syscall_id) | |
774 | int pid; | |
775 | enum target_waitkind * kind; | |
776 | int * syscall_id; | |
777 | { | |
778 | /* This version of Unix doesn't support notification of syscall events. | |
779 | */ | |
780 | return 0; | |
781 | } | |
782 | #endif | |
783 | ||
784 | ||
785 | #if !defined(CHILD_HAS_EXITED) | |
786 | int | |
787 | child_has_exited (pid, wait_status, exit_status) | |
788 | int pid; | |
789 | int wait_status; | |
790 | int * exit_status; | |
791 | { | |
792 | if (WIFEXITED (wait_status)) | |
793 | { | |
794 | *exit_status = WEXITSTATUS (wait_status); | |
795 | return 1; | |
796 | } | |
797 | ||
798 | if (WIFSIGNALED (wait_status)) | |
799 | { | |
800 | *exit_status = 0; /* ?? Don't know what else to say here. */ | |
801 | return 1; | |
802 | } | |
803 | ||
804 | /* ?? Do we really need to consult the event state, too? Assume the | |
805 | wait_state alone suffices. | |
806 | */ | |
807 | return 0; | |
808 | } | |
809 | #endif | |
810 | ||
811 | ||
310cc570 RP |
812 | static void |
813 | child_mourn_inferior () | |
814 | { | |
4ef1f467 DT |
815 | /* FIXME: Should be in a header file */ |
816 | extern void proc_remove_foreign PARAMS ((int)); | |
817 | ||
310cc570 | 818 | unpush_target (&child_ops); |
4ef1f467 | 819 | proc_remove_foreign (inferior_pid); |
310cc570 RP |
820 | generic_mourn_inferior (); |
821 | } | |
822 | ||
823 | static int | |
824 | child_can_run () | |
825 | { | |
4ef1f467 DT |
826 | /* This variable is controlled by modules that sit atop inftarg that may layer |
827 | their own process structure atop that provided here. hpux-thread.c does | |
828 | this because of the Hpux user-mode level thread model. */ | |
829 | ||
830 | return !child_suppress_run; | |
831 | } | |
832 | ||
833 | /* Send a SIGINT to the process group. This acts just like the user typed a | |
834 | ^C on the controlling terminal. | |
835 | ||
836 | XXX - This may not be correct for all systems. Some may want to use | |
837 | killpg() instead of kill (-pgrp). */ | |
838 | ||
839 | static void | |
840 | child_stop () | |
841 | { | |
842 | extern pid_t inferior_process_group; | |
843 | ||
844 | kill (-inferior_process_group, SIGINT); | |
310cc570 | 845 | } |
65b07ddc DT |
846 | |
847 | #if !defined(CHILD_ENABLE_EXCEPTION_CALLBACK) | |
848 | struct symtab_and_line * | |
849 | child_enable_exception_callback (kind, enable) | |
850 | enum exception_event_kind kind; | |
851 | int enable; | |
852 | { | |
853 | return (struct symtab_and_line *) NULL; | |
854 | } | |
855 | #endif | |
856 | ||
857 | #if !defined(CHILD_GET_CURRENT_EXCEPTION_EVENT) | |
858 | struct exception_event_record * | |
859 | child_get_current_exception_event () | |
860 | { | |
861 | return (struct exception_event_record *) NULL; | |
862 | } | |
863 | #endif | |
864 | ||
865 | ||
866 | #if !defined(CHILD_PID_TO_EXEC_FILE) | |
867 | char * | |
868 | child_pid_to_exec_file (pid) | |
869 | int pid; | |
870 | { | |
871 | /* This version of Unix doesn't support translation of a process ID | |
872 | to the filename of the executable file. | |
873 | */ | |
874 | return NULL; | |
875 | } | |
876 | #endif | |
877 | ||
878 | char * | |
879 | child_core_file_to_sym_file (core) | |
880 | char * core; | |
881 | { | |
882 | /* The target stratum for a running executable need not support | |
883 | this operation. | |
884 | */ | |
885 | return NULL; | |
886 | } | |
887 | ||
888 | ||
3aa6856a | 889 | \f |
bd5635a1 | 890 | struct target_ops child_ops = { |
dcc8abce JG |
891 | "child", /* to_shortname */ |
892 | "Unix child process", /* to_longname */ | |
893 | "Unix child process (started by the \"run\" command).", /* to_doc */ | |
894 | child_open, /* to_open */ | |
895 | 0, /* to_close */ | |
896 | child_attach, /* to_attach */ | |
65b07ddc DT |
897 | child_post_attach, /* to_post_attach */ |
898 | child_require_attach, /* to_require_attach */ | |
dcc8abce | 899 | child_detach, /* to_detach */ |
65b07ddc | 900 | child_require_detach, /* to_require_detach */ |
dcc8abce JG |
901 | child_resume, /* to_resume */ |
902 | child_wait, /* to_wait */ | |
65b07ddc | 903 | child_post_wait, /* to_post_wait */ |
dcc8abce JG |
904 | fetch_inferior_registers, /* to_fetch_registers */ |
905 | store_inferior_registers, /* to_store_registers */ | |
906 | child_prepare_to_store, /* to_prepare_to_store */ | |
907 | child_xfer_memory, /* to_xfer_memory */ | |
908 | child_files_info, /* to_files_info */ | |
909 | memory_insert_breakpoint, /* to_insert_breakpoint */ | |
910 | memory_remove_breakpoint, /* to_remove_breakpoint */ | |
911 | terminal_init_inferior, /* to_terminal_init */ | |
912 | terminal_inferior, /* to_terminal_inferior */ | |
913 | terminal_ours_for_output, /* to_terminal_ours_for_output */ | |
914 | terminal_ours, /* to_terminal_ours */ | |
915 | child_terminal_info, /* to_terminal_info */ | |
916 | kill_inferior, /* to_kill */ | |
917 | 0, /* to_load */ | |
918 | 0, /* to_lookup_symbol */ | |
919 | child_create_inferior, /* to_create_inferior */ | |
65b07ddc DT |
920 | child_post_startup_inferior, /* to_post_startup_inferior */ |
921 | child_acknowledge_created_inferior, /* to_acknowledge_created_inferior */ | |
922 | child_clone_and_follow_inferior, /* to_clone_and_follow_inferior */ | |
923 | child_post_follow_inferior_by_clone, /* to_post_follow_inferior_by_clone */ | |
924 | child_insert_fork_catchpoint, /* to_insert_fork_catchpoint */ | |
925 | child_remove_fork_catchpoint, /* to_remove_fork_catchpoint */ | |
926 | child_insert_vfork_catchpoint, /* to_insert_vfork_catchpoint */ | |
927 | child_remove_vfork_catchpoint, /* to_remove_vfork_catchpoint */ | |
928 | child_has_forked, /* to_has_forked */ | |
929 | child_has_vforked, /* to_has_vforked */ | |
930 | child_can_follow_vfork_prior_to_exec, /* to_can_follow_vfork_prior_to_exec */ | |
931 | child_post_follow_vfork, /* to_post_follow_vfork */ | |
932 | child_insert_exec_catchpoint, /* to_insert_exec_catchpoint */ | |
933 | child_remove_exec_catchpoint, /* to_remove_exec_catchpoint */ | |
934 | child_has_execd, /* to_has_execd */ | |
935 | child_reported_exec_events_per_exec_call, /* to_reported_exec_events_per_exec_call */ | |
936 | child_has_syscall_event, /* to_has_syscall_event */ | |
937 | child_has_exited, /* to_has_exited */ | |
dcc8abce | 938 | child_mourn_inferior, /* to_mourn_inferior */ |
310cc570 | 939 | child_can_run, /* to_can_run */ |
de43d7d0 | 940 | 0, /* to_notice_signals */ |
4ef1f467 DT |
941 | child_thread_alive, /* to_thread_alive */ |
942 | child_stop, /* to_stop */ | |
65b07ddc DT |
943 | child_enable_exception_callback, /* to_enable_exception_callback */ |
944 | child_get_current_exception_event, /* to_get_current_exception_event */ | |
945 | child_pid_to_exec_file, /* to_pid_to_exec_file */ | |
946 | child_core_file_to_sym_file, /* to_core_file_to_sym_file */ | |
dcc8abce JG |
947 | process_stratum, /* to_stratum */ |
948 | 0, /* to_next */ | |
949 | 1, /* to_has_all_memory */ | |
950 | 1, /* to_has_memory */ | |
951 | 1, /* to_has_stack */ | |
952 | 1, /* to_has_registers */ | |
953 | 1, /* to_has_execution */ | |
4ef1f467 DT |
954 | 0, /* to_sections */ |
955 | 0, /* to_sections_end */ | |
dcc8abce | 956 | OPS_MAGIC /* to_magic */ |
bd5635a1 RP |
957 | }; |
958 | ||
959 | void | |
960 | _initialize_inftarg () | |
961 | { | |
4ef1f467 DT |
962 | #ifdef HAVE_OPTIONAL_PROC_FS |
963 | char procname[32]; | |
964 | int fd; | |
965 | ||
966 | /* If we have an optional /proc filesystem (e.g. under OSF/1), | |
967 | don't add ptrace support if we can access the running GDB via /proc. */ | |
968 | #ifndef PROC_NAME_FMT | |
969 | #define PROC_NAME_FMT "/proc/%05d" | |
970 | #endif | |
971 | sprintf (procname, PROC_NAME_FMT, getpid ()); | |
972 | if ((fd = open (procname, O_RDONLY)) >= 0) | |
973 | { | |
974 | close (fd); | |
975 | return; | |
976 | } | |
977 | #endif | |
978 | ||
bd5635a1 RP |
979 | add_target (&child_ops); |
980 | } |