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