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