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