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