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